简单示例程序
下面是采用实时嵌入式操作系统SmallRTOS实现的多任务处理演示示例,主要包括任务创建、信号量创建、任务延时等功能。代码如下:
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职称计算机考试书PowerPoint2007中 .. 定价:¥45 优惠价:¥42 更多书籍 | |
2015年全国职称计算机考试教材(2007模 .. 定价:¥225 优惠价:¥213 更多书籍 |