Skip to content

Commit a8b9006

Browse files
authored
Merge pull request #120 from KurtE/FspTimer_AGT
FspTimer does not initialize properly if AGT timer is selected.
2 parents e53cacb + 5838864 commit a8b9006

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: cores/arduino/FspTimer.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ bool FspTimer::begin(timer_mode_t mode, uint8_t tp, uint8_t channel, float freq_
185185

186186
init_ok = true;
187187
/* AGT timer is always 16 bit */
188-
if(channel < TIMER_16_BIT_OFFSET && type == GPT_TIMER) {
188+
if(channel < TIMER_16_BIT_OFFSET && tp == GPT_TIMER) {
189189
/* timer a 32 BIT */
190-
set_period_counts(1.0 / freq_hz, CH32BIT_MAX);
190+
set_period_counts(tp, 1.0 / freq_hz, CH32BIT_MAX);
191191
}
192192
else {
193193
/* timer a 16 BIT */
194-
set_period_counts(1.0 / freq_hz, CH16BIT_MAX);
194+
set_period_counts(tp, 1.0 / freq_hz, CH16BIT_MAX);
195195
}
196196

197197
if(duty_perc >= 0 && duty_perc <= 100) {
@@ -215,11 +215,11 @@ void FspTimer::set_irq_callback(GPTimerCbk_f cbk , void *ctx /*= nullptr*/ ) {
215215
}
216216

217217
/* -------------------------------------------------------------------------- */
218-
void FspTimer::set_period_counts(float period, uint32_t _max) {
218+
void FspTimer::set_period_counts(uint8_t tp, float period, uint32_t _max) {
219219
/* -------------------------------------------------------------------------- */
220220

221221
uint32_t freq_hz = 0;
222-
if(type == GPT_TIMER) {
222+
if(tp == GPT_TIMER) {
223223
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKD);
224224
if(period * (float) freq_hz / 1.0 < _max) {
225225
_period_counts = (uint32_t) (period * (float) freq_hz / 1.0);
@@ -249,7 +249,7 @@ void FspTimer::set_period_counts(float period, uint32_t _max) {
249249
init_ok = false;
250250
}
251251
}
252-
else if(type == AGT_TIMER) {
252+
else if(tp == AGT_TIMER) {
253253
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKB);
254254
if(period * (float) freq_hz / 1.0 < _max) {
255255
_period_counts = (uint32_t) (period * (float) freq_hz / 1.0);
@@ -418,11 +418,11 @@ bool FspTimer::set_period_ms(double ms) {
418418
close();
419419
if(timer_cfg.channel < TIMER_16_BIT_OFFSET && type == GPT_TIMER) {
420420
/* timer a 32 BIT */
421-
set_period_counts(period_sec, CH32BIT_MAX);
421+
set_period_counts(type, period_sec, CH32BIT_MAX);
422422
}
423423
else {
424424
/* timer a 16 BIT */
425-
set_period_counts(period_sec, CH16BIT_MAX);
425+
set_period_counts(type, period_sec, CH16BIT_MAX);
426426
}
427427

428428
timer_cfg.period_counts = _period_counts;

Diff for: cores/arduino/FspTimer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class FspTimer {
9595
uint32_t _duty_cycle_counts;
9696
timer_source_div_t _sd;
9797
uint8_t type;
98-
void set_period_counts(float period, uint32_t max);
98+
void set_period_counts(uint8_t tp, float period, uint32_t max);
9999
TimerIrqCfg_t get_cfg_for_irq();
100100
static bool force_pwm_reserved;
101101
static TimerAvail_t gpt_used_channel[GPT_HOWMANY];

0 commit comments

Comments
 (0)