52 __builtin_tblwtl(u16_addrlo,u16_wordlo);
53 __builtin_tblwth(u16_addrlo,u16_wordhi);
56 #if (defined(__PIC24E__) || defined(__dsPIC33E__))
62 asm(
" mov W0, TBLPAG");
64 asm(
" tblwtl W3,[W1]");
65 asm(
" tblwth W2,[W1++]");
66 asm(
" tblwtl W5,[W1]");
67 asm(
" tblwth W4,[W1++]");
71 asm(
"mov w0,NVMADRU");
77 asm(
"mov W0, NVMKEY");
80 asm(
"bset NVMCON,#15");
84 asm(
"1: btsc NVMCON,#15");
100 u32_a.u16.ls16 = __builtin_tblrdl(u16_addrlo);
101 u32_a.u16.ms16 = __builtin_tblrdh(u16_addrlo);
113 #if (defined(__PIC24E__) || defined(__dsPIC33E__))
118 NVMADRU = u16_addrhi;
123 asm(
"mov W0, NVMKEY");
125 asm(
"mov W0,NVMKEY");
126 asm(
"bset NVMCON,#15");
132 while (NVMCON & 0x8000)
138 u16_save_TBLPAG = TBLPAG;
146 asm(
"tblwtl %0,[%0]"::
"r"(u16_addrlo));
148 __builtin_write_NVM();
152 while (NVMCON & 0x8000)
155 TBLPAG = u16_save_TBLPAG;
172 __builtin_write_NVM();
176 while (NVMCON & 0x8000)
192 #if (defined(__PIC24E__) || defined(__dsPIC33E__))
195 uint16_t u16_ICnt, u16_numInstructions;
197 ASSERT(u16_len <= FLASH_PAGEBYTES);
201 u16_numInstructions = u16_len/3;
202 if (u16_len % 3 != 0) u16_numInstructions++;
203 u16_numInstructions += (u16_numInstructions%FLASH_ROWSIZE);
204 #if (defined(__PIC24E__) || defined(__dsPIC33E__))
206 for (u16_ICnt = 0, u16_byteCnt=0; u16_ICnt<u16_numInstructions; u16_ICnt += 2,u16_byteCnt += 6) {
207 u32_a.u8[0] = pu8_data[u16_byteCnt];
208 u32_a.u8[1] = pu8_data[u16_byteCnt+1];
209 u32_a.u8[2] = pu8_data[u16_byteCnt+2];
211 u32_b.u8[0] = pu8_data[u16_byteCnt+3];
212 u32_b.u8[1] = pu8_data[u16_byteCnt+4];
213 u32_b.u8[2] = pu8_data[u16_byteCnt+5];
215 LoadTwoWords(u32_pmemAddress.u16.ms16, u32_pmemAddress.u16.ls16,u32_a.u16.ms16,u32_a.u16.ls16,u32_b.u16.ms16,u32_b.u16.ls16);
216 WriteMem2(u32_pmemAddress.u16.ms16, u32_pmemAddress.u16.ls16,0x4001);
217 u32_pmemAddress.u32 += 4;
220 for (u16_ICnt = 0, u16_byteCnt=0; u16_ICnt<u16_numInstructions; u16_ICnt += 1,u16_byteCnt += 3) {
221 u32_a.u8[0] = pu8_data[u16_byteCnt];
222 u32_a.u8[1] = pu8_data[u16_byteCnt+1];
223 u32_a.u8[2] = pu8_data[u16_byteCnt+2];
225 doWriteLatchFlash(u32_pmemAddress.u16.ms16, u32_pmemAddress.u16.ls16,u32_a.u16.ms16,u32_a.u16.ls16);
226 if ((u16_ICnt+1)%FLASH_ROWSIZE == 0) {
230 u32_pmemAddress.u32 += 2;
246 ASSERT(u16_len <= FLASH_PAGEBYTES);
247 for (u16_byteCnt=0; u16_byteCnt<u16_len; u16_byteCnt += 3) {
249 pu8_data[u16_byteCnt] = u32_a.u8[0];
250 pu8_data[u16_byteCnt+1] = u32_a.u8[1];
251 pu8_data[u16_byteCnt+2] = u32_a.u8[2];
252 u32_pmemAddress.u32 += 2;