This file controls the software Serial FIFO management.
Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
#include "compiler.h"
Data Structures | |
struct | ser_fifo_desc |
FIFO descriptor used by FIFO driver. More... | |
Typedefs | |
typedef struct ser_fifo_desc | ser_fifo_desc_t |
Enumerations | |
enum | { SER_FIFO_OK = 0, SER_FIFO_ERROR_OVERFLOW, SER_FIFO_ERROR_UNDERFLOW, SER_FIFO_ERROR } |
Error codes used by SERIAL FIFO driver. More... | |
Functions | |
static void | ser_fifo_flush (ser_fifo_desc_t *ser_fifo_desc) |
Flushes a software FIFO. More... | |
static uint8_t | ser_fifo_get_free_size (ser_fifo_desc_t *ser_fifo_desc) |
Returns the remaining free spaces of the FIFO (in number of elements). More... | |
static uint16_t | ser_fifo_get_used_size (ser_fifo_desc_t *ser_fifo_desc) |
Returns the number of elements in the FIFO. More... | |
int | ser_fifo_init (ser_fifo_desc_t *ser_fifo_desc, void *buffer, uint16_t size) |
Initializes a new software FIFO for a certain 'size'. More... | |
static bool | ser_fifo_is_empty (ser_fifo_desc_t *ser_fifo_desc) |
Tests if a FIFO is empty. More... | |
static bool | ser_fifo_is_full (ser_fifo_desc_t *ser_fifo_desc) |
Tests if a FIFO is full. More... | |
static uint16_t | ser_fifo_peek_uint16 (ser_fifo_desc_t *ser_fifo_desc) |
Gets a 16-bits element from the FIFO but does not remove it from the FIFO. More... | |
static uint32_t | ser_fifo_peek_uint32 (ser_fifo_desc_t *ser_fifo_desc) |
Gets a 32-bits element from the FIFO but does not remove it from the FIFO. More... | |
static uint8_t | ser_fifo_peek_uint8 (ser_fifo_desc_t *ser_fifo_desc) |
Gets a 8-bits element from the FIFO but does not remove it from the FIFO. More... | |
static int | ser_fifo_pull_uint16 (ser_fifo_desc_t *ser_fifo_desc, uint16_t *item) |
Gets a 16-bits element from the FIFO and checks for a possible underflow. More... | |
static uint16_t | ser_fifo_pull_uint16_nocheck (ser_fifo_desc_t *ser_fifo_desc) |
Gets a 16-bits element from the FIFO. More... | |
static int | ser_fifo_pull_uint32 (ser_fifo_desc_t *ser_fifo_desc, uint32_t *item) |
Gets a 32-bits element from the FIFO and checks for a possible underflow. More... | |
static uint32_t | ser_fifo_pull_uint32_nocheck (ser_fifo_desc_t *ser_fifo_desc) |
Gets a 32-bits element from the FIFO. More... | |
static int | ser_fifo_pull_uint8 (ser_fifo_desc_t *ser_fifo_desc, uint8_t *item) |
Gets a 8-bits element from the FIFO and checks for a possible underflow. More... | |
static uint8_t | ser_fifo_pull_uint8_nocheck (ser_fifo_desc_t *ser_fifo_desc) |
Gets a 8-bits element from the FIFO. More... | |
static int | ser_fifo_push_uint16 (ser_fifo_desc_t *ser_fifo_desc, uint32_t item) |
Puts a new 16-bits element into the FIFO and checks for a possible overflow. More... | |
static void | ser_fifo_push_uint16_nocheck (ser_fifo_desc_t *ser_fifo_desc, uint32_t item) |
Puts a new 16-bits element into the FIFO. More... | |
static int | ser_fifo_push_uint32 (ser_fifo_desc_t *ser_fifo_desc, uint32_t item) |
Puts a new 32-bits element into the FIFO and checks for a possible overflow. More... | |
static void | ser_fifo_push_uint32_nocheck (ser_fifo_desc_t *ser_fifo_desc, uint32_t item) |
Puts a new 32-bits element into the FIFO. More... | |
static int | ser_fifo_push_uint8 (ser_fifo_desc_t *ser_fifo_desc, uint32_t item) |
Puts a new 8-bits element into the FIFO and checks for a possible overflow. More... | |
static void | ser_fifo_push_uint8_nocheck (ser_fifo_desc_t *ser_fifo_desc, uint32_t item) |
Puts a new 8-bits element into the FIFO. More... | |
|
inlinestatic |
Flushes a software FIFO.
ser_fifo_desc | The FIFO descriptor. |
References ser_fifo_desc::read_index, and ser_fifo_desc::write_index.
|
inlinestatic |
Returns the remaining free spaces of the FIFO (in number of elements).
ser_fifo_desc | The FIFO descriptor. |
References ser_fifo_get_used_size(), and ser_fifo_desc::size.
|
inlinestatic |
Returns the number of elements in the FIFO.
ser_fifo_desc | The FIFO descriptor. |
References ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::write_index.
Referenced by ser_fifo_get_free_size(), and ser_fifo_is_full().
|
inlinestatic |
Tests if a FIFO is empty.
ser_fifo_desc | The FIFO descriptor. |
true | when the FIFO is empty. |
false | when the FIFO is not empty. |
References ser_fifo_desc::read_index, and ser_fifo_desc::write_index.
Referenced by ser_fifo_pull_uint16(), ser_fifo_pull_uint32(), and ser_fifo_pull_uint8().
|
inlinestatic |
Tests if a FIFO is full.
ser_fifo_desc | The FIFO descriptor. |
true | when the FIFO is full. |
false | when the FIFO is not full. |
References ser_fifo_get_used_size(), and ser_fifo_desc::size.
Referenced by ser_fifo_push_uint16(), ser_fifo_push_uint32(), and ser_fifo_push_uint8().
|
inlinestatic |
Gets a 16-bits element from the FIFO but does not remove it from the FIFO.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
References ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::u16ptr.
|
inlinestatic |
Gets a 32-bits element from the FIFO but does not remove it from the FIFO.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
References ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::u32ptr.
|
inlinestatic |
Gets a 8-bits element from the FIFO but does not remove it from the FIFO.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
References ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::u8ptr.
|
inlinestatic |
Gets a 16-bits element from the FIFO and checks for a possible underflow.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
FIFO_OK | when no error occurred. |
FIFO_ERROR_UNDERFLOW | when the FIFO was empty. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, SER_FIFO_ERROR_UNDERFLOW, ser_fifo_is_empty(), SER_FIFO_OK, and ser_fifo_desc::u16ptr.
|
inlinestatic |
Gets a 16-bits element from the FIFO.
ser_fifo_desc | The FIFO descriptor. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::u16ptr.
|
inlinestatic |
Gets a 32-bits element from the FIFO and checks for a possible underflow.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
FIFO_OK | when no error occurred. |
FIFO_ERROR_UNDERFLOW | when the FIFO was empty. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, SER_FIFO_ERROR_UNDERFLOW, ser_fifo_is_empty(), SER_FIFO_OK, and ser_fifo_desc::u32ptr.
|
inlinestatic |
Gets a 32-bits element from the FIFO.
ser_fifo_desc | The FIFO descriptor. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::u32ptr.
|
inlinestatic |
Gets a 8-bits element from the FIFO and checks for a possible underflow.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
FIFO_OK | when no error occurred. |
FIFO_ERROR_UNDERFLOW | when the FIFO was empty. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, SER_FIFO_ERROR_UNDERFLOW, ser_fifo_is_empty(), SER_FIFO_OK, and ser_fifo_desc::u8ptr.
|
inlinestatic |
Gets a 8-bits element from the FIFO.
ser_fifo_desc | The FIFO descriptor. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::read_index, and ser_fifo_desc::u8ptr.
|
inlinestatic |
Puts a new 16-bits element into the FIFO and checks for a possible overflow.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
FIFO_OK | when no error occurred. |
FIFO_ERROR_UNDERFLOW | when the FIFO was empty. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, SER_FIFO_ERROR_OVERFLOW, ser_fifo_is_full(), SER_FIFO_OK, ser_fifo_desc::u16ptr, and ser_fifo_desc::write_index.
|
inlinestatic |
Puts a new 16-bits element into the FIFO.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::u16ptr, and ser_fifo_desc::write_index.
|
inlinestatic |
Puts a new 32-bits element into the FIFO and checks for a possible overflow.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
SER_FIFO_OK | when no error occurred. |
SER_FIFO_ERROR_UNDERFLOW | when the FIFO was empty. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, SER_FIFO_ERROR_OVERFLOW, ser_fifo_is_full(), SER_FIFO_OK, ser_fifo_desc::u32ptr, and ser_fifo_desc::write_index.
|
inlinestatic |
Puts a new 32-bits element into the FIFO.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::u32ptr, and ser_fifo_desc::write_index.
|
inlinestatic |
Puts a new 8-bits element into the FIFO and checks for a possible overflow.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
FIFO_OK | when no error occurred. |
FIFO_ERROR_UNDERFLOW | when the FIFO was empty. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, SER_FIFO_ERROR_OVERFLOW, ser_fifo_is_full(), SER_FIFO_OK, ser_fifo_desc::u8ptr, and ser_fifo_desc::write_index.
|
inlinestatic |
Puts a new 8-bits element into the FIFO.
ser_fifo_desc | The FIFO descriptor. |
item | extracted element. |
References barrier, ser_fifo_desc::buffer, ser_fifo_desc::mask, ser_fifo_desc::u8ptr, and ser_fifo_desc::write_index.