点击下载LOOK_YIELD:
LOOK_YIELD.rar
(487.83 KB)
1.LOOK_YIELD.H
#ifndef __LOOK_YIELD_H
#define __LOOK_YIELD_H
#include "look_config.h"
#include <look.h>
#include <instantiate>
// 任务类 task_LOOK_YIELD1_t 的定义
class task_LOOK_YIELD1_t : public task_t {
public:
task_LOOK_YIELD1_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
private:
};
// 任务类 LOOK_YIELD1 的构造函数
__OPT_INLINE__ task_LOOK_YIELD1_t::task_LOOK_YIELD1_t()
{
// TODO: 在此初始化 task_LOOK_YIELD1_t 的类成员
}
// 任务类 task_LOOK_YIELD1_t 的定义
class task_LOOK_YIELD_t : public task_t {
public:
task_LOOK_YIELD_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
private:
};
// 任务类 LOOK_YIELD 的构造函数
__OPT_INLINE__ task_LOOK_YIELD_t::task_LOOK_YIELD_t()
{
// TODO: 在此初始化 task_LOOK_YIELD_t 的类成员
}
// 任务类 task_LOOK_YIELD2_t 的定义
class task_LOOK_YIELD2_t : public task_t {
public:
task_LOOK_YIELD2_t() __OPT_ATTR__; // 构造函数
protected:
void routine(); // 任务例程
private:
};
// 任务类 LOOK_YIELD2 的构造函数
__OPT_INLINE__ task_LOOK_YIELD2_t::task_LOOK_YIELD2_t()
{
// TODO: 在此初始化 task_LOOK_YIELD2_t 的类成员
}
extern instantiate::task<task_LOOK_YIELD1_t, LOOK_STACK_SIZE> task_LOOK_YIELD1;
extern instantiate::task<task_LOOK_YIELD2_t, LOOK_STACK_SIZE> task_LOOK_YIELD2;
#endif // __LOOK_YIELD_H
2.LOOK_YIELD.CPP
#include "LOOK_YIELD.h"
#include "NUC1xx.h"
#include "NUC1xxM051Seriescfg.h"
// 任务类 task_LOOK_YIELD1_t 的例程
void task_LOOK_YIELD1_t::routine()
{
// TODO: 在此编写 task_LOOK_YIELD1_t 例程的内容
while (true) {
// TODO: 在此编写 task_LOOK_YIELD1_t 例程的内容
GPIOAs.DMASK.Regs = ~0b100000;//只控制GPA5即LED4
for (unsigned int i = 0; i < 0x88888; i++) asm volatile("nop");//独占CPU
GPIOAs.DOUT.Bits.Pin5 ^= 1;//LED4闪烁
scheduler.yield();//让出CPU资源,任务主动切换交出控制权给task_LOOK_YIELD2_t
}
}
// 任务类 task_LOOK_YIELD2_t 的例程
void task_LOOK_YIELD2_t::routine()
{
// TODO: 在此编写 task_LOOK_YIELD2_t 例程的内容
unsigned int count = 0;
while (true) {
// TODO: 在此编写 task_LOOK_YIELD2_t 例程的内容
for (unsigned int i = 0; i < 3; i++) {//LED1~LED3组成跑马灯
GPIOAs.DMASK.Regs = ~0b011100;//只控制GPA2~GPA4即LED1~LED3
for (unsigned int j = 0; j < 0x48888; j++) asm volatile("nop");//独占CPU
GPIOAs.DOUT.Regs = (count << 2) ^ 0b011100;
count++;
}
scheduler.yield();//让出CPU资源,任务主动切换交出控制权给task_LOOK_YIELD1_t
}
}
#ifdef LOOK_SCHEDULING_PRIORITY
instantiate::task<task_LOOK_YIELD1_t, LOOK_STACK_SIZE> task_LOOK_YIELD1(0);
instantiate::task<task_LOOK_YIELD2_t, LOOK_STACK_SIZE> task_LOOK_YIELD2(0);
#else
instantiate::task<task_LOOK_YIELD1_t, LOOK_STACK_SIZE> task_LOOK_YIELD1;
instantiate::task<task_LOOK_YIELD2_t, LOOK_STACK_SIZE> task_LOOK_YIELD2;
#endif
|