-
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. (#37)
Co-authored-by: Manvendra Sharma <manvensh@amazon.com>
- Loading branch information
1 parent
8b46603
commit c522009
Showing
5 changed files
with
963 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,122 @@ | ||
/* | ||
* 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.c | ||
* @brief Example implementation of the OTA OS Functional Interface for | ||
* FreeRTOS. | ||
*/ | ||
|
||
/* FreeRTOS includes. */ | ||
#include "FreeRTOS.h" | ||
#include "queue.h" | ||
#include "timers.h" | ||
|
||
/* OTA OS POSIX Interface Includes.*/ | ||
|
||
#include "ota_demo.h" | ||
#include "ota_os_freertos.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; | ||
|
||
retVal = xQueueReceive( otaEventQueue, (OtaEventMsg_t *) pEventMsg, pdMS_TO_TICKS( 1000U ) ); | ||
|
||
if( retVal == pdTRUE ) | ||
{ | ||
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; | ||
} | ||
|
||
void OtaDeinitEvent_FreeRTOS() | ||
{ | ||
|
||
vQueueDelete( otaEventQueue ); | ||
|
||
printf( "OTA Event Queue Deleted. \n" ); | ||
|
||
} |
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,102 @@ | ||
/* | ||
* 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 <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.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. | ||
*/ | ||
void OtaDeinitEvent_FreeRTOS(); | ||
|
||
#endif /* ifndef _OTA_OS_FREERTOS_H_ */ |
Oops, something went wrong.