- Read/write bytes of EEPROM memory
- Test application
./main.py --help
./main.py read 0 512
./main.py write 0x01F0 0x55
- config.h
#ifndef CONFIG_H
#define CONFIG_H
#include BOARD_H
#define UART HW_SWUARTA( txd, DIABOLO_PIN_TX, \
rxd, DIABOLO_PIN_RX, \
startirq, (DIABOLO_PIN_RX,port,pcic,irq), \
counter, counter1, \
compare, compare0, \
clkdiv, 1, \
autosync, 51, \
fastreg, (shared,gpior0) )
#endif
- main.c
#include "config.h"
uint8_t uart_getbyte ( )
{
while ( !
hw(stat,UART).rxc )
}
void uart_putbyte ( uint8_t byte )
{
while ( !
hw(stat,UART).txc )
}
static void process ( uint8_t byte )
{
static uint8_t bcount = 0 ;
static union {
uint8_t buf[4] ;
struct {
uint8_t cmd ;
uint16_t addr ;
uint8_t n ;
} ;
} buf ;
if ( bcount == 0 ) {
if ( byte == 'E' || byte == 'e' ) {
buf.cmd = byte ;
bcount++ ;
}
} else if ( bcount < 4 )
buf.buf[bcount++] = byte ;
else {
bcount = 0 ;
if ( byte == '\n'
if ( buf.cmd == 'E' )
hw( write, eeprom0, buf.addr, buf.n );
else {
while ( buf.n-- ) {
uint8_t
byte =
hw( read, eeprom0, buf.addr );
uart_putbyte( byte );
buf.addr++ ;
}
}
uart_putbyte( '$' );
return ;
}
uart_putbyte( '!' );
}
}
int
main ( )
{
sleep, enabled,
sleep_mode, idle );
hw( enable, interrupts );
while ( !
hw(stat,UART).sync )
uart_putbyte( '$');
for(;;) {
if (
hw(stat,UART).rxc ) {
process(
hw( read, UART) );
}
}
}