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.
378 lines
9.4 KiB
378 lines
9.4 KiB
/*****************************************************************************
|
|
* 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_iicM1.h"
|
|
#include "c_type51.h"
|
|
///#include "msp_uart2.h"
|
|
|
|
#include "tpc_road.h"
|
|
TS_P_debug *pd=NULL;
|
|
|
|
////启动透传指令 开关打开 可以模拟当前串口发送
|
|
vtype L2_debug_comand(void)
|
|
{
|
|
u8 cmd=0,num=0;
|
|
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);
|
|
printf("\r\ndebugok",(int)(int)ts_Urec[D_UART1].debugok);
|
|
|
|
}
|
|
if(1 == ts_Urec[D_UART1].ok)
|
|
{ ts_Urec[D_UART1].ok = 0;////解析协议
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r1, ts_Urec[D_UART1].num);L1_uartD_0d0a();
|
|
///---------串口1的协议分两类 1类是 Fx开头的针对外设x的标准debug协议;例如FD开头是系统debug Fc是iic调试设备
|
|
////一类是Dx开头的对串口x透传协议 ////D2。。。。 透传给串口2的数据
|
|
cmd = D_uc_high(ts_Urecbuf.r1[0]);
|
|
num = D_uc_low(ts_Urecbuf.r1[0]);
|
|
printf(" 0->%X %X ",(int)cmd,(int)num );
|
|
if(cmd == 0x0D)
|
|
{////D2。。。。 透传给串口2的数据
|
|
L1_uartD_sendArrayhex(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
|
|
if(2 == num)
|
|
{ printf(" 2-> ");
|
|
L1_uart2_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
}else if(3 == num)
|
|
{ printf(" 3-> ");
|
|
L1_uart3_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else if(4 == num)
|
|
{ printf(" 4-> ");
|
|
L1_uart4_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else
|
|
{
|
|
}
|
|
return 1;
|
|
|
|
}
|
|
////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为Fx
|
|
if(0x0F == cmd)
|
|
{
|
|
///TS_P_debug
|
|
pd = (TS_P_debug*)ts_Urecbuf.r1;
|
|
L1_uartD_sendArrayhex((U8 *)pd, 5);////(U8 *)&pd,错误的表达方式 pd就是地址
|
|
return 1;
|
|
}
|
|
printf("\r\n ok ");
|
|
}
|
|
|
|
if(1 == ts_Urec[D_UART2].ok)
|
|
{ ts_Urec[D_UART2].ok = 0;////收到一帧数据
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r2, ts_Urec[D_UART2].num);
|
|
}
|
|
if(1 == ts_Urec[D_UART3].ok)
|
|
{ ts_Urec[D_UART3].ok = 0;////解析协议
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r3, ts_Urec[D_UART3].num);
|
|
}
|
|
if(1 == ts_Urec[D_UART4].ok)
|
|
{ ts_Urec[D_UART4].ok = 0;////解析协议
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r4, ts_Urec[D_UART4].num);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
////启动透传指令 开关打开 可以模拟当前串口发送
|
|
vtype L2_debug_comand333(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);
|
|
printf("\r\ndebugok",(int)(int)ts_Urec[D_UART1].debugok);
|
|
|
|
}
|
|
if(1 == ts_Urec[D_UART1].ok)
|
|
{ ts_Urec[D_UART1].ok = 0;////解析协议
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r1, ts_Urec[D_UART1].num);L1_uartD_0d0a();
|
|
///---------串口1的协议分两类 1类是 Fx开头的针对外设x的标准debug协议;例如FD开头是系统debug Fc是iic调试设备
|
|
////一类是Dx开头的对串口x透传协议 ////D2。。。。 透传给串口2的数据
|
|
if((ts_Urecbuf.r1[0]&0xF0) == 0xD0)
|
|
{////D2。。。。 透传给串口2的数据
|
|
printf("\r\n Dn=%x :",(int)(ts_Urecbuf.r1[0]&0x0F));
|
|
L1_uartD_sendArrayhex(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
|
|
if(ts_Urecbuf.r1[0]&0x0f == 0x02)
|
|
{ printf(" 2-> ");
|
|
L1_uart2_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
}else if(ts_Urecbuf.r1[0]&0x0f == 0x03)
|
|
{ printf(" 3-> ");
|
|
L1_uart3_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else if(ts_Urecbuf.r1[0]&0x0f == 0x04)
|
|
{ printf(" 4-> ");
|
|
L1_uart4_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1);
|
|
|
|
}else
|
|
{printf(" 4->%x %x ",(int)(ts_Urecbuf.r1[0]&0xF0), (int)(ts_Urecbuf.r1[0]&0x0f) );
|
|
}
|
|
return 1;
|
|
|
|
}
|
|
////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为Fx
|
|
if(ts_Urecbuf.r1[0]&0xf0 == 0xf0)
|
|
{
|
|
///TS_P_debug
|
|
pd = (TS_P_debug*)ts_Urecbuf.r1;
|
|
L1_uartD_sendArrayhex((U8 *)pd, 5);////(U8 *)&pd,错误的表达方式 pd就是地址
|
|
return 1;
|
|
}
|
|
printf("\r\n ok ");
|
|
}
|
|
|
|
if(1 == ts_Urec[D_UART2].ok)
|
|
{ ts_Urec[D_UART2].ok = 0;////收到一帧数据
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r2, ts_Urec[D_UART2].num);
|
|
}
|
|
if(1 == ts_Urec[D_UART3].ok)
|
|
{ ts_Urec[D_UART3].ok = 0;////解析协议
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r3, ts_Urec[D_UART3].num);
|
|
}
|
|
if(1 == ts_Urec[D_UART4].ok)
|
|
{ ts_Urec[D_UART4].ok = 0;////解析协议
|
|
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_sendArrayhex(ts_Urecbuf.r4, ts_Urec[D_UART4].num);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void L3_test_debug(u8 filter)
|
|
{
|
|
if(filter == pd->filter)
|
|
{///filter num d1 d2 d3 ....dn
|
|
//// FD 08 11 22 33 44 55 66 77 88
|
|
printf("\r\n FD ok");
|
|
|
|
switch (pd->ocr)
|
|
{
|
|
case 0x11:
|
|
|
|
printf("11");
|
|
//// D_lora_wakeup(); L0_uart2_sendArray(test, 13);
|
|
printf(" lora send ");
|
|
/// L1_uartD_sendArrayhex(test, 13);
|
|
//1/ 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x12:
|
|
printf("12");
|
|
/// D_lora_wakeup(); L0_uart2_sendArray(test2, 7);
|
|
printf(" lora send2 ");
|
|
/// L1_uartD_sendArrayhex(test2, 7);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
default:
|
|
printf(" pp error\r\n ");
|
|
|
|
break;
|
|
};
|
|
|
|
printf("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
|
|
|
|
|
|
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_senduc(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
|
|
******************************************************************************/
|
|
|