/** * \callgraph *\brief Initialize the blocks of flash memory used for reading/writing. *\details Uses Nordic's pstorage software abstraction/API to cleanly access flash when the SoftDevice (for BLE) * is also running. */ void ladybug_flash_init() { SEGGER_RTT_WriteString(0,"==> IN ladybug_flash_init\n"); pstorage_module_param_t pstorage_param; //Used when registering with pstorage pstorage_handle_t handle; //used to access the chunk-o-flash requested when registering //First thing is to initialize pstorage uint32_t err_code = pstorage_init(); //if initialization was not successful, the error routine will be called and the code won't proceed. APP_ERROR_CHECK(err_code); //Next is to register amount of flash needed. The smallest amount that can be requested is 16 bytes. I'm requesting //32 bytes because this is the number of bytes needed for plant_info. Two blocks are used...one for plant info and one for hydro values. I must make a //block request for the larger amount of bytes pstorage_param.block_size = BLOCK_SIZE; //request three blocks - one will be for pH, one for plant_info, and one for device name pstorage_param.block_count = 3; //assign a callback so know when a command has finished. pstorage_param.cb = ladybug_flash_handler; err_code = pstorage_register(&pstorage_param, &handle); APP_ERROR_CHECK(err_code); //Then get the handles to the blocks of flash pstorage_block_identifier_get(&handle, 0, &m_block_calibration_store_handle); pstorage_block_identifier_get(&handle,1,&m_block_plantInfo_store_handle); pstorage_block_identifier_get(&handle,2,&m_block_device_name_store_handle); // Create the timer. This will be called before a Flash activity is requested to avoid forever hanging. create_timer(); }
uint32_t dfu_init(void) { uint32_t err_code; pstorage_module_param_t storage_module_param = {.cb = pstorage_callback_handler}; m_init_packet_length = 0; m_image_crc = 0; err_code = pstorage_register(&storage_module_param, &m_storage_handle_app); if (err_code != NRF_SUCCESS) { m_dfu_state = DFU_STATE_INIT_ERROR; return err_code; } m_storage_handle_app.block_id = DFU_BANK_0_REGION_START; // Create the timer to monitor the activity by the peer doing the firmware update. err_code = app_timer_create(&m_dfu_timer_id, APP_TIMER_MODE_SINGLE_SHOT, dfu_timeout_handler); APP_ERROR_CHECK(err_code); // Start the DFU timer. err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); APP_ERROR_CHECK(err_code); m_data_received = 0; m_dfu_state = DFU_STATE_IDLE; return NRF_SUCCESS; }
uint32_t bootloader_dfu_start(void) { uint32_t err_code = NRF_SUCCESS; pstorage_module_param_t storage_params; storage_params.cb = pstorage_callback_handler; storage_params.block_size = sizeof(bootloader_settings_t); storage_params.block_count = 1; err_code = pstorage_init(); if (err_code != NRF_SUCCESS) { return err_code; } err_code = pstorage_register(&storage_params, &m_bootsettings_handle); if (err_code != NRF_SUCCESS) { return err_code; } // Clear swap if banked update is used. err_code = dfu_init(); if (err_code != NRF_SUCCESS) { return err_code; } err_code = dfu_transport_update_start(); wait_for_events(); return err_code; }
Storage::Storage() { u32 err; //Register with Terminal Terminal::AddTerminalCommandListener(this); //Initialize queue for queueing store and load tasks taskQueue = new SimpleQueue(taskBuffer, TASK_BUFFER_LENGTH); //Initialize pstorage library pstorage_module_param_t param; u8 num_blocks = STORAGE_BLOCK_NUMBER; bufferedOperationInProgress = false; param.block_size = STORAGE_BLOCK_SIZE; //Multiple of 4 and divisor of page size (pagesize is usually 1024) in case total size is bigger than page size param.block_count = 1; param.cb = PstorageEventHandler; err = pstorage_init(); APP_ERROR_CHECK(err); //Register a number of blocks if (pstorage_register(¶m, &handle) != NRF_SUCCESS) { logt("STORAGE", "Could not register storage"); } for (u32 i = 0; i < num_blocks; ++i) { pstorage_block_identifier_get(&handle, i, &block_handles[i]); } }
uint32_t bootloader_init(void) { uint32_t err_code; pstorage_module_param_t storage_params = {.cb = pstorage_callback_handler}; err_code = pstorage_init(); VERIFY_SUCCESS(err_code); m_bootsettings_handle.block_id = BOOTLOADER_SETTINGS_ADDRESS; err_code = pstorage_register(&storage_params, &m_bootsettings_handle); return err_code; }
H_U32 _StorageRegister(pstorage_handle_t *flash_handle, H_U32 block_size,H_U32 block_count,stroage_callback cb) { H_U32 err_code = 0; pstorage_module_param_t PST_param; wy_memset(&PST_param, 0 ,sizeof(pstorage_module_param_t)); PST_param.block_size = block_size; PST_param.block_count = block_count; PST_param.cb = cb; err_code = pstorage_register(&PST_param,flash_handle); APP_ERROR_CHECK(err_code); return err_code; }
uint32_t bootloader_init(void) { uint32_t err_code; pstorage_module_param_t storage_params; storage_params.cb = pstorage_callback_handler; storage_params.block_size = BOOTLOADER_SETTINGS_FLASH_BLOCK_SIZE; storage_params.block_count = BOOTLOADER_SETTINGS_FLASH_BLOCK_COUNT; err_code = pstorage_init(); if (err_code != NRF_SUCCESS) { return err_code; } err_code = pstorage_register(&storage_params, &m_bootsettings_handle); m_delay_applied = false; return err_code; }
bool pstorage_driver_cfg(uint16_t block_size) { uint32_t err_code; // Set module registration param. pstorage_driver.module_param.block_size = block_size; // Set desired block size for persistent memory storage. pstorage_driver.module_param.block_count = PSTORAGE_DRIVER_NUM_OF_BLOCKS; // Set number of blocks requested by the module. pstorage_driver.module_param.cb = pstorage_driver_cb_handler; // Set persistent storage error reporting callback // Initialize fields for store opperation. pstorage_driver_store.block = NULL; pstorage_driver_store.error_status = PS_STORE_STATUS_NO_ERR; pstorage_driver_store.state = STORE_STATE_IDLE; pstorage_driver_store.run_flag = false; pstorage_driver_store.wait_flag = false; // Register with persistent storage interface. err_code = pstorage_register(&pstorage_driver.module_param, &pstorage_driver.base_id); return (err_code == NRF_SUCCESS) ? true : false; }
uint32_t ble_ans_c_init(ble_ans_c_t * p_ans, const ble_ans_c_init_t * p_ans_init) { uint32_t err_code; pstorage_module_param_t param; if (p_ans_init->evt_handler == NULL) { return NRF_ERROR_INVALID_PARAM; } p_ans->evt_handler = p_ans_init->evt_handler; p_ans->error_handler = p_ans_init->error_handler; p_ans->service_handle = INVALID_SERVICE_HANDLE; p_ans->central_handle = INVALID_CENTRAL_HANDLE; p_ans->service_handle = 0; p_ans->message_buffer_size = p_ans_init->message_buffer_size; p_ans->p_message_buffer = p_ans_init->p_message_buffer; p_ans->conn_handle = BLE_CONN_HANDLE_INVALID; m_ans_c_obj = p_ans; memset(&m_service, 0, sizeof(alert_service_t)); memset(m_tx_buffer, 0, TX_BUFFER_SIZE); m_service.handle = INVALID_SERVICE_HANDLE; m_client_state = STATE_IDLE; param.block_count = 1; param.block_size = DISCOVERED_SERVICE_DB_SIZE * sizeof(uint32_t); // uint32_t array. param.cb = ans_pstorage_callback; // Register with storage module. err_code = pstorage_register(¶m, &m_flash_handle); mp_service_db = (alert_service_t *) (m_service_db); return err_code; }
void crypto_init(void) { uint32_t err_code; static const pstorage_module_param_t param = { .cb = crypto_pstorage_callback, .block_size = sizeof(crypto_persistent_keys_t), .block_count = 1 }; err_code = pstorage_register((pstorage_module_param_t*)¶m, &crypto_store_handle); APP_ERROR_CHECK(err_code); if (!crypto_loadKeys()) { srp_init(); crypto_sign_keypair(crypto_keys.sign.public, crypto_keys.sign.secret); // Store for reuse crypto_scheduleStoreKeys(); crypto_storeKeys(); } }