HRI board firmware  v2.1
Microcontroller firmware of the board used during the HRI labs.
circular_buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 EPFL-LSRO (Laboratoire de Systemes Robotiques).
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __CIRCULAR_BUFFER_H
18 #define __CIRCULAR_BUFFER_H
19 
20 #include "../main.h"
21 
37 typedef struct
38 {
39  uint8_t *buffer;
40  uint16_t bufferSize;
41  volatile uint16_t readIndex,
42  writeIndex;
44 
45 void cb_Init(cb_CircularBuffer* cb, uint8_t *buffer, uint16_t bufferSize);
46 uint16_t cb_ItemsCount(cb_CircularBuffer* cb);
49 void cb_Push(cb_CircularBuffer* cb, uint8_t newElem);
50 uint8_t cb_Pull(cb_CircularBuffer* cb);
51 
56 #endif
bool cb_IsFull(cb_CircularBuffer *cb)
Check if the queue is full.
Definition: circular_buffer.c:65
uint8_t * buffer
Pointer to the byte buffer.
Definition: circular_buffer.h:39
void cb_Push(cb_CircularBuffer *cb, uint8_t newElem)
Add a item at the back of the queue.
Definition: circular_buffer.c:84
uint8_t cb_Pull(cb_CircularBuffer *cb)
Extract the item at the front of the queue. Returns the value of the item at the front of the queue...
Definition: circular_buffer.c:108
volatile uint16_t writeIndex
Index of the next free location at the end of the queue.
Definition: circular_buffer.h:41
void cb_Init(cb_CircularBuffer *cb, uint8_t *buffer, uint16_t bufferSize)
Initializes a cb_CircularBuffer structure. Initializes a cb_CircularBuffer structure with the given b...
Definition: circular_buffer.c:29
bool cb_IsEmpty(cb_CircularBuffer *cb)
Check if the queue is empty.
Definition: circular_buffer.c:55
Circular buffer structure.
Definition: circular_buffer.h:37
uint16_t cb_ItemsCount(cb_CircularBuffer *cb)
Gets the number of bytes stored in the queue.
Definition: circular_buffer.c:42
uint16_t bufferSize
Size of buffer.
Definition: circular_buffer.h:40