Skip to content

Commit 0eb7e7d

Browse files
author
Cruz Monrreal
authored
Merge pull request ARMmbed#7703 from li-ho/adi_tmr_api
Resolve us_ticker.c api discrepancy between EV_COG_AD4050LZ and EV_COG_AD3029LZ
2 parents d84bf7f + 10af90a commit 0eb7e7d

File tree

5 files changed

+186
-63
lines changed

5 files changed

+186
-63
lines changed

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/us_ticker.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ static void event_timer()
202202

203203
tmrConfig.nLoad = cnt;
204204
tmrConfig.nAsyncLoad = cnt;
205-
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, tmrConfig);
205+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, &tmrConfig);
206206
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
207207
} else {
208208
tmrConfig.nLoad = 65535u;
209209
tmrConfig.nAsyncLoad = 65535u;
210-
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, tmrConfig);
210+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, &tmrConfig);
211211
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
212212
}
213213
}
@@ -274,13 +274,13 @@ void us_ticker_init(void)
274274
tmrConfig.nAsyncLoad = 0;
275275
tmrConfig.bReloading = false;
276276
tmrConfig.bSyncBypass = true; // Allow x1 prescale: requires PCLK as a clk
277-
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP0, tmrConfig);
277+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP0, &tmrConfig);
278278

279279
/* Configure GP1 to have a period 256 times longer than GP0 */
280280
tmrConfig.nLoad = 0;
281281
tmrConfig.nAsyncLoad = 0;
282282
tmrConfig.ePrescaler = ADI_TMR_PRESCALER_256; // TMR1 = 26MHz/256
283-
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP1, tmrConfig);
283+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP1, &tmrConfig);
284284

285285
/* Configure GP2 for doing event counts */
286286
tmrConfig.bCountingUp = true;
@@ -291,7 +291,7 @@ void us_ticker_init(void)
291291
tmrConfig.nAsyncLoad = 0;
292292
tmrConfig.bReloading = false;
293293
tmrConfig.bSyncBypass = true; // Allow x1 prescale
294-
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, tmrConfig);
294+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, &tmrConfig);
295295

296296

297297
/*------------------------- GP TIMER ENABLE ------------------------------*/

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/bsp/config/adi_tmr_config.h

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file adi_tmr_config.h
33
* @brief GP and RGB timer device driver configuration
44
-----------------------------------------------------------------------------
5-
Copyright (c) 2016 Analog Devices, Inc.
5+
Copyright (c) 2016-2018 Analog Devices, Inc.
66
77
All rights reserved.
88
@@ -169,7 +169,13 @@ POSSIBILITY OF SUCH DAMAGE.
169169
a value of 0 - 39. Please refer hardware reference manual to know
170170
which events can be captured by a particular GP timer.
171171
*/
172+
#if defined(__ADUCM3029__)
173+
#define TMR0_CFG_EVENT_CAPTURE (9u)
174+
#elif defined(__ADUCM4050__)
172175
#define TMR0_CFG_EVENT_CAPTURE (27u)
176+
#else
177+
#error TMR is not ported for this processor
178+
#endif
173179

174180
/*************************************************************
175181
GP Timer 0 PWM0 Configuration
@@ -295,8 +301,13 @@ POSSIBILITY OF SUCH DAMAGE.
295301
a value of 0 - 39. Please refer hardware reference manual to know
296302
which events can be captured by a particular GP timer.
297303
*/
304+
#if defined(__ADUCM3029__)
305+
#define TMR1_CFG_EVENT_CAPTURE (15u)
306+
#elif defined(__ADUCM4050__)
298307
#define TMR1_CFG_EVENT_CAPTURE (28u)
299-
308+
#else
309+
#error TMR is not ported for this processor
310+
#endif
300311
/*************************************************************
301312
GP Timer 1 PWM0 Configuration
302313
*************************************************************/
@@ -419,8 +430,13 @@ POSSIBILITY OF SUCH DAMAGE.
419430
a value of 0 - 39. Please refer hardware reference manual to know
420431
which events can be captured by a particular GP timer.
421432
*/
433+
#if defined(__ADUCM3029__)
434+
#define TMR2_CFG_EVENT_CAPTURE (6u)
435+
#elif defined(__ADUCM4050__)
422436
#define TMR2_CFG_EVENT_CAPTURE (27u)
423-
437+
#else
438+
#error TMR is not ported for this processor
439+
#endif
424440
/*************************************************************
425441
GP Timer 2 PWM0 Configuration
426442
*************************************************************/
@@ -451,7 +467,7 @@ POSSIBILITY OF SUCH DAMAGE.
451467

