1 #include <system_def.h>
3 #include <hal_machperiph.h>
8 #define IAP_CMD_PREPARE 50
9 #define IAP_CMD_WRITE 51
10 #define IAP_CMD_ERASE 52
11 #define IAP_CMD_READ_PARTID 54
16 extern void iap_asm_entry (unsigned int *,unsigned int *);
17 #define iap_entry iap_asm_entry
20 inline int addr2sec(unsigned long addr)
24 #elif defined INC_LPC214x_H
25 inline int addr2sec(unsigned long addr)
27 if (addr<0x8000) return (addr>>12);
28 else if (addr<0x78000) return (addr>>15)+7;
29 else return 22+((addr&0x7fff)>>12);
32 #error "Undefined type of CPU for function addr2sec!"
35 int lpcisp_read_partid()
37 command[0] = IAP_CMD_READ_PARTID;
38 iap_entry(command, result);
42 int lpcisp_prepare_sectors(unsigned char start, unsigned char end)
44 command[0] = IAP_CMD_PREPARE;
47 command[3] = FOSC/1000;
49 iap_entry(command, result);
51 return (CMD_SUCCESS == *result);
54 int lpcisp_erase_sectors(unsigned char start, unsigned char end)
56 command[0] = IAP_CMD_ERASE;
59 command[3] = FOSC/1000;
61 iap_entry(command, result);
63 return (CMD_SUCCESS == *result);
66 int lpcisp_erase(void *addr, int len)
71 start=addr2sec((unsigned long)addr);
72 end=addr2sec((unsigned long)addr+len-1);
74 if (end<start) return 0;
79 lpcisp_prepare_sectors(start,end);
80 if (CMD_SUCCESS != *result) return 0;
82 lpcisp_erase_sectors(start,end);
87 return (CMD_SUCCESS == *result);
90 int lpcisp_write(void *addr_des, const void *addr_src, int len)
95 start=addr2sec((unsigned long)addr_des);
101 lpcisp_prepare_sectors(start,end);
102 if (CMD_SUCCESS != *result) return 0;
104 command[0] = IAP_CMD_WRITE;
105 command[1] = (unsigned int)addr_des;
106 command[2] = (unsigned int)addr_src;
108 command[4] = FOSC/1000;
110 iap_entry(command, result);
113 restore_flags(flags);
115 return (CMD_SUCCESS == *result);