Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 346 → Rev 347

/tags/V0.26f/libstr91x/src/91x_wdg.c
0,0 → 1,253
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : 91x_wdg.c
* Author : MCD Application Team
* Version : V2.1
* Date : 12/22/2008
* Description : This file provides all the WDG firmware functions.
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
/* Includes ------------------------------------------------------------------*/
#include "91x_wdg.h"
#include "91x_scu.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
 
 
/* WDG End of Count interrupt Flag */
#define WDG_FLAG_EC 0x0001
 
 
/* WDG End of Count interrupt request */
#define WDG_IT_EC 0x0001
 
 
 
/* WDG Start/Stop counter */
#define WDG_Counter_Start 0x0002
#define WDG_Counter_Stop 0xFFFD
 
 
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Registers reset value */
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/*******************************************************************************
* Function Name : WDG_StructInit
* Description : Fills the WDG_InitTypeDef structure member with its reset
* value.
* Input : WDG_InitStruct : pointer to a WDG_InitTypeDef structure
* which will be initialized.
* Output : None
* Return : None
*******************************************************************************/
void WDG_StructInit(WDG_InitTypeDef *WDG_InitStruct)
{
 
/* Select the source clock */
WDG_InitStruct-> WDG_ClockSource = WDG_ClockSource_Apb;
 
/* Initialize Prescaler */
WDG_InitStruct->WDG_Prescaler =0xFF;
 
/* Initialize Preload */
WDG_InitStruct->WDG_Preload =0xFFFF;
 
 
}
 
/*******************************************************************************
* Function Name : WDG_Init
* Description : Initializes WDG peripheral according to the specified
* parameters in the WDG_InitStruct.
* Input : WDG_InitStruct: pointer to a WDG_InitTypeDef structure that
* contains the configuration information for the WDG peripheral.
* Output : None
* Return : None
*******************************************************************************/
void WDG_Init(WDG_InitTypeDef* WDG_InitStruct)
{
 
 
if(WDG_InitStruct->WDG_ClockSource == WDG_ClockSource_Apb)
{
/* Select The APB clock as clock source */
WDG->CR &= WDG_ClockSource_Apb;
}
 
else
{
/* Select the RTC clock as source */
WDG->CR |= WDG_ClockSource_Rtc ;
}
 
/* Configure WDG Prescaler register value */
WDG->PR = WDG_InitStruct->WDG_Prescaler;
 
/* Configure WDG Pre-load register value */
WDG->VR = WDG_InitStruct->WDG_Preload ;
 
}
 
/*******************************************************************************
* Function Name : WDG_TimerModeCmd
* Description : Enables or disables the WDG timer mode
* Input : NewState: new state of the WDG peripheral (Newstate can be
* ENABLE or DISABLE)
* Output : None
* Return : None
*******************************************************************************/
void WDG_TimerModeCmd(FunctionalState NewState)
{
if(NewState == ENABLE)
{
/* Start timer by setting SC bit in Control register */
WDG->CR |= WDG_Counter_Start;
}
else
{
/* Stop timer by clearning SC bit in Control register */
WDG->CR &= WDG_Counter_Stop;
}
}
 
/*******************************************************************************
* Function Name : WDG_StartWatchdogMode
* Description : Starts the watchdog mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void WDG_StartWatchdogMode(void)
{
/*reload watchdog*/
WDG->KR = WDG_KeyValue1;
WDG->KR = WDG_KeyValue2;
/*start watchdog*/
WDG->CR |= WDG_Mode_Wdg;
}
 
/*******************************************************************************
* Function Name : WDG_ITConfig
* Description : Enables or disables the WDG End of Count(EC) interrupt.
* Input : Newstate: new state of the End of Count(EC) WDG interrupt.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void WDG_ITConfig(FunctionalState NewState)
{
if(NewState == ENABLE)
{
/* Enable the End of Count interrupt */
WDG->MR |= WDG_IT_EC;
}
else
{
/* Disable the End of Count interrupt */
WDG->MR &= ~WDG_IT_EC;
}
}
 
/*******************************************************************************
* Function Name : WDG_GetCounter
* Description : Gets the WDG’s current counter value.
* Input : None
* Output : None
* Return : The WDG current counter value
*******************************************************************************/
u16 WDG_GetCounter(void)
{
return WDG->CNT;
}
 
/*******************************************************************************
* Function Name : WDG_GetITStatus
* Description : Checks whether the WDG End of Count(EC) interrupt is occured or not.
* Input : None
* Output : None
* Return : The new state of WDG_IT (SET or RESET).
*******************************************************************************/
ITStatus WDG_GetITStatus(void)
{
if(((WDG->SR & WDG_IT_EC) != RESET )&&((WDG->MR & WDG_IT_EC) != RESET ))
{
return SET;
}
else
{
return RESET;
}
}
 
/*******************************************************************************
* Function Name : WDG_ClearITPendingBit
* Description : Clears the WDG's End of Count(EC) interrupt pending bit.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void WDG_ClearITPendingBit(void)
{
/* Clear the EC pending bit */
WDG->SR &= ~WDG_IT_EC;
 
}
 
/*******************************************************************************
* Function Name : WDG_ClearFlag
* Description : Clears the WDG's End of Count(EC) Flag.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void WDG_ClearFlag(void)
{
/* Clear the EC Flag */
 
WDG->SR &= ~WDG_FLAG_EC;
}
 
/*******************************************************************************
* Function Name : WDG_GetFlagStatus
* Description : Checks whether the WDG End of Count(EC) flag is set or not.
* Input : None
* Output : None
* Return : The new state of the WDG_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus WDG_GetFlagStatus(void)
{
if((WDG->SR & WDG_FLAG_EC) != RESET )
{
return SET;
}
else
{
return RESET;
}
}
 
/*******************************************************************************
* Function Name : WDG_Reload
* Description : reloads the watchdog counter in watchdog mode
* Input : None
* Output : None
* Return : none
*******************************************************************************/
void WDG_Reload(void)
{
WDG->KR = WDG_KeyValue1;
WDG->KR = WDG_KeyValue2;
}
 
 
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/