点击下载LOOK_SEM:
LOOK_SEM.rar
(489 KB)
1.LOOK_SEM.H
#ifndef __LOOK_SEM_H
#define __LOOK_SEM_H
#include "look_config.h"
#include <look.h>
#include <instantiate>
// 任务类 task_LOOK_SEM1_t 的定义
class task_LOOK_SEM1_t : public task_t {
public:
task_LOOK_SEM1_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
};
// 任务类 LOOK_SEM1 的构造函数
__OPT_INLINE__ task_LOOK_SEM1_t::task_LOOK_SEM1_t()
{
// TODO: 在此初始化 task_LOOK_SEM_t 的类成员
}
extern instantiate::task<task_LOOK_SEM1_t, LOOK_STACK_SIZE> task_LOOK1_SEM;
// 任务类 task_LOOK_SEM2_t 的定义
class task_LOOK_SEM2_t : public task_t {
public:
task_LOOK_SEM2_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
};
// 任务类 LOOK_SEM2 的构造函数
__OPT_INLINE__ task_LOOK_SEM2_t::task_LOOK_SEM2_t()
{
// TODO: 在此初始化 task_LOOK_SEM_t 的类成员
}
extern instantiate::task<task_LOOK_SEM2_t, LOOK_STACK_SIZE> task_LOOK2_SEM;
#endif // __LOOK_SEM_H
2.LOOK_SEM.CPP
#include "LOOK_SEM.h"
#include "NUC1xx.h"
#include "NUC1xxM051Seriescfg.h"
sem_t sem = 1; // 信号灯共享
// 任务类 task_LOOK_SEM1_t 的例程
void task_LOOK_SEM1_t::routine()
{
// TODO: 在此编写 task_LOOK_SEM1_t 例程的内容
while (true) {
// TODO: 在此编写 task_LOOK_SEM1_t 例程的内容
if (sem.wait())//获取信号量,锁住以下共享设备
{
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;
sem.post();//释放信号量
}
}
}
// 任务类 task_LOOK_SEM2_t 的例程
void task_LOOK_SEM2_t::routine()
{
// TODO: 在此编写 task_LOOK_SEM2_t 例程的内容
while (true) {
// TODO: 在此编写 task_LOOK_SEM2_t 例程的内容
if (sem.wait())//获取信号量,锁住以下共享设备
{
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;
sem.post();//释放信号量
}
}
}
#ifdef LOOK_SCHEDULING_PRIORITY
instantiate::task<task_LOOK_SEM1_t, LOOK_STACK_SIZE> task_LOOK_SEM1(0);
instantiate::task<task_LOOK_SEM2_t, LOOK_STACK_SIZE> task_LOOK_SEM2(0);
#else
instantiate::task<task_LOOK_SEM1_t, LOOK_STACK_SIZE> task_LOOK_SEM1;
instantiate::task<task_LOOK_SEM2_t, LOOK_STACK_SIZE> task_LOOK_SEM2;
#endif
|