396 lines
9.1 KiB
C
396 lines
9.1 KiB
C
/**********************************************************************
|
|
RTOS底层接口函数头文件
|
|
|
|
**********************************************************************/
|
|
|
|
#ifndef __OS_TASK_H
|
|
#define __OS_TASK_H
|
|
#include "type.h"
|
|
//#include "FreeRTOS.h"
|
|
//#include "queue.h"
|
|
//#include "task.h"
|
|
#include "config.h"
|
|
#include "isys_config.h"
|
|
|
|
#define WATCHDOG_ENABLE (0)
|
|
#define TASK_CHK_ENABLE (1)
|
|
|
|
|
|
|
|
#define USE_LCD_MOUDLE (1)
|
|
#define USE_WEB_MODULE (1)
|
|
|
|
//@TMP_NOT_USED
|
|
//#define USE_LOG_MODULE (1)
|
|
|
|
|
|
#define OS_TICKS_PER_SEC (configTICK_RATE_HZ)
|
|
#define OS_WAIT_FOREVER (portMAX_DELAY)
|
|
#define OS_PER_TICK_MS (portTICK_RATE_MS)
|
|
|
|
#define OS_TASK_OK (0)
|
|
#define OS_TASK_MAX_ABNORMAL_TIME (30) //异常最大允许时间
|
|
|
|
#define OS_MSG_MAGIC_WORD (0X5533)
|
|
#define OS_MSG_ISR_TASK_ID (0XFF) //自定义的中断的任务ID
|
|
|
|
#define USE_MSG_DEBUG 0 //是否启用消息debug模式
|
|
#define USE_MEM_DEBUG 1
|
|
|
|
|
|
#define MAX_TIMER_NUM 10
|
|
|
|
|
|
#define ERR_NO_ERR 0
|
|
#define ERR_CREATE_TASK_FAILED 1
|
|
#define ERR_INVALID_PARA 2
|
|
#define ERR_INVALID_POINTER 3
|
|
#define ERR_TASKID_TOO_LARGE 4
|
|
#define ERR_NO_MEM 5
|
|
#define ERR_CREATE_QUEUE_FAILED 6
|
|
#define ERR_SEND_MSG_FAILED 7
|
|
#define ERR_SEM_PTR_INVALID 8
|
|
#define ERR_POST_SEM_FAILED 9
|
|
#define ERR_PEND_SEM_FAILED 10
|
|
|
|
#define ERR_MUTEX_PTR_INVALID 11
|
|
#define ERR_TAKE_MUTEX_FAILED 12
|
|
#define ERR_GIVE_MUTEX_FAILED 13
|
|
#define ERR_I2C_NUM_ERR 14
|
|
#define ERR_SPI_NUM_ERR 15
|
|
#define ERR_CREATE_SEM_FAILED 16
|
|
#define ERR_CREATE_MUTEX_FAILED 17
|
|
|
|
typedef void * SEM_HANDLE;
|
|
typedef void * MUTEX_HANDLE;
|
|
|
|
typedef uint32 HANDLE;
|
|
|
|
|
|
#define USE_DEBUG_UART 0 //串口调试信息开关 提交版本库时,本值必须为0
|
|
|
|
#if USE_DEBUG_UART //串口信息调试,可直接调用printf打印输出
|
|
#define DEBUG_UART 1
|
|
#endif
|
|
|
|
/*
|
|
#if USE_DEBUG_UART
|
|
extern int printf(const char *,...);
|
|
#else
|
|
#include "stdio.h"
|
|
#define printf(p,...) //若没开启调试模式,printf定义为空
|
|
#endif
|
|
*/
|
|
|
|
/*
|
|
typedef struct
|
|
{
|
|
uint16 type;
|
|
uint16 need_free; //若为申请消息,此位不要用,默认已填充释放标记
|
|
uint16 wPara;
|
|
uint16 rPara;
|
|
uint32 lPara;
|
|
}MSG,*pMSG;*/
|
|
|
|
typedef struct
|
|
{
|
|
MSG msg;
|
|
uint16 magci_word;
|
|
uint8 alloc_id;
|
|
uint8 rec_id;
|
|
}MSG_DEBUG;
|
|
|
|
typedef struct
|
|
{
|
|
uint32 tick;
|
|
uint32 size;
|
|
}MEM_DEBUG_HEADER;
|
|
|
|
|
|
typedef struct
|
|
{
|
|
#if USE_MEM_DEBUG
|
|
MEM_DEBUG_HEADER header;
|
|
#endif
|
|
uint8 mem[1];
|
|
}MEM_PTR;
|
|
|
|
|
|
#define MAX_TASK 16 //当前用户层任务上限 不包含以太网以及系统任务
|
|
|
|
|
|
//数组下标为task_id
|
|
typedef struct
|
|
{
|
|
uint32 num;
|
|
uint8 created[MAX_TASK]; //任务是否建立标识
|
|
uint8 status[MAX_TASK];
|
|
uint8 pause[MAX_TASK]; //暂停时间长度,单位 秒
|
|
uint8 ignore_chk[MAX_TASK]; //忽略检查,特殊任务使用
|
|
xQueueHandle queue[MAX_TASK];
|
|
}SYS_TASK,*pSYS_TASK;
|
|
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint32 isr_send_num;
|
|
uint32 task_send_num;
|
|
uint32 isr_alloc_num;
|
|
uint32 task_alloc_num;
|
|
uint32 free_num;
|
|
}S_MSG_STATE;
|
|
|
|
typedef struct
|
|
{
|
|
uint32 used;
|
|
uint32 total;
|
|
}S_MEM_STATE;
|
|
|
|
typedef struct
|
|
{
|
|
uint32 min_num;
|
|
uint32 min_msg_q[MAX_TASK];
|
|
uint32 sec_num;
|
|
uint32 sec_msg_q[MAX_TASK]; //依次存放配置的任务ID
|
|
}TIME_MSG_Q;
|
|
|
|
typedef struct
|
|
{ //待扩展
|
|
uint32 reset_total_time;
|
|
S_SYS_TIME close_time;
|
|
|
|
#if USE_LCD_MOUDLE
|
|
uint8 os_log[1];
|
|
#endif
|
|
|
|
}S_BACKUP_MEM;
|
|
|
|
|
|
//持续按键,等待间隔
|
|
#define KEY_DELAY_TIME (300)
|
|
#define TMR_IDLE 0
|
|
#define TMR_RUN 1
|
|
#define TMR_STOP 2
|
|
#define TMR_TYPE_ONE 0
|
|
#define TMR_TYPE_CYCLE 1
|
|
|
|
#define MSG_NEED_FREE (0x55)
|
|
#define MSG_NO_NEED_FREE (0xaa)
|
|
|
|
#define MSG_NEED_TO_FREE(pmsg) (pmsg->need_free==MSG_NEED_FREE)
|
|
|
|
|
|
enum{RET_OK = 0,RET_ERR,RET_NO_MEM,RET_NOT_FIND,RET_RET_ERR,RET_WRITE_FAIL,RET_READ_FAIL};
|
|
|
|
|
|
typedef struct __TIMER
|
|
{
|
|
uint32 state;
|
|
uint32 ticks;
|
|
uint32 count;
|
|
uint32 type;
|
|
uint32 task_id; //由创建该消息的接收
|
|
MSG msg;
|
|
}TIMER,*PTIMER;
|
|
|
|
|
|
|
|
typedef enum
|
|
{
|
|
MSG_RS232 = 0x10,
|
|
MSG_ETH,
|
|
MSG_SEC,
|
|
MSG_MINUTE,
|
|
MSG_WRITE_PARA,
|
|
MSG_READ_PARA,
|
|
MSG_KEY,
|
|
MSG_TIMER,
|
|
MSG_UPGRADE,
|
|
MSG_HTTP_UPDATE, //http发送给液晶做update校正,
|
|
MSG_WEB_SAVE_PARA,
|
|
MSG_FPGA_UPGRADE,//MSG_FPGA_UPGRADE_OVER
|
|
MSG_UDP_ALRM,
|
|
MSG_UART_ALRM,
|
|
MSG_LOG,
|
|
MSG_LOG_RECORD_RESET,
|
|
MSG_UART_RE_INIT,
|
|
MSG_SHOW_WAIT,
|
|
MSG_PSTS_UPDATE,
|
|
MSG_MCU_REBOOT,
|
|
|
|
|
|
MSG_IGMP_REINIT,
|
|
}MSG_TYPE;
|
|
|
|
enum{
|
|
DISPLAY_FPGA_UPGRADE_OVER=1,
|
|
DISPLAY_FPGA_UPGRADE_ERR,
|
|
DISPLAY_FPGA_UPGRADE_BUSY_TIMEOUT,
|
|
|
|
DISPALY_RFAGC_ERR_POWER_LOW,
|
|
DISPALY_RFAGC_ERR_POWER_HIGH
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
{
|
|
E_RA = 0x10,
|
|
W_SYSTEM,
|
|
W_RF,
|
|
W_WA,
|
|
W_WB,
|
|
W_WC,
|
|
W_WD,
|
|
W_WE,
|
|
W_WF,
|
|
W_RF_DELAY,
|
|
W_ADPC,
|
|
W_CONFIGA,
|
|
W_CONFIGB,
|
|
W_CONFIGC,
|
|
W_CONFIGD,
|
|
W_HTTP_CGI1,
|
|
W_HTTP_CGI2,
|
|
W_UPDATE_STOP,
|
|
W_UPDATE,
|
|
W_OUTPUT,
|
|
W_FAC_C,
|
|
W_FAC_F,
|
|
W_FAC_H,
|
|
W_RF_ONLY,
|
|
W_SIM_TEST,
|
|
W_SIM_PW_ERR,
|
|
W_SIM_PARA,
|
|
|
|
R_LOG = 100,
|
|
R_RF_DELAY,
|
|
R_UPDATE, //不可超过255 0xff
|
|
R_SIM_PARA,
|
|
R_LOG4,
|
|
}PARA_TYPE;
|
|
/*
|
|
#define UART_RCV_BUF_LEN (1024)
|
|
#define UART_SEND_BUF_LEN (256)
|
|
#define UART_REC_BUF_BAK (1<<2) ////必须全bit都为1的值+1 串口接收缓冲区
|
|
#define UART_PORT_NUM (3) //(4)
|
|
|
|
typedef struct
|
|
{
|
|
uint32 valid;
|
|
uint32 task_id; //处理串口消息任务ID
|
|
MUTEX_HANDLE mutex;
|
|
MSG msg[UART_REC_BUF_BAK];
|
|
uint16 index;
|
|
uint16 length; //发送长度
|
|
uint32 buf_cnt;
|
|
uint8 buffer[UART_REC_BUF_BAK][UART_RCV_BUF_LEN];
|
|
}S_UART_RX_CTRL;
|
|
*/
|
|
/**********************当前文件提供的对外API函数*************************************************/
|
|
uint32 create_task(void (*fun)(void*),char* pcname,uint32 task_id,uint32 task_pro,uint32 stacksize,uint32 queuesize);
|
|
uint32 task_set_ignore_chk(uint32 task_id);
|
|
|
|
uint32 send_msg(uint32 task_id,pMSG pmsg);
|
|
pMSG get_msg(uint32 wait_ticks);
|
|
|
|
MSG* alloc_msg(void);
|
|
void free_msg(pMSG p);
|
|
|
|
void *alloc_mem(uint32 size);
|
|
void free_mem(void* pmem);
|
|
|
|
//信号量相关函数,pend函数(等待),只能在正常任务中使用,post任务体,中断均可使用
|
|
//主要用来在中断中post,然后再一个任务中pend(阻塞型),减少中断处理时间并加快任务响应速度
|
|
SEM_HANDLE create_sem(uint32 max_count,uint32 init_count);
|
|
uint32 pend_sem(SEM_HANDLE sem_hd,uint32 wait_ticks);
|
|
uint32 post_sem(SEM_HANDLE sem_hd);
|
|
|
|
|
|
//互斥相关函数,只能在正常任务体中使用,不能用于中断 一般在多任务资源共享时使用 使用时take(若take不到,将会阻塞),用完后及时give
|
|
//时间短的操作,可以关任务调度实现
|
|
MUTEX_HANDLE create_mutex(void);
|
|
uint32 take_mutex(MUTEX_HANDLE mtx_hd);
|
|
uint32 give_mutex(MUTEX_HANDLE mtx_hd);
|
|
|
|
|
|
void os_int_enter(void);
|
|
void os_int_exit(void);
|
|
|
|
uint32 os_get_free_heap_size(void);
|
|
|
|
S_SYS_TIME *os_get_sys_time_ptr(void);
|
|
uint32 get_cpu_useage(void);
|
|
void send_clk_msg(void);
|
|
void calc_cpu_usage(void);
|
|
//void get_sys_time(S_SYS_TIME* pt);
|
|
void update_sys_time_by_rtc(void);
|
|
uint32 config_time_msg(uint32 type);
|
|
void sys_para_init(void);
|
|
//#define get_sys_tick xTaskGetTickCount
|
|
void get_msg_state(S_MSG_STATE *pstate);
|
|
void get_mem_state(S_MEM_STATE *pstate); //仅在内存调试打开时有效
|
|
uint32 get_current_task_id(uint32 *pid);
|
|
uint32 get_task_id(uint32 *pid,void *ptcb);
|
|
void task_is_ok(void);
|
|
uint32 task_chk_status(void);
|
|
void os_dead_task_abnormal(uint32 task_id);
|
|
void os_dead_wwdg(void);
|
|
void task_stop_sec_msg(void);
|
|
void task_resume_sec_msg(void);
|
|
/******************************************END*****************************************************/
|
|
|
|
/* Exported functions ------------------------------------------------------- */
|
|
extern uint32 get_sys_clk(void);
|
|
|
|
#if configUSE_CALC_CPU_USAGE
|
|
extern uint32 get_idle_run_time(void);
|
|
extern void set_idle_run_time(uint32);
|
|
#endif
|
|
|
|
|
|
#define OS_DEFAULT_STACK_SIZE (configMINIMAL_STACK_SIZE*2) //默认1k字节
|
|
#define OS_DEFAULT_QUEUE_SIZE (100*sizeof(void*))
|
|
|
|
|
|
|
|
/*--------------- Tasks ID -------------*/
|
|
|
|
//同一优先级任务可创建多个,
|
|
typedef enum
|
|
{
|
|
PRIORITY_VERY_HIGH = (tskIDLE_PRIORITY+4), //最高优先级任务,
|
|
PRIORITY_HIGH = (tskIDLE_PRIORITY+3), //特殊任务,如主任务等
|
|
PRIORITY_NORMAL = (tskIDLE_PRIORITY+2), //默认优先级
|
|
PRIORITY_LOW = (tskIDLE_PRIORITY+1), //低优先级任务
|
|
|
|
}E_TASK_RPIPRITY;
|
|
|
|
enum E_TASK_ID
|
|
{
|
|
MAIN_TASK_ID = 0,
|
|
LCD_TASK_ID,
|
|
UART_TASK_ID,
|
|
GPS_TASK_ID,
|
|
WEB_TASK_ID,
|
|
|
|
LOG_TASK_ID,// 5
|
|
TCP_REMOTE_TASK_ID,
|
|
FPGA_UPGRADE_TASK_ID,
|
|
SWAP_TASK_ID,
|
|
SPECT_TASK_ID,
|
|
|
|
UDP_REMOTE_TASK_ID,// 10
|
|
SNTP_TASK_ID,
|
|
TEST_TASK_ID,
|
|
AUTO_UDP_TASK_ID,
|
|
IDLE_TASK_ID,// 14
|
|
}; //任务序号,必须全局唯一,否则会出现异常
|
|
|
|
|
|
#endif
|
|
|
|
|