打印
[LOOK]

LOOK菜鸟mutex应用例程

[复制链接]
2399|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hotpower|  楼主 | 2011-5-20 18:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 hotpower 于 2011-5-23 19:03 编辑

点击下载:Look_Mutex
Look_Mutex.rar (577.64 KB)

1.look_mutex.h
 
#include "look_config.h"
#include <look.h>
#include <instantiate>
// 任务类 task_Look_Mutex_Led1_t 的定义
class task_Look_Mutex_Led1_t : public task_t {
public:
task_Look_Mutex_Led1_t() __OPT_ATTR__; // 构造函数

protected:
void routine();  // 任务例程
};
// 任务类 task_Look_Mutex_Led1_t 的构造函数
__OPT_INLINE__ task_Look_Mutex_Led1_t::task_Look_Mutex_Led1_t()
{
// TODO: 在此初始化 task_Look_Mutex_Led1_t 的类成员
}
// 任务类 task_Look_Mutex_Led2_t 的定义
class task_Look_Mutex_Led2_t : public task_t {
public:
task_Look_Mutex_Led2_t() __OPT_ATTR__; // 构造函数

protected:
void routine();  // 任务例程
};

// 任务类 task_Look_Mutex_Beep_t 的定义
class task_Look_Mutex_Beep_t : public task_t {
public:
task_Look_Mutex_Beep_t() __OPT_ATTR__; // 构造函数

protected:
void routine();  // 任务例程
};
// 任务类 task_Look_Mutex_Led1_t 的构造函数
__OPT_INLINE__ task_Look_Mutex_Beep_t::task_Look_Mutex_Beep_t()
{
// TODO: 在此初始化 task_Look_Mutex_Led1_t 的类成员
}
extern instantiate::task<task_Look_Mutex_Led1_t, LOOK_STACK_SIZE> task_Look_Mutex_Led1;
extern instantiate::task<task_Look_Mutex_Led2_t, LOOK_STACK_SIZE> task_Look_Mutex_Led2;
extern instantiate::task<task_Look_Mutex_Beep_t, LOOK_STACK_SIZE> task_Look_Mutex_Beep;
2.look_mutex.cpp

#include "Look_Mutex.h"
#include "NUC1xx.h"
#include "NUC1xxM051Seriescfg.h"
mutex_t mutex;
mbox_t<int> mbox(0);
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;   // 清中断 Mutex
return true;
}
// Keyboard_t 中断滞后服务例程
void Keyboard_t::dsr(int vector, uintptr_t count)
{
if (vector == EINT0_IRQn)//Key2
{
  mbox.do_tryput(6);
}
else if (vector == EINT1_IRQn)//Key1
{
  mbox.do_tryput(2);
}
}
Keyboard_t Key;         // 创建Key对象

// 任务类 task_Look_Mutex_Led1_t 的例程
void task_Look_Mutex_Led1_t::routine()
{
// TODO: 在此编写 task_Look_Mutex_Led1_t 例程的内容
while (true) {
  // TODO: 在此编写 task_Look_Mutex_Led1_t 例程的内容
  int Mutex = mutex.lock();
  if (Mutex)
  {
   delay(LOOK_TICKS_PER_SEC / 10);
      uint32_t data = ~0b100;
   GPIOAs.DMASK.Regs = ~0b111100;
   for (uint32_t i = 0; i < 18; i ++){
    data &= 0b111100;
      GPIOAs.DOUT.Regs = data;
      data <<= 1;
      data += data >> 4;
            delay(LOOK_TICKS_PER_SEC / 10);
   }
   GPIOAs.DOUT.Regs = 0b111100;
   mutex.unlock();
  }
//  delay(LOOK_TICKS_PER_SEC / 100);
}
}

// 任务类 task_Look_Mutex_Led2_t 的例程
void task_Look_Mutex_Led2_t::routine()
{      
// TODO: 在此编写 task_Look_Mutex_Led2_t 例程的内容
while (true) {
  // TODO: 在此编写 task_Look_Mutex_Led2_t 例程的内容
  int Mutex = mutex.lock();
  if (Mutex)
  {
   delay(LOOK_TICKS_PER_SEC / 10);
      uint32_t data = ~0b100000;
   GPIOAs.DMASK.Regs = ~0b111100;
   for (uint32_t i = 0; i < 18; i ++){
    data &= 0b111100;
      GPIOAs.DOUT.Regs = data;
      data >>= 1;
      data += data << 4;
            delay(LOOK_TICKS_PER_SEC / 10);
   }
   GPIOAs.DOUT.Regs = 0b111100;
   mutex.unlock();
  }
//  delay(LOOK_TICKS_PER_SEC / 100);
}
}

// 任务类 task_Look_Mutex_Beep_t 的例程
void task_Look_Mutex_Beep_t::routine()
{
// TODO: 在此编写 task_Look_Mutex_Beep_t 例程的内容
while (true) {
  // TODO: 在此编写 task_Look_Mutex_Beep_t 例程的内容
  uint32_t msg = mbox.get();//取出响铃次数
  if (msg)
  {
   GPIOBs.DMASK.Bits.Pin10 = 0;
   for (uint32_t i = 0; i < msg; i ++){//蜂鸣器响X次
     GPIOBs.DOUT.Bits.Pin10 ^= 1;//蜂鸣器响PB10=1,不响PB10=0
           delay(LOOK_TICKS_PER_SEC / 20);//断续间隔
   }
   GPIOBs.DOUT.Bits.Pin10 = 0;//蜂鸣器不响
  }
}
}
#ifdef LOOK_SCHEDULING_PRIORITY
instantiate::task<task_Look_Mutex_Led1_t, LOOK_STACK_SIZE> task_Look_Mutex_Led1(0);
instantiate::task<task_Look_Mutex_Led2_t, LOOK_STACK_SIZE> task_Look_Mutex_Led2(0);
instantiate::task<task_Look_Mutex_Beep_t, LOOK_STACK_SIZE> task_Look_Mutex_Beep(0);
#else
instantiate::task<task_Look_Mutex_Led1_t, LOOK_STACK_SIZE> task_Look_Mutex_Led1;
instantiate::task<task_Look_Mutex_Led2_t, LOOK_STACK_SIZE> task_Look_Mutex_Led2;
instantiate::task<task_Look_Mutex_Beep_t, LOOK_STACK_SIZE> task_Look_Mutex_Beep;
#endif
沙发
murex| | 2011-5-20 18:56 | 只看该作者
沙发

使用特权

评论回复
板凳
sunshitao| | 2011-5-20 18:58 | 只看该作者
板凳

使用特权

评论回复
地板
wang4101| | 2011-5-20 19:19 | 只看该作者
:lol

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1538

主题

21697

帖子

505

粉丝