-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding OTA Agent with suspend resume.
- Loading branch information
1 parent
bcd93cb
commit 2199b83
Showing
5 changed files
with
981 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* AWS IoT Over-the-air Update v3.4.0 | ||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* @file ota_os_freertos.c | ||
* @brief Example implementation of the OTA OS Functional Interface for | ||
* FreeRTOS. | ||
*/ | ||
|
||
/* FreeRTOS includes. */ | ||
#include "FreeRTOS.h" | ||
#include "timers.h" | ||
#include "queue.h" | ||
|
||
/* OTA OS POSIX Interface Includes.*/ | ||
|
||
#include "ota_os_freertos.h" | ||
#include "ota_demo.h" | ||
|
||
/* OTA Event queue attributes.*/ | ||
#define MAX_MESSAGES 20 | ||
#define MAX_MSG_SIZE sizeof( OtaEventMsg_t ) | ||
|
||
/* Array containing pointer to the OTA event structures used to send events to the OTA task. */ | ||
static OtaEventMsg_t queueData[ MAX_MESSAGES * MAX_MSG_SIZE ]; | ||
|
||
/* The queue control structure. .*/ | ||
static StaticQueue_t staticQueue; | ||
|
||
/* The queue control handle. .*/ | ||
static QueueHandle_t otaEventQueue; | ||
|
||
|
||
OtaOsStatus_t OtaInitEvent_FreeRTOS() | ||
{ | ||
OtaOsStatus_t otaOsStatus = OtaOsSuccess; | ||
|
||
otaEventQueue = xQueueCreateStatic( ( UBaseType_t ) MAX_MESSAGES, | ||
( UBaseType_t ) MAX_MSG_SIZE, | ||
( uint8_t * ) queueData, | ||
&staticQueue ); | ||
|
||
if( otaEventQueue == NULL ) | ||
{ | ||
otaOsStatus = OtaOsEventQueueCreateFailed; | ||
|
||
printf( "Failed to create OTA Event Queue: " | ||
"xQueueCreateStatic returned error: " | ||
"OtaOsStatus_t=%d \n", | ||
( int ) otaOsStatus ); | ||
} | ||
else | ||
{ | ||
printf( "OTA Event Queue created.\n" ); | ||
} | ||
|
||
return otaOsStatus; | ||
} | ||
|
||
OtaOsStatus_t OtaSendEvent_FreeRTOS( const void * pEventMsg ) | ||
{ | ||
OtaOsStatus_t otaOsStatus = OtaOsSuccess; | ||
BaseType_t retVal = pdFALSE; | ||
|
||
/* Send the event to OTA event queue.*/ | ||
retVal = xQueueSendToBack( otaEventQueue, pEventMsg, ( TickType_t ) 0 ); | ||
|
||
if( retVal == pdTRUE ) | ||
{ | ||
printf( "OTA Event Sent.\n" ); | ||
} | ||
else | ||
{ | ||
otaOsStatus = OtaOsEventQueueSendFailed; | ||
|
||
printf( "Failed to send event to OTA Event Queue: " | ||
"xQueueSendToBack returned error: " | ||
"OtaOsStatus_t=%d \n", | ||
( int ) otaOsStatus ); | ||
} | ||
|
||
return otaOsStatus; | ||
} | ||
|
||
OtaOsStatus_t OtaReceiveEvent_FreeRTOS( void * pEventMsg ) | ||
{ | ||
OtaOsStatus_t otaOsStatus = OtaOsSuccess; | ||
BaseType_t retVal = pdFALSE; | ||
|
||
/* Temp buffer.*/ | ||
uint8_t buff[ sizeof( OtaEventMsg_t ) ]; | ||
|
||
retVal = xQueueReceive( otaEventQueue, &buff, pdMS_TO_TICKS( 1000U ) ); | ||
|
||
if( retVal == pdTRUE ) | ||
{ | ||
/* copy the data from local buffer.*/ | ||
memcpy( pEventMsg, buff, MAX_MSG_SIZE ); | ||
printf( "OTA Event received \n" ); | ||
} | ||
else | ||
{ | ||
otaOsStatus = OtaOsEventQueueReceiveFailed; | ||
|
||
printf( "Failed to receive event or timeout from OTA Event Queue: " | ||
"xQueueReceive returned error: " | ||
"OtaOsStatus_t=%d \n", | ||
( int ) otaOsStatus ); | ||
} | ||
|
||
return otaOsStatus; | ||
} | ||
|
||
OtaOsStatus_t OtaDeinitEvent_FreeRTOS() | ||
{ | ||
OtaOsStatus_t otaOsStatus = OtaOsSuccess; | ||
|
||
/* Remove the event queue.*/ | ||
if( otaEventQueue != NULL ) | ||
{ | ||
vQueueDelete( otaEventQueue ); | ||
|
||
printf( "OTA Event Queue Deleted. \n" ); | ||
} | ||
|
||
return otaOsStatus; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. and its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Licensed under the MIT License. See the LICENSE accompanying this file | ||
* for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
/** | ||
* @file ota_os_freertos.h | ||
* @brief Function declarations for the example OTA OS Functional interface for | ||
* FreeRTOS. | ||
*/ | ||
|
||
#ifndef _OTA_OS_FREERTOS_H_ | ||
#define _OTA_OS_FREERTOS_H_ | ||
|
||
/* Standard library include. */ | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
/** | ||
* @ingroup ota_enum_types | ||
* @brief The OTA OS interface return status. | ||
*/ | ||
typedef enum OtaOsStatus | ||
{ | ||
OtaOsSuccess = 0, /*!< @brief OTA OS interface success. */ | ||
OtaOsEventQueueCreateFailed = 0x80U, /*!< @brief Failed to create the event queue. */ | ||
OtaOsEventQueueSendFailed, /*!< @brief Posting event message to the event queue failed. */ | ||
OtaOsEventQueueReceiveFailed, /*!< @brief Failed to receive from the event queue. */ | ||
OtaOsEventQueueDeleteFailed, /*!< @brief Failed to delete the event queue. */ | ||
} OtaOsStatus_t; | ||
|
||
/** | ||
* @brief Initialize the OTA events. | ||
* | ||
* This function initializes the OTA events mechanism for freeRTOS platforms. | ||
* | ||
* @param[pEventCtx] Pointer to the OTA event context. | ||
* | ||
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure. | ||
*/ | ||
OtaOsStatus_t OtaInitEvent_FreeRTOS( ); | ||
|
||
/** | ||
* @brief Sends an OTA event. | ||
* | ||
* This function sends an event to OTA library event handler on FreeRTOS platforms. | ||
* | ||
* @param[pEventCtx] Pointer to the OTA event context. | ||
* | ||
* @param[pEventMsg] Event to be sent to the OTA handler. | ||
* | ||
* @param[timeout] The maximum amount of time (msec) the task should block. | ||
* | ||
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure. | ||
*/ | ||
OtaOsStatus_t OtaSendEvent_FreeRTOS( const void * pEventMsg ); | ||
|
||
/** | ||
* @brief Receive an OTA event. | ||
* | ||
* This function receives next event from the pending OTA events on FreeRTOS platforms. | ||
* | ||
* @param[pEventCtx] Pointer to the OTA event context. | ||
* | ||
* @param[pEventMsg] Pointer to store message. | ||
* | ||
* @param[timeout] The maximum amount of time the task should block. | ||
* | ||
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure. | ||
*/ | ||
OtaOsStatus_t OtaReceiveEvent_FreeRTOS( void * pEventMsg ); | ||
|
||
/** | ||
* @brief Deinitialize the OTA Events mechanism. | ||
* | ||
* This function deinitialize the OTA events mechanism and frees any resources | ||
* used on FreeRTOS platforms. | ||
* | ||
* @param[pEventCtx] Pointer to the OTA event context. | ||
* | ||
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure. | ||
*/ | ||
OtaOsStatus_t OtaDeinitEvent_FreeRTOS( ); | ||
|
||
|
||
#endif /* ifndef _OTA_OS_FREERTOS_H_ */ |
Oops, something went wrong.