优化代码,修改 FALLTHROUGH 宏定义,增加递归互斥锁支持,改进调度器挂起和恢复逻辑,增强命令查找功能

This commit is contained in:
LokLiang
2025-05-20 09:00:06 +08:00
parent 66f799bd1c
commit 499994b239
6 changed files with 104 additions and 63 deletions

View File

@@ -6,7 +6,7 @@ os_state os_mutex_create(os_mutex_t *mutex)
{
OS_ASS_HDL(!os_mutex_is_valid(mutex), mutex->handle);
mutex->handle = xSemaphoreCreateMutex();
mutex->handle = xSemaphoreCreateRecursiveMutex();
if (mutex->handle == NULL)
{
OS_ERR("err %p\r\n", mutex->handle);
@@ -31,7 +31,7 @@ os_state os_mutex_lock(os_mutex_t *mutex, os_time_t wait_ms)
OS_ASS_HDL(os_mutex_is_valid(mutex), mutex->handle);
ret = xSemaphoreTake(mutex->handle, os_calc_msec_to_ticks(wait_ms));
ret = xSemaphoreTakeRecursive(mutex->handle, os_calc_msec_to_ticks(wait_ms));
if (ret != pdPASS)
{
OS_DBG("%s() fail @ %d, %u ms\n", __func__, __LINE__, wait_ms);
@@ -47,7 +47,7 @@ os_state os_mutex_unlock(os_mutex_t *mutex)
OS_ASS_HDL(os_mutex_is_valid(mutex), mutex->handle);
ret = xSemaphoreGive(mutex->handle);
ret = xSemaphoreGiveRecursive(mutex->handle);
if (ret != pdPASS)
{
OS_DBG("%s() fail @ %d\n", __func__, __LINE__);

View File

@@ -27,14 +27,7 @@ void os_int_exit(void)
bool os_is_isr_context(void)
{
if (int_flag)
{
return true;
}
else
{
return false;
}
return xPortInIsrContext() || (int_flag > 0);
}
void os_interrupt_disable(void)
@@ -49,12 +42,22 @@ void os_interrupt_enable(void)
void os_scheduler_suspend(void)
{
// 在进入临界区前检查是否在中断上下文中
if (os_is_isr_context())
{
OS_ERR("Called in isr"); // 在中断中不要挂起调度器,可能会导致死锁
return;
}
vTaskSuspendAll();
}
void os_scheduler_resume(void)
{
xTaskResumeAll();
// 只有在非中断上下文中才恢复调度器
if (!os_is_isr_context())
{
xTaskResumeAll();
}
}
bool os_scheduler_is_running(void)