View previous topic :: View next topic |
Author |
Message |
Tagge
Joined: 23 Aug 2005 Posts: 93
|
Putc() |
Posted: Thu Jul 06, 2006 1:02 am |
|
|
Hi,
can someone inform me about how the putc() function works inside an serial_tx_isr()? does it poll tx_empty until sent? beacuse if it does it will work much faster if the byte to send is written directly in to the TXREG?
example:
Code: |
#int_tbe
void serial_tx_isr() {
putc(t_buffer[t_next_out]);
t_next_out=(t_next_out+1) % T_BUFFER_SIZE;
if(t_next_in==t_next_out) disable_interrupts(INT_TBE);
}
Alternative:
void serial_tx_isr() {
TXREG = t_buffer[t_next_out];// faster?
t_next_out=(t_next_out+1) % T_BUFFER_SIZE;
if(t_next_in==t_next_out) disable_interrupts(INT_TBE);
}
|
Is this true? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 06, 2006 1:19 am |
|
|
putc() polls TXIF, not TRMT. So by writing directly to TXREG inside
the isr, you would save at most, two instruction cycles. These cycles
are caused by the "BTFSS 0C.4" instruction when it tests the TXIF bit
and takes the jump. Compared to the overhead of getting in and
out of the isr, and executing the other code such as your array fetch,
those two cycles are not important. |
|
|
Tagge
Joined: 23 Aug 2005 Posts: 93
|
|
Posted: Thu Jul 06, 2006 1:52 am |
|
|
But does the cpu wait in isr() for the whole byte to be sent (polling the TXIF), instead of just loading the tx buffer with the data and return from isr(). If so, thousends of cykles may be missed? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Jul 06, 2006 1:55 am |
|
|
Tagge wrote: | But does the cpu wait in isr() for the whole byte to be sent (polling the TXIF), instead of just loading the tx buffer with the data and return from isr(). If so, thousends of cykles may be missed? |
No it does not. The handler gets invoked because TF must be set. It writes the byte which immediately clears TF and the handler exits. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Tagge
Joined: 23 Aug 2005 Posts: 93
|
|
Posted: Thu Jul 06, 2006 4:23 am |
|
|
When writing to the TXREG, when a byte is recived the isr() is launched and the data shifted out from the register at in this case 2400baud. To put out the byte takes about 4,2mS, thats a lot of cycles that the cpu is occupied, TXIF active? Putc() is waiting for those 4,2mS!
If instead loading TXREG directly and return it would save 16000-17000cycles?
Could this be done and is this as I descibed it? |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 06, 2006 4:32 am |
|
|
You have what is going on 'reversed'.
Putc, checks that the transmit buffer is empty, _before_ transferring the character. If you arrive in the interrupt, then the buffer _is_ empty, so no wait takes place. Once the character is in the buffer, the hardware gets on with sending it, and putc, exits. There would only be a problem, if the interrupt handler attempted to transfer more than one character.
Best Wishes |
|
|
|