Contiki 3.x
stm32w-systick.c
1 /**
2  * \addtogroup stm32w-cpu
3  *
4  * @{
5  */
6 
7 /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
8 * File Name : stm32w108_systick.c
9 * Author : MCD Application Team
10 * Version : V2.0.3
11 * Date : 09/22/2008
12 * Description : This file provides all the SysTick firmware functions.
13 ********************************************************************************
14 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
15 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
16 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
17 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
18 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
19 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
20 *******************************************************************************/
21 
22 #include <stdint.h>
23 #include "stm32w-systick.h"
24 
25 /* SysTick registers bit mask */
26 /* CTRL TICKINT Mask */
27 #define CTRL_TICKINT_Set ((uint32_t)0x00000002)
28 #define CTRL_TICKINT_Reset ((uint32_t)0xFFFFFFFD)
29 /*--------------------------------------------------------------------------*/
30 /**
31  * \brief Configures the SysTick clock source.
32  * \param SysTick_CLKSource specifies the SysTick clock source.
33  * This parameter can be one of the following values:
34  * SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8
35  * selected as SysTick clock source.
36  * SysTick_CLKSource_HCLK: AHB clock selected as
37  * SysTick clock source.
38  */
39 void
40 SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
41 {
42  /* Check the parameters */
43  assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
44 
45  if(SysTick_CLKSource == SysTick_CLKSource_HCLK) {
46  SysTick->CTRL |= SysTick_CLKSource_HCLK;
47  } else {
48  SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
49  }
50 }
51 /*--------------------------------------------------------------------------*/
52 /**
53  * \brief Sets SysTick Reload value.
54  * \param Reload SysTick Reload new value. Must be between 1 and 0xFFFFFF.
55  */
56 void
57 SysTick_SetReload(uint32_t Reload)
58 {
59  /* Check the parameters */
60  assert_param(IS_SYSTICK_RELOAD(Reload));
61  SysTick->LOAD = Reload;
62 }
63 /*--------------------------------------------------------------------------*/
64 /**
65  * \brief Enables or disables the SysTick counter.
66  * \param SysTick_Counter new state of the SysTick counter.
67 * This parameter can be one of the following values:
68 * - SysTick_Counter_Disable: Disable counter
69 * - SysTick_Counter_Enable: Enable counter
70 * - SysTick_Counter_Clear: Clear counter value to 0
71  */
72 void
73 SysTick_CounterCmd(uint32_t SysTick_Counter)
74 {
75  /* Check the parameters */
76  assert_param(IS_SYSTICK_COUNTER(SysTick_Counter));
77 
78  if(SysTick_Counter == SysTick_Counter_Enable) {
79  SysTick->CTRL |= SysTick_Counter_Enable;
80  } else if(SysTick_Counter == SysTick_Counter_Disable) {
81  SysTick->CTRL &= SysTick_Counter_Disable;
82  } else { /* SysTick_Counter == SysTick_Counter_Clear */
83  SysTick->VAL = SysTick_Counter_Clear;
84  }
85 }
86 /*--------------------------------------------------------------------------*/
87 /**
88  * \brief Enables or disables the SysTick Interrupt.
89  * \param NewState new state of the SysTick Interrupt.
90 * This parameter can be: ENABLE or DISABLE.
91  */
92 void
93 SysTick_ITConfig(FunctionalState NewState)
94 {
95  /* Check the parameters */
96  assert_param(IS_FUNCTIONAL_STATE(NewState));
97 
98  if(NewState != DISABLE) {
99  SysTick->CTRL |= CTRL_TICKINT_Set;
100  } else {
101  SysTick->CTRL &= CTRL_TICKINT_Reset;
102  }
103 }
104 /*--------------------------------------------------------------------------*/
105 /**
106  * \brief Gets SysTick counter value.
107  * \return SysTick current value
108  */
109 uint32_t
111 {
112  return (SysTick->VAL);
113 }
114 /*--------------------------------------------------------------------------*/
115 /**
116  * \brief Checks whether the specified SysTick flag is set or not.
117  * \param SysTick_FLAG specifies the flag to check.
118 * This parameter can be one of the following values:
119 * - SysTick_FLAG_COUNT
120 * - SysTick_FLAG_SKEW
121 * - SysTick_FLAG_NOREF
122  */
123 FlagStatus
124 SysTick_GetFlagStatus(uint8_t SysTick_FLAG)
125 {
126  uint32_t statusreg = 0, tmp = 0;
127  FlagStatus bitstatus = RESET;
128 
129  /* Check the parameters */
130  assert_param(IS_SYSTICK_FLAG(SysTick_FLAG));
131 
132  /* Get the SysTick register index */
133  tmp = SysTick_FLAG >> 3;
134 
135  if(tmp == 2) { /* The flag to check is in CTRL register */
136  statusreg = SysTick->CTRL;
137  } else { /* The flag to check is in CALIB register */
138 
139  statusreg = SysTick->CALIB;
140  }
141 
142  if((statusreg & ((uint32_t) 1 << SysTick_FLAG)) != (uint32_t) RESET) {
143  bitstatus = SET;
144  } else {
145  bitstatus = RESET;
146  }
147  return bitstatus;
148 }
149 /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
150 /** @} */
#define SysTick
Definition: core_cm0.h:495
void SysTick_SetReload(uint32_t Reload)
Sets SysTick Reload value.
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
Configures the SysTick clock source.
FlagStatus SysTick_GetFlagStatus(uint8_t SysTick_FLAG)
Checks whether the specified SysTick flag is set or not.
void SysTick_ITConfig(FunctionalState NewState)
Enables or disables the SysTick Interrupt.
void SysTick_CounterCmd(uint32_t SysTick_Counter)
Enables or disables the SysTick counter.
uint32_t SysTick_GetCounter(void)
Gets SysTick counter value.