void BinaryFile::WriteShortString(const std::string& str) { if(str.length() + 1 > std::numeric_limits<unsigned char>::max()) throw std::out_of_range("String '" + str + "' is to long for a short string"); auto length = static_cast<unsigned char>(str.length() + 1); WriteUnsignedChar(length); WriteRawData(str.c_str(), length); }
/** * \brief It implement a program word command. * \param pNorFlashInfo Pointer to an struct NorFlashInfo instance. * \param address Start address offset to be wrote. * \param data word to be written. * \returns 0 if the operation was successful; otherwise returns an error code. */ uint8_t intel_Program( struct NorFlashInfo *pNorFlashInfo, uint32_t address, uint32_t data ) { uint32_t status; uint32_t datain; volatile uint32_t busAddress; uint8_t done = 0; uint8_t busWidth; busWidth = NorFlash_GetDataBusWidth(pNorFlashInfo); // Issue Read Array Command - just in case that the flash is not in Read Array mode intel_Reset(pNorFlashInfo, address); busAddress = NorFlash_GetAddressInChip(pNorFlashInfo, address); /* // Check if the data already have been erased. ReadRawData(busWidth, busAddress, (uint8_t*)&datain); if((datain & data)!= data) { return NorCommon_ERROR_CANNOTWRITE; } */ // Word programming operations are initiated by writing the Word Program Setup command to the device. WriteCommand(busWidth, busAddress, INTEL_CMD_PROGRAM_WORD); // This is followed by a second write to the device with the address and data to be programmed. WriteRawData(busWidth, busAddress, (uint8_t*)&data); // Status register polling do { status = intel_ReadStatus(pNorFlashInfo,address); // Check if the device is ready. if ((status & INTEL_STATUS_DWS) == INTEL_STATUS_DWS ) { // check if VPP within acceptable limits during program or erase operation. if ((status & INTEL_STATUS_VPPS) == INTEL_STATUS_VPPS ) { return NorCommon_ERROR_CANNOTWRITE; } // Check if the erase block operation is completed. if ((status & INTEL_STATUS_PS) == INTEL_STATUS_PS ) { return NorCommon_ERROR_CANNOTWRITE; } // check if Block locked during program or erase, operation aborted. else if ((status & INTEL_STATUS_BLS) == INTEL_STATUS_BLS ) { return NorCommon_ERROR_CANNOTWRITE; } else { done = 1; } } } while (!done); intel_ClearStatus(pNorFlashInfo); intel_Reset(pNorFlashInfo, address); return 0; }
void BinaryFile::WriteLongString(const std::string& str) { auto length = unsigned(str.length() + 1); WriteUnsignedInt(length); WriteRawData(str.c_str(), length); }