/* Write data to simulated EEPROM. 
Function uses TWI interface to write data into EEPROM memory. */
static ret_code_t eeprom_write(size_t addr, uint8_t const *pdata, size_t size)
/* Write data to simulated EEPROM. 
Function uses TWI interface to write data into EEPROM memory. */
static ret_code_t eeprom_write(size_t addr, uint8_t const *pdata, size_t size)
{
    ret_code_t ret;
    if (size > (EEPROM_SIM_SEQ_WRITE_MAX))
    {
        return NRF_ERROR_INVALID_LENGTH;
    }
    if ((addr / (EEPROM_SIM_SEQ_WRITE_MAX)) != ((addr + size - 1) / (EEPROM_SIM_SEQ_WRITE_MAX)))
    {
        return NRF_ERROR_INVALID_ADDR;
    }
    do
    {
        uint8_t buffer[1 + EEPROM_SIM_SEQ_WRITE_MAX];
        buffer[0] = (uint8_t)addr;
        memcpy(buffer + 1, pdata, size);
        ret = nrf_drv_twi_tx(&m_twi_master, EEPROM_SIM_ADDR, buffer, size + 1, false);
    }while (0);
    return ret;
}