/*============================================================================*/ void uart_handshake_init(void) { /* switch to meta port */ mtk_serial_set_current_uart(CFG_UART_META); /* if meta and log ports are SAME, need to re-init meta port with * different baudrate and disable log output during handshake to avoid * influence. */ if (CFG_UART_META == CFG_UART_LOG) { /* to prevent sync error with PC */ gpt_busy_wait_us(160); /* init to meta baudrate */ mtk_uart_init(UART_SRC_CLK_FRQ, CFG_META_BAUDRATE); /* disable log so that log message will be kept in log buffer */ log_buf_ctrl(0); log_ctrl(0); } /* send meta ready to tool via meta port first then let meta port to listen * meta response in the background to reduce the handshake wait time later. */ uart_send((u8*)HSHK_COM_READY, strlen(HSHK_COM_READY)); mtk_serial_set_current_uart(CFG_UART_LOG); g_meta_ready_start_time = get_timer(0); }
void platform_error_handler(void) { /* if log is disabled, re-init log port and enable it */ if (log_status() == 0) { mtk_uart_init(UART_SRC_CLK_FRQ, CFG_LOG_BAUDRATE); log_ctrl(1); } print("%s preloader fatal error...\n", MOD); /* enter emergency download mode */ platform_emergency_download(CFG_EMERGENCY_DL_TIMEOUT_MS); while(1); }
static bool uart_handshake_handler(struct bldr_command_handler *handler) { bool result = TRUE; bool avail; int sync_time; uint8 buf[HSHK_TOKEN_SZ + 1] = {'\0'}; struct bldr_command cmd; struct bldr_comport comport; struct comport_ops uart_ops = {.send = uart_send, .recv = uart_recv}; comport.type = COM_UART; comport.tmo = UART_SYNC_TIME; comport.ops = &uart_ops; sync_time = UART_SYNC_TIME - get_timer(g_meta_ready_start_time); sync_time = sync_time <= 0 ? 5 : sync_time; sync_time = sync_time > UART_SYNC_TIME ? UART_SYNC_TIME : sync_time; /* detect tool existence */ mtk_serial_set_current_uart(CFG_UART_META); avail = uart_listen(&comport, buf, HSHK_TOKEN_SZ, 1, sync_time); mtk_serial_set_current_uart(CFG_UART_LOG); if (!avail) { result = FALSE; goto exit; } cmd.data = buf; cmd.len = HSHK_TOKEN_SZ; result = handler->cb(handler, &cmd, &comport); exit: if (CFG_UART_META == CFG_UART_LOG) { /* enable log message again since no tool is connected */ if (result != TRUE) { /* init to log baudrate */ mtk_uart_init(UART_SRC_CLK_FRQ, CFG_LOG_BAUDRATE); /* enable log and flush the log buffer if log message available */ log_ctrl(1); } } print("\n"); print("%s <UART> wait sync time %dms->%dms\n", MOD, UART_SYNC_TIME, sync_time); print("%s <UART> receieved data: (%s)\n", MOD, buf); return result; }