diff --git a/Makefile b/Makefile index 3d4a2a3f2..f1dc502fa 100644 --- a/Makefile +++ b/Makefile @@ -60,9 +60,9 @@ ALL = $(TESTS:.c=.srec) $(TESTS:.c=.bin) $(TESTS:.c=.dis) all: src/start.o $(ALL) -tests/nvm-read.obj: src/maca.o -tests/rftest-rx.obj: src/maca.o -tests/rftest-tx.obj: src/maca.o +tests/nvm-read.obj: src/maca.o src/nvm.o +tests/rftest-rx.obj: src/maca.o src/nvm.o +tests/rftest-tx.obj: src/maca.o src/nvm.o %.srec: %.obj $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ diff --git a/doc/ws-dis b/doc/ws-dis index dc2808932..1ed0aa14b 100644 --- a/doc/ws-dis +++ b/doc/ws-dis @@ -5422,8 +5422,10 @@ Disassembly of section P2: 4031c6: 2900 cmp r1, #0 4031c8: d1fb bne.n 4031c2 4031ca: e7f2 b.n 4031b2 - 4031cc: 2901 cmp r1, #1 // at this point r1 is between 1 and 15 inclusive + 4031cc: 2901 cmp r1, #1 // 3: at this point r1 is between 1 and 15 inclusive 4031ce: d118 bne.n 403202 // if !=1 return + 4031e2: 2004 movs r0, #4 // return 4 bytes processed + 4031e4: 4770 bx lr 0x00000001 command 0xaaaaaaaa @@ -5445,8 +5447,6 @@ if (buf[0] == 0x00000001) { *buf[2] = (*buf[2] & ~buf[1]) | (buf[3] & buf[1]); } - 4031e2: 2004 movs r0, #4 // return 4 bytes processed - 4031e4: 4770 bx lr 4031e6: 4a09 ldr r2, [pc, #36] (40320c ) //2: r2=0x0000fff1 4031e8: 4291 cmp r1, r2 // r1 >=16 4031ea: d20a bcs.n 403202 // if r1 >= 0xfff1 then return 0 @@ -5460,7 +5460,7 @@ if (buf[0] == 0x00000001) { 4031fa: 4a06 ldr r2, [pc, #24] (403214 ) r2 = &u8RamValues 4031fc: 6800 ldr r0, [r0, #0] // r0 = next value in buffer 2nd half of pair 4031fe: 5450 strb r0, [r2, r1] // store this in u8RamValues - 403200: e7d7 b.n 4031b2 + 403200: e7d7 b.n 4031b2 // return 2 403202: 2000 movs r0, #0 // return 0 403204: 4770 bx lr 403206: 46c0 nop (mov r8, r8) diff --git a/include/maca.h b/include/maca.h index 4be48cc06..e374494c6 100644 --- a/include/maca.h +++ b/include/maca.h @@ -397,6 +397,7 @@ typedef union maca_maskirq_reg_tag uint32_t Reg; } maca_maskirq_reg_t; + #define _is_action_complete_interrupt(x) (0 != (maca_irq_acpl & x)) #define _is_filter_failed_interrupt(x) (0 != (maca_irq_flt & x)) diff --git a/include/nvm.h b/include/nvm.h index edae0030d..e76313c40 100644 --- a/include/nvm.h +++ b/include/nvm.h @@ -1,6 +1,8 @@ #ifndef NVM_H #define NVM_H +#include "embedded_types.h" + typedef enum { gNvmType_NoNvm_c, @@ -34,7 +36,7 @@ typedef enum /* ROM code seems to be THUMB */ /* need to be in a THUMB block before calling them */ -volatile nvmErr_t (*nvm_detect)(nvmInterface_t nvmInterface,nvmType_t* pNvmType) = 0x00006cb9; -volatile nvmErr_t (*nvm_read)(nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes) = 0x00006d69; -volatile void(*nvm_setsvar)(uint32_t zero_for_awesome) = 0x00007085; +extern volatile nvmErr_t (*nvm_detect)(nvmInterface_t nvmInterface,nvmType_t* pNvmType); +extern volatile nvmErr_t (*nvm_read)(nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes); +extern volatile void(*nvm_setsvar)(uint32_t zero_for_awesome); #endif //NVM_H diff --git a/src/maca.c b/src/maca.c index 558fc593e..0d624fd12 100644 --- a/src/maca.c +++ b/src/maca.c @@ -1,8 +1,11 @@ #include "embedded_types.h" #include "maca.h" +#include "nvm.h" #define reg(x) (*(volatile uint32_t *)(x)) +static uint8_t ram_values[4]; + void init_phy(void) { volatile uint32_t cnt; @@ -347,6 +350,66 @@ void set_channel(uint8_t chan) { /* duh! */ } +#define ROM_END 0x0013ffff +#define ENTRY_EOF 0x00000e0f +/* processes up to 4 words of initialization entries */ +/* returns the number of words processed */ +uint8_t exec_init_entry(uint32_t *entries, uint8_t *valbuf) +{ + volatile uint32_t i; + if(entries[0] <= ROM_END) { + if (entries[0] == 0) { + /* do delay command*/ + for(i=0; i= 16) && + (entries[0] < 0xfff1)) { + /* store bytes in valbuf */ + valbuf[(entries[0]>>4)-1] = entries[1]; + return 2; + } else if (entries[0] == ENTRY_EOF) { + return 0; + } else { + /* invalid command code */ + return 0; + } + + } else { /* address isn't in ROM space */ + /* do store value in address command */ + reg(entries[0]) = entries[1]; + return 2; + } +} + + +#define FLASH_INIT_MAGIC 0x00000abc +uint32_t init_from_flash(uint32_t addr) { + nvmType_t type=0; + nvmErr_t err; + uint32_t buf[4]; + uint16_t len; + uint32_t i=0; + err = nvm_detect(gNvmInternalInterface_c, &type); + nvm_setsvar(0); + err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, addr, 8); + i+=8; + if(buf[0] == FLASH_INIT_MAGIC) { + len = buf[1] & 0x0000ffff; + while(i