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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32F103_Keil/] [STM32F10xFWLib/] [src/] [stm32f10x_wwdg.c] - Blame information for rev 582

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 jeremybenn
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
2
* File Name          : stm32f10x_wwdg.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 09/29/2006
5
* Description        : This file provides all the WWDG firmware functions.
6
********************************************************************************
7
* History:
8
* 04/02/2007: V0.2
9
* 02/05/2007: V0.1
10
* 09/29/2006: V0.01
11
********************************************************************************
12
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
15
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
16
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
17
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
19
 
20
/* Includes ------------------------------------------------------------------*/
21
#include "stm32f10x_wwdg.h"
22
#include "stm32f10x_rcc.h"
23
 
24
/* Private typedef -----------------------------------------------------------*/
25
/* Private define ------------------------------------------------------------*/
26
/* ----------- WWDG registers bit address in the alias region ----------- */
27
#define WWDG_OFFSET       (WWDG_BASE - PERIPH_BASE)
28
 
29
/* Alias word address of EWI bit */
30
#define CFR_OFFSET        (WWDG_OFFSET + 0x04)
31
#define EWI_BitNumber     0x09
32
#define CFR_EWI_BB        (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
33
 
34
/* Alias word address of EWIF bit */
35
#define SR_OFFSET         (WWDG_OFFSET + 0x08)
36
#define EWIF_BitNumber    0x00
37
#define SR_EWIF_BB        (PERIPH_BB_BASE + (SR_OFFSET * 32) + (EWIF_BitNumber * 4))
38
 
39
/* --------------------- WWDG registers bit mask ------------------------ */
40
/* CR register bit mask */
41
#define CR_WDGA_Set       ((u32)0x00000080)
42
 
43
/* CFR register bit mask */
44
#define CFR_WDGTB_Mask    ((u32)0xFFFFFE7F)
45
#define CFR_W_Mask        ((u32)0xFFFFFF80)
46
 
47
#define BIT_Mask          ((u8)0x7F)
48
 
49
/* Private macro -------------------------------------------------------------*/
50
/* Private variables ---------------------------------------------------------*/
51
/* Private function prototypes -----------------------------------------------*/
52
/* Private functions ---------------------------------------------------------*/
53
 
54
/*******************************************************************************
55
* Function Name  : WWDG_DeInit
56
* Description    : Deinitializes the WWDG  peripheral registers to their default
57
*                  reset values.
58
* Input          : None
59
* Output         : None
60
* Return         : None
61
*******************************************************************************/
62
void WWDG_DeInit(void)
63
{
64
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
65
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
66
}
67
 
68
/*******************************************************************************
69
* Function Name  : WWDG_SetPrescaler
70
* Description    : Sets the WWDG Prescaler.
71
* Input          : - WWDG_Prescaler: specifies the WWDG Prescaler.
72
*                    This parameter can be one of the following values:
73
*                       - WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
74
*                       - WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
75
*                       - WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
76
*                       - WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
77
* Output         : None
78
* Return         : None
79
*******************************************************************************/
80
void WWDG_SetPrescaler(u32 WWDG_Prescaler)
81
{
82
  u32 tmpreg = 0;
83
 
84
  /* Check the parameters */
85
  assert(IS_WWDG_PRESCALER(WWDG_Prescaler));
86
 
87
  /* Clear WDGTB[8:7] bits */
88
  tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
89
 
90
  /* Set WDGTB[8:7] bits according to WWDG_Prescaler value */
91
  tmpreg |= WWDG_Prescaler;
92
 
93
  /* Store the new value */
94
  WWDG->CFR = tmpreg;
95
}
96
 
97
/*******************************************************************************
98
* Function Name  : WWDG_SetWindowValue
99
* Description    : Sets the WWDG window value.
100
* Input          : - WindowValue: specifies the window value to be compared to
101
*                    the downcounter.
102
*                    This parameter value must be lower than 0x80.
103
* Output         : None
104
* Return         : None
105
*******************************************************************************/
106
void WWDG_SetWindowValue(u8 WindowValue)
107
{
108
  u32 tmpreg = 0;
109
 
110
  /* Check the parameters */
111
  assert(IS_WWDG_WINDOW_VALUE(WindowValue));
112
 
113
  /* Clear W[6:0] bits */
114
  tmpreg = WWDG->CFR & CFR_W_Mask;
115
 
116
  /* Set W[6:0] bits according to WindowValue value */
117
  tmpreg |= WindowValue & BIT_Mask;
118
 
119
  /* Store the new value */
120
  WWDG->CFR = tmpreg;
121
}
122
 
123
/*******************************************************************************
124
* Function Name  : WWDG_EnableIT
125
* Description    : Enables the WWDG Early Wakeup interrupt(EWI).
126
* Input          : None
127
* Output         : None
128
* Return         : None
129
*******************************************************************************/
130
void WWDG_EnableIT(void)
131
{
132
  *(vu32 *) CFR_EWI_BB = (u32)ENABLE;
133
}
134
 
135
/*******************************************************************************
136
* Function Name  : WWDG_SetCounter
137
* Description    : Sets the WWDG counter value.
138
* Input          : - Counter: specifies the watchdog counter value.
139
*                    This parameter must be a number between 0x40 and 0x7F.
140
* Output         : None
141
* Return         : None
142
*******************************************************************************/
143
void WWDG_SetCounter(u8 Counter)
144
{
145
  /* Check the parameters */
146
  assert(IS_WWDG_COUNTER(Counter));
147
 
148
  /* Write to T[6:0] bits to configure the counter value, no need to do
149
     a read-modify-write; writing a 0 to WDGA bit does nothing */
150
  WWDG->CR = Counter & BIT_Mask;
151
}
152
 
153
/*******************************************************************************
154
* Function Name  : WWDG_Enable
155
* Description    : Enables WWDG and load the counter value.
156
*                  - Counter: specifies the watchdog counter value.
157
*                    This parameter must be a number between 0x40 and 0x7F.
158
* Input          : None
159
* Output         : None
160
* Return         : None
161
*******************************************************************************/
162
void WWDG_Enable(u8 Counter)
163
{
164
  /* Check the parameters */
165
  assert(IS_WWDG_COUNTER(Counter));
166
 
167
  WWDG->CR = CR_WDGA_Set | Counter;
168
}
169
 
170
/*******************************************************************************
171
* Function Name  : WWDG_GetFlagStatus
172
* Description    : Checks whether the Early Wakeup interrupt flag is set or not.
173
* Input          : None
174
* Output         : None
175
* Return         : The new state of the Early Wakeup interrupt flag (SET or RESET)
176
*******************************************************************************/
177
FlagStatus WWDG_GetFlagStatus(void)
178
{
179
  return (FlagStatus)(*(vu32 *) SR_EWIF_BB);
180
}
181
 
182
/*******************************************************************************
183
* Function Name  : WWDG_ClearFlag
184
* Description    : Clears Early Wakeup interrupt flag.
185
* Input          : None
186
* Output         : None
187
* Return         : None
188
*******************************************************************************/
189
void WWDG_ClearFlag(void)
190
{
191
  WWDG->SR = (u32)RESET;
192
}
193
 
194
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

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