mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
You now supply a buffer address and buffer size when initializing the fifo buffer.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2171 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
45b216bf57
commit
912ba59cf9
@ -103,7 +103,7 @@ int16_t fifoBuf_getBytePeek(t_fifo_buffer *buf)
|
|||||||
if (num_bytes < 1)
|
if (num_bytes < 1)
|
||||||
return -1; // no byte retuened
|
return -1; // no byte retuened
|
||||||
|
|
||||||
return buf->buffer[rd]; // return the byte
|
return buf->buf_ptr[rd]; // return the byte
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t fifoBuf_getByte(t_fifo_buffer *buf)
|
int16_t fifoBuf_getByte(t_fifo_buffer *buf)
|
||||||
@ -111,6 +111,7 @@ int16_t fifoBuf_getByte(t_fifo_buffer *buf)
|
|||||||
|
|
||||||
uint16_t rd = buf->rd;
|
uint16_t rd = buf->rd;
|
||||||
uint16_t buf_size = buf->buf_size;
|
uint16_t buf_size = buf->buf_size;
|
||||||
|
uint8_t *buff = buf->buf_ptr;
|
||||||
|
|
||||||
// get number of bytes available
|
// get number of bytes available
|
||||||
uint16_t num_bytes = fifoBuf_getUsed(buf);
|
uint16_t num_bytes = fifoBuf_getUsed(buf);
|
||||||
@ -118,7 +119,7 @@ int16_t fifoBuf_getByte(t_fifo_buffer *buf)
|
|||||||
if (num_bytes < 1)
|
if (num_bytes < 1)
|
||||||
return -1; // no byte returned
|
return -1; // no byte returned
|
||||||
|
|
||||||
uint8_t b = buf->buffer[rd];
|
uint8_t b = buff[rd];
|
||||||
if (++rd >= buf_size)
|
if (++rd >= buf_size)
|
||||||
rd = 0;
|
rd = 0;
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ uint16_t fifoBuf_getDataPeek(t_fifo_buffer *buf, void *data, uint16_t len)
|
|||||||
|
|
||||||
uint16_t rd = buf->rd;
|
uint16_t rd = buf->rd;
|
||||||
uint16_t buf_size = buf->buf_size;
|
uint16_t buf_size = buf->buf_size;
|
||||||
uint8_t *buff = buf->buffer;
|
uint8_t *buff = buf->buf_ptr;
|
||||||
|
|
||||||
// get number of bytes available
|
// get number of bytes available
|
||||||
uint16_t num_bytes = fifoBuf_getUsed(buf);
|
uint16_t num_bytes = fifoBuf_getUsed(buf);
|
||||||
@ -167,7 +168,7 @@ uint16_t fifoBuf_getData(t_fifo_buffer *buf, void *data, uint16_t len)
|
|||||||
|
|
||||||
uint16_t rd = buf->rd;
|
uint16_t rd = buf->rd;
|
||||||
uint16_t buf_size = buf->buf_size;
|
uint16_t buf_size = buf->buf_size;
|
||||||
uint8_t *buff = buf->buffer;
|
uint8_t *buff = buf->buf_ptr;
|
||||||
|
|
||||||
// get number of bytes available
|
// get number of bytes available
|
||||||
uint16_t num_bytes = fifoBuf_getUsed(buf);
|
uint16_t num_bytes = fifoBuf_getUsed(buf);
|
||||||
@ -204,12 +205,13 @@ uint16_t fifoBuf_putByte(t_fifo_buffer *buf, const uint8_t b)
|
|||||||
|
|
||||||
uint16_t wr = buf->wr;
|
uint16_t wr = buf->wr;
|
||||||
uint16_t buf_size = buf->buf_size;
|
uint16_t buf_size = buf->buf_size;
|
||||||
|
uint8_t *buff = buf->buf_ptr;
|
||||||
|
|
||||||
uint16_t num_bytes = fifoBuf_getFree(buf);
|
uint16_t num_bytes = fifoBuf_getFree(buf);
|
||||||
if (num_bytes < 1)
|
if (num_bytes < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
buf->buffer[wr] = b;
|
buff[wr] = b;
|
||||||
if (++wr >= buf_size)
|
if (++wr >= buf_size)
|
||||||
wr = 0;
|
wr = 0;
|
||||||
|
|
||||||
@ -223,7 +225,7 @@ uint16_t fifoBuf_putData(t_fifo_buffer *buf, const void *data, uint16_t len)
|
|||||||
|
|
||||||
uint16_t wr = buf->wr;
|
uint16_t wr = buf->wr;
|
||||||
uint16_t buf_size = buf->buf_size;
|
uint16_t buf_size = buf->buf_size;
|
||||||
uint8_t *buff = buf->buffer;
|
uint8_t *buff = buf->buf_ptr;
|
||||||
|
|
||||||
uint16_t num_bytes = fifoBuf_getFree(buf);
|
uint16_t num_bytes = fifoBuf_getFree(buf);
|
||||||
if (num_bytes > len)
|
if (num_bytes > len)
|
||||||
@ -253,11 +255,12 @@ uint16_t fifoBuf_putData(t_fifo_buffer *buf, const void *data, uint16_t len)
|
|||||||
return i; // return number of bytes copied
|
return i; // return number of bytes copied
|
||||||
}
|
}
|
||||||
|
|
||||||
void fifoBuf_init(t_fifo_buffer *buf)
|
void fifoBuf_init(t_fifo_buffer *buf, const void *buffer, const uint16_t buffer_size)
|
||||||
{
|
{
|
||||||
|
buf->buf_ptr = (uint8_t *)buffer;
|
||||||
buf->rd = 0;
|
buf->rd = 0;
|
||||||
buf->wr = 0;
|
buf->wr = 0;
|
||||||
buf->buf_size = FIFO_BUFFER_SIZE;
|
buf->buf_size = buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
|
@ -28,13 +28,11 @@
|
|||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
#define FIFO_BUFFER_SIZE 1024
|
|
||||||
|
|
||||||
// *********************
|
// *********************
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t buffer[FIFO_BUFFER_SIZE] __attribute__ ((aligned(4)));
|
uint8_t *buf_ptr;
|
||||||
volatile uint16_t rd;
|
volatile uint16_t rd;
|
||||||
volatile uint16_t wr;
|
volatile uint16_t wr;
|
||||||
uint16_t buf_size;
|
uint16_t buf_size;
|
||||||
@ -60,7 +58,7 @@ uint16_t fifoBuf_putByte(t_fifo_buffer *buf, const uint8_t b);
|
|||||||
|
|
||||||
uint16_t fifoBuf_putData(t_fifo_buffer *buf, const void *data, uint16_t len);
|
uint16_t fifoBuf_putData(t_fifo_buffer *buf, const void *data, uint16_t len);
|
||||||
|
|
||||||
void fifoBuf_init(t_fifo_buffer *buf);
|
void fifoBuf_init(t_fifo_buffer *buf, const void *buffer, const uint16_t buffer_size);
|
||||||
|
|
||||||
// *********************
|
// *********************
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user