码迷,mamicode.com
首页 > 其他好文 > 详细

一个简单的多任务程序

时间:2017-06-12 13:11:37      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:init   target   ati   highlight   ack   logs   func   work   lease   

转载请注明原文链接,http://www.cnblogs.com/flyingcloude/p/6992048.html
vxworks 一个简单的模拟收发数据的多任务程序
#include "vxWorks.h"
#include "semLib.h"
#include "taskLib.h"
#include "stdio.h"
#include "stdlib.h"
#include "sysLib.h"

#define STACK_SIZE 2000    /* Task Stack‘s size = 2000byte */

/*global variable*/
SEM_ID dataSemId;     /*synchronism semphore*/
int tidSend;        /*Send Task‘s Id*/
int tidReceive;        /*Receive Task‘s Id*/

/*function declaration*/
void progStart();
void taskSend();
void taskReceive();
void SendInit();
void ReceiveInit();
void progStop();


/******************************************************************
 *progStart - Start program
 *it is used to create "Send Task" and "Receive Task", and begin to run
 *Return: N/A
 ******************************************************************/

void progStart()
{
    /*create semphore*/
    dataSemId = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
    
    /*create Task*/
    tidSend = taskSpawn("tSend", 200, 0, STACK_SIZE, (FUNCPTR)taskSend, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    tidReceive = taskSpawn("tReceive", 220, 0, STACK_SIZE, (FUNCPTR)taskReceive, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    return;
}

/*****************************************************************
 *taskSend - Send data
 *release semphore(dataSemId) every two second, used to simulate the receipt of data
 */
void taskSend()
{
    /*Send Task‘s init*/
    SendInit();
    
    /* main Loop*/
    while(true)
    {
        /*two second‘s delay*/
        taskDelay(sysClkRateGet() * 2);
        semGive(dataSemId);
    }
    return;
}

/****************************************************************
 *taskReceive - receive data
 *wait semphore(dataSemId)
 */

void taskReceive()
{
    /*Receive Task‘s init*/
    ReceiveInit();
    /*main Loop*/
    while(true)
    {
        /*wait semphore*/
        semTake(dataSemId, WAIT_FOREVER);
        printf("\nReceive a data");
    }
    return;
}

/****************************************************************
 *SendInit - init send Task
 */
void SendInit()
{
    printf("\nInitial Send Task");
    return;
}

/*****************************************************************
 *ReceiveInit - init Receive Task
 */
void ReceiveInit()
{
    printf("\nInitial Receive Task");
    return;
}

/****************************************************************
 *progStop - stop program
 *delete semphore,delete task, then stop program
 */
void progStop()
{
    /*delete semphore*/
    semDelete(dataSemId);
    
    /*delete task*/
    taskDelete(tidSend);
    taskDelete(tidReceive);
    
    printf("The End\n");
    return;
}
 
PS:
  tt():显示一个任务的函数栈的调用状态,参数为某个任务的name或者ID
  ts():挂起某个任务。参数为某个任务的name或者ID
  tr():恢复某个任务。参数为某个任务的name或者ID
  td():删除某个任务。参数为某个任务的name或者ID

  转载请注明原文链接,http://www.cnblogs.com/flyingcloude/p/6992048.html

 

一个简单的多任务程序

标签:init   target   ati   highlight   ack   logs   func   work   lease   

原文地址:http://www.cnblogs.com/flyingcloude/p/6992048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!