📄 debugtask.c
字号:
/*
* description: DebugTask
* Maker : Kamada Satoru
* Copyright : (C)2004,SEIKO EPSON Corp. All Rights Reserved.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "DebugTask.h"
#include "DrvCtlTask.h"
#include "SPRSTS.h"
#include "UART_FUNC.h"
/*====================================*/
/* Define */
/*====================================*/
/* Continuation display */
#define DBG_DUMP_DIS (0x40)
#define DBG_ENTER_BYTE_DIS (0x01)
#define DBG_ENTER_WORD_DIS (0x02)
#define DBG_ENTER_DWORD_DIS (0x04)
/* Print limit */
#define PRINT_OUT_MAX_LINE (4)
#define PRINT_DB_MAX_BYTE (16)
#define PRINT_DW_MAX_BYTE (8)
#define PRINT_DD_MAX_BYTE (4)
/* Command */
#define DBG_ENTER_NEXT '\0'
#define DBG_ENTER_BACK '^'
#define DBG_ENTER_EXIT_Q 'Q'
#define DBG_ENTER_EXIT_q 'q'
/* VALUE CHANGE SIZE */
#define DBG_VALUE_SIZE_BYTE (2)
#define DBG_VALUE_SIZE_WORD (4)
#define DBG_VALUE_SIZE_DWORD (8)
/*====================================*/
/* Typedef */
/*====================================*/
/* Call back function */
typedef void (*PFN_CALLBACK) ( void );
/* Command information */
typedef struct _DATA_COMPOSITION
{
USHORT cmdType;
pfnCmdProc pfnCallBackRutin;
struct _dataMember{
CHAR rcvCmd[DBG_STR_MAX];
ULONG rcvAddress;
ULONG rcvData;
} dataMember;
} DATA_COMPOSITION;
/* Watch Print use */
typedef union _watch_print
{
ULONG watchLong;
struct _watchChar
{
UCHAR watchChar1;
UCHAR watchChar2;
UCHAR watchChar3;
UCHAR watchChar4;
} watchChar;
} watch_union;
/* Key wait info */
typedef struct tagKEY_INFO {
BOOL bEnable;
BOOL bEnbCmp; // Whether carry out comparison
UCHAR* pData;
USHORT size;
} KEY_INFO, *PKEY_INFO;
/*====================================*/
/* Function prototype */
/*====================================*/
LONG StringAnalysis( CHAR* pStr );
LONG ChangeStr( CHAR* pStrBuf );
int SplitStr( CHAR* pInputStr, CHAR* pOutputStr );
LONG CmdAnalysis( void );
LONG Cmd_Practice( void );
void DBOutput( UCHAR* pAddress );
void DWOutput( UCHAR* pAddress );
void DDOutput( UCHAR* pAddress );
void EBOutput( UCHAR* pAddress );
void EWOutput( USHORT* pAddress );
void EDOutput( ULONG* pAddress );
BOOL ErrOutput( LONG inStatus );
BOOL CheckCapitalAndSmall( UCHAR Src, UCHAR Dest );
LONG StrChangeHex( ULONG* pHexConvValue, CHAR* pStr , UCHAR size );
void ValChangeStr( CHAR* str , ULONG Val , UCHAR type , UCHAR mode);
static short UART_Callback( unsigned short wMsg, unsigned short wParam0, void *pParam1 );
static LONG GetStr( CHAR* pString, USHORT* pDataSize, OS_TMO tmout );
/* Functions which be called back */
LONG FuncCmdProcDB( LONG extra );
LONG FuncCmdProcDW( LONG extra );
LONG FuncCmdProcDD( LONG extra );
LONG FuncCmdProcEB( LONG extra );
LONG FuncCmdProcEW( LONG extra );
LONG FuncCmdProcED( LONG extra );
LONG FuncCmdProcWT( LONG extra );
LONG FuncCmdProcWTC( LONG extra );
LONG FuncCmdProcFlow( LONG extra );
LONG FuncCmdProcHelp( LONG extra );
LONG FuncCmdProcIDEMode( LONG extra );
LONG PrintOut( CHAR* pStr );
/*====================================*/
/* Variable */
/*====================================*/
DATA_COMPOSITION CurrentData; // Saving place of command information inputted
DATA_COMPOSITION OldData; // Saving place of command information inputted last time
static UCHAR InfoState; // Saving area of information received
BOOL FlowToggle = DBG_FLOW_DEFAULT; // Saving variable of flow switch
#ifdef DBG_FLOW_LV_C
UCHAR FlowLevel = DBG_FLOW_LV_C; // Flow output level
#else
UCHAR FlowLevel = 3; // Flow output level
#endif
static DBG_WATCH_DATA Watch_Area; // Saving area of Watch
watch_union watch_print; // WatchPrint use
KEY_INFO KeyInfo; // Variable for FlowGetKey use
// Add for Analog evaluation use
static unsigned char KeyCallbackFlag;
static CALLBACK_PROC KeyCallback;
/******************************************************************************/
/* Command information table */
/******************************************************************************/
TBL_CMD_INFO g_Tbl_CmdInfo[] = {
/*Information*/
{
"",
DBG_CMDID_INFO,
NULL,
"[MEMORY DUMP]",
""
},
/* Dump byte command information */
{
"DB",
DBG_CMDID_DUMP_BYTE,
FuncCmdProcDB,
"<Address> ",
"MEMORY DUMP乮僶僀僩扨埵 1byte乯"
},
/* Dump word command information */
{
"DW",
DBG_CMDID_DUMP_WORD,
FuncCmdProcDW,
"<Address> ",
"MEMORY DUMP乮儚乕僪扨埵 2byte乯"
},
/* Dump double word command information */
{
"DD",
DBG_CMDID_DUMP_DWORD,
FuncCmdProcDD,
"<Address> ",
"MEMORY DUMP乮僟僽儖儚乕僪扨埵 4byte乯"
},
/*Information*/
{
"",
DBG_CMDID_INFO,
NULL,
"[MEMORY ENTER]",
""
},
/* Enter byte command information */
{
"EB",
DBG_CMDID_ENTER_BYTE,
FuncCmdProcEB,
"<Address> <Data>",
"僨乕僞彂偒姺偊乮僶僀僩扨埵 1byte乯"
},
/* Enter word command information */
{
"EW",
DBG_CMDID_ENTER_WORD,
FuncCmdProcEW,
"<Address> <Data>",
"僨乕僞彂偒姺偊乮儚乕僪扨埵 2byte乯"
},
/* Enter double word command information */
{
"ED",
DBG_CMDID_ENTER_DWORD,
FuncCmdProcED,
"<Address> <Data>",
"僨乕僞彂偒姺偊乮僟僽儖儚乕僪扨埵 4byte乯"
},
/*Information*/
{
"",
DBG_CMDID_INFO,
NULL,
"[TRACE]",
""
},
/* Watch command information */
{
"WT",
DBG_CMDID_WATCH,
FuncCmdProcWT,
" ",
"搊榐偟偨儊儌儕撪梕乮搊榐儊儌儕扨埵乯",
},
/* Watch clear command information */
{
"WTC",
DBG_CMDID_WATCH_CLEAR,
FuncCmdProcWTC,
" ",
"搊榐偟偨儊儌儕撪梕偺0僋儕傾乮搊榐儊儌儕扨埵乯"
},
/* Flow command information */
{
"F",
DBG_CMDID_FLOW,
FuncCmdProcFlow,
" ",
"僀儀儞僩偺弌椡愝掕(Default帪偼OFF)"
},
/*Information*/
{
"",
DBG_CMDID_INFO,
NULL,
"[OTHER]",
""
},
/* Help command information */
{
"?",
DBG_CMDID_HELP,
FuncCmdProcHelp,
" ",
"僐儅儞僪偺擖椡彂幃堦棗弌椡"
},
/* Command table end */
{
NULL,
0,
NULL,
NULL,
NULL
}
};
/*=============================================================================
// Function_Name: DebugTask
// description : Debug task
// argument : None
// return : None
// =============================================================================
*/
void DebugTask( void )
{
CHAR pStr[DBG_STR_MAX]; // Temporary saving area of string received
LONG result = DBG_STATUS_SUCCESS; // Return value
UCHAR bErr;
int i;
// Initial state is in default
InfoState = DBG_STATE_INITIAL;
/* Message area initialization */
KeyInfo.bEnable = FALSE;
KeyInfo.bEnbCmp = FALSE;
KeyInfo.size = 0x00;
KeyInfo.pData = NULL;
memset(&Watch_Area, 0, sizeof(Watch_Area)); // Cope with warning for the optimization.
// Add for Analog evaluation use
KeyCallbackFlag = FALSE;
KeyCallback = NULL;
/* Task start */
if( FlowToggle == TRUE )
{
PrintOut("----- FLOW : ON -----");
PrintOut ( "\r\n>" );
}
// Loop
while(1)
{
switch( InfoState )
{
/* Initial state */
case DBG_STATE_INITIAL:
if( FlowToggle == FALSE )
{
PrintOut ( "\r\n>" );
}
else
{
PrintOut ( "\r\n" );
}
InfoState = DBG_STATE_WAIT_KEY_IN; /* State transition */
break;
/* Key-waiting state */
case DBG_STATE_WAIT_KEY_IN:
// Receive to string
FlowGetStr( pStr, (USHORT *)sizeof(pStr), 0 );
/* Move to next state when receiving string */
InfoState = DBG_STATE_STR_RCV; /* State transition. */
break;
/* State of receiving string */
case DBG_STATE_STR_RCV:
// Add for Analog evaluation use
// Check whether FlowKeyHit API is called.
if( KeyCallbackFlag == TRUE )
{
KeyCallback( 0, 0, 0 );
KeyCallbackFlag = FALSE;
KeyCallback = NULL;
InfoState = DBG_STATE_INITIAL; /* State transition */
}
else if( KeyInfo.bEnable == TRUE )
{
// Wait for key inputting from other task.
InfoState = DBG_STATE_KEY_INPUT;
}
else
{
/* Move to next state when receiving string */
InfoState = DBG_STATE_STR_ANALYSIS; /* State transition */
}
break;
/* State of string judgement */
case DBG_STATE_STR_ANALYSIS:
result = StringAnalysis( pStr );
/* String analysis */
if( result >= DBG_STATUS_SUCCESS )
{
if( result == DBG_STATUS_NOINPUT )
{
/* Move to initial state if there is no command data */
InfoState = DBG_STATE_INITIAL; /* State transition */
}
else
{
/* Move next state if it finish normally */
InfoState = DBG_STATE_CMD_PRACTICE; /* State transition */
}
}
else
{
/* Shift to state of error output in case of error */
InfoState = DBG_STATE_ERROR; /* State transition */
}
break;
/* Command execution state */
case DBG_STATE_CMD_PRACTICE:
PrintOut ( "\r\n" );
/* Carry out command which is after analysis */
result = CurrentData.pfnCallBackRutin( result );
/* Change state in case of no data inputted when re-write function running */
switch( result )
{
/* At the time of normal finish */
case DBG_STATUS_SUCCESS:
InfoState = DBG_STATE_INITIAL; /* State transition */
break;
/* For other cases, shift to state of error output */
default:
InfoState = DBG_STATE_ERROR; /* State transition */
break;
}
break;
/* Waiting for data input */
case DBG_STATE_KEY_INPUT:
bErr = FALSE;
if( KeyInfo.bEnbCmp == TRUE )
{
for( i = 0; i < KeyInfo.size; i++ )
{
if( CheckCapitalAndSmall( *(pStr + i), *(KeyInfo.pData+i) ) != TRUE )
{
bErr = TRUE;
}
}
if( bErr != TRUE )
{
// String is agreed
KeyInfo.bEnable = FALSE;
KeyInfo.bEnbCmp = FALSE;
KeyInfo.size = 0x00;
KeyInfo.pData = NULL;
}
else
{
/* Carry out error output */
ErrOutput( result );
}
}
else
{
// In case of no comparison, copy data and finish.
KeyInfo.size = (USHORT)strlen( pStr );
memcpy( KeyInfo.pData, pStr, KeyInfo.size );
// String is agreed.
KeyInfo.bEnable = FALSE;
KeyInfo.bEnbCmp = FALSE;
}
/* Shift to initial state */
InfoState = DBG_STATE_INITIAL; /* State transition */
break;
/* State of error output */
case DBG_STATE_ERROR:
default:
/* Carry out error output */
ErrOutput( result );
/* Shift to initial state */
InfoState = DBG_STATE_INITIAL; /* State transition */
break;
}
}
}
/*=============================================================================
// Function_Name: StringAnalysis
// description : String analysis function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -