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 support@ccsinfo.com

about EX_STISR.C

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



Joined: 08 Sep 2008
Posts: 84

View user's profile Send private message

about EX_STISR.C
PostPosted: Thu Oct 23, 2008 3:39 am     Reply with quote

Everybody hi,


I will really appreciate that anyone explain me what is happening in the TBE interruption routine (next_in, next_out roles etc...Rolling Eyes ) and how bgetc() functions ??, I tryed to understand them but without success.

Code:

#int_tbe
void serial_isr() {

   if(t_next_in!=t_next_out)
   {
      putc(t_buffer[t_next_out]);
      t_next_out=(t_next_out+1) % T_BUFFER_SIZE;
   }
   else
      disable_interrupts(int_tbe);
}


Code:

void bputc(char c) {
   short restart;
   int ni;

   restart=t_next_in==t_next_out;
   t_buffer[t_next_in]=c;
   ni=(t_next_in+1) % T_BUFFER_SIZE;
   while(ni==t_next_out);
   t_next_in=ni;
   if(restart)
      enable_interrupts(int_tbe);
}




thanks in advance and excuse me .
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 2:35 pm     Reply with quote

It's an interrupt-controlled circular buffer for the UART transmitter. It allows you to put up to 64 characters in the buffer and they will be transmitted automatically. Normally, to transmit several characters, your code has to wait until each character is sent, before the program can move on to the next section of code. In other words, the putc() function
"blocks" program flow. It can take over 60 ms to transmit 64 characters
if you just use printf() to send them. The interrupt-controlled circular
transmit buffer solves this problem.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 3:03 pm     Reply with quote

As PCM has pointed out, using interrupts gets around the blocking issue, which is a fancy way of saying that it avoids occupying the processor 100% until the entire message has been sent.

The TBE interrupt stands for Transmit Buffer Empty. In your startup code at the top of main(), never enable the TBE interrupt. If you're not sending data out via the USART, the transmit buffer will always be empty and the TBE interrupt will always "fire". For this reason, the bputc() function has the check to see if the character being sent is the first one - if it is, then the TBE interrupt is enabled because you want to know when it's safe to send the next character of your message. bputc() also has another check to see if you've completely filled your transmit buffer - if it is full, the code just waits in the while loop for the TBE routine to transmit another character.

The TBE routine just sends the current character and increments the "pointer" that will let it know which character has to be sent next time around. It also performs a check to see if there are any unsent characters left in the buffer (filled by bputc()), and if there aren't, it disables any further TBE interrupts.

Clear?
Salenko



Joined: 08 Sep 2008
Posts: 84

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 5:13 pm     Reply with quote

PCM programmer wrote:
It's an interrupt-controlled circular buffer for the UART transmitter. It allows you to put up to 64 characters in the buffer and they will be transmitted automatically. Normally, to transmit several characters, your code has to wait until each character is sent, before the program can move on to the next section of code. In other words, the putc() function "blocks" program flow. It can take over 60 ms to transmit 64 characters if you just use printf() to send them. The interrupt-controlled circulartransmit buffer solves this problem.


hi,

Thank you PCM Programmer for taking time to answer me, now the advantage of the interrupt-controlled circular buffer is clear to me.


Last edited by Salenko on Thu Oct 23, 2008 5:28 pm; edited 1 time in total
Salenko



Joined: 08 Sep 2008
Posts: 84

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 5:26 pm     Reply with quote

newguy wrote:
As PCM has pointed out, using interrupts gets around the blocking issue, which is a fancy way of saying that it avoids occupying the processor 100% until the entire message has been sent.

The TBE interrupt stands for Transmit Buffer Empty. In your startup code at the top of main(), never enable the TBE interrupt. If you're not sending data out via the USART, the transmit buffer will always be empty and the TBE interrupt will always "fire". For this reason, the bputc() function has the check to see if the character being sent is the first one - if it is, then the TBE interrupt is enabled because you want to know when it's safe to send the next character of your message. bputc() also has another check to see if you've completely filled your transmit buffer - if it is full, the code just waits in the while loop for the TBE routine to transmit another character.

The TBE routine just sends the current character and increments the "pointer" that will let it know which character has to be sent next time around. It also performs a check to see if there are any unsent characters left in the buffer (filled by bputc()), and if there aren't, it disables any further TBE interrupts.

Clear?


Hi newguy,

thank you too for taking time to explain the routines to me, I can say that I understood the essential of both of them. I think that basically, I was confused because of the name of the routine TBE (Transmit Buffer Empty) which led me to assume that this interruption is only enabled when the buffer is empty (totally empty).

Just to verify my understanding: in the other side (I mean the receiver microcontroller), the RDA routine and bgetc() (associated with bkhit()) are doing basically the same work but in reception as the TBE and bputc() in trasmission. is it right ?
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 8:19 pm     Reply with quote

Right. RDA = Receive Data Available. It only "fires" when the USART receives a valid character. The CCS example (I think it's called EX_SISR.c) simply retrieves the last character and places it in the receive buffer.
Salenko



Joined: 08 Sep 2008
Posts: 84

View user's profile Send private message

PostPosted: Fri Oct 24, 2008 7:45 am     Reply with quote

newguy wrote:
Right. RDA = Receive Data Available. It only "fires" when the USART receives a valid character. The CCS example (I think it's called EX_SISR.c) simply retrieves the last character and places it in the receive buffer.


Hi newguy,

right, it is called EX_SISR.C

thank you for your explanations. Wink
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