以上是pipe模块的头文件--pipe.h。
以上是pipe模块的实现代码--pipe.c 。
下面说一下它的用法:
#include "pipe.h" // 包含头文件
static BYTE command_buffer[132]; // 定义缓存的容量
static Pipe_t command_pipe; // 定义pipe结构体
void InitRs232CommandVariable(void)
{
pipe_init(&command_pipe, command_buffer, sizeof(command_buffer)); // 在初始化代码中初始化pipe结构体。
。。。。。。
}
void TaskCommand(void) // 在主循环中调用,用于读取pipe的字节流然后处理。
{
BYTE value;
// from pipe receive data
while(pipe_read(&command_pipe, &value)) // 从pipe读取字节流
{
if(ReceiveCommand(value)) // 接收到需要的字节流就跳出
{
// continue do nothing
}
else
{
break;
}
}
}
/*
* Function: IsrReceiveCommand
* Usage: IsrReceiveCommand
* ---------------------------------------
* 此函数在串口的中断处理函数中调用,以接受命令。
*/
void IsrReceiveCommand(BYTE value)
{
pipe_write(&command_pipe, value);
}