管道通信用于单片机的串口

以上是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);
}

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值