各位大神,我今天刚学到信号量,写了一个小程序,建立两个任务,分别使两个小灯闪烁。我想创建一个信号量,我看到书上解释说OSSemCreate()函数中给OS_SEM_CTR这个参数赋的值就是信号量的初始值,我在程序中给它赋值为2,可是我用串口打印出sem_led1->Ctr的值是0呢? 是我这个函数的写法不对还是怎么回事? 在线等,急急急!!!!
#include "app.h"
#include "bsp.h"
OS_TCB LED1_TCB;
static CPU_STK LED1_Stk[128];
OS_TCB LED2_TCB;
static CPU_STK LED2_Stk[128];
OS_SEM *sem_led1;
int main(void)
{
OS_ERR err;
BSP_Init();
OSInit(&err);
OSSemCreate ((OS_SEM *)sem_led1,
(CPU_CHAR *)"led1",
(OS_SEM_CTR )2,
(OS_ERR *)&err);
OSTaskCreate ((OS_TCB *)&LED1_TCB,
(CPU_CHAR *)"LED1",
(OS_TASK_PTR )Task_LED1,
(void *)0,
(OS_PRIO )2,
(CPU_STK *)&LED1_Stk[0],
(CPU_STK_SIZE )12,
(CPU_STK_SIZE )128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR *)&err);
OSTaskCreate ((OS_TCB *)&LED2_TCB,
(CPU_CHAR *)"LED2",
(OS_TASK_PTR )Task_LED2,
(void *)0,
(OS_PRIO )3,
(CPU_STK *)&LED2_Stk[0],
(CPU_STK_SIZE )12,
(CPU_STK_SIZE )128,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void *)0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR *)&err);
printf("\r\n%d",sem_led1->Ctr);
OSStart(&err);
} |