#include "look_config.h" #include <look.h> #include <instantiate> // 任务类 task_Look_KeyLed_t 的定义 class task_Look_KeyLed1_t : public task_t { public: task_Look_KeyLed1_t() __OPT_ATTR__; // 构造函数 protected: void routine(); // 任务例程 public: sem_t sem; // 信号灯为Led操作提供同步 }; // 任务类 task_Look_KeyLed_t 的构造函数 __OPT_INLINE__ task_Look_KeyLed1_t::task_Look_KeyLed1_t() : sem(0) { // TODO: 在此初始化 task_Look_KeyLed_t 的类成员 } extern instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1; // 任务类 task_Look_KeyLed_t 的定义 class task_Look_KeyLed2_t : public task_t { public: task_Look_KeyLed2_t() __OPT_ATTR__; // 构造函数 protected: void routine(); // 任务例程 public: sem_t sem; // 信号灯为Led操作提供同步 }; // 任务类 task_Look_KeyLed_t 的构造函数 __OPT_INLINE__ task_Look_KeyLed2_t::task_Look_KeyLed2_t() : sem(0) { // TODO: 在此初始化 task_Look_KeyLed_t 的类成员 } extern instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2; look_keyled.cpp复制 #include "Look_KeyLed.h" #include "NUC1xx.h" #include "NUC1xxM051Seriescfg.h" class Keyboard_t : public interrupt_t { public: Keyboard_t() __OPT_ATTR__; protected: bool isr(int vector); void dsr(int vector, uintptr_t count); }; // Keyboard_t 构造函数 inline Keyboard_t::Keyboard_t() { attach(EINT0_IRQn); attach(EINT1_IRQn); GPIOBs.IEN.Regs = (1 << Pin15) | (1 << Pin14); // 开启中断 vector_t::enable(EINT0_IRQn); vector_t::enable(EINT1_IRQn); } // Keyboard_t 中断服务例程 bool Keyboard_t::isr(int vector) { GPIOBs.ISRC.Regs = GPIOBs.ISRC.Regs; // 清中断 flag return true; } // Keyboard_t 中断滞后服务例程 void Keyboard_t::dsr(int vector, uintptr_t count) { if (vector == EINT0_IRQn) { task_Look_KeyLed1.sem.do_post(); } else if (vector == EINT1_IRQn) { task_Look_KeyLed2.sem.do_post(); } } Keyboard_t Key; // 创建Key对象 // 任务类 task_Look_KeyLed_t 的例程 void task_Look_KeyLed1_t::routine() { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 while (true) { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 if (sem.wait()) { uint32_t data = ~0b1000; GPIOAs.DMASK.Regs = ~0b111100; for (uint32_t i = 0; i < 8; i ++){ data &= 0b111100; data <<= 1; data += data >> 4; GPIOAs.DOUT.Regs = data; delay(LOOK_TICKS_PER_SEC / 10); } GPIOAs.DOUT.Regs = 0b111100; } } } // 任务类 task_Look_KeyLed_t 的例程 void task_Look_KeyLed2_t::routine() { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 while (true) { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 if (sem.wait()) { uint32_t data = ~0b100000; GPIOAs.DMASK.Regs = ~0b111100; for (uint32_t i = 0; i < 8; i ++){ data &= 0b111100; data >>= 1; data += data << 4; GPIOAs.DOUT.Regs = data; delay(LOOK_TICKS_PER_SEC / 10); } GPIOAs.DOUT.Regs = 0b111100; } } } #ifdef LOOK_SCHEDULING_PRIORITY instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1(0); instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2(0); #else instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1; instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2; #endif
#include "Look_KeyLed.h" #include "NUC1xx.h" #include "NUC1xxM051Seriescfg.h" class Keyboard_t : public interrupt_t { public: Keyboard_t() __OPT_ATTR__; protected: bool isr(int vector); void dsr(int vector, uintptr_t count); }; // Keyboard_t 构造函数 inline Keyboard_t::Keyboard_t() { attach(EINT0_IRQn); attach(EINT1_IRQn); GPIOBs.IEN.Regs = (1 << Pin15) | (1 << Pin14); // 开启中断 vector_t::enable(EINT0_IRQn); vector_t::enable(EINT1_IRQn); } // Keyboard_t 中断服务例程 bool Keyboard_t::isr(int vector) { GPIOBs.ISRC.Regs = GPIOBs.ISRC.Regs; // 清中断 flag return true; } // Keyboard_t 中断滞后服务例程 void Keyboard_t::dsr(int vector, uintptr_t count) { if (vector == EINT0_IRQn) { task_Look_KeyLed1.sem.do_post(); } else if (vector == EINT1_IRQn) { task_Look_KeyLed2.sem.do_post(); } } Keyboard_t Key; // 创建Key对象 // 任务类 task_Look_KeyLed_t 的例程 void task_Look_KeyLed1_t::routine() { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 while (true) { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 if (sem.wait()) { uint32_t data = ~0b1000; GPIOAs.DMASK.Regs = ~0b111100; for (uint32_t i = 0; i < 8; i ++){ data &= 0b111100; data <<= 1; data += data >> 4; GPIOAs.DOUT.Regs = data; delay(LOOK_TICKS_PER_SEC / 10); } GPIOAs.DOUT.Regs = 0b111100; } } } // 任务类 task_Look_KeyLed_t 的例程 void task_Look_KeyLed2_t::routine() { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 while (true) { // TODO: 在此编写 task_Look_KeyLed_t 例程的内容 if (sem.wait()) { uint32_t data = ~0b100000; GPIOAs.DMASK.Regs = ~0b111100; for (uint32_t i = 0; i < 8; i ++){ data &= 0b111100; data >>= 1; data += data << 4; GPIOAs.DOUT.Regs = data; delay(LOOK_TICKS_PER_SEC / 10); } GPIOAs.DOUT.Regs = 0b111100; } } } #ifdef LOOK_SCHEDULING_PRIORITY instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1(0); instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2(0); #else instantiate::task<task_Look_KeyLed1_t, LOOK_STACK_SIZE> task_Look_KeyLed1; instantiate::task<task_Look_KeyLed2_t, LOOK_STACK_SIZE> task_Look_KeyLed2; #endif
您需要 登录 才可以下载或查看,没有账号?注册
举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
等级类勋章
发帖类勋章
时间类勋章
人才类勋章
1460
21619
508
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号