|
13 | 13 | #include "communication/SimpleFOCDebug.h" |
14 | 14 | #include "FspTimer.h" |
15 | 15 |
|
| 16 | +#define GPT_OPEN (0x00475054ULL) |
| 17 | + |
16 | 18 | /* |
17 | 19 | We use the GPT timers, there are 2 channels (32 bit) + 6 channels (16 bit) |
18 | 20 | Each channel has 2 outputs (GTIOCAx and GTIOCBx) which can be complimentary. |
@@ -202,6 +204,7 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool |
202 | 204 | t->timer_cfg.p_context = nullptr; |
203 | 205 | t->timer_cfg.p_extend = &(t->ext_cfg); |
204 | 206 | t->timer_cfg.cycle_end_ipl = BSP_IRQ_DISABLED; |
| 207 | + t->timer_cfg.cycle_end_irq = FSP_INVALID_VECTOR; |
205 | 208 |
|
206 | 209 | t->ext_cfg.p_pwm_cfg = &(t->pwm_cfg); |
207 | 210 | t->pwm_cfg.trough_ipl = BSP_IRQ_DISABLED; |
@@ -256,6 +259,14 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool |
256 | 259 | t->ext_cfg.gtior_setting.gtior_b.obdflt = active_high ? 0x00 : 0x01; |
257 | 260 | } |
258 | 261 |
|
| 262 | + // lets stop the timer in case its running |
| 263 | + if (GPT_OPEN == t->ctrl.open) { |
| 264 | + if (R_GPT_Stop(&(t->ctrl)) != FSP_SUCCESS) { |
| 265 | + SIMPLEFOC_DEBUG("DRV: timer stop failed"); |
| 266 | + return false; |
| 267 | + } |
| 268 | + } |
| 269 | + |
259 | 270 | memset(&(t->ctrl), 0, sizeof(gpt_instance_ctrl_t)); |
260 | 271 | err = R_GPT_Open(&(t->ctrl),&(t->timer_cfg)); |
261 | 272 | if ((err != FSP_ERR_ALREADY_OPEN) && (err != FSP_SUCCESS)) { |
@@ -294,7 +305,7 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool |
294 | 305 | bool startTimerChannels(RenesasHardwareDriverParams* params, int num_channels) { |
295 | 306 | uint32_t mask = 0; |
296 | 307 | for (int i = 0; i < num_channels; i++) { |
297 | | - RenesasTimerConfig* t = params->timer_config[i]; |
| 308 | + // RenesasTimerConfig* t = params->timer_config[i]; |
298 | 309 | // if (R_GPT_Start(&(t->ctrl)) != FSP_SUCCESS) { |
299 | 310 | // SIMPLEFOC_DEBUG("DRV: timer start failed"); |
300 | 311 | // return false; |
|
0 commit comments