32 #include "avrmalloc.h" 43 storage_new (
int base,
int size)
48 storage_construct (stor, base, size);
55 storage_construct (Storage *stor,
int base,
int size)
65 stor->data =
avr_new0 (uint8_t, size);
73 storage_destroy (
void *stor)
83 storage_readb (Storage *stor,
int addr);
85 extern inline uint16_t
86 storage_readw (Storage *stor,
int addr);
89 storage_writeb (Storage *stor,
int addr, uint8_t val)
91 int _addr = addr - stor->base;
96 if ((_addr < 0) || (_addr >= stor->size))
97 avr_error (
"address out of bounds: 0x%x", addr);
99 stor->data[_addr] = val;
103 storage_writew (Storage *stor,
int addr, uint16_t val)
105 int _addr = addr - stor->base;
110 if ((_addr < 0) || (_addr >= stor->size))
111 avr_error (
"address out of bounds: 0x%x", addr);
113 stor->data[_addr] = (uint8_t) (val >> 8 & 0xff);
114 stor->data[_addr + 1] = (uint8_t) (val & 0xff);
118 storage_get_size (Storage *stor)
124 storage_get_base (Storage *stor)
#define avr_new0(type, count)
Macro for allocating memory and initializing it to zero.
void avr_free(void *ptr)
Free malloc'd memory.
void class_destroy(void *klass)
Releases resources allocated by class's <klass>_new() function.
#define avr_error(fmt, args...)
Print an error message to stderr and terminate program.
#define avr_new(type, count)
Macro for allocating memory.
void class_overload_destroy(AvrClass *klass, AvrClassFP_Destroy destroy)
Overload the default destroy method.
void class_construct(AvrClass *klass)
Initializes the AvrClass data structure.