MAX32660 Peripheral Driver API
Peripheral Driver API for the MAX32660
tmr.h
1
6/******************************************************************************
7 *
8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9 * Analog Devices, Inc.),
10 * Copyright (C) 2023-2024 Analog Devices, Inc.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 ******************************************************************************/
25
26/* Define to prevent redundant inclusion */
27#ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_TMR_H_
28#define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_TMR_H_
29
30/* **** Includes **** */
31#include "mxc_device.h"
32#include "mxc_errors.h"
33#include "tmr_regs.h"
34#include "mxc_sys.h"
35#include "gcr_regs.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
50typedef enum {
71
72 // Legacy names
73 TMR_PRES_1 = MXC_TMR_PRES_1,
74 TMR_PRES_2 = MXC_TMR_PRES_2,
75 TMR_PRES_4 = MXC_TMR_PRES_4,
76 TMR_PRES_8 = MXC_TMR_PRES_8,
77 TMR_PRES_16 = MXC_TMR_PRES_16,
78 TMR_PRES_32 = MXC_TMR_PRES_32,
79 TMR_PRES_64 = MXC_TMR_PRES_64,
80 TMR_PRES_128 = MXC_TMR_PRES_128,
81 TMR_PRES_256 = MXC_TMR_PRES_256,
82 TMR_PRES_512 = MXC_TMR_PRES_512,
83 TMR_PRES_1024 = MXC_TMR_PRES_1024,
84 TMR_PRES_2048 = MXC_TMR_PRES_2048,
85 TMR_PRES_4096 = MXC_TMR_PRES_4096
87
91typedef enum {
100
101 // Legacy names
102 TMR_MODE_ONESHOT = MXC_TMR_MODE_ONESHOT,
103 TMR_MODE_CONTINUOUS = MXC_TMR_MODE_CONTINUOUS,
104 TMR_MODE_COUNTER = MXC_TMR_MODE_COUNTER,
105 TMR_MODE_PWM = MXC_TMR_MODE_PWM,
106 TMR_MODE_CAPTURE = MXC_TMR_MODE_CAPTURE,
107 TMR_MODE_COMPARE = MXC_TMR_MODE_COMPARE,
108 TMR_MODE_GATED = MXC_TMR_MODE_GATED,
109 TMR_MODE_CAPTURE_COMPARE = MXC_TMR_MODE_CAPTURE_COMPARE
111
116typedef enum {
120
121 // Legacy names
122 TMR_BIT_MODE_32 = MXC_TMR_BIT_MODE_32,
123 TMR_BIT_MODE_16A = MXC_TMR_BIT_MODE_16A,
124 TMR_BIT_MODE_16B = MXC_TMR_BIT_MODE_16B,
126
130typedef enum {
135
136 // Legacy names
137 TMR_UNIT_NANOSEC = MXC_TMR_UNIT_NANOSEC,
138 TMR_UNIT_MICROSEC = MXC_TMR_UNIT_MICROSEC,
139 TMR_UNIT_MILLISEC = MXC_TMR_UNIT_MILLISEC,
140 TMR_UNIT_SEC = MXC_TMR_UNIT_SEC,
142
146typedef struct {
149 uint32_t cmp_cnt;
150 unsigned pol;
152
153/* **** Definitions **** */
154typedef void (*mxc_tmr_complete_t)(int error);
155
156/* **** Function Prototypes **** */
157
171
177
183
189
197int MXC_TMR_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm);
198
205
212
219
227uint32_t MXC_TMR_GetPeriod(mxc_tmr_regs_t *tmr, uint32_t prescalar, uint32_t frequency);
228
234
241
248
255
262void MXC_TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt);
263
269void MXC_TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt);
270
277void MXC_TMR_Delay(mxc_tmr_regs_t *tmr, uint32_t us);
278
286void MXC_TMR_TO_Start(mxc_tmr_regs_t *tmr, uint32_t us);
287
296
303
310
319
328
335
344
355int MXC_TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mxc_tmr_unit_t *units);
356
359#ifdef __cplusplus
360}
361#endif
362
363#endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_TMR_H_
Registers, Bit Masks and Bit Positions for the GCR Peripheral Module.
#define MXC_V_TMR_CN_TMODE_COUNTER
Definition: tmr_regs.h:154
#define MXC_F_TMR_CN_PRES3
Definition: tmr_regs.h:205
#define MXC_V_TMR_CN_TMODE_COMPARE
Definition: tmr_regs.h:160
#define MXC_S_TMR_CN_PRES_DIV_BY_8
Definition: tmr_regs.h:176
#define MXC_S_TMR_CN_PRES_DIV_BY_8192
Definition: tmr_regs.h:196
#define MXC_S_TMR_CN_PRES_DIV_BY_4
Definition: tmr_regs.h:174
#define MXC_V_TMR_CN_TMODE_GATED
Definition: tmr_regs.h:162
#define MXC_S_TMR_CN_PRES_DIV_BY_512
Definition: tmr_regs.h:188
#define MXC_S_TMR_CN_PRES_DIV_BY_16
Definition: tmr_regs.h:178
#define MXC_S_TMR_CN_TMODE_CAPCOMP
Definition: tmr_regs.h:165
#define MXC_S_TMR_CN_PRES_DIV_BY_64
Definition: tmr_regs.h:182
#define MXC_S_TMR_CN_PRES_DIV_BY_128
Definition: tmr_regs.h:184
#define MXC_S_TMR_CN_TMODE_ONE_SHOT
Definition: tmr_regs.h:151
#define MXC_S_TMR_CN_PRES_DIV_BY_1024
Definition: tmr_regs.h:190
#define MXC_S_TMR_CN_PRES_DIV_BY_2
Definition: tmr_regs.h:172
#define MXC_S_TMR_CN_PRES_DIV_BY_32
Definition: tmr_regs.h:180
#define MXC_V_TMR_CN_TMODE_CAPTURE
Definition: tmr_regs.h:158
#define MXC_V_TMR_CN_TMODE_PWM
Definition: tmr_regs.h:156
#define MXC_V_TMR_CN_TMODE_CONTINUOUS
Definition: tmr_regs.h:152
#define MXC_S_TMR_CN_PRES_DIV_BY_4096
Definition: tmr_regs.h:194
#define MXC_S_TMR_CN_PRES_DIV_BY_256
Definition: tmr_regs.h:186
#define MXC_S_TMR_CN_PRES_DIV_BY_2048
Definition: tmr_regs.h:192
#define MXC_S_TMR_CN_PRES_DIV_BY_1
Definition: tmr_regs.h:170
Definition: tmr_regs.h:76
unsigned pol
Polarity (0 or 1)
Definition: tmr.h:150
mxc_tmr_pres_t pres
Desired timer prescaler.
Definition: tmr.h:147
uint32_t cmp_cnt
Compare register value in timer ticks.
Definition: tmr.h:149
mxc_tmr_mode_t mode
Desired timer mode.
Definition: tmr.h:148
void MXC_TMR_EnableInt(mxc_tmr_regs_t *tmr)
enable interupt
uint32_t MXC_TMR_GetCount(mxc_tmr_regs_t *tmr)
Get the timer count.
void MXC_TMR_ClearFlags(mxc_tmr_regs_t *tmr)
Clear the timer interrupt.
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_Shutdown(mxc_tmr_regs_t *tmr)
Shutdown timer module clock.
uint32_t MXC_TMR_GetCompare(mxc_tmr_regs_t *tmr)
Get the timer compare count.
int MXC_TMR_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm)
Set the value of the first transition in PWM mode.
unsigned int MXC_TMR_SW_Stop(mxc_tmr_regs_t *tmr)
Stopwatch stop.
unsigned int MXC_TMR_TO_Remaining(mxc_tmr_regs_t *tmr)
Amount of time remaining until timeour.
uint32_t MXC_TMR_GetCapture(mxc_tmr_regs_t *tmr)
Get the timer capture count.
void MXC_TMR_Stop(mxc_tmr_regs_t *tmr)
Stop the timer.
void MXC_TMR_TO_Stop(mxc_tmr_regs_t *tmr)
Stop the Timeout timer.
void MXC_TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt)
Set the timer count.
int MXC_TMR_TO_Check(mxc_tmr_regs_t *tmr)
Check on time out timer.
void MXC_TMR_Start(mxc_tmr_regs_t *tmr)
Start the timer counting.
mxc_tmr_unit_t
Timer units of time enumeration.
Definition: tmr.h:130
mxc_tmr_bit_mode_t
Timer bit mode.
Definition: tmr.h:116
void MXC_TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
Set the timer compare count.
mxc_tmr_mode_t
Timer modes.
Definition: tmr.h:91
mxc_tmr_pres_t
Timer prescaler values.
Definition: tmr.h:50
void MXC_TMR_SW_Start(mxc_tmr_regs_t *tmr)
Start stopwatch.
uint32_t MXC_TMR_GetFlags(mxc_tmr_regs_t *tmr)
Get the timer interrupt status.
int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
Initialize timer module clock.
void MXC_TMR_TO_Start(mxc_tmr_regs_t *tmr, uint32_t us)
Start a timer that will time out after a certain number of microseconds.
void MXC_TMR_TO_Clear(mxc_tmr_regs_t *tmr)
Clear timeout timer back to zero.
uint32_t MXC_TMR_GetPeriod(mxc_tmr_regs_t *tmr, uint32_t prescalar, uint32_t frequency)
Calculate count for required frequency.
void MXC_TMR_Delay(mxc_tmr_regs_t *tmr, uint32_t us)
Dealay for a set periord of time measured in microseconds.
void MXC_TMR_DisableInt(mxc_tmr_regs_t *tmr)
disable interupt
unsigned int MXC_TMR_TO_Elapsed(mxc_tmr_regs_t *tmr)
Get elapsed time of timeout timer.
@ MXC_TMR_UNIT_SEC
Second Unit Indicator.
Definition: tmr.h:134
@ MXC_TMR_UNIT_MILLISEC
Millisecond Unit Indicator.
Definition: tmr.h:133
@ MXC_TMR_UNIT_MICROSEC
Microsecond Unit Indicator.
Definition: tmr.h:132
@ MXC_TMR_UNIT_NANOSEC
Nanosecond Unit Indicator.
Definition: tmr.h:131
@ MXC_TMR_BIT_MODE_16A
Timer Mode Lower 16 bit.
Definition: tmr.h:118
@ MXC_TMR_BIT_MODE_16B
Timer Mode Upper 16 bit.
Definition: tmr.h:119
@ MXC_TMR_BIT_MODE_32
Timer Mode 32 bit.
Definition: tmr.h:117
@ MXC_TMR_MODE_PWM
Timer Mode PWM.
Definition: tmr.h:95
@ MXC_TMR_MODE_CAPTURE_COMPARE
Timer Mode CAPTURECOMPARE.
Definition: tmr.h:99
@ MXC_TMR_MODE_ONESHOT
Timer Mode ONESHOT.
Definition: tmr.h:92
@ MXC_TMR_MODE_CAPTURE
Timer Mode CAPTURE.
Definition: tmr.h:96
@ MXC_TMR_MODE_CONTINUOUS
Timer Mode CONTINUOUS.
Definition: tmr.h:93
@ MXC_TMR_MODE_COMPARE
Timer Mode COMPARE.
Definition: tmr.h:97
@ MXC_TMR_MODE_GATED
Timer Mode GATED.
Definition: tmr.h:98
@ MXC_TMR_MODE_COUNTER
Timer Mode COUNTER.
Definition: tmr.h:94
@ MXC_TMR_PRES_4
Divide input clock by 4.
Definition: tmr.h:53
@ MXC_TMR_PRES_2
Divide input clock by 2.
Definition: tmr.h:52
@ MXC_TMR_PRES_64
Divide input clock by 64.
Definition: tmr.h:57
@ MXC_TMR_PRES_8
Divide input clock by 8.
Definition: tmr.h:54
@ MXC_TMR_PRES_1024
Divide input clock by 1024.
Definition: tmr.h:63
@ MXC_TMR_PRES_128
Divide input clock by 128.
Definition: tmr.h:58
@ MXC_TMR_PRES_32
Divide input clock by 32.
Definition: tmr.h:56
@ MXC_TMR_PRES_256
Divide input clock by 256.
Definition: tmr.h:59
@ MXC_TMR_PRES_1
Divide input clock by 1.
Definition: tmr.h:51
@ MXC_TMR_PRES_8192
Divide input clock by 8192.
Definition: tmr.h:69
@ MXC_TMR_PRES_4096
Divide input clock by 4096.
Definition: tmr.h:67
@ MXC_TMR_PRES_2048
Divide input clock by 2048.
Definition: tmr.h:65
@ MXC_TMR_PRES_512
Divide input clock by 512.
Definition: tmr.h:61
@ MXC_TMR_PRES_16
Divide input clock by 16.
Definition: tmr.h:55
Timer Configuration.
Definition: tmr.h:146
Registers, Bit Masks and Bit Positions for the TMR Peripheral Module.