Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API eMPL_MPU6050 mbed nRF51822
Diff: nRF51822/nordic-sdk/components/drivers_nrf/hal/nrf_nvmc.c
- Revision:
- 1:fc2f9d636751
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF51822/nordic-sdk/components/drivers_nrf/hal/nrf_nvmc.c Wed Apr 22 07:47:17 2015 +0000
@@ -0,0 +1,117 @@
+/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
+*
+* The information contained herein is property of Nordic Semiconductor ASA.
+* Terms and conditions of usage are described in detail in NORDIC
+* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+*
+* Licensees are granted free, non-transferable use of the information. NO
+* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+* the file.
+*
+* $LastChangedRevision: 17685 $
+*/
+
+/**
+ *@file
+ *@brief NMVC driver implementation
+ */
+
+#include "stdbool.h"
+#include "nrf.h"
+#include "nrf_nvmc.h"
+
+
+void nrf_nvmc_page_erase(uint32_t address)
+{
+ // Enable erase.
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+
+ // Erase the page
+ NRF_NVMC->ERASEPAGE = address;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+}
+
+
+void nrf_nvmc_write_byte(uint32_t address, uint8_t value)
+{
+ uint32_t byte_shift = address & (uint32_t)0x03;
+ uint32_t address32 = address & ~byte_shift; // Address to the word this byte is in.
+ uint32_t value32 = (*(uint32_t*)address32 & ~((uint32_t)0xFF << (byte_shift << (uint32_t)3)));
+ value32 = value32 + ((uint32_t)value << (byte_shift << 3));
+
+ // Enable write.
+ NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+
+ *(uint32_t*)address32 = value32;
+ while(NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+
+ NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
+ {
+ }
+}
+
+void nrf_nvmc_write_word(uint32_t address, uint32_t value)
+{
+ // Enable write.
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
+ }
+
+ *(uint32_t*)address = value;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
+ }
+
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+}
+
+void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes)
+{
+ uint32_t i;
+ for(i=0;i<num_bytes;i++)
+ {
+ nrf_nvmc_write_byte(address+i,src[i]);
+ }
+}
+
+void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words)
+{
+ uint32_t i;
+
+ // Enable write.
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+
+ for(i=0;i<num_words;i++)
+ {
+ ((uint32_t*)address)[i] = src[i];
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+ }
+
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
+ {
+ }
+}
+
\ No newline at end of file