CC23x0R5DriverLibrary
systick.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: systick.h
3  *
4  * Description: Prototypes for the SysTick driver.
5  *
6  * Copyright (c) 2022 Texas Instruments Incorporated
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1) Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2) Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3) Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ******************************************************************************/
35 
36 #ifndef __SYSTICK_H__
37 #define __SYSTICK_H__
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 //*****************************************************************************
49 //
50 // If building with a C++ compiler, make all of the definitions in this header
51 // have a C binding.
52 //
53 //*****************************************************************************
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #include <stdbool.h>
59 #include <stdint.h>
60 #include "../inc/hw_types.h"
61 #include "../inc/hw_ints.h"
62 #include "../inc/hw_memmap.h"
63 #include "../inc/hw_systick.h"
64 #include "debug.h"
65 #include "interrupt.h"
66 
67 //*****************************************************************************
68 //
69 // API Functions and Prototypes
70 //
71 //*****************************************************************************
72 
73 //*****************************************************************************
74 //
89 //
90 //*****************************************************************************
92 {
93  // Enable SysTick.
94  HWREG(SYSTICK_BASE + SYSTICK_O_CSR) |= (SYSTICK_CSR_CLKSOURCE | SYSTICK_CSR_ENABLE);
95 }
96 
97 //*****************************************************************************
98 //
105 //
106 //*****************************************************************************
108 {
109  // Disable SysTick.
110  HWREG(SYSTICK_BASE + SYSTICK_O_CSR) &= ~(SYSTICK_CSR_ENABLE);
111 }
112 
113 //*****************************************************************************
114 //
129 //
130 //*****************************************************************************
131 __STATIC_INLINE void SysTickRegisterInt(void (*pfnHandler)(void))
132 {
133  // Register the interrupt handler, returning an error if an error occurs.
134  IntRegister(INT_SYSTICK, pfnHandler);
135 
136  // Enable the SysTick interrupt.
137  HWREG(SYSTICK_BASE + SYSTICK_O_CSR) |= SYSTICK_CSR_TICKINT;
138 }
139 
140 //*****************************************************************************
141 //
151 //
152 //*****************************************************************************
154 {
155  // Disable the SysTick interrupt.
156  HWREG(SYSTICK_BASE + SYSTICK_O_CSR) &= ~(SYSTICK_CSR_TICKINT);
157 
158  // Unregister the interrupt handler.
159  IntUnregister(INT_SYSTICK);
160 }
161 
162 //*****************************************************************************
163 //
174 //
175 //*****************************************************************************
177 {
178  // Enable the SysTick interrupt.
179  HWREG(SYSTICK_BASE + SYSTICK_O_CSR) |= SYSTICK_CSR_TICKINT;
180 }
181 
182 //*****************************************************************************
183 //
190 //
191 //*****************************************************************************
193 {
194  // Disable the SysTick interrupt.
195  HWREG(SYSTICK_BASE + SYSTICK_O_CSR) &= ~(SYSTICK_CSR_TICKINT);
196 }
197 
198 //*****************************************************************************
199 //
206 
216 //
217 //*****************************************************************************
218 __STATIC_INLINE void SysTickSetPeriod(uint32_t period)
219 {
220  // Check the arguments.
221  ASSERT((period > 0) && (period <= 16777216));
222 
223  // Set the period of the SysTick counter.
224  HWREG(SYSTICK_BASE + SYSTICK_O_RVR) = period - 1;
225 }
226 
227 //*****************************************************************************
228 //
235 //
236 //*****************************************************************************
238 {
239  // Return the period of the SysTick counter.
240  return (HWREG(SYSTICK_BASE + SYSTICK_O_RVR) + 1);
241 }
242 
243 //*****************************************************************************
244 //
251 //
252 //*****************************************************************************
254 {
255  // Return the current value of the SysTick counter.
256  return (HWREG(SYSTICK_BASE + SYSTICK_O_CVR));
257 }
258 
259 //*****************************************************************************
260 //
261 // Mark the end of the C bindings section for C++ compilers.
262 //
263 //*****************************************************************************
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 //*****************************************************************************
269 //
273 //
274 //*****************************************************************************
275 
276 #endif // __SYSTICK_H__
__STATIC_INLINE uint32_t SysTickGetPeriod(void)
Gets the period of the SysTick counter.
Definition: systick.h:237
__STATIC_INLINE void SysTickDisableInt(void)
Disables the SysTick interrupt.
Definition: systick.h:192
__STATIC_INLINE void SysTickUnregisterInt(void)
Unregisters the interrupt handler for the SysTick interrupt in the dynamic interrupt table...
Definition: systick.h:153
__STATIC_INLINE void SysTickDisable(void)
Disables the SysTick counter.
Definition: systick.h:107
__STATIC_INLINE void SysTickEnableInt(void)
Enables the SysTick interrupt.
Definition: systick.h:176
#define ASSERT(expr)
Definition: debug.h:71
__STATIC_INLINE uint32_t SysTickGetValue(void)
Gets the current value of the SysTick counter.
Definition: systick.h:253
__STATIC_INLINE void SysTickEnable(void)
Enables the SysTick counter.
Definition: systick.h:91
void IntUnregister(uint32_t intNum)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:124
void IntRegister(uint32_t intNum, void(*handler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
__STATIC_INLINE void SysTickSetPeriod(uint32_t period)
Sets the period of the SysTick counter.
Definition: systick.h:218
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
__STATIC_INLINE void SysTickRegisterInt(void(*pfnHandler)(void))
Registers an interrupt handler for the SysTick interrupt in the dynamic interrupt table...
Definition: systick.h:131