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.
403 lines
8.9 KiB
403 lines
8.9 KiB
//////////////////////////////////////////////////////////////////////////
|
|
/// COPYRIGHT NOTICE
|
|
/// Copyright (c) 2023 CCSENS
|
|
/// All rights reserved.
|
|
///
|
|
/// @file main.c
|
|
/// @brief main app
|
|
///
|
|
///(本文件实现的功能的详述)
|
|
///
|
|
/// @version 1.1 CCsens technology
|
|
/// @author CC
|
|
/// @date 20150102
|
|
///
|
|
///
|
|
/// 修订说明:最初版本
|
|
/// Modified by:
|
|
/// Modified date:
|
|
/// Version:
|
|
/// Descriptions:
|
|
// 20160413 CC-ACC-VH02
|
|
|
|
/*****************************************************************************
|
|
update by cc @20220305
|
|
|
|
|
|
|
|
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是
|
|
个需要平衡的事情.
|
|
|
|
clib/clib.c:
|
|
公用的函数 和硬件无关
|
|
放置串行模式(串口等其他通讯总线类的输出)输出的函数,
|
|
一些覆盖模式输出的(lcd等固屏输出的)的也可使用
|
|
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
app
|
|
asp
|
|
bsp
|
|
|
|
debug 选择哪个串口作为debug协议的通讯
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
tpc/: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式
|
|
公用的串口通讯定义
|
|
struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_
|
|
void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中
|
|
|
|
--------------------------------------------------------------------------------------------
|
|
msp/msp_uartx.c
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------------------
|
|
msp/msp_uart0.c 底层代码 和cpu相关 缓存发送也放在里面
|
|
L0_UART0_Init
|
|
UART0_IRQHandler
|
|
L0_Usend_uc------UserDef
|
|
-----------------------------------------------------------------------------------------
|
|
********************************************************************************/
|
|
|
|
#include "msp_uartN.h"
|
|
|
|
TS_Uart_Send_ ts_Usend[SERIAL_MAX_NUM]= {0};
|
|
TS_send_buf_ ts_Usendbuf;
|
|
|
|
TS_rec_road_ ts_Urec[SERIAL_MAX_NUM]= {0};
|
|
TS_rec_buf_ ts_Urecbuf;
|
|
code vU16 S_send_max[4]=
|
|
{
|
|
D_send1_max,
|
|
D_send2_max,
|
|
D_send3_max,
|
|
D_send4_max
|
|
};
|
|
|
|
void L0_uartN_set(U8 uartx,U8 x)
|
|
{
|
|
switch(uartx)
|
|
{
|
|
case 0:
|
|
SBUF = (x);
|
|
break;
|
|
case 1:
|
|
S2BUF = (x);///
|
|
break;
|
|
case 2:
|
|
S3BUF = (x);
|
|
break;
|
|
case 3:
|
|
S4BUF = (x);
|
|
break;
|
|
default:break;
|
|
}
|
|
}
|
|
/*
|
|
void L0_waitFree_uartN888(U8 uartx)
|
|
{
|
|
ts_Usend[uartx].over = 0;
|
|
while(ts_Usend[uartx].now != 0)
|
|
{
|
|
#if 10 //发送数据特别快时,某些情况下会导致数据发送出错
|
|
if(ts_Usend[uartx].over ++ > 600000)///这样写居然出错
|
|
|
|
{////ts_uart[uartx].p->ok = D_ready;
|
|
|
|
ts_Usend[uartx].now = 0;
|
|
break;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
*/
|
|
|
|
void L0_waitFree_uartN(U8 uartx)
|
|
{
|
|
ts_Usend[uartx].over = 0;
|
|
while(ts_Usend[uartx].now != 0)
|
|
{
|
|
#if 10 //发送数据特别快时,某些情况下会导致数据发送出错
|
|
/// if(ts_uart[uartx].p->over ++ > 600000)///这样写居然出错(vU32)
|
|
ts_Usend[uartx].over ++;
|
|
if(ts_Usend[uartx].over > 20000)////600 000--4s
|
|
{////ts_uart[uartx].p->ok = D_ready;
|
|
ts_Usend[uartx].max = ts_Usend[uartx].now;
|
|
ts_Usend[uartx].ok = D_ready;
|
|
// ts_Usend[uartx].over = 0;
|
|
// ts_Usend[uartx].now = 1;
|
|
ts_Usend[uartx].now = 0;
|
|
break;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#define D_485R 0
|
|
#define D_485S 1
|
|
|
|
|
|
void L0_uartN_485(U8 uartx,U8 x)
|
|
{
|
|
if (D_485R == x)
|
|
{
|
|
switch(uartx)
|
|
{
|
|
case 0:
|
|
D_UART1_485_RX();
|
|
break;
|
|
case 1:
|
|
break;
|
|
case 2:
|
|
break;
|
|
case 3:
|
|
//// D_UART4_485_RX();
|
|
break;
|
|
default:break;
|
|
}
|
|
}else
|
|
{
|
|
switch(uartx)
|
|
{
|
|
case 0:
|
|
D_UART1_485_TX();
|
|
break;
|
|
case 1:
|
|
break;
|
|
case 2:
|
|
break;
|
|
case 3:
|
|
//// D_UART4_485_TX();
|
|
break;
|
|
default:break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void L0_uartN_Array(U8 uartx,void *buf,U16 len)
|
|
{
|
|
u16 i;
|
|
|
|
L0_waitFree_uartN(uartx);
|
|
|
|
L0_uartN_485(uartx,D_485S);
|
|
ts_Usend[uartx].ok = D_ready;
|
|
ts_Usend[uartx].over = 0;
|
|
ts_Usend[uartx].now = 1;
|
|
if (len > ts_Usend[uartx].max_def)
|
|
{
|
|
len = ts_Usend[uartx].max_def - 1;
|
|
}
|
|
ts_Usend[uartx].max = len;
|
|
//将参数buf拷贝至内部buf
|
|
for(i = 0;i < len;i ++)
|
|
{
|
|
ts_Usend[uartx].sbuf[i] = ((U8*)buf)[i];
|
|
}
|
|
L0_uartN_set(uartx,ts_Usend[uartx].sbuf[0]);
|
|
}
|
|
|
|
|
|
void L0_uartN_Arraylong(U8 uartx,U8 *buf,U16 usStart,U16 usEnd)
|
|
{
|
|
//L0_uart0_sendbuf(str,strlen(str));
|
|
U16 t;
|
|
t = usEnd-usStart;
|
|
t ++;
|
|
L0_uartN_Array(uartx,&buf[usStart],t);
|
|
}
|
|
|
|
|
|
void L0_uartN_uc(U8 uartx,U8 ww)
|
|
{
|
|
L0_uartN_Array(uartx,&ww,1);
|
|
}
|
|
|
|
void L0_uartN_us(U8 uartx,vU16 ww)
|
|
{
|
|
U_U16 uStemp;
|
|
uStemp.word = ww;
|
|
ts_Usend[uartx].buf3[0] = uStemp.BYTE2.h;
|
|
ts_Usend[uartx].buf3[1] = uStemp.BYTE2.l;
|
|
L0_uartN_Array(uartx,ts_Usend[uartx].buf3,2);
|
|
}
|
|
|
|
void L0_uartN_ul(U8 uartx,vU32 ww)
|
|
{
|
|
U_U32 uStemp;
|
|
L0_waitFree_uartN(uartx);
|
|
uStemp.dWord = ww;
|
|
ts_Usend[uartx].buf3[0] = uStemp.BYTE4.byte0;
|
|
ts_Usend[uartx].buf3[1] = uStemp.BYTE4.byte1;
|
|
ts_Usend[uartx].buf3[2] = uStemp.BYTE4.byte2;
|
|
ts_Usend[uartx].buf3[3] = uStemp.BYTE4.byte3;
|
|
L0_uartN_Array(uartx,ts_Usend[uartx].buf3,4);
|
|
}
|
|
|
|
void L0_uartN_0d0a(U8 uartx)
|
|
{
|
|
L0_waitFree_uartN(uartx);
|
|
ts_Usend[uartx].buf3[0] = 0x0d;
|
|
ts_Usend[uartx].buf3[1] = 0x0a;
|
|
L0_uartN_Array(uartx,ts_Usend[uartx].buf3,2);
|
|
}
|
|
|
|
void L0_uartN_uchex(U8 uartx,U8 ww)
|
|
{
|
|
L0_waitFree_uartN(uartx);
|
|
ts_Usend[uartx].buf3[0] = cguHex2Char[D_uc_high(ww)][1];
|
|
ts_Usend[uartx].buf3[1] = cguHex2Char[D_uc_low (ww)][1];
|
|
L0_uartN_Array(uartx,ts_Usend[uartx].buf3,2);
|
|
}
|
|
|
|
void L0_uartN_ushex(U8 uartx,vU16 ww)
|
|
{
|
|
U_F16 k;
|
|
L0_waitFree_uartN(uartx);
|
|
k.us = ww;
|
|
ts_Usend[uartx].buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1];
|
|
ts_Usend[uartx].buf3[1] = cguHex2Char[D_uc_low (k.BYTE2.H)][1];
|
|
ts_Usend[uartx].buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1];
|
|
ts_Usend[uartx].buf3[3] = cguHex2Char[D_uc_low (k.BYTE2.L)][1];
|
|
L0_uartN_Array(uartx,ts_Usend[uartx].buf3,4);
|
|
}
|
|
|
|
void L0_uartN_ulhex(U8 uartx,U32 ww)
|
|
{
|
|
U_U32 k;
|
|
L0_waitFree_uartN(uartx);
|
|
k.dWord = ww;
|
|
ts_Usend[uartx].buf3[0] = cguHex2Char[D_uc_high(k.BYTE4.byte0)][1];
|
|
ts_Usend[uartx].buf3[1] = cguHex2Char[D_uc_low (k.BYTE4.byte0)][1];
|
|
ts_Usend[uartx].buf3[2] = cguHex2Char[D_uc_high(k.BYTE4.byte1)][1];
|
|
ts_Usend[uartx].buf3[3] = cguHex2Char[D_uc_low (k.BYTE4.byte1)][1];
|
|
ts_Usend[uartx].buf3[4] = cguHex2Char[D_uc_high(k.BYTE4.byte2)][1];
|
|
ts_Usend[uartx].buf3[5] = cguHex2Char[D_uc_low (k.BYTE4.byte2)][1];
|
|
ts_Usend[uartx].buf3[6] = cguHex2Char[D_uc_high(k.BYTE4.byte3)][1];
|
|
ts_Usend[uartx].buf3[7] = cguHex2Char[D_uc_low (k.BYTE4.byte3)][1];
|
|
L0_uartN_Array(uartx,ts_Usend[uartx].buf3,8);
|
|
}
|
|
|
|
void L0_uartN_str(U8 uartx,U8 *str)
|
|
{
|
|
L0_uartN_Array(uartx,str,Lc_strlen(str));
|
|
}
|
|
|
|
void L0_uartN_uchexArray(U8 uartx,vU8 *buf,U16 n)
|
|
{
|
|
int i;
|
|
for(i=0;i<n;i++)
|
|
{
|
|
L0_uartN_uchex(uartx,buf[i]);
|
|
L0_uartN_uc(uartx,' ');
|
|
}
|
|
/// L0_uartN_0d0a(uartx);
|
|
}
|
|
|
|
|
|
|
|
|
|
void L0_uartN_ushexArray(U8 uartx,vU16 *buf,U16 n)
|
|
{
|
|
int i;
|
|
for(i=0;i<n;i++)
|
|
{
|
|
L0_uartN_ushex(uartx,buf[i]);
|
|
L0_uartN_uc(uartx,' ');
|
|
}
|
|
/// L0_uartN_0d0a(uartx);
|
|
}
|
|
|
|
|
|
///////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//withoutbuf>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
|
|
void L0_uartN_sbuf(U8 uartx)/////cc 2023/04/23--4:23:19 修正bug 调用时放到ts_Usend[uartx].max 复制的前面
|
|
{
|
|
ts_Usend[uartx].max = 0;
|
|
ts_Usend[uartx].now = 0;
|
|
ts_Usend[uartx].ok = D_ready;
|
|
ts_Usend[uartx].max_def = S_send_max[uartx];
|
|
switch(uartx)
|
|
{
|
|
case 0:
|
|
ts_Usend[uartx].sbuf = ts_Usendbuf.s1;
|
|
break;
|
|
case 1:
|
|
ts_Usend[uartx].sbuf = ts_Usendbuf.s2;
|
|
break;
|
|
case 2:
|
|
ts_Usend[uartx].sbuf = ts_Usendbuf.s3;
|
|
break;
|
|
case 3:
|
|
ts_Usend[uartx].sbuf = ts_Usendbuf.s4;
|
|
break;
|
|
default:break;
|
|
}
|
|
}
|
|
|
|
////使用内置的usend buf的发送 cc 2023/04/23--4:25:8 调用的时候不可使用本通道的缓存
|
|
void L0_uartN_Array_withoutbuf(U8 uartx,U16 len)
|
|
{
|
|
/// u16 i;
|
|
L0_waitFree_uartN(uartx);
|
|
|
|
L0_uartN_485(uartx,D_485S);
|
|
L0_uartN_sbuf(uartx);
|
|
|
|
if (len > ts_Usend[uartx].max_def)
|
|
{
|
|
len = ts_Usend[uartx].max_def - 1;
|
|
}
|
|
ts_Usend[uartx].max = len;
|
|
L0_uartN_set(uartx,ts_Usend[uartx].sbuf[0]);
|
|
}
|
|
|
|
///cc 2023/04/23--4:25:8 调用的时候不可使用本通道的缓存
|
|
void L0_uartN_Arrayhex_withoutbuf(U8 uartx,vU8 *buf,U16 len)
|
|
{
|
|
vU16 i;vU16 t;
|
|
|
|
L0_waitFree_uartN(uartx);
|
|
if (len > (ts_Usend[uartx].max_def/3))
|
|
{
|
|
len = ts_Usend[uartx].max_def/3 - 1;
|
|
}
|
|
for(i = 0;i < len;i ++)
|
|
{
|
|
|
|
t = i * 3;
|
|
ts_Usend[uartx].sbuf[t] = cguHex2Char[D_uc_high(buf[i])][1];/// 34 '3'--33
|
|
t ++;
|
|
ts_Usend[uartx].sbuf[t] = cguHex2Char[D_uc_low (buf[i])][1];/// 34 '3'--33
|
|
t ++;
|
|
ts_Usend[uartx].sbuf[t] = ' ';
|
|
t ++;
|
|
|
|
}
|
|
// len 2 11x 22x \0
|
|
ts_Usend[uartx].sbuf[t] = ' ';
|
|
t++;
|
|
ts_Usend[uartx].sbuf[t] = 0x00;
|
|
L0_uartN_Array_withoutbuf(uartx,t-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|