add support for extra write data string.

This commit is contained in:
Mariano Alvira 2009-05-09 14:43:17 -04:00
parent 04286f8aa7
commit a0db791175

View file

@ -20,24 +20,37 @@
#define DELAY 400000
#define DEBUG 1
#if DEBUG
void putc(uint8_t c);
void puts(uint8_t *s);
void put_hex(uint8_t x);
void put_hex16(uint16_t x);
void put_hex32(uint32_t x);
uint8_t getc();
void flushrx();
const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'};
#else
#define putc(...)
#define puts(...)
#define put_hex(...)
#define put_hex16(...)
#define put_hex32(...)
#endif
uint8_t getc(void);
void flushrx(void);
uint32_t to_u32(char *c);
#include "isr.h"
#define NBYTES 8
#define WRITE_ADDR 0x1e000
//#define WRITE_ADDR 0x0
#define WRITEVAL0 0x00000001
#define WRITEVAL1 0x00000000
#define NBYTES 16
enum parse_states {
SCAN_X,
READ_CHARS,
PROCESS,
MAX_STATE,
};
__attribute__ ((section ("startup")))
void main(void) {
@ -47,6 +60,8 @@ void main(void) {
volatile uint32_t buf[NBYTES/4];
volatile uint32_t i;
volatile uint32_t len=0;
volatile uint32_t state = SCAN_X;
volatile uint32_t addr,data;
*(volatile uint32_t *)GPIO_PAD_DIR0 = 0x00000100;
@ -140,12 +155,55 @@ void main(void) {
puts("flasher done\n\r");
while(c=getc()) {putc(c);}
state = SCAN_X; addr=0;
while((c=getc())) {
putc(c);
if(state == SCAN_X) {
puts("scanx\n\r");
/* read until we see an 'x' */
if(c==0) { break; }
if(c!='x'){ continue; }
/* go to read_chars once we have an 'x' */
state = READ_CHARS;
i = 0;
}
if(state == READ_CHARS) {
puts("readchars i ");
put_hex(i);
puts(" c ");
putc(c);
puts("\n\r");
/* read all the chars up to a ',' */
((uint8_t *)buf)[i++] = c;
/* after reading a ',' */
/* goto PROCESS state */
if((c == ',') || (c == 0)) { state = PROCESS; }
}
if(state == PROCESS) {
puts("process\n\r");
if(addr==0) {
/*interpret the string as the starting address */
addr = to_u32((uint8_t *)buf);
} else {
/* string is data to write */
data = to_u32((uint8_t *)buf);
puts("writing addr ");
put_hex32(addr);
puts(" data ");
put_hex32(data);
puts("\n\r");
err = nvm_write(gNvmInternalInterface_c, 1, (uint8_t *)&data, addr, 4);
addr += 4;
}
/* look for the next 'x' */
state=SCAN_X;
}
}
while(1) {continue;};
}
void flushrx()
void flushrx(void)
{
volatile uint8_t c;
while(reg(UR1CON) !=0) {
@ -153,7 +211,48 @@ void flushrx()
}
}
uint8_t getc()
/* Convert from ASCII hex. Returns
the value, or 16 if it was space/newline, or
32 if some other character. */
uint8_t from_hex(uint8_t ch)
{
if(ch==' ' || ch=='\r' || ch=='\n')
return 16;
if(ch < '0')
goto bad;
if(ch <= '9')
return ch - '0';
ch |= 0x20;
if(ch < 'a')
goto bad;
if(ch <= 'f')
return ch - 'a' + 10;
bad:
return 32;
}
uint32_t to_u32(char *c)
{
volatile uint32_t ret=0;
volatile uint32_t i,val;
/* c should be /x\d+,/ */
i=1; /* skip x */
while(c[i] != ',') {
puts("to_u32 on ");
putc(c[i]);
puts(" with i ");
put_hex(i);
puts("\n\r");
ret = ret<<4;
val = from_hex(c[i++]);
ret += val;
}
return ret;
}
uint8_t getc(void)
{
volatile uint8_t c;
while(reg(UR1CON) == 0);