Altera_Forum
Honored Contributor
20 years agouart hal questions ?
1. how can I open the uart for non blocking read ?
2. how can I do "blocking output" with "non blocking read" ? ( without modifying altera_avalon_uart.c) 3. how can I disable RTS/CTS in software ? 1. without OS a blocking uart read is not very usefull I open the uart in the following way: int fdterm; // FILEDESCRIPTOR RETURNED BY OPEN FILE *fpterm; // FILEPOINTER RETURNED BY FDOPEN flags= O_RDWR | O_NONBLOCK | O_NOCTTY; fdterm = open(devicename,flags); if(fdterm==0) { DPRINTF("ERROR open devive:%s\r\n",devicename); return -1; } fpterm=fdopen(fdterm,"rw+"); if(fpterm==0) { DPRINTF("ERROR fdopen devive:%s\r\n",devicename); } .. // then I can read nonblocking ... res=read(fdterm,uart1_tempbuff,sizeof(uart1_tempbuff)-1); if(res>0) { // we have receuived any characters .. } 2. using fprintf(fpterm,"...") I get scrambled output I think this is because in "altera_avalon_uart.c" in function alt_avalon_uart_write the buffer is overwritten. I get correct output, if I set disable "no_block=0" .. int alt_avalon_uart_write (alt_fd* fd, const char* ptr, int len) { alt_irq_context context; int no_block; alt_u32 next; alt_avalon_uart_dev* dev = (alt_avalon_uart_dev*) fd->dev; int count = len; /* * Construct a flag to indicate whether the device is being accessed in * blocking or non-blocking mode. */ no_block = (fd->fd_flags & O_NONBLOCK); no_block=0; // set no_block to 0 to get printf working /* ... 3. I have configured the uart in sopc builder with RTS/CTS but don't want to use it in software. I use the following function to clear the flag ALT_AVALON_UART_FC. ... int uart_set_flowcontrol(int filedescriptor,BYTE flowctrl) { alt_fd* fd; alt_avalon_uart_dev* dev; // pointer to uart device if(filedescriptor<0) return -1; // see alt_ioctrl.c fd = (filedescriptor < 0) ? NULL : &alt_fd_list[filedescriptor]; if (fd) { dev=(alt_avalon_uart_dev*)fd->dev; if(flowctrl) { dev->flags|=ALT_AVALON_UART_FC; } else { dev->flags&=~ALT_AVALON_UART_FC; } return 0; } return -1; } ... 4. I change baudrate with the function ... int uart_set_baudrate(int filedescriptor,int baudrate) { struct termios term; int res; res=ioctl(filedescriptor,TIOCMGET,&term); if(res<0) { DPRINTF("ERROR ioctl filedescriptor:%d\r\n",filedescriptor); return res; } term.c_ispeed=baudrate; term.c_ospeed=baudrate; res=ioctl(filedescriptor,TIOCMSET,&term); if(res<0) { DPRINTF("ERROR ioctl filedescriptor:%d\r\n",filedescriptor); } return res; } ... is this correct ???