118 lines
3.6 KiB
C
118 lines
3.6 KiB
C
/****************************************************************************
|
|
文件名称 : chrg_thread.h
|
|
完成日期 :
|
|
当前版本号 : V1.0
|
|
主要功能 : 统一管理业务线程,业务线程信息定义。
|
|
版本历史 : 创建原始版本
|
|
说明 :
|
|
******************************************************************************/
|
|
|
|
#ifndef __CHRG_THREAD_H__
|
|
#define __CHRG_THREAD_H__
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "chrg_north.h"
|
|
#include "chrg_south.h"
|
|
#include "chrg_comm.h"
|
|
#include "chrg_lcd.h"
|
|
#include "chrg_roll_nor.h"
|
|
#include "chrg_roll_sou.h"
|
|
|
|
typedef enum {
|
|
IDX_THR_NORTH = 0, // 北向接收线程
|
|
IDX_THR_SOUTH, // 南向接收线程
|
|
IDX_THR_COMM, // 对外通信线程
|
|
IDX_THR_LCD, // LCD 接收线程
|
|
IDX_THR_ROLL_NOR, // 北向轮巡发送线程
|
|
IDX_THR_ROLL_SOU, // 南向轮巡发送线程
|
|
|
|
TOTAL_THRS
|
|
} eIDX_THRS;
|
|
|
|
#define PRI_THR_NORTH 15
|
|
#define PRI_THR_SOUTH 14
|
|
#define PRI_THR_COMM 13
|
|
#define PRI_THR_LCD 12
|
|
#define PRI_THR_ROLL_NOR 16
|
|
#define PRI_THR_ROLL_SOU 16
|
|
|
|
|
|
#define EN_THR_NONE 0x00
|
|
#define EN_THR_MUTEX 0x01 // 线程使用 锁
|
|
#define EN_THR_SEM 0x02 // 线程使用 信号量
|
|
#define EN_THR_MAILBOX 0x04 // 线程使用 邮箱
|
|
#define EN_THR_EVENT 0x08 // 线程使用 事件
|
|
#define EN_THR_MQ 0x10 // 线程使用 消息队列
|
|
#define EN_THR_MASK (EN_THR_MUTEX|EN_THR_SEM|EN_THR_MAILBOX|EN_THR_EVENT|EN_THR_MQ)
|
|
|
|
/* 线程信息 */
|
|
struct chrg_thread_t {
|
|
const char *name; // 线程名
|
|
struct rt_thread *tid; // 线程编号
|
|
|
|
rt_mutex_t mutex; // 锁
|
|
rt_sem_t sem; // 信号量
|
|
rt_mailbox_t mb; // 邮件
|
|
rt_event_t ev; // 事件
|
|
rt_mq_t mq; // 消息队列
|
|
|
|
rt_uint8_t mask; // use b0:lock b1:sem b2:mailbox b3:event b4:messagequeue
|
|
|
|
rt_uint8_t index; // 线程索引
|
|
rt_uint8_t priority; // 优先级
|
|
rt_uint32_t stack; // 堆栈大小
|
|
rt_uint32_t tick; // 时间片
|
|
|
|
void (*entry)(void *parameter); // 线程体入口
|
|
};
|
|
|
|
extern struct chrg_thread_t chrgthr[TOTAL_THRS];
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_thread_evt_send
|
|
函数描述: 向指定线程发送事件编号
|
|
输入参数: idx: 目的线程编号, data: 事件编号
|
|
输出参数: -
|
|
返回说明: 0: OK , !=0 : FAILED
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern rt_err_t chrg_thread_evt_send (eIDX_THRS idx, rt_uint32_t data);
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_thread_mb_send
|
|
函数描述: 向指定线程发送邮件
|
|
输入参数: idx: 目的线程编号, *data: 邮件指针
|
|
输出参数: -
|
|
返回说明: RT_EOK: OK , RT_ERROR : FAILED
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern rt_err_t chrg_thread_mb_send (eIDX_THRS idx, void *data);
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_thread_mq_send
|
|
函数描述: 向指定线程发送消息队列
|
|
输入参数: idx: 目的线程编号, *data: 消息队列指针, len:消息长度
|
|
输出参数: -
|
|
返回说明: 0: OK , !=0 : FAILED
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern rt_err_t chrg_thread_mq_send (eIDX_THRS idx, void *data, rt_size_t len);
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_thread_create
|
|
函数描述: 创建单个线程
|
|
输入参数: idx: 线程编号
|
|
输出参数: -
|
|
返回说明: RT_EOK: OK , RT_ERROR : FAILED
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern int chrg_thread_create (eIDX_THRS idx);
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|