void writeEepromBlock() { eeWriteBlockCmp((uint8_t *)Block_buffer, eepromAddress, BlockCount); eepromAddress += BlockCount; }
int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint16_t count) { enum FatWriteOperation { FATWRITE_NONE, FATWRITE_EEPROM, FATWRITE_FIRMWARE }; static unsigned int operation = FATWRITE_NONE; TRACE("FAT12 Write(sector=%d, count=%d)", sector, count); if (sector < 3) { // reserved, read-only } else if (sector < 3 + (EESIZE/BLOCKSIZE)) { // eeprom while (count) { if (operation == FATWRITE_NONE && isEepromStart(buffer)) { TRACE("EEPROM start found in sector %d", sector); operation = FATWRITE_EEPROM; } if (operation == FATWRITE_EEPROM) { eeWriteBlockCmp((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); } buffer += BLOCKSIZE; sector++; count--; if (sector-3 >= (EESIZE/BLOCKSIZE)) { TRACE("EEPROM end written at sector %d", sector-1); operation = FATWRITE_NONE; } } } else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) { // firmware uint32_t address; address = sector - 3 - (EESIZE/BLOCKSIZE); address *= BLOCKSIZE; address += FIRMWARE_ADDRESS; while (count) { for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) { if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) { if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE && isFirmwareStart(buffer)) { TRACE("FIRMWARE start found in sector %d", sector); operation = FATWRITE_FIRMWARE; } if (operation == FATWRITE_FIRMWARE) { writeFlash((uint32_t *)address, (uint32_t *)buffer); } } address += FLASH_PAGESIZE; buffer += FLASH_PAGESIZE; } sector++; count--; if (sector-3-(EESIZE/BLOCKSIZE) >= (FLASHSIZE/BLOCKSIZE)) { TRACE("FIRMWARE end written at sector %d", sector-1); operation = FATWRITE_NONE; } } } return 0 ; }
static void EeFsFlush() { eeWriteBlockCmp((uint8_t *)&eeFs, 0, sizeof(eeFs)); }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count ) { static int offset = 0; // TRACE("FAT12 Write(sector=%d, count=%d)", sector, count); if ( sector >= 3 ) { if ( sector < 67 ) { while (count) { if (offset == 0 && sector == 3 ) { if ( isValidEepromStart( buffer ) ) { // TRACE("EEPROM start found in sector %d", sector); offset = sector; EepromBlocked = 0 ; } else { EepromBlocked = 1 ; } } if ( EepromBlocked ) { return 1 ; } if (offset && sector >= offset && (sector-offset) < EESIZE/BLOCKSIZE) { eeWriteBlockCmp((uint8_t *)buffer, (sector-offset)*BLOCKSIZE, BLOCKSIZE); } buffer += BLOCKSIZE; sector++; count--; if (sector-offset >= EESIZE/BLOCKSIZE) { // TRACE("EEPROM end written at sector %d", sector-1); offset = 0; } } } else if ( sector < 1091 ) { // firmware uint32_t address ; address = sector - 67 ; address *= 512 ; address += 0x08000000 ; uint32_t i ; while ( count ) { for ( i = 0 ; i < 2 ; i += 1 ) { if ( address >= 0x08008000 ) // Protect bootloader { if ( address <= (0x08000000 + (512*1024) - 256) ) // in range { program( (uint32_t *)address, (uint32_t *) buffer ) ; // size is 256 bytes } } address += 256 ; buffer += 256 ; } count -= 1 ; } } } return 0 ; }
static void EeFsFlushFreelist() { eeWriteBlockCmp((uint8_t *)&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList)); }
static void EeFsFlushDirEnt(uint8_t i_fileId) { eeWriteBlockCmp((uint8_t *)&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt)); }
static void EeFsSetDat(blkid_t blk, uint8_t ofs, uint8_t *buf, uint8_t len) { eeWriteBlockCmp(buf, (blk*BS)+ofs+sizeof(blkid_t)+BLOCKS_OFFSET, len); }
static void EeFsSetLink(blkid_t blk, blkid_t val) { static blkid_t s_link; // we write asynchronously, then nothing on the stack! s_link = val; eeWriteBlockCmp((uint8_t *)&s_link, (blk*BS)+BLOCKS_OFFSET, sizeof(blkid_t)); }
void EFile::EeFsFlush() { eeWriteBlockCmp(eeFs, 0,sizeof(eeFs)); }
void EFile::EeFsSetDat(uint8_t blk,uint8_t ofs,uint8_t*buf,uint8_t len){ //EeFsWrite( blk,ofs+1,val); eeWriteBlockCmp(buf, (uint16_t)(blk*BS+ofs+1), len); }
void EFile::EeFsWrite(uint8_t blk,uint8_t ofs,uint8_t val){ eeWriteBlockCmp(&val, (uint16_t)(blk*BS+ofs), 1); }