static int flash_nrf_write(struct device *dev, off_t addr, const void *data, size_t len) { int ret; if (write_protect) { return -EACCES; } if (!is_addr_valid(addr, len)) { return -EINVAL; } if (!len) { return 0; } SYNC_LOCK(); #if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC) if (ticker_is_initialized(0)) { ret = write_in_timeslice(addr, data, len); } else #endif /* CONFIG_SOC_FLASH_NRF_RADIO_SYNC */ { ret = write(addr, data, len); } SYNC_UNLOCK(); return ret; }
static int flash_nrf_erase(struct device *dev, off_t addr, size_t size) { u32_t pg_size = NRF_FICR->CODEPAGESIZE; u32_t n_pages = size / pg_size; int ret; /* Erase can only be done per page */ if (((addr % pg_size) != 0) || ((size % pg_size) != 0)) { return -EINVAL; } if (!is_addr_valid(addr, size)) { return -EINVAL; } if (!n_pages) { return 0; } SYNC_LOCK(); #if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC) if (ticker_is_initialized(0)) { ret = erase_in_timeslice(addr, size); } else #endif /* CONFIG_SOC_FLASH_NRF_RADIO_SYNC */ { ret = erase(addr, size); } SYNC_UNLOCK(); return ret; }
static int flash_nrf_write_protection(struct device *dev, bool enable) { SYNC_LOCK(); if (enable) { NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; } else { NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; } nvmc_wait_ready(); SYNC_UNLOCK(); return 0; }