本帖最后由 hotpower 于 2011-5-23 19:02 编辑
本例程是在Lee老师和M0菜地的指导和监督下在线实时完成的。
点击下载LOOK_MMBOX
LOOK_MMBOX.rar
(523.74 KB)
1.LOOK_MMBOX.h#ifndef __LOOK_MMBOX_H
#define __LOOK_MMBOX_H
#include "look_config.h"
#include <look.h>
#include <instantiate>
// 任务类 task_LOOK_MMBOX_t 的定义
class task_LOOK_MMBOX_t : public task_t {
public:
task_LOOK_MMBOX_t() __OPT_ATTR__; // 构造函数
bool send_message(int msg);
protected:
void routine(); // 任务例程
private:
mmbox_t<int, 16> mmbox;
};
// 任务类 LOOK_MMBOX 的构造函数
__OPT_INLINE__ task_LOOK_MMBOX_t::task_LOOK_MMBOX_t()
{
// TODO: 在此初始化 task_LOOK_MMBOX_t 的类成员
}
// 任务类 task_LOOK_BEEP_t 的定义
class task_LOOK_BEEP_t : public task_t {
public:
task_LOOK_BEEP_t() __OPT_ATTR__; // 构造函数
bool send_message(int msg);
protected:
void routine(); // 任务例程
private:
mbox_t<int> mbox;
};
// 任务类 LOOK_BEEP 的构造函数
__OPT_INLINE__ task_LOOK_BEEP_t::task_LOOK_BEEP_t()
: mbox(0)
{
// TODO: 在此初始化 task_LOOK_BEEP_t 的类成员
}
extern instantiate::task<task_LOOK_MMBOX_t, LOOK_STACK_SIZE> task_LOOK_MMBOX;
extern instantiate::task<task_LOOK_BEEP_t, LOOK_STACK_SIZE> task_LOOK_BEEP;
#endif // __LOOK_MMBOX_H
2.LOOK_MMBOX.cpp#include "LOOK_MMBOX.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)//Key2
{
task_LOOK_BEEP.send_message(3);//响三声
}
else if (vector == EINT1_IRQn)//Key1
{
task_LOOK_BEEP.send_message(1);//响一声
}
}
Keyboard_t Key; // 创建Key对象
// 任务类 task_LOOK_MMBOX_t 的例程
void task_LOOK_MMBOX_t::routine()
{
// TODO: 在此编写 task_LOOK_MMBOX_t 例程的内容
while (true) {
// TODO: 在此编写 task_LOOK_MMBOX_t 例程的内容
int msg = mmbox.get(); // 等待邮箱消息
if (msg)
{
GPIOAs.DMASK.Regs = ~0b111100;
GPIOAs.DOUT.Regs = (msg << 2) ^ 0b111100;
delay(LOOK_TICKS_PER_SEC / 5);
}
}
}
bool task_LOOK_MMBOX_t::send_message(int msg)
{
return mmbox.tryput(msg);
}
// 任务类 task_LOOK_BEEP_t 的例程
void task_LOOK_BEEP_t::routine()
{
// TODO: 在此编写 task_LOOK_BEEP_t 例程的内容
while (true) {
// TODO: 在此编写 task_LOOK_BEEP_t 例程的内容
int msg = mbox.get(); // 等待邮箱消息
if (msg)
{
for (int i = 0; i < 16; i ++){
task_LOOK_MMBOX.send_message(i);
}
GPIOBs.DMASK.Bits.Pin10 = 0;
for (int i = 0; i < (msg * 2); i ++){
GPIOBs.DOUT.Bits.Pin10 ^= 1;
delay(LOOK_TICKS_PER_SEC / 20);
}
GPIOBs.DOUT.Bits.Pin10 = 0;
}
}
}
bool task_LOOK_BEEP_t::send_message(int msg)
{
return mbox.do_tryput(msg);
}
#ifdef LOOK_SCHEDULING_PRIORITY
instantiate::task<task_LOOK_MMBOX_t, LOOK_STACK_SIZE> task_LOOK_MMBOX(0);
instantiate::task<task_LOOK_BEEP_t, LOOK_STACK_SIZE> task_LOOK_BEEP(0);
#else
instantiate::task<task_LOOK_MMBOX_t, LOOK_STACK_SIZE> task_LOOK_MMBOX;
instantiate::task<task_LOOK_BEEP_t, LOOK_STACK_SIZE> task_LOOK_BEEP;
#endif
|