Flash HAL vt functions now receive flash handler Flash HAL was update to pass the flash_hal struct as first parameter to all vt functions. This enables a flash device to receive custom configuration/state.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b0b89a31 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b0b89a31 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b0b89a31 Branch: refs/heads/develop Commit: b0b89a314689d6786271e58e295f87898423ee8b Parents: a71c6ea Author: Fabio Utzig <[email protected]> Authored: Thu Jan 19 15:29:30 2017 -0200 Committer: Fabio Utzig <[email protected]> Committed: Fri Jan 20 07:27:40 2017 -0200 ---------------------------------------------------------------------- hw/mcu/native/src/hal_flash.c | 31 +++++++++++++++++------------ hw/mcu/nordic/nrf51xxx/src/hal_flash.c | 28 ++++++++++++++++---------- hw/mcu/nordic/nrf52xxx/src/hal_flash.c | 28 ++++++++++++++++---------- hw/mcu/nxp/MK64F12/src/hal_flash.c | 28 ++++++++++++++++---------- 4 files changed, 69 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0b89a31/hw/mcu/native/src/hal_flash.c ---------------------------------------------------------------------- diff --git a/hw/mcu/native/src/hal_flash.c b/hw/mcu/native/src/hal_flash.c index e4dedde..b892cf6 100644 --- a/hw/mcu/native/src/hal_flash.c +++ b/hw/mcu/native/src/hal_flash.c @@ -30,12 +30,15 @@ char *native_flash_file; static int file; static void *file_loc; -static int native_flash_init(void); -static int native_flash_read(uint32_t address, void *dst, uint32_t length); -static int native_flash_write(uint32_t address, const void *src, - uint32_t length); -static int native_flash_erase_sector(uint32_t sector_address); -static int native_flash_sector_info(int idx, uint32_t *address, uint32_t *size); +static int native_flash_init(const struct hal_flash *dev); +static int native_flash_read(const struct hal_flash *dev, uint32_t address, + void *dst, uint32_t length); +static int native_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t length); +static int native_flash_erase_sector(const struct hal_flash *dev, + uint32_t sector_address); +static int native_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *address, uint32_t *size); static const struct hal_flash_funcs native_flash_funcs = { .hff_read = native_flash_read, @@ -141,7 +144,7 @@ flash_native_write_internal(uint32_t address, const void *src, uint32_t length, /* Ensure data is not being overwritten. */ if (!allow_overwrite) { - rc = native_flash_read(cur, buf, chunk_sz); + rc = native_flash_read(NULL, cur, buf, chunk_sz); assert(rc == 0); for (i = 0; i < chunk_sz; i++) { assert(buf[i] == 0xff); @@ -157,7 +160,8 @@ flash_native_write_internal(uint32_t address, const void *src, uint32_t length, } static int -native_flash_write(uint32_t address, const void *src, uint32_t length) +native_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t length) { assert(address % native_flash_dev.hf_align == 0); return flash_native_write_internal(address, src, length, 0); @@ -171,7 +175,8 @@ flash_native_memset(uint32_t offset, uint8_t c, uint32_t len) } static int -native_flash_read(uint32_t address, void *dst, uint32_t length) +native_flash_read(const struct hal_flash *dev, uint32_t address, void *dst, + uint32_t length) { flash_native_ensure_file_open(); memcpy(dst, (char *)file_loc + address, length); @@ -207,7 +212,7 @@ flash_sector_len(int sector) } static int -native_flash_erase_sector(uint32_t sector_address) +native_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address) { int area_id; uint32_t len; @@ -224,7 +229,8 @@ native_flash_erase_sector(uint32_t sector_address) } static int -native_flash_sector_info(int idx, uint32_t *address, uint32_t *size) +native_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *address, uint32_t *size) { assert(idx < FLASH_NUM_AREAS); @@ -234,11 +240,10 @@ native_flash_sector_info(int idx, uint32_t *address, uint32_t *size) } static int -native_flash_init(void) +native_flash_init(const struct hal_flash *dev) { if (native_flash_file) { flash_native_file_open(native_flash_file); } return 0; } - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0b89a31/hw/mcu/nordic/nrf51xxx/src/hal_flash.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_flash.c b/hw/mcu/nordic/nrf51xxx/src/hal_flash.c index 43004d8..9f37617 100644 --- a/hw/mcu/nordic/nrf51xxx/src/hal_flash.c +++ b/hw/mcu/nordic/nrf51xxx/src/hal_flash.c @@ -27,12 +27,15 @@ #define NRF51_FLASH_SECTOR_SZ 1024 -static int nrf51_flash_read(uint32_t address, void *dst, uint32_t num_bytes); -static int nrf51_flash_write(uint32_t address, const void *src, - uint32_t num_bytes); -static int nrf51_flash_erase_sector(uint32_t sector_address); -static int nrf51_flash_sector_info(int idx, uint32_t *address, uint32_t *sz); -static int nrf51_flash_init(void); +static int nrf51_flash_read(const struct hal_flash *dev, uint32_t address, + void *dst, uint32_t num_bytes); +static int nrf51_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t num_bytes); +static int nrf51_flash_erase_sector(const struct hal_flash *dev, + uint32_t sector_address); +static int nrf51_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *address, uint32_t *sz); +static int nrf51_flash_init(const struct hal_flash *dev); static const struct hal_flash_funcs nrf51_flash_funcs = { .hff_read = nrf51_flash_read, @@ -66,7 +69,8 @@ nrf51_flash_wait_ready(void) } static int -nrf51_flash_read(uint32_t address, void *dst, uint32_t num_bytes) +nrf51_flash_read(const struct hal_flash *dev, uint32_t address, void *dst, + uint32_t num_bytes) { memcpy(dst, (void *)address, num_bytes); return 0; @@ -76,7 +80,8 @@ nrf51_flash_read(uint32_t address, void *dst, uint32_t num_bytes) * Flash write is done by writing 4 bytes at a time at a word boundary. */ static int -nrf51_flash_write(uint32_t address, const void *src, uint32_t num_bytes) +nrf51_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t num_bytes) { int sr; int rc = -1; @@ -145,7 +150,7 @@ out: } static int -nrf51_flash_erase_sector(uint32_t sector_address) +nrf51_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address) { int sr; int rc = -1; @@ -171,7 +176,8 @@ out: } static int -nrf51_flash_sector_info(int idx, uint32_t *address, uint32_t *sz) +nrf51_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *address, uint32_t *sz) { assert(idx < nrf51_flash_dev.hf_sector_cnt); *address = idx * NRF51_FLASH_SECTOR_SZ; @@ -180,7 +186,7 @@ nrf51_flash_sector_info(int idx, uint32_t *address, uint32_t *sz) } static int -nrf51_flash_init(void) +nrf51_flash_init(const struct hal_flash *dev) { return 0; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0b89a31/hw/mcu/nordic/nrf52xxx/src/hal_flash.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_flash.c b/hw/mcu/nordic/nrf52xxx/src/hal_flash.c index 6627cdf..7d3410b 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_flash.c +++ b/hw/mcu/nordic/nrf52xxx/src/hal_flash.c @@ -25,12 +25,15 @@ #define NRF52K_FLASH_SECTOR_SZ 4096 -static int nrf52k_flash_read(uint32_t address, void *dst, uint32_t num_bytes); -static int nrf52k_flash_write(uint32_t address, const void *src, - uint32_t num_bytes); -static int nrf52k_flash_erase_sector(uint32_t sector_address); -static int nrf52k_flash_sector_info(int idx, uint32_t *address, uint32_t *sz); -static int nrf52k_flash_init(void); +static int nrf52k_flash_read(const struct hal_flash *dev, uint32_t address, + void *dst, uint32_t num_bytes); +static int nrf52k_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t num_bytes); +static int nrf52k_flash_erase_sector(const struct hal_flash *dev, + uint32_t sector_address); +static int nrf52k_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *address, uint32_t *sz); +static int nrf52k_flash_init(const struct hal_flash *dev); static const struct hal_flash_funcs nrf52k_flash_funcs = { .hff_read = nrf52k_flash_read, @@ -64,7 +67,8 @@ nrf52k_flash_wait_ready(void) } static int -nrf52k_flash_read(uint32_t address, void *dst, uint32_t num_bytes) +nrf52k_flash_read(const struct hal_flash *dev, uint32_t address, void *dst, + uint32_t num_bytes) { memcpy(dst, (void *)address, num_bytes); return 0; @@ -74,7 +78,8 @@ nrf52k_flash_read(uint32_t address, void *dst, uint32_t num_bytes) * Flash write is done by writing 4 bytes at a time at a word boundary. */ static int -nrf52k_flash_write(uint32_t address, const void *src, uint32_t num_bytes) +nrf52k_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t num_bytes) { int sr; int rc = -1; @@ -142,7 +147,7 @@ out: } static int -nrf52k_flash_erase_sector(uint32_t sector_address) +nrf52k_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address) { int sr; int rc = -1; @@ -168,7 +173,8 @@ out: } static int -nrf52k_flash_sector_info(int idx, uint32_t *address, uint32_t *sz) +nrf52k_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *address, uint32_t *sz) { assert(idx < nrf52k_flash_dev.hf_sector_cnt); *address = idx * NRF52K_FLASH_SECTOR_SZ; @@ -177,7 +183,7 @@ nrf52k_flash_sector_info(int idx, uint32_t *address, uint32_t *sz) } static int -nrf52k_flash_init(void) +nrf52k_flash_init(const struct hal_flash *dev) { return 0; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0b89a31/hw/mcu/nxp/MK64F12/src/hal_flash.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nxp/MK64F12/src/hal_flash.c b/hw/mcu/nxp/MK64F12/src/hal_flash.c index 0930a85..3231662 100644 --- a/hw/mcu/nxp/MK64F12/src/hal_flash.c +++ b/hw/mcu/nxp/MK64F12/src/hal_flash.c @@ -31,12 +31,15 @@ #include "MK64F12.h" #include "fsl_flash.h" -static int mk64f12_flash_read(uint32_t address, void *dst, uint32_t num_bytes); -static int mk64f12_flash_write(uint32_t address, const void *src, - uint32_t num_bytes); -static int mk64f12_flash_erase_sector(uint32_t sector_address); -static int mk64f12_flash_sector_info(int idx, uint32_t *addr, uint32_t *sz); -static int mk64f12_flash_init(void); +static int mk64f12_flash_read(const struct hal_flash *dev, uint32_t address, + void *dst, uint32_t num_bytes); +static int mk64f12_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t num_bytes); +static int mk64f12_flash_erase_sector(const struct hal_flash *dev, + uint32_t sector_address); +static int mk64f12_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *addr, uint32_t *sz); +static int mk64f12_flash_init(const struct hal_flash *dev); static const struct hal_flash_funcs mk64f12_flash_funcs = { .hff_read = mk64f12_flash_read, @@ -55,14 +58,16 @@ struct hal_flash mk64f12_flash_dev = { }; static int -mk64f12_flash_read(uint32_t address, void *dst, uint32_t num_bytes) +mk64f12_flash_read(const struct hal_flash *dev, uint32_t address, + void *dst, uint32_t num_bytes) { memcpy(dst, (void *)address, num_bytes); return 0; } static int -mk64f12_flash_write(uint32_t address, const void *src, uint32_t len) +mk64f12_flash_write(const struct hal_flash *dev, uint32_t address, + const void *src, uint32_t len) { if (address % sizeof(uint32_t)) { /* @@ -77,7 +82,7 @@ mk64f12_flash_write(uint32_t address, const void *src, uint32_t len) } static int -mk64f12_flash_erase_sector(uint32_t sector_address) +mk64f12_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address) { if (FLASH_Erase(&mk64f12_config, sector_address, mk64f12_config.PFlashSectorSize, kFLASH_apiEraseKey) == kStatus_Success) @@ -86,7 +91,8 @@ mk64f12_flash_erase_sector(uint32_t sector_address) } static int -mk64f12_flash_sector_info(int idx, uint32_t *addr, uint32_t *sz) +mk64f12_flash_sector_info(const struct hal_flash *dev, int idx, + uint32_t *addr, uint32_t *sz) { *addr = mk64f12_config.PFlashBlockBase + (idx * mk64f12_config.PFlashSectorSize); *sz = mk64f12_config.PFlashSectorSize; @@ -94,7 +100,7 @@ mk64f12_flash_sector_info(int idx, uint32_t *addr, uint32_t *sz) } static int -mk64f12_flash_init(void) +mk64f12_flash_init(const struct hal_flash *dev) { if (FLASH_Init(&mk64f12_config) == kStatus_Success) { mk64f12_flash_dev.hf_base_addr = mk64f12_config.PFlashBlockBase;
