2009-01-22 19:46:47 +00:00
|
|
|
// eLua "char device" buffering system
|
|
|
|
|
|
|
|
#ifndef __BUF_H__
|
|
|
|
#define __BUF_H__
|
|
|
|
|
|
|
|
#include "type.h"
|
|
|
|
|
|
|
|
// [TODO] the buffer data type is currently u8, is this OK?
|
|
|
|
typedef u8 t_buf_data;
|
|
|
|
|
|
|
|
// IDs of "bufferable" devices
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BUF_ID_UART = 0,
|
- Buffer refactored to handle multibyte data.
Code which was previously using buffer has been updated to work with the
changes.
API has also changed in accordance:
int buf_set(unsigned resid, unsigned resnum, u8 logsize, size_t dsize);
int buf_is_enabled( unsigned resid, unsigned resnum );
unsigned buf_get_size( unsigned resid, unsigned resnum );
unsigned buf_get_count( unsigned resid, unsigned resnum );
int buf_write( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
Essentially buf_rx_cb and buf_get_char have been renamed to buf_write and
buf_read. For these, one now passes a pointer to where the data is coming
from or going to, and a dsize parameter indicating how many bytes should be
copied. Also, buf_set takes this same dsize parameter, and keeps it in the
struct. This allows us to ensure that when data is read or written the
number of bytes matches the buffer element size.
I thought about maintaining compatibility functions to provide the original
buf_rx_cb and buf_get_byte API calls, however there weren't a large number
of uses of buf, so it wasn't hard to convert things.
One caveat: BUF_MOD_INCR assumes that byte counts for alternate type sizes
will be powers of 2.
Also, BUF_SIZE_xx's are assumed to refer to element counts.
- UART buffering enabled on LM3S
This doesn't include switching the ADC code over to using these buffers quite
yet.
I'm open to comments on these modifications if theres a better or simpler
approach. I've checked to make sure buffers work on LM3S, but I don't own any
other platforms to make sure there aren't unintended side-effects.
2009-02-09 03:43:47 +00:00
|
|
|
BUF_ID_ADC = 1,
|
2009-01-22 19:46:47 +00:00
|
|
|
BUF_ID_FIRST = BUF_ID_UART,
|
- Buffer refactored to handle multibyte data.
Code which was previously using buffer has been updated to work with the
changes.
API has also changed in accordance:
int buf_set(unsigned resid, unsigned resnum, u8 logsize, size_t dsize);
int buf_is_enabled( unsigned resid, unsigned resnum );
unsigned buf_get_size( unsigned resid, unsigned resnum );
unsigned buf_get_count( unsigned resid, unsigned resnum );
int buf_write( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
Essentially buf_rx_cb and buf_get_char have been renamed to buf_write and
buf_read. For these, one now passes a pointer to where the data is coming
from or going to, and a dsize parameter indicating how many bytes should be
copied. Also, buf_set takes this same dsize parameter, and keeps it in the
struct. This allows us to ensure that when data is read or written the
number of bytes matches the buffer element size.
I thought about maintaining compatibility functions to provide the original
buf_rx_cb and buf_get_byte API calls, however there weren't a large number
of uses of buf, so it wasn't hard to convert things.
One caveat: BUF_MOD_INCR assumes that byte counts for alternate type sizes
will be powers of 2.
Also, BUF_SIZE_xx's are assumed to refer to element counts.
- UART buffering enabled on LM3S
This doesn't include switching the ADC code over to using these buffers quite
yet.
I'm open to comments on these modifications if theres a better or simpler
approach. I've checked to make sure buffers work on LM3S, but I don't own any
other platforms to make sure there aren't unintended side-effects.
2009-02-09 03:43:47 +00:00
|
|
|
BUF_ID_LAST = BUF_ID_ADC,
|
2009-01-22 19:46:47 +00:00
|
|
|
BUF_ID_TOTAL = BUF_ID_LAST - BUF_ID_FIRST + 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// This structure describes a buffer
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
u8 logsize;
|
|
|
|
volatile u16 wptr, rptr, count;
|
|
|
|
t_buf_data *buf;
|
2009-02-10 05:50:48 +00:00
|
|
|
u8 logdsize;
|
2009-01-22 19:46:47 +00:00
|
|
|
} buf_desc;
|
|
|
|
|
|
|
|
// Buffer sizes (there are power of 2 to speed up modulo operations)
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BUF_SIZE_NONE = 0,
|
|
|
|
BUF_SIZE_16 = 4,
|
|
|
|
BUF_SIZE_32,
|
|
|
|
BUF_SIZE_64,
|
|
|
|
BUF_SIZE_128,
|
|
|
|
BUF_SIZE_256,
|
|
|
|
BUF_SIZE_512,
|
|
|
|
BUF_SIZE_1024,
|
|
|
|
BUF_SIZE_2048,
|
|
|
|
BUF_SIZE_4096,
|
|
|
|
BUF_SIZE_8192,
|
|
|
|
BUF_SIZE_16384,
|
|
|
|
BUF_SIZE_32768
|
|
|
|
};
|
|
|
|
|
- Buffer refactored to handle multibyte data.
Code which was previously using buffer has been updated to work with the
changes.
API has also changed in accordance:
int buf_set(unsigned resid, unsigned resnum, u8 logsize, size_t dsize);
int buf_is_enabled( unsigned resid, unsigned resnum );
unsigned buf_get_size( unsigned resid, unsigned resnum );
unsigned buf_get_count( unsigned resid, unsigned resnum );
int buf_write( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
Essentially buf_rx_cb and buf_get_char have been renamed to buf_write and
buf_read. For these, one now passes a pointer to where the data is coming
from or going to, and a dsize parameter indicating how many bytes should be
copied. Also, buf_set takes this same dsize parameter, and keeps it in the
struct. This allows us to ensure that when data is read or written the
number of bytes matches the buffer element size.
I thought about maintaining compatibility functions to provide the original
buf_rx_cb and buf_get_byte API calls, however there weren't a large number
of uses of buf, so it wasn't hard to convert things.
One caveat: BUF_MOD_INCR assumes that byte counts for alternate type sizes
will be powers of 2.
Also, BUF_SIZE_xx's are assumed to refer to element counts.
- UART buffering enabled on LM3S
This doesn't include switching the ADC code over to using these buffers quite
yet.
I'm open to comments on these modifications if theres a better or simpler
approach. I've checked to make sure buffers work on LM3S, but I don't own any
other platforms to make sure there aren't unintended side-effects.
2009-02-09 03:43:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-22 19:46:47 +00:00
|
|
|
// Buffer API
|
- Buffer refactored to handle multibyte data.
Code which was previously using buffer has been updated to work with the
changes.
API has also changed in accordance:
int buf_set(unsigned resid, unsigned resnum, u8 logsize, size_t dsize);
int buf_is_enabled( unsigned resid, unsigned resnum );
unsigned buf_get_size( unsigned resid, unsigned resnum );
unsigned buf_get_count( unsigned resid, unsigned resnum );
int buf_write( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
Essentially buf_rx_cb and buf_get_char have been renamed to buf_write and
buf_read. For these, one now passes a pointer to where the data is coming
from or going to, and a dsize parameter indicating how many bytes should be
copied. Also, buf_set takes this same dsize parameter, and keeps it in the
struct. This allows us to ensure that when data is read or written the
number of bytes matches the buffer element size.
I thought about maintaining compatibility functions to provide the original
buf_rx_cb and buf_get_byte API calls, however there weren't a large number
of uses of buf, so it wasn't hard to convert things.
One caveat: BUF_MOD_INCR assumes that byte counts for alternate type sizes
will be powers of 2.
Also, BUF_SIZE_xx's are assumed to refer to element counts.
- UART buffering enabled on LM3S
This doesn't include switching the ADC code over to using these buffers quite
yet.
I'm open to comments on these modifications if theres a better or simpler
approach. I've checked to make sure buffers work on LM3S, but I don't own any
other platforms to make sure there aren't unintended side-effects.
2009-02-09 03:43:47 +00:00
|
|
|
int buf_set(unsigned resid, unsigned resnum, u8 logsize, size_t dsize);
|
2009-01-22 19:46:47 +00:00
|
|
|
int buf_is_enabled( unsigned resid, unsigned resnum );
|
|
|
|
unsigned buf_get_size( unsigned resid, unsigned resnum );
|
|
|
|
unsigned buf_get_count( unsigned resid, unsigned resnum );
|
- Buffer refactored to handle multibyte data.
Code which was previously using buffer has been updated to work with the
changes.
API has also changed in accordance:
int buf_set(unsigned resid, unsigned resnum, u8 logsize, size_t dsize);
int buf_is_enabled( unsigned resid, unsigned resnum );
unsigned buf_get_size( unsigned resid, unsigned resnum );
unsigned buf_get_count( unsigned resid, unsigned resnum );
int buf_write( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
Essentially buf_rx_cb and buf_get_char have been renamed to buf_write and
buf_read. For these, one now passes a pointer to where the data is coming
from or going to, and a dsize parameter indicating how many bytes should be
copied. Also, buf_set takes this same dsize parameter, and keeps it in the
struct. This allows us to ensure that when data is read or written the
number of bytes matches the buffer element size.
I thought about maintaining compatibility functions to provide the original
buf_rx_cb and buf_get_byte API calls, however there weren't a large number
of uses of buf, so it wasn't hard to convert things.
One caveat: BUF_MOD_INCR assumes that byte counts for alternate type sizes
will be powers of 2.
Also, BUF_SIZE_xx's are assumed to refer to element counts.
- UART buffering enabled on LM3S
This doesn't include switching the ADC code over to using these buffers quite
yet.
I'm open to comments on these modifications if theres a better or simpler
approach. I've checked to make sure buffers work on LM3S, but I don't own any
other platforms to make sure there aren't unintended side-effects.
2009-02-09 03:43:47 +00:00
|
|
|
int buf_write( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
|
|
|
|
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data, size_t dsize );
|
|
|
|
|
2009-01-22 19:46:47 +00:00
|
|
|
|
|
|
|
#endif
|