Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions

     Lists the full set of available APIs to manage OTA updates and Host File Downloads.

Modules

 Common
 
 WINC
 
 HFD
 

Functions

NMI_API sint8 m2m_ota_abort (void)
 Request OTA Abort. More...
 
NMI_API sint8 m2m_ota_init (tpfOtaUpdateCb pfOtaUpdateCb, tpfOtaNotifCb pfOtaNotifCb)
 Initialize the OTA layer. More...
 
NMI_API sint8 m2m_ota_notif_check_for_update (void)
 Check for OTA update. More...
 
NMI_API sint8 m2m_ota_notif_sched (uint32 u32Period)
 Schedule OTA update. More...
 
NMI_API sint8 m2m_ota_notif_set_url (uint8 *u8Url)
 Set the OTA url. More...
 
NMI_API sint8 m2m_ota_rollback (void)
 Request OTA Rollback image. More...
 
NMI_API sint8 m2m_ota_start_update (unsigned char *pcDownloadUrl)
 Request OTA start update using the downloaded URL. More...
 
NMI_API sint8 m2m_ota_switch_firmware (void)
 Switch to the upgraded Firmware. More...
 
sint8 m2m_wifi_check_ota_rb (void)
 Synchronous API to check presence and compatibility of the WINC image that is stored in the inactive flash partition. This is the image that would run on the WINC IC if m2m_ota_switch_firmware or m2m_ota_rollback were called, followed by a reset of the WINC IC. More...
 

sint8 m2m_ota_abort ( void  )

Request OTA Abort.

Request the WINC to abort an OTA or Host File download in progress.
If no download is in progress, the API will respond with failure.

Request the WINC to abort an OTA in progress.
If no download is in progress, the API will respond with failure.

Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
See Also
m2m_ota_init m2m_ota_start_update
Returns
The function returns M2M_SUCCESS for a successful operation and a negative value otherwise.
sint8 m2m_ota_init ( tpfOtaUpdateCb  pfOtaUpdateCb,
tpfOtaNotifCb  pfOtaNotifCb 
)

Initialize the OTA layer.

Synchronous initialization function for the OTA layer by registering the update callback.
The notification callback is not supported at the current version. Calling this API is a MUST for all the OTA API's.

Parameters
[in]pfOtaUpdateCbOTA Update callback function.
[in]pfOtaNotifCbOTA notify callback function.
Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Parameters
[in]pfOtaUpdateCbOTA Update callback function.
[in]pfOtaNotifCbOTA Notify callback function.
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
Parameters
[in]pfOtaUpdateCbOTA Update callback function.
[in]pfOtaNotifCbOTA Notify callback function.
Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.

Referenced by main().

sint8 m2m_ota_notif_check_for_update ( void  )

Check for OTA update.

Synchronous function to check for the OTA update using the Notification Server URL.
Function is not implemented (not supported at the current version).

Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Warning
Function is not implemented (not supported at the current version).
See Also
m2m_ota_init m2m_ota_notif_set_url
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
sint8 m2m_ota_notif_sched ( uint32  u32Period)

Schedule OTA update.

Schedule OTA notification Server check for update request after specific number of days.
Function is not implemented (not supported at the current version).

Parameters
[in]u32PeriodPeriod in days
Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Parameters
[in]u32PeriodPeriod in days
Warning
Function is not implemented (not supported at the current version).
See Also
m2m_ota_init m2m_ota_notif_check_for_update m2m_ota_notif_set_url
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
sint8 m2m_ota_notif_set_url ( uint8 u8Url)

Set the OTA url.

Set the OTA notification server URL, the function needs to be called before any check for update.
This functionality is not supported by WINC firmware.

Parameters
[in]u8UrlThe url server address.
Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Parameters
[in]u8UrlSet the OTA notification server URL, the function needs to be called before any check for update.
Precondition
Prior calling of m2m_ota_init is required.
Warning
Notification Server is not supported in the current version (function is not implemented).
See Also
m2m_ota_init
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
sint8 m2m_ota_rollback ( void  )

Request OTA Rollback image.

Request OTA Roll-back to the old (inactive) WINC image, the WINC firmware will check the validity of the inactive image and activate it if valid. On completion, a callback of type tpfOtaUpdateCb is called (application must previously have provided the callback via m2m_ota_init). If the callback indicates successful activation, the newly-activated image will start running after next system reset.

Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Warning
If rollback requires a host driver update in order to maintain HIF compatibility (HIF major value change), then it is recommended to update the host driver prior to calling this API.
In the event of system reset with incompatible driver/firmware, compatibility can be recovered by calling m2m_ota_rollback or m2m_ota_switch_firmware. See Example.
See Also
m2m_ota_init m2m_ota_start_update
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.

