Chinaunix首页 | 论坛 | 博客
  • 博客访问: 275584
  • 博文数量: 39
  • 博客积分: 1215
  • 博客等级: 军士长
  • 技术积分: 471
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-17 19:34
个人简介

grace under pressure

文章分类

全部博文(39)

文章存档

2013年(6)

2012年(28)

2011年(5)

分类: C/C++

2013-12-25 13:15:32

软件平台:CCS V5.4.0

硬件平台:SEED-DEC5502

说明:创建工程见“DspBios V542_CSL LED测试程序1”,该工程是基于DspBios V5.4.2.01.09例程mail

 

说明:

邮箱(不用我们平时用的邮箱)是用来做任务同步的,可以进行任务之间的切换。对于使用过操作系统的人,应该比较清楚,我不做详细叙述。

 

DSP/BIOS中邮箱机制,有这样一个结构体

typedef struct MsgObj {

    Int         id;             /* writer task id */

    Char        val;            /* message value */

} MsgObj, *Msg;

通过英文注释也能比较清楚的了解,一个是邮箱发送者的id号,一个是邮箱发送过来的消息。具体使用见附件的代码。

 

工程设置的步骤:

A、              双击打开mailbox.tcf,在TSK中删除writer1以及writer2任务,同时修改writer0的优秀级为2,使优先级高于reader任务(上面的修改是为了更好的帮助我们理解)

B、              关闭tcf配置窗口,并再修改mailbox.c文件为附件中内容,并在工程的Properties中将CSL库文件的路径添加进去,见附图1

C、              下载运行,调用RAW Logs查看输出结果,记住选择查看trace的输出结果(这样比较清晰),见附图2

注意:完成步骤E后运行会提示#35 #error NO CHIP DEFINED,解决方法为:选择工程,右击选择Properties,然后Build->C5500 Compiler->Advanced Options->Predefined Symbols中添加"CHIP_5502"

附件:


点击(此处)折叠或打开

  1. #include <std.h>

  2. #include <log.h>
  3. #include <mbx.h>
  4. #include <tsk.h>

  5. #include "mailboxcfg.h"


  6. #define NUMMSGS 2 /* number of messages */

  7. #define TIMEOUT 10

  8. typedef struct MsgObj {
  9.     Int id; /* writer task id */
  10.     Char val; /* message value */
  11. } MsgObj, *Msg;


  12. Void reader(Void);
  13. Void writer(Arg id_arg);

  14. /*
  15.  * ======== main ========
  16.  */
  17. Void main()
  18. {
  19.     /* Does nothing */
  20. }

  21. /*
  22.  * ======== reader ========
  23.  */
  24. Void reader(Void)
  25. {
  26.     MsgObj msg;
  27.     Int i;

  28.     for (i=0; ;i++) {

  29.         /* wait for mailbox to be posted by writer() */
  30.         if (MBX_pend(&mbx, &msg, TIMEOUT) == 0) {
  31.             LOG_printf(&trace, "timeout expired for MBX_pend()");
  32.             break;
  33.         }

  34.         /* print value */
  35.         LOG_printf(&trace, "read '%c' from (%d).", msg.val, msg.id);
  36.     }
  37.     LOG_printf(&trace, "reader done.");
  38. }

  39. /*
  40.  * ======== writer ========
  41.  */
  42. Void writer(Arg id_arg)
  43. {
  44.     MsgObj msg;
  45.     Int i;
  46.     Int id = ArgToInt (id_arg);

  47.     for (i=0; i < NUMMSGS; i++) {
  48.         /* fill in value */
  49.         msg.id = id;
  50.         msg.val = i % NUMMSGS + (Int)('a');

  51.         /* enqueue message */
  52.         MBX_post(&mbx, &msg, TIMEOUT);
  53.        
  54.         LOG_printf(&trace, "(%d) writing '%c' ...", id, (Int)msg.val);

  55.         /* what happens if you call TSK_yield() here? */
  56.         /* TSK_yield(); */
  57.     }

  58.     LOG_printf(&trace, "writer (%d) done.", id);
  59. }

附图


附图1

附图2


阅读(6475) | 评论(0) | 转发(0) |
0

上一篇:DspBios V542笔记(三) CSL LED测试程序3

下一篇:没有了

给主人留下些什么吧!~~