From e829aa632c65485909a8f9e0b7f364cbbbb35b7e Mon Sep 17 00:00:00 2001 From: "sabith @ atlas" Date: Tue, 22 Oct 2024 16:07:18 +0530 Subject: [PATCH] timer: delete existing timer on create - if timer exists on create, then delete it - this is to allow changing modes on create --- .../core/mcu/apollo3/uhal/uhal_timer.c | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/cores/apollo3/component/core/mcu/apollo3/uhal/uhal_timer.c b/cores/apollo3/component/core/mcu/apollo3/uhal/uhal_timer.c index 016e49b5..9470e423 100644 --- a/cores/apollo3/component/core/mcu/apollo3/uhal/uhal_timer.c +++ b/cores/apollo3/component/core/mcu/apollo3/uhal/uhal_timer.c @@ -202,15 +202,22 @@ int32_t uhal_timer_create (TimerID_E timer_id, timer_handler tmr_handler, TimerM uhal_timer_pdata[timer_id].timer_id = timer_id; uhal_timer_pdata[timer_id].timer_func = tmr_handler; - if(apollo3_timer_id == NULL) + if(apollo3_timer_id != NULL) { - apollo3_timer_id = xTimerCreate("TMR", - 1, - get_apollo_timer_mode(mode), - NULL, - uhal_timer_handler_dispatcher); + if(pdPASS != xTimerDelete(apollo3_timer_id, OSTIMER_WAIT_FOR_QUEUE)) + { + return -UDRV_INTERNAL_ERR; + } + set_apollo_timer_id(timer_id, NULL); + apollo3_timer_id = NULL; } + apollo3_timer_id = xTimerCreate("TMR", + 1, + get_apollo_timer_mode(mode), + NULL, + uhal_timer_handler_dispatcher); + if (apollo3_timer_id != NULL) { set_apollo_timer_id(timer_id, apollo3_timer_id); return UDRV_RETURN_OK; @@ -332,15 +339,22 @@ int32_t uhal_sys_timer_create (SysTimerID_E timer_id, timer_handler tmr_handler, uhal_sys_timer_pdata[timer_id].sys_timer_id = timer_id; uhal_sys_timer_pdata[timer_id].timer_func = tmr_handler; - if(apollo3_timer_id == NULL) + if(apollo3_timer_id != NULL) { - apollo3_timer_id = xTimerCreate("SYS_TMR", - 1, - get_apollo_timer_mode(mode), - NULL, - uhal_sys_timer_handler_dispatcher); + if(pdPASS != xTimerDelete(apollo3_timer_id, OSTIMER_WAIT_FOR_QUEUE)) + { + return -UDRV_INTERNAL_ERR; + } + set_sys_apollo_timer_id(timer_id, NULL); + apollo3_timer_id = NULL; } + apollo3_timer_id = xTimerCreate("SYS_TMR", + 1, + get_apollo_timer_mode(mode), + NULL, + uhal_sys_timer_handler_dispatcher); + if (apollo3_timer_id != NULL) { set_sys_apollo_timer_id(timer_id, apollo3_timer_id); return UDRV_RETURN_OK;