Referenced by main().

sint8 m2m_ota_start_update ( unsigned char *  pcDownloadUrl)

Request OTA start update using the downloaded URL.

Request OTA start update using the download URL. The OTA module will download the OTA image, ensure integrity of the image and update the validity of the image in the control structure. On completion, a callback of type tpfOtaUpdateCb is called (callback previously provided via m2m_ota_init). Switching to the updated image additionally requires completion of m2m_ota_switch_firmware and system_reset.

Request OTA start update using the download URL. The OTA module will download the OTA image, ensure integrity of the image and update the validity of the image in the control structure. On completion, a callback of type tpfOtaUpdateCb is called (callback previously provided via m2m_ota_init). Switching to the updated image additionally requires completion of m2m_ota_switch_firmware, followed by a WINC reset.

Parameters
[in]pcDownloadUrlThe download firmware URL, you get it from device info.
Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Parameters
[in]pcDownloadUrlThe download firmware URL, according to the application server.
Warning
Calling this API does not guarantee OTA WINC image update, it depends on the connection with the download server and the validity of the image.
Calling this API invalidates any previous valid rollback image, irrespective of the result, but when the OTA succeeds, the current image will become the rollback image after m2m_ota_switch_firmware.
Precondition
m2m_ota_init is a prerequisite and must have been called before using m2m_ota_start_update.
Switching to the newly downloaded image requires calling m2m_ota_switch_firmware API.
See Also
m2m_ota_init m2m_ota_switch_firmware tpfOtaUpdateCb
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise. Note that successful operation in this context means the OTA update request has reached the firmware OTA module. It does not indicate whether or not the image update succeeded.

Example

This example shows how an OTA image update and switch is carried out. It demonstrates use of the following OTA APIs:

It also makes use of m2m_wifi_check_ota_rb in order to inform OTA decisions.

static void OtaUpdateCb(uint8 u8OtaUpdateStatusType, uint8 u8OtaUpdateStatus)
{
sint8 s8tmp;
tstrM2mRev strtmp;
M2M_INFO("%d %d\n", u8OtaUpdateStatusType, u8OtaUpdateStatus);
switch(u8OtaUpdateStatusType)
{
case DL_STATUS:
if(u8OtaUpdateStatus == OTA_STATUS_SUCCESS)
{
M2M_INFO("OTA download succeeded\n");
{
// In this case the application SHOULD update the host driver before calling
// @ref m2m_ota_switch_firmware(). Switching firmware image and resetting without updating host
// driver would lead to severely limited functionality (i.e. OTA rollback only).
}
else if(s8tmp == M2M_SUCCESS)
{
// In this case the application MAY WANT TO update the host driver before calling
// @ref m2m_ota_switch_firmware(). Switching firmware image and resetting without
// updating host driver may lead to suboptimal functionality.
}
else
{
M2M_INFO("Cannot recognize downloaded image\n");
// In this case the application MUST NOT update the host driver if such an update would change the
// driver HIF Major field. Firmware switch @ref using m2m_ota_switch_firmware() is blocked.
break;
}
// Switch to the upgraded firmware
M2M_INFO("Now switching active partition...\n");
}
break;
case SW_STATUS:
case RB_STATUS:
if(u8OtaUpdateStatus == OTA_STATUS_SUCCESS)
{
M2M_INFO("Switch/Rollback succeeded\n");
// Start the host SW upgrade if required, then system reset is required (Reinitialize the driver)
M2M_INFO("Now resetting the system...\n");
}
break;
}
}
static void wifi_event_cb(uint8 u8WiFiEvent, void *pvMsg)
{
// ...
{
// After successful connection, start the OTA upgrade
}
break;
default:
break;
// ...
}
int main(void)
{
sint8 s8Ret = M2M_SUCCESS;
bool rollback_required = FALSE;
// System init, etc should be here...
m2m_memset((uint8 *)&param, 0, sizeof(param));
param.pfAppWifiCb = wifi_event_cb;
// Initialize the WINC Driver
s8Ret = m2m_wifi_init(&param);
{
M2M_ERR("Firmware version mismatch\n");
if(s8Ret == M2M_SUCCESS)
{
// In this case the image in the inactive partition has compatible HIF. We will switch/rollback to it
// after initializing the OTA module.
rollback_required = TRUE;
}
}
if(M2M_SUCCESS != s8Ret)
{
M2M_ERR("Driver Init Failed <%d>\n", s8Ret);
while(1);
}
// Initialize the OTA module
if(rollback_required)
{
// We need to call either @ref m2m_ota_rollback() or @ref m2m_ota_switch_firmware() (functionally equivalent).
}
else
{
// Connect to AP that provides connection to the OTA server
}
while(1)
{
// Handle the app state machine plus the WINC event handler
}
}
}
Parameters
[in]pcDownloadUrlThe download firmware URL, according to the application server.
Warning
Calling this API does not guarantee OTA WINC image update, it depends on the connection with the download server and the validity of the image.
Calling this API invalidates any previous valid rollback image, irrespective of the result, but when the OTA succeeds, the current image will become the rollback image after m2m_ota_switch_firmware.
Precondition
m2m_ota_init is a prerequisite and must have been called before using m2m_ota_start_update.
Switching to the newly downloaded image requires calling m2m_ota_switch_firmware API.
See Also
m2m_ota_init m2m_ota_switch_firmware tpfOtaUpdateCb
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise. Note that successful operation in this context means the OTA update request has reached the firmware OTA module. It does not indicate whether or not the image update succeeded.

