CC13xx Driver Library
systick.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: systick.h
3 * Revised: 2015-11-16 19:41:47 +0100 (Mon, 16 Nov 2015)
4 * Revision: 45094
5 *
6 * Description: Prototypes for the SysTick driver.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __SYSTICK_H__
49 #define __SYSTICK_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_ints.h>
65 #include <inc/hw_nvic.h>
66 #include <inc/hw_types.h>
67 #include <driverlib/debug.h>
68 #include <driverlib/interrupt.h>
69 
70 //*****************************************************************************
71 //
72 // API Functions and Prototypes
73 //
74 //*****************************************************************************
75 
76 //*****************************************************************************
77 //
92 //
93 //*****************************************************************************
94 __STATIC_INLINE void
96 {
97  //
98  // Enable SysTick.
99  //
100  HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE;
101 }
102 
103 //*****************************************************************************
104 //
111 //
112 //*****************************************************************************
113 __STATIC_INLINE void
115 {
116  //
117  // Disable SysTick.
118  //
119  HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE);
120 }
121 
122 //*****************************************************************************
123 //
135 //
136 //*****************************************************************************
137 __STATIC_INLINE void
138 SysTickIntRegister(void (*pfnHandler)(void))
139 {
140  //
141  // Register the interrupt handler, returning an error if an error occurs.
142  //
143  IntRegister(INT_SYSTICK, pfnHandler);
144 
145  //
146  // Enable the SysTick interrupt.
147  //
148  HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
149 }
150 
151 //*****************************************************************************
152 //
162 //
163 //*****************************************************************************
164 __STATIC_INLINE void
166 {
167  //
168  // Disable the SysTick interrupt.
169  //
170  HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
171 
172  //
173  // Unregister the interrupt handler.
174  //
175  IntUnregister(INT_SYSTICK);
176 }
177 
178 //*****************************************************************************
179 //
190 //
191 //*****************************************************************************
192 __STATIC_INLINE void
194 {
195  //
196  // Enable the SysTick interrupt.
197  //
198  HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
199 }
200 
201 //*****************************************************************************
202 //
209 //
210 //*****************************************************************************
211 __STATIC_INLINE void
213 {
214  //
215  // Disable the SysTick interrupt.
216  //
217  HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
218 }
219 
220 //*****************************************************************************
221 //
237 //
238 //*****************************************************************************
239 __STATIC_INLINE void
240 SysTickPeriodSet(uint32_t ui32Period)
241 {
242  //
243  // Check the arguments.
244  //
245  ASSERT((ui32Period > 0) && (ui32Period <= 16777216));
246 
247  //
248  // Set the period of the SysTick counter.
249  //
250  HWREG(NVIC_ST_RELOAD) = ui32Period - 1;
251 }
252 
253 //*****************************************************************************
254 //
261 //
262 //*****************************************************************************
263 __STATIC_INLINE uint32_t
265 {
266  //
267  // Return the period of the SysTick counter.
268  //
269  return(HWREG(NVIC_ST_RELOAD) + 1);
270 }
271 
272 //*****************************************************************************
273 //
280 //
281 //*****************************************************************************
282 __STATIC_INLINE uint32_t
284 {
285  //
286  // Return the current value of the SysTick counter.
287  //
288  return(HWREG(NVIC_ST_CURRENT));
289 }
290 
291 //*****************************************************************************
292 //
293 // Mark the end of the C bindings section for C++ compilers.
294 //
295 //*****************************************************************************
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif // __SYSTICK_H__
301 
302 //*****************************************************************************
303 //
307 //
308 //*****************************************************************************
static void SysTickDisable(void)
Disables the SysTick counter.
Definition: systick.h:114
static void SysTickPeriodSet(uint32_t ui32Period)
Sets the period of the SysTick counter.
Definition: systick.h:240
static uint32_t SysTickValueGet(void)
Gets the current value of the SysTick counter.
Definition: systick.h:283
static void SysTickIntUnregister(void)
Unregisters the interrupt handler for the SysTick interrupt.
Definition: systick.h:165
static void SysTickIntEnable(void)
Enables the SysTick interrupt.
Definition: systick.h:193
#define ASSERT(expr)
Definition: debug.h:74
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:200
static uint32_t SysTickPeriodGet(void)
Gets the period of the SysTick counter.
Definition: systick.h:264
static void SysTickIntDisable(void)
Disables the SysTick interrupt.
Definition: systick.h:212
static void SysTickEnable(void)
Enables the SysTick counter.
Definition: systick.h:95
static void SysTickIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for the SysTick interrupt.
Definition: systick.h:138
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:152