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

Software Buffer for UART, problem

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








Software Buffer for UART, problem
PostPosted: Mon Apr 14, 2008 10:15 am     Reply with quote

Hi

I use a software UART, this part is working.

I want to imp. a buffer of 10 char, but I have lot of problem to get it work.

Some code...

Code:

#define com_buffer_max 10   //set buffer length
#define com_buffer_clear 255 //define empty buffer data

struct _com_buffer{
           int buffer[com_buffer_max+2];
           int rbcnt; //counter to read from buffer
           int wbcnt; //counter to write from buffer
           int1 ok;       //buffer data is ok
}com_buffer;

//**data to the buffer**//
void com_buffer_w(int c){
  com_buffer.buffer[com_buffer.wbcnt++] =c;
 
  if (com_buffer.wbcnt > com_buffer_max) com_buffer.wbcnt=0;
 
}

//**read one char from the buffer, the buffer pointer move one step forward**//
int com_buffer_r(void){
 int c;
 
 if (com_buffer.buffer[com_buffer.rbcnt] != com_buffer_clear){
  c=com_buffer.buffer[com_buffer.rbcnt];
  com_buffer.buffer[com_buffer.rbcnt]=com_buffer_clear;
  com_buffer.rbcnt++;
  if (com_buffer.rbcnt > com_buffer_max) com_buffer.rbcnt=0;
  com_buffer.ok=1;
 }
 else{
  com_buffer.ok =0;
  c=com_buffer_clear;
 }
 return c;
}



Init buffer before use:
Code:
//init com buffer.
void com_buffer_init(void){
 int i;
 for (i=0; i<=com_buffer_max; i++) com_buffer.buffer[i]=com_buffer_clear;
 com_buffer.wbcnt=0;
 com_buffer.rbcnt=0;
 com_buffer.ok =0;
}



Write to the buffer:
Code:
com_buffer_w(i);


Read the buffer:
Code:
data = com_buffer_r();
  if (com_buffer_kbhit()){
....
}



Any sugest, or maybe some ex. of working buffer.

/F
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 10:53 am     Reply with quote

Look at the sample code in Ex_Sisr.c
Quote:
c:\program files\picc\examples\ex_sisr.c
Guest








PostPosted: Tue Apr 15, 2008 5:07 am     Reply with quote

Look here...
ganssle.com/tem/tem110.pdf
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