Thanks to those who have replied.
To Richard, AFAIK the example on the Keil website
>http://www.keil.com/download/docs/288.asp
does not make use of the hardware TX buffer. To do that you'd need
code along the lines of (*warning untested code*):
void uart0_isr(void) __irq { /* not for public use */
unsigned char source = U0IIR & 0x06; /* only interested in interrupt
bits */
int index;
switch (source) {
case 0x02: /* transmit holding register empty */
uart0.TX_internal_buffer_space = uart_TX_internal_buffer_size;
while ((uart0.TX_internal_buffer_space > 0)
&& (uart0.TX_Extract_Index != uart0.TX_Insert_Index)) {
U0THR = uart0_TX_Buffer[uart0.TX_Extract_Index++];
if (uart0.TX_Extract_Index == uart0TX_BufferSize)
uart0.TX_Extract_Index = 0;
--uart0.TX_internal_buffer_space;
}
break;
case 0x04: /* receiver buffer register occupied */
...
break;
case 0x06: /* RX Line status change or error */
source = U0LSR;
break;
default: /* should not have interrupted */
break;
}
VICVectAddr = 0; /* satisfy the Vector Interrupt Controller */
}
and a "put into buffer" routine like:
void uart0_putch(char c) { /* this will HANG while buffer is full */
int newIndex;
if (uart0.TX_internal_buffer_space > 0) {
U0THR = c;
--uart0.TX_internal_buffer_space;
} else {
newIndex = uart0.TX_Insert_Index + 1;
if (uart0TX_BufferSize == newIndex)
newIndex = 0;
while (newIndex == uart0.TX_Extract_Index)
; /* hang while buffer is full */
uart0_TX_Buffer[uart0.TX_Insert_Index] = c;
uart0.TX_Insert_Index = newIndex;
if ((uart0.TX_internal_buffer_space > 0)
&& (uart0.TX_Insert_Index != uart0.TX_Extract_Index)) {
/* just missed empty interrupt! */
c = uart0_TX_Buffer[uart0.TX_Extract_Index];
newIndex = uart0.TX_Extract_Index + 1;
if (uart0TX_BufferSize == newIndex)
newIndex = 0;
uart0.TX_Extract_Index = newIndex;
U0THR = c; /* this might cause interrupt */
}
}
}
And to Sten, I don't see any mention on your website that your code
makes use of the TX FIFO. Should one just assume that
professional-quality code like yours does every possible optimisation?
Or should I browse through the code to see if it has the facilities I
might desire?
>
>if you have a 16byte-hardware-FIFO why you should not use it?!?
>I have written an interrupt-driven driver which is using configurable
>software TX and RX FIFOs between ISR and task. The task is feeding the
>TX FIFO with data and the ISR in background is feeding UART's hardware
>FIFO with 16 bytes/call (if available) from TX FIFO. It's a maximum
>efficiency with a minimum overhead.
> http://nanortos.net-attack.de/
I suppose part of the question is whether an arm with modern
peripherals is too large to be worth learning in its entirety. And
another part is that people should be able to make money by selling
their libraries and/or tools.
Regards,
DanishMessage
Re: optimum uart buffered transmit example?
2005-11-21 by dr_danish_ali
Attachments
- No local attachments were found for this message.