-
Notifications
You must be signed in to change notification settings - Fork 19
/
one_os.c
83 lines (77 loc) · 1.81 KB
/
one_os.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include"one_os.h"
#include"spin_common.h"
#include"spin_userstart.h"
#include"spin_interupt.h"
#include"spin_timer.h"
#include"spin_exinterupt.h"
#include"spin_gpio.h"
#include"spin_uart.h"
#include"spin_watchdog.h"
#include"spin_pwrmgr.h"
#include<string.h>
#include<stdio.h>
#define TASK_MAX(task) (sizeof(task)/sizeof(task[0]))
//定时喂狗闪灯任务
void task1(){
static uint recv_fre=0;
recv_fre=~recv_fre;
spin_set_gpio_bit_value(GPIO2,5,recv_fre);
spin_watchdog_clear();
}
void task2(){
static uchar idata recv[BUFF_MAX_SIZE];
uint ret = 0;
ret = spin_read_uart(recv);
if(ret != 0)
spin_write_uart(recv,ret);
}
//定时发送数据到串口
void task3(){
static uchar idata send[BUFF_MAX_SIZE/2];
static unsigned long sec=0;
sprintf(send,"time:%llu\r\n",sec++);
spin_write_uart(send,strlen(send));
}
static Tasks idata task[]=
{
{0,1,4000,4000,task1}, //喂狗闪灯 500ms
{1,1,400,400,task2},//读串口 50ms
// {2,1,8000,8000,task3},//写串口 1000ms
};
void TaskHangup(unsigned char Task_Num)//任务挂起函数,参数就是你的任务编号
{
task[Task_Num].Run=0;
}
void TaskRecovery(unsigned char Task_Num)//任务恢复函数,参数就是你的任务编号
{
task[Task_Num].Run=1;
}
void TaskRemarks(void) //放在定时器中断里面
{
unsigned char i;
for (i=0; i<TASK_MAX(task); i++)
{
if (task[i].Timer)
{
task[i].Timer--;
if (task[i].Timer == 0) //所以用65500这个值保证溢出的时候也能执行下面的语句
{
task[i].Timer = task[i].ItvTime;
task[i].Run = 1;
}
}
}
}
void TaskProcess(void)//放在你的while(1)循环里面
{
unsigned char i;
for (i=0; i<TASK_MAX(task); i++)
{
if (task[i].Run)
{
task[i].Run = 0;
task[i].TaskHook();
}
}
idle_mode();//进入低功耗模式
}