Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "at91sam9263.h"
- #include "FIFO.h"
- void FIFO_Init (struct FIFO *Fifo){
- Fifo->head=0;
- Fifo->tail=0;
- /* optional: initialize data in buffer with 0 */
- }
- void FIFO_Empty (struct FIFO *Fifo){
- Fifo->head = Fifo->tail;
- /* now FIFO is empty*/
- }
- int FIFO_Put (struct FIFO *Fifo, char Data){
- if ((Fifo->tail-Fifo->head)==1 || (Fifo->head-Fifo->tail)==BUFFERSIZE) {
- return -1; /* FIFO overflow */
- };
- Fifo->buffer[Fifo->head] = Data;
- Fifo->head = (Fifo->head + 1) & BUFFERSIZE;
- return 1; /* Put 1 byte successfully */
- }
- int FIFO_Get (struct FIFO *Fifo, char *Data){
- if (Fifo->head!=Fifo->tail){
- *Data = Fifo->buffer[Fifo->tail];
- Fifo->tail = (Fifo->tail + 1) & BUFFERSIZE;
- return 1; /* Get 1 byte successfully */
- }
- else return -1; /* No data in FIFO */
- }
- #define BUFFERSIZE 0xF
- typedef struct FIFO {
- char buffer [BUFFERSIZE + 1];
- unsigned int head;
- unsigned int tail;
- } jebac_embedy;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement