📄 emnetrtos.h
字号:
/* Data Structure Define */
#include<p18f452.h>
//#define MAX_SEM 255
typedef unsigned char emBool; /* FALSE or TRUE */
typedef unsigned char emInt8; /* 0 to +255 */
typedef unsigned int emInt16; /* 0 to +65,535 */
typedef unsigned long emInt32; /* 0 to +4,294,967,295 */
typedef char emchar8;
#define MAX_TASK 16
#define HTM0 0
#define LTM0 0
#define TRUE 1
#define FALSE 0
#define CPU_CLOCK 20 //当使用不同的时钟时,请更改此设置
#define HARD_TIMER_NULL 7
#define HARD_TIMER_WORK 6
typedef struct{ /* status of hardtimer: */
emInt8 Ht_value:5; /* 5 bits of high bits of timer*/
emInt8 Flg:3; /* high 3 bits of state 111 表明定时器未启动,110 表明定时器正在工作*/
} emHardtStatus;
typedef struct HardTimer{
union{
emHardtStatus IDtimer;
emInt8 bIDtimer;
}htstatus;
emInt16 Lt_value;
emInt32 temp;
};
#define emWpth(nRunID) TOSH=pTcb[nRunID].byRpch /* write branch high pc valuePCLATH*/
#define emWptl(nRunID) TOSL=pTcb[nRunID].byRpcl /* write branch low pc valuePCL*/
#define emWpth1(nRunID) TOSH=pTcb[nRunID].bySpch /* PCLATHwrite branch high pc value*/
#define emWptl1(nRunID) TOSL=pTcb[nRunID].bySpcl /* PCLwrite branch low pc value*/
#define emSpch(nRunID) pTcb[nRunID].byRpch=TOSH /* Save current task high pc value*/
#define emSpcl(nRunID) pTcb[nRunID].byRpcl=TOSL /* Save current task low pc value*/
#define emSfsrh(nRunID) pTcb[nRunID].bySavf=FSR0H /* Save current task high pc value*/
#define emSfsrl(nRunID) pTcb[nRunID].bySavb=FSR0L /* Save current task low pc value*/
#define emWfsrh(nRunID) FSR0H=pTcb[nRunID].bySavf /* Save current task high pc value*/
#define emWfsrl(nRunID) FSR0L=pTcb[nRunID].bySavb /* Save current task low pc value*/
emBool emSetHardTimer(emInt8 tid, emInt16 value);
emBool emStartHardTimer(emInt8 tid);
emInt8 emCheckHardTimer(emInt8 tid);
/* 属性 16 位,状态8位,操作类型8位 MCC-18可能不支持下面的位操作形式*/
typedef struct { /* status consists of: */
emInt8 prio:4; /* 4 bits of priority */
emInt8 statu:4; /* 4 bits of state */
} emStatus;
typedef emInt8 emStatusByte; /*status use by byte*/
#define RUNNING 00 /*运行状态*/
#define READY 01
#define WAIT 02 /*等待消息或事件*/
#define DELAY 03 /*准确延时*/
#define TERMINATED 04 /*超时造成这种状态*/
#define FINISHED 05
#define SUPEND 06 /*当高级任务中断低级任务时*/
#define TASKNULL 15 /*表示此任务没有用*/
struct tcb {
unsigned char bySpch;
unsigned char bySpcl;
union {
emStatus bits;
emStatusByte byte;
}status;
emInt8 delaytime;
unsigned char byRpch;
unsigned char byRpcl;
emInt8 bySavw;
emInt8 bySavf;
emInt8 bySavb;
};
#define OK 0
#define E_SYS -5 /*系统错误*/
#define E_ID -10 /*invalid ID number*/
#define E_CTX -15 /*context error*/
#define E_TMOVT -20 /*timeout exceeded*/
#define E_PRO -25 /*priority error*/
/*Run task search Function*/
void emSerTask(void);
/*Following is message functions define*/
void emCreatTask( void (* taskname)(),unsigned char taskID,unsigned char taskpro);//现在最大任务号为15,最多先允许创建16个任务
void emStar(void);
void emSched(void);
void emChpTask(unsigned char taskpro);
void emDeyTask(unsigned char dtim);
/*Message transfer,first create a 2 bytes message struct*/
#define NULLMESG 255 //没有消息时的状态
#define IDLEMESG 254
typedef struct{ //用一个字节,表示两个任务ID
emInt8 txMesgtaskID:4;//产生消息的任务ID
emInt8 rxMesgtaskID:4;//接收消息任务ID
}emTaskMesg;
typedef struct emMessage{
union{
emTaskMesg taskID;
emInt8 btaskID;
}tID;
emInt8 Mesg; //消息的内容
};
emchar8 emCreateMesg(emInt8 mesgID,emInt8 TaskID);//创建消息,参数为消息号.最多有256条消息.目前只分配了16条的消息存储空间,成功返回1,错误返回0
emchar8 emTxMesg(emInt8 mesgID,emInt8 message);//发送消息到对应的消息号中,参数2为发送的内容,成功返回1,错误返回0
emInt8 emRxMesg(emInt8 mesgID);//从消息队列中接收消息,返回值为消息内容
emInt8 emWaitMesg(emInt8 mesgID);//,emInt8 message);//等待消息,参数2为等待的内容,有消息则执行,没有则调用挂起函数挂起此任务
void emDeleteMesg(emInt8 mesgID);//删除消息
/*Timer Functions,basictime is tick*/
#define NULLTIME 255 //定义定时器没有设置定时值
#define IDLETIME 254 //定义定时器没有使用
typedef struct emTimer{
union{
emTaskMesg TaskID;
emInt8 btaskID;
}tID;
emInt8 Valuetime;
};
emchar8 emCreateTimer(emInt8 timeID,emInt8 TaskID);//创建定时器,只有16个,多出则报告错误。
void emSetimeValue(emInt8 timeID,emInt8 tvalue);//设置定时器的定时时间
emInt8 emStartTimer(emInt8 timeID);
void emDeleteTimer(emInt8 timeID);
void emWait(void);
//#define MAX_Buf 255//buffer pool only two for pic18452
#ifndef MAXTBUF
#define MAX_Buf 255
#endif
/*Define the attribute of mailbox*/
#define malNULL 15
#define malExist 1
#define malReded 2
#define malReceived 3
#define malBroadcast 4
typedef struct{
emInt8 mailAttribute:4;
emInt8 mailID:4;
}Atrmail;
typedef union mailFirst{
Atrmail atr;
emInt8 Firstb;
};
typedef union mailtask{
emTaskMesg tID;
emInt8 Seconeb;
};
/*Following is message functions define*/
emInt8 *emGetMem(emInt8 mnum);//get memory from RAM
char emCreatMal(unsigned char nid,unsigned char nsi);//create mailbox
unsigned char *emGetSmal(unsigned char nid);//get the start address of mailbox in buffer memory
char emSendMal(unsigned char miD,unsigned char *pMesg,unsigned char nByte);//send mailbox
unsigned char *emRecMal(unsigned char miD);//recieve mailbox,ok return the length of mailbox
unsigned char *emReadMal(unsigned char miD);//一对多机制下的邮箱信息读
void *emReleaseMal(unsigned char miD);//释放邮箱资源
char emBroadMal(unsigned char miD,unsigned char *pMesg,unsigned char nByte);//一对多邮箱的信息发送
/*typedef struct emSem1{
union{
emTaskMesg taskID;
emInt8 bID;
}tID;
emInt16 Isem;
};*/
//char emCreatFlg(unsigned char fID,unsigned iniVal);//create flag and give the ini value
//void emRelFlg(unsigned char fID);//release evenflag
//void emWatFlg(unsigned char fID);//if wait do the taskexec.
//void emSetFlg(unsigned char fID);
//emchar8 emAwaitFlg(unsigned char fID);
/*Flag functions define*/
#define idle 15
#define taken 1
typedef struct {
emInt8 statu:4;
emInt8 RtaskID:4;
} emResSem;
struct emSem1
{ emResSem ResSem;
emInt16 queue;
};
char emCreatSem(unsigned char SemID);//创建一个标志位,
char emGetSem (unsigned char SemID);
void emRelSem(unsigned char SemID);
/*semaphore define*/
#define semNULL 255
//sem struct define
/*sem functions define */
//void emCreatSem(unsigned char sID,char iniVal);
void emRelSem(unsigned char sID);
void emWatSem(unsigned char sID);
/*following is time slice functions define */
char emSetTice(void);//(unsigned char fclock),unsigned char tnum);//set the timeslice by user
void emSysini(void);
/*following function is system Message*/
/*#define SysTcpConnect 200
#define SysTcpTransmit 201
#define SysTcpTransmited 202
#define SysTcpRecieve 203
#define SysTcpRecieved 204
#define SysTcpClosed 205
#define SysNetLinked 210 //TCP断开,但以太网连接着
#define SysNetShutdown 211 //以太网也断开
#define SysTcpBufferNULL 220
#define SysTcpBufferBusy 221*/
#define SysArpRecieved 150 //收到相应的arp包
#define SysArpTransmited 151 //arp包发送成功
#define SysArpResponsed 152 //对arp请求包进行了相应
#define SysArpGetwrong 153 //arp包内容错误
#define SysArpGetNull 154 //arp包为空
#define SysPingRecieved 155 //收到ping包
#define SysPingResponse 156 //对ping包进行了响应
#define SysMacGetnothing 157 //没有收到数据包
#define NODE1establish 158 //节点1连在网上
#define NODE2establish 159 //节点2连在网上
#define NODE3establish 160 //节点3连在网上
#define NODE1disconnect 161 //节点1没有连在网上
#define NODE2disconnect 162 //节点2没有连在网上
#define NODE3disconnect 163 //节点3没有连在网上
#define sysTMREend 164 //定时时间到
#define SysTcpConnect 200 //TCP连接建立
#define SysTcpTransmit 201 //发送TCP包
#define SysTcpTransmited 202 //TCP包发送成功
#define SysTcpRecieve 203 //接受TCP包
#define SysTcpRecieved 204 //已经接受到TCP包
#define SysTcpClosed 205 //关断TCP连接
#define SysTcpWrong 206 //TCP包出现错误
#define SysTcpDisconnect 207 //TCP连接失败
#define SysNetLinked 210 //TCP断开,但以太网连接着
#define SysNetShutdown 211 //以太网也断开
#define SysTcpTsBufferNULL 220 //TCP发送缓冲区为空
#define SysTcpTsBufferBusy 221 //TCP发送缓冲区满
#define SysTcpRcBufferNULL 220 //TCP接受缓冲区为空
#define SysTcpRcBufferBusy 221 //TCP接受缓冲区满
void emTxSysMesg(emInt8 message);
emInt8 emRxSysMesg(void);
void emDelSysMesg(void);
#define SysMailLength 16
#define SysMailNULL 15
#define SysMailSysReceive 14
#define SysMailTaskReceive 13
#define SysMailToSys 7
#define SysMailToTask 6
void emCreatSysMal(void);
char emSendSysMal(emInt8 maila,emInt8 *pMesg,emInt8 nByte);
emInt8 emGetSysMal(void);
emInt8 *emRecSysMal(emInt8 maila);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -