事件标志组(信号量集)的使用:
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)