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

Please explain this line

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








Please explain this line
PostPosted: Sat Dec 20, 2003 4:42 pm     Reply with quote

Please explain this line of ex_sisr.c

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
.....
.....
.....
#int_rda
void serial_isr()
{
int t;

buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE; <----------"What is %. Please examples the number of next_in and the next value of next_in" if(next_in==next_out)
next_in=t; // Buffer full !!
}


What is modules(%) ????????????
KerryW
Guest







PostPosted: Sat Dec 20, 2003 4:48 pm     Reply with quote

Modulus is the remainder after a division.

Example:
30%4=2, because 30/4=7 with a remainder of 2.
dyeatman



Joined: 06 Sep 2003
Posts: 1910
Location: Norman, OK

View user's profile Send private message

Meaning of line
PostPosted: Sat Dec 20, 2003 5:16 pm     Reply with quote

This code is a neat programming trick!

The line: next_in=(next_in+1) % BUFFER_SIZE;

causes the incoming char pointer to bump to the next available buffer location. If it is at the end of Buffer_Size then it will "wrap around" back to the beginning of the buffer. This setup is known as a "ring buffer".

The line: if(next_in==next_out) next_in=t; // Buffer full !!

checks to see if the next char coming in (location of the next_in pointer) will overwrite the next char waiting to be processed out of the ring buffer. If it will, it "resets" the pointer back to the last location used which was saved earlier in variable t.

Dave
cwatters



Joined: 18 Dec 2003
Posts: 5
Location: Belgium

View user's profile Send private message

PostPosted: Sun Dec 21, 2003 1:40 pm     Reply with quote

In effect..

Increment next_in but if the result is greater than buffer_size start again at 0.
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