452468
/*! @} */
453469

454-
470+
#if defined(__ADUCM4050__)
455471
/*************************************************************
456472
RGB Timer Configuration
457473
*************************************************************/
@@ -629,7 +645,7 @@ POSSIBILITY OF SUCH DAMAGE.
629645
the PWM output remains idle. It can be any value from 0 to 65535.
630646
*/
631647
#define TMR3_CFG_PWM2_MATCH_VALUE (0u)
632-
648+
#endif
633649
/*! @} */
634650

635651
/*************************************************************
@@ -676,9 +692,17 @@ POSSIBILITY OF SUCH DAMAGE.
676692
#error "Invalid configuration"
677693
#endif
678694

695+
#if defined(__ADUCM3029__)
696+
#if TMR0_CFG_EVENT_CAPTURE > 15u
697+
#error "Invalid configuration"
698+
#endif
699+
#elif defined(__ADUCM4050__)
679700
#if TMR0_CFG_EVENT_CAPTURE > 39u
680701
#error "Invalid configuration"
681702
#endif
703+
#else
704+
#error TMR is not ported for this processor
705+
#endif
682706

683707
#if TMR0_CFG_ENABLE_PWM0_MATCH_MODE > 1u
684708
#error "Invalid configuration"
@@ -736,9 +760,17 @@ POSSIBILITY OF SUCH DAMAGE.
736760
#error "Invalid configuration"
737761
#endif
738762

763+
#if defined(__ADUCM3029__)
764+
#if TMR1_CFG_EVENT_CAPTURE > 15u
765+
#error "Invalid configuration"
766+
#endif
767+
#elif defined(__ADUCM4050__)
739768
#if TMR1_CFG_EVENT_CAPTURE > 39u
740769
#error "Invalid configuration"
741770
#endif
771+
#else
772+
#error TMR is not ported for this processor
773+
#endif
742774

743775
#if TMR1_CFG_ENABLE_PWM0_MATCH_MODE > 1u
744776
#error "Invalid configuration"
@@ -796,9 +828,17 @@ POSSIBILITY OF SUCH DAMAGE.
796828
#error "Invalid configuration"
797829
#endif
798830

831+
#if defined(__ADUCM3029__)
832+
#if TMR2_CFG_EVENT_CAPTURE > 15u
833+
#error "Invalid configuration"
834+
#endif
835+
#elif defined(__ADUCM4050__)
799836
#if TMR2_CFG_EVENT_CAPTURE > 39u
800837
#error "Invalid configuration"
801838
#endif
839+
#else
840+
#error TMR is not ported for this processor
841+
#endif
802842

803843
#if TMR2_CFG_ENABLE_PWM0_MATCH_MODE > 1u
804844
#error "Invalid configuration"
@@ -812,6 +852,7 @@ POSSIBILITY OF SUCH DAMAGE.
812852
#error "Invalid configuration"
813853
#endif
814854

855+
#if defined(__ADUCM4050__)
815856
/*************************************************************
816857
RGB Timer Macro Validation
817858
**************************************************************/
@@ -896,6 +937,7 @@ POSSIBILITY OF SUCH DAMAGE.
896937
#error "Invalid configuration"
897938
#endif
898939

