Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 /*
be_bryan 0:b74591d5ab33 2 * Copyright (c) 2017 Nordic Semiconductor ASA
be_bryan 0:b74591d5ab33 3 * All rights reserved.
be_bryan 0:b74591d5ab33 4 *
be_bryan 0:b74591d5ab33 5 * Redistribution and use in source and binary forms, with or without modification,
be_bryan 0:b74591d5ab33 6 * are permitted provided that the following conditions are met:
be_bryan 0:b74591d5ab33 7 *
be_bryan 0:b74591d5ab33 8 * 1. Redistributions of source code must retain the above copyright notice, this list
be_bryan 0:b74591d5ab33 9 * of conditions and the following disclaimer.
be_bryan 0:b74591d5ab33 10 *
be_bryan 0:b74591d5ab33 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
be_bryan 0:b74591d5ab33 12 * integrated circuit in a product or a software update for such product, must reproduce
be_bryan 0:b74591d5ab33 13 * the above copyright notice, this list of conditions and the following disclaimer in
be_bryan 0:b74591d5ab33 14 * the documentation and/or other materials provided with the distribution.
be_bryan 0:b74591d5ab33 15 *
be_bryan 0:b74591d5ab33 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
be_bryan 0:b74591d5ab33 17 * used to endorse or promote products derived from this software without specific prior
be_bryan 0:b74591d5ab33 18 * written permission.
be_bryan 0:b74591d5ab33 19 *
be_bryan 0:b74591d5ab33 20 * 4. This software, with or without modification, must only be used with a
be_bryan 0:b74591d5ab33 21 * Nordic Semiconductor ASA integrated circuit.
be_bryan 0:b74591d5ab33 22 *
be_bryan 0:b74591d5ab33 23 * 5. Any software provided in binary or object form under this license must not be reverse
be_bryan 0:b74591d5ab33 24 * engineered, decompiled, modified and/or disassembled.
be_bryan 0:b74591d5ab33 25 *
be_bryan 0:b74591d5ab33 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
be_bryan 0:b74591d5ab33 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
be_bryan 0:b74591d5ab33 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
be_bryan 0:b74591d5ab33 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
be_bryan 0:b74591d5ab33 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
be_bryan 0:b74591d5ab33 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
be_bryan 0:b74591d5ab33 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
be_bryan 0:b74591d5ab33 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
be_bryan 0:b74591d5ab33 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
be_bryan 0:b74591d5ab33 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
be_bryan 0:b74591d5ab33 36 *
be_bryan 0:b74591d5ab33 37 */
be_bryan 0:b74591d5ab33 38
be_bryan 0:b74591d5ab33 39 #include "flash_api.h"
be_bryan 0:b74591d5ab33 40 #include "nrf_nvmc.h"
be_bryan 0:b74591d5ab33 41 #include "nrf_soc.h"
be_bryan 0:b74591d5ab33 42 #include "nrf_sdm.h"
be_bryan 0:b74591d5ab33 43
be_bryan 0:b74591d5ab33 44 #if DEVICE_FLASH
be_bryan 0:b74591d5ab33 45
be_bryan 0:b74591d5ab33 46 int32_t flash_init(flash_t *obj)
be_bryan 0:b74591d5ab33 47 {
be_bryan 0:b74591d5ab33 48 (void)(obj);
be_bryan 0:b74591d5ab33 49 uint8_t sd_enabled;
be_bryan 0:b74591d5ab33 50 if ((sd_softdevice_is_enabled(&sd_enabled) == NRF_SUCCESS) && sd_enabled == 1) {
be_bryan 0:b74591d5ab33 51 return -1;
be_bryan 0:b74591d5ab33 52 }
be_bryan 0:b74591d5ab33 53 return 0;
be_bryan 0:b74591d5ab33 54 }
be_bryan 0:b74591d5ab33 55
be_bryan 0:b74591d5ab33 56 int32_t flash_free(flash_t *obj)
be_bryan 0:b74591d5ab33 57 {
be_bryan 0:b74591d5ab33 58 (void)(obj);
be_bryan 0:b74591d5ab33 59 return 0;
be_bryan 0:b74591d5ab33 60 }
be_bryan 0:b74591d5ab33 61
be_bryan 0:b74591d5ab33 62 int32_t flash_erase_sector(flash_t *obj, uint32_t address)
be_bryan 0:b74591d5ab33 63 {
be_bryan 0:b74591d5ab33 64 (void)(obj);
be_bryan 0:b74591d5ab33 65 uint8_t sd_enabled;
be_bryan 0:b74591d5ab33 66 if ((sd_softdevice_is_enabled(&sd_enabled) == NRF_SUCCESS) && sd_enabled == 1) {
be_bryan 0:b74591d5ab33 67 return -1;
be_bryan 0:b74591d5ab33 68 }
be_bryan 0:b74591d5ab33 69 nrf_nvmc_page_erase(address);
be_bryan 0:b74591d5ab33 70 return 0;
be_bryan 0:b74591d5ab33 71 }
be_bryan 0:b74591d5ab33 72
be_bryan 0:b74591d5ab33 73 int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
be_bryan 0:b74591d5ab33 74 {
be_bryan 0:b74591d5ab33 75 uint8_t sd_enabled;
be_bryan 0:b74591d5ab33 76 if ((sd_softdevice_is_enabled(&sd_enabled) == NRF_SUCCESS) && sd_enabled == 1) {
be_bryan 0:b74591d5ab33 77 return -1;
be_bryan 0:b74591d5ab33 78 }
be_bryan 0:b74591d5ab33 79 /* We will use *_words function to speed up flashing code. Word means 32bit -> 4B
be_bryan 0:b74591d5ab33 80 * or sizeof(uint32_t).
be_bryan 0:b74591d5ab33 81 */
be_bryan 0:b74591d5ab33 82 nrf_nvmc_write_words(address, (const uint32_t *) data, (size / sizeof(uint32_t)));
be_bryan 0:b74591d5ab33 83 return 0;
be_bryan 0:b74591d5ab33 84 }
be_bryan 0:b74591d5ab33 85
be_bryan 0:b74591d5ab33 86 uint32_t flash_get_size(const flash_t *obj)
be_bryan 0:b74591d5ab33 87 {
be_bryan 0:b74591d5ab33 88 (void)(obj);
be_bryan 0:b74591d5ab33 89 /* Just count flash size. */
be_bryan 0:b74591d5ab33 90 return NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE;
be_bryan 0:b74591d5ab33 91 }
be_bryan 0:b74591d5ab33 92
be_bryan 0:b74591d5ab33 93 uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
be_bryan 0:b74591d5ab33 94 {
be_bryan 0:b74591d5ab33 95 (void)(obj);
be_bryan 0:b74591d5ab33 96 /* Test if passed address is in flash space. */
be_bryan 0:b74591d5ab33 97 if (address < flash_get_size(obj)) {
be_bryan 0:b74591d5ab33 98 return NRF_FICR->CODEPAGESIZE;
be_bryan 0:b74591d5ab33 99 }
be_bryan 0:b74591d5ab33 100 /* Something goes wrong, return invalid size error code. */
be_bryan 0:b74591d5ab33 101 return MBED_FLASH_INVALID_SIZE;
be_bryan 0:b74591d5ab33 102 }
be_bryan 0:b74591d5ab33 103
be_bryan 0:b74591d5ab33 104 uint32_t flash_get_page_size(const flash_t *obj)
be_bryan 0:b74591d5ab33 105 {
be_bryan 0:b74591d5ab33 106 (void)(obj);
be_bryan 0:b74591d5ab33 107 return NRF_FICR->CODEPAGESIZE;
be_bryan 0:b74591d5ab33 108 }
be_bryan 0:b74591d5ab33 109
be_bryan 0:b74591d5ab33 110 uint32_t flash_get_start_address(const flash_t *obj)
be_bryan 0:b74591d5ab33 111 {
be_bryan 0:b74591d5ab33 112 return 0;
be_bryan 0:b74591d5ab33 113 }
be_bryan 0:b74591d5ab33 114
be_bryan 0:b74591d5ab33 115 #endif
be_bryan 0:b74591d5ab33 116
be_bryan 0:b74591d5ab33 117 /** @}*/