char BSL430_writeWord(unsigned long addr, int data) { char exceptions; if (LockedStatus == UNLOCKED) { exceptions = SUCCESSFUL_OPERATION; #ifdef RAM_BASED_BSL while (FCTL3 & BUSY) ; #endif __data20_write_short(addr, data); #ifdef RAM_BASED_BSL while (FCTL3 & BUSY) ; #endif if (data != __data20_read_short(addr)) { exceptions = MEMORY_WRITE_CHECK_FAILED; } #ifndef DO_NOT_CHECK_VPE if (FCTL4 & VPE) { exceptions = VOLTAGE_CHANGE_DURING_PROGRAM; } #endif } else { exceptions = BSL_LOCKED; } return exceptions; }
/****************************************************************************** * @fn dl2rc * * @brief Copy the DL image to the RC image location. * * NOTE: Assumes that DL image at least fills lower flash. * Assumes that DL image ends on a flash page boundary. * * @param None. * * @return None. */ static void dl2rc(void) { uint32 addr = DATA_OFFSET; uint32 addr2 = HI_ROM_BEG; uint16 *ptr; preamble_t preamble; uint16 buf; uint8 cnt = 0; vddWait(VDD_MIN_OTA); HalOTARead(DATA_OFFSET+PREAMBLE_OFFSET, (uint8 *)&preamble, sizeof(preamble_t), HAL_OTA_DL); FCTL3 = FWKEY; // Clear Lock bit. for (ptr = (uint16 *)LO_ROM_BEG; ptr <= (uint16 *)LO_ROM_END ; ) { FCTL1 = FWKEY + ERASE; // Set Erase bit. *ptr = 0; // Dummy write to erase Flash segment. FCTL1 = FWKEY + WRT; // Set WRT bit for write operation do { HalXNVRead(addr, (uint8 *)&buf, 2); *ptr++ = buf; addr += 2; } while (--cnt); // Wrap a uint8 once to count 256 * 2 = 512. } for (; addr < preamble.programLength+DATA_OFFSET; ) { FCTL1 = FWKEY + ERASE; // Set Erase bit. __data20_write_char(addr2,0); // Dummy write to erase Flash segment. FCTL1 = FWKEY + WRT; // Set WRT bit for write operation do { HalXNVRead(addr, (uint8 *)&buf, 2); __data20_write_short(addr2, buf); addr2 += 2; addr += 2; } while (--cnt); // Wrap a uint8 once to count 256 * 2 = 512. } FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit }