/**
|
******************************************************************************
|
* @file xl_wdog.c
|
* @author Kirk ,xu.wang
|
* @version 4.5.2
|
* @date Fri Mar 26 17:29:12 2021
|
* @brief This file provide function about WDOG firmware program
|
******************************************************************************
|
* @attention
|
*
|
* 2019 by Chipways Communications,Inc. All Rights Reserved.
|
* This software is supplied under the terms of a license
|
* agreement or non-disclosure agreement with Chipways.
|
* Passing on and copying of this document,and communication
|
* of its contents is not permitted without prior written
|
* authorization.
|
*
|
* <h2><center>© COPYRIGHT 2019 Chipways</center></h2>
|
******************************************************************************
|
*/
|
|
#if defined(__cplusplus)
|
extern "C" {
|
#endif /* __cplusplus */
|
|
/* Includes ---------------------------------------------------------------*/
|
#include "xl_wdog.h"
|
|
/** @addtogroup XL6600_StdPeriph_Driver
|
* @{
|
*/
|
|
/** @defgroup WDOG WDOG Module
|
* @brief WDOG Driver Modules Library
|
* @{
|
*/
|
|
/* Private typedef -----------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
|
|
/** @defgroup WDOG_Private_Functions
|
* @{
|
*/
|
|
/**
|
* @brief ÉèÖÃWDOGÍâÉè¼Ä´æÆ÷Ϊ³õʼ״̬
|
* @param WDOGx: WDTÍâÉè¡£
|
* @retval None
|
*/
|
void WDOG_DeInit(WDOG_Type *WDOGx)
|
{
|
/* Deinitializes to default reset values */
|
//WDOGx->CS2 = 0x00;
|
WDOGx->CS1 = 0x00;
|
}
|
|
/**
|
* @brief ³õʼ»¯WTDģʽ
|
* @param WDOGx: Ñ¡ÔñWDTÍâÉè¡£
|
* @param WDOG_InitStruct: WDOG_InitTypeDef ÀàÐ͵ÄÖ¸Õ룬°üº¬Ìض¨µÄWDTÍâÉèµÄÉèÖÃÐÅÏ¢
|
* @retval None
|
*/
|
void WDOG_Init(WDOG_Type *WDOGx, const WDOG_InitTypeDef *WDOG_InitStruct)
|
{
|
uint8_t tmpreg1;
|
uint32_t tmpreg;
|
|
/*---------------------------- WDT CS2 Configuration ------------------------*/
|
/* Get the WDT CS1 value */
|
tmpreg1 = (uint8_t)WDOGx->CS2 ;
|
|
/* Clear RPL, RMOD bits */
|
//tmpreg1 &= ~(WDOG_CS2_CLK_MASK | WDOG_CS2_PRES_MASK | WDOG_CS2_STOP_MASK | WDOG_CS2_WAIT_MASK | WDOG_CS2_DEBUG_MASK);
|
tmpreg1 &= ~0x7Fu;
|
|
/* Set the bit in CS1 Register */
|
tmpreg1 |= (uint8_t)(WDOG_InitStruct->WDOG_ClkSource | \
|
((uint32_t)WDOG_InitStruct->WDOG_DEBUGEn << WDOG_CS2_DEBUG_SHIFT) | \
|
((uint32_t)WDOG_InitStruct->WDOG_PRESEn << WDOG_CS2_PRES_SHIFT) | \
|
((uint32_t)WDOG_InitStruct->WDOG_STOPEn << WDOG_CS2_STOP_SHIFT) | \
|
((uint32_t)WDOG_InitStruct->WDOG_WAITEn << WDOG_CS2_WAIT_SHIFT));
|
|
/* Write to WDT CS1 */
|
WDOGx->CS2 = (uint32_t)tmpreg1;
|
|
/*---------------------------- WDT CS1 Configuration ------------------------*/
|
/* Get the WDT CS1 value */
|
tmpreg = WDOGx->CS1;
|
|
/* Clear RPL, RMOD bits */
|
tmpreg &= ~(WDOG_CS1_RMOD_MASK | WDOG_CS1_RPL_MASK);
|
|
/* Set the bit in CS1 Register */
|
tmpreg |= (((uint32_t)WDOG_InitStruct->WDOG_PulseLength << WDOG_CS1_RPL_SHIFT) | \
|
((uint32_t)WDOG_InitStruct->WDOG_ResponseMode << WDOG_CS1_RMOD_SHIFT));
|
|
/* Write to WDT CS1 */
|
WDOGx->CS1 = tmpreg ;
|
/*------------------------------------ end --------------------------------*/
|
}
|
|
/**
|
* @brief WDOGʹÄÜ
|
* @param WDOGx: Ñ¡ÔñWODGÍâÉè¡£
|
* @param State: WDOGʹÄÜ״̬
|
* Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
|
* @arg ENABLE: WDOGʹÄÜ
|
* @arg DISABLE: WDOGʧÄÜ
|
* @retval None
|
*/
|
void WDOG_EnableCmd(WDOG_Type *WDOGx,FunctionalState State)
|
{
|
if(State !=DISABLE)
|
{
|
/* Enable the WDT */
|
WDOGx->CS1 |= WDOG_CS1_EN_MASK;
|
}
|
else
|
{
|
/* Disable the WDT */
|
WDOGx->CS1 &= ~WDOG_CS1_EN_MASK;
|
}
|
}
|
|
/**
|
* @brief ½¨Á¢¿´ÃŹ·Ê±ÖÓ·ÖÆµ
|
* @param WDOGx: Ñ¡ÔñWDTÍâÉè¡£
|
* @param TimeoutIndex: ³¬Ê±Ê±¼ä
|
* @retval None
|
*/
|
void WDOG_SetTimeoutPeriod(WDOG_Type *WDOGx, uint8_t TimeoutIndex)
|
{
|
WDOGx->TORR &= ~WDOG_TORR_TOP_MASK;
|
WDOGx->TORR |= TimeoutIndex;
|
}
|
|
/**
|
* @brief »ñµÃÄÚ²¿¼ÆÊýÆ÷µÄÖµ
|
* @param WDOGx: Ñ¡ÔñWDTÍâÉè¡£
|
* @retval ¼ÆÊýÆ÷µÄµ±Ç°Öµ
|
*/
|
uint32_t WDOG_GetCurrentVal(const WDOG_Type *WDOGx)
|
{
|
return WDOGx->CCVR ;
|
}
|
|
/**
|
* @brief ÖØÆô WDT
|
* @param WDOGx: Ñ¡ÔñWDTÍâÉè¡£
|
* @retval None
|
*/
|
void WDOG_CountRestart(WDOG_Type *WDOGx)
|
{
|
/* write the value 0x76 to the register */
|
WDOGx->CRR = 0x76;
|
}
|
|
/**
|
* @brief »ñµÃWDOGÖжÏ״̬
|
* @param WDOGx: Ñ¡ÔñWDTÍâÉè¡£
|
* @retval ÖжÏ״̬
|
*/
|
FlagStatus WDOG_GetIntStatus(const WDOG_Type *WDOGx)
|
{
|
FlagStatus ret;
|
|
/* get the interrupt status */
|
if(WDOGx->STAT != 0u)
|
{
|
ret = SET;
|
}
|
else
|
{
|
ret = RESET;
|
}
|
|
return ret;
|
}
|
|
/**
|
* @brief Çå¿ÕWDOGÖжÏ
|
* @param WDOGx: Ñ¡ÔñWDTÍâÉè¡£
|
* @retval None
|
*/
|
void WDOG_ClrInt(const WDOG_Type *WDOGx)
|
{
|
/* Dummy read to clear */
|
(void)(WDOGx->EOI);
|
}
|
|
/**
|
* @}
|
*/
|
|
/**
|
* @}
|
*/
|
|
#ifdef __cplusplus
|
}
|
#endif /* __cplusplus */
|
/**
|
* @}
|
*/
|
|
/**
|
* @}
|
*/
|