本帖最后由 hotpower 于 2011-8-4 13:13 编辑
建议ICP采用5008版本
1.Cortex.rar(覆盖以前的LOOK安装目录)
2.LOOK_FLAG
3.贴图
4.程序片段-
- #include "Look_Flag.h"
- #define LOOK_H 1
- #define LOOK_SEMIHOST
- #if LOOK_H == 0
- #include "NUC1xx.h"
- #include "NUC1xxM051Seriescfg.h"
- #else
- #include <nuc120re3an.h>
- using namespace nuvoton;
- #endif
- #ifdef LOOK_SEMIHOST
- #include <ostream>
- #include <semihosting>
- using namespace redapricot;
- ostream_t<semihosting::console_t, 128> cout;
- #endif
- flag_t Flag(0);
- class Keyboard_t : public interrupt_t {
- public:
- __INLINE__ Keyboard_t();
- protected:
- bool isr(int vector);
- void dsr(int vector, uintptr_t count);
- };
- // Keyboard_t 构造函数
- __INLINE__ Keyboard_t::Keyboard_t()
- {
- #ifdef LOOK_SEMIHOST
- cout << "Keyboard_t构造函数开始" << endl;
- #endif
- attach(EINT0_IRQn);
- attach(EINT1_IRQn);
- #if LOOK_H == 0
- GPIOBs.IEN.Regs = (1 << Pin15) | (1 << Pin14); // 开启中断
- #else
- GPIOB.IEN(0)
- .IF_EN15(1)
- .IF_EN14(1); // 开启中断
- #endif
- vector_t::enable(EINT0_IRQn);
- vector_t::enable(EINT1_IRQn);
- #ifdef LOOK_SEMIHOST
- cout << "Keyboard_t构造函数结束" << endl;
- #endif
- }
- // Keyboard_t 中断服务例程
- bool Keyboard_t::isr(int vector)
- {
- #if LOOK_H == 0
- GPIOBs.ISRC.Regs = GPIOBs.ISRC.Regs; // 清中断 flag
- #else
- //注意:下句被优化了
- // GPIOB.ISRC = GPIOB.ISRC; // 清中断 flag
- //注意:下句不能被优化,特别注意()是建立缓存
- GPIOB.ISRC = GPIOB.ISRC(); // 清中断 flag
- #endif
- #ifdef LOOK_SEMIHOST
- cout << "中断Keyboard_t清除中断标志" << endl;
- #endif
- return true;
- }
- // Keyboard_t 中断滞后服务例程
- void Keyboard_t::dsr(int vector, uintptr_t count)
- {
- static uint32_t n = 0b01;
- if (vector == EINT0_IRQn)//Key2
- {
- Flag.do_set_bits(n);
- n <<= 1;
- if (n == 8) n = 0b111;
- else if(n > 8) n = 1;
- #ifdef LOOK_SEMIHOST
- cout << "中断Keyboard_t按下Key2键" << endl;
- #endif
- }
- else if (vector == EINT1_IRQn)//Key1
- {
- Flag.do_set_bits(0b111);
- #ifdef LOOK_SEMIHOST
- cout << "中断Keyboard_t按下Key1键" << endl;
- #endif
- }
- }
- Keyboard_t Key; // 创建Key对象
- // 任务类 task_Look_Flag_Led1_t 的例程
- void task_Look_Flag_Led1_t::routine()
- {
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led1_t开始:" << endl;
- #endif
- // TODO: 在此编写 task_Look_Flag_Led1_t 例程的内容
- while (true) {
- // TODO: 在此编写 task_Look_Flag_Led1_t 例程的内容
- int flag = Flag.wait(0b001, flag_t::ANY_CONSUME);
- if (flag)
- {
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led1_t flag=" << flag << endl;
- #endif
- uint32_t data = ~0b100;
- for (uint32_t i = 0; i < 8; i ++){
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led1_t LED闪烁" << flag << endl;
- #endif
- #if LOOK_H == 0
- GPIOAs.DMASK.Regs = ~0b001100;
- GPIOAs.DOUT.Regs = data;
- #else
- // GPIOA.DMASK = ~0b001100;
- GPIOA.DMASK(-1)
- .DMASK3(0)
- .DMASK2(0);
- GPIOA.DOUT = data;
- #endif
- data ^= 0b1100;
- delay(LOOK_TICKS_PER_SEC / 10);
- }
- #if LOOK_H == 0
- GPIOAs.DMASK.Regs = ~0b001100;
- GPIOAs.DOUT.Regs = 0b001100;
- #else
- // GPIOA.DMASK = ~0b001100;//节约4字节
- GPIOA.DMASK(-1)
- .DMASK3(0)
- .DMASK2(0);
- // GPIOA.DOUT = 0b001100;
- GPIOA.DOUT(0)
- .DOUT3(1)
- .DOUT2(1);
- #endif
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led1_t延时" << LOOK_TICKS_PER_SEC / 10 << "mS" << endl;
- #endif
- delay(LOOK_TICKS_PER_SEC / 10);
- }
-
- }
- }
- // 任务类 task_Look_Flag_Led2_t 的例程
- void task_Look_Flag_Led2_t::routine()
- {
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led2_t开始:" << endl;
- #endif
- // TODO: 在此编写 task_Look_Flag_Led2_t 例程的内容
- while (true) {
- // TODO: 在此编写 task_Look_Flag_Led2_t 例程的内容
- int flag = Flag.wait(0b010, flag_t::ANY_CONSUME);
- if (flag)
- {
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led2_t flag=" << flag << endl;
- #endif
- uint32_t data = ~0b100000;
- for (uint32_t i = 0; i < 8; i ++){
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led2_t LED闪烁" << flag << endl;
- #endif
- #if LOOK_H == 0
- GPIOAs.DMASK.Regs = ~0b110000;
- GPIOAs.DOUT.Regs = data;
- #else
- // GPIOA.DMASK = ~0b110000;//节约4字节
- GPIOA.DMASK(-1)
- .DMASK5(0)
- .DMASK4(0);
- GPIOA.DOUT = data;
- #endif
- data ^= 0b110000;
- delay(LOOK_TICKS_PER_SEC / 10);
- }
- #if LOOK_H == 0
- GPIOAs.DMASK.Regs = ~0b110000;
- GPIOAs.DOUT.Regs = 0b110000;
- #else
- // GPIOA.DMASK = ~0b110000;
- GPIOA.DMASK(-1)
- .DMASK5(0)
- .DMASK4(0);
- // GPIOA.DOUT = 0b110000;
- GPIOA.DOUT(0)
- .DOUT5(1)
- .DOUT4(1);
- #endif
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Led2_t延时" << LOOK_TICKS_PER_SEC / 10 << "mS" << endl;
- #endif
- delay(LOOK_TICKS_PER_SEC / 10);
- }
- }
- }
- // 任务类 task_Look_Flag_Beep_t 的例程
- void task_Look_Flag_Beep_t::routine()
- {
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Beep_t开始:" << endl;
- #endif
- // TODO: 在此编写 task_Look_Flag_Beep_t 例程的内容
- while (true) {
- // TODO: 在此编写 task_Look_Flag_Beep_t 例程的内容
- int flag = Flag.wait(0b100, flag_t::ANY_CONSUME);
- if (flag)
- {
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Beep_t flag=" << flag << endl;
- #endif
- for (uint32_t i = 0; i < 6; i ++){//蜂鸣器响三次
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Beep_t蜂鸣器发声" << endl;
- #endif
- #if LOOK_H == 0
- GPIOBs.DOUT.Bits.Pin10 ^= 1;//蜂鸣器响PB10=1,不响PB10=0
- #else
- #if LOOK_H == 1
- GPIOB.DOUT().DOUT10 ^= 1;
- // #else
- // GPIOB.DOUT()
- // .DOUT10.lambda([](uint32_t data) { return data ^ 1; });
- #endif
- #endif
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Beep_t延时" << LOOK_TICKS_PER_SEC / 20 << "mS" << endl;
- #endif
- delay(LOOK_TICKS_PER_SEC / 20);//断续间隔
- }
- #if LOOK_H == 0
- GPIOBs.DOUT.Bits.Pin10 = 0;//蜂鸣器不响
- #else
- // GPIOB.DOUT().DOUT10 = 0;
- GPIOB.DOUT().DOUT10(0);
- #endif
- #ifdef LOOK_SEMIHOST
- cout << "任务task_Look_Flag_Beep_t关闭蜂鸣器" << endl;
- #endif
- }
- }
- //
- }
- #ifdef LOOK_SCHEDULING_PRIORITY
- instantiate::task<task_Look_Flag_Led1_t, LOOK_STACK_SIZE> task_Look_Flag_Led1(1);
- instantiate::task<task_Look_Flag_Led2_t, LOOK_STACK_SIZE> task_Look_Flag_Led2(2);
- instantiate::task<task_Look_Flag_Beep_t, LOOK_STACK_SIZE> task_Look_Flag_Beep(0);
- #else
- instantiate::task<task_Look_Flag_Led1_t, LOOK_STACK_SIZE> task_Look_Flag_Led1;
- instantiate::task<task_Look_Flag_Led2_t, LOOK_STACK_SIZE> task_Look_Flag_Led2;
- instantiate::task<task_Look_Flag_Beep_t, LOOK_STACK_SIZE> task_Look_Flag_Beep;
- #endif
|