MAX32675 Peripheral Driver API
Peripheral Driver API for the MAX32675
tmr.h
1 
6 /* ****************************************************************************
7  * Copyright (C) 2016 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 
119 typedef enum {
127 
131 typedef struct {
136  uint32_t cmp_cnt;
137  unsigned pol;
138 } mxc_tmr_cfg_t;
139 
140 /* **** Definitions **** */
141 typedef void (*mxc_tmr_complete_t) (int error);
142 
143 /* **** Function Prototypes **** */
144 
154 int MXC_TMR_Init (mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t* cfg, bool init_pins);
155 
160 void MXC_TMR_Shutdown (mxc_tmr_regs_t *tmr);
161 
166 void MXC_TMR_Start (mxc_tmr_regs_t* tmr);
167 
172 void MXC_TMR_Stop (mxc_tmr_regs_t* tmr);
173 
181 int MXC_TMR_SetPWM (mxc_tmr_regs_t* tmr, uint32_t pwm);
182 
188 uint32_t MXC_TMR_GetCompare (mxc_tmr_regs_t* tmr);
189 
195 uint32_t MXC_TMR_GetCapture (mxc_tmr_regs_t* tmr);
196 
202 uint32_t MXC_TMR_GetCount (mxc_tmr_regs_t* tmr);
203 
212 uint32_t MXC_TMR_GetPeriod (mxc_tmr_regs_t* tmr, mxc_tmr_clock_t clock, uint32_t prescalar, uint32_t frequency);
213 
219 
225 uint32_t MXC_TMR_GetFlags (mxc_tmr_regs_t* tmr);
226 
233 
240 
248 
256 
263 void MXC_TMR_SetCompare (mxc_tmr_regs_t *tmr, uint32_t cmp_cnt);
264 
270 void MXC_TMR_SetCount (mxc_tmr_regs_t *tmr, uint32_t cnt);
271 
278 void MXC_TMR_Delay (mxc_tmr_regs_t *tmr, unsigned long us);
279 
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 
360 #ifdef __cplusplus
361 }
362 #endif
363 
364 #endif /* _TMR_H_ */
TMR_MODE_ONESHOT
@ TMR_MODE_ONESHOT
Timer Mode ONESHOT.
Definition: tmr.h:84
MXC_S_TMR_CTRL0_MODE_A_CONTINUOUS
#define MXC_S_TMR_CTRL0_MODE_A_CONTINUOUS
Definition: tmr_regs.h:186
MXC_TMR_GetCompare
uint32_t MXC_TMR_GetCompare(mxc_tmr_regs_t *tmr)
Get the timer compare count.
MXC_S_TMR_CTRL0_MODE_A_COMPARE
#define MXC_S_TMR_CTRL0_MODE_A_COMPARE
Definition: tmr_regs.h:194
mxc_tmr_cfg_t::pres
mxc_tmr_pres_t pres
Desired timer prescaler.
Definition: tmr.h:132
MXC_S_TMR_CTRL0_MODE_A_CAPCOMP
#define MXC_S_TMR_CTRL0_MODE_A_CAPCOMP
Definition: tmr_regs.h:198
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_4096
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_4096
Definition: tmr_regs.h:231
MXC_TMR_EXT_CLK
@ MXC_TMR_EXT_CLK
External Clock.
Definition: tmr.h:121
MXC_TMR_ClearFlags
void MXC_TMR_ClearFlags(mxc_tmr_regs_t *tmr)
Clear the timer interrupt.
mxc_tmr_clock_t
mxc_tmr_clock_t
Clock settings.
Definition: tmr.h:119
MXC_TMR_32M_CLK
@ MXC_TMR_32M_CLK
32MHz Clock
Definition: tmr.h:123
MXC_TMR_GetFlags
uint32_t MXC_TMR_GetFlags(mxc_tmr_regs_t *tmr)
Get the timer interrupt status.
TMR_PRES_16
@ TMR_PRES_16
Divide input clock by 16.
Definition: tmr.h:69
TMR_MODE_PWM
@ TMR_MODE_PWM
Timer Mode PWM.
Definition: tmr.h:87
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_8
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_8
Definition: tmr_regs.h:213
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_512
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_512
Definition: tmr_regs.h:225
TMR_PRES_256
@ TMR_PRES_256
Divide input clock by 256.
Definition: tmr.h:73
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_16
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_16
Definition: tmr_regs.h:215
MXC_TMR_TO_Check
int MXC_TMR_TO_Check(mxc_tmr_regs_t *tmr)
Check on time out timer.
MXC_TMR_SW_Stop
unsigned int MXC_TMR_SW_Stop(mxc_tmr_regs_t *tmr)
Stopwatch stop.
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_128
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_128
Definition: tmr_regs.h:221
TMR_MODE_CAPTURE_COMPARE
@ TMR_MODE_CAPTURE_COMPARE
Timer Mode CAPTURECOMPARE.
Definition: tmr.h:91
mxc_tmr_cfg_t::pol
unsigned pol
Polarity (0 or 1)
Definition: tmr.h:137
MXC_TMR_Shutdown
void MXC_TMR_Shutdown(mxc_tmr_regs_t *tmr)
Shutdown timer module clock.
MXC_TMR_APB_CLK
@ MXC_TMR_APB_CLK
PCLK CLock
Definition: tmr.h:120
TMR_MODE_COUNTER
@ TMR_MODE_COUNTER
Timer Mode COUNTER.
Definition: tmr.h:86
TMR_PRES_4096
@ TMR_PRES_4096
Divide input clock by 4096.
Definition: tmr.h:77
TMR_PRES_64
@ TMR_PRES_64
Divide input clock by 64.
Definition: tmr.h:71
mxc_tmr_cfg_t::mode
mxc_tmr_mode_t mode
Desired timer mode.
Definition: tmr.h:133
MXC_S_TMR_CTRL0_MODE_A_ONE_SHOT
#define MXC_S_TMR_CTRL0_MODE_A_ONE_SHOT
Definition: tmr_regs.h:184
MXC_TMR_SetCompare
void MXC_TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
Set the timer compare count.
TMR_PRES_2
@ TMR_PRES_2
Divide input clock by 2.
Definition: tmr.h:66
MXC_TMR_GetPeriod
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.
TMR_UNIT_MICROSEC
@ TMR_UNIT_MICROSEC
Microsecond Unit Indicator.
Definition: tmr.h:109
TMR_PRES_8
@ TMR_PRES_8
Divide input clock by 8.
Definition: tmr.h:68
TMR_UNIT_SEC
@ TMR_UNIT_SEC
Second Unit Indicator.
Definition: tmr.h:111
MXC_TMR_TO_Start
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.
TMR_MODE_CAPTURE
@ TMR_MODE_CAPTURE
Timer Mode CAPTURE.
Definition: tmr.h:88
MXC_S_TMR_CTRL0_MODE_A_CAPTURE
#define MXC_S_TMR_CTRL0_MODE_A_CAPTURE
Definition: tmr_regs.h:192
TMR_PRES_2048
@ TMR_PRES_2048
Divide input clock by 2048.
Definition: tmr.h:76
TMR_UNIT_MILLISEC
@ TMR_UNIT_MILLISEC
Millisecond Unit Indicator.
Definition: tmr.h:110
mxc_tmr_mode_t
mxc_tmr_mode_t
Timer modes.
Definition: tmr.h:83
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_1024
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_1024
Definition: tmr_regs.h:227
MXC_TMR_80K_CLK
@ MXC_TMR_80K_CLK
80KHz Clock
Definition: tmr.h:125
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_1
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_1
Definition: tmr_regs.h:207
TMR_PRES_512
@ TMR_PRES_512
Divide input clock by 512.
Definition: tmr.h:74
TMR_PRES_4
@ TMR_PRES_4
Divide input clock by 4
Definition: tmr.h:67
MXC_TMR_EnableInt
void MXC_TMR_EnableInt(mxc_tmr_regs_t *tmr)
enable interupt
MXC_TMR_TO_Elapsed
unsigned int MXC_TMR_TO_Elapsed(mxc_tmr_regs_t *tmr)
Get elapsed time of timeout timer.
mxc_tmr_pres_t
mxc_tmr_pres_t
Timer prescaler values.
Definition: tmr.h:64
TMR_MODE_CONTINUOUS
@ TMR_MODE_CONTINUOUS
Timer Mode CONTINUOUS.
Definition: tmr.h:85
mxc_tmr_cfg_t
Timer Configuration.
Definition: tmr.h:131
mxc_tmr_cfg_t::cmp_cnt
uint32_t cmp_cnt
Compare register value in timer ticks.
Definition: tmr.h:136
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_32
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_32
Definition: tmr_regs.h:217
mxc_tmr_bit_mode_t
mxc_tmr_bit_mode_t
Timer bit mode.
Definition: tmr.h:98
MXC_TMR_Delay
void MXC_TMR_Delay(mxc_tmr_regs_t *tmr, unsigned long us)
Dealay for a set periord of time measured in microseconds.
MXC_S_TMR_CTRL0_MODE_A_PWM
#define MXC_S_TMR_CTRL0_MODE_A_PWM
Definition: tmr_regs.h:190
MXC_S_TMR_CTRL0_MODE_A_GATED
#define MXC_S_TMR_CTRL0_MODE_A_GATED
Definition: tmr_regs.h:196
TMR_PRES_128
@ TMR_PRES_128
Divide input clock by 128.
Definition: tmr.h:72
MXC_TMR_DisableWakeup
void MXC_TMR_DisableWakeup(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
Disable wakeup from sleep.
MXC_TMR_32K_CLK
@ MXC_TMR_32K_CLK
32KHz Clock
Definition: tmr.h:124
MXC_TMR_SetCount
void MXC_TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt)
Set the timer count.
MXC_TMR_TO_Stop
void MXC_TMR_TO_Stop(mxc_tmr_regs_t *tmr)
Stop the Timeout timer.
TMR_UNIT_NANOSEC
@ TMR_UNIT_NANOSEC
Nanosecond Unit Indicator.
Definition: tmr.h:108
TMR_PRES_1
@ TMR_PRES_1
Divide input clock by 1.
Definition: tmr.h:65
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_256
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_256
Definition: tmr_regs.h:223
TMR_BIT_MODE_16A
@ TMR_BIT_MODE_16A
Timer Mode Lower 16 bit.
Definition: tmr.h:100
TMR_BIT_MODE_16B
@ TMR_BIT_MODE_16B
Timer Mode Upper 16 bit.
Definition: tmr.h:101
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_2048
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_2048
Definition: tmr_regs.h:229
MXC_TMR_SW_Start
void MXC_TMR_SW_Start(mxc_tmr_regs_t *tmr)
Start stopwatch.
MXC_TMR_Init
int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)
Initialize timer module clock.
mxc_tmr_cfg_t::bitMode
mxc_tmr_bit_mode_t bitMode
Desired timer bits
Definition: tmr.h:134
MXC_TMR_Start
void MXC_TMR_Start(mxc_tmr_regs_t *tmr)
Start the timer counting.
MXC_TMR_TO_Remaining
unsigned int MXC_TMR_TO_Remaining(mxc_tmr_regs_t *tmr)
Amount of time remaining until timeour.
mxc_tmr_regs_t
Definition: tmr_regs.h:88
MXC_TMR_GetCapture
uint32_t MXC_TMR_GetCapture(mxc_tmr_regs_t *tmr)
Get the timer capture count.
MXC_TMR_TO_Clear
void MXC_TMR_TO_Clear(mxc_tmr_regs_t *tmr)
Clear timeout timer back to zero.
TMR_MODE_GATED
@ TMR_MODE_GATED
Timer Mode GATED.
Definition: tmr.h:90
MXC_TMR_8M_CLK
@ MXC_TMR_8M_CLK
8MHz Clock
Definition: tmr.h:122
TMR_PRES_32
@ TMR_PRES_32
Divide input clock by 32.
Definition: tmr.h:70
MXC_S_TMR_CTRL0_MODE_A_COUNTER
#define MXC_S_TMR_CTRL0_MODE_A_COUNTER
Definition: tmr_regs.h:188
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_2
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_2
Definition: tmr_regs.h:209
MXC_TMR_DisableInt
void MXC_TMR_DisableInt(mxc_tmr_regs_t *tmr)
disable interupt
TMR_PRES_1024
@ TMR_PRES_1024
Divide input clock by 1024.
Definition: tmr.h:75
mxc_tmr_cfg_t::clock
mxc_tmr_clock_t clock
Desired clock source.
Definition: tmr.h:135
TMR_BIT_MODE_32
@ TMR_BIT_MODE_32
Timer Mode 32 bit
Definition: tmr.h:99
MXC_TMR_EnableWakeup
void MXC_TMR_EnableWakeup(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
Enable wakeup from sleep.
TMR_MODE_COMPARE
@ TMR_MODE_COMPARE
Timer Mode COMPARE.
Definition: tmr.h:89
MXC_TMR_SetPWM
int MXC_TMR_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm)
Set the value of the first transition in PWM mode.
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_4
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_4
Definition: tmr_regs.h:211
mxc_tmr_unit_t
mxc_tmr_unit_t
Timer units of time enumeration.
Definition: tmr.h:107
MXC_TMR_GetTime
int MXC_TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mxc_tmr_unit_t *units)
Get time from timer.
MXC_TMR_Stop
void MXC_TMR_Stop(mxc_tmr_regs_t *tmr)
Stop the timer.
MXC_TMR_GetCount
uint32_t MXC_TMR_GetCount(mxc_tmr_regs_t *tmr)
Get the timer count.
MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_64
#define MXC_S_TMR_CTRL0_CLKDIV_A_DIV_BY_64
Definition: tmr_regs.h:219