Using a LPC2400/LPC17xx family of microcontrollers, if I use a TX ring buffer, I think there is a risk of the THRE interrupt to come so quickly that the hardware TX buffer is emptied before any task can post data in the ring buffer - terminating the transmission. I solved this by checking in application (not ISR) whether there is a pending IRQ and starting a new transmission if there is data to send without a pending interrupt. I am not fond of this. Any thought would be appreciated.
Where should I start. I know. You write about if I use a TX ring buffer like there is only one solution. Well there isn't. See. Your implementation might work in a way that you are not fond of, but other implementations are likely to be different (aka better). You don't even give the slightest detail of the implementation you're using or where you (obviously) copied it from.
I will not waste any more time on you. Goodbye.
I did not copy the software from anyone or anywhere. I presented the abstract case in which a THRE interrupt is coming in so fast that application task cannot keep up causing the transmission to end prematurely, and was wondering whether there is a better solution. Why are you so bitter? Help if you can, say nothing if you can't!
Well, the abstract case here is that lots of microcontrollers needs a kick-start by putting data in transmit register to then get transmit empty interrupts.
So yes, it is very common to need to have code that checks if the transmitter is stalled or not. If not stalled, then it's enough to put data in the ring buffer. If it has stalled, then you need to kick-start by giving data to UART.
Like it or not - it is what it is. Processors that don't need data in UART to arm the transmit empty interrupt normally have a different behaviour. The same moment you enable transmit interrupts, it generates the interrupt "give me food". So the basic difference then is that when you don't have data to send, you need to disable the interrupt source. And when you have data to send, you need to check if the interrupt source is enabled (allowing you to just put more data in ring buffer) or if the interrupt source is disabled (to block UART from constant transmit-empty interrupts) you then need to give data to UART and enable interrupt.
In the end, we need to write programs based on the hardware design. Not what we like.
Thank you.