OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_STR75x_IAR/] [STLibrary/] [src/] [75x_wdg.c] - Blame information for rev 577

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2
* File Name          : 75x_wdg.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 03/10/2006
5
* Description        : This file provides all the WDG software functions.
6
********************************************************************************
7
* History:
8
* 07/17/2006 : V1.0
9
* 03/10/2006 : V0.1
10
********************************************************************************
11
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
13
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
14
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
15
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
16
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17
*******************************************************************************/
18
 
19
/* Includes ------------------------------------------------------------------*/
20
#include "75x_wdg.h"
21
 
22
/* Private typedef -----------------------------------------------------------*/
23
/* Private define ------------------------------------------------------------*/
24
/* Private macro -------------------------------------------------------------*/
25
/* Private variables ---------------------------------------------------------*/
26
/* Registers reset value */
27
#define WDG_Preload_Mask     0xFFFF
28
#define WDG_Prescaler_Mask   0xFF
29
 
30
/* WDG Start/Stop counter */
31
#define WDG_Counter_Start_Mask  0x0002
32
#define WDG_Counter_Stop_Mask   0xFFFD
33
 
34
/* WDG Sequence */
35
#define WDG_KeyValue1_Mask      0xA55A
36
#define WDG_KeyValue2_Mask      0x5AA5
37
 
38
/* Private function prototypes -----------------------------------------------*/
39
/* Private functions ---------------------------------------------------------*/
40
 
41
/******************************************************************************
42
* Function Name  : WDG_DeInit
43
* Description    : Deinitializes the WDG peripheral registers to their default
44
*                  reset values.
45
* Input          : None
46
* Output         : None
47
* Return         : None
48
*******************************************************************************/
49
void WDG_DeInit(void)
50
{
51
  /* Reset all the WDG registers */
52
  WDG->CR = 0x0000;
53
  WDG->PR = 0x00FF;
54
  WDG->VR = 0xFFFF;
55
  WDG->CNT = 0xFFFF;
56
  WDG->SR = 0x0000;
57
  WDG->MR = 0x0000;
58
  WDG->KR = 0x0000;
59
}
60
 
61
/*******************************************************************************
62
* Function Name  : WDG_Init
63
* Description    : Initializes WDG  peripheral according to the specified
64
*                  parameters in the WDG_InitStruct.
65
* Input          : WDG_InitStruct: pointer to a WDG_InitTypeDef structure that
66
*                  contains the configuration information for the WDG peripheral.
67
* Output         : None
68
* Return         : None
69
*******************************************************************************/
70
void WDG_Init(WDG_InitTypeDef* WDG_InitStruct)
71
{
72
  /* Configure WDG Prescaler register value */
73
  WDG->PR = WDG_InitStruct->WDG_Prescaler;
74
 
75
  /* Configure WDG Pre-load register value */
76
  WDG->VR = WDG_InitStruct->WDG_Preload ;
77
 
78
  if(WDG_InitStruct->WDG_Mode == WDG_Mode_WDG)
79
  {
80
    /* Select WDG mode */
81
    WDG->CR |= WDG_Mode_WDG ;
82
  }
83
  else
84
  {
85
    /* Select Timer mode */
86
    WDG->CR &= WDG_Mode_Timer;
87
  }
88
}
89
 
90
/*******************************************************************************
91
* Function Name  : WDG_StructInit
92
* Description    : Fills each WDG_InitStruct member with its default value.
93
* Input          : WDG_InitStruct : pointer to a WDG_InitTypeDef structure
94
*                  which will be initialized.
95
* Output         : None
96
* Return         : None
97
*******************************************************************************/
98
void WDG_StructInit(WDG_InitTypeDef *WDG_InitStruct)
99
{
100
  /* Initialize mode */
101
  WDG_InitStruct->WDG_Mode = WDG_Mode_Timer;
102
 
103
  /* Initialize Preload */
104
  WDG_InitStruct->WDG_Preload = WDG_Preload_Mask ;
105
 
106
  /* Initialize Prescaler */
107
  WDG_InitStruct->WDG_Prescaler = WDG_Prescaler_Mask;
108
}
109
 
