Esempio n. 1
0
OSStatus platform_flash_write( const platform_flash_t *peripheral, volatile uint32_t* start_address, uint8_t* data ,uint32_t length  )
{
  OSStatus err = kNoErr;

  require_action_quiet( peripheral != NULL, exit, err = kParamErr);
  require_action( *start_address >= peripheral->flash_start_addr 
               && *start_address + length <= peripheral->flash_start_addr + peripheral->flash_length, exit, err = kParamErr);
    
  if( peripheral->flash_type == FLASH_TYPE_EMBEDDED ){
    err = internalFlashWrite( start_address, (uint32_t *)data, length); 
    require_noerr(err, exit);
  }
#ifdef USE_MICO_SPI_FLASH
  else if( peripheral->flash_type == FLASH_TYPE_SPI ){
    err = sflash_write( &sflash_handle, *start_address, data, length );
    require_noerr(err, exit);
    *start_address += length;
  }
#endif
  else{
    err = kTypeErr;
    goto exit;
  }

exit:
  return err;
}
Esempio n. 2
0
OSStatus platform_flash_write( platform_flash_driver_t *driver, volatile uint32_t* FlashAddress, uint8_t* Data ,uint32_t DataLength  )
{
  OSStatus err = kNoErr;

  require_action_quiet( driver != NULL, exit, err = kParamErr);
  require_action_quiet( driver->initialized != false, exit, err = kNotInitializedErr);
  require_action( *FlashAddress >= driver->peripheral->flash_start_addr 
               && *FlashAddress + DataLength <= driver->peripheral->flash_start_addr + driver->peripheral->flash_length, exit, err = kParamErr);
#ifndef NO_MICO_RTOS 
  mico_rtos_lock_mutex( &driver->flash_mutex );
#endif
  if( driver->peripheral->flash_type == FLASH_TYPE_INTERNAL ){
    err = internalFlashWrite(FlashAddress, (uint32_t *)Data, DataLength); 
    require_noerr(err, exit_with_mutex);
  }
#ifdef USE_MICO_SPI_FLASH
  else if( driver->peripheral->flash_type == FLASH_TYPE_SPI ){
    err = sflash_write( &sflash_handle, *FlashAddress, Data, DataLength );
    require_noerr(err, exit_with_mutex);
    *FlashAddress += DataLength;
  }
#endif
  else{
    err = kTypeErr;
    goto exit_with_mutex;
  }

exit_with_mutex: 
#ifndef NO_MICO_RTOS 
  mico_rtos_unlock_mutex( &driver->flash_mutex );
#endif

exit:
  return err;
}