void CPU_InitializeCommunication() { NATIVE_PROFILE_PAL_COM(); // STDIO can be different from the Debug Text port // do these first so we can print out messages if(COM_IsSerial(HalSystemConfig.DebugTextPort)) { USART_Initialize( ConvertCOM_ComPort(HalSystemConfig.DebugTextPort), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); } if(COM_IsSerial(HalSystemConfig.stdio)) { USART_Initialize( ConvertCOM_ComPort(HalSystemConfig.stdio), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); } if(COM_IsUsb(HalSystemConfig.DebugTextPort)) { USB_Configure( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort), NULL ); USB_Initialize( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort) ); USB_OpenStream( ConvertCOM_UsbStream(HalSystemConfig.DebugTextPort), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ ); } Network_Initialize(); }
void __section("SectionForFlashOperations") Native_Profiler_WriteToCOM(void *buffer, UINT32 size) { UINT64 time1, time2; time1 = Native_Profiler_TimeInMicroseconds(); USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); // disable watchdog Watchdog_GetSetEnabled( FALSE, TRUE ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string char *offset = (char *) buffer; do { UINT32 bytes_written = USART_Write(ConvertCOM_ComPort(USART_DEFAULT_PORT), offset, size); offset += bytes_written; size -= bytes_written; } while(size); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); Watchdog_GetSetEnabled( TRUE, TRUE ); time2 = Native_Profiler_TimeInMicroseconds(); s_native_profiler.initTime += (time2 - time1); }
void __section("SectionForFlashOperations") Native_Profiler_Dump() { lcd_printf("Buffer is full. Dumping...\r\n"); UINT64 time1, time2; time1 = Native_Profiler_TimeInMicroseconds(); USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); // clear_watchdog // if we do not disable the watchdog, it can be called while we dump data Watchdog_GetSetEnabled( FALSE, TRUE ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string char *offset = (char *)&ProfilerBufferBegin; UINT32 size = (char *)s_native_profiler.position - (char *)&ProfilerBufferBegin; do { UINT32 bytes_written = USART_Write(ConvertCOM_ComPort(USART_DEFAULT_PORT), offset, size); offset += bytes_written; size -= bytes_written; } while(size); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); Watchdog_GetSetEnabled( TRUE, TRUE ); time2 = Native_Profiler_TimeInMicroseconds(); s_native_profiler.initTime += (time2 - time1); s_native_profiler.position = &ProfilerBufferBegin; *s_native_profiler.position++ = NATIVE_PROFILER_START_TAG; *s_native_profiler.position++ = s_native_profiler.engineTimeOffset; s_native_profiler.writtenData = FALSE; }
void CPU_UninitializeCommunication() { NATIVE_PROFILE_PAL_COM(); // STDIO can be different from the Debug Text port // do these first so we can print out messages if(COM_IsSerial(HalSystemConfig.DebugTextPort)) { USART_Uninitialize( ConvertCOM_ComPort(HalSystemConfig.DebugTextPort) ); } if(COM_IsSerial(HalSystemConfig.stdio)) { USART_Uninitialize( ConvertCOM_ComPort(HalSystemConfig.stdio) ); } // if USB is not defined, the STUB_USB will be set // Do not uninitialize the USB on soft reboot if USB is our debugger link // Close all streams on USB controller 0 except debugger (if it uses a USB stream) for( int stream = 0; stream < USB_MAX_QUEUES; stream++ ) { if(!COM_IsUsb(HalSystemConfig.DebuggerPorts[0]) || (ConvertCOM_UsbStream(HalSystemConfig.DebugTextPort) != stream)) { USB_CloseStream(stream); // OK for unopen streams } } USB_Uninitialize(0); // USB_Uninitialize will only stop USB controller 0 if it has no open streams Network_Uninitialize(); }
STREAM_DRIVER_DETAILS* COM2_driver_details( UINT32 handle ) { static STREAM_DRIVER_DETAILS details = { DRIVER_BUFFERED_IO, &RxBuffer_Com[ RX_USART_BUFFER_SIZE * ConvertCOM_ComPort( COM2 ) ], &TxBuffer_Com[ TX_USART_BUFFER_SIZE * ConvertCOM_ComPort( COM2 ) ], RX_USART_BUFFER_SIZE, TX_USART_BUFFER_SIZE, TRUE, TRUE, FALSE }; return &details; }
void StartApplication( void (*StartAddress)() ) { PortBooterLoadProgram((void**)&StartAddress); hal_printf( "Starting main application at 0x%08x\r\n", (size_t)StartAddress ); LCD_Clear(); USART_Flush( ConvertCOM_ComPort(g_State.UsartPort) ); if(g_State.UsingUsb) { USB_Flush( ConvertCOM_UsbStream( g_State.UsbPort ) ); USB_CloseStream( ConvertCOM_UsbStream(g_State.UsbPort) ); USB_Uninitialize( ConvertCOM_UsbController(g_State.UsbPort) ); //disable the USB for the next application } DISABLE_INTERRUPTS(); LCD_Uninitialize(); CPU_DisableCaches(); (*StartAddress)(); }
void monitor_debug_printf( const char* format, ... ) { char buffer[256]; va_list arg_ptr; va_start( arg_ptr, format ); int len = hal_vsnprintf( buffer, sizeof(buffer)-1, format, arg_ptr ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string USART_Write( ConvertCOM_ComPort(USART_DEFAULT_PORT), buffer, len ); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); va_end( arg_ptr ); }
BOOL DebuggerPort_Flush( COM_HANDLE ComPortNum ) { NATIVE_PROFILE_PAL_COM(); switch(ExtractTransport(ComPortNum)) { case USART_TRANSPORT: return USART_Flush( ConvertCOM_ComPort( ComPortNum ) ); case USB_TRANSPORT: return USB_Flush( ConvertCOM_UsbStream(ComPortNum) ); case SOCKET_TRANSPORT: return SOCKETS_Flush( ConvertCOM_SockPort(ComPortNum) ); } return FALSE; }
BOOL DebuggerPort_Uninitialize( COM_HANDLE ComPortNum ) { NATIVE_PROFILE_PAL_COM(); switch(ExtractTransport(ComPortNum)) { case USART_TRANSPORT: return USART_Uninitialize( ConvertCOM_ComPort(ComPortNum) ); case USB_TRANSPORT: USB_CloseStream( ConvertCOM_UsbStream(ComPortNum) ); return USB_Uninitialize( ConvertCOM_UsbController(ComPortNum) ); case SOCKET_TRANSPORT: return SOCKETS_Uninitialize(ConvertCOM_SockPort(ComPortNum)); } return FALSE; }
void CPU_ProtectCommunicationGPIOs( BOOL On ) { NATIVE_PROFILE_PAL_COM(); switch(ExtractTransport(HalSystemConfig.DebugTextPort)) { case USART_TRANSPORT: CPU_USART_ProtectPins( ConvertCOM_ComPort(HalSystemConfig.DebugTextPort), On ); return ; case USB_TRANSPORT: CPU_USB_ProtectPins ( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort), On ); return; default: return; } }
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size ) { NATIVE_PROFILE_PAL_COM(); UINT32 transport = ExtractTransport(ComPortNum); const char* dataTmp = Data; INT32 totWrite = 0; int retries = 100; while(size > 0 && retries--) { int ret = 0; switch(transport) { case USART_TRANSPORT: ret = USART_Write( ConvertCOM_ComPort( ComPortNum ), dataTmp, size ); break; case USB_TRANSPORT: ret = USB_Write( ConvertCOM_UsbStream( ComPortNum ), dataTmp, size ); break; case SOCKET_TRANSPORT: ret = SOCKETS_Write( ConvertCOM_SockPort(ComPortNum), dataTmp, size ); break; } if(ret < 0) { break; } else if(ret == 0) { // if interrupts are off and our buffer is full then there is nothing we can do if(!INTERRUPTS_ENABLED_STATE()) break; Events_WaitForEvents(0, 1); } else { retries = 50; // reset retries size -= ret; dataTmp += ret; totWrite += ret; } } return totWrite; }
BOOL DebuggerPort_Initialize( COM_HANDLE ComPortNum ) { NATIVE_PROFILE_PAL_COM(); switch(ExtractTransport(ComPortNum)) { case USART_TRANSPORT: return USART_Initialize( ConvertCOM_ComPort(ComPortNum), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); case USB_TRANSPORT: if(USB_CONFIG_ERR_OK != USB_Configure( ConvertCOM_UsbController(ComPortNum), NULL )) return FALSE; if(!USB_Initialize( ConvertCOM_UsbController(ComPortNum) )) return FALSE; return USB_OpenStream( ConvertCOM_UsbStream(ComPortNum), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ ); case SOCKET_TRANSPORT: return SOCKETS_Initialize(ConvertCOM_SockPort(ComPortNum)); } return FALSE; }
void FAULT_HandlerDisplay( UINT32 *registers, UINT32 exception ) { int i; USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), USART_DEFAULT_BAUDRATE, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); if (exception) { monitor_debug_printf("EXCEPTION 0x%02x:\r\n", exception); } else { monitor_debug_printf("ERROR:\r\n"); } monitor_debug_printf(" cpsr=0x%08x\r\n", registers[15]); monitor_debug_printf(" pc =0x%08x\r\n", registers[14]); monitor_debug_printf(" lr =0x%08x\r\n", registers[13]); monitor_debug_printf(" sp =0x%08x\r\n", registers + 16); for(i = 0; i <= 12; i++) { monitor_debug_printf(" r%02d =0x%08x\r\n", i, registers[i]); } }
int DebuggerPort_Read( COM_HANDLE ComPortNum, char* Data, size_t size ) { NATIVE_PROFILE_PAL_COM(); int ret = 0; switch(ExtractTransport(ComPortNum)) { case USART_TRANSPORT: ret = USART_Read( ConvertCOM_ComPort( ComPortNum ), Data, size ); break; case USB_TRANSPORT: ret = USB_Read( ConvertCOM_UsbStream( ComPortNum ), Data, size ); break; case SOCKET_TRANSPORT: ret = SOCKETS_Read( ConvertCOM_SockPort(ComPortNum), Data, size ); break; } return ret; }
void ABORT_HandlerDisplay( UINT32 *registers_const, UINT32 sp, UINT32 lr, UINT32 pc_offset, const char *Title, BOOL SerialOutput ) { UINT32 cpsr; UINT32 pc; int i; int j; #if !defined(PLATFORM_ARM_OS_PORT) UINT8* stackbytes; const UINT32* const stackwords = (UINT32 *)sp; #endif int page; UINT32* registers; #if defined(PLATFORM_ARM_MC9328) UINT32 URXDn_X; MC9328MXL_USART& USART = MC9328MXL::USART( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); #else // TODO ??? #endif ++ABORT_recursion_counter; dump_again: page = 0; registers = registers_const; cpsr = *registers++; pc = (*registers++) - pc_offset; if(SerialOutput) { // unprotect the GPIO pins for USART, allowing USART output USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), USART_DEFAULT_BAUDRATE, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); monitor_debug_printf("ERROR: %s\r\n", Title); monitor_debug_printf(" cpsr=0x%08x\r\n", cpsr); monitor_debug_printf(" pc =0x%08x\r\n", pc); monitor_debug_printf(" lr =0x%08x\r\n", lr); for(i = 0; i <= 12; i++) { monitor_debug_printf(" r%d=0x%08x\r\n", i, registers[i]); } monitor_debug_printf(" sp =0x%08x\r\n", sp); RegisterDump(); } // don't let the screen go away if the watchdog was enabled. Watchdog_Disable(); //Flash_ChipReadOnly(TRUE); // first dump stuff to the com port, then go interactive with the buttons and LCD if(SerialOutput) { monitor_debug_printf("ERROR: %s\r\n", Title); monitor_debug_printf(" cpsr=0x%08x\r\n", cpsr); monitor_debug_printf(" pc =0x%08x\r\n", pc); monitor_debug_printf(" lr =0x%08x\r\n", lr); for(i = 0; i <= 12; i++) { monitor_debug_printf(" r%d=0x%08x\r\n", i, registers[i]); } monitor_debug_printf(" sp =0x%08x\r\n", sp); #if !defined(PLATFORM_ARM_OS_PORT) stackbytes = (UINT8 *)sp; for(i = 0; i < 16; i++) { monitor_debug_printf("[0x%08x] :", (UINT32)&stackbytes[i*16]); for(j = 0; j < 16; j++) { // don't cause a data abort here! if((UINT32) &stackbytes[i*16 + j] < (UINT32) &StackTop) { monitor_debug_printf(" %02x", stackbytes[i*16 + j]); } else { monitor_debug_printf(" "); } } monitor_debug_printf(" "); for(j = 0; j < 16; j++) { if((UINT32) &stackbytes[i*16 + j] < (UINT32) &StackTop) { monitor_debug_printf("%c", (stackbytes[i*16 + j] >= ' ') ? stackbytes[i*16 + j] : '.'); } } monitor_debug_printf("\r\n"); } #endif } //--// // make sure USART is ready to go (clock enabled, pins set active) regardless of charger state, idem potent call if it was already on CPU_ProtectCommunicationGPIOs( FALSE ); #if defined(PLATFORM_ARM_MC9328) while(USART.URXDn_X[0] & MC9328MXL_USART::URXDn__CHARRDY); #else // TODO ??? #endif //--// // go interactive with the buttons and LCD while(true) { UINT32 CurrentButtonsState; lcd_printf("\f"); switch(page) { case 0: lcd_printf("%-12s \r\n\r\n", Title); lcd_printf("Build Date:\r\n"); lcd_printf("%-12s \r\n" , __DATE__); lcd_printf("%-12s \r\n" , __TIME__); lcd_printf("\r\n"); lcd_printf("cps=0x%08x\r\n", cpsr); lcd_printf("pc =0x%08x\r\n", pc); lcd_printf("lr =0x%08x\r\n", lr); lcd_printf("sp =0x%08x\r\n", sp); break; case 1: lcd_printf("Registers 1\r\n\r\n"); for(i = 0; i < 10; i++) { lcd_printf("r%1d =0x%08x\r\n", i, registers[i]); } break; case 2: lcd_printf("Registers 2\r\n\r\n"); for(i = 10; i < 13; i++) { lcd_printf("r%2d=0x%08x\r\n", i, registers[i]); } break; case 3: default: { #if !defined(PLATFORM_ARM_OS_PORT) UINT32 index = (page-3)*10; lcd_printf("Stack %08x\r\n\r\n", (UINT32)&stackwords[index]); for(i = 0; i < 10; i++) { stackbytes = (UINT8 *)&stackwords[index+i]; // don't cause a data abort displaying past the end of the stack! if((UINT32) &stackwords[index+i] < (UINT32) &StackTop) { lcd_printf("%08x %c%c%c%c\r\n", stackwords[index+i], (stackbytes[0] >= ' ') ? stackbytes[0] : '.', (stackbytes[1] >= ' ') ? stackbytes[1] : '.', (stackbytes[2] >= ' ') ? stackbytes[2] : '.', (stackbytes[3] >= ' ') ? stackbytes[3] : '.' ); } else { lcd_printf(" \r\n"); } } #endif } break; } // wait for a button press while(0 == (CurrentButtonsState = Buttons_CurrentHWState())) { #if defined(PLATFORM_ARM_MC9328) if(USART.URXDn_X[0] & MC9328MXL_USART::URXDn__CHARRDY) { goto StartMonitorMode; } #else // TODO ??? #endif } // wait for 10 mSec HAL_Time_Sleep_MicroSeconds(10000/64); // wait for it to release while(0 == (CurrentButtonsState ^ Buttons_CurrentHWState())); // wait for 10 mSec HAL_Time_Sleep_MicroSeconds(10000/64); if(CurrentButtonsState & BUTTON_B5) { page = (page + 1); // no limit of stack pages LCD_Clear(); } if(CurrentButtonsState & BUTTON_B2) { page = (page > 0) ? page - 1 : 0; LCD_Clear(); } if((CurrentButtonsState & BUTTON_B4) || (CurrentButtonsState & BUTTON_B0)) { goto dump_again; } continue; #if defined(PLATFORM_ARM_MC9328) StartMonitorMode: #endif { char data[16]; UINT32 pos = 0; LCD_Clear(); lcd_printf("\fMONITOR MODE\r\n"); HAL_Time_Sleep_MicroSeconds(10000); while(1) { #if defined(PLATFORM_ARM_MC9328) URXDn_X = USART.URXDn_X[0]; if(URXDn_X & MC9328MXL_USART::URXDn__CHARRDY) { data[pos++] = (char)(URXDn_X & MC9328MXL_USART::URXDn__DATA_mask); #else if(false) { // TODO ??? #endif switch(data[0]) { case 'L': monitor_debug_printf("rb=0x%08x\r\n", HalSystemConfig.RAM1.Base ); monitor_debug_printf("rs=0x%08x\r\n", HalSystemConfig.RAM1.Size ); monitor_debug_printf("fb=0x%08x\r\n", HalSystemConfig.FLASH.Base); monitor_debug_printf("fs=0x%08x\r\n", HalSystemConfig.FLASH.Size); break; case 'M': if(pos < 12) continue; { UINT8* start = *(UINT8**)&data[4]; UINT8* end = *(UINT8**)&data[8]; lcd_printf( "\f\r\n\r\nREAD:\r\n %08x\r\n %08x", (UINT32)start, (UINT32)end ); if(AbortHandler_CheckMemoryRange( start, end )) { while(start < end) { monitor_debug_printf("[0x%08x]", (UINT32)start); for(j = 0; j < 128; j++) { monitor_debug_printf("%02x", *start++); if(start == end) break; } monitor_debug_printf("\r\n"); } } else { monitor_debug_printf("ERROR: invalid range: %08x-%08x\r\n", (UINT32)start, (UINT32)end ); } } break; case 'R': for(i = 0; i <= 12; i++) { monitor_debug_printf("r%d=%08x\r\n", i, registers[i]); } monitor_debug_printf("sp=%08x\r\n", sp); monitor_debug_printf("lr=%08x\r\n", lr); monitor_debug_printf("pc=%08x\r\n", pc); monitor_debug_printf("cpsr=%08x\r\n", cpsr); #if defined(PLATFORM_ARM_MC9328) monitor_debug_printf("BWA=%08x\r\n", 0); monitor_debug_printf("BWC=%08x\r\n", 0); #else // TODO ??? #endif break; case '\r': case '\n': case ' ': break; default: monitor_debug_printf("ERROR: unknown command %c\r\n", data[0] ); break; } pos = 0; } else if(Buttons_CurrentHWState()) { // wait for it to release while (Buttons_CurrentHWState()); LCD_Clear(); break; } } } } } #endif // !defined(ABORTS_REDUCESIZE) extern "C" { void UNDEF_Handler( UINT32* registers, UINT32 sp, UINT32 lr ) { ASSERT_IRQ_MUST_BE_OFF(); #if !defined(ABORTS_REDUCESIZE) Verify_RAMConstants((void *) FALSE); ABORT_HandlerDisplay(registers, sp, lr, 4, "Undef Instr", TRUE); CPU_Halt(); #else CPU_Reset(); #endif // !defined(ABORTS_REDUCESIZE) }
int COM2_write( char* buffer, size_t size ) { return USART_Write( ConvertCOM_ComPort( COM2 ), buffer, size ); }
int COM2_read( char* buffer, size_t size ) { return USART_Read( ConvertCOM_ComPort( COM2 ), buffer, size ); }