void Task0_Usart (void *pdata)
{
pdata = pdata; /* Prevent compiler warning */
INT8U err;
WDTCTL = WDT_MDLY_32; /* Set time tick 32 mS */
IE1 |= 0x01; /* Enable Watchdog timer interrupts */
BSP_CLK_Init();
BSP_UART_Init();
//OSTaskCreate(Task1_Usart, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], 5);
while (1)
{
err=OSSemPost(DispSem); //发Sem
switch(err)
{
case OS_NO_ERR:
{
P4DIR=0XFF;
P4OUT=0X05;
TXBUF1 = 0x30; //成功 发0
}; break;
case OS_SEM_OVF:
{
P4DIR=0XFF;
P4OUT=0X0A;
}; break; //溢出 LED显示00001010
case OS_ERR_EVENT_TYPE:
{
P4DIR=0XFF;
P4OUT=0X07; //不是信号量 00000111
}; break;
case OS_ERR_PEVENT_NULL:
{
P4DIR=0XFF; //空指针 00001111
P4OUT=0X0F;
}; break;
}
OSTimeDly(30);
}
}
void Task1_Usart(void *pdata) //接Sem
{
pdata = pdata;
INT16U Value;
WDTCTL = WDT_MDLY_32; /* Set time tick 32 mS */
IE1 |= 0x01; /* Enable Watchdog timer interrupts */
while (1)
{
Value = OSSemAccept(DispSem);
if(Value>0)
{
P4DIR=0XFF;
P4OUT=0X50;
TXBUF1 = 0x31;
}
OSTimeDly(50);
}
}
以上输出:1010010.......
OS_EVENT *DispSem;
#define TASK_STK_SIZE 256 /* Size of each task's stacks (# of OS_STK entries) */
OS_STK Task0Stk[TASK_STK_SIZE];
OS_STK Task1Stk[TASK_STK_SIZE];
OS_STK Task2Stk[TASK_STK_SIZE];
OS_STK Task3Stk[TASK_STK_SIZE];
void Task0_Usart(void *pdata); /* Function prototypes of Startup task */
void Task1_Usart(void *pdata);
void Task2_Usart(void *pdata); /* Led Display */
void Task3_Usart(void *pdata);
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
// INT8U err;
OSInit(); /* Initialize uC/OS-II */
DispSem = OSSemCreate(1);
//OSTaskCreate(Task0_Usart, (void *)0, &Task0Stk[TASK_STK_SIZE - 1], 4);
//OSTaskCreate(Task1_Usart, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], 6);
//OSTaskCreate(Task2_Usart, (void *)0, &Task2Stk[TASK_STK_SIZE - 1], 8);
OSTaskCreate(Task3_Usart, (void *)0, &Task3Stk[TASK_STK_SIZE - 1], 10);
OSStart(); /* Start multitasking */
}
void Task0_Usart (void *pdata)
{
pdata = pdata; /* Prevent compiler warning */
INT8U err;
WDTCTL = WDT_MDLY_32; /* Set time tick 32 mS */
IE1 |= 0x01; /* Enable Watchdog timer interrupts */
BSP_CLK_Init();
BSP_UART_Init();
//OSTaskCreate(Task1_Usart, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], 5);
while (1)
{
err=OSSemPost(DispSem); //发Sem
switch(err)
{
case OS_NO_ERR:
{
P4DIR=0XFF;
P4OUT=0X05;
TXBUF1 = 0x30; //成功 发0
}; break;
case OS_SEM_OVF:
{
P4DIR=0XFF;
P4OUT=0X0A;
}; break; //溢出 LED显示00001010
case OS_ERR_EVENT_TYPE:
{
P4DIR=0XFF;
P4OUT=0X07; //不是信号量 00000111
}; break;
case OS_ERR_PEVENT_NULL:
{
P4DIR=0XFF; //空指针 00001111
P4OUT=0X0F;
}; break;
}
OSTimeDly(20);
}
}
void Task1_Usart(void *pdata) //接Sem
{
pdata = pdata;
INT16U Value;
WDTCTL = WDT_MDLY_32; /* Set time tick 32 mS */
IE1 |= 0x01; /* Enable Watchdog timer interrupts */
//OSTaskCreate(Task2_Usart, (void *)0, &Task2Stk[TASK_STK_SIZE - 1], 8);
while (1)
{
Value = OSSemAccept(DispSem);
if(Value>0)
{
P4DIR=0XFF;
P4OUT=0X50;
TXBUF1 = 0x31;
}
OSTimeDly(40);
}
}
以上是OSSem的全部代码:在main主函数里改变//Usart会输出不同的十进制。
问题:
OSTaskCreate(Task0_Usart, (void *)0, &Task0Stk[TASK_STK_SIZE - 1], 4);
OSTaskCreate(Task1_Usart, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], 6);
OSTaskCreate(Task2_Usart, (void *)0, &Task2Stk[TASK_STK_SIZE - 1], 8);
OSTaskCreate(Task3_Usart, (void *)0, &Task3Stk[TASK_STK_SIZE - 1], 10);
全部打开 无输出: