簡單示例程序
下面是采用實(shí)時嵌入式操作系統(tǒng)SmallRTOS實(shí)現(xiàn)的多任務(wù)處理演示示例,主要包括任務(wù)創(chuàng)建、信號量創(chuàng)建、任務(wù)延時等功能。代碼如下:
OSTaskHandle_t HWTaskHandle = NULL;
OSTaskHandle_t GBTaskHandle = NULL;
OSSemHandle_t GBSemaphoreHandle = NULL;
void TaskHelloWorld( void *pvParameters );
void TaskGoodBye( void *pvParameters );
int main( void )
{
GBSemaphoreHandle = OSSemCreate();
// configure and start tasks
HWTaskHandle = OSTaskCreate(TaskHelloWorld, NULL, OSMINIMAL_STACK_SIZE, OSLOWEAST_PRIORITY+1, "HW");
GBTaskHandle = OSTaskCreate(TaskGoodBye, NULL, OSMINIMAL_STACK_SIZE, OSLOWEAST_PRIORITY+2, "GB");
/* Start the tasks and timer running. */
OSStart();
for( ;; );
return 0;
}
void TaskHelloWorld( void *pvParameters )
{
/* Remove compiler warning about unused parameter. */
( void ) pvParameters;
for( ;; )
{
OSSemPost(GBSemaphoreHandle);
OSTaskSleep(200*OSTICKS_PER_MS);
}
}
void TaskGoodBye( void *pvParameters )
{
/* Remove compiler warning about unused parameter. */
( void ) pvParameters;
for( ;; )
{
OSSemPend(GBSemaphoreHandle, OSPEND_FOREVER_VALUE);
}
}
2015職稱計算機(jī)考試書PowerPoint2007中 .. 定價:¥45 優(yōu)惠價:¥42 更多書籍 | |
2015年全國職稱計算機(jī)考試教材(2007模 .. 定價:¥225 優(yōu)惠價:¥213 更多書籍 |