Forum Discussion
4 Replies
- Altera_Forum
Honored Contributor
something like this:
int uart_set_baudrate(int filedescriptor,int baudrate) { struct termios term; int res; assert(filedescriptor); 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; } to get filedescriptor use: int fd; fd=open("/dev/uart_0",O_RDWR | O_NONBLOCK | O_NOCTTY); - Altera_Forum
Honored Contributor
Fischer I already found this answer .. but never success with this way...
I suggest : In Quartus II v6.0 Handbook -> embedded peripherals. You could find this for UART baudrate configuration : divisor=int((clok freq/baudrate)+0.5) According to your clock freq and the baudrate you want, write into the divisor : IOWR_ALTERA_AVALON_UART_DIVISOR(uart_base_addr, new_divisor); don't forget to allow modification of divisor in SOPC Builder you can also read your divisor with IORD_ALTERA_AVALON_UART_DIVISOR.. You don't need to open a file descriptor on the uart IP device example : clock freq : 50Mhz baudrate : 921600 bds divisor = 54 - Altera_Forum
Honored Contributor
sorry, I forget to mention that you have to define
ALTERA_AVALON_UART_USE_IOCTL in c-compiler settings in your system library. (see altera_avalon_uart.c) it is indeed only the baudrate setting, that is supported by the altera device driver's ioctrl function. the ioctrl function is the "linux" way to set the baudrate. the direct way to modify the baudrate like Billooj suggest's works, but it ignores the driver. this is not so much a problem in the case of only baudrate settings, but modifying other uart registers directly may confuse the hal driver. it is dangerous to bypass the driver, that means mix hall driver functions and direct SDK access, if you do not exactly know what you are doing. e.g. in the case of the baudrate, if you set the baudrate with IOWR_ALTERA_AVALON_UART_DIVISOR, you cannot read it back with "res=ioctl(filedescriptor,TIOCMGET,&term);" if you work with filedescriptors you can change "/dev/uart_0" to e.g. "/dev/uart1" and everything works again. I think result is IOWR_ALTERA_AVALON_UART_DIVISOR is advantage: - simple - short - works disadvantage - dangerous to directly access hardware registers, which is normally done by the HAL driver. (not a good programming style, also not possible in linux" - not portable - Altera_Forum
Honored Contributor
Thanx for precisions Fisher.
I'll try again modify parameters with temrmios structure.