Exemple #1
0
static void bootloader_settings_save(bootloader_settings_t * p_settings)
{
    //TODO. This is temporary
    static uint8_t              ant_boot_settings[BOOTLOADER_SETTINGS_FLASH_BLOCK_SIZE];
    static pstorage_handle_t    ant_boot_settings_handle;

    /* Backing up ant_boot_settings. */
    ant_boot_settings_handle.module_id  = m_bootsettings_handle.module_id;
    ant_boot_settings_handle.block_id   = m_bootsettings_handle.block_id + (BOOTLOADER_SETTINGS_FLASH_BLOCK_SIZE * (BOOTLOADER_SETTINGS_FLASH_BLOCK_COUNT - 1));
    memcpy(ant_boot_settings, (uint8_t*)ant_boot_settings_handle.block_id, BOOTLOADER_SETTINGS_FLASH_BLOCK_SIZE);

    /* NOTE: Must erase the whole module to prevent pstorage block erasing which uses swap space*/
    uint32_t err_code = pstorage_clear(&m_bootsettings_handle,
                                        BOOTLOADER_SETTINGS_FLASH_BLOCK_SIZE * BOOTLOADER_SETTINGS_FLASH_BLOCK_COUNT);
    APP_ERROR_CHECK(err_code);

    /* Write back ant_boot_settings */
    err_code = pstorage_store(&ant_boot_settings_handle,
                              ant_boot_settings,
                              BOOTLOADER_SETTINGS_FLASH_BLOCK_SIZE,
                              0);
    APP_ERROR_CHECK(err_code);

    err_code = pstorage_store(&m_bootsettings_handle,
                              (uint8_t *)p_settings,
                              sizeof(bootloader_settings_t),
                              0);
    APP_ERROR_CHECK(err_code);
}
Exemple #2
0
/**@brief Function for activating received Application image.
 *
 *  @details This function will move the received application image fram swap (bank 1) to
 *           application area (bank 0).
 *
 * @return NRF_SUCCESS on success. Error code otherwise.
 */
static uint32_t dfu_activate_app(void)
{
    uint32_t err_code;

    // Erase BANK 0.
    err_code = pstorage_clear(&m_storage_handle_app, m_start_packet.app_image_size);
    APP_ERROR_CHECK(err_code);

    err_code = pstorage_store(&m_storage_handle_app,
                                  (uint8_t *)m_storage_handle_swap.block_id,
                                  m_start_packet.app_image_size,
                                  0);

    if (err_code == NRF_SUCCESS)
    {
        dfu_update_status_t update_status;

        memset(&update_status, 0, sizeof(dfu_update_status_t ));
        update_status.status_code = DFU_UPDATE_APP_COMPLETE;
        update_status.app_crc     = m_image_crc;
        update_status.app_size    = m_start_packet.app_image_size;

        bootloader_dfu_update_process(update_status);
    }

    return err_code;
}
Exemple #3
0
uint32_t ble_ans_c_service_delete(void)
{
    if (m_client_state == STATE_UNINITIALIZED)
    {
        return NRF_SUCCESS;
    }

    return pstorage_clear(&m_flash_handle, (DISCOVERED_SERVICE_DB_SIZE * sizeof(uint32_t)));
}
Exemple #4
0
uint32_t ble_ans_c_service_delete(void)
{
    if (m_client_state == STATE_UNINITIALIZED)
    {
        return NRF_SUCCESS;
    }

    return pstorage_clear(&m_flash_handle, 0);
}
Exemple #5
0
/**@brief   Function for preparing swap before receiving application or bootloader image.
 *
 * @details This function will erase current swap area to ensure flash is ready for storage of the
 *          Application or Bootloader image. Upon erase complete a callback will be done.
 *          See \ref dfu_bank_prepare_t for further details.
 */
static void dfu_prepare_func_swap_erase(uint32_t image_size)
{
    uint32_t err_code;

    mp_storage_handle_active = &m_storage_handle_swap;

    m_dfu_state = DFU_STATE_PREPARING;
    err_code    = pstorage_clear(&m_storage_handle_swap, DFU_IMAGE_MAX_SIZE_BANKED);
    APP_ERROR_CHECK(err_code);
}
Exemple #6
0
H_U32 _StorageErase(pstorage_handle_t *flash_handle,H_U32 size)
{
	WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"erasing...");
	H_U32 err_code = 0; 
	err_code = pstorage_clear(flash_handle,size); 
	wy_tools_op()->_delay_ms(100);
	return err_code;
	//APP_ERROR_CHECK(err_code); 

}
static void bootloader_settings_save(bootloader_settings_t * p_settings)
{
    uint32_t err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t));
    APP_ERROR_CHECK(err_code);

    err_code = pstorage_store(&m_bootsettings_handle, 
                              (uint8_t *)p_settings, 
                              sizeof(bootloader_settings_t),
                              0);
    APP_ERROR_CHECK(err_code);
}
Exemple #8
0
/**@brief   Function for preparing of flash before receiving SoftDevice image.
 *
 * @details This function will erase current application area to ensure sufficient amount of
 *          storage for the SoftDevice image. Upon erase complete a callback will be done.
 *          See \ref dfu_bank_prepare_t for further details.
 */
