MSPM0C1105_C1106 Driver Library  2.05.01.00
dl_systick.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file dl_systick.h
34  * @brief System Tick Timer (SysTick) Driver Library
35  * @defgroup SYSTICK M0P System Tick Timer (SysTick)
36  *
37  * @anchor ti_dl_m0p_dl_systick_Overview
38  * # Overview
39  *
40  * SysTick is a simple timer that is part of the Cortex-M architecture. Its
41  * intended purpose is to provide a periodic interrupt for an RTOS, but it can
42  * be used for other simple timing purposes.
43  *
44  * <hr>
45  ******************************************************************************
46  */
50 #ifndef ti_dl_m0p_dl_systick__include
51 #define ti_dl_m0p_dl_systick__include
52 
53 #include <stdbool.h>
54 #include <stdint.h>
55 
56 #include <ti/devices/msp/msp.h>
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 /* clang-format off */
63 
67 #define DL_SYSTICK_config(x) SysTick_Config(x)
68 
69 /* clang-format on */
70 
81 __STATIC_INLINE void DL_SYSTICK_init(uint32_t period)
82 {
83  SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk;
84  SysTick->LOAD = period - (uint32_t) 1;
85  SysTick->VAL = 0;
86 }
87 
98 __STATIC_INLINE void DL_SYSTICK_setPeriod(uint32_t period)
99 {
100  SysTick->LOAD = period - (uint32_t) 1;
101 }
102 
109 __STATIC_INLINE void DL_SYSTICK_resetValue(void)
110 {
111  SysTick->VAL = 0;
112 }
113 
121 __STATIC_INLINE uint32_t DL_SYSTICK_getPeriod(void)
122 {
123  return (SysTick->LOAD + (uint32_t) 1);
124 }
125 
133 __STATIC_INLINE uint32_t DL_SYSTICK_getValue(void)
134 {
135  return SysTick->VAL;
136 }
137 
141 __STATIC_INLINE void DL_SYSTICK_enableInterrupt(void)
142 {
143  SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
144 }
145 
149 __STATIC_INLINE void DL_SYSTICK_disableInterrupt(void)
150 {
151  SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk);
152 }
153 
161 __STATIC_INLINE void DL_SYSTICK_enable(void)
162 {
163  SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
164 }
165 
169 __STATIC_INLINE void DL_SYSTICK_disable(void)
170 {
171  SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk);
172 }
173 
182 __STATIC_INLINE bool DL_SYSTICK_isEnabled(void)
183 {
184  return (
185  (SysTick->CTRL & SysTick_CTRL_ENABLE_Msk) == SysTick_CTRL_ENABLE_Msk);
186 }
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 #endif /* ti_dl_m0p_dl_systick__include */
193 
__STATIC_INLINE uint32_t DL_SYSTICK_getPeriod(void)
Get the period for the SysTick.
Definition: dl_systick.h:121
__STATIC_INLINE uint32_t DL_SYSTICK_getValue(void)
Get the current value of SysTick counter.
Definition: dl_systick.h:133
__STATIC_INLINE void DL_SYSTICK_enable(void)
Enable the SysTick, starts counting once enabled.
Definition: dl_systick.h:161
__STATIC_INLINE void DL_SYSTICK_disable(void)
Disable the SysTick, stops counting once disabled.
Definition: dl_systick.h:169
__STATIC_INLINE void DL_SYSTICK_disableInterrupt(void)
Disable the SysTick interrupt.
Definition: dl_systick.h:149
__STATIC_INLINE bool DL_SYSTICK_isEnabled(void)
Checks if the SysTick is enabled.
Definition: dl_systick.h:182
__STATIC_INLINE void DL_SYSTICK_setPeriod(uint32_t period)
Set the period for the SysTick.
Definition: dl_systick.h:98
__STATIC_INLINE void DL_SYSTICK_init(uint32_t period)
Initializes the System Tick Timer (SysTick)
Definition: dl_systick.h:81
__STATIC_INLINE void DL_SYSTICK_enableInterrupt(void)
Enable the SysTick interrupt.
Definition: dl_systick.h:141
__STATIC_INLINE void DL_SYSTICK_resetValue(void)
Reset the current value of the SysTick.
Definition: dl_systick.h:109
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale