FreeRTOS 信号量
OSAL源码
| 文件 | 作用 |
|---|---|
| osal_sema.h | 公开接口 |
| osal_internal_sema.h | Wrapper与适配层接口 |
| osal_sema.c | 参数检查与封装 |
| os_impl_sema.c | FreeRTOS实现 |
1. 定义句柄
App/app_init/user_task_config/user_task_reso_config.h
osal_sema_handle_t data_ready_semaphore = NULL;2. 创建
App/app_init/user_task_config/user_task_reso_config.c
二值信号量:
osal_sema_binary_create(&data_ready_semaphore);计数信号量:
osal_sema_counting_create(10U, 0U, &data_ready_semaphore);3. 释放与等待
生产或等待事件的业务
.c
osal_sema_give(data_ready_semaphore);
if (osal_sema_take(data_ready_semaphore,
OSAL_WAIT_FOREVER) == OSAL_SUCCESS)
{
/* 处理事件 */
}give 和 take 在中断中调用时会自动使用 FreeRTOS FromISR 接口。
4. 删除
App/app_init/user_task_config/user_task_reso_config.c
osal_sema_delete(data_ready_semaphore);
data_ready_semaphore = NULL;