m3dev

cortex m3 debug tools -- superceded by mdebug
git clone http://frotz.net/git/m3dev.git
Log | Files | Refs | README | LICENSE

iap.c (987B)


      1 #include <fw/types.h>
      2 
      3 #include <arch/cpu.h>
      4 #include <arch/iap.h>
      5 
      6 #define IAP_OP_PREPARE		50
      7 #define IAP_OP_WRITE		51
      8 #define IAP_OP_ERASE_SECTOR	52
      9 #define IAP_OP_BLANK_CHECK	53
     10 #define IAP_OP_READ_PART_ID	54
     11 #define IAP_OP_READ_BOOT_VERS	55
     12 #define IAP_OP_COMPARE		56
     13 #define IAP_OP_REINVOKE_ISP	57
     14 #define IAP_OP_READ_UID		58
     15 #define IAP_OP_ERASE_PAGE	59
     16 #define IAP_OP_EEPROM_WRITE	61
     17 #define IAP_OP_EEPROM_READ	62
     18 
     19 void (*romcall)(u32 *in, u32 *out) = (void*) 0x1fff1ff1;
     20 
     21 static int iap_eeprom_op(u32 op, void *buf, unsigned addr, int len)
     22 {
     23 	u32 in[5];
     24 	u32 out[4];
     25 
     26 	in[0] = op;
     27 	in[1] = addr;
     28 	in[2] = (u32) buf;
     29 	in[3] = len;
     30 	in[4] = 48000;
     31 
     32 	disable_interrupts();
     33 	romcall(in, out);
     34 	enable_interrupts();
     35 
     36 	return -((int)out[0]);
     37 }
     38 
     39 int iap_eeprom_read(void *buf, unsigned addr, int len)
     40 {
     41 	return iap_eeprom_op(IAP_OP_EEPROM_READ, buf, addr, len);
     42 }
     43 
     44 int iap_eeprom_write(unsigned addr, void *buf, int len)
     45 {
     46 	return iap_eeprom_op(IAP_OP_EEPROM_WRITE, buf, addr, len);
     47 }
     48