| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- /******************************************************************************
- *
- * @brief providing APIs for system integration module (SIM).
- *
- *******************************************************************************
- *
- * provide APIs for SIM
- ******************************************************************************/
- #include "common.h"
- #include "sim.h"
- /******************************************************************************
- * Global variables
- ******************************************************************************/
- /******************************************************************************
- * Constants and macros
- ******************************************************************************/
- /******************************************************************************
- * Local types
- ******************************************************************************/
- /******************************************************************************
- * Local function prototypes
- ******************************************************************************/
- /******************************************************************************
- * Local variables
- ******************************************************************************/
- /******************************************************************************
- * Local functions
- ******************************************************************************/
- /******************************************************************************
- * Global functions
- ******************************************************************************/
- /******************************************************************************
- * define SIM API list
- *
- *//*! @addtogroup sim_api_list
- * @{
- *******************************************************************************/
- #if defined(CPU_NV32)
- /*****************************************************************************//*!
- *
- * @brief initialize SIM registers.
- *
- * @param[in] pConfig pointer to SIM configuration.
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @see SIM_ConfigType
- *****************************************************************************/
- void SIM_Init(SIM_ConfigType *pConfig)
- {
- uint32_t u32Sopt;
- uint32_t u32PinSel;
- uint32_t u32Scgc;
- uint32_t u32BusDiv;
- /*
- * intialize the registers to reset default values
- */
- u32Sopt = 0x0010000E; /* enable SWD, RESET, and NMI pins */
- u32PinSel = 0;
- u32Scgc = 0x00003000; /* enable SWD and FLASH */
- u32BusDiv = 0;
- u32BusDiv = pConfig->sBits.bBusDiv;
- if(pConfig->sBits.bDisableNMI)
- {
- u32Sopt &= ~SIM_SOPT_NMIE_MASK;
- }
- if(pConfig->sBits.bDisableRESET)
- {
- u32Sopt &= ~SIM_SOPT_RSTPE_MASK;
- }
- if(pConfig->sBits.bDisableSWD)
- {
- u32Sopt &= ~SIM_SOPT_SWDE_MASK;
- }
- if(pConfig->sBits.bEnableCLKOUT)
- {
- u32Sopt |= SIM_SOPT_CLKOE_MASK;
- }
- if(pConfig->sBits.bETMSYNC)
- {
- u32Sopt |= SIM_SOPT_ETMSYNC_MASK;
- }
- if(pConfig->sBits.bRXDCE)
- {
- u32Sopt |= SIM_SOPT_RXDCE_MASK;
- }
- if(pConfig->sBits.bTXDME)
- {
- u32Sopt |= SIM_SOPT_TXDME_MASK;
- }
- if(pConfig->sBits.bACIC)
- {
- u32Sopt |= SIM_SOPT_ACIC_MASK;
- }
- if(pConfig->sBits.bRTCC)
- {
- u32Sopt |= SIM_SOPT_RTCC_MASK;
- }
- if(pConfig->sBits.bRXDFE)
- {
- u32Sopt |= SIM_SOPT_RXDFE_MASK;
- }
- u32Sopt |= ((pConfig->u8BusRef & 0x07) << 16);
- u32Sopt |= ((pConfig->u8Delay) << 24);
- u32Sopt |= ((pConfig->sBits.u8ADHWT & 0x03) << 8);
- u32PinSel = pConfig->u32PinSel;
- u32Scgc = pConfig->u32SCGC;
-
- /* write SIM registers */
- SIM->SOPT = u32Sopt;
- SIM->PINSEL = u32PinSel;
- SIM->SCGC = u32Scgc;
- SIM->BUSDIV = u32BusDiv;
- }
- #elif defined(CPU_NV32M3)
- /*****************************************************************************//*!
- *
- * @brief initialize SIM registers.
- *
- * @param[in] pConfig pointer to SIM configuration.
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @see SIM_ConfigType
- *****************************************************************************/
- void SIM_Init(SIM_ConfigType *pConfig)
- {
- uint32_t u32Sopt;
- uint32_t u32PinSel;
- uint32_t u32Scgc;
- uint32_t u32ClockDiv;
- /*
- * intialize the registers to reset default values
- */
- u32Sopt = 0x0010000E; /* enable SWD, RESET, and NMI pins */
- u32PinSel = 0;
- u32Scgc = 0x00003000; /* enable SWD and FLASH */
- u32ClockDiv = 0;
- u32ClockDiv = pConfig->u32CLKDIV;
- if(pConfig->sBits.bDisableNMI)
- {
- u32Sopt &= ~SIM_SOPT_NMIE_MASK;
- }
- if(pConfig->sBits.bDisableRESET)
- {
- u32Sopt &= ~SIM_SOPT_RSTPE_MASK;
- }
- if(pConfig->sBits.bDisableSWD)
- {
- u32Sopt &= ~SIM_SOPT_SWDE_MASK;
- }
- if(pConfig->sBits.bEnableCLKOUT)
- {
- u32Sopt |= SIM_SOPT_CLKOE_MASK;
- }
- if(pConfig->sBits.bETMSYNC)
- {
- u32Sopt |= SIM_SOPT_ETMSYNC_MASK;
- }
- if(pConfig->sBits.bRXDCE)
- {
- u32Sopt |= SIM_SOPT_RXDCE_MASK;
- }
- if(pConfig->sBits.bTXDME)
- {
- u32Sopt |= SIM_SOPT_TXDME_MASK;
- }
- if(pConfig->sBits.bACTRG)
- {
- u32Sopt |= SIM_SOPT_ACTRG_MASK;
- }
- u32Sopt |= ((pConfig->u8BusRef & 0x07) << 16);
- u32Sopt |= ((pConfig->u8Delay) << 24);
- u32Sopt |= ((pConfig->sBits.u8ADHWT & 0x07) << 20);
- u32Sopt |= ((pConfig->sBits.bRXDFE)&0x03<<8);
- u32Sopt |= ((pConfig->sBits.bETMIC)&0x03<<6);
- u32PinSel = pConfig->u32PinSel;
- u32Scgc = pConfig->u32SCGC;
- /* write SIM registers */
- SIM->SOPT = u32Sopt;
- SIM->PINSEL = u32PinSel;
- SIM->SCGC = u32Scgc;
- SIM->CLKDIV = u32ClockDiv;
- }
- #elif defined(CPU_NV32M4)
- /*****************************************************************************//*!
- *
- * @brief initialize SIM registers.
- *
- * @param[in] pConfig pointer to SIM configuration.
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @see SIM_ConfigType
- *****************************************************************************/
- void SIM_Init(SIM_ConfigType *pConfig)
- {
- uint32_t u32Sopt;
- uint32_t u32PinSel;
- uint32_t u32Scgc;
- uint32_t u32ClockDiv;
- /*
- * intialize the registers to reset default values
- */
- u32Sopt = 0x0E; /* enable SWD, RESET, and NMI pins */
- u32PinSel = 0;
- u32Scgc = 0x00003000; /* enable SWD and FLASH */
- u32ClockDiv = 0;
- u32ClockDiv = pConfig->u32CLKDIV;
- if(pConfig->sBits.bDisableNMI)
- {
- u32Sopt &= ~SIM_SOPT0_NMIE_MASK;
- }
- if(pConfig->sBits.bDisableRESET)
- {
- u32Sopt &= ~SIM_SOPT0_RSTPE_MASK;
- }
- if(pConfig->sBits.bDisableSWD)
- {
- u32Sopt &= ~SIM_SOPT0_SWDE_MASK;
- }
- if(pConfig->sBits.bEnableCLKOUT)
- {
- u32Sopt |= SIM_SOPT0_CLKOE_MASK;
- }
- if(pConfig->sBits.bETMSYNC)
- {
- u32Sopt |= SIM_SOPT0_ETMSYNC_MASK;
- }
- if(pConfig->sBits.bRXDCE)
- {
- u32Sopt |= SIM_SOPT0_RXDCE_MASK;
- }
- if(pConfig->sBits.bTXDME)
- {
- u32Sopt |= SIM_SOPT0_TXDME_MASK;
- }
- if(pConfig->sBits.bACTRG)
- {
- u32Sopt |= SIM_SOPT0_ACTRG_MASK;
- }
- u32Sopt |= ((pConfig->u8BusRef & 0x07) << 16);
- u32Sopt |= ((pConfig->u8Delay) << 24);
- u32Sopt |= ((pConfig->sBits.u8ADHWT & 0x07) << 20);
- u32Sopt |= ((pConfig->sBits.bRXDFE)&0x03<<8);
- //u32Sopt |= ((pConfig->sBits.bETMIC)&0x03<<6);
- u32PinSel = pConfig->u32PinSel;
- u32Scgc = pConfig->u32SCGC;
- /* write SIM registers */
- SIM->SOPT0 = u32Sopt;
- SIM->PINSEL = u32PinSel;
- SIM->SCGC = u32Scgc;
- SIM->CLKDIV = u32ClockDiv;
- }
- #endif
- /*****************************************************************************//*!
- *
- * @brief set SIM clock gating registers to enable or disable peripheral clocks.
- *
- * @param[in] u32PeripheralMask peripherial bits mask.
- * @param[in] u8GateOn 1: ON, 0: OFF.
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- *****************************************************************************/
- void SIM_SetClockGating(uint32_t u32PeripheralMask, uint8_t u8GateOn)
- {
- uint32_t u32Scgc;
- /*
- * save original clock gating value
- */
- u32Scgc = SIM->SCGC;
-
- if(u8GateOn)
- {
- u32Scgc |= u32PeripheralMask;
- }
- else
- {
- u32Scgc &= ~u32PeripheralMask;
- }
- SIM->SCGC = u32Scgc;
- }
- /*****************************************************************************//*!
- *
- * @brief read the corresponding status flags.
- *
- * @param[in] u32StatusMask indicates which status to be read.
- *
- * @return status.
- *
- * @ Pass/ Fail criteria: none
- *****************************************************************************/
- uint32_t SIM_GetStatus(uint32_t u32StatusMask)
- {
- uint32_t u32Status;
- u32Status = SIM->SRSID & u32StatusMask;
- return (u32Status);
- }
- /*****************************************************************************//*!
- *
- * @brief read the corresponding ID.
- *
- * @param[in] u8ID type of ID.
- *
- * @return ID
- *
- * @ Pass/ Fail criteria: none.
- * @see IDType.
- *****************************************************************************/
- uint8_t SIM_ReadID(IDType sID)
- {
- uint32_t u32ID;
- uint8_t u8IDOffset[4] =
- {
- 28, 24, 20,16
- };
- u32ID = (SIM->SRSID >> u8IDOffset[sID]) & 0x0F;
- return (u32ID);
- }
- /*! @} End of sim_api_list */
|