本帖最后由 hotpower 于 2011-5-23 19:03 编辑
点击下载:Look_Mbox_KeyLed
Look_Mbox_KeyLed.rar
(651.59 KB)
1.Look_Mbox_KeyLed.h#include "look_config.h"
#include <look.h>
#include <instantiate>
// 任务类 task_Look_Mbox_KeyLed_t 的定义
class task_Look_Mbox_KeyLed_t : public task_t {
public:
task_Look_Mbox_KeyLed_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
public:
mbox_t<int> mbox;
};
// 任务类 task_Look_Mbox_KeyLed_t 的构造函数
__OPT_INLINE__ task_Look_Mbox_KeyLed_t::task_Look_Mbox_KeyLed_t()
: mbox(0)
{
// TODO: 在此初始化 task_Look_Mbox_KeyLed_t 的类成员
}
extern instantiate::task<task_Look_Mbox_KeyLed_t, LOOK_STACK_SIZE> task_Look_Mbox_KeyLed;
// 任务类 task_Look_Mbox_KeyLed_t 的定义
class task_Look_Mbox_Beep_t : public task_t {
public:
task_Look_Mbox_Beep_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
public:
sem_t sem; // 信号灯为Led操作提供同步
};
// 任务类 task_Look_Mbox_Beep_t 的构造函数
__OPT_INLINE__ task_Look_Mbox_Beep_t::task_Look_Mbox_Beep_t()
: sem(0)
{
// TODO: 在此初始化 task_Look_Mbox_KeyLed_t 的类成员
}
extern instantiate::task<task_Look_Mbox_Beep_t, LOOK_STACK_SIZE> task_Look_Mbox_Beep;
2.Look_Mbox_KeyLed.cpp
#include "Look_Mbox_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)
{
task_Look_Mbox_Beep.sem.do_post();
task_Look_Mbox_KeyLed.mbox.do_tryput(vector == EINT0_IRQn ? 1 : 2); // 发送消息
}
Keyboard_t Key; // 创建Key对象
// 任务类 task_Look_Mbox_KeyLed_t 的例程
void task_Look_Mbox_KeyLed_t::routine()
{
// TODO: 在此编写 task_Look_Mbox_KeyLed_t 例程的内容
uint32_t data, i;
while (true) {
// TODO: 在此编写 task_Look_Mbox_KeyLed_t 例程的内容
int msg = mbox.get(); // 等待邮箱消息
switch (msg) {
case 1:
data = ~0b100;
GPIOAs.DMASK.Regs = ~0b111100;
for (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;
break;
case 2:
data = ~0b100000;
GPIOAs.DMASK.Regs = ~0b111100;
for (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;
break;
}
}
}
// 任务类 task_Look_Mbox_Beep_t 的例程
void task_Look_Mbox_Beep_t::routine()
{
// TODO: 在此编写 task_Look_Mbox_Beep_t 例程的内容
while (true) {
// TODO: 在此编写 task_Look_Mbox_Beep_t 例程的内容
if (sem.wait())
{
GPIOBs.DMASK.Bits.Pin10 = 0;
for (uint32_t i = 0; i < 6; i ++){
GPIOBs.DOUT.Bits.Pin10 ^= 1;
delay(LOOK_TICKS_PER_SEC / 20);
}
GPIOBs.DOUT.Bits.Pin10 = 0;
}
}
}
#ifdef LOOK_SCHEDULING_PRIORITY
instantiate::task<task_Look_Mbox_KeyLed_t, LOOK_STACK_SIZE> task_Look_Mbox_KeyLed(0);
instantiate::task<task_Look_Mbox_Beep_t, LOOK_STACK_SIZE> task_Look_Mbox_Beep(0);
#else
instantiate::task<task_Look_Mbox_KeyLed_t, LOOK_STACK_SIZE> task_Look_Mbox_KeyLed;
instantiate::task<task_Look_Mbox_Beep_t, LOOK_STACK_SIZE> task_Look_Mbox_Beep;
#endif
|