MAX32655 Peripheral Driver API
Peripheral Driver API for the MAX32655
tmr.h
1 
6 /* ****************************************************************************
7  * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  *************************************************************************** */
38 
39 /* Define to prevent redundant inclusion */
40 #ifndef _TMR_H_
41 #define _TMR_H_
42 
43 /* **** Includes **** */
44 #include "mxc_device.h"
45 #include "tmr_regs.h"
46 #include "mxc_sys.h"
47 #include "gcr_regs.h"
48 #include "mcr_regs.h"
49 #include "stdbool.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
64 typedef enum {
79 
83 typedef enum {
93 
98 typedef enum {
103 
107 typedef enum {
113 
117 typedef enum {
118  MXC_TMR_APB_CLK = 0,
119  MXC_TMR_EXT_CLK,
120  /*8M and 60M clocks can be used for Timers 0,1,2 and 3*/
121  MXC_TMR_32M_CLK,
122  MXC_TMR_8M_CLK,
123  /*32K clock can be used for Timers 0,1,2,3 and 4*/
124  MXC_TMR_32K_CLK,
125  /*8K and EXT clocks can only be used for Timers 4 and 5*/
126  MXC_TMR_8K_CLK,
128 
132 typedef struct {
133  mxc_tmr_pres_t pres;
134  mxc_tmr_mode_t mode;
135  mxc_tmr_bit_mode_t bitMode;
136  mxc_tmr_clock_t clock;
137  uint32_t cmp_cnt;
138  unsigned pol;
139 } mxc_tmr_cfg_t;
140 
141 /* **** Definitions **** */
142 typedef void (*mxc_tmr_complete_t) (int error);
143 
144 /* **** Function Prototypes **** */
145 
155 int MXC_TMR_Init (mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t* cfg, bool init_pins);
156 
161 void MXC_TMR_Shutdown (mxc_tmr_regs_t *tmr);
162 
167 void MXC_TMR_Start (mxc_tmr_regs_t* tmr);
168 
173 void MXC_TMR_Stop (mxc_tmr_regs_t* tmr);
174 
182 int MXC_TMR_SetPWM (mxc_tmr_regs_t* tmr, uint32_t pwm);
183 
189 uint32_t MXC_TMR_GetCompare (mxc_tmr_regs_t* tmr);
190 
196 uint32_t MXC_TMR_GetCapture (mxc_tmr_regs_t* tmr);
197 
203 uint32_t MXC_TMR_GetCount (mxc_tmr_regs_t* tmr);
204 
213 uint32_t MXC_TMR_GetPeriod (mxc_tmr_regs_t* tmr, mxc_tmr_clock_t clock, uint32_t prescalar, uint32_t frequency);
214 
220 
226 uint32_t MXC_TMR_GetFlags (mxc_tmr_regs_t* tmr);
227 
234 
241 
249 
257 
264 void MXC_TMR_SetCompare (mxc_tmr_regs_t *tmr, uint32_t cmp_cnt);
265 
271 void MXC_TMR_SetCount (mxc_tmr_regs_t *tmr, uint32_t cnt);
272 
279 void MXC_TMR_Delay (mxc_tmr_regs_t *tmr, unsigned long us);
280 
287 void MXC_TMR_TO_Start (mxc_tmr_regs_t *tmr, unsigned long us);
288 
297 
303 void MXC_TMR_TO_Stop (mxc_tmr_regs_t *tmr);
304 
310 void MXC_TMR_TO_Clear (mxc_tmr_regs_t *tmr);
311 
319 unsigned int MXC_TMR_TO_Elapsed (mxc_tmr_regs_t *tmr);
320 
328 unsigned int MXC_TMR_TO_Remaining (mxc_tmr_regs_t *tmr);
329 
335 void MXC_TMR_SW_Start (mxc_tmr_regs_t *tmr);
336 
344 unsigned int MXC_TMR_SW_Stop (mxc_tmr_regs_t *tmr);
345 
356 int MXC_TMR_GetTime (mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mxc_tmr_unit_t *units);
357 
368 int MXC_TMR_GetTicks(mxc_tmr_regs_t *tmr, uint32_t time, mxc_tmr_unit_t units, uint32_t *ticks);
369 
372 #ifdef __cplusplus
373 }
374 #endif
375 
376 #endif /* _TMR_H_ */
mxc_tmr_unit_t
Timer units of time enumeration.
Definition: tmr.h:107
void MXC_TMR_TO_Clear(mxc_tmr_regs_t *tmr)
Clear timeout timer back to zero.
uint32_t MXC_TMR_GetCompare(mxc_tmr_regs_t *tmr)
Get the timer compare count.
uint32_t MXC_TMR_GetFlags(mxc_tmr_regs_t *tmr)
Get the timer interrupt status.
Definition: tmr.h:71
Definition: tmr.h:67
#define MXC_V_TMR_CTRL0_MODE_A_CAPTURE
Definition: tmr_regs.h:191
mxc_tmr_pres_t pres
Definition: tmr.h:133
void MXC_TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt)
Set the timer count.
#define MXC_V_TMR_CTRL0_MODE_A_PWM
Definition: tmr_regs.h:189
Definition: tmr.h:70
Definition: tmr.h:85
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_4096
Definition: tmr_regs.h:231
Definition: tmr.h:72
int MXC_TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mxc_tmr_unit_t *units)
Get time from timer.
void MXC_TMR_DisableInt(mxc_tmr_regs_t *tmr)
disable interupt
unsigned pol
Definition: tmr.h:138
Definition: tmr.h:108
#define MXC_S_TMR_CTRL0_MODE_A_CAPCOMP
Definition: tmr_regs.h:198
void MXC_TMR_EnableInt(mxc_tmr_regs_t *tmr)
enable interupt
void MXC_TMR_ClearFlags(mxc_tmr_regs_t *tmr)
Clear the timer interrupt.
mxc_tmr_mode_t mode
Definition: tmr.h:134
int MXC_TMR_GetTicks(mxc_tmr_regs_t *tmr, uint32_t time, mxc_tmr_unit_t units, uint32_t *ticks)
Get ticks from timer.
#define MXC_V_TMR_CTRL0_MODE_A_COMPARE
Definition: tmr_regs.h:193
#define MXC_V_TMR_CTRL0_MODE_A_CONTINUOUS
Definition: tmr_regs.h:185
unsigned int MXC_TMR_SW_Stop(mxc_tmr_regs_t *tmr)
Stopwatch stop.
Definition: tmr.h:75
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_512
Definition: tmr_regs.h:225
Definition: tmr.h:99
Definition: tmr.h:87
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_1
Definition: tmr_regs.h:207
int MXC_TMR_TO_Check(mxc_tmr_regs_t *tmr)
Check on time out timer.
#define MXC_S_TMR_CTRL0_MODE_A_ONE_SHOT
Definition: tmr_regs.h:184
mxc_tmr_clock_t
Peripheral Clock settings.
Definition: tmr.h:117
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_4
Definition: tmr_regs.h:211
void MXC_TMR_TO_Start(mxc_tmr_regs_t *tmr, unsigned long us)
Start a timer that will time out after a certain number of microseconds.
Definition: tmr.h:84
uint32_t MXC_TMR_GetPeriod(mxc_tmr_regs_t *tmr, mxc_tmr_clock_t clock, uint32_t prescalar, uint32_t frequency)
Calculate count for required frequency.
Definition: tmr.h:69
Definition: tmr.h:109
unsigned int MXC_TMR_TO_Elapsed(mxc_tmr_regs_t *tmr)
Get elapsed time of timeout timer.
void MXC_TMR_Shutdown(mxc_tmr_regs_t *tmr)
Shutdown timer module clock.
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_1024
Definition: tmr_regs.h:227
Definition: tmr.h:101
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_128
Definition: tmr_regs.h:221
Definition: tmr.h:110
#define MXC_V_TMR_CTRL0_MODE_A_COUNTER
Definition: tmr_regs.h:187
void MXC_TMR_TO_Stop(mxc_tmr_regs_t *tmr)
Stop the Timeout timer.
Definition: tmr.h:66
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_2
Definition: tmr_regs.h:209
Definition: tmr.h:65
Definition: tmr.h:90
Definition: tmr.h:100
Definition: tmr.h:88
uint32_t cmp_cnt
Definition: tmr.h:137
void MXC_TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
Set the timer compare count.
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_256
Definition: tmr_regs.h:223
Timer Configuration.
Definition: tmr.h:132
mxc_tmr_mode_t
Timer modes.
Definition: tmr.h:83
void MXC_TMR_DisableWakeup(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
Disable wakeup from sleep.
void MXC_TMR_Start(mxc_tmr_regs_t *tmr)
Start the timer counting.
uint32_t MXC_TMR_GetCount(mxc_tmr_regs_t *tmr)
Get the timer count.
Definition: tmr.h:77
uint32_t MXC_TMR_GetCapture(mxc_tmr_regs_t *tmr)
Get the timer capture count.
void MXC_TMR_SW_Start(mxc_tmr_regs_t *tmr)
Start stopwatch.
mxc_tmr_bit_mode_t bitMode
Definition: tmr.h:135
mxc_tmr_pres_t
Timer prescaler values.
Definition: tmr.h:64
#define MXC_V_TMR_CTRL0_MODE_A_GATED
Definition: tmr_regs.h:195
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_32
Definition: tmr_regs.h:217
Definition: tmr.h:91
Definition: tmr.h:89
int MXC_TMR_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm)
Set the value of the first transition in PWM mode.
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_64
Definition: tmr_regs.h:219
void MXC_TMR_Stop(mxc_tmr_regs_t *tmr)
Stop the timer.
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_2048
Definition: tmr_regs.h:229
Definition: tmr.h:74
unsigned int MXC_TMR_TO_Remaining(mxc_tmr_regs_t *tmr)
Amount of time remaining until timeour.
Definition: tmr.h:76
Definition: tmr.h:73
Definition: tmr.h:68
Definition: tmr.h:111
Definition: tmr.h:86
void MXC_TMR_EnableWakeup(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
Enable wakeup from sleep.
Definition: tmr_regs.h:88
void MXC_TMR_Delay(mxc_tmr_regs_t *tmr, unsigned long us)
Dealay for a set periord of time measured in microseconds.
int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)
Initialize timer module clock.
mxc_tmr_clock_t clock
Definition: tmr.h:136
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_8
Definition: tmr_regs.h:213
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_16
Definition: tmr_regs.h:215
mxc_tmr_bit_mode_t
Timer bit mode.
Definition: tmr.h:98