-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixes #50
- Loading branch information
Showing
17 changed files
with
423 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
project(Drivers) | ||
add_library(${PROJECT_NAME} STATIC bno055.c sbus.c bno055_uart.c ppm.c protobuf.c) | ||
add_library(${PROJECT_NAME} STATIC bno055.c sbus.c bno055_uart.c ppm.c protobuf.c ring_buffer.c) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC AvrHAL ToolboxPlaneMessages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @file ring_buffer.c | ||
* @author Paul Nykiel | ||
* @date 27.12.22 | ||
* @brief Implemtation of the fixed-size, byte sized object ring-buffer utility module . | ||
* @ingroup Drivers | ||
*/ | ||
#include "ring_buffer.h" | ||
|
||
ring_buffer_data_t ring_buffer_init(void) { | ||
ring_buffer_data_t uart_buffer_data = {.buf = {0}, .read_index = 0, .len = 0}; | ||
return uart_buffer_data; | ||
} | ||
|
||
bool ring_buffer_put(ring_buffer_data_t *ring_buffer_data, uint8_t data) { | ||
if (ring_buffer_data->len == RING_BUFFER_SIZE) { | ||
return false; | ||
} | ||
uint16_t index = (ring_buffer_data->read_index + ring_buffer_data->len) % RING_BUFFER_SIZE; | ||
ring_buffer_data->buf[index] = data; | ||
ring_buffer_data->len += 1; | ||
return true; | ||
} | ||
|
||
bool ring_buffer_get(ring_buffer_data_t *ring_buffer_data, uint8_t *out) { | ||
if (ring_buffer_data->len > 0) { | ||
*out = ring_buffer_data->buf[ring_buffer_data->read_index]; | ||
ring_buffer_data->read_index = (ring_buffer_data->read_index + 1) % RING_BUFFER_SIZE; | ||
ring_buffer_data->len -= 1; | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @file ring_buffer.h | ||
* @author Paul Nykiel | ||
* @date 27.12.22 | ||
* @brief Declaration of the fixed-size, byte sized object ring-buffer utility module . | ||
* @ingroup Drivers | ||
*/ | ||
#ifndef FLIGHTCONTROLLER_RING_BUFFER_H | ||
#define FLIGHTCONTROLLER_RING_BUFFER_H | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
/** | ||
* Size of the ring-buffer, i.e. number of elements/bytes. | ||
*/ | ||
enum { RING_BUFFER_SIZE = 512 }; | ||
|
||
/** | ||
* Internal data for the ring buffer | ||
*/ | ||
typedef struct { | ||
uint8_t buf[RING_BUFFER_SIZE]; ///< Buffer for the data | ||
uint16_t read_index; ///< Index of the next data to read (i.e. oldest data) | ||
uint16_t len; ///< Number of elements | ||
} ring_buffer_data_t; | ||
|
||
/** | ||
* Create a correctly initialized ring_buffer_data_t object. | ||
* @return an ring_buffer_data_t for usage with the other functions. | ||
*/ | ||
ring_buffer_data_t ring_buffer_init(void); | ||
|
||
/** | ||
* Write a byte to the ring buffer. | ||
* @param ring_buffer_data the internal data of the ring-buffer | ||
* @param data the byte to add | ||
* @return true if the object could be added, false if the buffer is already full | ||
*/ | ||
bool ring_buffer_put(ring_buffer_data_t *ring_buffer_data, uint8_t data); | ||
|
||
/** | ||
* Get a byte from the ring buffer if available. | ||
* @param ring_buffer_data the internal data of the ring-buffer | ||
* @param out the byte that got read | ||
* @return true if a byte was available, otherwise false | ||
*/ | ||
bool ring_buffer_get(ring_buffer_data_t *ring_buffer_data, uint8_t *out); | ||
|
||
#endif // FLIGHTCONTROLLER_RING_BUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.