Skip to content

Commit

Permalink
hal_flash: implement with nonvolatile storage
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Feb 22, 2024
1 parent f4b5264 commit 668775c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 113 deletions.
50 changes: 0 additions & 50 deletions wm1110/wm1110/include/smtc_hal_flash.h

This file was deleted.

30 changes: 30 additions & 0 deletions wm1110/wm1110/include_tock/smtc_hal_flash.h
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
80 changes: 17 additions & 63 deletions wm1110/wm1110/src_tock/smtc_hal_flash.c
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;
}

0 comments on commit 668775c

Please sign in to comment.