diff --git a/.github/workflows/scripts/build.py b/.github/workflows/scripts/build.py index 2c96276022..00d83d87b1 100644 --- a/.github/workflows/scripts/build.py +++ b/.github/workflows/scripts/build.py @@ -44,6 +44,9 @@ def build_project(project:Path, target, board, maxim_path:Path, distclean=False, extra_args=None) -> Tuple[int, tuple]: clean_cmd = "make clean" if not distclean else "make distclean" + if "Bluetooth" in project.as_posix() or "BLE" in project.as_posix(): + # Clean cordio lib for BLE projects + clean_cmd += "&& make clean.cordio" res = run(clean_cmd, cwd=project, shell=True, capture_output=True, encoding="utf-8") # Test build diff --git a/.github/workflows/zephyr-hal.yml b/.github/workflows/zephyr-hal.yml index e61d43abd9..b4087b8efd 100644 --- a/.github/workflows/zephyr-hal.yml +++ b/.github/workflows/zephyr-hal.yml @@ -17,14 +17,11 @@ on: env: # Add environment variables here - PR_NUM: ${{ github.event.number }} + PR_NUM: ${{ github.event.pull_request.number }} # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: if_merged: - # Run only when a PR is merged - if: github.event.pull_request.merged == true - # The type of OS that the job will run on runs-on: [ ubuntu-latest ] @@ -39,6 +36,7 @@ jobs: with: # Specific Branch, tag, or SHA to checkout (uses default branch if empty) ref: '' + ssh-key: ${{ secrets.MSDK_SSH_KEY }} # Repository name (Default will be the current repo the action is running from) repository: ${{ github.repository }} fetch-depth: 0 @@ -51,6 +49,7 @@ jobs: with: # Specific Branch, tag, or SHA to checkout (uses default branch if empty) ref: 'develop' + ssh-key: ${{ secrets.MSDK_SSH_KEY }} # Name of different repository ('organization_name/repo_name') # Update the following line to point to the hal_adi repo once that repo is created. repository: 'analogdevicesinc/hal_adi' @@ -66,11 +65,12 @@ jobs: # directory that contains the 'msdk' and 'hal_adi' folders. bash ./msdk/.github/workflows/scripts/zephyr-hal.sh - - name: Push hal_adi repository - uses: EndBug/add-and-commit@v9.0.1 - with: - add: '*' - message: 'Updating Zephyr MSDK Hal based on msdk PR# $PR_NUM' - push: true - # Specify path in workspace to the repo you want to push to - cwd: './hal_adi' + - name: Push changes to hal_adi repository + run: | + echo "$(pwd) - $(ls)" + cd ./hal_adi + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + git add * + git commit -m "Update Zephyr MSDK Hal based on MSDK PR: https://github.com/analogdevicesinc/msdk/pull/${PR_NUM}" + git push diff --git a/Examples/MAX32655/Bluetooth/RF_Test/main.c b/Examples/MAX32655/Bluetooth/RF_Test/main.c index d9861254be..459bfac8ce 100644 --- a/Examples/MAX32655/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32655/Bluetooth/RF_Test/main.c @@ -243,8 +243,8 @@ uint8_t processEscSequence(uint8_t *seq) * * \brief adds latest command to command history buffer * - * \param q pointer to the circular buffer holding command history - * \param cmd pointer to the command string to be added + * \param q pointer to the circular buffer holding command history + * \param cmd pointer to the command string to be added * * \return None. */ @@ -271,9 +271,9 @@ void cmdHistoryAdd(queue_t *q, const uint8_t *cmd) * \fn updateQueuePointer. * * \brief Updates an internal marker pointing to historical command to be printed, based on up/down arrow - * - * \param q pointer to the circular buffer holding command history - * + * + * \param q pointer to the circular buffer holding command history + * * \param upArrow flag used to upated the queuePoniter delimiting which command to print * * \return None. @@ -393,9 +393,9 @@ void prompt(void) * \fn printHint * * \brief Prints the help string of any command matching the current inputbuffer - * + * * \param buff pointer to the inputbuffer - * + * * \return None. */ /*************************************************************************************************/ @@ -694,17 +694,25 @@ void txTestTask(void *pvParameters) snprintf(str, sizeof(str), "%s%s", str, (const char *)getPhyStr(phy)); APP_TRACE_INFO1("%s", str); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); + /* stat test */ if (testConfig.testType == BLE_TX_TEST) { res = LlEnhancedTxTest(testConfig.channel, packetLen, packetType, phy, 0); } else { res = LlEnhancedRxTest(testConfig.channel, phy, 0, 0); } + xTaskResumeAll(); //Restore scheduler + APP_TRACE_INFO2("result = %u %s", res, res == LL_SUCCESS ? "(SUCCESS)" : "(FAIL)"); /* if duration value was given then let the test run that amount of time and end */ if (testConfig.duration_ms) { vTaskDelay(testConfig.duration_ms); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); LlEndTest(NULL); + xTaskResumeAll(); //Restore scheduler xSemaphoreGive(rfTestMutex); } pausePrompt = false; diff --git a/Examples/MAX32665/Bluetooth/RF_Test/main.c b/Examples/MAX32665/Bluetooth/RF_Test/main.c index 22f2e38ca2..1a01be00a7 100644 --- a/Examples/MAX32665/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32665/Bluetooth/RF_Test/main.c @@ -246,8 +246,8 @@ uint8_t processEscSequence(uint8_t *seq) * * \brief adds latest command to command history buffer * - * \param q pointer to the circular buffer holding command history - * \param cmd pointer to the command string to be added + * \param q pointer to the circular buffer holding command history + * \param cmd pointer to the command string to be added * * \return None. */ @@ -274,9 +274,9 @@ void cmdHistoryAdd(queue_t *q, const uint8_t *cmd) * \fn updateQueuePointer. * * \brief Updates an internal marker pointing to historical command to be printed, based on up/down arrow - * - * \param q pointer to the circular buffer holding command history - * + * + * \param q pointer to the circular buffer holding command history + * * \param upArrow flag used to upated the queuePoniter delimiting which command to print * * \return None. @@ -396,9 +396,9 @@ void prompt(void) * \fn printHint * * \brief Prints the help string of any command matching the current inputbuffer - * + * * \param buff pointer to the inputbuffer - * + * * \return None. */ /*************************************************************************************************/ @@ -695,17 +695,25 @@ void txTestTask(void *pvParameters) snprintf(str, sizeof(str), "%s%s", str, (const char *)getPhyStr(phy)); APP_TRACE_INFO1("%s", str); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); + /* stat test */ if (testConfig.testType == BLE_TX_TEST) { res = LlEnhancedTxTest(testConfig.channel, packetLen, packetType, phy, 0); } else { res = LlEnhancedRxTest(testConfig.channel, phy, 0, 0); } + xTaskResumeAll(); //Restore scheduler + APP_TRACE_INFO2("result = %u %s", res, res == LL_SUCCESS ? "(SUCCESS)" : "(FAIL)"); /* if duration value was given then let the test run that amount of time and end */ if (testConfig.duration_ms) { vTaskDelay(testConfig.duration_ms); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); LlEndTest(NULL); + xTaskResumeAll(); //Restore scheduler xSemaphoreGive(rfTestMutex); } pausePrompt = false; diff --git a/Examples/MAX32690/Bluetooth/RF_Test/main.c b/Examples/MAX32690/Bluetooth/RF_Test/main.c index 22f2e38ca2..1a01be00a7 100644 --- a/Examples/MAX32690/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32690/Bluetooth/RF_Test/main.c @@ -246,8 +246,8 @@ uint8_t processEscSequence(uint8_t *seq) * * \brief adds latest command to command history buffer * - * \param q pointer to the circular buffer holding command history - * \param cmd pointer to the command string to be added + * \param q pointer to the circular buffer holding command history + * \param cmd pointer to the command string to be added * * \return None. */ @@ -274,9 +274,9 @@ void cmdHistoryAdd(queue_t *q, const uint8_t *cmd) * \fn updateQueuePointer. * * \brief Updates an internal marker pointing to historical command to be printed, based on up/down arrow - * - * \param q pointer to the circular buffer holding command history - * + * + * \param q pointer to the circular buffer holding command history + * * \param upArrow flag used to upated the queuePoniter delimiting which command to print * * \return None. @@ -396,9 +396,9 @@ void prompt(void) * \fn printHint * * \brief Prints the help string of any command matching the current inputbuffer - * + * * \param buff pointer to the inputbuffer - * + * * \return None. */ /*************************************************************************************************/ @@ -695,17 +695,25 @@ void txTestTask(void *pvParameters) snprintf(str, sizeof(str), "%s%s", str, (const char *)getPhyStr(phy)); APP_TRACE_INFO1("%s", str); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); + /* stat test */ if (testConfig.testType == BLE_TX_TEST) { res = LlEnhancedTxTest(testConfig.channel, packetLen, packetType, phy, 0); } else { res = LlEnhancedRxTest(testConfig.channel, phy, 0, 0); } + xTaskResumeAll(); //Restore scheduler + APP_TRACE_INFO2("result = %u %s", res, res == LL_SUCCESS ? "(SUCCESS)" : "(FAIL)"); /* if duration value was given then let the test run that amount of time and end */ if (testConfig.duration_ms) { vTaskDelay(testConfig.duration_ms); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); LlEndTest(NULL); + xTaskResumeAll(); //Restore scheduler xSemaphoreGive(rfTestMutex); } pausePrompt = false; diff --git a/Libraries/CMSIS/Device/Maxim/MAX32657/Include/max32657.h b/Libraries/CMSIS/Device/Maxim/MAX32657/Include/max32657.h index 1472891893..44e8107324 100644 --- a/Libraries/CMSIS/Device/Maxim/MAX32657/Include/max32657.h +++ b/Libraries/CMSIS/Device/Maxim/MAX32657/Include/max32657.h @@ -153,7 +153,11 @@ typedef enum { #include #include -#define IS_SECURE_ENVIRONMENT (defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)) +#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +#define IS_SECURE_ENVIRONMENT 1 +#else +#define IS_SECURE_ENVIRONMENT 0 +#endif /* ================================================================================ */ /* ================== Device Specific Memory Section ================== */ diff --git a/Libraries/Cordio/platform/targets/maxim/build/cordio_lib.mk b/Libraries/Cordio/platform/targets/maxim/build/cordio_lib.mk index 510c6dc7cb..5343a51519 100644 --- a/Libraries/Cordio/platform/targets/maxim/build/cordio_lib.mk +++ b/Libraries/Cordio/platform/targets/maxim/build/cordio_lib.mk @@ -92,7 +92,8 @@ ${CORDIO_BUILD_DIR}/${CORDIO_LIB}: ${CORDIO_C_FILES} ${PROJECTMK} $(MAKE) -f ${CORDIO_DIR}/platform/targets/maxim/build/libCordio.mk lib MAXIM_PATH=${MAXIM_PATH} PROJECT=${CORDIO_LIB} \ CORDIO_LIB_VAR=${CORDIO_LIB_VAR} BUILD_DIR=${CORDIO_BUILD_DIR} MFLOAT_ABI=$(MFLOAT_ABI) \ DUAL_CORE=$(DUAL_CORE) RISCV_CORE=$(RISCV_CORE) TRACE=${TRACE} DEBUG=${DEBUG} RTOS=${RTOS} \ - CFG_DEV="${CFG_DEV}" PROJECTMK=${PROJECTMK} BOARD=${BOARD} MXC_OPTIMIZE_CFLAGS=${CORDIO_OPTIMIZE_CFLAGS} + CFG_DEV="${CFG_DEV}" PROJECTMK=${PROJECTMK} BOARD=${BOARD} MXC_OPTIMIZE_CFLAGS=${CORDIO_OPTIMIZE_CFLAGS} \ + BT_VER=${BT_VER} clean.cordio: diff --git a/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_uart.c b/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_uart.c index 1335481b84..61b0c723aa 100644 --- a/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_uart.c +++ b/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_uart.c @@ -82,37 +82,51 @@ static struct { * \return None. */ /*************************************************************************************************/ +void UART_CommonHandler(mxc_uart_regs_t *uart) +{ + const int32_t err = MXC_UART_AsyncHandler(uart); + + if(err == E_INVALID) + { + // If the uart is the console, we can try to recover since it is not critical + if(MXC_UART_GET_IDX(uart) == CONSOLE_UART) + { + MXC_UART_ClearRXFIFO(uart); + } + else + { + PAL_SYS_ASSERT(err == E_NO_ERROR); + } + } + +} void UART0_IRQHandler(void) { - int result0; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result0 = MXC_UART_AsyncHandler(MXC_UART0); - (void)result0; - PAL_SYS_ASSERT(result0 == 0); + UART_CommonHandler(MXC_UART0); + } void UART1_IRQHandler(void) { - int result1; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result1 = MXC_UART_AsyncHandler(MXC_UART1); - (void)result1; - PAL_SYS_ASSERT(result1 == 0); + UART_CommonHandler(MXC_UART1); + } void UART2_IRQHandler(void) -{ - int result2; +{ + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result2 = MXC_UART_AsyncHandler(MXC_UART2); - (void)result2; - PAL_SYS_ASSERT(result2 == 0); + UART_CommonHandler(MXC_UART2); + } void UART3_IRQHandler(void) { - int result3; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result3 = MXC_UART_AsyncHandler(MXC_UART3); - (void)result3; - PAL_SYS_ASSERT(result3 == 0); + UART_CommonHandler(MXC_UART3); + } /*************************************************************************************************/ @@ -159,6 +173,8 @@ void RISCV_IRQHandler(void) /*************************************************************************************************/ void palUartCallback(mxc_uart_req_t* req, int error) { + + int i; for(i = 0; i < PAL_UARTS; i++) { /* Find the corresponding rqeuest and call the callback */ diff --git a/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_uart.c b/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_uart.c index 1335481b84..139a4262fb 100644 --- a/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_uart.c +++ b/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_uart.c @@ -82,37 +82,51 @@ static struct { * \return None. */ /*************************************************************************************************/ +void UART_CommonHandler(mxc_uart_regs_t *uart) +{ + const int32_t err = MXC_UART_AsyncHandler(uart); + + if(err == E_INVALID) + { + // If the uart is the console, we can try to recover since it is not critical + if(MXC_UART_GET_IDX(uart) == CONSOLE_UART) + { + MXC_UART_ClearRXFIFO(uart); + } + else + { + PAL_SYS_ASSERT(err == E_NO_ERROR); + } + } + +} void UART0_IRQHandler(void) { - int result0; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result0 = MXC_UART_AsyncHandler(MXC_UART0); - (void)result0; - PAL_SYS_ASSERT(result0 == 0); + UART_CommonHandler(MXC_UART0); + } void UART1_IRQHandler(void) { - int result1; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result1 = MXC_UART_AsyncHandler(MXC_UART1); - (void)result1; - PAL_SYS_ASSERT(result1 == 0); + UART_CommonHandler(MXC_UART1); + } void UART2_IRQHandler(void) { - int result2; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result2 = MXC_UART_AsyncHandler(MXC_UART2); - (void)result2; - PAL_SYS_ASSERT(result2 == 0); + UART_CommonHandler(MXC_UART2); + } void UART3_IRQHandler(void) { - int result3; + PalLedOn(PAL_LED_ID_CPU_ACTIVE); - result3 = MXC_UART_AsyncHandler(MXC_UART3); - (void)result3; - PAL_SYS_ASSERT(result3 == 0); + UART_CommonHandler(MXC_UART3); + } /*************************************************************************************************/ diff --git a/Libraries/Cordio/wsf/sources/targets/freertos/wsf_timer.c b/Libraries/Cordio/wsf/sources/targets/freertos/wsf_timer.c index 84654c692e..d539d7f183 100644 --- a/Libraries/Cordio/wsf/sources/targets/freertos/wsf_timer.c +++ b/Libraries/Cordio/wsf/sources/targets/freertos/wsf_timer.c @@ -21,10 +21,11 @@ * limitations under the License. */ /*************************************************************************************************/ +#include "wsf_timer.h" +#include #include "wsf_types.h" #include "wsf_queue.h" -#include "wsf_timer.h" #include "wsf_assert.h" #include "wsf_cs.h" @@ -36,22 +37,20 @@ #include "timers.h" #include "queue.h" -#include - -#if ( configUSE_TIMERS != 1 ) +#if (configUSE_TIMERS != 1) #error Enable timers in FreeRTOSConfig.h by definiing configUSE_TIMERS as 1 #endif typedef struct TimerStruct { - struct TimerStruct *next; - struct TimerStruct *prev; - wsfTimer_t *wsfTimerStruct; - TimerHandle_t tmr; + struct TimerStruct *next; + struct TimerStruct *prev; + wsfTimer_t *wsfTimerStruct; + TimerHandle_t tmr; } TimerStruct_t; typedef struct TimerList { - TimerStruct_t *head; - TimerStruct_t *tail; + TimerStruct_t *head; + TimerStruct_t *tail; } TimerList_t; static TimerList_t s_timers = { NULL, NULL }; @@ -59,131 +58,132 @@ static QueueHandle_t s_queue = NULL; void prvTimerCallback(TimerHandle_t xTimer) { - WsfCsEnter(); - TimerStruct_t *firedTimer = NULL; - for (TimerStruct_t *ts = s_timers.head; ts != NULL; ts = ts->next) { - if (ts->tmr == xTimer) { - firedTimer = ts; - break; + WsfCsEnter(); + TimerStruct_t *firedTimer = NULL; + for (TimerStruct_t *ts = s_timers.head; ts != NULL; ts = ts->next) { + if (ts->tmr == xTimer) { + firedTimer = ts; + break; + } } - } - if (firedTimer) { - /* Get the timer handler */ - wsfHandlerId_t handler = firedTimer->wsfTimerStruct->handlerId; - if (!xQueueSend(s_queue, &firedTimer->wsfTimerStruct, portMAX_DELAY)) { - WSF_ASSERT(0); + if (firedTimer) { + /* Get the timer handler */ + wsfHandlerId_t handler = firedTimer->wsfTimerStruct->handlerId; + if (!xQueueSend(s_queue, &firedTimer->wsfTimerStruct, portMAX_DELAY)) { + WSF_ASSERT(0); + } + WsfTaskSetReady(handler, WSF_TIMER_EVENT); + firedTimer->wsfTimerStruct->isStarted = FALSE; + } else { + /* Timer not found */ + WSF_ASSERT(0); } - WsfTaskSetReady(handler, WSF_TIMER_EVENT); - firedTimer->wsfTimerStruct->isStarted = FALSE; - } else { - /* Timer not found */ - WSF_ASSERT(0); - } - WsfCsExit(); + WsfCsExit(); } void WsfTimerInit(void) { - s_queue = xQueueCreate(configTIMER_QUEUE_LENGTH, sizeof(wsfTimer_t*)); + s_queue = xQueueCreate(configTIMER_QUEUE_LENGTH, sizeof(wsfTimer_t *)); } void WsfTimerStartMs(wsfTimer_t *pTimer, wsfTimerTicks_t ms) { - WsfCsEnter(); - /* Look if there is existing timer */ - TimerStruct_t *existingTimer = NULL; - for (TimerStruct_t *ts = s_timers.head; ts != NULL; ts = ts->next) { - if (ts->wsfTimerStruct == pTimer) { - existingTimer = ts; - break; + WsfCsEnter(); + /* Look if there is existing timer */ + TimerStruct_t *existingTimer = NULL; + for (TimerStruct_t *ts = s_timers.head; ts != NULL; ts = ts->next) { + if (ts->wsfTimerStruct == pTimer) { + existingTimer = ts; + break; + } } - } - uint32_t ticks = pdMS_TO_TICKS(ms); - if (existingTimer) { - if (ticks != pTimer->ticks) { - /* Update timer interval */ - xTimerChangePeriod(existingTimer->tmr, ticks, 0); - } - /* Restart the existing timer */ - pTimer->isStarted = xTimerReset(existingTimer->tmr, 0); - } else { - TimerHandle_t tmr = xTimerCreate(NULL, ticks, - pdFALSE, - NULL, prvTimerCallback); - pTimer->isStarted = xTimerStart(tmr, 0); - - TimerStruct_t *ts = (TimerStruct_t*) WsfBufAlloc( - sizeof(TimerStruct_t)); - memset(ts, 0, sizeof(TimerStruct_t)); - ts->wsfTimerStruct = pTimer; - ts->tmr = tmr; - ts->wsfTimerStruct->ticks = ticks; - if (s_timers.tail) { - /* Append to the list end */ - TimerStruct_t *prev = s_timers.tail; - prev->next = ts; - ts->prev = prev; - s_timers.tail = ts; + uint32_t ticks = pdMS_TO_TICKS(ms); + if (existingTimer) { + if (ticks != pTimer->ticks) { + /* Update timer interval */ + xTimerChangePeriod(existingTimer->tmr, ticks, 0); + } + /* Restart the existing timer */ + pTimer->isStarted = xTimerReset(existingTimer->tmr, 0); } else { - /* Create first element */ - s_timers.head = ts; - s_timers.tail = ts; + TimerHandle_t tmr = xTimerCreate(NULL, ticks, pdFALSE, NULL, prvTimerCallback); + pTimer->isStarted = xTimerStart(tmr, 0); + + TimerStruct_t *ts = (TimerStruct_t *)WsfBufAlloc(sizeof(TimerStruct_t)); + memset(ts, 0, sizeof(TimerStruct_t)); + ts->wsfTimerStruct = pTimer; + ts->tmr = tmr; + ts->wsfTimerStruct->ticks = ticks; + if (s_timers.tail) { + /* Append to the list end */ + TimerStruct_t *prev = s_timers.tail; + prev->next = ts; + ts->prev = prev; + s_timers.tail = ts; + } else { + /* Create first element */ + s_timers.head = ts; + s_timers.tail = ts; + } } - } - WsfCsExit(); + WsfCsExit(); } void WsfTimerStartSec(wsfTimer_t *pTimer, wsfTimerTicks_t sec) { - WsfTimerStartMs(pTimer, sec * 1000); + WsfTimerStartMs(pTimer, sec * 1000); } void WsfTimerStop(wsfTimer_t *pTimer) { - WsfCsEnter(); - TimerStruct_t *itemToRemove = NULL; - for (TimerStruct_t *ts = s_timers.head; ts != NULL; ts = ts->next) { - if (ts->wsfTimerStruct == pTimer) { - itemToRemove = ts; - break; + WsfCsEnter(); + TimerStruct_t *itemToRemove = NULL; + for (TimerStruct_t *ts = s_timers.head; ts != NULL; ts = ts->next) { + if (ts->wsfTimerStruct == pTimer) { + itemToRemove = ts; + break; + } } - } - if (itemToRemove) { - /* Delete the timer and its list item */ - xTimerStop(itemToRemove->tmr, portMAX_DELAY); - xTimerDelete(itemToRemove->tmr, portMAX_DELAY); - TimerStruct_t *prev = itemToRemove->prev; - TimerStruct_t *next = itemToRemove->next; - if (prev) { - prev->next = next; + if (itemToRemove) { + /* Delete the timer and its list item */ + xTimerStop(itemToRemove->tmr, portMAX_DELAY); + xTimerDelete(itemToRemove->tmr, portMAX_DELAY); + TimerStruct_t *prev = itemToRemove->prev; + TimerStruct_t *next = itemToRemove->next; + if (prev) { + prev->next = next; + } else { + /* Removing head */ + s_timers.head = NULL; + } + if (next) { + next->prev = prev; + } + + /* Update Head if NULL / was removed */ + if (s_timers.head == NULL) { + s_timers.head = next; + } + + /* Update tail if removing tail */ + if (s_timers.tail == itemToRemove) { + s_timers.tail = prev; + } + + itemToRemove->wsfTimerStruct->isStarted = FALSE; + WsfBufFree(itemToRemove); } else { - /* Removing head */ - s_timers.head = NULL; - s_timers.tail = NULL; - } - if (next) { - next->prev = prev; - } - - /* Update tail if removing tail */ - if(s_timers.tail == itemToRemove) { - s_timers.tail = prev; + /* Timer not found; */ } - - itemToRemove->wsfTimerStruct->isStarted = FALSE; - WsfBufFree(itemToRemove); - } else { - /* Timer not found; */ - } - WsfCsExit(); + WsfCsExit(); } -wsfTimer_t* WsfTimerServiceExpired(wsfTaskId_t taskId) +wsfTimer_t *WsfTimerServiceExpired(wsfTaskId_t taskId) { - wsfTimer_t *tmr; - if (xQueueReceive(s_queue, &tmr, 0)) { - return tmr; - } - return NULL; + wsfTimer_t *tmr; + if (xQueueReceive(s_queue, &tmr, 0)) { + return tmr; + } + return NULL; } diff --git a/Libraries/PeriphDrivers/Source/TMR/tmr_me16.c b/Libraries/PeriphDrivers/Source/TMR/tmr_me16.c index 469531f866..901344e360 100644 --- a/Libraries/PeriphDrivers/Source/TMR/tmr_me16.c +++ b/Libraries/PeriphDrivers/Source/TMR/tmr_me16.c @@ -25,14 +25,14 @@ int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins) { - uint8_t tmr_id; + uint8_t tmr_id = MXC_TMR_GET_IDX(tmr); uint8_t clockSource = MXC_TMR_CLK0; if (cfg == NULL) { return E_NULL_PTR; } - MXC_ASSERT((tmr_id = MXC_TMR_GET_IDX(tmr)) >= 0); + MXC_ASSERT(tmr_id >= 0); switch (cfg->clock) { case MXC_TMR_EXT_CLK: