📄 ssp_debug.c
字号:
#include "syscfg.h"#ifdef __cplusplusextern "C"{#endif #if( AOS_INCLUDE_SSP_KER_DEBUG == TRUE )#undef __INC_ASOCK_H__#include "aos.h"#include "ssp_msg.h"#include "ssp_debug.h"#include "ssp_cputick.h"#include "ssp_spy.h"#include "cfm/cfm_pub.h"#include "cli/cli_pub.h"#if(CONFIG_BOARD_EIA == TRUE && CONFIG_OS_VXWORKS == TRUE)BOOL_T phy_console_is_to_u1000( );#endif#define NULL_SOCKET -1struct msg_blk_que x_print_que;U32 print_task_id = U32_BUTT;U32 x_sock_rcv_task_id = U32_BUTT;U32 trans_processor_id = U32_BUTT;U32 debuger_ip_addr = U32_BUTT;U16 debuger_port = U16_BUTT;U32 debuger_connet_status = DEBUG_CONNECTED_NOT;U32 is_debug_init = FALSE;S32 x_send_sock;U32 g_dbgPrint2Log;U32 m_debug_init(){ U32 result = AOS_SUCC; trans_processor_id = U32_BUTT; debuger_ip_addr = U32_BUTT; debuger_port = U16_BUTT; debuger_connet_status = DEBUG_CONNECTED_NOT; x_sock_rcv_task_id = U32_BUTT; x_send_sock = NULL_SOCKET; msg_lock_que_init( &x_print_que );#if( CONFIG_BOARD_EIA == TRUE ) g_dbgPrint2Log = 0;#else g_dbgPrint2Log = 1;#endif result = aos_task_create("xprint", 10*1024, TASK_PRIO_LOWEST, AOS_TASK_NOPREEMPT, (VOID(*)(VOID *))print_task, (VOID*)&x_print_que, &print_task_id); if( AOS_SUCC != result ) { return result; } is_debug_init = TRUE; return AOS_SUCC;}U32 debug_init_proc( START_ORDER_E order ){ U32 result; switch( order ) { case STARTUP_BEFORE_INITIAL: break; case STARTUP_INITIAL: break; case STARTUP_LOAD_DATA: break; case STARTUP_GO: #if 0 result = aos_task_create("xsockt", 10*1024, TASK_PRIO_NORMAL, AOS_TASK_NOPREEMPT, (VOID(*)(VOID *))x_sock_rcv_task, (VOID*)NULL, &x_sock_rcv_task_id); if( AOS_SUCC != result ) { return result; } #endif aos_timer_start( NULL, MPE_DEBUG, DBG_REPORT_TIMER_LEN, DBG_REPORT_TIMER, 0, AOS_TIMER_NO_LOOP ); break; default: AOS_ASSERT(0); break; } return AOS_SUCC;}U32 aos_printf( MPE mpe, const S8*format, ...){ VA_LIST argptr; struct dbg_frame_s *dbg_frame_p; S32 offset; struct msg_blk *mb; SYS_TIME_S now; U32 local_proc_id; static U8 serialno = (U8)-1;#define print_buf (dbg_frame_p->u.printmsg.str) if( FALSE == is_debug_init ) { return AOS_FAIL; } if( AOS_SUCC != ssp_mpe_print_verify( mpe ) ) { return AOS_FAIL; } ++serialno; if( x_print_que.qlen > CONFIG_PRINT_MSG_NUM ) { return AOS_FAIL; } dbg_frame_p = (struct dbg_frame_s*)aos_msg_alloc( MPE_DEBUG, sizeof(struct dbg_frame_s) ); if( NULL == dbg_frame_p ) { return AOS_FAIL; } mb = msg_alloc(); if(NULL == mb) { aos_msg_free( (VOID*)dbg_frame_p ); return AOS_FAIL; } dbg_frame_p->is_to_borad = LOCAL_PRINT; mb->head = mem_obj_head(dbg_frame_p); mb->truelen = mem_obj_size(dbg_frame_p); mb->end = mb->head + mb->truelen; mb->data = (U8*)dbg_frame_p; mb->len = sizeof(struct dbg_frame_s); mb->tail = mb->data + mb->len; aos_time_get(&now); offset = aos_snprintf( (S8*)(print_buf), DEBUG_BUFFER_LEN, "[%03u-%02d:%02d:%02d:%03d]", serialno, now.hour,now.minute,now.second,now.millisec ); if( offset < DEBUG_BUFFER_LEN ) { VA_START( argptr, format ); offset +=aos_vsnprintf((S8*)(&print_buf[offset]), (U32)(DEBUG_BUFFER_LEN-offset), format, argptr ); VA_END( argptr ); } if( DEBUG_BUFFER_LEN < offset ) { offset = DEBUG_BUFFER_LEN; } print_buf[offset++] = '\r'; print_buf[offset++] = '\n'; print_buf[offset] = '\0'; local_proc_id = LOCAL_PROCESSOR_ID; dbg_frame_p->dstProcessorId = AOS_HTONL(local_proc_id); dbg_frame_p->length = AOS_HTONS((U16)ELEMENT_OFFSET(struct dbg_frame_s, u.printmsg) + (U16)ELEMENT_OFFSET(struct print_frame_s,str) + (U16)offset + 1 - (U16)DBG_RESV_HEAD_LEN); dbg_frame_p->u.printmsg.mpe = (U8)mpe; dbg_frame_p->cmd = DEBUG_SHOW; if( U32_BUTT != print_task_id ) { msg_que_tail( &x_print_que, mb ); aos_event_post( print_task_id,1 ); } else { arch_printf( mpe, print_buf ); aos_dmem_free( (VOID*)mb->head); msg_free(mb); } return AOS_SUCC;#undef print_buf}VOID debug_msg_proc( MSG_S *msg, VOID *pvMsg ){ struct dbg_frame_s *debugp = (struct dbg_frame_s *)pvMsg; if( NULL == msg || NULL == debugp ) { return; } if( (LOCAL_PROCESSOR_ID != msg->dstProcessorId) ||(MPE_DEBUG != msg->dstMpe) ) { return; } if( MPE_TIMER == msg->srcMpe ) { #if( CONFIG_BOARD_EIA == TRUE ) if( dev_is_linkok_with_gmpu() ) { dbg_info_log(); } else { aos_timer_start( NULL, MPE_DEBUG, DBG_REPORT_TIMER_LEN, DBG_REPORT_TIMER, 0, AOS_TIMER_NO_LOOP ); }#else dbg_info_log();#endif return; } if( TRANS_TO_ADA == debugp->is_to_borad ) { if( DEBUG_CONNECTED_LOCAL == debuger_connet_status ) { debug_output(debugp); } return; } else if( TRANS_TO_ADA_CLI == debugp->is_to_borad ) { debug_output(debugp); return; } debug_convert_byte_order( debugp ); if( (DEBUG_SHAKEHAND != debugp->cmd) &&(DEBUG_CONNECTED_NOT == debuger_connet_status ) ) { return; } switch( debugp->cmd ) { case DEBUG_CMD: debug_cmdmsg_handle( &debugp->u.cmdmsg ); break; case DEBUG_L3_MSG: debug_l3_msg_constructor( &debugp->u.l3msg ); break; case DEBUG_L2_MSG: lcm_l2_msg_constructor( &debugp->u.l2msg ); break; case DEBUG_SHOW: aos_printf( MPE_DEBUG,"Unexpected print message" ); break; case DEBUG_SHAKEHAND: debuger_ip_addr = debugp->debuger_ip_addr; debuger_port = debugp->u.debuger_port; trans_processor_id = msg->srcProcessorId; if( LOCAL_PROCESSOR_ID == msg->srcProcessorId ) { debuger_connet_status = DEBUG_CONNECTED_LOCAL; if( MPE_CLI == msg->srcMpe ) { debuger_connet_status |= DEBUG_CONNECTED_CLI; } } else { debuger_connet_status = DEBUG_CONNECTED_REMOTE; if( MPE_CLI == msg->srcMpe ) { debuger_connet_status |= DEBUG_CONNECTED_CLI; } } aos_printf( MPE_DEBUG, "ADA CONNECTED ...,WELCOME!" ); break; case DEBUG_GOODBYE: aos_printf( MPE_DEBUG, "ADA DISCONNECTED ...,GOODBYE!" ); debuger_connet_status = DEBUG_CONNECTED_NOT; debuger_ip_addr = 0; debuger_port = U16_BUTT; trans_processor_id = U32_BUTT; break; default: aos_printf( MPE_DEBUG, "Unknown debug cmd=%d", debugp->cmd ); break; }}VOID print_task( struct msg_blk_que *que ){ struct msg_blk *mb; SOCKADDRIN_S addr; struct dbg_frame_s *dbg_frame_p; U32 event; AOS_ASSERT( NULL!= que ); aos_memset( &addr, 0, sizeof(SOCKADDRIN_S) ); print_task_id = aos_task_self(); for( ;; ) { aos_event_wait(U32_BUTT, AOS_WAIT_ANY, 0, &event); while( NULL != (mb = msg_deque( que ) ) ) { dbg_frame_p = ( struct dbg_frame_s*)mb->data; if( LOCAL_PRINT == dbg_frame_p->is_to_borad ) { if( AOS_SUCC != ssp_mpe_print_verify( dbg_frame_p->u.printmsg.mpe ) ) { aos_dmem_free( (VOID*)mb->head ); msg_free( mb ); continue; } if( DEBUG_CONNECTED_LOCAL & debuger_connet_status ) { if( DEBUG_CONNECTED_CLI & debuger_connet_status ) {#if( AOS_INCLUDE_SMP_CLI == TRUE ) cli_out_string( AOS_HTONL(debuger_ip_addr), dbg_frame_p->u.printmsg.str );#endif } else { if( NULL_SOCKET == x_send_sock ) { x_send_sock = socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP); } addr.sin_chFamily = AF_INET; addr.sin_stAddr.s_ulAddr = debuger_ip_addr; addr.sin_usPort = debuger_port; sendto( x_send_sock, (S8*)&dbg_frame_p->dstProcessorId, AOS_NTOHS(dbg_frame_p->length), 0, &addr, sizeof(SOCKADDRIN_S) ); } } else if( DEBUG_CONNECTED_REMOTE & debuger_connet_status ) { MSG_S msg; dbg_frame_p->debuger_ip_addr = debuger_ip_addr; dbg_frame_p->debuger_port_agnt = debuger_port; if( DEBUG_CONNECTED_CLI & debuger_connet_status ) { dbg_frame_p->is_to_borad = TRANS_TO_ADA_CLI; } else { dbg_frame_p->is_to_borad = TRANS_TO_ADA; } msg.dstProcessorId = trans_processor_id; msg.dstMpe = MPE_DEBUG; msg.srcProcessorId = LOCAL_PROCESSOR_ID; msg.srcMpe = MPE_RTPEIG; msg.msgPrio = MSG_PRIO_NORMAL; msg.ulSize = AOS_NTOHS(dbg_frame_p->length)+DBG_RESV_HEAD_LEN; msg.pvMsgBuf = (VOID*)dbg_frame_p; SYS_HANDLE_LOCK(); aos_msg_trysend( &msg ); SYS_HANDLE_UNLOCK(); continue; }#if(CONFIG_BOARD_EIA == TRUE && CONFIG_OS_VXWORKS == TRUE) else if( phy_console_is_to_u1000() ) { com_send_console_msg( dbg_frame_p->u.printmsg.str, aos_strlen(dbg_frame_p->u.printmsg.str) ); }#endif else { arch_printf( dbg_frame_p->u.printmsg.mpe, dbg_frame_p->u.printmsg.str ); } } else if( TRANS_TO_ADA == dbg_frame_p->is_to_borad )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -