#include "Look_mbox_buff.h" #include "utils/debug.h" #include "numicro/sfr/gpio" mbox_t<int, 250> Mbox;// 创建 int 型邮箱 int sum; instance_task1_Look_mbox_buff_t task1_Look_mbox_buff(1); // 任务实例 // 任务类 task1_Look_mbox_buff_t 的例程 __DEBUG//debug调试不优化便于调试 void task1_Look_mbox_buff_t::routine() { // TODO: 在此编写例程的内容 using namespace sfr::gpio; while (true) { // TODO: 在此编写例程的内容 for(int i = 0; i < 250; i++) { Mbox.tryput_front(i); } sum = 0; GPIOA.DOUT().DOUT2 = 0;//LED1亮 delay(LOOK_TICKS_PER_SEC / 5); GPIOA.DOUT().DOUT3(1)//LED2灭 .DOUT2(1);//LED1灭 delay(LOOK_TICKS_PER_SEC / 5); } } instance_task2_Look_mbox_buff_t task2_Look_mbox_buff(2); // 任务实例 // 任务类 task2_Look_mbox_buff_t 的例程 __DEBUG//debug调试不优化便于调试 void task2_Look_mbox_buff_t::routine() { // TODO: 在此编写例程的内容 using namespace sfr::gpio; while (true) { // TODO: 在此编写例程的内容 int msg; if (Mbox.get(msg)) { sum += msg; if (sum == 0x7995) { GPIOA.DOUT().DOUT3 = 0;//LED2亮 } } } }
收藏1 举报
#include "Look_cond.h" #include "utils/debug.h" #include "numicro/sfr/gpio" int Sum = 0; flag_t Flag(0); mutex_t Mutex; cond_t Cond; // eint_t 类提供了 INT0/INT1 的接口 // 当 INT0/INT1 发生时,对象将发送相应的 int 消息到 mbox。 class eint_t : public interrupt_t { public: __INLINE eint_t(); protected: bool isr(int vector); void dsr(int vector, uintptr_t count); }; // eint 构造函数 __DEBUG//debug调试不优化便于调试 __INLINE eint_t::eint_t() { using namespace sfr::gpio; attach(EINT0_IRQn);//绑定外部中断0 attach(EINT1_IRQn);//绑定外部中断1 GPIOB.IEN(0).IF_EN15(1).IF_EN14(1);//开启Key1,Key2中断 vector_t::enable(EINT0_IRQn);//使能外部中断0即Key1中断 vector_t::enable(EINT1_IRQn);//使能外部中断1即Key2中断 } // eint 中断服务例程 __DEBUG//debug调试不优化便于调试 bool eint_t::isr(int vector) { using namespace sfr::gpio; GPIOB.ISRC = GPIOB.ISRC; // 清中断 flag return true; } // eint 中断滞后服务例程 __DEBUG//debug调试不优化便于调试 void eint_t::dsr(int vector, uintptr_t count) { using namespace sfr::gpio; if (vector == EINT0_IRQn)//Key2中断 { Flag.do_set_bits(2);//在中断中唤醒任务2 } else if (vector == EINT1_IRQn)//Key1中断 { Flag.do_set_bits(1);//在中断中唤醒任务1 } } eint_t eint; // 创建 eint 对象 instance_task1_Look_cond_t task1_Look_cond(1); // 任务实例 // 任务类 task1_Look_cond_t 的例程 __DEBUG//debug调试不优化便于调试 void task1_Look_cond_t::routine() { // TODO: 在此编写 task1_Look_cond_t 例程的内容 using namespace sfr::gpio; while (true) { // TODO: 在此编写 task1_Look_cond_t 例程的内容 int flag = Flag.wait(1, flag_t::ANY_CONSUME);//阻塞等待Key1中断 if (flag) { GPIOA.DOUT().DOUT2 ^= 1;//LED1闪烁 Mutex.lock(); Sum++; if (Sum < 3) Mutex.unlock(); else{ Mutex.unlock(); Cond.signal(); } } } } instance_task2_Look_cond_t task2_Look_cond(2); // 任务实例 // 任务类 task1_Look_cond_t 的例程 __DEBUG//debug调试不优化便于调试 void task2_Look_cond_t::routine() { // TODO: 在此编写 task2_Look_cond_t 例程的内容 using namespace sfr::gpio; while (true) { // TODO: 在此编写 task2_Look_cond_t 例程的内容 int flag = Flag.wait(2, flag_t::ANY_CONSUME);//阻塞等待Key2中断 if (flag) { GPIOA.DOUT().DOUT3 ^= 1;//LED2闪烁 Sum++; if (Sum < 3) Mutex.unlock(); else{ Mutex.unlock(); Cond.signal(); } } } } instance_task3_Look_cond_t task3_Look_cond(3); // 任务实例 // 任务类 task3_Look_cond_t 的例程 __DEBUG//debug调试不优化便于调试 void task3_Look_cond_t::routine() { // TODO: 在此编写 task3_Look_cond_t 例程的内容 using namespace sfr::gpio; while (true) { // TODO: 在此编写 task3_Look_cond_t 例程的内容 Mutex.lock(); while (Sum < 3){//Key1或Key2按键合计次数为三次时激活 Cond.wait(Mutex); Mutex.unlock(); Sum = 0; GPIOA.DOUT().DOUT4(0).DOUT5(0);//LED3,LED4亮 delay(LOOK_TICKS_PER_SEC / 2);//延时亮0.5S GPIOA.DOUT().DOUT4(1).DOUT5(1);//LED3,LED4灭 break; } } }
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
人才类勋章
等级类勋章
发帖类勋章
时间类勋章
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号