📄 sys_debug.c
字号:
/*
* usrdebug.c
*
* Copyright (C) 2005 Cheertek Inc, K300 all right reserved.
*
* Nov 28, 2005 file created by K300 (Mark Lu).
*
* User Debug Interface.
*/
#include "stdio.h"
#include "string.h"
#include "ct_type.h"
#include "ct_os.h"
#include "ct_uart.h"
#include "task_cfg.h"
#include "sys_debug.h"
#include "ct_irq.h"
/*************************************************************************
* Define declare.
************************************************************************/
#define USRDEBUG_MAX_COMMAND_LENGTH 100
#define USRDEBUG_QUEUE_SIZE 256
//#define CT_CMDI_WAIT (0xffffffff)
/************************************************************************
* Print macro.
************************************************************************/
#if 0
#define CMD_OUT(p)
#else
#define CMD_OUT(p) printf p
#endif
/************************************************************************
* Debug macro.
************************************************************************/
#if 0
#define DBG_PRINT(p)
#else
#define DBG_PRINT(p) printf p
#endif
u32 fd_point = 5;
//void UsrDebug_Handle(u8 data,u8 status);
static void UsrDebug_Handle(void);
void UsrDebug_Handle_LISR(u8 data,u8 status);
//MSG_PARAMETER MenuMsgQueue;
#ifdef TFT_ENABLE
// debug tools
#define DVB_DEBUG_TOOLS_TIMEOUT 20
#if 0
#define DVB_DEBUG_TOOLS_READ_DRAM_CMD 0x61 //'a'
#define DVB_DEBUG_TOOLS_READ_DRAM_CMD_ACK 0x62 //'b'
#define DVB_DEBUG_TOOLS_READ_DRAM_CMD_ERROR 0x63 //'c'
//Write DRAM Tag
#define DVB_DEBUG_TOOLS_WRITE_DRAM_CMD 0x64 //'d'
#define DVB_DEBUG_TOOLS_WRITE_DRAM_CMD_ACK 0x65 //'e'
#define DVB_DEBUG_TOOLS_WRITE_DRAM_COMPLETE_ACK 0x66 //'f'
#define DVB_DEBUG_TOOLS_WRITE_DRAM_CMD_ERROR 0x67 //'g'
//Binary Mode Tag
#define DVB_DEBUG_TOOLS_START_BINARY_MODE_CMD 0x41 //'A'
#define DVB_DEBUG_TOOLS_START_BINARY_MODE_ACK 0x42 //'B'
#define DVB_DEBUG_TOOLS_START_BINARY_MODE_ERROR 0x43 //'C'
#define DVB_DEBUG_TOOLS_END_BINARY_MODE_CMD 0x44 //'D'
#define DVB_DEBUG_TOOLS_END_BINARY_MODE_ACK 0x45 //'E'
#define DVB_DEBUG_TOOLS_END_BINARY_MODE_ERROR 0x46 //'F'
#define DVB_DEBUG_TOOLS_ERROR_RECOVER_CMD 0x47 //'G'
#define DVB_DEBUG_TOOLS_END_CMD 0x48 //'H' //PC end sending command to 8051
#else
//Read DRAM Tag
#define DVB_DEBUG_TOOLS_READ_DRAM_CMD 0x91
#define DVB_DEBUG_TOOLS_READ_DRAM_CMD_ACK 0x92
#define DVB_DEBUG_TOOLS_READ_DRAM_CMD_ERROR 0x93
//Write DRAM Tag
#define DVB_DEBUG_TOOLS_WRITE_DRAM_CMD 0x94
#define DVB_DEBUG_TOOLS_WRITE_DRAM_CMD_ACK 0x95
#define DVB_DEBUG_TOOLS_WRITE_DRAM_COMPLETE_ACK 0x96
#define DVB_DEBUG_TOOLS_WRITE_DRAM_CMD_ERROR 0x97
//Binary Mode Tag
#define DVB_DEBUG_TOOLS_START_BINARY_MODE_CMD 0xF1
#define DVB_DEBUG_TOOLS_START_BINARY_MODE_ACK 0xF2
#define DVB_DEBUG_TOOLS_START_BINARY_MODE_ERROR 0xF3
#define DVB_DEBUG_TOOLS_END_BINARY_MODE_CMD 0xF4
#define DVB_DEBUG_TOOLS_END_BINARY_MODE_ACK 0xF5
#define DVB_DEBUG_TOOLS_END_BINARY_MODE_ERROR 0xF6
#define DVB_DEBUG_TOOLS_ERROR_RECOVER_CMD 0xFB
#define DVB_DEBUG_TOOLS_END_CMD 0xFF //PC end sending command to 8051
#endif
#define DVB_LOW_BYTE(w) ((u8)(w))
#define DVB_HIGH_BYTE(w) ((u8)(((u32)(w) >> 8) & 0xFF))
#define DVB_LOW_WORD(l) ((u16)(u32)(l))
#define DVB_HIGH_WORD(l) ((u16)((((u32)(l)) >> 16) & 0xFFFF))
#endif
#define DVB_DEBUG_PASSWD (999)
/*************************************************************************
* Global variables.
************************************************************************/
extern bool8 bGetHISRInfo;
static bool8 b8UsrdebugInit = FALSE;
static CTOS_SEMAPHORE AuUsrDebugSemore;
/*************************************************************************
* Local variables.
************************************************************************/
static u8 u8Argc = 0;
static u8 au8Argv[8][DEBUG_MAX_ARGV_LENGTH];
static u8 au8CmdBuf[USRDEBUG_MAX_COMMAND_LENGTH];
static u8 u8CmdCount = 0;
static u8 au8DebugStack[DVB_DEBUG_TASK_STACK_SIZE];
//static u32 au32DebugQueue[USRDEBUG_QUEUE_SIZE];
static CTOS_TASK Usrdebug_Task;
#ifdef PVR_ENABLE
// for callback
static u32 _u32PVRPlaybackStartTime = 0;
static u32 _u32PVRPlaybackEndTime = 0;
static EN_PVR_EVENT _enPVRCurrentEvent = EN_PVR_EVENT_NONE;
// for long test
// Record
static bool8 _b8LongTestRecord = FALSE;
static u16 _u16RecordDuration = 0;
// Different Record
static bool8 _b8LongTestDifferentRecord = FALSE;
static u16 _u16DifferentRecordDuration = 0;
static u16 _u16DifferentIncreaseTime = 0;
// Playback
static bool8 _b8LongTestPlayback = FALSE;
static u32 _u32PlaybackFileIndex = 0;
// Different Playback
static bool8 _b8LongTestDifferentPlayback = FALSE;
static u32 _u32DifferentPlaybackFileIndex = 0;
static u32 _u32DifferentPlaybackFileCount = 0;
// Key
static bool8 _b8LongTestKey = FALSE;
static bool8 _b8LongTestKeyPlayback = FALSE;
static u8 _u8LongTestKey = 0;
static u8 _u8LongTestSpeed = 0;
#endif
/************************************************************************
* Functions declare.
************************************************************************/
static u32 DHConvert(char *s);
EN_DRV_RESULT Usrdebug_ParseCommand(u8 *pu8ParStr, u8 *pu8ParArgc, u8 *pu8ParArgv);
EN_DRV_RESULT Usrdebug_ExecuteCommand(u8 *pu8ExeArgv);
static void Usrdebug_InterfaceTask(u32, void *);
#ifdef TFT_ENABLE
static void Sys_DebugToolsTimeout(void);
static void Sys_DebugToolsCMD(void);
static u32 Sys_DebugToolsValueConverter(u8 *pu8Value);
void DVB_DebugTools(bool8 b8Flag);
void DVB_DebugToolsMem(bool8 b8Read, u32 u32Address, u32 u32Value);
static bool8 _b8DebugTools = FALSE;
#endif
static u16 u16DynamicCmdNum = 0;
static USRDEBUG_USER_COMMAND *stDynamicCmd = NULL;
static EN_SWITCH_DEBUG enSwitchDebug=0;
/************************************************************************
* get user debug cmd table
************************************************************************/
void DVB_SetUserdebugTable(USRDEBUG_USER_COMMAND *pstUserTable,u16 u16CmdNum)
{
stDynamicCmd = pstUserTable;
u16DynamicCmdNum = u16CmdNum;
}
/************************************************************************
* switch between user debug table and system debug table
************************************************************************/
EN_SWITCH_DEBUG DVB_GetUserDebugMode(void)
{
return enSwitchDebug;
}
EN_SWITCH_DEBUG DVB_SetUserDebugMode(EN_SWITCH_DEBUG _enSwitchDebug)
{
enSwitchDebug = _enSwitchDebug;
return enSwitchDebug;
}
void DVB_SwitchDebugTable(u16 u16Password)
{
if(enSwitchDebug==EN_USER_DEBUG&&u16Password==DVB_DEBUG_PASSWD)
enSwitchDebug=EN_SYSTEM_DEBUG;
else
enSwitchDebug=EN_USER_DEBUG;
}
/************************************************************************
* Userdebug initialised function.
************************************************************************/
static CTOS_HISR stUartRxHISR;
#if defined (CTOS_NUCLEUS)
static u8 u8UartRXHISR_Stack[DEBUG_UART_RX_HISR_STACK_SIZE];
#endif
#if defined (CTOS_ECOS)
#define UART_VECTOR INTR_UART_1
#endif
EN_DRV_RESULT DVB_DebugInitial(void)
{
if(TRUE==b8UsrdebugInit)
{
return (DRV_OK);
}
if(EN_CTOS_SUCCESS!=CT_OS_CreateSemaphore(&AuUsrDebugSemore,"AuDebug",0, EN_CTOS_SUSPEND_FIFO))
{
DBG_PRINT(("\n\r>>Error, CT_OS_CreateSemaphore"));
return (DRVERR_NOTOK);
}
if(EN_CTOS_SUCCESS != CT_OS_CreateTask(&Usrdebug_Task, "DVBDBG", Usrdebug_InterfaceTask, &au8DebugStack[0], DVB_DEBUG_TASK_STACK_SIZE, DVB_DEBUG_TASK_PRIORITY, DVB_DEBUG_TASK_TIME_SLICE))
{
DBG_PRINT(("\r\n>> DVB_DebugInitial: create task fail!!"));
return (DRVERR_NOTOK);
}
#if defined (CTOS_NUCLEUS)
CT_OS_CreateHISR(&stUartRxHISR, "Rx_HISR", UsrDebug_Handle, 10, &u8UartRXHISR_Stack, DEBUG_UART_RX_HISR_STACK_SIZE);
#endif
#if defined (CTOS_ECOS)
CT_OS_CreateHISR(UART_VECTOR, &stUartRxHISR, "Rx_HISR", UsrDebug_Handle, 10, NULL, 0);
#endif
if(DRV_OK!=CT_UART_RegisterRxCallback(UsrDebug_Handle_LISR))
{
DBG_PRINT(("\r\n>>Error,CT_UART_RegisterRxCallback "));
return (DRVERR_NOTOK);
}
#ifdef DEVICE_LOG
if(DRV_OK != DVB_LOG_Initial())
{
DBG_PRINT(("\n>> [USRDLOG] DVB_LogInitial fail \n"));
}
#endif
DBG_PRINT(("\n\r>> [USRDEBUG] DVB_DebugInitial success"));
b8UsrdebugInit = TRUE;
return (DRV_OK);
} /* end DVB_DebugInitial */
/************************************************************************
* Userdebug initialised function.
************************************************************************/
EN_DRV_RESULT DVB_DebugStart(void)
{
/*
* Start the command interface running...
*/
if (EN_CTOS_SUCCESS != CT_OS_ResumeTask(&Usrdebug_Task))
{
return (DRVERR_NOTOK);
}
return (DRV_OK);
} /* end UsrDebug_Initial */
/************************************************************************
* Receive the user input character and save the character to u8CmdBuf.
* When user press enter, then call function usrdebug_parse_command.
************************************************************************/
static void Usrdebug_InterfaceTask(u32 u32Argc, void* pArgv)
{
// u32 i;
u32 j;
u32 k;
CMD_OUT(("\n\rCDAT >>"));
while (1)
{
/*
* Wait Semore from UsrDebug_Handle.
*/
CMD_OUT(("\n\rCDAT >>"));
if(EN_CTOS_SUCCESS!=CT_OS_WaitOnSemaphore(&AuUsrDebugSemore,CTOS_WAIT))
{
CMD_OUT(("\n\rError,CT_OS_WaitOnSemaphore"));
}
if (Usrdebug_ParseCommand(&au8CmdBuf[0], &u8Argc, (u8 *)au8Argv) == DRV_OK)
{
if (Usrdebug_ExecuteCommand((u8 *)au8Argv) == DRV_OK)
{
CMD_OUT(("\n\r[USRDEBUG]%s OK", au8Argv[0]));
// CMD_OUT(("\n\rCDAT >>"));
}else
{
CMD_OUT(("\n\r no command %s", au8Argv[0]));
}
/*
* Clean argv and argc.
*/
for (j = 0; j < u8Argc; j++)
{
for (k = 0; k < DEBUG_MAX_ARGV_LENGTH; k++)
{
au8Argv[j][k] = 0;
}
}
u8Argc = 0;
}
/*
* Clean receive buffer.
*/
u8CmdCount=0;
memset(au8CmdBuf, 0, USRDEBUG_MAX_COMMAND_LENGTH);
}
} /* end Usrdebug_Task */
/************************************************************************
* Parse the user command to independent argument. Separated by space,
* tab or comma.
************************************************************************/
EN_DRV_RESULT Usrdebug_ParseCommand(u8 *pu8ParStr, u8 *pu8ParArgc, u8 *pu8ParArgv)
{
u8 i;
u8 u8Char;
u8 u8ArgcStrCnt = 0;
u8 u8Result = DRVERR_NOTOK;
u16 u16ParStrCnt;
u16ParStrCnt = strlen(pu8ParStr);
if (u16ParStrCnt == 0)
{
return (DRVERR_NOTOK);
}
for (i = 0; i < u16ParStrCnt; i++)
{
u8Char = pu8ParStr[i];
switch (u8Char)
{
case 0x00:
case ' ' :
case ',' :
case '\t':
if (u8ArgcStrCnt != 0)
{
(*pu8ParArgc)++;
u8ArgcStrCnt = 0;
}
break;
default :
pu8ParArgv[((*pu8ParArgc) * DEBUG_MAX_ARGV_LENGTH) + (u8ArgcStrCnt++)] = u8Char;
u8Result = DRV_OK;
break;
}
}
if (u8Result == DRV_OK)
{
(*pu8ParArgc)++;
}
return (u8Result);
} /* end UsrdebugParseCommand */
/************************************************************************
* Execute the command.
************************************************************************/
EN_DRV_RESULT Usrdebug_ExecuteCommand(u8 *pu8ExeArgv)
{
u16 i = 0;
u16 u16CmdNum = sizeof(stSysCmd) / sizeof(USRDEBUG_USER_COMMAND);
if(enSwitchDebug==EN_USER_DEBUG)
{
for (i = 0; i < u16DynamicCmdNum; i++)
{
if (strcmp(stDynamicCmd[i].au8Name, &pu8ExeArgv[0]) == 0)
{
CMD_OUT(("\n\r"));
if( stDynamicCmd[i].func_ptr==NULL )
return (DRVERR_NOTOK);
stDynamicCmd[i].func_ptr(DHConvert(&pu8ExeArgv[1 * DEBUG_MAX_ARGV_LENGTH])
, DHConvert(&pu8ExeArgv[2 * DEBUG_MAX_ARGV_LENGTH])
, DHConvert(&pu8ExeArgv[3 * DEBUG_MAX_ARGV_LENGTH]));
return (DRV_OK);
}
}
}else
{
for (i = 0; i < u16CmdNum; i++)
{
if (strcmp(stSysCmd[i].au8Name, &pu8ExeArgv[0]) == 0)
{
CMD_OUT(("\n\r"));
if( stSysCmd[i].func_ptr==NULL )
return (DRVERR_NOTOK);
stSysCmd[i].func_ptr(DHConvert(&pu8ExeArgv[1 * DEBUG_MAX_ARGV_LENGTH]),
DHConvert(&pu8ExeArgv[2 * DEBUG_MAX_ARGV_LENGTH]),
DHConvert(&pu8ExeArgv[3 * DEBUG_MAX_ARGV_LENGTH]));
return (DRV_OK);
}
}
}
return (DRVERR_NOTOK);
} /* end UsrdebugExecuteCommand */
/************************************************************************
*
************************************************************************/
static u32 DHConvert(char *s)
{
u16 i, m;
u32 k;
if (s == NULL) { return 0; }
i = 0;
while ((s[i] != 10 && s[i] != 13 && s[i] != 0) || i == 10) i++;
s[i] = 0;
if (s[0] == '0' && (s[1] == 'X' || s[1] == 'x'))
{
k = 0 ;
for (i = 2; i < strlen(s); i++)
{
if (s[i] == ' '|| s[i] == '\t') break;
k <<= 4;
if ('0' <= s[i] && s[i] <='9')
{
k += (s[i] - '0');
}
else if ('a'<= s[i] && s[i] <= 'f')
{
k += (s[i] - 'a' + 10);
}
else if ('A' <= s[i] && s[i] <= 'F')
{
k += (s[i] - 'A' + 10);
}
else if (s[i] == '?')
{
k = DVB_Random()%(k+1);
}
}
return ((u32)k);
}
else
{
m = strlen(s);
if (10 <= m) return (-1);
k = 0;
for (i = 0; i < m ;i++)
{
if(s[i] == '?')
{
k = DVB_Random()%(k+1);
}
else
{
k = (k * 10) + (s[i] - '0');
}
}
return ((u32)k);
}
}
/*********************************************************************************
*
*********************************************************************************/
static u8 u8UartRxData;
void UsrDebug_Handle_LISR(u8 data,u8 status)
{
CT_OS_ActivateHISR(&stUartRxHISR);
u8UartRxData=data;
}
void UsrDebug_Handle(void)
{
u8 u8data;
u8 au8String[10];
#ifdef CTOS_ECOS
extern void CT_OS_DumpPCStackByTaskId(u16 u16TaskID,u32 u32Num);
#endif
u8data=u8UartRxData;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -