1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
//*****************************************************************************
//
// am_hal_stimer.h
//! @file
//!
//! @brief Functions for accessing and configuring the STIMER.
//!
//! @addtogroup stimer2 Counter/Timer (STIMER)
//! @ingroup apollo2hal
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2017, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 1.2.11 of the AmbiqSuite Development Package.
//
//*****************************************************************************
#ifndef AM_HAL_STIMER_H
#define AM_HAL_STIMER_H
//
// Compute address of a given COMPARE or CAPTURE register.
// Note - For Apollo2, the parameter n should be 0 (as only 1 stimer module
// exists) and the parameter r should be 0-7 (compare) or 0-3 (capture).
//
#define AM_REG_STIMER_COMPARE(n, r) (AM_REG_CTIMERn(n) + \
AM_REG_CTIMER_SCMPR0_O + (r * 4))
#define AM_REG_STIMER_CAPTURE(n, r) (AM_REG_CTIMERn(n) + \
AM_REG_CTIMER_SCAPT0_O + (r * 4))
//*****************************************************************************
//
//! @name Interrupt Status Bits
//! @brief Interrupt Status Bits for enable/disble use
//!
//! These macros may be used to set and clear interrupt bits
//! @{
//
//*****************************************************************************
#define AM_HAL_STIMER_INT_COMPAREA AM_REG_CTIMER_STMINTSTAT_COMPAREA_M
#define AM_HAL_STIMER_INT_COMPAREB AM_REG_CTIMER_STMINTSTAT_COMPAREB_M
#define AM_HAL_STIMER_INT_COMPAREC AM_REG_CTIMER_STMINTSTAT_COMPAREC_M
#define AM_HAL_STIMER_INT_COMPARED AM_REG_CTIMER_STMINTSTAT_COMPARED_M
#define AM_HAL_STIMER_INT_COMPAREE AM_REG_CTIMER_STMINTSTAT_COMPAREE_M
#define AM_HAL_STIMER_INT_COMPAREF AM_REG_CTIMER_STMINTSTAT_COMPAREF_M
#define AM_HAL_STIMER_INT_COMPAREG AM_REG_CTIMER_STMINTSTAT_COMPAREG_M
#define AM_HAL_STIMER_INT_COMPAREH AM_REG_CTIMER_STMINTSTAT_COMPAREH_M
#define AM_HAL_STIMER_INT_OVERFLOW AM_REG_CTIMER_STMINTSTAT_OVERFLOW_M
#define AM_HAL_STIMER_INT_CAPTUREA AM_REG_CTIMER_STMINTSTAT_CAPTUREA_M
#define AM_HAL_STIMER_INT_CAPTUREB AM_REG_CTIMER_STMINTSTAT_CAPTUREB_M
#define AM_HAL_STIMER_INT_CAPTUREC AM_REG_CTIMER_STMINTSTAT_CAPTUREC_M
#define AM_HAL_STIMER_INT_CAPTURED AM_REG_CTIMER_STMINTSTAT_CAPTURED_M
//! @}
//*****************************************************************************
//
//! @name STimer Configuration Bits
//! @brief Interrupt Status Bits for enable/disble use
//!
//! These macros may be used to set and clear interrupt bits
//! @{
//
//*****************************************************************************
#define AM_HAL_STIMER_CFG_THAW \
AM_REG_CTIMER_STCFG_FREEZE_THAW
#define AM_HAL_STIMER_CFG_FREEZE \
AM_REG_CTIMER_STCFG_FREEZE_FREEZE
#define AM_HAL_STIMER_CFG_RUN \
AM_REG_CTIMER_STCFG_CLEAR_RUN
#define AM_HAL_STIMER_CFG_CLEAR \
AM_REG_CTIMER_STCFG_CLEAR_CLEAR
#define AM_HAL_STIMER_CFG_COMPARE_A_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_A_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_B_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_B_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_C_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_C_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_D_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_D_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_E_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_E_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_F_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_F_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_G_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_G_EN_ENABLE
#define AM_HAL_STIMER_CFG_COMPARE_H_ENABLE \
AM_REG_CTIMER_STCFG_COMPARE_H_EN_ENABLE
//! @}
//*****************************************************************************
//
//! @name Clock Configuration options
//! @brief STimer Configuration register options.
//!
//! These options are to be used with the am_hal_stimer_config() function.
//! @{
//
//*****************************************************************************
#define AM_HAL_STIMER_NO_CLK \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_NOCLK)
#define AM_HAL_STIMER_HFRC_3MHZ \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_HFRC_DIV16)
#define AM_HAL_STIMER_HFRC_187_5KHZ \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_HFRC_DIV256)
#define AM_HAL_STIMER_XTAL_32KHZ \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_XTAL_DIV1)
#define AM_HAL_STIMER_XTAL_16KHZ \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_XTAL_DIV2)
#define AM_HAL_STIMER_XTAL_1KHZ \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_XTAL_DIV32)
#define AM_HAL_STIMER_LFRC_1KHZ \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_LFRC_DIV1)
#define AM_HAL_STIMER_HFRC_CTIMER0A \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_CTIMER0A)
#define AM_HAL_STIMER_HFRC_CTIMER0B \
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_CTIMER0B)
//! @}
//*****************************************************************************
//
//! @name Capture Control Register options.
//! @brief Configuration options for capture control register.
//!
//! These options are to be used with the am_hal_stimer_capture_control_set
//! function.
//! @{
//
//*****************************************************************************
#define AM_HAL_STIMER_CAPTURE_A_ENABLE \
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_A_ENABLE
#define AM_HAL_STIMER_CAPTURE_B_ENABLE \
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_B_ENABLE
#define AM_HAL_STIMER_CAPTURE_C_ENABLE \
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_C_ENABLE
#define AM_HAL_STIMER_CAPTURE_D_ENABLE \
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_D_ENABLE
//! @}
//*****************************************************************************
//
//
//
//*****************************************************************************
//*****************************************************************************
//
// Stimer configuration structure
//
//*****************************************************************************
typedef struct
{
//
//! Configuration options for the STIMER
//
uint32_t ui32STimerConfig;
}
am_hal_stimer_config_t;
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// External function definitions
//
//*****************************************************************************
extern uint32_t am_hal_stimer_config(uint32_t ui32STimerConfig);
extern uint32_t am_hal_stimer_counter_get(void);
extern void am_hal_stimer_counter_clear(void);
extern void am_hal_stimer_compare_delta_set(uint32_t ui32CmprInstance,
uint32_t ui32Delta);
extern uint32_t am_hal_stimer_compare_get(uint32_t ui32CmprInstance);
extern void am_hal_stimer_capture_start(uint32_t ui32CaptureNum,
uint32_t ui32GPIONumber,
bool bPolarity);
extern void am_hal_stimer_capture_stop(uint32_t ui32CaptureNum);
extern uint32_t am_hal_stimer_capture_get(uint32_t ui32CaptureNum);
extern void am_hal_stimer_int_enable(uint32_t ui32Interrupt);
extern uint32_t am_hal_stimer_int_enable_get(void);
extern void am_hal_stimer_int_disable(uint32_t ui32Interrupt);
extern void am_hal_stimer_int_set(uint32_t ui32Interrupt);
extern void am_hal_stimer_int_clear(uint32_t ui32Interrupt);
extern uint32_t am_hal_stimer_int_status_get(bool bEnabledOnly);
#ifdef __cplusplus
}
#endif
#endif // AM_HAL_STIMER_H
//*****************************************************************************
//
// End Doxygen group.
//! @}
//
//*****************************************************************************
|