1 //*****************************************************************************
2 //
3 //! @file am_hal_systick.h
4 //!
5 //! @brief Functions for accessing and configuring the SYSTICK.
6 //!
7 //! @addtogroup systick3 SYSTICK - System Timer
8 //! @ingroup apollo3_hal
9 //! @{
10 //
11 //*****************************************************************************
12 
13 //*****************************************************************************
14 //
15 // Copyright (c) 2024, Ambiq Micro, Inc.
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are met:
20 //
21 // 1. Redistributions of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
23 //
24 // 2. Redistributions in binary form must reproduce the above copyright
25 // notice, this list of conditions and the following disclaimer in the
26 // documentation and/or other materials provided with the distribution.
27 //
28 // 3. Neither the name of the copyright holder nor the names of its
29 // contributors may be used to endorse or promote products derived from this
30 // software without specific prior written permission.
31 //
32 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
36 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 // POSSIBILITY OF SUCH DAMAGE.
43 //
44 // This is part of revision release_sdk_3_2_0-dd5f40c14b of the AmbiqSuite Development Package.
45 //
46 //*****************************************************************************
47 #ifndef AM_HAL_SYSTICK_H
48 #define AM_HAL_SYSTICK_H
49 
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54 
55 //*****************************************************************************
56 //
57 // External function definitions
58 //
59 //*****************************************************************************
60 
61 //*****************************************************************************
62 //
63 //! @brief Start the SYSTICK.
64 //!
65 //! This function starts the systick timer.
66 //!
67 //! @note This timer does not run in deep-sleep mode as it runs from the core
68 //! clock, which is gated in deep-sleep. If a timer is needed in deep-sleep use
69 //! one of the ctimers instead. Also to note is this timer will consume higher
70 //! power than the ctimers.
71 //
72 //*****************************************************************************
73 extern void am_hal_systick_start(void);
74 
75 //*****************************************************************************
76 //
77 //! @brief Stop the SYSTICK.
78 //!
79 //! This function stops the systick timer.
80 //!
81 //! @note This timer does not run in deep-sleep mode as it runs from the core
82 //! clock, which is gated in deep-sleep. If a timer is needed in deep-sleep use
83 //! one of the ctimers instead. Also to note is this timer will consume higher
84 //! power than the ctimers.
85 //
86 //*****************************************************************************
87 extern void am_hal_systick_stop(void);
88 
89 //*****************************************************************************
90 //
91 //! @brief Enable the interrupt in the SYSTICK.
92 //!
93 //! This function enables the interupt in the systick timer.
94 //
95 //*****************************************************************************
96 extern void am_hal_systick_int_enable(void);
97 
98 //*****************************************************************************
99 //
100 //! @brief Disable the interrupt in the SYSTICK.
101 //!
102 //! This function disables the interupt in the systick timer.
103 //
104 //*****************************************************************************
105 extern void am_hal_systick_int_disable(void);
106 
107 //*****************************************************************************
108 //
109 //! @brief Reads the interrupt status.
110 //!
111 //! This function reads the interrupt status in the systick timer.
112 //!
113 //! @return the interrupt status.
114 //
115 //*****************************************************************************
116 extern uint32_t am_hal_systick_int_status_get(void);
117 
118 //*****************************************************************************
119 //
120 //! @brief Reset the interrupt in the SYSTICK.
121 //!
122 //! This function resets the systick timer by clearing out the configuration
123 //! register.
124 //
125 //*****************************************************************************
126 extern void am_hal_systick_reset(void);
127 
128 //*****************************************************************************
129 //
130 //! @brief Load the value into the SYSTICK.
131 //!
132 //! @param ui32LoadVal the desired load value for the systick. Maximum value is
133 //! 0x00FF.FFFF.
134 //!
135 //! This function loads the desired value into the systick timer.
136 //
137 //*****************************************************************************
138 extern void am_hal_systick_load(uint32_t ui32LoadVal);
139 
140 //*****************************************************************************
141 //
142 //! @brief Get the current count value in the SYSTICK.
143 //!
144 //! This function gets the current count value in the systick timer.
145 //!
146 //! @return Current count value.
147 //
148 //*****************************************************************************
149 extern uint32_t am_hal_systick_count(void);
150 
151 //*****************************************************************************
152 //
153 //! @brief Wait the specified number of ticks.
154 //!
155 //! This function delays for the given number of SysTick ticks.
156 //!
157 //! @note If the SysTick timer is being used elsewhere, it will be corrupted
158 //! by calling this function.
159 //!
160 //! @return 0 if successful.
161 //
162 //*****************************************************************************
163 extern uint32_t am_hal_systick_wait_ticks(uint32_t ui32Ticks);
164 
165 //*****************************************************************************
166 //
167 //! @brief Delay the specified number of microseconds.
168 //!
169 //! This function will use the SysTick timer to delay until the specified
170 //!  number of microseconds have elapsed.  It uses the processor clocks and
171 //!  takes into account the current CORESEL setting.
172 //!
173 //! @note If the SysTick timer is being used elsewhere, it will be corrupted
174 //! by calling this function.
175 //!
176 //! @return Total number of SysTick ticks delayed.
177 //
178 //*****************************************************************************
179 extern uint32_t am_hal_systick_delay_us(uint32_t ui32NumUs);
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif // AM_HAL_SYSTICK_H
186 
187 //*****************************************************************************
188 //
189 // End Doxygen group.
190 //! @}
191 //
192 //*****************************************************************************
193