void spectrum_info(u16 table[256], int verbose) { // dump range // 01234567890123 // XE: xx: xxxxcr static u08 *buf = (u08 *)"XE: xx xxxx\r\n"; static u08 *sep = (u08 *)"XE: xx ----\r\n"; u16 sum = 0; for(u08 i=0;i<255;i++) { sum += table[i]; } if(verbose) { for(u08 i=0;i<255;i++) { // draw range border if((i==B0)||(i==B1)||(i==B2)||(i==B3)) { byte_to_hex(i,sep+4); uart_send_data(sep,14); } // draw non zero values if(table[i] != 0) { byte_to_hex(i,buf+4); word_to_hex(table[i],buf+7); uart_send_data(buf,14); } } } // sort in into ranges u16 total = 0; u16 zero1Count = 0; u16 zero2Count = 0; u16 zero3Count = 0; for(u08 i=B0;i<B1;i++) { zero1Count += table[i]; } for(u08 i=B1;i<B2;i++) { zero2Count += table[i]; } for(u08 i=B2;i<B3;i++) { zero3Count += table[i]; } total = zero1Count + zero2Count + zero3Count; uart_send_string((u08 *)"XS: "); uart_send_hex_word_space(sum); uart_send_hex_word_space(total); uart_send_hex_word_space(zero1Count); uart_send_hex_word_space(zero2Count); uart_send_hex_word_crlf(zero3Count); }
/*---------------------------- Send one byte data to PC Input: dat (UART data) Output:- ----------------------------*/ void uart_send_hex_byte(BYTE dat) { char ch; uart_send_string("BYTE: "); ch = HEX_TABLE[(dat >> 4) & 0x0f]; uart_send_data(ch); ch = HEX_TABLE[dat & 0x0f]; uart_send_data(ch); uart_send_string("\r\n"); }
int main(void) { pin_init(); uart_init(); uart_set_rx_callback(&my_rx_callback); uart_enable(); sei(); while(1) { uart_send_data(ch_cycles, 4*CH_NUM); uart_send_data(ch_rpm, 2*CH_NUM); measure_rpm(); _delay_ms(1000); } }
/** * Displays a hex dump on the debug console (16 bytes per line) * \param pbData Pointer to dump data * \param ulDataLen Length of data dump */ void DumpData(uint8_t* pbData, uint32_t ulDataLen) { uint8_t vl_buf[16]; uint32_t ulIdx = 0; char word[16]; uint8_t i = 0; for(ulIdx = 0; ulIdx < ulDataLen; ++ulIdx) { if(0 == (ulIdx % 16) && ulIdx) { for (i = 0; i < 16; i++) { //uart0_send_data(word[i]); uart_send_data(UART1_BASE_PTR, word[i]); } //uart0_send_string("\r\n"); uart_send_string(UART1_BASE_PTR, "\r\n"); } if (pbData[ulIdx] > 31 && pbData[ulIdx] < 127) { word[ulIdx%16] = pbData[ulIdx]; } else { word[ulIdx%16] = '.'; } snprintf((char*)vl_buf, sizeof(vl_buf), "%02X ", pbData[ulIdx]); //uart0_send_string(vl_buf); uart_send_string(UART1_BASE_PTR, vl_buf); } if ((ulIdx % 16) == 0) ulIdx = 16; else ulIdx = ulIdx % 16; for (i = 0; i < ulIdx; i++) { //uart0_send_data(word[i]); uart_send_data(UART1_BASE_PTR, word[i]); } // uart0_send_string("\r\n"); uart_send_string(UART1_BASE_PTR, "\r\n"); }
void loop(){ if(uart_has_data()) { uart_receive_data(); data++; uart_send_data(); } }
int main(void) { // board setup stuff led_init(); uart_init(); floppy_low_init(); sdpin_init(); spi_low_cs_init(); spi_low_mst_init(); //timer_init(); // say hello uart_send_string((u08 *)"--- dfx-sampler sam7x/SPI ---"); uart_send_crlf(); // do initial setup rtc_init(); memory_init(); floppy_select_on(); track_init(); floppy_select_off(); net_init(); // print current RTC uart_send_string((u08 *)"rtc: "); uart_send_string((u08 *)rtc_get_time_str()); uart_send_crlf(); // show network info net_info(); while(1) { uart_send_string((u08 *)"> "); led_green(1); // get next command via SPI u08 *cmd; u08 len = cmd_uart_get_next(&cmd); led_green(0); if(len>0) { u08 result[CMD_MAX_SIZE]; u08 res_size = CMD_MAX_SIZE; // parse and execute command cmd_parse(len, cmd, &res_size, result); // report result if(res_size > 0) { uart_send_data(result, res_size); uart_send_crlf(); } } } }
/*---------------------------- Send one byte data to PC Input: dat (UART data) Output:- ----------------------------*/ void uart_send_hex_word(WORD dat) { char ch; uart_send_string("WORD: "); ch = HEX_TABLE[(dat >> 12) & 0x0f]; uart_send_data(ch); ch = HEX_TABLE[(dat >> 8) & 0x0f]; uart_send_data(ch); ch = HEX_TABLE[(dat >> 4) & 0x0f]; uart_send_data(ch); ch = HEX_TABLE[(dat >> 0) & 0x0f]; uart_send_data(ch); uart_send_string("\r\n"); }
int make_ack_uart_send_data(u8* _buf) { u16 cnt=0; make_ack_head( _buf, PROTOCOL_ACK_UART_SEND_DATA); _buf[4]=get_com_attr.id +1; if (get_com_attr.id >=MAX_COM_PORT ||g_uart_send_cnt ==0 ||g_uart_send_cnt>0x800){ _buf[5]=0; _buf[6]=0; }else{ cnt=uart_send_data(buf); _buf[5]=cnt/0x100; _buf[6]=cnt%0x100; } _buf[7]=make_crc_num(_buf, 7); return 7+1; }
/*---------------------------- send string to UART ----------------------------*/ void uart_send_string(char *string) { while(*string) { uart_send_data(*string); string++; } }
void TCC_HANDLER(TCC_PORT_B) { uart_send_data(&port_b); // clear irq tcc(TCC_PORT_B)->INTFLAG.reg = TCC_INTENSET_OVF; }
ide_dbg_status_t ide_dbg_ack_data(machine_uart_obj_t* uart) { uint32_t length = 0; ack_start: length = xfer_length - xfer_bytes; length = (length>IDE_DBG_MAX_PACKET) ? IDE_DBG_MAX_PACKET : length; if(length == 0) { if(cmd == USBDBG_NONE) is_busy_sending = false; return IDE_DBG_STATUS_OK; } switch (cmd) { case USBDBG_FW_VERSION: { ((uint32_t*)ide_dbg_cmd_buf)[0] = MICROPY_VERSION_MAJOR; ((uint32_t*)ide_dbg_cmd_buf)[1] = MICROPY_VERSION_MINOR; ((uint32_t*)ide_dbg_cmd_buf)[2] = MICROPY_VERSION_MICRO; cmd = USBDBG_NONE; break; } case USBDBG_TX_BUF_LEN: { *((uint32_t*)ide_dbg_cmd_buf) = Buffer_Size(&g_uart_send_buf_ide); cmd = USBDBG_NONE; break; } case USBDBG_TX_BUF: { Buffer_Gets(&g_uart_send_buf_ide, ide_dbg_cmd_buf, length); if (xfer_bytes+ length == xfer_length) { cmd = USBDBG_NONE; } break; } case USBDBG_FRAME_SIZE: { // Return 0 if FB is locked or not ready. ((uint32_t*)ide_dbg_cmd_buf)[0] = 0; // Try to lock FB. If header size == 0 frame is not ready if (mutex_try_lock(&(JPEG_FB()->lock), MUTEX_TID_IDE)) { // If header size == 0 frame is not ready if (JPEG_FB()->size == 0) { // unlock FB mutex_unlock(&(JPEG_FB()->lock), MUTEX_TID_IDE); } else { // Return header w, h and size/bpp ((uint32_t*)ide_dbg_cmd_buf)[0] = JPEG_FB()->w; ((uint32_t*)ide_dbg_cmd_buf)[1] = JPEG_FB()->h; ((uint32_t*)ide_dbg_cmd_buf)[2] = JPEG_FB()->size; } } } cmd = USBDBG_NONE; break; case USBDBG_FRAME_DUMP: if (xfer_bytes < xfer_length) { if(MICROPY_UARTHS_DEVICE == uart->uart_num) { temp_size = uarths_send_data(JPEG_FB()->pixels, xfer_length); } else if(UART_DEVICE_MAX > uart->uart_num) { // uart_configure(uart->uart_num, (size_t)uart->baudrate, (size_t)uart->bitwidth, uart->stop, uart->parity); temp_size= uart_send_data(uart->uart_num, JPEG_FB()->pixels, xfer_length); } cmd = USBDBG_NONE; xfer_bytes = xfer_length; JPEG_FB()->w = 0; JPEG_FB()->h = 0; JPEG_FB()->size = 0; mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE); } break; case USBDBG_ARCH_STR: { snprintf((char *) ide_dbg_cmd_buf, IDE_DBG_MAX_PACKET, "%s [%s:%08X%08X%08X]", OMV_ARCH_STR, OMV_BOARD_TYPE,0,0,0);//TODO: UID cmd = USBDBG_NONE; break; } case USBDBG_SCRIPT_RUNNING: { *((uint32_t*)ide_dbg_cmd_buf) = script_running?1:0; cmd = USBDBG_NONE; break; } case USBDBG_FILE_SAVE_STATUS: { *((uint32_t*)ide_dbg_cmd_buf) = ide_file_save_status; cmd = USBDBG_NONE; break; } default: /* error */ break; } if(length && !is_sending_jpeg) { if(MICROPY_UARTHS_DEVICE == uart->uart_num) { temp_size = uarths_send_data(ide_dbg_cmd_buf, length); } else if(UART_DEVICE_MAX > uart->uart_num) temp_size= uart_send_data(uart->uart_num, ide_dbg_cmd_buf, length); xfer_bytes += length; if( xfer_bytes < xfer_length ) goto ack_start; } if(cmd == USBDBG_NONE) { is_sending_jpeg = false; is_busy_sending = false; } }