登录 免费注册 首页 | 行业黑名单 | 帮助
维库电子市场网
技术交流 | 电路欣赏 | 工控天地 | 数字广电 | 通信技术 | 电源技术 | 测控之家 | EMC技术 | ARM技术 | EDA技术 | PCB技术 | 嵌入式系统
驱动编程 | 集成电路 | 器件替换 | 模拟技术 | 新手园地 | 单 片 机 | DSP技术 | MCU技术 | IC 设计 | IC 产业 | CAN-bus/DeviceNe

菜鸟请教实时操作系统概念性问题

作者:艾森豪威尔 栏目:嵌入式系统
菜鸟请教实时操作系统概念性问题
消息队列的问题:
有两个任务:RECEIVER()从消息队列接收消息,优先级为5,sender()向消息队列存消息,优先级为7。
函数TestMessage()负责creat 消息队列以及这两个任务,先创建消息队列,然后分别创建RECEIVER()和sender()。其中有一段代码是把当前任务优先级设置为4,我不明其意。请高手帮我看看,解答一下,好吗?

代码如下:
#define NO_USER_TASKS 3
#define MESSAGE_LENGTH 40
#define NUM_OF_MESSAGES 3
#define SENDER_DELAY 7000

message_queue_t *qid_RECEIVER;//消息队列

/* Structure used to pass arguments to sender tasks */
struct msg_s {
        CHAR data[MESSAGE_LENGTH];
        CHAR *tag;
};

/* data associated to sender tasks */
struct sender_data_s {
        CHAR *NAME;
};

/* messages sent */
static CHAR *messages[] = { "first message", "second message", "third message" };

/* Start OS20 */
void os20start( void )
{

        device_id_t    devid = device_id();

        /*  welcome to OS20 */
        printf ("******** Start of Messages Practical ********\n");
        printf("OS20 version %s\n", kernel_version());
        printf("DEVICE %x (%s)\n\n", devid.id, device_NAME(devid));

        printf("Kernel Started: Main running at OS20 priority %d\n\n\n", task_priority(NULL));

}


/* RECEIVER code */
void RECEIVER( void )
{
        struct msg_s *msg;
        int i;

        printf( "RECEIVER running...\n");
        for (i=0; i< ( NUM_OF_MESSAGES *2 ); i++ ) {
        //接收消息,如果没有,则任务阻塞
                msg = (struct msg_s *) message_receive(qid_RECEIVER);
            printf( "received message from %s sender, content: \"%s\"\n\n", msg->tag, msg->data);
                message_release(qid_RECEIVER, (void *)msg);
        }
}

/* sender code */
void sender( void )
{
        struct msg_s *msg;
        int i;

      struct sender_data_s *tdata;

      tdata = (struct sender_data_s *)  task_data(NULL);

        printf( "%s sender running...\n", tdata->NAME );

        for (i = 0; i < NUM_OF_MESSAGES; i++ ) {
        //获取一块可用的消息buffer,如果没有可用的,则任务阻塞
            msg = (struct msg_s *)message_claim(qid_RECEIVER);
            strcpy( msg->data, messages[i] );
            msg->tag = tdata->NAME;
            message_send(qid_RECEIVER, (void*) msg );
            printf( "%s sender sent message %02d\n", tdata->NAME, i);
            task_delay(SENDER_DELAY);
        }
}

/* TestMessage creates a message queue, a RECEIVER task, a sender task
   and waits for them to complete */

void TestMessage(void)
{
        task_t *task, *Tasks[NO_USER_TASKS];   
        int i;

      struct sender_data_s *tdata;

        printf("TestMessage\n");

        /* create message queues */
        qid_RECEIVER = message_create_queue(sizeof(struct msg_s), NUM_OF_MESSAGES);

        /* create tasks */

        /* RECEIVER */
        task = task_create((void (*)(void* )) RECEIVER, 0, 10240, 5, "RECEIVER", 0);
        /*  check creation ok */
        if (task == NULL)
        {
          printf ("Error : create. Unable to create task structure or stack\n");
          exit (EXIT_FAILURE);
        }
        Tasks[0] = task;
        printf( "RECEIVER created\n");
        
        /* first sender */
      tdata = malloc( sizeof(struct sender_data_s));
      if ( tdata == NULL ) {
           printf( "Error: Unable to create sender data structure\n") ;
           exit( EXIT_FAILURE );    
      }
      tdata->NAME = (CHAR*) &("first");
        task = task_create( (void (*)(void*)) sender, 0, 2048, 7, "first sender", 0);
        /*  check creation ok */
        if (task == NULL)
        {
          printf ("Error : create. Unable to create task structure or stack\n");
          exit (EXIT_FAILURE);
        }
        Tasks[1] = task;
      task_data_set(Tasks[1], (void*) tdata);        
      printf( "%s sender created\n", tdata->NAME );

        /* second sender */
        tdata = malloc( sizeof(struct sender_data_s));
      if ( tdata == NULL ) {
           printf( "Error: Unable to create sender data structure\n") ;
           exit( EXIT_FAILURE );    
      }
 
参与讨论
昵称:
讨论内容:
 
 
相关帖子
填充脉冲法
关于UCGUI
怎样做才好?
uCOS下的问题
请大家指点,我要找设计方案,Intel CPU + VT8606 + VT82C686B
免费注册为维库电子开发网会员,参与电子工程师社区讨论,点此进入


Copyright © 1998-2006 www.dzsc.com 浙ICP证030469号