1 |
582 |
jeremybenn |
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
2 |
|
|
* File Name : stm32f10x_systick.c
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Date First Issued : 09/29/2006
|
5 |
|
|
* Description : This file provides all the SysTick 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_systick.h"
|
22 |
|
|
|
23 |
|
|
/* Private typedef -----------------------------------------------------------*/
|
24 |
|
|
/* Private define ------------------------------------------------------------*/
|
25 |
|
|
/* ---------------------- SysTick registers bit mask -------------------- */
|
26 |
|
|
/* CTRL TICKINT Mask */
|
27 |
|
|
#define CTRL_TICKINT_Set ((u32)0x00000002)
|
28 |
|
|
#define CTRL_TICKINT_Reset ((u32)0xFFFFFFFD)
|
29 |
|
|
|
30 |
|
|
/* SysTick Flag Mask */
|
31 |
|
|
#define FLAG_Mask ((u8)0x1F)
|
32 |
|
|
|
33 |
|
|
/* Private macro -------------------------------------------------------------*/
|
34 |
|
|
/* Private variables ---------------------------------------------------------*/
|
35 |
|
|
/* Private function prototypes -----------------------------------------------*/
|
36 |
|
|
/* Private functions ---------------------------------------------------------*/
|
37 |
|
|
|
38 |
|
|
/*******************************************************************************
|
39 |
|
|
* Function Name : SysTick_CLKSourceConfig
|
40 |
|
|
* Description : Configures the SysTick clock source.
|
41 |
|
|
* Input : - SysTick_CLKSource: specifies the SysTick clock source.
|
42 |
|
|
* This parameter can be one of the following values:
|
43 |
|
|
* - SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8
|
44 |
|
|
* selected as SysTick clock source.
|
45 |
|
|
* - SysTick_CLKSource_HCLK: AHB clock selected as
|
46 |
|
|
* SysTick clock source.
|
47 |
|
|
* Output : None
|
48 |
|
|
* Return : None
|
49 |
|
|
*******************************************************************************/
|
50 |
|
|
void SysTick_CLKSourceConfig(u32 SysTick_CLKSource)
|
51 |
|
|
{
|
52 |
|
|
/* Check the parameters */
|
53 |
|
|
assert(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
|
54 |
|
|
|
55 |
|
|
if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
|
56 |
|
|
{
|
57 |
|
|
SysTick->CTRL |= SysTick_CLKSource_HCLK;
|
58 |
|
|
}
|
59 |
|
|
else
|
60 |
|
|
{
|
61 |
|
|
SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/*******************************************************************************
|
66 |
|
|
* Function Name : SysTick_SetReload
|
67 |
|
|
* Description : Sets SysTick Reload value.
|
68 |
|
|
* Input : - Reload: SysTick Reload new value.
|
69 |
|
|
* This parameter must be a number between 1 and 0xFFFFFF.
|
70 |
|
|
* Output : None
|
71 |
|
|
* Return : None
|
72 |
|
|
*******************************************************************************/
|
73 |
|
|
void SysTick_SetReload(u32 Reload)
|
74 |
|
|
{
|
75 |
|
|
/* Check the parameters */
|
76 |
|
|
assert(IS_SYSTICK_RELOAD(Reload));
|
77 |
|
|
|
78 |
|
|
SysTick->LOAD = Reload;
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
/*******************************************************************************
|
82 |
|
|
* Function Name : SysTick_CounterCmd
|
83 |
|
|
* Description : Enables or disables the SysTick counter.
|
84 |
|
|
* Input : - SysTick_Counter: new state of the SysTick counter.
|
85 |
|
|
* This parameter can be one of the following values:
|
86 |
|
|
* - SysTick_Counter_Disable: Disable counter
|
87 |
|
|
* - SysTick_Counter_Enable: Enable counter
|
88 |
|
|
* - SysTick_Counter_Clear: Clear counter value to 0
|
89 |
|
|
* Output : None
|
90 |
|
|
* Return : None
|
91 |
|
|
*******************************************************************************/
|
92 |
|
|
void SysTick_CounterCmd(u32 SysTick_Counter)
|
93 |
|
|
{
|
94 |
|
|
/* Check the parameters */
|
95 |
|
|
assert(IS_SYSTICK_COUNTER(SysTick_Counter));
|
96 |
|
|
|
97 |
|
|
if (SysTick_Counter == SysTick_Counter_Clear)
|
98 |
|
|
{
|
99 |
|
|
SysTick->VAL = SysTick_Counter_Clear;
|
100 |
|
|
}
|
101 |
|
|
else
|
102 |
|
|
{
|
103 |
|
|
if (SysTick_Counter == SysTick_Counter_Enable)
|
104 |
|
|
{
|
105 |
|
|
SysTick->CTRL |= SysTick_Counter_Enable;
|
106 |
|
|
}
|
107 |
|
|
else
|
108 |
|
|
{
|
109 |
|
|
SysTick->CTRL &= SysTick_Counter_Disable;
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/*******************************************************************************
|
115 |
|
|
* Function Name : SysTick_ITConfig
|
116 |
|
|
* Description : Enables or disables the SysTick Interrupt.
|
117 |
|
|
* Input : - NewState: new state of the SysTick Interrupt.
|
118 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
119 |
|
|
* Output : None
|
120 |
|
|
* Return : None
|
121 |
|
|
*******************************************************************************/
|
122 |
|
|
void SysTick_ITConfig(FunctionalState NewState)
|
123 |
|
|
{
|
124 |
|
|
/* Check the parameters */
|
125 |
|
|
assert(IS_FUNCTIONAL_STATE(NewState));
|
126 |
|
|
|
127 |
|
|
if (NewState != DISABLE)
|
128 |
|
|
{
|
129 |
|
|
SysTick->CTRL |= CTRL_TICKINT_Set;
|
130 |
|
|
}
|
131 |
|
|
else
|
132 |
|
|
{
|
133 |
|
|
SysTick->CTRL &= CTRL_TICKINT_Reset;
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
/*******************************************************************************
|
138 |
|
|
* Function Name : SysTick_GetCounter
|
139 |
|
|
* Description : Gets SysTick counter value.
|
140 |
|
|
* Input : None
|
141 |
|
|
* Output : None
|
142 |
|
|
* Return : SysTick current value
|
143 |
|
|
*******************************************************************************/
|
144 |
|
|
u32 SysTick_GetCounter(void)
|
145 |
|
|
{
|
146 |
|
|
return(SysTick->VAL);
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
/*******************************************************************************
|
150 |
|
|
* Function Name : SysTick_GetFlagStatus
|
151 |
|
|
* Description : Checks whether the specified SysTick flag is set or not.
|
152 |
|
|
* Input : - SysTick_FLAG: specifies the flag to check.
|
153 |
|
|
* This parameter can be one of the following values:
|
154 |
|
|
* - SysTick_FLAG_COUNT
|
155 |
|
|
* - SysTick_FLAG_SKEW
|
156 |
|
|
* - SysTick_FLAG_NOREF
|
157 |
|
|
* Output : None
|
158 |
|
|
* Return : None
|
159 |
|
|
*******************************************************************************/
|
160 |
|
|
FlagStatus SysTick_GetFlagStatus(u8 SysTick_FLAG)
|
161 |
|
|
{
|
162 |
|
|
u32 tmp = 0;
|
163 |
|
|
u32 statusreg = 0;
|
164 |
|
|
FlagStatus bitstatus = RESET;
|
165 |
|
|
|
166 |
|
|
/* Check the parameters */
|
167 |
|
|
assert(IS_SYSTICK_FLAG(SysTick_FLAG));
|
168 |
|
|
|
169 |
|
|
/* Get the SysTick register index */
|
170 |
|
|
tmp = SysTick_FLAG >> 5;
|
171 |
|
|
|
172 |
|
|
if (tmp == 1) /* The flag to check is in CTRL register */
|
173 |
|
|
{
|
174 |
|
|
statusreg = SysTick->CTRL;
|
175 |
|
|
}
|
176 |
|
|
else /* The flag to check is in CALIB register */
|
177 |
|
|
{
|
178 |
|
|
statusreg = SysTick->CALIB;
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
/* Get the flag position */
|
182 |
|
|
tmp = SysTick_FLAG & FLAG_Mask;
|
183 |
|
|
|
184 |
|
|
if ((statusreg & ((u32)1 << tmp)) != (u32)RESET)
|
185 |
|
|
{
|
186 |
|
|
bitstatus = SET;
|
187 |
|
|
}
|
188 |
|
|
else
|
189 |
|
|
{
|
190 |
|
|
bitstatus = RESET;
|
191 |
|
|
}
|
192 |
|
|
return bitstatus;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|