平车主控板(运维板)
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.
 
 
 
 
 

227 lines
7.3 KiB

//////////////////////////////////////////////////////////////////////////
/// 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:
// 20160413 CC-ACC-VH02
// 连接至 J22 RXD0 TXD0
//P5_DIR &= ~BITN1; //p5.1输出TXD
//P5_DIR |= BITN0; //p5.0输入RXD
//P5_SEL0 &= ~(BITN0 +BITN1); //设置P5.0 P5.1为UART0 RXD TXD
//P5_SEL1 |= BITN0 +BITN1;
/*****************************************************************************
update by cc @201700110
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是
个需要平衡的事情.
clib/clib.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
-----------------------------------------------------------------------------------------
********************************************************************************/
#include "uart3.h"
#include <stdio.h>
//struct _s_protocol_ s_at0;
struct _s_uart3_send_buf_ s_uart3_send_shop;
struct _s_uart3_send_buf_ s_uart3_send_depot;
#define FOSC 11059200UL
#define BRT (256 - FOSC / 115200 / 32) ///定时器1 模式2 做串口波特率
void L0_uart3_init(void) //57600
{
#if 0 //57600
S3CON = 0x10; //8位数据,可变波特率
S3CON |= 0x40; //串口3选择定时器3为波特率发生器
T4T3M |= 0x02; //定时器3时钟为Fosc,即1T
T3L = 0xD0; //设定定时初值
T3H = 0xFF; //设定定时初值
T4T3M |= 0x08; //启动定时器3
#else //115200
S3CON = 0x10; //8位数据,可变波特率
S3CON |= 0x40; //串口3选择定时器3为波特率发生器
T4T3M |= 0x02; //定时器3时钟为Fosc,即1T
T3L = 0xE8; //设定定时初值
T3H = 0xFF; //设定定时初值
T4T3M |= 0x08; //启动定时器3
#endif
D_uart3_ES_INT_OPEN(); //打开串口中断
}
void L1_uart3_buf_init(void)
{
s_uart3_send_depot.p = s_uart3_send_depot.buf;
s_uart3_send_shop.now = 0;
L0_uart3_init();
}
void L0_uart3_uc(U8 ww)
{
s_uart3_send_depot.max = 1;
s_uart3_send_depot.buf[0] = ww;
s_uart3_send_depot.p = s_uart3_send_depot.buf;
L0_uart3_sendbuf();
}
void L0_uart3_us(U16 ww)
{
L0_uart3_uc(ww >> 8 & 0xFF);
L0_uart3_uc(ww >> 0 & 0xFF);
}
void L0_uart3_0d0a(void)
{
s_uart3_send_depot.max = 2;
s_uart3_send_depot.buf[0] = 0x0d;
s_uart3_send_depot.buf[1] = 0x0a;
s_uart3_send_depot.p = s_uart3_send_depot.buf;
L0_uart3_sendbuf();
}
// L0_uart3_uc(cguHex2Char[D_uc_low(s->sec)][0]);
void L0_uart3_uchex(U8 ww)
{
s_uart3_send_depot.max = 2;
s_uart3_send_depot.buf[0] = cguHex2Char[D_uc_low(ww)][1];
s_uart3_send_depot.buf[1] = cguHex2Char[D_uc_high(ww)][1];
s_uart3_send_depot.p = s_uart3_send_depot.buf;
L0_uart3_sendbuf();
}
void L0_uart3_ulhex(vU32 ww)
{
U_U32 ultemp;
ultemp.dWord = ww;
L0_uart3_uchex(ultemp.BYTE4.byte0);
L0_uart3_uchex(ultemp.BYTE4.byte1);
L0_uart3_uchex(ultemp.BYTE4.byte2);
L0_uart3_uchex(ultemp.BYTE4.byte3);
}
void L0_uart3_sendstr(U8 *str)
{
//L0_uart3_sendbuf(str,strlen(str));
s_uart3_send_depot.max = strlen(str);
s_uart3_send_depot.p = str;
L0_uart3_sendbuf();
}
void L0_uart3_sendArray(U8 *buf,U8 len)
{
//L0_uart3_sendbuf(str,strlen(str));
s_uart3_send_depot.max = len;
s_uart3_send_depot.p = buf;
L0_uart3_sendbuf();
}
// 发送buf数组 中的0----(num-1)
void L0_uart3_sendbuf(void)
{
register unsigned char n = 0;
if(s_uart3_send_depot.max>= D_send_buf_max)
{
s_uart3_send_depot.max = D_send_buf_max - 1;
}
D_uart3_ES_INT_CLOSE();
if(0 == s_uart3_send_shop.now)
{/// 上次的已经发送完毕了,或者第一次开始
/// (s_uart3_send_shop.now == s_uart3_send_shop.max = 0 buf中为空)
for(n = 0;n < s_uart3_send_depot.max; n++)
{
s_uart3_send_shop.buf[n] = s_uart3_send_depot.p[n];
}
s_uart3_send_shop.max = s_uart3_send_depot.max;
L0_uart3_IntTIClear();
s_uart3_send_shop.now = 1;
///D_uart3_ES_INT(1);
L0_uart3_set(s_uart3_send_shop.buf[0]);
}else
{// 需要插入
/// [0]--?--[pool.now]--?--[pool.max-1].......................................
/// [0]--?--[pool.now]--?--[pool.max]+[bath.0]--?---[bath.max-1].............
for(n = 0;n < s_uart3_send_depot.max; n++)
{
s_uart3_send_shop.buf[s_uart3_send_shop.max] = s_uart3_send_depot.p[n];
s_uart3_send_shop.max ++;
if(s_uart3_send_shop.max >= D_send_buf_max)
{
s_uart3_send_shop.max = D_send_buf_max - 1;
}
}
}
D_uart3_ES_INT_OPEN();
}
/*************************************************
UART 中断
*************************************************/
#define D_SERVE_UART3 interrupt 17
void INTERRUPT_UART3(void) D_SERVE_UART3// using 3
{
D_uart3_ES_INT_CLOSE();
//------------------------------------------------
if(L0_uart3_IntRI()) //如果是U0接收中断
{L0_uart3_IntRIClear(); //清除接收中断标志
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>用户程序 添加协议>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/// output: 对应的结构体变量中携带 缓存buf和协议ok的标志
//s_uart3_rec.reg = L0_uart3_get();
//s_uart3_rec.ok = 1;
Lp0_uart3_fun(L0_uart3_get());
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//------------------------------------------------------------
else
{
if(L0_uart3_IntTI()) //如果是U0发送中断
{L0_uart3_IntTIClear(); //清除发送中断标志
if(s_uart3_send_shop.max != s_uart3_send_shop.now)
{
L0_uart3_set(s_uart3_send_shop.buf[s_uart3_send_shop.now]);
s_uart3_send_shop.now ++;
}else
{
s_uart3_send_shop.max = 0;
s_uart3_send_shop.now = 0;//可以发送下一个数据
}
}
}
D_uart3_ES_INT_OPEN();
}