static void report_nonce_from_uartrx(int com) { int length; u32 nonce; struct TRANS_BUFFER *tb = &uart_trans_buffer[com]; while(trans_buffer_out_length(tb) >= 4) { CLEAR_IRQ_FLAG((1 << com)); get_trans_buffer(tb, (u8*)&nonce, 4); PR_DEBUG("COM%d",com+1); DBG_CMD(">>>",(u8*)&nonce, 4); #if defined(USE_STM3210E_EVAL) if (COM_USART[com] == BTC_COM1 || COM_USART[com] == BTC_COM2) report_btc_nonce(nonce); else if (COM_USART[com] == LTC_COM1 || COM_USART[com] == LTC_COM2) report_ltc_nonce(nonce); #else if (COM_USART[com] == BTC_COM1) report_btc_nonce(nonce); else if (COM_USART[com] == LTC_COM1) report_ltc_nonce(nonce); #endif } if(IS_IRQ_FLAG((1 << com))) { delay_us(CMD_WAIT_TIME); //PR_DEBUG("get btc report data\n"); CLEAR_IRQ_FLAG((1 << com)); length = get_trans_buffer(&uart_trans_buffer[com], (u8*)&nonce, 4); flush_trans_buffer(&uart_trans_buffer[com]); if (length < 4)/* invalid nonce */ return; PR_DEBUG("COM%d",com+1); DBG_CMD(">>>",(u8*)&nonce, 4); #if defined(USE_STM3210E_EVAL) if (COM_USART[com] == BTC_COM1 || COM_USART[com] == BTC_COM2) report_btc_nonce(nonce); else if (COM_USART[com] == LTC_COM1 || COM_USART[com] == LTC_COM2) report_ltc_nonce(nonce); #else if (COM_USART[com] == BTC_COM1) report_btc_nonce(nonce); else if (COM_USART[com] == LTC_COM1) report_ltc_nonce(nonce); #endif //led0_revert(); } }
int get_trans_buffer_cmd(struct TRANS_BUFFER *tb, uint8_t * buffer) { int length = trans_buffer_has_cmd(tb); if (length > 0) get_trans_buffer(tb, buffer, length); return length; }
void dispatch_host_cmd(void) { u32 length; u8 *p = cmd_buffer; struct TRANS_BUFFER *tb = &uart_trans_buffer[COM1]; //struct TRANS_BUFFER *tb = &usb_trans_buffer; //if(com1_frame_count < 10) { // return; //} while (length = get_trans_buffer_cmd(tb,p)) { DBG_CMD("get cmd<<",p,length); com1_frame_count = 0; delay_us(CMD_WAIT_TIME); _dispatch_host_cmd(p, length); } if(com1_frame_count < 5) { return; } if ((trans_buffer_out_length(tb) > 0)) { length = get_trans_buffer(tb, p, CMD_MAX_LENGTH); _dispatch_host_cmd(p, length); //PR_DEBUG("get cmd by delay\n"); } }
void dispatch_host_cmd(void) { u32 length; u8 *p = cmd_buffer; if(IS_IRQ_FLAG(USBOUT_IRQ_FLAG)) { CLEAR_IRQ_FLAG(USBOUT_IRQ_FLAG); FrameCount = 0; //PR_DEBUG("usb out int\n"); } /* when usb out int occurs here, it's huge chance to get incomplete data>64 bytes*/ while (length = get_trans_buffer_cmd(&usb_trans_buffer,p)) { DBG_CMD("get cmd<<",p,length); delay_us(CMD_WAIT_TIME); _dispatch_host_cmd(p, length); } if(IS_IRQ_FLAG(USBOUT_IRQ_FLAG)) return; if ((trans_buffer_out_length(&usb_trans_buffer) > 0)) { delay_ms(5); length = get_trans_buffer(&usb_trans_buffer, p, CMD_MAX_LENGTH); _dispatch_host_cmd(p, length); //PR_DEBUG("get cmd by delay\n"); } }
void report_nonce_to_host(void) { u32 length; u8 * p = report_buffer; u32 nonce; int i; // for (i=0; i<COMn; i++) { // length = get_trans_buffer(&uart_trans_buffer[i], p, REPORT_MAX_LENGTH); // if (length > 0) // trans_buf_to_usb(p, length); // } if(IS_IRQ_FLAG(COM1_IRQ_FLAG)) { delay_us(200); length = get_trans_buffer(&uart_trans_buffer[COM1], p, REPORT_MAX_LENGTH); if (length > 0) trans_buf_to_usb(p, length); CLEAR_IRQ_FLAG(COM1_IRQ_FLAG); } /*btc channel*/ if(IS_IRQ_FLAG(COM2_IRQ_FLAG)) { delay_us(1000); //PR_DEBUG("get btc report data\n"); length = get_trans_buffer(&uart_trans_buffer[COM2], (u8*)&nonce, 4); //PR_DEBUG("len=%d,%08X",length, nonce); if (length == 4) report_btc_nonce(nonce); CLEAR_IRQ_FLAG(COM2_IRQ_FLAG); led0_revert(); } /*ltc channel*/ if(IS_IRQ_FLAG(COM3_IRQ_FLAG)) { delay_us(1000); //PR_DEBUG("get btc report data\n"); length = get_trans_buffer(&uart_trans_buffer[COM3], (u8*)&nonce, 4); if (length == 4) report_ltc_nonce(nonce); CLEAR_IRQ_FLAG(COM3_IRQ_FLAG); led0_revert(); } #if defined(USE_STM3210E_EVAL) /*btc channel*/ if(IS_IRQ_FLAG(COM4_IRQ_FLAG)) { delay_us(1000); length = get_trans_buffer(&uart_trans_buffer[COM4], (u8*)&nonce, 4); if (length == 4) report_btc_nonce(nonce); CLEAR_IRQ_FLAG(COM4_IRQ_FLAG); led0_revert(); } /*ltc channel*/ if(IS_IRQ_FLAG(COM5_IRQ_FLAG)) { delay_us(1000); length = get_trans_buffer(&uart_trans_buffer[COM5], (u8*)&nonce, 4); if (length == 4) report_ltc_nonce(nonce); CLEAR_IRQ_FLAG(COM5_IRQ_FLAG); led0_revert(); } #endif }