Patched version of nrf51822 FOTA compatible driver, with GPTIO disabled, as it clashed with the mbed definitions...
Fork of nRF51822 by
nrf_nvmc.c
00001 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 * $LastChangedRevision: 17685 $ 00012 */ 00013 00014 /** 00015 *@file 00016 *@brief NMVC driver implementation 00017 */ 00018 00019 #include "stdbool.h" 00020 #include "nrf.h" 00021 #include "nrf_nvmc.h" 00022 00023 00024 void nrf_nvmc_page_erase(uint32_t address) 00025 { 00026 // Enable erase. 00027 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; 00028 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00029 { 00030 } 00031 00032 // Erase the page 00033 NRF_NVMC->ERASEPAGE = address; 00034 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00035 { 00036 } 00037 00038 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; 00039 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00040 { 00041 } 00042 } 00043 00044 00045 void nrf_nvmc_write_byte(uint32_t address, uint8_t value) 00046 { 00047 uint32_t byte_shift = address & (uint32_t)0x03; 00048 uint32_t address32 = address & ~byte_shift; // Address to the word this byte is in. 00049 uint32_t value32 = (*(uint32_t*)address32 & ~((uint32_t)0xFF << (byte_shift << (uint32_t)3))); 00050 value32 = value32 + ((uint32_t)value << (byte_shift << 3)); 00051 00052 // Enable write. 00053 NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos); 00054 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00055 { 00056 } 00057 00058 *(uint32_t*)address32 = value32; 00059 while(NRF_NVMC->READY == NVMC_READY_READY_Busy) 00060 { 00061 } 00062 00063 NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos); 00064 { 00065 } 00066 } 00067 00068 void nrf_nvmc_write_word(uint32_t address, uint32_t value) 00069 { 00070 // Enable write. 00071 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; 00072 while (NRF_NVMC->READY == NVMC_READY_READY_Busy){ 00073 } 00074 00075 *(uint32_t*)address = value; 00076 while (NRF_NVMC->READY == NVMC_READY_READY_Busy){ 00077 } 00078 00079 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; 00080 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00081 { 00082 } 00083 } 00084 00085 void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes) 00086 { 00087 uint32_t i; 00088 for(i=0;i<num_bytes;i++) 00089 { 00090 nrf_nvmc_write_byte(address+i,src[i]); 00091 } 00092 } 00093 00094 void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words) 00095 { 00096 uint32_t i; 00097 00098 // Enable write. 00099 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; 00100 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00101 { 00102 } 00103 00104 for(i=0;i<num_words;i++) 00105 { 00106 ((uint32_t*)address)[i] = src[i]; 00107 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00108 { 00109 } 00110 } 00111 00112 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; 00113 while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 00114 { 00115 } 00116 } 00117
Generated on Tue Jul 12 2022 17:56:13 by 1.7.2