事件标志组(信号量集)的使用:
static OS_STK task_testled[STARTUP_TASK_STK_SIZE];
static OS_STK task_testluart1[STARTUP_TASK_STK_SIZE];
static OS_STK task_testluart2[STARTUP_TASK_STK_SIZE];
OS_FLAG_GRP *Sem_F = NULL; /* 定义一个信号量集指针 */
u8 err = 0;
void TestUart1 ( void *p_arg ) {
for ( ;; ) {
OSFlagPost ( Sem_F, ( OS_FLAGS ) 2, OS_FLAG_SET, &err ); /* 向信号量集发信号 */
printf ( "Uart 1 is running\r\n" );
OSTimeDlyHMSM ( 0, 0, 0, 500 );
}
}
void TestUart2 ( void *p_arg ) {
for ( ;; ) {
OSFlagPost ( Sem_F, ( OS_FLAGS ) 1, OS_FLAG_SET, &err ); /* 向信号量集发信号 */
printf ( "Uart 2 is running\r\n" );
OSTimeDlyHMSM ( 0, 0, 0, 500 );
}
}
void TestLed ( void *p_arg ) {
for ( ;; ) {
OSFlagPend ( Sem_F, ( OS_FLAGS ) 3, OS_FLAG_WAIT_SET_ALL, 0, &err ); /* 请求信号量集 */
LED0 = !LED0;
OSTimeDlyHMSM ( 0, 0, 0, 500 );
}
}
int main ( void ) {
SysTick_init();
LED_Init();
uart_init ( 9600 );
OSInit();
Sem_F = OSFlagCreate ( 0, &err );
OSTaskCreate ( TestLed, ( void * ) 0, &task_testled[STARTUP_TASK_STK_SIZE - 1], STARTUP_TASK_PRIO - 1 );
OSTaskCreate ( TestUart1, ( void * ) 0, &task_testluart1[STARTUP_TASK_STK_SIZE - 1], STARTUP_TASK_PRIO );
OSTaskCreate ( TestUart2, ( void * ) 0, &task_testluart2[STARTUP_TASK_STK_SIZE - 1], STARTUP_TASK_PRIO + 1 );
OSStart();
return 0;
}