Beispiel #1
0
void eepromWriteProcess()
{
  // TRACE("eepromWriteProcess(state=%d)", eepromWriteState);

  switch (eepromWriteState) {
    case EEPROM_ERASING_FILE_BLOCK1:
    case EEPROM_ERASING_FILE_BLOCK2:
    case EEPROM_WRITING_BUFFER:
    case EEPROM_ERASING_FAT_BLOCK:
    case EEPROM_WRITING_NEW_FAT:
      if (Spi_complete) {
        eepromWriteState = EepromWriteState(eepromWriteState + 1);
      }
      break;

    case EEPROM_ERASING_FILE_BLOCK1_WAIT:
    case EEPROM_ERASING_FILE_BLOCK2_WAIT:
    case EEPROM_WRITING_BUFFER_WAIT:
    case EEPROM_ERASING_FAT_BLOCK_WAIT:
    case EEPROM_WRITING_NEW_FAT_WAIT:
      if ((eepromReadStatus() & 1) == 0) {
        eepromWriteState = EepromWriteState(eepromWriteState + 1);
      }
      break;

    case EEPROM_START_WRITE:
      eepromWriteState = EEPROM_ERASING_FILE_BLOCK1;
      eepromEraseBlock(eepromWriteDestinationAddr, false);
      break;

    case EEPROM_ERASE_FILE_BLOCK2:
      eepromWriteState = EEPROM_ERASING_FILE_BLOCK2;
      eepromEraseBlock(eepromWriteDestinationAddr + EEPROM_BLOCK_SIZE, false);
      break;

    case EEPROM_WRITE_BUFFER:
    {
      EepromFileHeader * header = (EepromFileHeader *)eepromWriteBuffer;
      header->fileIndex = eepromWriteFileIndex;
      header->size = eepromWriteSize;
      uint32_t size = min<uint32_t>(EEPROM_BUFFER_SIZE-sizeof(EepromFileHeader), eepromWriteSize);
      memcpy(eepromWriteBuffer+sizeof(EepromFileHeader), eepromWriteSourceAddr, size);
      eepromWriteState = EEPROM_WRITING_BUFFER;
      eepromWrite(eepromWriteDestinationAddr, eepromWriteBuffer, sizeof(EepromFileHeader)+size, false);
      eepromWriteSourceAddr += size;
      eepromWriteDestinationAddr += sizeof(EepromFileHeader)+size;
      eepromWriteSize -= size;
      break;
    }

    case EEPROM_WRITE_NEXT_BUFFER:
    {
      uint32_t size = min<uint32_t>(EEPROM_BUFFER_SIZE, eepromWriteSize);
      if (size > 0) {
        memcpy(eepromWriteBuffer, eepromWriteSourceAddr, size);
        eepromWriteState = EEPROM_WRITING_BUFFER;
        eepromWrite(eepromWriteDestinationAddr, eepromWriteBuffer, size, false);
        eepromWriteSourceAddr += size;
        eepromWriteDestinationAddr += size;
        eepromWriteSize -= size;
        break;
      }
      else if (eepromFatAddr == 0 || eepromFatAddr == EEPROM_BLOCK_SIZE) {
        eepromWriteState = EEPROM_ERASING_FAT_BLOCK;
        eepromEraseBlock(eepromFatAddr, false);
        break;
      }
    }
    /* no break */

    case EEPROM_WRITE_NEW_FAT:
      eepromWriteState = EEPROM_WRITING_NEW_FAT;
      eepromWrite(eepromFatAddr, (uint8_t *)&eepromHeader, sizeof(eepromHeader), false);
      break;

    case EEPROM_END_WRITE:
      eepromWriteState = EEPROM_IDLE;
      break;

    default:
      break;
  }
}
Beispiel #2
0
void eepromWaitReadStatus()
{
  while ((eepromReadStatus() & 1) != 0) {
    SIMU_SLEEP(5/*ms*/);
  }
}