|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
/// COPYRIGHT NOTICE
|
|
|
|
/// Copyright (c) 2015, 传控科技
|
|
|
|
/// All rights reserved.
|
|
|
|
///
|
|
|
|
/// @file main.c
|
|
|
|
/// @brief main app
|
|
|
|
///
|
|
|
|
///(本文件实现的功能的详述)
|
|
|
|
///
|
|
|
|
/// @version 1.1 CCsens technology
|
|
|
|
/// @author CC
|
|
|
|
/// @date 20150102
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// 修订说明:最初版本
|
|
|
|
/// Modified by:
|
|
|
|
/// Modified date:
|
|
|
|
/// Version:
|
|
|
|
/// Descriptions:
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
/*****************************************************************************
|
|
|
|
update by cc @201700110
|
|
|
|
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是
|
|
|
|
个需要平衡的事情.
|
|
|
|
|
|
|
|
clib/c_lib.c:
|
|
|
|
公用的函数 和硬件无关
|
|
|
|
放置串行模式(串口等其他通讯总线类的输出)输出的函数,
|
|
|
|
一些覆盖模式输出的(lcd等固屏输出的)的也可使用
|
|
|
|
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
uartcom/Uprotocol2app
|
|
|
|
协议到应用
|
|
|
|
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关
|
|
|
|
|
|
|
|
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------
|
|
|
|
L3_UARTcom0_exp_protocol 解析应用协议
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式
|
|
|
|
公用的串口通讯定义
|
|
|
|
struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_
|
|
|
|
void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中
|
|
|
|
--------------------------------------------------------------------------------------------
|
|
|
|
msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面
|
|
|
|
L0_UART0_Init
|
|
|
|
UART0_IRQHandler
|
|
|
|
L0_Usend_uc------UserDef
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _uartN_H
|
|
|
|
#define _uartN_H
|
|
|
|
#include "../clib/c_lib.h"
|
|
|
|
#include "../tpc/tpc_x.h"
|
|
|
|
#include "c_lib.h"
|
|
|
|
|
|
|
|
#define D_uartN_free() (0 == ts_uart_send_shop[uartx].max)
|
|
|
|
#define D_uartN_busy() (0 != ts_uart_send_shop[uartx].max)
|
|
|
|
#define D_BRT_COUNT(t,clk,uartBRT) (U16)(65536- (clk / (4 * uartBRT * t)))
|
|
|
|
|
|
|
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
|
|
////fixme:和cpu的程序容量息息相关
|
|
|
|
#define D_send_buf_max 16 /// 9600bps = 10000bps = 1000 Bps = 1Byte/ms
|
|
|
|
/// 19200bps = 20000bps = 2000Bps = 2Byte/ms = 1Byte/0.5ms
|
|
|
|
/// 128Bytes = 128*0.5ms = 64ms
|
|
|
|
#define D_send_buf2_max 8 //此处改动会影响L0_uartN_ulhex函数
|
|
|
|
|
|
|
|
typedef struct _ts_uart0_send_buf_
|
|
|
|
{//8byte
|
|
|
|
vU8 num; //接收到的数目注意数据长度的范围
|
|
|
|
vU8 *p;
|
|
|
|
vU16 now; /// 当前buf所在的位置 0------(max-1)
|
|
|
|
vU16 max; /// 当前buf的最大值,也就是需要发送的长度
|
|
|
|
vU32 over; /// 结束等待标志,over累加到某个值时,结束等待
|
|
|
|
vU8 ok; /// 发送完成标志
|
|
|
|
vU8 buf[D_send_buf_max + 1];
|
|
|
|
/// U8 buf2[D_send_buf2_max];
|
|
|
|
vU8 buf3[D_send_buf2_max];
|
|
|
|
//// U8 buf4[D_send_buf_max];
|
|
|
|
/// U8 buf[D_send_buf_max + 1];//buffer 的第一位是 长度
|
|
|
|
}TP_Uart_RE_;
|
|
|
|
|
|
|
|
// typedef struct _TS_uart_reg
|
|
|
|
// {
|
|
|
|
// TP_Uart_RE_ *p;
|
|
|
|
// //eUSCI_UART_Config *c;
|
|
|
|
// //int sta;
|
|
|
|
// //U8 heartbeat;
|
|
|
|
// TP_Handler_X *t;
|
|
|
|
// void (*tp_handler)(TP_Handler_X *); //reentrant;
|
|
|
|
// U8 *ack; //ack
|
|
|
|
// }TS_uart_reg;
|
|
|
|
|
|
|
|
typedef struct _TS_uart_reg
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
vU8 num; //接收到的数目注意数据长度的范围
|
|
|
|
vU8 *p;
|
|
|
|
vU16 now; /// 当前buf所在的位置 0------(max-1)
|
|
|
|
vU16 max; /// 当前buf中数据长度,也就是需要发送的长度
|
|
|
|
vU32 over; /// 结束等待标志,over累加到某个值时,结束等待
|
|
|
|
vU8 ok; /// 发送完成标志
|
|
|
|
vU8 *buf;
|
|
|
|
vU8 buf3[D_UART_send_buf2_max];
|
|
|
|
U16 bufmax; ///buf的最大长度
|
|
|
|
}s;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
vU8 reg;
|
|
|
|
vU8 ok; //接收协议ok标志,串口初始化设置为0
|
|
|
|
vU8 idle; //空闲标志
|
|
|
|
vU8 overtime_t; //超时溢出的计数器
|
|
|
|
vU8 head; //接收标志头标志,串口初始化设置0
|
|
|
|
vU8 num; //协议实际长度
|
|
|
|
vU8 *buf; ////协议缓冲,由每个串口根据需要的缓冲区大小自己定义
|
|
|
|
U16 bufmax; ///buf的最大长度
|
|
|
|
}r;
|
|
|
|
|
|
|
|
void (*tp_handler)(U8 uartx);
|
|
|
|
U8 uartx;
|
|
|
|
|
|
|
|
}TS_uart_reg;
|
|
|
|
|
|
|
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
|
#define SERIAL_MAX_NUM 1
|
|
|
|
extern TS_uart_reg ts_uart[SERIAL_MAX_NUM];
|
|
|
|
|
|
|
|
extern void L0_uartN_init(U8 uartx);
|
|
|
|
extern void L0_uartN_set(U8 uartx,U8 x);
|
|
|
|
extern U8 L0_uartN_get(U8 uartx);
|
|
|
|
extern void L0_uartN_sendArray(U8 uartx,void *buf,U16 len);
|
|
|
|
extern void L0_uartN_uc(U8 uartx,U8 ww);
|
|
|
|
extern void L0_uartN_us(U8 uartx,vU16 ww);
|
|
|
|
extern void L0_uartN_ul(U8 uartx,vU32 ww);
|
|
|
|
extern void L0_uartN_0d0a(U8 uartx);
|
|
|
|
extern void L0_uartN_uchex(U8 uartx, U8 ww);
|
|
|
|
extern void L0_uartN_ushex(U8 uartx, U16 ww);
|
|
|
|
extern void L0_uartN_ulhex(U8 uartx, U32 ww);
|
|
|
|
extern void L0_uartN_sendstr(U8 uartx,U8 *buf);
|
|
|
|
extern void L1_uartN_uchexArray(U8 uartx,vU8 *buf,U16 n);
|
|
|
|
|
|
|
|
|
|
|
|
#endif //#ifndef _uartN_H
|
|
|
|
|