static otError addSetting(otInstance * aInstance, uint16_t aKey, bool aIndex0, const uint8_t *aValue, uint16_t aValueLength) { otError error = OT_ERROR_NONE; OT_TOOL_PACKED_BEGIN struct addSettingsBlock { struct settingsBlock block; uint8_t data[kSettingsBlockDataSize]; } OT_TOOL_PACKED_END addBlock; uint32_t settingsSize = SETTINGS_CONFIG_PAGE_NUM > 1 ? SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM / 2 : SETTINGS_CONFIG_PAGE_SIZE; addBlock.block.flag = 0xff; addBlock.block.key = aKey; if (aIndex0) { addBlock.block.flag &= (~kBlockIndex0Flag); } addBlock.block.flag &= (~kBlockAddBeginFlag); addBlock.block.length = aValueLength; if ((sSettingsUsedSize + getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)) >= settingsSize) { otEXPECT_ACTION(swapSettingsBlock(aInstance) >= (getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)), error = OT_ERROR_NO_BUFS); } utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, reinterpret_cast<uint8_t *>(&addBlock.block), sizeof(struct settingsBlock)); memset(addBlock.data, 0xff, kSettingsBlockDataSize); memcpy(addBlock.data, aValue, addBlock.block.length); utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize + sizeof(struct settingsBlock), reinterpret_cast<uint8_t *>(addBlock.data), getAlignLength(addBlock.block.length)); addBlock.block.flag &= (~kBlockAddCompleteFlag); utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, reinterpret_cast<uint8_t *>(&addBlock.block), sizeof(struct settingsBlock)); sSettingsUsedSize += (sizeof(struct settingsBlock) + getAlignLength(addBlock.block.length)); exit: return error; }
static otError addSetting(otInstance * aInstance, uint16_t aKey, bool aIndex0, const uint8_t *aValue, uint16_t aValueLength) { otError error = OT_ERROR_NONE; OT_TOOL_PACKED_BEGIN struct addSettingsBlock { struct settingsBlock block; uint8_t data[OT_SETTINGS_BLOCK_DATA_SIZE]; } OT_TOOL_PACKED_END addBlock; uint32_t settingsSize = SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM / 2; addBlock.block.flag = 0xff; addBlock.block.key = aKey; if (aIndex0) { addBlock.block.flag &= (~OT_FLASH_BLOCK_INDEX_0_FLAG); } addBlock.block.flag &= (~OT_FLASH_BLOCK_ADD_BEGIN_FLAG); addBlock.block.length = aValueLength; if ((sSettingsUsedSize + getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)) >= settingsSize) { otEXPECT_ACTION(swapSettingsBlock(aInstance) >= (getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)), error = OT_ERROR_NO_BUFS); } utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, (uint8_t *)(&addBlock.block), sizeof(struct settingsBlock)); memset(addBlock.data, 0xff, OT_SETTINGS_BLOCK_DATA_SIZE); memcpy(addBlock.data, aValue, addBlock.block.length); utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize + sizeof(struct settingsBlock), (uint8_t *)(addBlock.data), getAlignLength(addBlock.block.length)); addBlock.block.flag &= (~OT_FLASH_BLOCK_ADD_COMPLETE_FLAG); utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, (uint8_t *)(&addBlock.block), sizeof(struct settingsBlock)); sSettingsUsedSize += (sizeof(struct settingsBlock) + getAlignLength(addBlock.block.length)); exit: return error; }