Example

This example shows how an OTA image update and switch is carried out. It demonstrates use of the following OTA APIs:

static void OtaUpdateCb(uint8 u8OtaUpdateStatusType, uint8 u8OtaUpdateStatus)
{
M2M_INFO("%d %d\n", u8OtaUpdateStatusType, u8OtaUpdateStatus);
switch(u8OtaUpdateStatusType)
{
case DL_STATUS:
if(u8OtaUpdateStatus == OTA_STATUS_SUCCESS)
{
M2M_INFO("OTA download succeeded\n");
// In this case the application MAY WANT TO update the host driver before calling
// @ref m2m_ota_switch_firmware(). Switching firmware image and resetting without
// updating host driver may lead to suboptimal functionality.
// Switch to the upgraded firmware
M2M_INFO("Now switching active partition...\n");
}
break;
case SW_STATUS:
case RB_STATUS:
if(u8OtaUpdateStatus == OTA_STATUS_SUCCESS)
{
M2M_INFO("Switch/Rollback succeeded\n");
// Start the host SW upgrade if required, then system reset is required (Reinitialize the driver)
M2M_INFO("Now resetting the system...\n");
}
break;
}
}
static void wifi_event_cb(uint8 u8WiFiEvent, void *pvMsg)
{
// ...
{
// After successful connection, start the OTA upgrade
}
break;
default:
break;
// ...
}
int main (void)
{
sint8 s8Ret = M2M_SUCCESS;
bool rollback_required = FALSE;
// System init, etc should be here...
m2m_memset((uint8*)&param, 0, sizeof(param));
param.pfAppWifiCb = wifi_event_cb;
// Initialize the WINC Driver
s8Ret = m2m_wifi_init(&param);
{
M2M_ERR("Firmware version mismatch\n");
}
if (M2M_SUCCESS != s8Ret)
{
M2M_ERR("Driver Init Failed <%d>\n",s8Ret);
while(1);
}
// Initialize the OTA module
// Connect to AP that provides connection to the OTA server
while(1)
{
// Handle the app state machine plus the WINC event handler
}
}
}

Referenced by wifi_cb().

sint8 m2m_ota_switch_firmware ( void  )

Switch to the upgraded Firmware.

Request switch to the updated WINC image. The WINC firmware will check the validity of the inactive image and activate it if valid. On completion, a callback of type tpfOtaUpdateCb is called (application must previously have provided the callback via m2m_ota_init). If the callback indicates successful activation, the newly-activated image will start running after next system reset.

Returns
The function returns M2M_SUCCESS for success and a negative value otherwise.
Warning
If switch requires a host driver update in order to maintain HIF compatibility (HIF major value change), then it is recommended to update the host driver prior to calling this API.
In the event of system reset with incompatible driver/firmware, compatibility can be recovered by calling m2m_ota_rollback or m2m_ota_switch_firmware. See Example.
See Also
m2m_ota_init m2m_ota_start_update
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.

Referenced by OtaUpdateCb().

sint8 m2m_wifi_check_ota_rb ( void  )

Synchronous API to check presence and compatibility of the WINC image that is stored in the inactive flash partition. This is the image that would run on the WINC IC if m2m_ota_switch_firmware or m2m_ota_rollback were called, followed by a reset of the WINC IC.

Synchronous API to check presence and compatibility of the WINC image that is stored in the inactive flash partition. This is the image that would run on the WINC if m2m_ota_switch_firmware or m2m_ota_rollback were called, followed by a reset of the WINC.

Returns
The function SHALL return M2M_SUCCESS for compatible image and a negative value otherwise.
The function returns M2M_SUCCESS for compatible image and a negative value otherwise.

References hif_check_compatibility(), M2M_SUCCESS, nm_get_hif_info(), NULL, and ret.

Referenced by main(), and OtaUpdateCb().