OK, so while the executable is running. How much CPU is being used ? The reason I ask may be less than obvious, but Iām asking because I do not know what type pruIo is. But the assignment of this type looks remarkably similar to mmap(). e.g. a file mapped to a region in memory.
So a few things to take notice of.
First, youāre making a call to select() every while loop iteration. That is to say: every 1ms, assuming the OS lets you. select() I believe is a system call, and can slow things down. If the call to the file descriptor object is blocking. It can slow things down quite considerably. Here, again, Iām not familiar with TJFās library to know. One potential āfixā might be to change the file descriptor object to O_NONBLOCK using fcntl(). Then perhaps look into using epoll() which has none of the performance issues that select(), or poll() have. Which is something I do not experience with personally, but have been reading a lot about lately for my own purposes.
Second, you making a call to every while loop cycle to fprintf() which has to format 8 variables down to every 1ms. fprintf(), Iām not very familiar with, but if it is similar to printf() this can be another performance hit. With that said, Iām not sure how you could avoid this. That is to say, I know what the function does, I just have never read the actual implementation code . . . so could not tell you how it does, what it does. Iām assuming, it behaves exactly like printf(), but allows one to send this formatted output to an alternate āfile streamā. Without . . .heh . . . āmagic hand wavingā.
Thirdly, and Iām still not quite sure how often this happens. Because I have not even a clue what the TEMP_FAILURE_RETRY macro does. Here, Im assuming it returns some condition based on the state of the file descriptor( ready read, etc ). But once you break out of the while loop, into the outside do loop, you have cough 3 what I think are also system calls to tcgetattr(). But once again, Iām not all that familiar with termios either . . .
Anyway, are you seeing a pattern here ? For very performant code, system calls are baaaaaaaaad. Did I emphasize that enough ? This is why many people when working with file descriptors often use mmap() Or rather is one very good reason why. Unfortunately Iām also not all that familiar with the ADC on this platform either . . . However, assuming there is a sysfs pseudo file available for the ADC, using mmap() to map to it should not be all that difficult. After that, I think the majority of the difficulty would be working out timing. Or in other words it is very possible using mmap() on the file descriptor to the ADC and just pumping that data straight into the termios buffer may be too fast.
Anyway, sorry I could not answer your question better . . . but hopefully I did give you a few things to consider. Perhaps TJF can elaborate on some of the points I made, and prove / disprove what Iām assuming in many cases.