RET_CODE sn_client_process(void) { u32 ret = 0, i = 0; u8 ch = 0; u16 code = 0xFFFF; u8 hkey = 0xFF; void * p_dev = dev_find_identifier(NULL, DEV_IDT_TYPE, SYS_DEV_TYPE_UIO); dm_read(class_get_handle_by_id(DM_CLASS_ID), FPKEY_BLOCK_ID, 0, 5, sizeof(u8), &hkey); uart_flush(0); OS_PRINTF(SN_CLIRNT_SIG); for(i = 0; i < SN_TIMEOUT; i++) { uio_get_code(p_dev, &code); if(hkey != 0xFF) { if((code & 0x100) && (hkey == (code & 0xFF))) { jump_to_usbupgrade(); return ERR_FAILURE; } } ret = uart_read_byte(0, &ch, 100); if((ret == 0) && (ch == SN_CLIRNT_RES)) { return SUCCESS; } } return ERR_FAILURE; }
int kb_input() { int i, timeout; if (!uart_poll()) return 0; int c = uart_read_byte(); if (c == ESC_CHAR) { c = kb_expect(); if (c < 0) return ESC_CHAR; if (c != '[') { return 0; } c = kb_expect(); if (c < 0) return 0; return (c & 0xff) | 0x1b00; } return c; }
int wrc_ptp_set_mode(int mode) { uint32_t start_tics, lock_timeout = 0; ptp_mode = 0; wrc_ptp_stop(); switch (mode) { case WRC_MODE_GM: rtOpts.primarySource = TRUE; rtOpts.wrConfig = WR_M_ONLY; rtOpts.masterOnly = TRUE; spll_init(SPLL_MODE_GRAND_MASTER, 0, 1); lock_timeout = LOCK_TIMEOUT_GM; break; case WRC_MODE_MASTER: rtOpts.primarySource = FALSE; rtOpts.wrConfig = WR_M_ONLY; rtOpts.masterOnly = TRUE; spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1); lock_timeout = LOCK_TIMEOUT_FM; break; case WRC_MODE_SLAVE: rtOpts.primarySource = FALSE; rtOpts.wrConfig = WR_S_ONLY; rtOpts.masterOnly = FALSE; spll_init(SPLL_MODE_SLAVE, 0, 1); break; } initDataClock(&rtOpts, &ptpClockDS); start_tics = timer_get_tics(); mprintf("Locking PLL"); shw_pps_gen_enable_output(0); while (!spll_check_lock(0) && lock_timeout) { timer_delay_ms(1000); mprintf("."); if (time_after(timer_get_tics(), start_tics + lock_timeout)) { mprintf("\nLock timeout.\n"); return -ETIMEDOUT; } else if (uart_read_byte() == 27) { mprintf("\n"); return -EINTR; } } mprintf("\n"); if (mode == WRC_MODE_MASTER || mode == WRC_MODE_GM) shw_pps_gen_enable_output(1); ptp_mode = mode; return 0; }
int kb_expect() { int timeout; for (timeout = ESC_TIMEOUT; timeout > 0; timeout--) if (uart_poll()) return uart_read_byte(); return -1; }
/** * @function: uart_read * @param: Maximum length of data to be read. * @param: Local data buffer to be written to. * @return: Amount of data actually read. * @brief: Reads a chunk of data from the UART * interface. */ size_t uart_read(size_t max_length, uint8_t* data) { size_t i = 0; for(; i < max_length; i++) { if((data[i] = uart_read_byte()) == '\0') { break; } } if(data[i] != '\0') { data[i] = '\0'; } return i; }
BOOL ap_satcodx_recv_read_uart( satcodx_impl_data_t *p_satcodx_impl_data, u8 *p_ch, u32 time_out) { #ifdef SATCODX_DEBUG u32 cur_timestamp = mtos_ticks_get(); if(last_timestamp == 0) { last_timestamp = cur_timestamp; max_interval = 0; } else { if((cur_timestamp - last_timestamp) > max_interval) { max_interval = cur_timestamp - last_timestamp; } } #endif #if WIN32 if(uartwin_read_byte(p_ch,time_out) != 0) { return FALSE; } else { return TRUE; } #else if(uart_read_byte(UART_ID_0,p_ch, time_out) != 0) { return FALSE; } else { return TRUE; } #endif }
static int octeon_serial_getc(void) { return uart_read_byte(gd->arch.console_uart); }