int main(int argc, char *argv[]) { char uart_port[8]; unsigned i; bglib_output = output; for (i=0; i<100; ++i){ sprintf(uart_port, "COM%d", i); if (!uart_open(uart_port)) break; } // Reset dongle to get it into known state ble_cmd_system_reset(0); uart_close(); do { Sleep(500); // 0.5s } while (uart_open(uart_port)); // Execute action ble_cmd_gap_discover(gap_discover_observation); // Message loop while (state != state_finish) { if (read_message(UART_TIMEOUT) > 0) break; } uart_close(); return 0; }
ER GPSRec_Open(UART_BAUDRATE BaudRate) { if (bGPSRecOpened) return E_SYS; #if (RECEIVE_FROM_UART2) if (uart2_open() == E_OK) #else if (uart_open() == E_OK) #endif { debug_msg("\r\nUART2: Open success\r\n"); #if (RECEIVE_FROM_UART2) uart2_init(BaudRate, UART_LEN_L8_S1, UART_PARITY_NONE); #else uart_init(BaudRate, UART_LEN_L8_S1, UART_PARITY_NONE); #endif } else { debug_err(("UART2: open fail!\r\n")); return E_SYS; } debug_msg("Start GPS receive task\r\n"); sta_tsk(GPSRECEIVE_ID,0); loc_cpu(); bGPSRecOpened = TRUE; unl_cpu(); return E_OK; }
void log_init(void) { output_buffer = heap_alloc(BUFF_LEN); output_mutex = mutex_create(); uart_init(UART_PORT, NULL, 0); uart_open(UART_PORT, UART_BAUDRATE, 0); }
void ui_usb_enum_event(uhc_device_t *dev, uhc_enum_status_t status) { ui_enum_status = status; switch (dev->speed) { case UHD_SPEED_HIGH: ui_device_speed_blink = 250; break; case UHD_SPEED_FULL: ui_device_speed_blink = 500; break; case UHD_SPEED_LOW: default: ui_device_speed_blink = 1000; break; } if (ui_enum_status == UHC_ENUM_SUCCESS) { // USB Device CDC connected // Open and configure UART and USB CDC ports usb_cdc_line_coding_t cfg = { .dwDTERate = CPU_TO_LE32(115200), .bCharFormat = CDC_STOP_BITS_1, .bParityType = CDC_PAR_NONE, .bDataBits = 8, }; uart_open(); uart_config(&cfg); uhi_cdc_open(0, &cfg); } }
/*********************************************************************** * * Function: term_init * * Purpose: Initialize terminal I/O interface * * Processing: * Use the UART driver to open and initialize the serial port * session. * * Parameters: None * * Outputs: None * * Returns: Nothing * * Notes: None * **********************************************************************/ void term_init(void) { UART_CBS_T cbs; UART_CONTROL_T ucntl; UART_REGS_T *puartregs = UART5; /* Setup UART */ uartdev = uart_open((void *) puartregs, 0); if (uartdev != 0) { /* 115.2K, 8 data bits, no parity, 1 stop bit */ ucntl.baud_rate = 115200; ucntl.parity = UART_PAR_NONE; ucntl.databits = 8; ucntl.stopbits = 1; uart_ioctl(uartdev, UART_SETUP_TRANSFER, (INT_32) &ucntl); uartbrk = FALSE; /* Setup RX and TX callbacks */ cbs.rxcb = term_dat_recv_cb; cbs.txcb = term_dat_send_cb; cbs.rxerrcb = term_status_cb; uart_ioctl(uartdev, UART_INSTALL_CBS, (INT_32) &cbs); int_enable(IRQ_UART_IIR5); } /* Initialize TX and RX ring buffers */ txfill = txget = rxfill = rxget = txsize = rxsize = 0; }
bool pn532_uart_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound) { /** @note: Due to UART bus we can't know if its really a pn532 without * sending some PN53x commands. But using this way to probe devices, we can * have serious problem with other device on this bus */ #ifndef SERIAL_AUTOPROBE_ENABLED (void) pnddDevices; (void) szDevices; *pszDeviceFound = 0; DBG ("%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe."); return false; #else /* SERIAL_AUTOPROBE_ENABLED */ *pszDeviceFound = 0; serial_port sp; const char *pcPorts[] = DEFAULT_SERIAL_PORTS; const char *pcPort; int iDevice = 0; while ((pcPort = pcPorts[iDevice++])) { sp = uart_open (pcPort); DBG ("Trying to find PN532 device on serial port: %s at %d bauds.", pcPort, SERIAL_DEFAULT_PORT_SPEED); if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) { bool bComOk; // Serial port claimed but we need to check if a PN532_UART is connected. uart_set_speed (sp, SERIAL_DEFAULT_PORT_SPEED); // PN532 could be powered down, we need to wake it up before line testing. pn532_uart_wakeup ((nfc_device_spec_t) sp); // Check communication using "Diagnose" command, with "Communication test" (0x00) if (!pn532_uart_check_communication ((nfc_device_spec_t) sp, &bComOk)) continue; if (!bComOk) continue; uart_close (sp); snprintf (pnddDevices[*pszDeviceFound].acDevice, DEVICE_NAME_LENGTH - 1, "%s (%s)", "PN532", pcPort); pnddDevices[*pszDeviceFound].acDevice[DEVICE_NAME_LENGTH - 1] = '\0'; pnddDevices[*pszDeviceFound].pcDriver = PN532_UART_DRIVER_NAME; pnddDevices[*pszDeviceFound].pcPort = strdup (pcPort); pnddDevices[*pszDeviceFound].uiSpeed = SERIAL_DEFAULT_PORT_SPEED; DBG ("Device found: %s.", pnddDevices[*pszDeviceFound].acDevice); (*pszDeviceFound)++; // Test if we reach the maximum "wanted" devices if ((*pszDeviceFound) >= szDevices) break; } # ifdef DEBUG if (sp == INVALID_SERIAL_PORT) DBG ("Invalid serial port: %s", pcPort); if (sp == CLAIMED_SERIAL_PORT) DBG ("Serial port already claimed: %s", pcPort); # endif /* DEBUG */ } #endif /* SERIAL_AUTOPROBE_ENABLED */ return true; }
void ui_usb_enum_event(USBH_device_t *dev, USBH_enum_status_t status) { ui_enum_status = status; switch (dev->speed) { case UHD_SPEED_HIGH: ui_device_speed_blink = 250; break; case UHD_SPEED_FULL: ui_device_speed_blink = 500; break; case UHD_SPEED_LOW: default: ui_device_speed_blink = 1000; break; } if (ui_enum_status == UHC_ENUM_SUCCESS) { /* USB Device CDC connected Open and configure UART and USB CDC ports */ CDCLineCoding cfg = { .dwDTERate = (115200), .bCharFormat = CDCLineCoding_ONESTOPBIT, .bParityType = CDCLineCoding_NOPARITY, .bDataBits = 8, }; TRACE_INFO("USART OPEN"); uart_open(); uart_config(&cfg); uhi_cdc_open(0, &cfg); } }
void echonode(void) { TiCc2420Adapter * cc; TiUartAdapter * uart; char * msg = "welcome to echonode..."; uint8 buf[BUF_SIZE]; uint8 len; target_init(); HAL_SET_PIN_DIRECTIONS(); wdt_disable(); led_on(LED_ALL); hal_delay( 500 ); led_off( LED_ALL ); cc = cc2420_construct( (void *)(&g_cc), sizeof(TiCc2420Adapter) ); uart = uart_construct( (void *)(&g_uart), sizeof(TiUartAdapter) ); uart_open( uart, 0, 38400, 8, 1, 0x00 ); uart_write( uart, msg, strlen(msg), 0x00 ); cc2420_open( cc, 0, NULL, NULL, 0x00 ); cc2420_setchannel( cc, DEFAULT_CHANNEL ); cc2420_setrxmode( cc ); // Enable RX cc2420_enable_addrdecode( cc ); // 使能地址译码 cc2420_setpanid( cc, PANID ); // 网络标识 cc2420_setshortaddress( cc, LOCAL_ADDRESS ); // 网内标识 hal_enable_interrupts(); while(1) { cc2420_evolve( cc ); len = cc2420_read( cc, (char*)(&buf[0]), BUF_SIZE, 0x00 ); if (len > 6) { uart_putchar( uart, '>' ); // switch source address and destination address _change(buf[3], buf[7]); _change(buf[4], buf[8]); _change(buf[5], buf[9]); _change(buf[6], buf[10]); buf[29] = 56; // simulate data read from sensor cc2420_write( cc, (char*)(&buf[0]), len, 0x00 ); hal_delay( 10 ); // @attention // You needn't call cc2420_setrxmode() here, because the hal_cc2420 // module will handle it inside. // cc2420_setrxmode( cc ); } } }
/***************************************************************************** Prototype : detector_uart_start Description : start uart Input : DetectorUart *dev Output : None Return Value : static Calls : Called By : History : 1.Date : 2012/4/6 Author : Sun Modification : Created function *****************************************************************************/ static Int32 detector_uart_start(DetectorUart *dev) { Int32 ret = E_NO; if(dev->fd <= 0) { /* open uart */ ret = uart_open(dev->devName, dev->baudRate, dev->dataBits, dev->stopBits, dev->parity); if(ret < 0) { ERR("open UART failed"); return ret; } /* record fd */ dev->fd = ret; /* set timeout for 1 byte recv */ ret = uart_set_timeout(dev->fd, dev->packetLen, dev->timeout); /* set transition delay time */ if(!ret) ret = uart_set_trans_delay(dev->chanId, dev->baudRate); } else UART_FLUSH(dev->fd); return ret; }
void recvnode2(void) { TiCc2420Adapter * cc; TiUartAdapter * uart; char * msg = "welcome to recvnode..."; target_init(); HAL_SET_PIN_DIRECTIONS(); wdt_disable(); led_open(); led_off( LED_ALL ); hal_delay( 500 ); led_on( LED_RED ); cc = cc2420_construct( (void *)(&g_cc), sizeof(TiCc2420Adapter) ); uart = uart_construct( (void *)(&g_uart), sizeof(TiUartAdapter) ); uart_open( uart, 0, 38400, 8, 1, 0x00 ); uart_write( uart, msg, strlen(msg), 0x00 ); cc2420_open( cc, 0, _cc2420_listener, cc, 0x00 ); cc2420_setchannel( cc, DEFAULT_CHANNEL ); cc2420_setrxmode( cc ); //Enable RX cc2420_disable_addrdecode( cc ); //使能地址译码 cc2420_setpanid( cc, PANID ); //网络标识 cc2420_setshortaddress( cc, LOCAL_ADDRESS ); //网内标识 cc2420_enable_autoack(cc); #ifdef TEST_ACK cc2420_enable_autoack(cc); #endif hal_enable_interrupts(); while(1) {}; }
void debug_init(void) { debug_buff = malloc(MAX_DEBUG_LEN); debug_mutex = kmutex_create(); uart_init(1,1024); uart_open(1,115200,0); }
/*------------------------------------------- | Name:dev_stm32f4xx_uart_x_open | Description: | Parameters: | Return Type: | Comments: | See: ---------------------------------------------*/ int dev_stm32f4xx_uart_x_open(desc_t desc, int o_flag, board_stm32f4xx_uart_info_t * uart_info){ // if(uart_info->desc_r<0 && uart_info->desc_w<0) { uart_open(&uart_info->uart_descriptor, 115200, 32, 128, 128, UART_HW_FLOW_CTRL_NONE, 0); } // if(o_flag & O_RDONLY) { if(uart_info->desc_r<0) { uart_info->desc_r = desc; } else return -1; //already open } if(o_flag & O_WRONLY) { if(uart_info->desc_w<0) { uart_info->desc_w = desc; } else return -1; //already open } if(!ofile_lst[desc].p) ofile_lst[desc].p=uart_info; //unmask IRQ if(uart_info->desc_r>=0 && uart_info->desc_w>=0) { } return 0; }
bool initUartOutput(flowOutputState state, char* port, unsigned int baud, size_t bufferSize) { // Initialize UART communication int uartErrno = uart_open(port, baud); if (uartErrno) { caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART, "Failed to identify serial communication, errno=%i.",uartErrno); return (false); } // Test message char* testMessage = "DVS128UART"; if (uart_tx((int) strlen(testMessage), (unsigned char*) testMessage)) { caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART, "Test transmission unsuccessful - connection closed."); uart_close(); return(false); } // Start output handler thread state->thread = 0; if (thrd_create(&state->thread, &outputHandlerThread, state) != thrd_success) { caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,"Failed to start output handler thread"); return (false); } state->buffer = ringBufferInit(bufferSize); if (state->buffer == NULL) { caerLog(CAER_LOG_ERROR, SUBSYSTEM_UART, "Failed to allocate transfer ring-buffer."); return (false); } atomic_store(&state->running, true); caerLog(CAER_LOG_NOTICE, SUBSYSTEM_UART, "Streaming flow events to port %s.",port); return (true); }
/*#####################################################*/ bool board_init() { //RtcStruct.Rtc_ClkSource = _Rtc_Clk_Source_RCOSC_gc; core_init(); //timer_init(); /*-----------------------------------------------------*/ /* Set up the Uart 0 like debug interface with RxBuff = 256, TxBuff = 256, 115200b/s*/ DebugCom = new_(new_uart); DebugCom->BaudRate = 115200; DebugCom->RxBuffSize = 20; DebugCom->TxBuffSize = 10; //DebugCom->Mode = UsartCom_Mode_Asynchronus; DebugCom->Priority = 0; DebugCom->UartNr = 5; uart_open(DebugCom); /*-----------------------------------------------------*/ /* Display board message*/ #if defined(BOARD_MESSAGE) UARTPutc(DebugCom, 0xFF); UARTPutc(DebugCom, 0xFF); UARTPutc(DebugCom, '\n'); UARTPutc(DebugCom, '\r'); UARTprintf(DebugCom, "Use %s Board.\n\r", BOARD_MESSAGE); #endif /*-----------------------------------------------------*/ HARDBTN1 = gpio_assign(0, 1, GPIO_DIR_INPUT); gpio_up_dn(HARDBTN1, 1); /*-----------------------------------------------------*/ LED1 = gpio_assign(3, 12, GPIO_DIR_OUTPUT); LED2 = gpio_assign(3, 13, GPIO_DIR_OUTPUT); LED3 = gpio_assign(3, 14, GPIO_DIR_OUTPUT); LED4 = gpio_assign(3, 15, GPIO_DIR_OUTPUT); /*-----------------------------------------------------*/ return true; }
int main(void){ GPIO_InitTypeDef GPIO_InitStructure; //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); /* GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); */ if (SysTick_Config(SystemCoreClock / 1000)) while (1); uart_open(USART1, 9600, USART_FLAG_TXE); while(1){ char msg_out[] = "Hello World\n\r"; uint16_t i; for (i = 0; i < sizeof(msg_out); i++){ uart_putc(msg_out[i], USART1); } //uart_putc('H', USART1); Delay(250); } }
bool main_cdc_enable(uint8_t port) { main_b_cdc_enable = true; // Open communication uart_open(port); return true; }
void uart_socket_example(void *param) { char tx_data[] = {0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; uart_set_str uartset; struct timeval tv; fd_set readfds; int read_len = 0, count = 0; int ret = 0; char rxbuf[512]; int uart_fd; uart_socket_t *uart_socket = NULL; uartset.BaudRate = 9600; uartset.number = 8; uartset.StopBits = 0; uartset.FlowControl = 0; uartset.parity = 0; strcpy(uartset.UartName, "uart0"); uart_socket = uart_open(&uartset); if(uart_socket == NULL){ uart_printf("Init uart socket failed!\n"); goto Exit; } uart_fd = uart_socket->fd; uart_printf("\nOpen uart socket: %d\n", uart_fd); while(1) { FD_ZERO(&readfds); FD_SET(uart_fd, &readfds); tv.tv_sec = 0; tv.tv_usec = 20000; if(count++ == 50){ uart_write(uart_socket, tx_data, sizeof(tx_data)); //uart_print_data("TX:", tx_data, sizeof(tx_data)); count = 0; } ret = select(uart_fd + 1, &readfds, NULL, NULL, &tv); //uart_printf("[%d] select ret = %x count=%d\n", xTaskGetTickCount(), ret, count); if(ret > 0) { if(FD_ISSET(uart_fd, &readfds)) { read_len = uart_read(uart_socket, rxbuf, sizeof(rxbuf)); if(read_len > 0) { uart_print_data("RX:", rxbuf, read_len); if(rtl_strncmp(rxbuf, "close", 5) == 0) break; } } //else for other sockets } } uart_printf("Exit uart socket example!\n"); uart_close(uart_socket); Exit: vTaskDelete(NULL); }
int OpenProxmark(size_t i) { sp = uart_open(serial_port_name); if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT) { //poll once a second return 0; } return 1; }
int main(int argc, char** argv) { char* uart_port = NULL; if (argc == 2) uart_port = argv[1]; else { printf("Usage: %s <serial_port>\n\n", argv[0]); return 1; } bglib_output = output; if (uart_open(uart_port)) { printf("ERROR: Unable to open serial port\n"); return 1; } // Reset dongle to get it into known state ble_cmd_system_reset(0); uart_close(); do { usleep(500000); // 0.5s } while (uart_open(uart_port)); ble_cmd_gap_end_procedure(); ble_cmd_gap_discover(gap_discover_observation); while (1) { if (read_message(UART_TIMEOUT) > 0) break; } uart_close(); return 0; }
void main_cdc_close(uint8_t port) { switch(port){ case 0: // COMM0 uart_close(&USART_COMM0); // close COMM0, this also disables interrupts break; case 1: // Switch back to XBEE forwarding/programming, open COMM1 uart_open(&USART_COMM1); // restore communication with main processor on COMM1 usart_set_rx_interrupt_level(&USART_COMM1, USART_INT_LVL_HI); break; } }
/*********************************************************************** * * Function: uart_output_init * * Purpose: Initialize UART output * * Processing: * See function. * * Parameters: None * * Outputs: None * * Returns: Nothing * * Notes: None * **********************************************************************/ void uart_output_init(void) { UART_CONTROL_T ucntl; /* Open the UART for message output */ /* Setup UART for 8 data bits, no parity, 1 stop bit */ ucntl.baud_rate = UARTOUTPUTRATE; ucntl.parity = UART_PAR_NONE; ucntl.databits = 8; ucntl.stopbits = 1; uartdev = uart_open((void *) UARTOUTPUTDEV, (INT_32) &ucntl); }
int main(void){ FRESULT rc; UINT bw, br, i; if(SysTick_Config(SystemCoreClock / 1000)) while(1); xfunc_in = mygetchar; xfunc_out = myputchar; uart_open(USART1,9600,0); f_mount(0, &Fatfs); xprintf("\nOpen an existing file (message.txt).\n"); rc = f_open(&Fil, "MESSAGE.TXT", FA_READ); xprintf("\nresult:%u;\n",rc); if(!rc){ xprintf("\nType the file content.\n"); for(;;){ rc = f_read(&Fil, Buff, sizeof Buff, &br); if(rc || !br) break; for(i=0; i<br; i++) myputchar(Buff[i]); } if (rc) die(rc); xprintf("\nClose the file.\n"); rc=f_close(&Fil); if(rc) die(rc); } xprintf("\nCreate a new file (hello.txt).\n"); rc = f_open(&Fil, "HELLO.TXT", FA_WRITE | FA_CREATE_ALWAYS); if(rc) die(rc); xprintf("\nWrite a text data. (Hello world!)\n"); rc = f_write(&Fil, "Hello world!\r\n", 14, &bw); if(rc) die(rc); xprintf("%u bytes written.\n", bw); /*while(1){ uart_putc('a',USART1); xputc('b'); Delay(1000); }*/ }
static int uart_diag_init(const struct diag *diag) { struct uart_diag *uart_diag = (struct uart_diag *) diag; uart_set_params(uart_diag->uart, uart_diag->params); /* XXX */ /* set params */ uart_open(uart_diag->uart); /* allow future `open' */ uart_close(uart_diag->uart); return 0; };
void uart_test(void) { char buf[1024]; char buf2[1024]; int i; int len; int ret; /* uart1 tx <---> uart3 rx * uart1 rx <---> uart3 tx */ ret = uart_open(1,115200,8,'n',1); dprintf("uart2 open ret:%d\r\n",ret); ret = uart_open(3,115200,8,'n',1); dprintf("uart3 open ret:%d\r\n",ret); while(1) { for(i = 0; i<sizeof(buf); i++) buf[i] = i & 0xff; uart_tx(1, buf, sizeof(buf)); while(!uart_tx_buffer_empty(1)) { RDIAG(LEGACY_DEBUG,"wait uart 2 tx finish"); } while(1) { len = uart_rx(3, buf2, sizeof(buf2)); dprintf("len:%d\r\n",len); if(len > 0) { for(i = 0; i<len; i++) dprintf("%2x",buf2[i]); } else { dprintf("\r\n"); break; } } } }
void main_cdc_open(uint8_t port) { switch(port){ case 0: // COMM0 lithneProgrammer.resetMain(); uart_open(&USART_COMM0); usart_set_rx_interrupt_level(&USART_COMM0, USART_INT_LVL_HI); // receive interrupt break; case 1: // Switched to XBEE direct: close COMM1 uart_close(&USART_COMM1); // close COMM1, this also disables interrupts usart_set_rx_interrupt_level(&USART_XBEE, USART_INT_LVL_HI); break; } }
static inline void app_setup_dbg() { BAUD baudrate; pin_enable(DBG_CONSOLE_TX_PIN, STM32_GPIO_MODE_OUTPUT_AF_PUSH_PULL_50MHZ, false); uart_open(DBG_CONSOLE, UART_MODE_STREAM | UART_TX_STREAM); baudrate.baud = DBG_CONSOLE_BAUD; baudrate.data_bits = 8; baudrate.parity = 'N'; baudrate.stop_bits= 1; uart_set_baudrate(DBG_CONSOLE, &baudrate); uart_setup_printk(DBG_CONSOLE); uart_setup_stdout(DBG_CONSOLE); open_stdout(); }
//**************************************************************************** // MAIN FUNCTION //**************************************************************************** void main(void) { int iRetVal; // // Board Initialisation // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Initialize the platform // platform_init(); // // Configuring UART // g_tUartHndl = uart_open(PRCM_UARTA0); // // Start the SimpleLink Host // iRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY); if(iRetVal < 0) { UART_PRINT("could not create simplelink task\n\r"); LOOP_FOREVER(); } // // setting up timer and gpio as source for wake up from HIBERNATE // iRetVal = osi_TaskCreate(TimerGPIOTask, (const signed char *)"set wk_src for hibernate", OSI_STACK_SIZE, NULL, 1, NULL ); if(iRetVal < 0) { UART_PRINT("Task creation failed\n\r"); LOOP_FOREVER(); } // // Start the task scheduler // osi_start(); }
void main() { // Buffer para almacenar teclas uint8_t buf[10]; uint8_t index = 0; ANSEL = 0x00; TRISA = 0xFF; TRISB = 0b00000100; // Get UART ID, The UART library works on parts with more than one UART/USART modules xUARTHandle uart1 = uart_init(E_UART_1); // Configure UART (standard serial port settings) if (uart_control(uart1, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1, 9600)) for (;;); // Invalid UART settings, should not get here // Open UART and begin usage if (uart_open(uart1)) { // Send a string uart_puts(uart1, "PIC UART Demo\r\n"); // Main loop for (;;) { // Check if UART received some data if (uart_available(uart1)) { // receive a single byte buf[index] = uart_read(uart1); // send a single byte (echo) uart_write(uart1, buf[index]); // Send a string with control characters uart_puts(uart1, "\r\n"); // Increase counter and check limits index++; if (index == 10) { // Send other string uart_puts(uart1, "\r\nRX: "); // Send the 10 characters array uart_write_array(uart1, buf, 10); uart_puts(uart1, "\r\n"); // Reset index index = 0; } } } } for (;;); // Should not get here }
FTVOID ft9xx_int_print (char *p) { sys_enable(sys_device_uart0); gpio_function(FT9XX_UART0_TX, pad_uart0_txd); /* UART0 TXD */ gpio_function(FT9XX_UART0_RX, pad_uart0_rxd); /* UART0 RXD */ uart_open(UART0, /* Device */ FT9XX_PRESCALER, /* Prescaler = 1 */ UART_DIVIDER_9600_BAUD, uart_data_bits_8, /* No. Data Bits */ uart_parity_none, /* Parity */ uart_stop_bits_1); /* No. Stop Bits */ FTPRINT("\n"); FTPRINT(p); }
//Reads data into uart's fifo. int uart_read_start(uart_s* uart, int timeout){ if (!uart->rxfifo){ uart_printf(CLR_CANCEL,0,"Uart has no rxfifo\n"); return -1; } uart_printf(CLR_CANCEL,2,"uart_read_start\n"); if (!uart->opened){ uart_open(uart); } //Wiggle /* int status = TIOCM_CTS; ioctl (uart->fd, TIOCMBIS, &status); ioctl (uart->fd, TIOCMBIC, &status); */ //Use a buffer to flatten the fifo. uint8_t* buff = (uint8_t*)malloc(uart->rxfifo->size); int n = uart_read(uart,buff,512,timeout); //Some debug data: uart_printf(CLR_CANCEL,1,"Received %i characters\n",n); #if(UARTDEBUG) if (n){ printf_hex_block(buff,n,1); } #endif if (n == -1){ free(buff); return -1; } //Store in fifo. int i =0; int r=n; while(r--){ fifo_putc(uart->rxfifo,buff[i]); i++; } uart_printf(CLR_CANCEL,1,"Done\n"); free(buff); return n; }