-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFifo.c
More file actions
54 lines (46 loc) · 1.33 KB
/
Fifo.c
File metadata and controls
54 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// FiFo.c
// Runs on LM4F120/TM4C123
// Provide functions that implement the Software FiFo Buffer
// Last Modified: 4/10/2023
// Student names: Devin Chaky
#include <stdint.h>
// Declare state variables for FiFo
// size, buffer, put and get indexes
#define FIFO_SIZE 16
static char Fifo[FIFO_SIZE];
static uint8_t PutI; // index to put new
static uint8_t GetI; // index of oldest
// *********** FiFo_Init**********
// Initializes a software FIFO of a
// fixed size and sets up indexes for
// put and get operations
void Fifo_Init() {
//Complete this
PutI = 0;
GetI = 0;
}
// *********** FiFo_Put**********
// Adds an element to the FIFO
// Input: Character to be inserted
// Output: 1 for success and 0 for failure
// failure is when the buffer is full
uint32_t Fifo_Put(char data){
//Complete this routine
if(((PutI+1)%FIFO_SIZE) == GetI) return 0; // fail if full
Fifo[PutI] = data;
PutI = (PutI+1)%FIFO_SIZE;
return(1);
}
// *********** Fifo_Get**********
// Gets an element from the FIFO
// Input: none
// Output: If the FIFO is empty return 0
// If the FIFO has data, remove it, and return it
char Fifo_Get(void){
//Complete this routine
uint32_t getData;
if(GetI==PutI) return 0;
getData = Fifo[GetI];
GetI = (GetI+1)%FIFO_SIZE;
return(getData);
}