Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void pstorage_handle(pstorage_handle_t * p_handle,
- uint8_t op_code,
- uint32_t result,
- uint8_t * p_data,
- uint32_t data_len) {
- //todo: this is for error handler. Need to nortify if something happen
- uint32_t err_code;
- uint8_t data[4] = {1,2,3,4};
- uint8_t temp_result[4];
- uint32_t count;
- pstorage_handle_t temp_block;
- switch(op_code)
- {
- case PSTORAGE_STORE_OP_CODE:
- case PSTORAGE_UPDATE_OP_CODE:
- if (result == NRF_SUCCESS)
- {
- nrf_delay_ms(1000);
- pstorage_block_identifier_get(&m_pstorage_handle, 0, &temp_block);
- err_code = pstorage_load(temp_result, &temp_block, 4, 0 );
- if (err_code != NRF_SUCCESS)
- APP_ERROR_CHECK(err_code);
- nrf_gpio_pin_set(LED_START + temp_result[0]);
- //Store operation successful.
- }
- else
- {
- // Store operation failed.
- }
- // Source memory can now be reused or freed.
- break;
- case PSTORAGE_CLEAR_OP_CODE:
- if (result == NRF_SUCCESS)
- {
- pstorage_block_identifier_get(&m_pstorage_handle, 0, &temp_block);
- err_code = pstorage_store(&temp_block, data, 4, 0);
- //nrf_delay_ms(1000);
- if (err_code != NRF_SUCCESS)
- APP_ERROR_CHECK(err_code);
- } else
- {
- }
- break;
- case PSTORAGE_LOAD_OP_CODE:
- nrf_gpio_pin_set(LED_START + p_data[0]);
- break;
- default:
- break;
- }
- }
- //init pstorage
- static void data_init(void){
- uint32_t err_code;
- extern pstorage_handle_t m_pstorage_handle;
- extern pstorage_module_param_t m_pstorage_param;
- err_code = pstorage_init();
- if (err_code == NRF_SUCCESS) {
- //module initialization successful
- m_pstorage_param.block_size = 20;
- m_pstorage_param.block_count = 2;
- m_pstorage_param.cb = pstorage_handle;
- err_code = pstorage_register(&m_pstorage_param, &m_pstorage_handle);
- if (err_code != NRF_SUCCESS)
- APP_ERROR_CHECK(err_code);
- err_code = pstorage_clear(&m_pstorage_handle, 20*2);
- if (err_code != NRF_SUCCESS)
- APP_ERROR_CHECK(err_code);
- } else {
- APP_ERROR_CHECK(err_code);
- }
- }
- int main(void)
- {
- advertising_status = 0;
- // Initialize
- leds_init();
- timers_init();
- ble_stack_init();
- scheduler_init();
- data_init();
- // Enter main loop
- for (;;)
- {
- app_sched_execute();
- power_manage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement