MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
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  * $Date: 2018-10-31 10:32:51 -0500 (Wed, 31 Oct 2018) $
38  * $Revision: 38826 $
39  *
40  *************************************************************************** */
41 
42 /* Define to prevent redundant inclusion */
43 #ifndef _TMR_H_
44 #define _TMR_H_
45 
46 /* **** Includes **** */
47 #include "mxc_config.h"
48 #include "tmr_regs.h"
49 #include "mxc_sys.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
64 typedef enum {
65  TMR_PRES_1 = MXC_S_TMR_CN_PRES_DIV1,
78 } tmr_pres_t;
79 
83 typedef enum {
84  TMR_MODE_ONESHOT = MXC_V_TMR_CN_TMODE_ONESHOT,
92 } tmr_mode_t;
93 
97 typedef enum {
102 } tmr_unit_t;
103 
107 typedef struct {
108  tmr_mode_t mode;
109  uint32_t cmp_cnt;
110  unsigned pol;
111 } tmr_cfg_t;
112 
116 typedef struct {
117  unsigned pol;
118  uint32_t per_cnt;
119  uint32_t duty_cnt;
120 } tmr_pwm_cfg_t;
121 
122 /* **** Definitions **** */
123 
124 /* **** Function Prototypes **** */
125 
132 void TMR_Init(mxc_tmr_regs_t *tmr, tmr_pres_t pres, const sys_cfg_tmr_t* sys_cfg);
133 
138 void TMR_Shutdown(mxc_tmr_regs_t *tmr);
139 
144 void TMR_Enable(mxc_tmr_regs_t* tmr);
145 
150 void TMR_Disable(mxc_tmr_regs_t* tmr);
151 
157 void TMR_Config(mxc_tmr_regs_t *tmr, const tmr_cfg_t *cfg);
158 
166 int TMR_PWMConfig(mxc_tmr_regs_t *tmr, const tmr_pwm_cfg_t *cfg);
167 
175 int TMR_PWMSetDuty(mxc_tmr_regs_t *tmr, uint32_t duty);
176 
184 int TMR_PWMSetPeriod(mxc_tmr_regs_t* tmr, uint32_t per);
185 
191 uint32_t TMR_GetCompare(mxc_tmr_regs_t* tmr);
192 
198 uint32_t TMR_GetCapture(mxc_tmr_regs_t* tmr);
199 
205 uint32_t TMR_GetCount(mxc_tmr_regs_t* tmr);
206 
211 void TMR_IntClear(mxc_tmr_regs_t* tmr);
212 
218 uint32_t TMR_IntStatus(mxc_tmr_regs_t* tmr);
219 
227 void TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt);
228 
234 void TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt);
235 
245 int TMR_GetTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks);
246 
256 int TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units);
257 
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif /* _TMR_H_ */
Divide input clock by 32.
Definition: tmr.h:71
#define MXC_S_TMR_CN_PRES_DIV8
CN_PRES_DIV8 Setting.
Definition: tmr_regs.h:158
Divide input clock by 16.
Definition: tmr.h:70
Divide input clock by 4.
Definition: tmr.h:68
tmr_pres_t
Timer prescaler values.
Definition: tmr.h:64
Timer Mode COUNTER.
Definition: tmr.h:87
int TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units)
Convert timer ticks to real time.
int TMR_PWMSetDuty(mxc_tmr_regs_t *tmr, uint32_t duty)
Set the timer duty cycle.
#define MXC_F_TMR_CN_PRES3
CN_PRES3 Mask.
Definition: tmr_regs.h:175
void TMR_Config(mxc_tmr_regs_t *tmr, const tmr_cfg_t *cfg)
Configure the timer.
Divide input clock by 2048.
Definition: tmr.h:77
Divide input clock by 512.
Definition: tmr.h:75
int TMR_GetTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks)
Convert real time to timer ticks.
Timer PWM Configuration.
Definition: tmr.h:116
void TMR_IntClear(mxc_tmr_regs_t *tmr)
Clear the timer interrupt.
void TMR_Enable(mxc_tmr_regs_t *tmr)
Enable the timer.
Millisecond Unit Indicator.
Definition: tmr.h:100
int TMR_PWMSetPeriod(mxc_tmr_regs_t *tmr, uint32_t per)
Set the timer period.
#define MXC_S_TMR_CN_PRES_DIV64
CN_PRES_DIV64 Setting.
Definition: tmr_regs.h:164
Nanosecond Unit Indicator.
Definition: tmr.h:98
void TMR_Init(mxc_tmr_regs_t *tmr, tmr_pres_t pres, const sys_cfg_tmr_t *sys_cfg)
Initialize timer module clock.
uint32_t TMR_IntStatus(mxc_tmr_regs_t *tmr)
Get the timer interrupt status.
void TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
Set the timer compare count.
#define MXC_V_TMR_CN_TMODE_CONTINUOUS
CN_TMODE_CONTINUOUS Value.
Definition: tmr_regs.h:134
uint32_t TMR_GetCapture(mxc_tmr_regs_t *tmr)
Get the timer capture count.
void TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt)
Set the timer count.
Divide input clock by 1.
Definition: tmr.h:66
Timer Configuration.
Definition: tmr.h:107
Divide input clock by 1024.
Definition: tmr.h:76
#define MXC_V_TMR_CN_TMODE_CAPTURE
CN_TMODE_CAPTURE Value.
Definition: tmr_regs.h:140
#define MXC_V_TMR_CN_TMODE_CAPTURECOMPARE
CN_TMODE_CAPTURECOMPARE Value.
Definition: tmr_regs.h:146
Second Unit Indicator.
Definition: tmr.h:101
#define MXC_S_TMR_CN_PRES_DIV2
CN_PRES_DIV2 Setting.
Definition: tmr_regs.h:154
void TMR_Shutdown(mxc_tmr_regs_t *tmr)
Shutdown timer module clock.
Divide input clock by 256.
Definition: tmr.h:74
#define MXC_V_TMR_CN_TMODE_ONESHOT
CN_TMODE_ONESHOT Value.
Definition: tmr_regs.h:132
#define MXC_S_TMR_CN_PRES_DIV128
CN_PRES_DIV128 Setting.
Definition: tmr_regs.h:166
#define MXC_S_TMR_CN_PRES_DIV32
CN_PRES_DIV32 Setting.
Definition: tmr_regs.h:162
Timer Mode COMPARE.
Definition: tmr.h:90
Timer Mode ONESHOT.
Definition: tmr.h:85
Divide input clock by 64.
Definition: tmr.h:72
int TMR_PWMConfig(mxc_tmr_regs_t *tmr, const tmr_pwm_cfg_t *cfg)
Configure the timer for PWM operation.
unsigned pol
Compare register value in timer ticks.
Definition: tmr.h:110
uint32_t duty_cnt
PWM period in timer ticks.
Definition: tmr.h:119
#define MXC_V_TMR_CN_TMODE_COMPARE
CN_TMODE_COMPARE Value.
Definition: tmr_regs.h:142
Timer Mode PWM.
Definition: tmr.h:88
uint32_t TMR_GetCompare(mxc_tmr_regs_t *tmr)
Get the timer compare count.
uint32_t per_cnt
PWM polarity (0 or 1)
Definition: tmr.h:118
Timer Mode CAPTURE.
Definition: tmr.h:89
Divide input clock by 8.
Definition: tmr.h:69
tmr_unit_t
Timer units of time enumeration.
Definition: tmr.h:97
Divide input clock by 128.
Definition: tmr.h:73
uint32_t cmp_cnt
Desired timer mode.
Definition: tmr.h:109
Structure type to access the TMR Registers.
Definition: tmr_regs.h:88
#define MXC_V_TMR_CN_TMODE_GATED
CN_TMODE_GATED Value.
Definition: tmr_regs.h:144
Microsecond Unit Indicator.
Definition: tmr.h:99
Divide input clock by 2.
Definition: tmr.h:67
void TMR_Disable(mxc_tmr_regs_t *tmr)
Disable the timer.
Timer Mode CONTINUOUS.
Definition: tmr.h:86
#define MXC_S_TMR_CN_PRES_DIV4
CN_PRES_DIV4 Setting.
Definition: tmr_regs.h:156
uint32_t TMR_GetCount(mxc_tmr_regs_t *tmr)
Get the timer count.
#define MXC_V_TMR_CN_TMODE_COUNTER
CN_TMODE_COUNTER Value.
Definition: tmr_regs.h:136
#define MXC_S_TMR_CN_PRES_DIV1
CN_PRES_DIV1 Setting.
Definition: tmr_regs.h:152
Timer Mode GATED.
Definition: tmr.h:91
#define MXC_S_TMR_CN_PRES_DIV16
CN_PRES_DIV16 Setting.
Definition: tmr_regs.h:160
#define MXC_V_TMR_CN_TMODE_PWM
CN_TMODE_PWM Value.
Definition: tmr_regs.h:138
tmr_mode_t
Timer modes.
Definition: tmr.h:83