/*=====================================================================================================*/ int main( void ) { SystemInit(); GPIO_Config(); #if FLASH_RW_U8 Flash_EraseSector(FLASH_SECTOR_6); Flash_WriteDataU8(FLASH_SECTOR_6, WriteDataU8, 1024); Flash_ReadDataU8(FLASH_SECTOR_6, ReadDataU8, 1024); LED_R = (Cmp_ArrU8(WriteDataU8, ReadDataU8, 1024) == SUCCESS) ? 0 : 1; #endif #if FLASH_RW_U16 Flash_EraseSector(FLASH_SECTOR_6); Flash_WriteDataU16(FLASH_SECTOR_6, WriteDataU16, 512); Flash_ReadDataU16(FLASH_SECTOR_6, ReadDataU16, 512); LED_G = (Cmp_ArrU16(WriteDataU16, ReadDataU16, 512) == SUCCESS) ? 0 : 1; #endif #if FLASH_RW_U32 Flash_EraseSector(FLASH_SECTOR_6); Flash_WriteDataU32(FLASH_SECTOR_6, WriteDataU32, 256); Flash_ReadDataU32(FLASH_SECTOR_6, ReadDataU32, 256); LED_B = (Cmp_ArrU32(WriteDataU32, ReadDataU32, 256) == SUCCESS) ? 0 : 1; #endif Delay_10ms(100); while(1) { LED_R = !LED_R; LED_G = !LED_G; LED_B = !LED_B; Delay_10ms(10); } }
void saveRoomInfo(uint8_t index) { uint32_t addr = getFlashAddress(index); roomInfo[index].crc = CRC16((uint8_t *)&roomInfo[index], sizeof(stRoomInfo) - sizeof(uint16_t)); Flash_EraseSector(addr); Flash_EraseSector(addr + FLASH_SECTOR_SIZE); Flash_PageWrite((uint8_t *)&roomInfo[index], addr, sizeof(stRoomInfo)); Flash_PageWrite((uint8_t *)&roomInfo[index], addr + FLASH_SECTOR_SIZE, sizeof(stRoomInfo)); bitMapFlashDateError &= ~(1 << index); }
void writeAdminPWToFlash(uint8_t* pw) { memcpy(adminPassword, pw, M_ADMIN_PASSWORD_LENGTH); Flash_EraseSector(M_FLASH_ADDRESS_ADMIN_CARD_ID + FLASH_SECTOR_SIZE); Flash_PageWrite(pw, M_FLASH_ADDRESS_ADMIN_CARD_ID + FLASH_SECTOR_SIZE, M_ADMIN_PASSWORD_LENGTH); }
void writeAdminCardIDToFlash(uint8_t* cardID) { Flash_EraseSector(M_FLASH_ADDRESS_ADMIN_CARD_ID); Flash_PageWrite(adminCardID, M_FLASH_ADDRESS_ADMIN_CARD_ID, sizeof(adminCardID)); }