|
本帖最后由 shxsxlh 于 2021-9-2 10:53 编辑
c6748 EVM开发板的Semaphore_Binary,例程中添加了运行信息的打印代码,从打印信息来看,信号量为0时,此时TaskCoreLED2被挂起,但是依然会执行TaskCoreLED2中的语句,这是为什么?
Int main()
{
PSCInit(); // 外设使能配置
GPIOBankPinMuxSet(); // 管脚复用配置
GPIOBankPinInit(); // GPIO 管脚初始化
Semaphore_Params semParams; // 创建一个信号量
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
sem = Semaphore_create(1, &semParams, NULL);
Task_Params taskParams; // 创建两个任务
Task_Params_init(&taskParams);
taskParams.priority = 1;
tsk1 = Task_create(TaskCoreLED1, &taskParams, NULL);
Task_Params_init(&taskParams);
taskParams.priority = 2;
tsk2 = Task_create(TaskCoreLED2, &taskParams, NULL);
BIOS_start(); // 启动 SYS/BIOS 系统
return(0);
}
// 任务线程TaskCoreLED2,优先级为2
Void TaskCoreLED2(UArg a0, UArg a1)
{
while(1)
{
if(Semaphore_getCount(sem) == 0)
{
System_printf("TaskCoreLED2 任务被挂起\n");
}
System_printf("TaskCoreLED2 任务 计数值(之前):%d\n", Semaphore_getCount(sem));
// 挂起
Semaphore_pend(sem, BIOS_WAIT_FOREVER);
System_printf("TaskCoreLED2 任务 计数值(之后):%d\n", Semaphore_getCount(sem));
System_flush();
// LED 闪烁
unsigned char i;
for(i = 0; i < 2; i++)
{
GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_HIGH);
Delay(0x01FFFFFF);
GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_LOW);
Delay(0x01FFFFFF);
System_printf("TaskCoreLED2----LED2 twinkle count is :%d\n", i);
System_flush();
}
// 发布
Semaphore_post(sem);
System_printf("TaskCoreLED2----Semaphore_post\n");
System_flush();
// 休眠以允许低优先级任务执行
Task_sleep(100);
}
}
// 任务线程TaskCoreLED1,优先级为1
Void TaskCoreLED1(UArg a0, UArg a1)
{
while(1)
{
if(Semaphore_getCount(sem) == 0)
{
System_printf("TaskCoreLED1 任务被挂起\n");
}
System_printf("TaskCoreLED1 任务 计数值(之前):%d\n", Semaphore_getCount(sem));
// 挂起
Semaphore_pend(sem, BIOS_WAIT_FOREVER);
System_printf("TaskCoreLED1 任务 计数值(之后):%d\n", Semaphore_getCount(sem));
System_flush();
// LED 闪烁
unsigned char i;
for(i = 0; i < 5; i++)
{
GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_HIGH);
Delay(0x000FFFFF);
GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_LOW);
Delay(0x000FFFFF);
System_printf("TaskCoreLED1----LED1 twinkle count is :%d\n", i);
System_flush();
}
// 发布
Semaphore_post(sem);
System_printf("TaskCoreLED1----Semaphore_post\n");
System_flush();
}
}
|
|