- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ???Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
<div class='quotetop'>QUOTE </div>
--- Quote Start --- 1. how can I open the uart for non blocking read ?[/b] --- Quote End --- As you put it in your example, this opens the UART non-blocking int fdterm; // FILEDESCRIPTOR RETURNED BY OPEN flags= O_RDWR | O_NONBLOCK | O_NOCTTY; fdterm = open(devicename,flags); <div class='quotetop'>QUOTE </div> --- Quote Start --- 2. how can I do "blocking output" with "non blocking read" ?[/b] --- Quote End --- Open it twice i.e. int fdterm; // NON BLOCKING FILEDESCRIPTOR RETURNED BY OPEN int fdterm_block; // BLOCKING FILEDESCRIPTOR RETURNED BY OPEN flags= O_RDWR | O_NONBLOCK | O_NOCTTY; fdterm = open(devicename,flags); flags= O_RDWR | O_NOCTTY; fdterm_block = open(devicename,flags); Use the appropriate handle depending upon whether you want blocking or non-blocking behaviour <div class='quotetop'>QUOTE </div> --- Quote Start --- 3. how can I disable RTS/CTS in software ?[/b] --- Quote End --- You can't it's asssumed that if you selected this hardware in SOPC Builder you will want the software. If you don't want RTS CTS turn it off in SOPC builder and save yourself some hardware resources- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks rugbybloke,
the question of RTS/CTS is just that I don't know, if I will need it later. Also I have 3 nearly equal projects, so that I don't want to change the sopc system. So I think, it only needs to clear the flag ALT_AVALON_UART_FC. Is the function "uart_set_flowcontrol correct" ???- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The function looks OK to me, but try it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I can't seem to get the 'open' command to work, only the 'fopen' one which doesn't seem to support non-blocking access. What include files are you using? Thanks, Richard- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The best way to find things like this is to use man on a unix machine, or type "linux man open" into google.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i think open is in <fcntl.h>, don't know if you need all, just a copy from my file
# include <sys/ioctl.h> // open ???# include <fcntl.h># include<string.h> // rand(),srand()# include<stdlib.h> // write(),read(),usleep()# include<unistd.h> # include <priv/alt_file.h># include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h" # include<time.h>
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page