[LOOK] LOOK菜鸟sem应用例程

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

点击下载完整的工程包:


look_keyled.h

  1. #include "look_config.h"
  2. #include <look.h>
  3. #include <instantiate>
  4. // 任务类 task_Look_KeyLed_t 的定义
  5. class task_Look_KeyLed1_t : public task_t {
  6. public:
  7. task_Look_KeyLed1_t() __OPT_ATTR__; // 构造函数

  8. protected:
  9. void routine();  // 任务例程
  10. public:
  11. sem_t sem;   // 信号灯为Led操作提供同步
  12. };
  13. // 任务类 task_Look_KeyLed_t 的构造函数
  14. __OPT_INLINE__ task_Look_KeyLed1_t::task_Look_KeyLed1_t()
  15. : sem(0)
  16. {
  17. // TODO: 在此初始化 task_Look_KeyLed_t 的类成员
  18. }
  19. extern instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1;
  20. // 任务类 task_Look_KeyLed_t 的定义
  21. class task_Look_KeyLed2_t : public task_t {
  22. public:
  23. task_Look_KeyLed2_t() __OPT_ATTR__; // 构造函数

  24. protected:
  25. void routine();  // 任务例程
  26. public:
  27. sem_t sem;   // 信号灯为Led操作提供同步
  28. };
  29. // 任务类 task_Look_KeyLed_t 的构造函数
  30. __OPT_INLINE__ task_Look_KeyLed2_t::task_Look_KeyLed2_t()
  31. : sem(0)
  32. {
  33. // TODO: 在此初始化 task_Look_KeyLed_t 的类成员
  34. }
  35. extern instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2;

look_keyled.cpp

  1. #include "Look_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. if (vector == EINT0_IRQn)
  30. {
  31.      task_Look_KeyLed1.sem.do_post();
  32. }
  33. else if (vector == EINT1_IRQn)
  34. {
  35.      task_Look_KeyLed2.sem.do_post();
  36. }
  37. }
  38. Keyboard_t Key;         // 创建Key对象

  39. // 任务类 task_Look_KeyLed_t 的例程
  40. void task_Look_KeyLed1_t::routine()
  41. {
  42. // TODO: 在此编写 task_Look_KeyLed_t 例程的内容
  43. while (true) {
  44.   // TODO: 在此编写 task_Look_KeyLed_t 例程的内容
  45.   if (sem.wait())
  46.   {
  47.          uint32_t data = ~0b1000;
  48.    GPIOAs.DMASK.Regs = ~0b111100;
  49.    for (uint32_t i = 0; i < 8; i ++){
  50.      data &= 0b111100;
  51.      data <<= 1;
  52.      data += data >> 4;
  53.      GPIOAs.DOUT.Regs = data;
  54.            delay(LOOK_TICKS_PER_SEC / 10);
  55.    }
  56.    GPIOAs.DOUT.Regs = 0b111100;
  57.   }
  58. }
  59. }
  60. // 任务类 task_Look_KeyLed_t 的例程
  61. void task_Look_KeyLed2_t::routine()
  62. {
  63. // TODO: 在此编写 task_Look_KeyLed_t 例程的内容
  64. while (true) {
  65.   // TODO: 在此编写 task_Look_KeyLed_t 例程的内容
  66.   if (sem.wait())
  67.   {
  68.          uint32_t data = ~0b100000;
  69.    GPIOAs.DMASK.Regs = ~0b111100;
  70.    for (uint32_t i = 0; i < 8; i ++){
  71.      data &= 0b111100;
  72.      data >>= 1;
  73.      data += data << 4;
  74.      GPIOAs.DOUT.Regs = data;
  75.            delay(LOOK_TICKS_PER_SEC / 10);
  76.    }
  77.    GPIOAs.DOUT.Regs = 0b111100;
  78.   }
  79. }
  80. }

  81. #ifdef LOOK_SCHEDULING_PRIORITY
  82. instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1(0);
  83. instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2(0);
  84. #else
  85. instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1;
  86. instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2;
  87. #endif

本帖子中包含更多资源

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

×
weshiluwei6 发表于 2011-5-18 12:59 | 显示全部楼层
zhan占座 很想跟着学习 不过境界没倒啊
john_lee 发表于 2011-5-18 13:05 | 显示全部楼层
老哥太强了,都自己摸到如此地步啦!
Swallow_0322 发表于 2011-5-18 14:03 | 显示全部楼层
顶!:P
 楼主| hotpower 发表于 2011-5-18 14:06 | 显示全部楼层
晕,这个对于一个逆向人是个最小的问题。
学习就是从模仿开始的。
necho 发表于 2011-5-18 22:25 | 显示全部楼层
非常强悍
athud 发表于 2011-5-18 22:35 | 显示全部楼层
看不懂呀
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[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

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