[LOOK] LOOK菜鸟mbox应用例程

[复制链接]
 楼主| hotpower 发表于 2011-5-18 19:23 | 显示全部楼层 |阅读模式
本帖最后由 hotpower 于 2011-5-23 19:03 编辑

点击下载:Look_Mbox_KeyLed


1.Look_Mbox_KeyLed.h
  1. #include "look_config.h"
  2. #include <look.h>
  3. #include <instantiate>

  4. // 任务类 task_Look_Mbox_KeyLed_t 的定义
  5. class task_Look_Mbox_KeyLed_t : public task_t {
  6. public:
  7. task_Look_Mbox_KeyLed_t() __OPT_ATTR__; // 构造函数

  8. protected:
  9. void routine(); // 任务例程
  10. public:
  11. mbox_t<int> mbox;
  12. };

  13. // 任务类 task_Look_Mbox_KeyLed_t 的构造函数
  14. __OPT_INLINE__ task_Look_Mbox_KeyLed_t::task_Look_Mbox_KeyLed_t()
  15. : mbox(0)
  16. {
  17. // TODO: 在此初始化 task_Look_Mbox_KeyLed_t 的类成员
  18. }

  19. extern instantiate::task<task_Look_Mbox_KeyLed_t, LOOK_STACK_SIZE> task_Look_Mbox_KeyLed;

  20. // 任务类 task_Look_Mbox_KeyLed_t 的定义
  21. class task_Look_Mbox_Beep_t : public task_t {
  22. public:
  23. task_Look_Mbox_Beep_t() __OPT_ATTR__; // 构造函数

  24. protected:
  25. void routine(); // 任务例程

  26. public:
  27. sem_t sem; // 信号灯为Led操作提供同步
  28. };

  29. // 任务类 task_Look_Mbox_Beep_t 的构造函数
  30. __OPT_INLINE__ task_Look_Mbox_Beep_t::task_Look_Mbox_Beep_t()
  31. : sem(0)
  32. {
  33. // TODO: 在此初始化 task_Look_Mbox_KeyLed_t 的类成员
  34. }

  35. extern instantiate::task<task_Look_Mbox_Beep_t, LOOK_STACK_SIZE> task_Look_Mbox_Beep;
2.Look_Mbox_KeyLed.cpp

  1. #include "Look_Mbox_KeyLed.h"
  2. #include "NUC1xx.h"
  3. #include "NUC1xxM051Seriescfg.h"
  4. class Keyboard_t : public interrupt_t {
  5. public:
  6. Keyboard_t() __OPT_ATTR__;
  7. protected:
  8. bool isr(int vector);
  9. void dsr(int vector, uintptr_t count);
  10. };
  11. // Keyboard_t 构造函数
  12. inline Keyboard_t::Keyboard_t()
  13. {
  14. attach(EINT0_IRQn);
  15. attach(EINT1_IRQn);
  16. GPIOBs.IEN.Regs = (1 << Pin15) | (1 << Pin14);   // 开启中断
  17. vector_t::enable(EINT0_IRQn);
  18. vector_t::enable(EINT1_IRQn);
  19. }
  20. // Keyboard_t 中断服务例程
  21. bool Keyboard_t::isr(int vector)
  22. {
  23. GPIOBs.ISRC.Regs = GPIOBs.ISRC.Regs;   // 清中断 flag
  24. return true;
  25. }
  26. // Keyboard_t 中断滞后服务例程
  27. void Keyboard_t::dsr(int vector, uintptr_t count)
  28. {
  29.     task_Look_Mbox_Beep.sem.do_post();
  30. task_Look_Mbox_KeyLed.mbox.do_tryput(vector == EINT0_IRQn ? 1 : 2);  // 发送消息
  31. }
  32. Keyboard_t Key;         // 创建Key对象

  33. // 任务类 task_Look_Mbox_KeyLed_t 的例程
  34. void task_Look_Mbox_KeyLed_t::routine()
  35. {
  36. // TODO: 在此编写 task_Look_Mbox_KeyLed_t 例程的内容
  37. uint32_t data, i;
  38. while (true) {
  39.   // TODO: 在此编写 task_Look_Mbox_KeyLed_t 例程的内容
  40.   int msg = mbox.get();     // 等待邮箱消息
  41.   switch (msg) {
  42.    case 1:
  43.            data = ~0b100;
  44.      GPIOAs.DMASK.Regs = ~0b111100;
  45.      for (i = 0; i < 8; i ++){
  46.         data &= 0b111100;
  47.         data <<= 1;
  48.         data += data >> 4;
  49.         GPIOAs.DOUT.Regs = data;
  50.               delay(LOOK_TICKS_PER_SEC / 10);
  51.      }
  52.      GPIOAs.DOUT.Regs = 0b111100;
  53.        break;
  54.    case 2:
  55.            data = ~0b100000;
  56.      GPIOAs.DMASK.Regs = ~0b111100;
  57.      for (i = 0; i < 8; i ++){
  58.         data &= 0b111100;
  59.         data >>= 1;
  60.         data += data << 4;
  61.         GPIOAs.DOUT.Regs = data;
  62.               delay(LOOK_TICKS_PER_SEC / 10);
  63.      }
  64.      GPIOAs.DOUT.Regs = 0b111100;
  65.        break;
  66.   }
  67. }
  68. }
  69. // 任务类 task_Look_Mbox_Beep_t 的例程
  70. void task_Look_Mbox_Beep_t::routine()
  71. {
  72. // TODO: 在此编写 task_Look_Mbox_Beep_t 例程的内容
  73. while (true) {
  74.   // TODO: 在此编写 task_Look_Mbox_Beep_t 例程的内容
  75.   if (sem.wait())
  76.   {
  77.    GPIOBs.DMASK.Bits.Pin10 = 0;
  78.    for (uint32_t i = 0; i < 6; i ++){
  79.      GPIOBs.DOUT.Bits.Pin10 ^= 1;
  80.            delay(LOOK_TICKS_PER_SEC / 20);
  81.    }
  82.    GPIOBs.DOUT.Bits.Pin10 = 0;
  83.   }
  84. }
  85. }
  86. #ifdef LOOK_SCHEDULING_PRIORITY
  87. instantiate::task<task_Look_Mbox_KeyLed_t, LOOK_STACK_SIZE> task_Look_Mbox_KeyLed(0);
  88. instantiate::task<task_Look_Mbox_Beep_t, LOOK_STACK_SIZE> task_Look_Mbox_Beep(0);
  89. #else
  90. instantiate::task<task_Look_Mbox_KeyLed_t, LOOK_STACK_SIZE> task_Look_Mbox_KeyLed;
  91. instantiate::task<task_Look_Mbox_Beep_t, LOOK_STACK_SIZE> task_Look_Mbox_Beep;
  92. #endif

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
Swallow_0322 发表于 2011-5-18 19:28 | 显示全部楼层
沙发!大叔真勤奋!:victory:
 楼主| hotpower 发表于 2011-5-18 19:31 | 显示全部楼层
是老师的look色诱俺的~~~

明天将i2c用LOOK搞搞
murex 发表于 2011-5-18 22:19 | 显示全部楼层
菜农真勤快,干活速度很快啊
li923661521 发表于 2011-5-18 22:35 | 显示全部楼层
支持大叔!
nayaix 发表于 2011-7-23 19:18 | 显示全部楼层
顶起
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

508

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

508

粉丝
快速回复 在线客服 返回列表 返回顶部