-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hal_flash: implement with nonvolatile storage
- Loading branch information
Showing
3 changed files
with
47 additions
and
113 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
#ifndef __SMTC_HAL_FLASH_H | ||
#define __SMTC_HAL_FLASH_H | ||
|
||
|
||
#define ADDR_FLASH_LORAWAN_CONTEXT 0 | ||
#define ADDR_FLASH_MODEM_CONTEXT 512 | ||
#define ADDR_FLASH_DEVNONCE_CONTEXT 1024 | ||
#define ADDR_FLASH_SECURE_ELEMENT_CONTEXT 1536 | ||
|
||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
smtc_hal_status_t hal_flash_init( void ); | ||
|
||
smtc_hal_status_t hal_flash_deinit( void ); | ||
|
||
smtc_hal_status_t hal_flash_erase_page( uint32_t addr, uint8_t nb_page ); | ||
|
||
smtc_hal_status_t hal_flash_write_buffer( uint32_t addr, const uint8_t* buffer, uint32_t size ); | ||
|
||
void hal_flash_read_buffer( uint32_t addr, uint8_t* buffer, uint32_t size ); | ||
|
||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,39 @@ | ||
#include <tock.h> | ||
#include <nonvolatile_storage.h> | ||
|
||
//#include "nrf_fstorage.h" | ||
#include "smtc_hal.h" | ||
|
||
#ifdef SOFTDEVICE_PRESENT | ||
#include "nrf_soc.h" | ||
#include "nrf_sdh.h" | ||
#include "nrf_sdh_ble.h" | ||
#include "nrf_fstorage_sd.h" | ||
#else | ||
//#include "nrf_drv_clock.h" | ||
//#include "nrf_fstorage_nvmc.h" | ||
#endif | ||
|
||
//static void fstorage_evt_handler( nrf_fstorage_evt_t * p_evt ); | ||
|
||
// NRF_FSTORAGE_DEF( nrf_fstorage_t fstorage ) = | ||
// { | ||
// .evt_handler = fstorage_evt_handler, | ||
// .start_addr = APP_FLASH_ADDR_START, | ||
// .end_addr = APP_FLASH_ADDR_END, | ||
// }; | ||
|
||
smtc_hal_status_t hal_flash_init( void ) | ||
{ | ||
// nrf_fstorage_api_t * p_fs_api; | ||
|
||
// #ifdef SOFTDEVICE_PRESENT | ||
// p_fs_api = &nrf_fstorage_sd; | ||
// #else | ||
// p_fs_api = &nrf_fstorage_nvmc; | ||
// #endif | ||
|
||
// nrf_fstorage_init( &fstorage, p_fs_api, NULL ); | ||
return SMTC_HAL_SUCCESS; | ||
} | ||
|
||
smtc_hal_status_t hal_flash_erase_page( uint32_t addr, uint8_t nb_page ) | ||
{ | ||
// if( addr >= APP_FLASH_ADDR_START && addr <= APP_FLASH_ADDR_END && nb_page <= APP_FLASH_PAGE_MAX ) | ||
// { | ||
// nrf_fstorage_erase( &fstorage, addr, nb_page, NULL ); | ||
// while( nrf_fstorage_is_busy( &fstorage )) | ||
// { | ||
// #ifdef SOFTDEVICE_PRESENT | ||
// ( void )sd_app_evt_wait( ); | ||
// #else | ||
// __WFE(); | ||
// #endif | ||
// } | ||
// } | ||
return SMTC_HAL_SUCCESS; | ||
} | ||
|
||
smtc_hal_status_t hal_flash_write_buffer( uint32_t addr, const uint8_t* buffer, uint32_t size ) | ||
{ | ||
// if( addr >= APP_FLASH_ADDR_START && addr <= APP_FLASH_ADDR_END && size <= APP_FLASH_SIZE_MAX ) | ||
// { | ||
// nrf_fstorage_write( &fstorage, addr, buffer, size, NULL ); | ||
// while( nrf_fstorage_is_busy( &fstorage )) | ||
// { | ||
// #ifdef SOFTDEVICE_PRESENT | ||
// ( void )sd_app_evt_wait( ); | ||
// #else | ||
// __WFE(); | ||
// #endif | ||
// } | ||
// } | ||
returncode_t ret; | ||
|
||
ret = nonvolatile_storage_write_sync(buffer, size, addr); | ||
if (ret != RETURNCODE_SUCCESS) return SMTC_HAL_FAILURE; | ||
|
||
return SMTC_HAL_SUCCESS; | ||
} | ||
|
||
void hal_flash_read_buffer( uint32_t addr, uint8_t* buffer, uint32_t size ) | ||
{ | ||
// if( addr >= APP_FLASH_ADDR_START && addr <= APP_FLASH_ADDR_END && size <= APP_FLASH_SIZE_MAX ) | ||
// { | ||
// nrf_fstorage_read( &fstorage, addr, buffer, size ); | ||
// } | ||
} | ||
returncode_t ret; | ||
|
||
// static void fstorage_evt_handler( nrf_fstorage_evt_t * p_evt ) | ||
// { | ||
|
||
// } | ||
ret = nonvolatile_storage_read_sync(buffer, size, addr); | ||
if (ret != RETURNCODE_SUCCESS) return SMTC_HAL_FAILURE; | ||
|
||
return SMTC_HAL_SUCCESS; | ||
} | ||
|
||
smtc_hal_status_t hal_flash_deinit( void ) | ||
{ | ||
// nrf_fstorage_uninit( &fstorage, NULL ); | ||
return SMTC_HAL_SUCCESS; | ||
} |