FIFO Library
Software FIFO
Main Page
Related Pages
Modules
Data Structures
Files
All
Data Structures
Functions
Variables
Typedefs
Groups
Pages
fifo.h
/*****************************************************************************
Software FIFO using circular buffer
structs and generic functions to increase usability
Copyright (C) 2015 Falk Brunner
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
You can contact the author at Falk.Brunner@gmx.de
*****************************************************************************/
#ifndef _FIFO_H
#define _FIFO_H
typedef
uint8_t
fifo_data_t
;
typedef
uint16_t
fifo_size_t
;
typedef
struct
{
fifo_data_t
volatile
*
volatile
write_p;
fifo_data_t
volatile
*
volatile
read_p;
fifo_data_t
volatile
*
volatile
base;
fifo_data_t
volatile
*
volatile
top;
fifo_size_t
volatile
size;
}
fifo_t
;
//-FUNCTIONS---------------------------------------------------------------------------------------------------------
void
fifo_init
(
fifo_t
*fifo,
fifo_data_t
*data,
fifo_size_t
size);
void
fifo_write
(
fifo_t
*fifo,
fifo_data_t
data);
void
fifo_write_busy
(
fifo_t
*fifo,
fifo_data_t
data);
fifo_data_t
fifo_read_busy
(
fifo_t
*fifo);
fifo_data_t
fifo_read
(
fifo_t
*fifo);
fifo_size_t
fifo_get_level
(
fifo_t
*fifo);
fifo_size_t
fifo_get_free
(
fifo_t
*fifo);
void
fifo_write_bursted
(
fifo_t
*fifo,
fifo_size_t
count);
void
fifo_read_bursted
(
fifo_t
*fifo,
fifo_size_t
count);
fifo_size_t
fifo_get_write_wrap
(
fifo_t
*fifo);
fifo_size_t
fifo_get_read_wrap
(
fifo_t
*fifo);
//-ISR FUNCTIONS---------------------------------------------------------------------------------------------------------
inline
void
fifo_write_ISR
(
fifo_t
*fifo,
fifo_data_t
data);
inline
fifo_data_t
fifo_read_ISR
(
fifo_t
*fifo);
inline
fifo_size_t
fifo_get_level_ISR
(
fifo_t
*fifo);
inline
fifo_size_t
fifo_get_free_ISR
(
fifo_t
*fifo);
//- INLINE FUNCTIONS ------------------------------------------------------------------------------------------------------------------
inline
fifo_data_t
fifo_read_ISR
(
fifo_t
*fifo) {
fifo_data_t
data;
fifo_data_t
*tmp;
tmp = (
fifo_data_t
*)fifo->
read_p
;
data = *tmp++;
if (tmp > fifo->
top
) {
fifo->
read_p
= fifo->
base
;
}
else
{
fifo->
read_p
= tmp;
}
return
data;
}
inline
void
fifo_write_ISR
(
fifo_t
*fifo,
fifo_data_t
data) {
fifo_data_t
*tmp;
tmp = (
fifo_data_t
*)fifo->
write_p
;
*tmp++ = data;
if (tmp > fifo->
top
) {
fifo->
write_p
= fifo->
base
;
}
else
{
fifo->
write_p
= tmp;
}
}
inline
fifo_size_t
fifo_get_level_ISR
(
fifo_t
*fifo) {
fifo_size_t
tmp;
fifo_data_t
*tmp_w, *tmp_r;
tmp_w = (
fifo_data_t
*)fifo->
write_p
;
tmp_r = (
fifo_data_t
*)fifo->
read_p
;
tmp = tmp_w - tmp_r;
if
(tmp_w < tmp_r) {
tmp += fifo->
size
;
}
return
tmp;
}
inline
fifo_size_t
fifo_get_free_ISR
(
fifo_t
*fifo) {
fifo_size_t
tmp;
fifo_data_t
*tmp_w, *tmp_r;
tmp_w = (
fifo_data_t
*)fifo->
write_p
;
tmp_r = (
fifo_data_t
*)fifo->
read_p
;
tmp = tmp_w - tmp_r;
if
(tmp_w < tmp_r) {
tmp += fifo->
size
;
}
return
(fifo->
size
- tmp - 1);
}
#endif
Generated on Wed Sep 30 2015 08:34:36 for FIFO Library by
1.8.6