TJ-WW03-H03/APP_smoke_N_V1.3/HARDWARE/WWDG/wwdg.c

112 lines
4.0 KiB
C

////////////////////////////////////////////////////////////////////////////////
/// @file wwdg.c
/// @author AE TEAM
/// @brief In window comparator mode,The transformation results are detected
/// Set the threshold value from 0 to 3V, and connect PB6 and PA0 with
/// jumper cap to see the effect.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////
// Define to prevent recursive inclusion
#define _WWDG_C_
#include "fpc.h"
// Files includes
//#include "delay.h"
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Hardware_Abstract_Layer
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup WWDG
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup WWDG_Exported_Functions
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @brief delay nTime ms
/// @note get x times.
/// @param nTime nTime ms.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief Setup the GPIO port clock
/// @note This function should affected by chip version.
/// @param GPIOx : Select GPIO port.
/// @param NewState : Enable or disable the GPIO clock.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void Wwdg_reset_ON(u8 ucTcnt, u8 ucWcnt)
{
// WWDG configuration
// Enable WWDG clock
RCC_APB1PeriphClockCmd(RCC_APB1ENR_WWDG, ENABLE);
//WWDG_Prescaler_x,x?1,2,4,8,WWDG counter clock = (PCLK1/4096)/x
WWDG_SetPrescaler(WWDG_Prescaler_8);
WWDG_SetWindowValue(ucWcnt);
// Enable WWDG and set counter value from 0x40 to 0x7F
// Enable WWDG and set counter value to 127, WWDG timeout = ~683 us * 64 = 43.7 ms
//In this case the refresh window is: ~683 * (127-80)= 32.1ms < refresh window < ~683 * 64 = 43.7ms
WWDG_Enable(ucTcnt);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Setup the GPIO port clock
/// @note This function should affected by chip version.
/// @param GPIOx : Select GPIO port.
/// @param NewState : Enable or disable the GPIO clock.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void Wwdg_irq_ON(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = WWDG_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
RCC_APB1PeriphClockCmd(RCC_APB1ENR_WWDG, ENABLE);
WWDG_SetWindowValue(0x70);
WWDG_EnableIT();
//Here is the configuration. The parameter value must be less than the
//window value, otherwise the reset will occur immediately.
WWDG_Enable(0x66);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Setup the GPIO port clock
/// @note This function should affected by chip version.
/// @param GPIOx : Select GPIO port.
/// @param NewState : Enable or disable the GPIO clock.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void WWDG_IRQHandler (void)
{
if(WWDG_GetFlagStatus()) {
WWDG_ClearFlag();
WWDG_SetCounter(0x66);
}
}
/// @}
/// @}
/// @}