110
/*******************************************************************************
111
* Function Name  : WDG_Cmd
112
* Description    : Enables or disables the WDG peripheral.
113
* Input          : NewState: new state of the WDG peripheral.
114
*                  This parameter can be: ENABLE or DISABLE.
115
* Output         : None
116
* Return         : None
117
*******************************************************************************/
118
void WDG_Cmd(FunctionalState NewState)
119
{
120
  if((WDG->CR & WDG_Mode_WDG) == 0)
121
  {
122
    /* Timer mode */
123
    if(NewState == ENABLE)
124
    {
125
      /* Start timer by setting SC bit in Control register */
126
      WDG->CR |= WDG_Counter_Start_Mask;
127
    }
128
    else
129
    {
130
      /* Stop timer by clearing SC bit in Control register */
131
      WDG->CR &= WDG_Counter_Stop_Mask;
132
    }
133
  }
134
  else
135
  {
136
    /* Watchdog mode */
137
    if(NewState == ENABLE)
138
    {
139
      WDG->KR = WDG_KeyValue1_Mask;
140
      WDG->KR = WDG_KeyValue2_Mask;
141
    }
142
  }
143
}
144
 
145
/*******************************************************************************
146
* Function Name  : WDG_ITConfig
147
* Description    : Enables or disables the WDG End of Count(EC) interrupt.
148
* Input          : Newstate:  new state of the WDG End of Count(EC) interrupt.
149
*                  This parameter can be: ENABLE or DISABLE.
150
* Output         : None
151
* Return         : None
152
*******************************************************************************/
153
void WDG_ITConfig(FunctionalState NewState)
154
{
155
  if(NewState == ENABLE)
156
  {
157
    /* Enable the End of Count interrupt */
158
    WDG->MR |= WDG_IT_EC;
159
  }
160
  else
161
  {
162
    /* Disable the End of Count interrupt */
163
    WDG->MR &= ~WDG_IT_EC;
164
  }
165
}
166
 
167
/*******************************************************************************
168
* Function Name  : WDG_GetCounter
169
* Description    : Gets the WDG’s current counter value.
170
* Input          : None
171
* Output         : None
172
* Return         : The WDG current counter value
173
*******************************************************************************/
174
u16 WDG_GetCounter(void)
175
{
176
   return WDG->CNT;
177
}
178
 
179
/*******************************************************************************
180
* Function Name  : WDG_GetFlagStatus
181
* Description    : Checks whether the WDG End of Count(EC) flag is set or not.
182
* Input          : None
183
* Output         : None
184
* Return         : The new state of WDG End of Count(EC) flag (SET or RESET).
185
*******************************************************************************/
186
FlagStatus WDG_GetFlagStatus(void)
187
{
188
  if((WDG->SR & WDG_FLAG_EC) != RESET )
189
  {
190
    return SET;
191
  }
192
  else
193
  {
194
    return RESET;
195
  }
196
}
197
 
198
/*******************************************************************************
199
* Function Name  : WDG_ClearFlag
200
* Description    : Clears the WDG’s End of Count(EC) pending flag.
201
* Input          : None
202
* Output         : None
203
* Return         : None
204
*******************************************************************************/
205
void WDG_ClearFlag(void)
206
{
207
  /* Clear the EC pending bit */
208
  WDG->SR &= ~WDG_FLAG_EC;
209
}
210
 
211
/*******************************************************************************
212
* Function Name  : WDG_GetITStatus
213
* Description    : Checks whether the WDG End of Count(EC) interrupt has
214
*                  occurred or not.
215
* Input          : None
216
* Output         : None
217
* Return         : The new state of WDG End of Count(EC) interrupt (SET or RESET).
218
*******************************************************************************/
219
ITStatus WDG_GetITStatus(void)
220
{
221
  if(((WDG->SR & WDG_IT_EC) != RESET )&&((WDG->MR & WDG_IT_EC) != RESET ))
222
  {
223
    return SET;
224
  }
225
  else
226
  {
227
    return RESET;
228
  }
229
}
230
 
231
/*******************************************************************************
232
* Function Name  : WDG_ClearITPendingBit
233
* Description    : Clears the WDG's End of Count(EC) interrupt pending bit.
234
* Input          : None
235
* Output         : None
236
* Return         : None
237
*******************************************************************************/
238
void WDG_ClearITPendingBit(void)
239
{
240
 /* Clear the EC pending bit */
241
  WDG->SR &= ~WDG_IT_EC;
242
}
243
 
244
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.