Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
12489 Discussions

UART block until all data is sent

ONors
New Contributor I
414 Views

I need to synchronize sending some data on a UART to some other events. I therefore need to know when the UART have completed sending all data in the SW buffer. I am using the regular UART in Quartus 13.1 and the regular altera_avalon_uart_driver for Nios II. How can I make a call that will block until the data is sent or get an interrupt when it is sent?

Here are some things I have tried.
I have tried opening the UART with fopen, sending data with fputs and waiting for all data to be sent with fflush. fflush returned almost immediately and long before all data was sent so fflush did not work for this purpose. I have also tried different types of buffering with setvbub. I have tried different variations of the open and write functions. I see there is a function called tcdrain that is supposed to, from my understanding, wait until all data is sent. It is actually just a macro #  define tcdrain(fd)   _ioctl (fd, _TCSBRK, 1). But it does not link since it can not find _ioctl. I have tried using ioctl (fd, _TCSBRK, 1) but it did not wait until the data was sent.

0 Kudos
1 Solution
ShengN_Intel
Employee
315 Views

Hi,

 

May be you can try to access these uart core control register bits for interrupt. Can refer to this manual (page 145).

ShengN_Intel_0-1652320956787.png

 

Best Regards

Sheng

p/s: If any answer from community or Intel support are helpful, please feel free to mark as solution and give Kudos.

 

View solution in original post

4 Replies
ShengN_Intel
Employee
373 Views

Hi,


Have you try with UART operating in blocking mode using fcntl() command.

https://stackoverflow.com/questions/914463/how-to-make-a-file-descriptor-blocking

https://code.activestate.com/recipes/577384-setting-a-file-descriptor-to-blocking-or-non-block/


Regards,

Sheng

p/s: If any answer from community or Intel support are helpful, please feel free to mark as solution and give Kudos.


ONors
New Contributor I
350 Views

I can make the UART operate in blocking mode using fcntl(). In blocking mode, a call to write something to the UART will block if the SW buffer is full. Unfortunately what I need to know is when the SW buffer empties. In altera_avalon_uart.h I see that the size of the SW buffer for both RX and TX is set to ALT_AVALON_UART_BUF_LEN. If edit this to two, one did not work, I get almost what I want. Unfortunately It also sets the RX buffer to a low value for this UART and both RX and TX buffer of all the other UARTs to a lower value than I like. I can probably make my own driver where I resolve this issues. But for now I think I will just bypass the driver and access the UART registers directly to achieve what I need.

ShengN_Intel
Employee
316 Views

Hi,

 

May be you can try to access these uart core control register bits for interrupt. Can refer to this manual (page 145).

ShengN_Intel_0-1652320956787.png

 

Best Regards

Sheng

p/s: If any answer from community or Intel support are helpful, please feel free to mark as solution and give Kudos.

 

ONors
New Contributor I
300 Views

Yes, by bypassing the driver, accessing the device registers directly and using my own interrupt routine I was able to achieve what I needed.

Reply