Read a certain amount of bytes from a file in WINC's Flash using SPI transfer.
- Parameters
-
[in] | u8Handler | ID of the file we are trying to read from. Must be valid. |
[in] | pu8Buff | Pointer to a buffer to store the data being read. Must be valid. |
[in] | u32Offset | Offset from start of the file to read from (in bytes). |
[in] | u32Size | The amount of data to read (in Bytes). |
- Returns
- Status of the read operation.
- Warning
- Before using m2m_ota_host_file_read_spi, the WINC needs to be put in a special mode to allow for a safe access to the Flash. This can be done by calling m2m_wifi_download_mode or m2m_wifi_reinit_hold before trying to read.
- Parameters
-
[in] | u8Handler | Handler of the file we are trying to read from. Must be valid. |
[in] | pu8Buff | Pointer to a buffer to store the data being read. Must not be NULL. |
[in] | u32Offset | Offset from start of the file to read from (in bytes). |
[in] | u32Size | The amount of data to read (in Bytes). |
- Returns
- The function SHALL return M2M_SUCCESS for success and a negative value otherwise.
- Warning
- Reading of a file via SPI can be much faster than by reading it via the HIF. However, the read will be blocking and it will require the WINC to be put into download mode prior to the read, the download mode means that the WINC will act as Flash device and not as a Wifi device. So, before using m2m_ota_host_file_read_spi, the Application should call m2m_wifi_download_mode before trying to read. After the read finishes, the WINC needs to be reset (see m2m_wifi_reinit).
A valid file handler must be provided, this means that it needs to match the handler internally stored by the WINC and must not be HFD_INVALID_HANDLER.
- See Also
- m2m_ota_init m2m_ota_host_file_get
File Download SPI Read Example
The following is an example of how to perform a read file from the WINC via SPI.
typedef struct {
}FileDescriptor;
static FileDescriptor gstrAppFile;
char *acURL = "http://www.microchip.com/_images/ics/medium-ATWINC1500-MODULE-28.png";
static void ReadFileSPI(void);
static void wifi_event_cb(
uint8 u8WiFiEvent,
void * pvMsg);
static void wifi_event_cb(
uint8 u8WiFiEvent,
void * pvMsg)
{
{
gstrAppFile.u32Offset = 0;
{
M2M_ERR(
"File Download Failed!\n");
}
}
break;
default:
break;
}
{
M2M_INFO(
"%d %d\n",u8OtaUpdateStatusType,u8OtaUpdateStatus);
{
{
ReadFileSPI();
}
}
}
{
{
gstrAppFile.u8Handler = u8Handler;
gstrAppFile.u32Size = u32Size;
}
else
{
}
}
static void ReadFileSPI(void)
{
M2M_INFO(
"\nFile Read completed, Offset: %lu, Size of Read: %lu.\n", gstrAppFile.u32Offset, u32AmountToRead);
EXIT:
return;
}
{
{
M2M_ERR(
"Driver Init Failed <%d>\n",s8Ret);
while(1);
}
}
References ENTRY_ID_HOSTFILE, FLASH_SECTOR_SZ, HFD_INVALID_HANDLER, M2M_ERR, M2M_ERR_FAIL, M2M_ERR_INVALID_ARG, M2M_SUCCESS, m2m_wifi_get_state(), NULL, spi_flash_read(), spi_flexible_flash_find_section(), and WIFI_STATE_INIT.