[抢楼250] 菜地公告:即日起创建《菜农Cortex-M0助学园地》(盖楼入口)

[复制链接]
997980|18727
 楼主| hotpower 发表于 2011-12-3 01:38 | 显示全部楼层
mbox_buff.cpp
  1. #include "Look_mbox_buff.h"
  2. #include "utils/debug.h"
  3. #include "numicro/sfr/gpio"

  4. mbox_t<int, 250> Mbox;// 创建 int 型邮箱
  5. int sum;

  6. instance_task1_Look_mbox_buff_t task1_Look_mbox_buff(1);        // 任务实例

  7. // 任务类 task1_Look_mbox_buff_t 的例程
  8. __DEBUG//debug调试不优化便于调试
  9. void task1_Look_mbox_buff_t::routine()
  10. {
  11.         // TODO: 在此编写例程的内容
  12.         using namespace sfr::gpio;
  13.         while (true) {
  14.                 // TODO: 在此编写例程的内容
  15.                 for(int i = 0; i < 250; i++)
  16.                 {
  17.                         Mbox.tryput_front(i);
  18.                 }
  19.                 sum = 0;
  20.                 GPIOA.DOUT().DOUT2 = 0;//LED1亮
  21.                 delay(LOOK_TICKS_PER_SEC / 5);
  22.                 GPIOA.DOUT().DOUT3(1)//LED2灭
  23.                             .DOUT2(1);//LED1灭
  24.                 delay(LOOK_TICKS_PER_SEC / 5);
  25.         }
  26. }

  27. instance_task2_Look_mbox_buff_t task2_Look_mbox_buff(2);        // 任务实例

  28. // 任务类 task2_Look_mbox_buff_t 的例程
  29. __DEBUG//debug调试不优化便于调试
  30. void task2_Look_mbox_buff_t::routine()
  31. {
  32.         // TODO: 在此编写例程的内容
  33.         using namespace sfr::gpio;
  34.         while (true) {
  35.                 // TODO: 在此编写例程的内容
  36.                 int msg;
  37.                 if (Mbox.get(msg))
  38.                 {
  39.                         sum += msg;
  40.                         if (sum == 0x7995)
  41.                         {
  42.                                 GPIOA.DOUT().DOUT3 = 0;//LED2亮
  43.                         }

  44.                 }
  45.         }
  46. }
 楼主| hotpower 发表于 2011-12-3 01:38 | 显示全部楼层
mbox_buff.cpp
  1. #include "Look_mbox_buff.h"
  2. #include "utils/debug.h"
  3. #include "numicro/sfr/gpio"

  4. mbox_t<int, 250> Mbox;// 创建 int 型邮箱
  5. int sum;

  6. instance_task1_Look_mbox_buff_t task1_Look_mbox_buff(1);        // 任务实例

  7. // 任务类 task1_Look_mbox_buff_t 的例程
  8. __DEBUG//debug调试不优化便于调试
  9. void task1_Look_mbox_buff_t::routine()
  10. {
  11.         // TODO: 在此编写例程的内容
  12.         using namespace sfr::gpio;
  13.         while (true) {
  14.                 // TODO: 在此编写例程的内容
  15.                 for(int i = 0; i < 250; i++)
  16.                 {
  17.                         Mbox.tryput_front(i);
  18.                 }
  19.                 sum = 0;
  20.                 GPIOA.DOUT().DOUT2 = 0;//LED1亮
  21.                 delay(LOOK_TICKS_PER_SEC / 5);
  22.                 GPIOA.DOUT().DOUT3(1)//LED2灭
  23.                             .DOUT2(1);//LED1灭
  24.                 delay(LOOK_TICKS_PER_SEC / 5);
  25.         }
  26. }

  27. instance_task2_Look_mbox_buff_t task2_Look_mbox_buff(2);        // 任务实例

  28. // 任务类 task2_Look_mbox_buff_t 的例程
  29. __DEBUG//debug调试不优化便于调试
  30. void task2_Look_mbox_buff_t::routine()
  31. {
  32.         // TODO: 在此编写例程的内容
  33.         using namespace sfr::gpio;
  34.         while (true) {
  35.                 // TODO: 在此编写例程的内容
  36.                 int msg;
  37.                 if (Mbox.get(msg))
  38.                 {
  39.                         sum += msg;
  40.                         if (sum == 0x7995)
  41.                         {
  42.                                 GPIOA.DOUT().DOUT3 = 0;//LED2亮
  43.                         }

  44.                 }
  45.         }
  46. }
 楼主| hotpower 发表于 2011-12-3 01:39 | 显示全部楼层
cond.cpp
  1. #include "Look_cond.h"
  2. #include "utils/debug.h"
  3. #include "numicro/sfr/gpio"

  4. int Sum = 0;
  5. flag_t Flag(0);
  6. mutex_t Mutex;
  7. cond_t Cond;

  8. // eint_t 类提供了 INT0/INT1 的接口
  9. // 当 INT0/INT1 发生时,对象将发送相应的 int 消息到 mbox。
  10. class eint_t : public interrupt_t {
  11. public:
  12.         __INLINE eint_t();

  13. protected:
  14.         bool isr(int vector);
  15.         void dsr(int vector, uintptr_t count);
  16. };

  17. // eint 构造函数
  18. __DEBUG//debug调试不优化便于调试
  19. __INLINE eint_t::eint_t()
  20. {
  21.         using namespace sfr::gpio;
  22.         attach(EINT0_IRQn);//绑定外部中断0
  23.         attach(EINT1_IRQn);//绑定外部中断1
  24.         GPIOB.IEN(0).IF_EN15(1).IF_EN14(1);//开启Key1,Key2中断
  25.         vector_t::enable(EINT0_IRQn);//使能外部中断0即Key1中断
  26.         vector_t::enable(EINT1_IRQn);//使能外部中断1即Key2中断
  27. }

  28. // eint 中断服务例程
  29. __DEBUG//debug调试不优化便于调试
  30. bool eint_t::isr(int vector)
  31. {
  32.         using namespace sfr::gpio;
  33.         GPIOB.ISRC = GPIOB.ISRC;                        // 清中断 flag
  34.         return true;
  35. }

  36. // eint 中断滞后服务例程
  37. __DEBUG//debug调试不优化便于调试
  38. void eint_t::dsr(int vector, uintptr_t count)
  39. {
  40.         using namespace sfr::gpio;
  41.         if (vector == EINT0_IRQn)//Key2中断
  42.         {
  43.                 Flag.do_set_bits(2);//在中断中唤醒任务2
  44.         }
  45.         else if (vector == EINT1_IRQn)//Key1中断
  46.         {
  47.                 Flag.do_set_bits(1);//在中断中唤醒任务1
  48.         }
  49. }

  50. eint_t eint;                                                                        // 创建 eint 对象

  51. instance_task1_Look_cond_t task1_Look_cond(1);        // 任务实例

  52. // 任务类 task1_Look_cond_t 的例程
  53. __DEBUG//debug调试不优化便于调试
  54. void task1_Look_cond_t::routine()
  55. {
  56.         // TODO: 在此编写 task1_Look_cond_t 例程的内容
  57.         using namespace sfr::gpio;
  58.         while (true) {
  59.                 // TODO: 在此编写 task1_Look_cond_t 例程的内容
  60.                 int flag = Flag.wait(1, flag_t::ANY_CONSUME);//阻塞等待Key1中断
  61.                 if (flag)
  62.                 {
  63.                         GPIOA.DOUT().DOUT2 ^= 1;//LED1闪烁
  64.                         Mutex.lock();
  65.                         Sum++;
  66.                         if (Sum < 3) Mutex.unlock();
  67.                         else{
  68.                                 Mutex.unlock();
  69.                                 Cond.signal();

  70.                         }
  71.                 }
  72.         }
  73. }

  74. instance_task2_Look_cond_t task2_Look_cond(2);        // 任务实例

  75. // 任务类 task1_Look_cond_t 的例程
  76. __DEBUG//debug调试不优化便于调试
  77. void task2_Look_cond_t::routine()
  78. {
  79.         // TODO: 在此编写 task2_Look_cond_t 例程的内容
  80.         using namespace sfr::gpio;
  81.         while (true) {
  82.                 // TODO: 在此编写 task2_Look_cond_t 例程的内容
  83.                 int flag = Flag.wait(2, flag_t::ANY_CONSUME);//阻塞等待Key2中断
  84.                 if (flag)
  85.                 {
  86.                         GPIOA.DOUT().DOUT3 ^= 1;//LED2闪烁
  87.                         Sum++;
  88.                         if (Sum < 3) Mutex.unlock();
  89.                         else{
  90.                                 Mutex.unlock();
  91.                                 Cond.signal();

  92.                         }
  93.                 }
  94.         }
  95. }

  96. instance_task3_Look_cond_t task3_Look_cond(3);        // 任务实例

  97. // 任务类 task3_Look_cond_t 的例程
  98. __DEBUG//debug调试不优化便于调试
  99. void task3_Look_cond_t::routine()
  100. {
  101.         // TODO: 在此编写 task3_Look_cond_t 例程的内容
  102.         using namespace sfr::gpio;
  103.         while (true) {
  104.                 // TODO: 在此编写 task3_Look_cond_t 例程的内容
  105.                 Mutex.lock();
  106.                 while (Sum < 3){//Key1或Key2按键合计次数为三次时激活
  107.                         Cond.wait(Mutex);
  108.                         Mutex.unlock();
  109.                         Sum = 0;
  110.                         GPIOA.DOUT().DOUT4(0).DOUT5(0);//LED3,LED4亮
  111.                         delay(LOOK_TICKS_PER_SEC / 2);//延时亮0.5S
  112.                         GPIOA.DOUT().DOUT4(1).DOUT5(1);//LED3,LED4灭
  113.                         break;
  114.                 }
  115.         }
  116. }
 楼主| hotpower 发表于 2011-12-3 02:21 | 显示全部楼层
 楼主| hotpower 发表于 2011-12-3 02:23 | 显示全部楼层