static void dfu_prepare_func_app_erase(uint32_t image_size)
{
    uint32_t err_code;

    mp_storage_handle_active = &m_storage_handle_app;

    // Doing a SoftDevice update thus current application must be cleared to ensure enough space
    // for new SoftDevice.
    m_dfu_state = DFU_STATE_PREPARING;
    err_code    = pstorage_clear(&m_storage_handle_app, m_image_size);
    APP_ERROR_CHECK(err_code);
}
Exemple #9
0
bool Storage::BufferedWrite(u8* data, u32 block,u32 len)
{

	logt("STORAGE", "Writing len:%u to block:%u", len, block);

	//Call clear first before writing to the flash
	//Clear will generate an event that is handeled in the PstorabeEventHandler
	u32 err = pstorage_clear(&block_handles[block], 128);
	APP_ERROR_CHECK(err);

	return true;
}
/**
 * \callgraph
 * \brief	When the Ladybug needs to store info, it calls the flash_write routine.
 * \details	This routine assumes the flash storage to be used has been initialized by a call to flash_init.  Match the handle to
 * 		flash storage to the info the caller wants to write.
 * \note		As directed by the nRF51822 documentation, the flash storage is first cleared before a write to flash happens.
 * @param what_data_to_write	Whether to write out plant info, calibration values, or the device name.
 * @param p_bytes_to_write	A pointer to the bytes to be written to flash.
 * @param num_bytes_to_write	The number of bytes to write to flash
 * @param did_flash_action	Function caller passes in to be informed of the outcome of the Flash request.  The pointer to the function must be valid.
 */
void ladybug_flash_write(flash_rw_t what_data_to_write, uint8_t *p_bytes_to_write,pstorage_size_t num_bytes_to_write,void(*did_flash_action)(uint32_t err_code)){
  SEGGER_RTT_WriteString(0,"==> IN ladybug_flash_write\n");
  // Check parameters.  The what_data_to_write param is checked below in the switch statement.
  if (p_bytes_to_write == NULL || (did_flash_action == NULL)){
      APP_ERROR_HANDLER(LADYBUG_ERROR_NULL_POINTER);
  }
  if (num_bytes_to_write <= 0){
      APP_ERROR_HANDLER(LADYBUG_ERROR_NUM_BYTES_TO_WRITE);
  }
  // Set the static variable used to hold the location of the callback function to the pointer passed in by the caller.
  m_flash_return = did_flash_action;
  // Must clear the Flash block before write (or get unpredictable results).

  pstorage_handle_t *p_handle;
  switch (what_data_to_write) {
    case plantInfo:
      p_handle = &m_block_plantInfo_store_handle;
      break;
    case calibrationValues:
      p_handle = &m_block_calibration_store_handle;
      break;
    case deviceName:
      p_handle = &m_block_device_name_store_handle;
      break;
    default:
      APP_ERROR_HANDLER(LADYBUG_ERROR_INVALID_COMMAND);
      break;
  }
  //clearing the pstorage/flash sets the bytes to 0xFF
  // m_mypstorage_wait_flag is set to 0 within ladybug_flash_handler().  This way the system lets us know the Flash activity happened.
  m_mypstorage_wait_flag = 1;
  // There is a chance the Flash activity doesn't happen so we use a timer to prevent waiting forever.
  start_timer();
  uint32_t err_code = pstorage_clear(p_handle, BLOCK_SIZE);
  while(m_mypstorage_wait_flag) {  }
  APP_ERROR_CHECK(err_code);
  // The flash action happened, so turn off the timer before it goes off.
  stop_timer();
  // Start the timer up again to timeout if writing to flash doesn't happen
  start_timer();
  m_mypstorage_wait_flag = 1;
  err_code = pstorage_store(p_handle, p_bytes_to_write, num_bytes_to_write, 0);
  while(m_mypstorage_wait_flag) {  }
  APP_ERROR_CHECK(err_code);
  stop_timer();
}