1 /******************** (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 ********************************************************************************
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 *******************************************************************************/
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32f10x_systick.h"
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)
30 /* SysTick Flag Mask */
31 #define FLAG_Mask ((u8)0x1F)
33 /* Private macro -------------------------------------------------------------*/
34 /* Private variables ---------------------------------------------------------*/
35 /* Private function prototypes -----------------------------------------------*/
36 /* Private functions ---------------------------------------------------------*/
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.
49 *******************************************************************************/
50 void SysTick_CLKSourceConfig(u32 SysTick_CLKSource)
52 /* Check the parameters */
53 assert(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
55 if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
57 SysTick->CTRL |= SysTick_CLKSource_HCLK;
61 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
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.
72 *******************************************************************************/
73 void SysTick_SetReload(u32 Reload)
75 /* Check the parameters */
76 assert(IS_SYSTICK_RELOAD(Reload));
78 SysTick->LOAD = Reload;
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
91 *******************************************************************************/
92 void SysTick_CounterCmd(u32 SysTick_Counter)
94 /* Check the parameters */
95 assert(IS_SYSTICK_COUNTER(SysTick_Counter));
97 if (SysTick_Counter == SysTick_Counter_Clear)
99 SysTick->VAL = SysTick_Counter_Clear;
103 if (SysTick_Counter == SysTick_Counter_Enable)
105 SysTick->CTRL |= SysTick_Counter_Enable;
109 SysTick->CTRL &= SysTick_Counter_Disable;
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.
121 *******************************************************************************/
122 void SysTick_ITConfig(FunctionalState NewState)
124 /* Check the parameters */
125 assert(IS_FUNCTIONAL_STATE(NewState));
127 if (NewState != DISABLE)
129 SysTick->CTRL |= CTRL_TICKINT_Set;
133 SysTick->CTRL &= CTRL_TICKINT_Reset;
137 /*******************************************************************************
138 * Function Name : SysTick_GetCounter
139 * Description : Gets SysTick counter value.
142 * Return : SysTick current value
143 *******************************************************************************/
144 u32 SysTick_GetCounter(void)
146 return(SysTick->VAL);
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
159 *******************************************************************************/
160 FlagStatus SysTick_GetFlagStatus(u8 SysTick_FLAG)
164 FlagStatus bitstatus = RESET;
166 /* Check the parameters */
167 assert(IS_SYSTICK_FLAG(SysTick_FLAG));
169 /* Get the SysTick register index */
170 tmp = SysTick_FLAG >> 5;
172 if (tmp == 1) /* The flag to check is in CTRL register */
174 statusreg = SysTick->CTRL;
176 else /* The flag to check is in CALIB register */
178 statusreg = SysTick->CALIB;
181 /* Get the flag position */
182 tmp = SysTick_FLAG & FLAG_Mask;
184 if ((statusreg & ((u32)1 << tmp)) != (u32)RESET)
195 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/