rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
{
rt_base_t level;
/* parameter check */
RT_ASSERT(sem != RT_NULL);
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
if (cmd == RT_IPC_CMD_RESET)
{
rt_ubase_t value;
/* get value */
value = (rt_ubase_t)arg;
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* resume all waiting thread */
_ipc_list_resume_all(&sem->parent.suspend_thread);
/* set new value */
sem->value = (rt_uint16_t)value;
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_schedule();
return RT_EOK;
}
return -RT_ERROR;
}
RTM_EXPORT(rt_sem_control);
注意 arg这个参数是void *类型,当需要将信号量复位为0时需要写成如下格式:
rt_sem_control(sys_g.mi.sem_tdat_rf, RT_IPC_CMD_RESET, (void*)0);
不可写为:
rt_sem_control(sys_g.mi.sem_tdat_rf, RT_IPC_CMD_RESET, 0);
否则鬼知道0地址处会有些什么东西去运行。