Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:01

0001 /*
0002  * Copyright 2017-2020, 2022 NXP
0003  * All rights reserved.
0004  *
0005  * SPDX-License-Identifier: BSD-3-Clause
0006  */
0007 
0008 #ifndef _FSL_SEMA4_H_
0009 #define _FSL_SEMA4_H_
0010 
0011 #include "fsl_common.h"
0012 
0013 /*!
0014  * @addtogroup sema4
0015  * @{
0016  */
0017 
0018 /******************************************************************************
0019  * Definitions
0020  *****************************************************************************/
0021 
0022 /*! @name Driver version */
0023 /*@{*/
0024 /*! @brief SEMA4 driver version */
0025 #define FSL_SEMA4_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
0026 /*@}*/
0027 
0028 /*! @brief The number to reset all SEMA4 gates. */
0029 #define SEMA4_GATE_NUM_RESET_ALL (64U)
0030 
0031 #if defined(SEMA4_GATE_COUNT)
0032 
0033 /*!
0034  * @brief SEMA4 gate n register address.
0035  */
0036 #define SEMA4_GATEn(base, n) ((base)->GATE[(n)])
0037 
0038 #ifndef FSL_FEATURE_SEMA4_GATE_COUNT
0039 #define FSL_FEATURE_SEMA4_GATE_COUNT SEMA4_GATE_COUNT
0040 #endif
0041 
0042 #else
0043 
0044 /*!
0045  * @brief SEMA4 gate n register address.
0046  */
0047 #define SEMA4_GATEn(base, n) (((volatile uint8_t *)(&((base)->Gate00)))[(n)])
0048 
0049 #endif
0050 
0051 /*******************************************************************************
0052  * API
0053  ******************************************************************************/
0054 
0055 #if defined(__cplusplus)
0056 extern "C" {
0057 #endif
0058 
0059 /*!
0060  * @brief Initializes the SEMA4 module.
0061  *
0062  * This function initializes the SEMA4 module. It only enables the clock but does
0063  * not reset the gates because the module might be used by other processors
0064  * at the same time. To reset the gates, call either SEMA4_ResetGate or
0065  * SEMA4_ResetAllGates function.
0066  *
0067  * @param base SEMA4 peripheral base address.
0068  */
0069 void SEMA4_Init(SEMA4_Type *base);
0070 
0071 /*!
0072  * @brief De-initializes the SEMA4 module.
0073  *
0074  * This function de-initializes the SEMA4 module. It only disables the clock.
0075  *
0076  * @param base SEMA4 peripheral base address.
0077  */
0078 void SEMA4_Deinit(SEMA4_Type *base);
0079 
0080 /*!
0081  * @brief Tries to lock the SEMA4 gate.
0082  *
0083  * This function tries to lock the specific SEMA4 gate. If the gate has been
0084  * locked by another processor, this function returns an error code.
0085  *
0086  * @param base SEMA4 peripheral base address.
0087  * @param gateNum  Gate number to lock.
0088  * @param procNum  Current processor number.
0089  *
0090  * @retval kStatus_Success     Lock the sema4 gate successfully.
0091  * @retval kStatus_Fail Sema4 gate has been locked by another processor.
0092  */
0093 status_t SEMA4_TryLock(SEMA4_Type *base, uint8_t gateNum, uint8_t procNum);
0094 
0095 /*!
0096  * @brief Locks the SEMA4 gate.
0097  *
0098  * This function locks the specific SEMA4 gate. If the gate has been
0099  * locked by other processors, this function waits until it is unlocked and then
0100  * lock it.
0101  *
0102  * @param base SEMA4 peripheral base address.
0103  * @param gateNum  Gate number to lock.
0104  * @param procNum  Current processor number.
0105  */
0106 void SEMA4_Lock(SEMA4_Type *base, uint8_t gateNum, uint8_t procNum);
0107 
0108 /*!
0109  * @brief Unlocks the SEMA4 gate.
0110  *
0111  * This function unlocks the specific SEMA4 gate. It only writes unlock value
0112  * to the SEMA4 gate register. However, it does not check whether the SEMA4 gate is locked
0113  * by the current processor or not. As a result, if the SEMA4 gate is not locked by the current
0114  * processor, this function has no effect.
0115  *
0116  * @param base SEMA4 peripheral base address.
0117  * @param gateNum  Gate number to unlock.
0118  */
0119 static inline void SEMA4_Unlock(SEMA4_Type *base, uint8_t gateNum)
0120 {
0121     assert(gateNum < (uint8_t)FSL_FEATURE_SEMA4_GATE_COUNT);
0122 
0123     SEMA4_GATEn(base, gateNum) = 0U;
0124 }
0125 
0126 /*!
0127  * @brief Gets the status of the SEMA4 gate.
0128  *
0129  * This function checks the lock status of a specific SEMA4 gate.
0130  *
0131  * @param base SEMA4 peripheral base address.
0132  * @param gateNum  Gate number.
0133  *
0134  * @return Return -1 if the gate is unlocked, otherwise return the
0135  * processor number which has locked the gate.
0136  */
0137 static inline int32_t SEMA4_GetLockProc(SEMA4_Type *base, uint8_t gateNum)
0138 {
0139     assert(gateNum < (uint8_t)FSL_FEATURE_SEMA4_GATE_COUNT);
0140 
0141     return (int32_t)(SEMA4_GATEn(base, gateNum)) - 1;
0142 }
0143 
0144 /*!
0145  * @brief Resets the SEMA4 gate to an unlocked status.
0146  *
0147  * This function resets a SEMA4 gate to an unlocked status.
0148  *
0149  * @param base SEMA4 peripheral base address.
0150  * @param gateNum  Gate number.
0151  *
0152  * @retval kStatus_Success         SEMA4 gate is reset successfully.
0153  * @retval kStatus_Fail Some other reset process is ongoing.
0154  */
0155 status_t SEMA4_ResetGate(SEMA4_Type *base, uint8_t gateNum);
0156 
0157 /*!
0158  * @brief Resets all SEMA4 gates to an unlocked status.
0159  *
0160  * This function resets all SEMA4 gate to an unlocked status.
0161  *
0162  * @param base SEMA4 peripheral base address.
0163  *
0164  * @retval kStatus_Success         SEMA4 is reset successfully.
0165  * @retval kStatus_Fail Some other reset process is ongoing.
0166  */
0167 static inline status_t SEMA4_ResetAllGates(SEMA4_Type *base)
0168 {
0169     return SEMA4_ResetGate(base, SEMA4_GATE_NUM_RESET_ALL);
0170 }
0171 
0172 /*!
0173  * @brief Enable the gate notification interrupt.
0174  *
0175  * Gate notification provides such feature, when core tried to lock the gate
0176  * and failed, it could get notification when the gate is idle.
0177  *
0178  * @param base SEMA4 peripheral base address.
0179  * @param procNum  Current processor number.
0180  * @param mask OR'ed value of the gate index, for example: (1<<0) | (1<<1) means
0181  * gate 0 and gate 1.
0182  */
0183 static inline void SEMA4_EnableGateNotifyInterrupt(SEMA4_Type *base, uint8_t procNum, uint32_t mask)
0184 {
0185     mask = __REV(__RBIT(mask));
0186     base->CPINE[procNum].CPINE |= (uint16_t)mask;
0187 }
0188 
0189 /*!
0190  * @brief Disable the gate notification interrupt.
0191  *
0192  * Gate notification provides such feature, when core tried to lock the gate
0193  * and failed, it could get notification when the gate is idle.
0194  *
0195  * @param base SEMA4 peripheral base address.
0196  * @param procNum  Current processor number.
0197  * @param mask OR'ed value of the gate index, for example: (1<<0) | (1<<1) means
0198  * gate 0 and gate 1.
0199  */
0200 static inline void SEMA4_DisableGateNotifyInterrupt(SEMA4_Type *base, uint8_t procNum, uint32_t mask)
0201 {
0202     mask = __REV(__RBIT(mask));
0203     base->CPINE[procNum].CPINE &= (uint16_t)(~mask);
0204 }
0205 
0206 /*!
0207  * @brief Get the gate notification flags.
0208  *
0209  * Gate notification provides such feature, when core tried to lock the gate
0210  * and failed, it could get notification when the gate is idle. The status flags
0211  * are cleared automatically when the gate is locked by current core or locked
0212  * again before the other core.
0213  *
0214  * @param base SEMA4 peripheral base address.
0215  * @param procNum  Current processor number.
0216  * @return OR'ed value of the gate index, for example: (1<<0) | (1<<1) means
0217  * gate 0 and gate 1 flags are pending.
0218  */
0219 static inline uint32_t SEMA4_GetGateNotifyStatus(SEMA4_Type *base, uint8_t procNum)
0220 {
0221     return __REV(__RBIT(base->CPNTF[procNum].CPNTF));
0222 }
0223 
0224 /*!
0225  * @brief Resets the SEMA4 gate IRQ notification.
0226  *
0227  * This function resets a SEMA4 gate IRQ notification.
0228  *
0229  * @param base SEMA4 peripheral base address.
0230  * @param gateNum  Gate number.
0231  *
0232  * @retval kStatus_Success Reset successfully.
0233  * @retval kStatus_Fail    Some other reset process is ongoing.
0234  */
0235 status_t SEMA4_ResetGateNotify(SEMA4_Type *base, uint8_t gateNum);
0236 
0237 /*!
0238  * @brief Resets all SEMA4 gates IRQ notification.
0239  *
0240  * This function resets all SEMA4 gate IRQ notifications.
0241  *
0242  * @param base SEMA4 peripheral base address.
0243  *
0244  * @retval kStatus_Success  Reset successfully.
0245  * @retval kStatus_Fail     Some other reset process is ongoing.
0246  */
0247 static inline status_t SEMA4_ResetAllGateNotify(SEMA4_Type *base)
0248 {
0249     return SEMA4_ResetGateNotify(base, SEMA4_GATE_NUM_RESET_ALL);
0250 }
0251 
0252 #if defined(__cplusplus)
0253 }
0254 #endif
0255 
0256 /*!
0257  * @}
0258  */
0259 
0260 #endif /* _FSL_SEMA4_H_ */