楼差1664
 楼主| hotpower 发表于 2011-12-3 02:23 | 显示全部楼层
继续努力,俺要在此楼技术楼聊
plc_avr 发表于 2011-12-3 06:29 | 显示全部楼层
盖楼......
 楼主| hotpower 发表于 2011-12-3 07:21 | 显示全部楼层
 楼主| hotpower 发表于 2011-12-3 07:23 | 显示全部楼层
俺6点都起来了,到早市买条大鱼。
Swallow_0322 发表于 2011-12-3 07:23 | 显示全部楼层
大叔开始测试LOOK,加油!:victory:
Swallow_0322 发表于 2011-12-3 07:23 | 显示全部楼层
签到...
 楼主| hotpower 发表于 2011-12-3 07:40 | 显示全部楼层
报到。
 楼主| hotpower 发表于 2011-12-3 07:45 | 显示全部楼层
三心,俺开始测试了,look表现良好。
老师暴力的头文件非常给力。
实际俺可以做些其它cortexm的look测试。
Ryanhsiung 发表于 2011-12-3 10:55 | 显示全部楼层
Ryanhsiung 发表于 2011-12-3 10:56 | 显示全部楼层
 楼主| hotpower 发表于 2011-12-3 11:55 | 显示全部楼层
晕,老套了,123,456

应该250
51小刚 发表于 2011-12-3 15:52 | 显示全部楼层
盖楼!
plc_avr 发表于 2011-12-3 15:59 | 显示全部楼层
盖楼....
 楼主| hotpower 发表于 2011-12-3 17:06 | 显示全部楼层
 楼主| hotpower 发表于 2011-12-3 17:14 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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