// ============================================================================= // boot_MonitorDoMonitoring // ----------------------------------------------------------------------------- /// This function actually implement the monitoring operations. // ============================================================================= PROTECTED VOID boot_MonitorDoMonitoring(VOID) { BOOT_HOST_USB_MONITOR_CTX_T hostUsbContext; BOOT_MONITOR_OP_STATUS_T monitorLoopStatus = BOOT_MONITOR_OP_STATUS_NONE; hostUsbContext.MonitorMode = BOOT_HOST_USB_MODE_BOOT; // Get current time to calculate time-out exit UINT32 enterTime = hwp_timer->HWTimer_CurVal; // Configure the IOMux to let the PXTS exit. #ifdef BOOT_WITH_IOMUX_PROFILE hwp_debugPort->Debug_Port_Mode |= DEBUG_PORT_PXTS_EXL_CLOCK_POL | DEBUG_PORT_MODE_CONFIG_MODE_PXTS; hwp_debugPort->Pxts_Exl_Cfg |= DEBUG_PORT_ENABLE_PXTS_TAG(1<<HAL_DBG_PXTS_BOOT); hwp_configRegs->Alt_mux_select &= ~CFG_REGS_DEBUG_PORT_MASK; #endif // BOOT_WITH_IOMUX_PROFILE BOOT_PROFILE_PULSE(BOOT_POWER_STATE_DONE); // Initializes the uart baudrate detection variables. g_bootUartMonitorBrDetected = FALSE; g_bootUartMonitorBaudRate = 0; // We enter the monitor if access is forced through // boot mode or there is no code on CS0. if ((g_bootBootMode & BOOT_MODE_FORCE_MONITOR) || *(BOOT_FLASH_PROGRAMMED_PATTERN_ADDRESS) != BOOT_FLASH_PROGRAMMED_PATTERN) { BOOT_PROFILE_PULSE(BOOT_ENTER_MONITOR_LOOP); // If we are out of reset, set the status to 'waiting for a command'. // Otherwise, keep the status as it was probably set by the boot sector // and carries a specific meaning. if (hwp_debugHost->p2h_status == BOOT_HST_STATUS_NONE) { hwp_debugHost->p2h_status = BOOT_HST_STATUS_WAITING_FOR_COMMAND; } // Open the UART monitor, only when the boot mode requires it. if (g_bootBootMode & BOOT_MODE_UART_MONITOR_ENABLE) { boot_UartMonitorOpen(); } // Open the USB monitor, except when to boot mode prevents it. if (!(g_bootBootMode & BOOT_MODE_USB_MONITOR_DISABLE)) { boot_UsbInitVar(); boot_HostUsbClockEnable(); boot_UsbOpen(boot_HostUsbDeviceCallback); // We never exit this function, so the hostUsbContext // is valid (On the stack). boot_HostUsbOpen(&hostUsbContext, 0, 0); } while (1) { // We are in the monitor. We are indefinitely trying to // execute command from any (available) monitor. This // is done through a dedicated function per monitor // (boot_HstMonitor for the host monitor, // boot_UartMonitor for the uart monitor, // boot_HostUsbRecv for the USB monitor.) // When any of them receive a "Exit the monitor" // BOOT_HST_MONITOR_END_CMD command, it // returns BOOT_MONITOR_OP_STATUS_EXIT, and we check that to leave the // monitor loop. monitorLoopStatus = BOOT_MONITOR_OP_STATUS_NONE; // Host monitor always enabled. monitorLoopStatus |= boot_HstMonitor(); // Process the UART monitor, only when to boot mode requires it. if (g_bootBootMode & BOOT_MODE_UART_MONITOR_ENABLE) { monitorLoopStatus |= boot_UartMonitor(); } // Process the USB monitor, except when to boot mode prevents it. if (!(g_bootBootMode & BOOT_MODE_USB_MONITOR_DISABLE)) { // Receive a USB packet, parse it and execute // the command if any. // Return BOOT_MONITOR_OP_STATUS_EXIT if the exit monitor command is received. monitorLoopStatus |= boot_HostUsbRecv(); // If a read command was received, send a packet // with the read data. boot_HostUsbSend(); } // Check the status returned by the monitors. if (monitorLoopStatus & BOOT_MONITOR_OP_STATUS_EXIT) { // Exit the monitoring loop break; } // Check we received a command, and update the timeout // FIXME Fixe here to implement the behaviour about the timeout // (No command or after the command) if (monitorLoopStatus & BOOT_MONITOR_OP_STATUS_CONTINUE) { // Update the timeout or set a variable bypassing the // timeout stuff. enterTime = hwp_timer->HWTimer_CurVal; } if (monitorLoopStatus == BOOT_MONITOR_OP_STATUS_NONE) { // No command received. // Exit the loop if valid flash and timeout. if ((*(BOOT_FLASH_PROGRAMMED_PATTERN_ADDRESS) == BOOT_FLASH_PROGRAMMED_PATTERN) && ((hwp_timer->HWTimer_CurVal - enterTime) > (BOOT_IDLE_TIMEOUT*16384))) { // If no command was sent, we have to tell we're not ready // anymore to handle new commands. hwp_debugHost->p2h_status = BOOT_HST_STATUS_NONE; break; } } } // Close the UART monitor, only when the boot mode requires it. if (g_bootBootMode & BOOT_MODE_UART_MONITOR_ENABLE) { boot_UartMonitorClose(); } // Close the USB monitor, except when to boot mode prevents it. if (!(g_bootBootMode & BOOT_MODE_USB_MONITOR_DISABLE)) { boot_HostUsbClose(); boot_UsbClose(); } } }
PUBLIC UINT8 hal_HostUsbRecv(VOID) { return boot_HostUsbSend(); }