940+
#endif
899941
/*! @} */
900942

901943

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/bsp/drivers/tmr/adi_tmr.h

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file adi_tmr.h
33
* @brief GP and RGB timer device driver public header file
44
-----------------------------------------------------------------------------
5-
Copyright (c) 2016 Analog Devices, Inc.
5+
Copyright (c) 2016-2018 Analog Devices, Inc.
66
77
All rights reserved.
88
@@ -56,12 +56,16 @@ POSSIBILITY OF SUCH DAMAGE.
5656
* @{
5757
*/
5858

59+
/* C++ linkage */
60+
#ifdef __cplusplus
61+
extern "C" {
62+
#endif /* __cplusplus */
5963

6064
/*!
6165
*****************************************************************************
6266
* \enum ADI_TMR_RESULT
6367
* Enumeration for result code returned from the timer device driver functions.
64-
* The return value of all timer APIs returning #ADI_TMR_RESULT should always
68+
* The return value of all timer APIs returning #ADI_TMR_RESULT should always
6569
* be tested at the application level for success or failure.
6670
*****************************************************************************/
6771
typedef enum {
@@ -97,10 +101,17 @@ typedef enum {
97101
ADI_TMR_DEVICE_GP1 = 1u,
98102
/*! General purpose timer 2 */
99103
ADI_TMR_DEVICE_GP2 = 2u,
104+
#if defined(__ADUCM3029__)
105+
/*! Total number of devices (private) */
106+
ADI_TMR_DEVICE_NUM = 3u,
107+
#elif defined(__ADUCM4050__)
100108
/*! RGB timer */
101109
ADI_TMR_DEVICE_RGB = 3u,
102110
/*! Total number of devices (private) */
103111
ADI_TMR_DEVICE_NUM = 4u,
112+
#else
113+
#error TMR is not ported for this processor
114+
#endif
104115
} ADI_TMR_DEVICE;
105116

106117
/*!
@@ -110,7 +121,7 @@ typedef enum {
110121
*****************************************************************************/
111122
typedef enum {
112123
/*! Timeout event occurred */
113-
ADI_TMR_EVENT_TIMEOUT = 0x01,
124+
ADI_TMR_EVENT_TIMEOUT = 0x01,
114125
/*! Event capture event occurred */
115126
ADI_TMR_EVENT_CAPTURE = 0x02,
116127
} ADI_TMR_EVENT;
@@ -124,7 +135,7 @@ typedef enum {
124135
/*! Count every 1 source clock periods */
125136
ADI_TMR_PRESCALER_1 = 0u,
126137
/*! Count every 16 source clock periods */
127-
ADI_TMR_PRESCALER_16 = 1u,
138+
ADI_TMR_PRESCALER_16 = 1u,
128139
/*! Count every 64 source clock periods */
129140
ADI_TMR_PRESCALER_64 = 2u,
130141
/*! Count every 256 source clock periods */
@@ -138,11 +149,11 @@ typedef enum {
138149
*****************************************************************************/
139150
typedef enum {
140151
/*! Use periphreal clock (PCLK) */
141-
ADI_TMR_CLOCK_PCLK = 0u,
152+
ADI_TMR_CLOCK_PCLK = 0u,
142153
/*! Use internal high frequency clock (HFOSC) */
143-
ADI_TMR_CLOCK_HFOSC = 1u,
154+
ADI_TMR_CLOCK_HFOSC = 1u,
144155
/*! Use internal low frequency clock (LFOSC) */
145-
ADI_TMR_CLOCK_LFOSC = 2u,
156+
ADI_TMR_CLOCK_LFOSC = 2u,
146157
/*! Use external low frequency clock (LFXTAL) */
147158
ADI_TMR_CLOCK_LFXTAL = 3u,
148159
} ADI_TMR_CLOCK_SOURCE;
@@ -151,7 +162,7 @@ typedef enum {
151162
*****************************************************************************
152163
* \enum ADI_TMR_PWM_OUTPUT
153164
* RGB PWM outputs, used to specify which PWM output to configure. For the GP
154-
* timers only #ADI_TMR_PWM_OUTPUT_0 is allowed. The RGB timer has all three
165+
* timers only #ADI_TMR_PWM_OUTPUT_0 is allowed. The RGB timer has all three
155166
* outputs.
156167
*****************************************************************************/
157168
typedef enum {
@@ -168,7 +179,7 @@ typedef enum {
168179
/*!
169180
*****************************************************************************
170181
* \struct ADI_TMR_CONFIG
171-
* Configuration structure to fill and pass to #adi_tmr_ConfigTimer when
182+
* Configuration structure to fill and pass to #adi_tmr_ConfigTimer when
172183
* configuring the GP or RGB timer
173184
*****************************************************************************/
174185
typedef struct {
@@ -180,7 +191,7 @@ typedef struct {
180191
ADI_TMR_PRESCALER ePrescaler;
181192
/*! Clock source */
182193
ADI_TMR_CLOCK_SOURCE eClockSource;
183-
/*! Load value (only relent in periodic mode) */
194+
/*! Load value (only relevant in periodic mode) */
184195
uint16_t nLoad;
185196
/*! Asynchronous load value (only relevant in periodic mode, and when PCLK is used) */
186197
uint16_t nAsyncLoad;
@@ -193,7 +204,7 @@ typedef struct {
193204
/*!
194205
*****************************************************************************
195206
* \struct ADI_TMR_EVENT_CONFIG
196-
* Configuration structure to fill and pass to #adi_tmr_ConfigEvent when
207+
* Configuration structure to fill and pass to #adi_tmr_ConfigEvent when
197208
* configuring event capture
198209
*****************************************************************************/
199210
typedef struct {
@@ -208,7 +219,7 @@ typedef struct {
208219
/*!
209220
*****************************************************************************
210221
* \struct ADI_TMR_PWM_CONFIG
211-
* Configuration structure to fill and pass to #adi_tmr_ConfigPwm when
222+
* Configuration structure to fill and pass to #adi_tmr_ConfigPwm when
212223
* configuring pulse width modulation output
213224
*****************************************************************************/
214225
typedef struct {
@@ -232,9 +243,9 @@ typedef struct {
232243
ADI_TMR_RESULT adi_tmr_Init (ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfCallback, void * const pCBParam, bool bEnableInt);
233244

234245
/* Configuration interface functions */
235-
ADI_TMR_RESULT adi_tmr_ConfigTimer (ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG timerConfig);
236-
ADI_TMR_RESULT adi_tmr_ConfigEvent (ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_CONFIG eventConfig);
237-
ADI_TMR_RESULT adi_tmr_ConfigPwm (ADI_TMR_DEVICE const eDevice, ADI_TMR_PWM_CONFIG pwmConfig );
246+
ADI_TMR_RESULT adi_tmr_ConfigTimer (ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG* timerConfig);
247+
ADI_TMR_RESULT adi_tmr_ConfigEvent (ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_CONFIG* eventConfig);
248+
ADI_TMR_RESULT adi_tmr_ConfigPwm (ADI_TMR_DEVICE const eDevice, ADI_TMR_PWM_CONFIG* pwmConfig );
238249

239250
/* Timer start and stop */
240251
ADI_TMR_RESULT adi_tmr_Enable (ADI_TMR_DEVICE const eDevice, bool bEnable);
@@ -246,7 +257,9 @@ ADI_TMR_RESULT adi_tmr_GetCaptureCount (ADI_TMR_DEVICE const eDevice, uint16_t *
246257
/* Reload function */
247258
ADI_TMR_RESULT adi_tmr_Reload (ADI_TMR_DEVICE const eDevice);
248259

249-
260+
#ifdef __cplusplus
261+
}
262+
#endif
250263
/*! @} */
251264

252265

0 commit comments

Comments
 (0)