Skip to content

FspTimer does not initialize properly if AGT timer is selected. #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cores/arduino/FspTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ bool FspTimer::begin(timer_mode_t mode, uint8_t tp, uint8_t channel, float freq_

init_ok = true;
/* AGT timer is always 16 bit */
if(channel < TIMER_16_BIT_OFFSET && type == GPT_TIMER) {
if(channel < TIMER_16_BIT_OFFSET && tp == GPT_TIMER) {
/* timer a 32 BIT */
set_period_counts(1.0 / freq_hz, CH32BIT_MAX);
set_period_counts(tp, 1.0 / freq_hz, CH32BIT_MAX);
}
else {
/* timer a 16 BIT */
set_period_counts(1.0 / freq_hz, CH16BIT_MAX);
set_period_counts(tp, 1.0 / freq_hz, CH16BIT_MAX);
}

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

/* -------------------------------------------------------------------------- */
void FspTimer::set_period_counts(float period, uint32_t _max) {
void FspTimer::set_period_counts(uint8_t tp, float period, uint32_t _max) {
/* -------------------------------------------------------------------------- */

uint32_t freq_hz = 0;
if(type == GPT_TIMER) {
if(tp == GPT_TIMER) {
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKD);
if(period * (float) freq_hz / 1.0 < _max) {
_period_counts = (uint32_t) (period * (float) freq_hz / 1.0);
Expand Down Expand Up @@ -249,7 +249,7 @@ void FspTimer::set_period_counts(float period, uint32_t _max) {
init_ok = false;
}
}
else if(type == AGT_TIMER) {
else if(tp == AGT_TIMER) {
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKB);
if(period * (float) freq_hz / 1.0 < _max) {
_period_counts = (uint32_t) (period * (float) freq_hz / 1.0);
Expand Down Expand Up @@ -418,11 +418,11 @@ bool FspTimer::set_period_ms(double ms) {
close();
if(timer_cfg.channel < TIMER_16_BIT_OFFSET && type == GPT_TIMER) {
/* timer a 32 BIT */
set_period_counts(period_sec, CH32BIT_MAX);
set_period_counts(type, period_sec, CH32BIT_MAX);
}
else {
/* timer a 16 BIT */
set_period_counts(period_sec, CH16BIT_MAX);
set_period_counts(type, period_sec, CH16BIT_MAX);
}

timer_cfg.period_counts = _period_counts;
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/FspTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class FspTimer {
uint32_t _duty_cycle_counts;
timer_source_div_t _sd;
uint8_t type;
void set_period_counts(float period, uint32_t max);
void set_period_counts(uint8_t tp, float period, uint32_t max);
TimerIrqCfg_t get_cfg_for_irq();
static bool force_pwm_reserved;
static TimerAvail_t gpt_used_channel[GPT_HOWMANY];
Expand Down