#include #include #include #include "mtask.h" #include "itu.h" #include "debug.h" #include "3048f.h" #include "initperi.h" #include "sio0.h" #include "sio1.h" typedef void (*VECTOR)(void); typedef char (*GETCH_FUNC)( void ); typedef void (*PUTCH_FUNC)( char a ) ; #define MAX_COMMAND 60 #define BS 8 static char* GetCommandLine( void ) ; static void ResetJump( VECTOR ) ; static char* ReadOutWhiteSpace( char* Buffer ) ; static char* NextParameter( char* Buffer ) ; void main( void ); static void SystemInformation( int MoreInfo ) ; void StackDump( int i,void( *DumpWait )( unsigned long a ), int WaitNumber, unsigned int( *DumpStopCondition )( void ) ) ; void DumpAllStack( void( *DumpWait )( unsigned long a ), int WaitNumber, unsigned int( *DumpStopCondition )( void ) ) ; static GETCH_FUNC GetChar ;//このモニターで使用する1文字入力ルーチン static PUTCH_FUNC PutChar ;//このモニターで使用する1文字出力ルーチン /****************************************************************************** 機能要約 機能 引き数 戻り値 注意 ******************************************************************************/ void Monitor( void ) { extern void _start( void ) ; extern TASK CPUTaskCommandMode( void ) ; static const char* const HowToUse[] = { "d memory dump (ex d 0xff00)" , "r reset" , "s stack dump" , "v version and system infomation" , "z dump zero area" , "1 disp timer" , NULL } ; char* Buffer ; long Address ; int i ; GetChar = GetcSio1 ; PutChar = PutcSio1 ; Sleep( 100 ) ; DbgCrLf() ; DbgCrLf() ; SystemInformation( 0 ) ; for(;;) { DbgCrLf() ; dbgprint( "MON>" ) ; Buffer = GetCommandLine() ; if( Buffer == 0 ) { continue ; } DbgCrLf() ; i = toupper( *Buffer ) ; switch( i ) { case '0' : Buffer ++ ; Address = AtoL( Buffer ) ; tprintf( "GetPulse=%d", GetPulse() ) ; for( ; Address != 0 ; Address -- ) { BitSet( P4DR,7 ) ; BitClr( P4DR,7 ) ; } tprintf( "GetPulse=%d 0x%x", GetPulse(), GetPulse() ) ; break ; case '1' : while( RecvLength1() == 0 ) { dbgprint( "GetTimer:" ); dbgprint(ItoA10(GetTimer())); DbgOut('\r' ) ; Sleep( 1000 ) ; } GetChar() ; DbgCrLf() ; break ; case 'D' : Buffer ++ ; Address = AtoL( Buffer ) ; DumpAddress( Address, 0xffffff, Sleep, 2, RecvLength1 ) ; DbgCrLf() ; break ; case 'R' : ResetJump( NULL ) ; break ; case 'V' : SystemInformation( 1 ) ; break ; case 'S' : Buffer = NextParameter( Buffer ) ; if( isdigit( ( int )*Buffer ) ) { i = AtoL( Buffer ) ; StackDump( i, Sleep, 2, RecvLength1 ) ; break ; } DumpAllStack( Sleep, 2, RecvLength1 ) ; DbgCrLf() ; break ; default : OutputStrings( HowToUse ) ; break ; } } } /****************************************************************************** 機能要約 機能 引数 戻り値 注意 ******************************************************************************/ void DumpAllStack( void( *DumpWait )( unsigned long a ), int WaitNumber, unsigned int( *DumpStopCondition )( void ) ) { int i ; for( i = 0 ; i < GetNumOfTask() ; i ++ ) { StackDump( i, DumpWait, WaitNumber, DumpStopCondition ) ; } } void StackDump( int i,void( *DumpWait )( unsigned long a ), int WaitNumber, unsigned int( *DumpStopCondition )( void ) ) { dbgsbcr( "--- Stack ", ( char )i ) ; DumpAddress( ( long )GetStackHead( i ), ( long )GetStack( i ) , DumpWait, WaitNumber, DumpStopCondition ) ; } static void ResetJump( VECTOR RunAddress ) { extern void start() ; DisableIRQ; if( RunAddress == NULL ) { dbgcr( "reset" ) ; Sleep( 200 ) ; start() ; } RunAddress() ; } static char* NextParameter( char* Buffer ) { Buffer ++ ; return( ReadOutWhiteSpace( Buffer ) ) ; } static char* ReadOutWhiteSpace( char* Buffer ) { for(; *Buffer != 0 ; Buffer ++ ) { if( *Buffer != ' ' ) { if( *Buffer != '\t' ) { return( Buffer ) ; } } } return( Buffer ) ; } /****************************************************************************** 機能要約 機能 引き数 戻り値 注意 ******************************************************************************/ static char* GetCommandLine( void ) { char Data ; short i = 0 ; static char CommandBuffer[ MAX_COMMAND + 1 ] ; //頭についたコントロールコード等を削除する for(;;) { Data = GetChar() ; PutChar( Data ) ; if( Data > ' ' ) { break ; } } i = 0 ; CommandBuffer[ i ] = ( char )Data ; for( i = 1 ; i < MAX_COMMAND ; ) { Data = GetChar() ; //BS の場合 if( Data == BS ) { if( i > 0 ) { PutChar( BS ) ; PutChar( ' ' ) ; PutChar( BS ) ; i -- ; } continue ; } // CR とか LF の場合 if( Data < ' ' ) { CommandBuffer[ i ] = 0 ; PutChar( Data ) ; strlwr( CommandBuffer ) ; return( CommandBuffer ) ; } //通常のキャラクタの場合 CommandBuffer[ i ] = Data ; PutChar( Data ) ; i ++ ; } return( 0 ) ; } /****************************************************************************** 機能要約 機能 引き数 戻り値 注意 ******************************************************************************/ static void SystemInformation( int MoreInfo ) { static const char* const Abstruct[] = { "start system " , "00" , NULL } ; dbgsbcr( "monitor Task#", GetMyTaskNo() ) ; OutputStrings( Abstruct ) ; }