1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00
elua/inc/buf.h
Bogdan Marinescu 45285ea064 - LTR: even if we (obviously) can't set new keys/values in a rotable, we still respect the __newindex metamethod. This allows for interesting tricks, like the one shown below :)
- complete rewrite of the PIO module. New usage:

pio.PA = 10 -- set the value of PA to 10
pio.PB_1 = 1 -- set the value of pin 1 of PB to 1

local value = pio.PB -- get the value of PB
local value = pio.PB_3 -- get the value of pin 3 of PB

pio.PA_DIR = pio.OUTPUT/pio.INPUT - set the direction of PA
pio.dir[ pio.PA ] = pio.OUTPUT/pio.INPUT - same as above

pio.PA_2_DIR = pio.OUTPUT/pio.INPUT - set the direction of pin 2 of PA
pio.dir[ pio.PA_2 ] = pio.OUTPUT/pio.INPUT - same as above

pio.PA_PULL = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - set pulls on PA
pio.pull[ pio.PA ] = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - same as above

pio.P0_3_PULL = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - set pulls on pin 3 of P0
pio.pull[ pio.P0_3 ] = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - same as above

- samples modified to use the new PIO syntax
- bugfix in AT91SAM7X256 UART int handler
- fixed yet another bug in AVR32's libc (actually replaced strcmp (which is broken on AVR32) with a custom version).
2009-02-10 17:54:01 +00:00

61 lines
1.2 KiB
C

// 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,
BUF_ID_ADC = 1,
BUF_ID_FIRST = BUF_ID_UART,
BUF_ID_LAST = BUF_ID_ADC,
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;
u8 logdsize;
} 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 API
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 );
#endif