📄 message.c
字号:
//==============================================================================================
//File : message.c
//Description : 消息系统
//==============================================================================================
#define MESSAGE_C
#include "config.H"
#undef in
#undef out
#undef size
#define in MessageBuf[0]
#define out MessageBuf[1]
#define count MessageBuf[2]
static uint8 MessageBuf[MESSAGE_BUF_SIZE];//队列结构:in + out + count + data...
//==============================================================================================
//Function : Push
//Description : 将1字节数据压入消息队列
//Arguments : byte--1字节数据
//Returns : void
//==============================================================================================
static void _Push(uint8 byte)
{
MessageBuf[in++] = byte;
if(in >= MESSAGE_BUF_SIZE)
{
in = 3;
}
}
//==============================================================================================
//Function : Pop
//Description : 将1字节数据弹出消息队列
//Arguments : voidbyte--1字节数据
//Returns : 1字节数据
//==============================================================================================
static uint8 _Pop(void)
{
uint8 temp;
temp = MessageBuf[out++];
count++;
if(out >= MESSAGE_BUF_SIZE)
{
out = 3;
}
return temp;
}
//==============================================================================================
//Function : QueueCreate
//Description : 建立队列
//Arguments : void
//Returns : void
//==============================================================================================
void MessageInit(void)
{
in = 3; //入队位置
out = 3; //出队位置
count = MESSAGE_BUF_SIZE - 3; //可用空间
}
//==============================================================================================
//Function : MessagePush
//Description : 压入消息(无参数)
//Arguments : void
//Returns : void
//==============================================================================================
//bit MessagePush(MESSAGE msg)
uint8 MessagePush(MESSAGE msg)
{
uint8 ea;
ea = EA;
EA = 0;
if(count > 1)
{
_Push(msg);
count --;
EA = ea;
return 1;
}
EA = ea;
return 0;
}
//==============================================================================================
//Function : Message
//Description : 消息循环:分配消息到各个处理流程
//Arguments : void
//Returns : void
//==============================================================================================
//bit Message(uint8 *msg )
uint8 Message(uint8 *msg )
{
EA = 0;
if(MESSAGE_BUF_SIZE-3-count > 0) //已用空间>=2
{
*msg= _Pop();
EA = 1;
return MES_OK;
}
else
{
EA=1;
return MES_NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -