You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.3 KiB
89 lines
3.3 KiB
4 years ago
|
|
||
4 years ago
|
/*****************************************************************************
|
||
|
update by cc @201501101001
|
||
|
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是
|
||
|
个需要平衡的事情.
|
||
|
|
||
|
uartcom/uartlib.c:
|
||
|
公用的函数 和硬件无关
|
||
|
放置串行模式(串口等其他通讯总线类的输出)输出的函数,
|
||
|
一些覆盖模式输出的(lcd等固屏输出的)的也可使用
|
||
|
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
uartcom/uartcom0
|
||
|
和uart相关的通讯协议 com + n
|
||
|
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关
|
||
|
|
||
|
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------
|
||
|
L3_UARTcom0_exp_protocol 解析应用协议
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
uartcom/uprotocol: 主要是为 uartcom + n服务的 驱动层到应用层缓存的过度
|
||
|
公用的串口通讯定义
|
||
|
struct _s_protocol_ 的公共协议包(关键的结构体)的声明------struct _s_protocol_
|
||
|
void L1_uart_2buf(struct _s_protocol_ *p)串行数据保存到缓冲中
|
||
|
--------------------------------------------------------------------------------------------
|
||
|
msp/uartx.c 底层代码 和cpu相关
|
||
|
L0_UART0_Init
|
||
|
UART0_IRQHandler
|
||
|
L0_Usend_uc----------s_at0
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
********************************************************************************/
|
||
|
|
||
4 years ago
|
#include "debug.h"
|
||
4 years ago
|
#include "../clib/clib.h"
|
||
|
|
||
|
//NUM: 0 1 2 3 4
|
||
|
// Fx R1 R2 R3 ocr
|
||
|
// F+从机 R1 R2 R3 校验
|
||
|
//相关功能移动到tpc_fx.c
|
||
|
/// 实践中发现 如果收到多个以0d0a结束的短协议时,如果
|
||
|
/// 协议之间间隔时间太短,ok处理不及时 会出现丢失协议的
|
||
|
/// 的情况,所以 对于短暂的多个协议 应该有一定容量的缓冲
|
||
|
/// 保留 ,同时 处理完协议后,应该清除接收缓冲,否则缓冲
|
||
|
/// 会在自身满了后自动清除
|
||
|
//_s_HRTU_P_rf_
|
||
|
/// _s_HRTU_Pfx_
|
||
|
/// fx 11 22 33 oc -- oc = 11+ 22+33
|
||
|
//buf 0 1 2 3 [4]
|
||
|
//fd 01 02 03 06 fd为头 010203为数据 06为数据校验和(01+02+03)
|
||
|
|
||
|
//对于连续的多条协议,如果前一条处理不及时,可能会被后一条覆盖
|
||
|
void L1_s2b_PH1 (struct _tp_handler_x *p) //reentrant
|
||
|
{
|
||
|
if (0 == p->head)
|
||
|
{
|
||
|
if (D_HETU_FX_fi == (p->reg & p->head_0))
|
||
|
{
|
||
|
p->head = 1;
|
||
|
p->num = 1;
|
||
|
p->buf[0] = p->reg;
|
||
|
//p->ok = 1;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
p->buf[p->num++] = p->reg;
|
||
|
if(p->num >= D_HETU_FX_buf_max) // [D_HETU_FX_buf_max == 5]
|
||
|
{
|
||
|
p->ocr = p->buf[1];
|
||
|
p->ocr += p->buf[2];
|
||
|
p->ocr += p->buf[3];
|
||
|
if(p->ocr == p->buf[D_HETU_FX_buf_max-1])
|
||
|
{
|
||
|
if (p->ok != 1)
|
||
|
{
|
||
|
p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文
|
||
|
}
|
||
|
}
|
||
|
p->head = 0; //放在if (p->ok != 1) 外
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/******************************************************************************
|
||
|
** End Of File
|
||
|
******************************************************************************/
|
||
|
|