|
|
|
/*****************************************************************************
|
|
|
|
* debug_drv.c: debug app
|
|
|
|
*
|
|
|
|
* Copyright(C) 2013, cc
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* History
|
|
|
|
* 2013.05.24 ver 1.00 Prelimnary version, first Release
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
|
|
if(ts_s2b_debug.idle)
|
|
|
|
{
|
|
|
|
ts_s2b_debug.idle = 0;
|
|
|
|
printf("\r\n O");
|
|
|
|
if(ts_s2b_debug.len > 0)
|
|
|
|
{
|
|
|
|
//// L1_uartD_sendArrayhex((U8 *)&ts_s2b_debug.t, 5);
|
|
|
|
/// xxxx///提取协议
|
|
|
|
/// if(debgu) ts_s2b_debug.ok =1;
|
|
|
|
|
|
|
|
printf("\r\n len = %d",(int)ts_s2b_debug.len);
|
|
|
|
ts_s2b_debug.len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "debug_drv.h"
|
|
|
|
#include "msp_iicMx.h"
|
|
|
|
#include "c_type51.h"
|
|
|
|
#include "tpc_road.h"
|
|
|
|
///#include "bsp_lora_jx.h"
|
|
|
|
///#include "bsp_lora.h"
|
|
|
|
|
|
|
|
#include "msp_eeprom.h"
|
|
|
|
|
|
|
|
TS_P_debug *pd = NULL;
|
|
|
|
TS_P_rs485 *pd485 = NULL;
|
|
|
|
|
|
|
|
u8 L3_tpc_D2uart(u8 cmd,u8 num)
|
|
|
|
{
|
|
|
|
if(cmd == 0x0D)
|
|
|
|
{////D2。。。。 透传给串口2的数据
|
|
|
|
|
|
|
|
if(2 == num)////发送D2 11 22 33的指令后 解析完D2,给串口2 发送11 22 33
|
|
|
|
{
|
|
|
|
printf1("\r\n - >2: %D ",(int)ts_Urec[D_UART1].num);
|
|
|
|
/// D_lora_wakeup();
|
|
|
|
/// L1_uart2_Array(&ts_Urec[D_UART1].sp[1], ts_Urec[D_UART1].num-1);
|
|
|
|
L0_uartN_Arrayhex_withoutbuf(D_UART1,&ts_Urec[D_UART1].sp[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else if(3 == num)
|
|
|
|
{ printfs("\r\n->3:");
|
|
|
|
////L1_uart3_Array(&ts_Urec[D_UART1].sp[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else if(4 == num)
|
|
|
|
{ printfs("\r\n->4:");
|
|
|
|
////L1_uart4_Array(&ts_Urec[D_UART1].sp[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
printfs("\r\nmust in(D2,D3,D4):");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////通过debug串口 透传协议
|
|
|
|
#if 0
|
|
|
|
u8 L3_tpc_hex(void)
|
|
|
|
{
|
|
|
|
u8 cmd=0, num=0;
|
|
|
|
cmd = D_uc_high(ts_Urec[D_UART1].sp[0]);////为485 调整 第一个
|
|
|
|
num = D_uc_low(ts_Urec[D_UART1].sp[0]);
|
|
|
|
printf(" 1->cmd=%X num=%X len = %d ",(int)cmd,(int)num, (int)ts_Urec[D_UART1].num);
|
|
|
|
|
|
|
|
////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为Fx
|
|
|
|
if(0x0F == cmd)///fx r1 r2 r3 r4 ocr
|
|
|
|
{
|
|
|
|
///TS_P_debug
|
|
|
|
///printfs("\r\n cmd = ");
|
|
|
|
////pd = (TS_P_debug*)ts_Urec[D_UART1].sp;
|
|
|
|
L0_uartN_Arrayhex_withoutbuf(D_UART1,&ts_Urec[D_UART1].sp[0], ts_Urec[D_UART1].num);////(U8 *)&pd,错误的表达方式 pd就是地址
|
|
|
|
if(num == 0x0e)
|
|
|
|
{
|
|
|
|
/// L3_tpc_FEdebug();return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(L3_tpc_D2uart(cmd,num))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printfs("\r\n cmd error!!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
u8 L3_tpc_hex(void)
|
|
|
|
{
|
|
|
|
u8 filter = 0, slaveId = 0, cmd = 0;
|
|
|
|
filter = ts_Urec[D_UART1].sp[0];
|
|
|
|
slaveId = ts_Urec[D_UART1].sp[1];
|
|
|
|
cmd = ts_Urec[D_UART1].sp[2];
|
|
|
|
//printf(" 1->filter=%X slaveId=%X cmd=%X len = %d ",(int)filter,(int)slaveId, (int)cmd, (int)ts_Urec[D_UART1].num);
|
|
|
|
|
|
|
|
////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为AA
|
|
|
|
///AA 02 10 00 02 A3 B4 6C
|
|
|
|
if(0xAA == filter)
|
|
|
|
{
|
|
|
|
//L0_uartN_Arrayhex_withoutbuf(D_UART1,&ts_Urec[D_UART1].sp[0], ts_Urec[D_UART1].num);
|
|
|
|
if(0x02 == slaveId)
|
|
|
|
{
|
|
|
|
// if(ocr)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// printfs("\r\n cmd error!!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
////启动透传指令 开关打开 可以模拟当前串口发送
|
|
|
|
vtype L2_debug_ONcomand(void)
|
|
|
|
{
|
|
|
|
if(1 == ts_Urec[D_UART1].debugok)
|
|
|
|
{
|
|
|
|
ts_Urec[D_UART1].debugok = 0;////解析协议
|
|
|
|
/// printf("\r\nw ts_Urec[D_UART1].max = %d num = %d",(int)ts_Urec[D_UART1].rmax,(int)ts_Urec[D_UART1].num);
|
|
|
|
// printf1("\r\ndebugok %2x",(int)ts_Urec[D_UART1].debugok);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(1 == ts_Urec[D_UART1].ok)
|
|
|
|
{
|
|
|
|
ts_Urec[D_UART1].ok = 0;////解析协议
|
|
|
|
|
|
|
|
//// printf1("\r\nD_UART1 ok %d ",(int) ts_Urec[D_UART1].num);
|
|
|
|
// D_LED1_REV();
|
|
|
|
|
|
|
|
pd485 = (TS_P_rs485 *)ts_Urecbuf.r1;
|
|
|
|
|
|
|
|
/// L0_uartN_Arrayhex_withoutbuf(D_UART1,ts_Urecbuf.r1, ts_Urec[D_UART1].num);
|
|
|
|
/// 串口1的协议分两类 1类是 Fx开头的针对外设x的标准debug协议;例如FD开头是系统debug Fc是iic调试设备
|
|
|
|
/// 一类是Dx开头的对串口x透传协议 ////D2。。。。 透传给串口2的数据
|
|
|
|
return L3_tpc_hex();///
|
|
|
|
/// return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********
|
|
|
|
if(1 == ts_Urec[D_UART2].ok)
|
|
|
|
{ ts_Urec[D_UART2].ok = 0;////收到一帧数据
|
|
|
|
printf("\r\nUART2:rec: ");
|
|
|
|
///sprintf(," %s ",ts_Urecbuf.r2);
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
|
|
L1_uartD_Arrayhex(ts_Urecbuf.r2, ts_Urec[D_UART2].num);
|
|
|
|
Lc_buf_copy_uc(ts_Urecbuf.r5,ts_Urecbuf.r2,ts_Urec[D_UART2].num);
|
|
|
|
return L3_tpc_lora(ts_Urecbuf.r5);///
|
|
|
|
}
|
|
|
|
*********/
|
|
|
|
|
|
|
|
#ifdef D_USE_UART3
|
|
|
|
if(1 == ts_Urec[D_UART3].ok)
|
|
|
|
{ ts_Urec[D_UART3].ok = 0;////解析协议
|
|
|
|
printfs("\r\nD_UART3 ok ");
|
|
|
|
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
|
|
L1_uartD_Arrayhex(ts_Urecbuf.r3, ts_Urec[D_UART3].num);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#warning "CC: without uart3"
|
|
|
|
|
|
|
|
#endif///D_USE_UART33
|
|
|
|
|
|
|
|
#ifdef D_USE_UART4
|
|
|
|
if(1 == ts_Urec[D_UART4].ok)
|
|
|
|
{ ts_Urec[D_UART4].ok = 0;////解析协议
|
|
|
|
printfs("\r\nD_UART3 ok ");
|
|
|
|
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
|
|
L1_uartD_Arrayhex(ts_Urecbuf.r4, ts_Urec[D_UART4].num);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#warning "CC: without uart4"
|
|
|
|
#endif///D_USE_UART4
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void L3_test_ONdebug(u8 filter)//// ON listen function
|
|
|
|
{
|
|
|
|
if(filter == pd->filter)
|
|
|
|
{///filter num d1 d2 d3 ....dn
|
|
|
|
//// FD 08 11 22 33 44 55 66 77 88
|
|
|
|
printfs("\r\nDdebug:FD R1 R2 R3 R4 ocr FD->");
|
|
|
|
|
|
|
|
switch (pd->ocr)
|
|
|
|
{ case 0x11:////Fd 11 22 33 44 55 66 11
|
|
|
|
|
|
|
|
if(pd->R6 == 0x66)
|
|
|
|
{///gb2312
|
|
|
|
printf(" \r\n \r\n准备烧写,确认主机版本+22M晶振+监测波特率921600 后使用download \r\n ");
|
|
|
|
printf(" \r\n \r\n 3秒内点击 下载按钮 \r\n ");
|
|
|
|
|
|
|
|
Lc_delay_ms(1000);
|
|
|
|
printf(" \r\n3\r\n ");
|
|
|
|
Lc_delay_ms(1000);
|
|
|
|
printf(" \r\n2\r\n ");
|
|
|
|
Lc_delay_ms(1000);
|
|
|
|
printf(" \r\n1\r\n ");
|
|
|
|
L0_IAP_enter_ISP();///BITN_1(IAP_CONTR, BITN6|BITN5);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
printf(" \r\n烧写命令错误\r\n ");///gb2312
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x22:
|
|
|
|
///FD 13 01 33 44 50 /// P13 =1
|
|
|
|
///FX R1 R2 R3 R4 ocr
|
|
|
|
///FD R1 R2 R3 R4 ocr
|
|
|
|
///FD ch adr reg 12
|
|
|
|
///FD 01 AE 09 44 22 读取 iic第一通道的01 | 地址AE的设备 | 寄存器09
|
|
|
|
pd->ocr = L2_IICMx_Read1Reg1D(pd->R1,pd->R2,pd->R3);
|
|
|
|
printf4("22 ch:(%2X)-%2X S %2X=%2X\r\n",(int)pd->R1,(int)pd->R2,(int)pd->R3,(int)pd->ocr);
|
|
|
|
break;
|
|
|
|
case 0x23:
|
|
|
|
///FD 13 01 33 50 /// P13 =1
|
|
|
|
///FX R1 R2 R3 R4 ocr
|
|
|
|
///FX R1 R2 R3 R4 ocr
|
|
|
|
///FD ch adr reg dat 12
|
|
|
|
///FD 01 AE 09 04 23 iic第一通道的01 | 地址AE的设备 | 寄存器09 写入 04
|
|
|
|
printf4("23 ch:(%2X)-%2X W %2X=%2X\r\n",(int)pd->R1,(int)pd->R2,(int)pd->R3,(int)pd->R4);
|
|
|
|
L2_IICMx_WriteCmd(pd->R1,pd->R2,pd->R3,pd->R4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
printfs(" pp error\r\n ");
|
|
|
|
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
printfs("333");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///#define D_keil_sim
|
|
|
|
#ifdef D_keil_sim
|
|
|
|
void UartInit(void) //9600bps@11.0592MHz
|
|
|
|
{
|
|
|
|
SCON = 0x50; //8位数�?可变波特�?
|
|
|
|
AUXR |= 0x01; //串口1选择定时�?为波特率发生�?
|
|
|
|
AUXR |= 0x04; //定时�?时钟为Fosc,�?T
|
|
|
|
T2L = 0xE0; //设定定时初� �?
|
|
|
|
T2H = 0xFE; //设定定时初�?
|
|
|
|
AUXR |= 0x10; //启动定时�?
|
|
|
|
}
|
|
|
|
|
|
|
|
void L3_debug_drv_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
Ts_debug.uxrev = D_ts_uartX_rev;
|
|
|
|
|
|
|
|
Ts_debug.td = (TS_P_debug *)Ts_debug.uxrev->buf;
|
|
|
|
Ts_debug.ok = &Ts_debug.uxrev->debugok;
|
|
|
|
UartInit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char putchar(char ch)
|
|
|
|
{
|
|
|
|
SBUF = ch;
|
|
|
|
while(TI == 0);
|
|
|
|
TI = 0;
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#warning "CC: putchar ok"
|
|
|
|
|
|
|
|
void L3_debug_drv_init(void)
|
|
|
|
{
|
|
|
|
/// D_s2b_road1_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
char putchar(char ch)
|
|
|
|
{
|
|
|
|
/* Place your implementation of fputc here */
|
|
|
|
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
|
|
|
|
/// HAL_UART_Transmit_IT(&huart4, (uint8_t *)&ch, 1);
|
|
|
|
L1_uartD_uc(ch);
|
|
|
|
return ch;
|
|
|
|
///SBUF= ch;
|
|
|
|
/// while(t)
|
|
|
|
/// while(!TI);
|
|
|
|
// TI = 0;
|
|
|
|
/// return (SBUF = ch);
|
|
|
|
}
|
|
|
|
#endif ///#ifdef D_keil_sim
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
void L3_debug_drv_init(void)
|
|
|
|
{
|
|
|
|
L0pf_send_uc = L0_uart0_uc;
|
|
|
|
Lc_print("\r\n debug shell init:\t");
|
|
|
|
/// io ���õı�д��
|
|
|
|
|
|
|
|
Lc_print("Mode:");
|
|
|
|
#ifdef D_debug_time
|
|
|
|
Lc_print(" debug");
|
|
|
|
#else
|
|
|
|
//D_debug_time_using
|
|
|
|
Lc_print(" normal");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef D_debug_sim
|
|
|
|
|
|
|
|
fff
|
|
|
|
void L3_debug_cycle(void)
|
|
|
|
{
|
|
|
|
INTERRUPT_UART();
|
|
|
|
TIMER0_IRQHandler();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
#endif
|
|
|
|
void L3_test_debug(u8 filter)
|
|
|
|
{
|
|
|
|
if(filter == Ts_debug.td->filter)
|
|
|
|
{///filter num d1 d2 d3 ....dn
|
|
|
|
//// FD 08 11 22 33 44 55 66 77 88
|
|
|
|
L1_uartD_sendArrayhex(Ts_debug.td,Ts_debug.td->R1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void L3_iicx_debug(u8 filter)
|
|
|
|
{
|
|
|
|
if(filter == Ts_debug.td->filter)
|
|
|
|
{
|
|
|
|
if(0x10 == Ts_debug.td->ocr)///read reg1 num 读取reg1地址中的num个数�?
|
|
|
|
{
|
|
|
|
|
|
|
|
//NUM: 0 1 2 3 4
|
|
|
|
// Fx R1 R2 R3 ocr
|
|
|
|
// sla reg1 num
|
|
|
|
/// f1 32 15 06 10
|
|
|
|
|
|
|
|
//NUM: 0 1 2 3 4
|
|
|
|
// Fx R1 R2 R3 ocr
|
|
|
|
// sla reg1 num
|
|
|
|
/// f1 32 0x28 06 10
|
|
|
|
/// f1 32 0x28 06 10
|
|
|
|
/// 28
|
|
|
|
/// 0010 1000 28
|
|
|
|
/// 1010 1000 a8
|
|
|
|
L2_IICM1_ReadReg(Ts_debug.td->R1,Ts_debug.td->R2,Ts_debug.d,Ts_debug.td->R3);
|
|
|
|
///printf("\r\n 0x%2x 0x%2x\r\n",(int)Ts_debug.d[0],(int)Ts_debug.d[1]);
|
|
|
|
L1_uartD_sendArrayhex(Ts_debug.d,Ts_debug.td->R3);
|
|
|
|
/// printf("\r\n 0x%2x\r\n",(int)Ts_debug.td->ocr);
|
|
|
|
}
|
|
|
|
else if(0x11 == Ts_debug.td->ocr)
|
|
|
|
{
|
|
|
|
L2_IICM1_ReadReg(Ts_debug.td->R1,Ts_debug.td->R2,Ts_debug.d,Ts_debug.td->R3);
|
|
|
|
//printf("\r\n 0x%2x 0x%2x\r\n",(int)Ts_debug.d[0],(int)Ts_debug.d[1]);
|
|
|
|
//L1_uartD_sendArrayhex(Ts_debug.d,Ts_debug.td->R3);
|
|
|
|
printf("\r\n 0x%2x 0x%2x\r\n",(int)Ts_debug.d[0],(int)Ts_debug.d[1]);
|
|
|
|
}
|
|
|
|
else if(0x12 == Ts_debug.td->ocr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** End Of File
|
|
|
|
******************************************************************************/
|