This is the original message. Dave's header file only version is essentially the same as my procedural code. The header file version would, naturally, be all inline code and likely tighter for small systems with minimal calls to the fifo routines (or fifo routines buried inside single point of access higher level routines like getc() putc()...)
I thought I was responding to a message to the avr-chat list. Obviously this kind of message isn't appropriate for the Gcc compiler list. I apologize in advance :) -----Original Message----- From: Larry Barello [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 16, 2005 11:53 AM To: 'Dave Hylands' Subject: RE: [avr-gcc-list] Problems with ATMEGA8 USART So, who has the tiniest fifo routine in C? I don't mean lack of text, but size of compiled code. The best I have done is using powers of two with masks on the indexes (32 byte buffer being a convenient size). ----- #define BUFSIZE 32 #define BUFMSK 0x1F #define Nextfifo(A) ((unsigned char)(((A) + 1) & BUFMSK)) #define isEmpty(A) ((A)->in == (A)->out) #define isFull(A) (Nextfifo((A)->in) == (A)->out) typedef struct { volatile unsigned char in; volatile unsigned char out; volatile unsigned char buf[BUFSIZE]; } Fifo, *pFifo; int PutFifo(pFifo p, char c) { unsigned char t = Nextfifo(p->in); if (t == p->out) return -1; else { p->buf[p->in] = c; p->in = t; return 0; } } int PullFifo(pFifo p) { if (isEmpty(p)) return -1; else { int c = p->buf[p->out]; p->out = Nextfifo(p->out); return c; } } void DelLastFifo(pFifo p) { if (!isEmpty(p)) { p->in = (p->in - 1) & BUFMSK; } } void FlushFifo(pFifo p) { p->in = p->out = 0; } -----Original Message----- From: Dave Hylands > Be warned that the head/tail usage can be something of a religious > war with people. There are those who champion the opposite roles > of head/tail, and remember it with "when you join a queue, should you > join at the head or the tail ?" - so if you inherit code, it is > always worth double checking which rule the author is following. I get around this problem with cicular buffers by having get and put ptrs or indicies. It makes it much more obvious what they do. http://lists.nongnu.org/mailman/listinfo/avr-gcc-list _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list