| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- /******************************************************************************
- *
- * @brief Provide common watchdog module routines.
- *
- * @history:
- * Jun. 25, 2013 modified the watch dog unlock sequence and disable sequence
- ******************************************************************************/
- #include "common.h"
- #include "wdog.h"
-
- /******************************************************************************
- * Global variables
- ******************************************************************************/
- /******************************************************************************
- * Constants and macros
- ******************************************************************************/
- /******************************************************************************
- * Local types
- ******************************************************************************/
- /******************************************************************************
- * Local function prototypes
- ******************************************************************************/
- /******************************************************************************
- * Local variables
- ******************************************************************************/
- /******************************************************************************
- * Local functions
- ******************************************************************************/
- /******************************************************************************
- * Global functions
- ******************************************************************************/
- /******************************************************************************
- * define watchdog API list
- *
- *//*! @addtogroup wdog_api_list
- * @{
- *******************************************************************************/
- /*****************************************************************************//*!
- *
- * @brief Watchdog ETMer disable routine.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @see WDOG_Enable
- *****************************************************************************/
- void WDOG_Disable(void)
- {
- uint8_t u8Cs1 = WDOG->CS1;
- uint8_t u8Cs2 = WDOG->CS2;
- uint16_t u16TOVAL = WDOG->TOVAL;
- uint16_t u16WIN = WDOG->WIN;
- u8Cs1 &= ~WDOG_CS1_EN_MASK;
- /* First unlock the watchdog so that we can write to registers */
- WDOG_Unlock();
- WDOG->CS2 = u8Cs2;
- WDOG->TOVAL = u16TOVAL;
- WDOG->WIN = u16WIN;
- WDOG->CS1 = u8Cs1;
- }
- /*****************************************************************************//*!
- *
- * @brief Watchdog ETMer disable routine with update enabled.
- *
- * Disable watchdog but the watchdog can be enabled and updated later.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @see WDOG_Enable
- *****************************************************************************/
- void WDOG_DisableWDOGEnableUpdate(void)
- {
- uint8_t u8Cs1 = WDOG->CS1;
- uint8_t u8Cs2 = WDOG->CS2;
- uint16_t u16TOVAL = WDOG->TOVAL;
- uint16_t u16WIN = WDOG->WIN;
- u8Cs1 &= ~WDOG_CS1_EN_MASK;
- u8Cs1 |= WDOG_CS1_UPDATE_MASK;
- /* First unlock the watchdog so that we can write to registers */
- //WDOG_Unlock();
- WDOG->CS2 = u8Cs2;
- WDOG->TOVAL = u16TOVAL;
- WDOG->WIN = u16WIN;
- WDOG->CS1 = u8Cs1;
- }
- /*****************************************************************************//*!
- *
- * @brief Watchdog ETMer enable routine.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @see WDOG_Disable
- *****************************************************************************/
- void WDOG_Enable(void)
- {
- uint8_t u8Cs1 = WDOG->CS1;
-
- u8Cs1 |= WDOG_CS1_EN_MASK;
- /* First unlock the watchdog so that we can write to registers */
- WDOG_Unlock();
- WDOG->CS1 = u8Cs1;
- }
- /*****************************************************************************//*!
- *
- * @brief initialize watchdog.
- *
- * @param[in] pConfig poiner to watchdog configuration strcture.
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- *
- * @warning make sure that WDOG is not initialized after reset or WDOG update is enabled
- * after reset by calling WDOG_EnableUpdate / WDOG_DisableWDOGEnableUpdate.
- *
- * @see WDOG_EnableUpdate, WDOG_DisableWDOGEnableUpdate
- *
- *****************************************************************************/
- void WDOG_Init(WDOG_ConfigPtr pConfig)
- {
- uint8_t u8Cs1;
- uint8_t u8Cs2;
- uint16_t u16Toval;
- uint16_t u16Win;
-
- u8Cs1 = 0x80; /* default CS1 register value */
- u8Cs2 = 0;
- u16Toval = pConfig->u16ETMeOut;
- u16Win = pConfig->u16WinETMe;
-
- if(pConfig->sBits.bDisable)
- {
- u8Cs1 &= ~WDOG_CS1_EN_MASK;
- }
- if(pConfig->sBits.bIntEnable)
- {
- u8Cs1 |= WDOG_CS1_INT_MASK;
- }
- if(pConfig->sBits.bStopEnable)
- {
- u8Cs1 |= WDOG_CS1_STOP_MASK;
- }
- if(pConfig->sBits.bDbgEnable)
- {
- u8Cs1 |= WDOG_CS1_DBG_MASK;
- }
- if(pConfig->sBits.bWaitEnable)
- {
- u8Cs1 |= WDOG_CS1_WAIT_MASK;
- }
- if(pConfig->sBits.bUpdateEnable)
- {
- u8Cs1 |= WDOG_CS1_UPDATE_MASK;
- }
- if(pConfig->sBits.bWinEnable)
- {
- u8Cs2 |= WDOG_CS2_WIN_MASK;
- }
- if(pConfig->sBits.bPrescaler)
- {
- u8Cs2 |= WDOG_CS2_PRES_MASK;
- }
- u8Cs2 |= (pConfig->sBits.bClkSrc & 0x03);
-
- /* write regisers */
- WDOG_Unlock(); /* unlock watchdog first */
- WDOG->CS2 = u8Cs2;
- WDOG->TOVAL8B.TOVALL = u16Toval;
- WDOG->TOVAL8B.TOVALH = u16Toval >> 8;
-
- WDOG->WIN8B.WINL = u16Win;
- WDOG->WIN8B.WINH = u16Win >> 8;
-
- WDOG->CS1 = u8Cs1;
- }
- /*****************************************************************************//*!
- *
- * @brief initialize watchdog to the default state.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @warning make sure that WDOG update is enabled after reset by calling WDOG_EnableUpdate.
- * or by calling WDOG_DisableWDOGEnableUpdate.
- *
- * @see WDOG_DisableWDOGEnableUpdate, WDOG_EnableUpdate
- *
- *****************************************************************************/
- void WDOG_DeInit(void)
- {
- WDOG_Unlock();
-
- WDOG->CS2 = WDOG_CS2_DEFAULT_VALUE;
- WDOG->TOVAL = WDOG_TOVAL_DEFAULT_VALUE;
- WDOG->WIN = WDOG_WIN_DEFAULT_VALUE;
- WDOG->CS1 = WDOG_CS1_DEFAULT_VALUE;
- }
- /*****************************************************************************//*!
- *
- * @brief feed/refresh watchdog.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- *****************************************************************************/
- void WDOG_Feed(void)
- {
- DisableInterrupts;
- WDOG->CNT = 0x02A6;
- WDOG->CNT = 0x80B4;
- EnableInterrupts;
- }
- /*****************************************************************************//*!
- *
- * @brief enable update of WDOG.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @warning this must be the last step of writing control bits sequence.
- *****************************************************************************/
- void WDOG_EnableUpdate(void)
- {
- uint8_t u8Cs1 = WDOG->CS1;
- uint8_t u8Cs2 = WDOG->CS2;
- uint16_t u16TOVAL = WDOG->TOVAL;
- uint16_t u16WIN = WDOG->WIN;
- u8Cs1 |= WDOG_CS1_UPDATE_MASK;
- /* First unlock the watchdog so that we can write to registers */
- WDOG_Unlock();
- WDOG->CS2 = u8Cs2;
- WDOG->TOVAL = u16TOVAL;
- WDOG->WIN = u16WIN;
- WDOG->CS1 = u8Cs1;
- }
- /*****************************************************************************//*!
- *
- * @brief disable update of WDOG.
- *
- * @param none
- *
- * @return none
- *
- * @ Pass/ Fail criteria: none
- * @warning this must be the last step of writing control bits sequence.
- *****************************************************************************/
- void WDOG_DisableUpdate(void)
- {
- uint8_t u8Cs1 = WDOG->CS1;
- uint8_t u8Cs2 = WDOG->CS2;
- uint16_t u16TOVAL = WDOG->TOVAL;
- uint16_t u16WIN = WDOG->WIN;
- u8Cs1 &= ~WDOG_CS1_UPDATE_MASK;
- /* First unlock the watchdog so that we can write to registers */
- WDOG_Unlock();
- WDOG->CS2 = u8Cs2;
- WDOG->TOVAL = u16TOVAL;
- WDOG->WIN = u16WIN;
- WDOG->CS1 = u8Cs1;
-
- }
- /********************************************************************/
- /*! @} End of wdog_api_list */
|