CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Putc()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

Putc()
PostPosted: Thu Jul 06, 2006 1:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 06, 2006 1:19 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 06, 2006 1:52 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jul 06, 2006 1:55 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 06, 2006 4:23 am     Reply with quote

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







PostPosted: Thu Jul 06, 2006 4:32 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group