Verified Commit a92c8dda authored by Vincent Coubard's avatar Vincent Coubard
Browse files

Update AWS to us CMSIS RTOS


Signed-off-by: Vincent Coubard's avatarVincent Coubard <vincent.coubard@arm.com>
parent 814a48c8
......@@ -8,7 +8,7 @@ add_library(ota_for_aws STATIC EXCLUDE_FROM_ALL
"${aws-iot-device-sdk_SOURCE_DIR}/libraries/aws/ota-for-aws-iot-embedded-sdk/source/ota_http.c"
"${aws-iot-device-sdk_SOURCE_DIR}/libraries/aws/ota-for-aws-iot-embedded-sdk/source/ota_interface.c"
"${aws-iot-device-sdk_SOURCE_DIR}/libraries/aws/ota-for-aws-iot-embedded-sdk/source/ota_mqtt.c"
"${aws-iot-device-sdk_SOURCE_DIR}/libraries/aws/ota-for-aws-iot-embedded-sdk/source/portable/os/ota_os_freertos.c"
"ota_os_cmsisrtos.c"
)
target_include_directories(ota_for_aws
......@@ -29,7 +29,7 @@ target_include_directories(ota_for_aws
target_link_libraries(ota_for_aws
PUBLIC
freertos-kernel
cmsis-rtos-api
tinycbor
coreJSON
)
/*
* AWS IoT Over-the-air Update v3.1.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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_cmsisrtos.c
*/
/* OTA OS POSIX Interface Includes.*/
#include "ota_os_cmsisrtos.h"
/* OTA Library include. */
#include "ota.h"
#include "ota_private.h"
#include "cmsis_os2.h"
#include "RTE_Components.h"
#include <stdlib.h>
/* OTA Event queue attributes.*/
#define MAX_MESSAGES 20
#define MAX_MSG_SIZE sizeof(OtaEventMsg_t)
/* The queue control handle. .*/
static osMessageQueueId_t otaEventQueue;
/* OTA App Timer callback.*/
static OtaTimerCallback_t otaTimerCallback;
/* OTA Timer handles.*/
static osTimerId_t otaTimer[OtaNumOfTimers];
/* OTA Timer callbacks.*/
static void requestTimerCallback(osTimerId_t T);
static void selfTestTimerCallback(osTimerId_t T);
void (*timerCallback[OtaNumOfTimers])(osTimerId_t T) = {requestTimerCallback, selfTestTimerCallback};
OtaOsStatus_t OtaInitEvent_CMSISRTOS(OtaEventContext_t *pEventCtx)
{
(void)pEventCtx;
otaEventQueue = osMessageQueueNew(MAX_MESSAGES, MAX_MSG_SIZE, NULL);
if (otaEventQueue == NULL) {
LogError(("Failed to create OTA Event Queue: "
"xQueueCreateStatic returned error: "
"OtaOsStatus_t=%i ",
OtaOsEventQueueCreateFailed));
return OtaOsEventQueueCreateFailed;
} else {
LogDebug(("OTA Event Queue created."));
}
return OtaOsSuccess;
}
OtaOsStatus_t OtaSendEvent_CMSISRTOS(OtaEventContext_t *pEventCtx, const void *pEventMsg, unsigned int timeout)
{
(void)pEventCtx;
(void)timeout;
/* Send the event to OTA event queue.*/
osStatus_t retVal = osMessageQueuePut(otaEventQueue, pEventMsg, 0, 0);
if (retVal == osOK) {
LogDebug(("OTA Event Sent."));
} else {
LogError(("Failed to send event to OTA Event Queue: "
"osMessageQueuePut returned error: "
"OtaOsStatus_t=%i ",
OtaOsEventQueueSendFailed));
return OtaOsEventQueueSendFailed;
}
return OtaOsSuccess;
}
OtaOsStatus_t OtaReceiveEvent_CMSISRTOS(OtaEventContext_t *pEventCtx, void *pEventMsg, uint32_t timeout)
{
/* Temp buffer.*/
uint8_t buff[sizeof(OtaEventMsg_t)];
(void)pEventCtx;
(void)timeout;
osStatus_t retVal = osMessageQueueGet(otaEventQueue, &buff, 0, osWaitForever);
if (retVal == osOK) {
/* copy the data from local buffer.*/
memcpy(pEventMsg, buff, MAX_MSG_SIZE);
LogDebug(("OTA Event received"));
} else {
LogError(("Failed to receive event from OTA Event Queue: "
"xQueueReceive returned error: "
"OtaOsStatus_t=%i ",
OtaOsEventQueueReceiveFailed));
return OtaOsEventQueueSendFailed;
}
return OtaOsSuccess;
}
OtaOsStatus_t OtaDeinitEvent_CMSISRTOS(OtaEventContext_t *pEventCtx)
{
(void)pEventCtx;
/* Remove the event queue.*/
if (otaEventQueue != NULL) {
osMessageQueueDelete(otaEventQueue);
otaEventQueue = NULL;
LogDebug(("OTA Event Queue Deleted."));
}
return OtaOsSuccess;
}
static void selfTestTimerCallback(osTimerId_t T)
{
(void)T;
LogDebug(("Self-test expired within %ums\r\n", otaconfigSELF_TEST_RESPONSE_WAIT_MS));
if (otaTimerCallback != NULL) {
otaTimerCallback(OtaSelfTestTimer);
} else {
LogWarn(("Self-test timer event unhandled.\r\n"));
}
}
static void requestTimerCallback(osTimerId_t T)
{
(void)T;
LogDebug(("Request timer expired in %ums \r\n", otaconfigFILE_REQUEST_WAIT_MS));
if (otaTimerCallback != NULL) {
otaTimerCallback(OtaRequestTimer);
} else {
LogWarn(("Request timer event unhandled.\r\n"));
}
}
OtaOsStatus_t OtaStartTimer_CMSISRTOS(OtaTimerId_t otaTimerId,
const char *const pTimerName,
const uint32_t timeout,
OtaTimerCallback_t callback)
{
OtaOsStatus_t otaOsStatus = OtaOsSuccess;
configASSERT(callback != NULL);
configASSERT(pTimerName != NULL);
/* Set OTA lib callback. */
otaTimerCallback = callback;
/* If timer is not created.*/
if (otaTimer[otaTimerId] == NULL) {
/* Create the timer. */
osTimerAttr_t attr = {
.name = pTimerName,
};
otaTimer[otaTimerId] = osTimerNew(timerCallback[otaTimerId], osTimerOnce, NULL, &attr);
if (otaTimer[otaTimerId] == NULL) {
otaOsStatus = OtaOsTimerCreateFailed;
LogError(("Failed to create OTA timer: "
"timerCreate returned NULL "
"OtaOsStatus_t=%i ",
otaOsStatus));
} else {
LogDebug(("OTA Timer created."));
/* Start the timer. */
osStatus_t retVal = osTimerStart(otaTimer[otaTimerId], pdMS_TO_TICKS(timeout));
if (retVal == osOK) {
LogDebug(("OTA Timer started."));
} else {
otaOsStatus = OtaOsTimerStartFailed;
LogError(("Failed to start OTA timer: "
"timerStart returned error."));
}
}
} else {
/* Reset the timer. */
osStatus_t retVal = osTimerStart(otaTimer[otaTimerId], pdMS_TO_TICKS(timeout));
if (retVal == osOK) {
LogDebug(("OTA Timer restarted."));
} else {
otaOsStatus = OtaOsTimerRestartFailed;
LogError(("Failed to set OTA timer timeout: "
"timer_settime returned error: "
"OtaOsStatus_t=%i ",
otaOsStatus));
}
}
return otaOsStatus;
}
OtaOsStatus_t OtaStopTimer_CMSISRTOS(OtaTimerId_t otaTimerId)
{
if (otaTimer[otaTimerId] != NULL) {
/* Stop the timer. */
osStatus_t retVal = osTimerStop(otaTimer[otaTimerId]);
if (retVal == osOK) {
LogDebug(("OTA Timer Stopped for Timerid=%i.", otaTimerId));
} else {
LogError(("Failed to stop OTA timer: "
"timer_settime returned error: "
"OtaOsStatus_t=%i ",
OtaOsTimerStopFailed));
return OtaOsTimerStopFailed;
}
} else {
LogWarn(("OTA Timer handle NULL for Timerid=%i, can't stop.", otaTimerId));
}
return OtaOsSuccess;
}
OtaOsStatus_t OtaDeleteTimer_CMSISRTOS(OtaTimerId_t otaTimerId)
{
OtaOsStatus_t otaOsStatus = OtaOsSuccess;
if (otaTimer[otaTimerId] != NULL) {
/* Delete the timer. */
osStatus_t retVal = osTimerDelete(otaTimer[otaTimerId]);
if (retVal == osOK) {
otaTimer[otaTimerId] = NULL;
LogDebug(("OTA Timer deleted."));
} else {
otaOsStatus = OtaOsTimerDeleteFailed;
LogError(("Failed to delete OTA timer: "
"timer_delete returned error: "
"OtaOsStatus_t=%i ",
otaOsStatus));
}
} else {
otaOsStatus = OtaOsTimerDeleteFailed;
LogWarn(("OTA Timer handle NULL for Timerid=%i, can't delete.", otaTimerId));
}
return otaOsStatus;
}
void *Malloc_CMSISRTOS(size_t size)
{
return pvPortMalloc(size);
}
void Free_CMSISRTOS(void *ptr)
{
vPortFree(ptr);
}
/*
* AWS IoT Over-the-air Update v3.1.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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_cmsisrtos.h
* @brief Function declarations for the example OTA OS Functional interface
*/
#ifndef _OTA_OS_CMSISRTOS_H_
#define _OTA_OS_CMSISRTOS_H_
/* Standard library include. */
#include <stdint.h>
#include <string.h>
/* OTA library interface include. */
#include "ota_os_interface.h"
/**
* @brief Initialize the OTA events.
*
* This function initializes the OTA events mechanism for CMSIS RTOS platforms.
*
* @param[pEventCtx] Pointer to the OTA event context.
*
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure.
*/
OtaOsStatus_t OtaInitEvent_CMSISRTOS(OtaEventContext_t *pEventCtx);
/**
* @brief Sends an OTA event.
*
* This function sends an event to OTA library event handler on CMSIS RTOS 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_CMSISRTOS(OtaEventContext_t *pEventCtx, const void *pEventMsg, unsigned int timeout);
/**
* @brief Receive an OTA event.
*
* This function receives next event from the pending OTA events on CMSIS RTOS 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_CMSISRTOS(OtaEventContext_t *pEventCtx, void *pEventMsg, uint32_t timeout);
/**
* @brief Deinitialize the OTA Events mechanism.
*
* This function deinitialize the OTA events mechanism and frees any resources
* used on CMSIS RTOS platforms.
*
* @param[pEventCtx] Pointer to the OTA event context.
*
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure.
*/
OtaOsStatus_t OtaDeinitEvent_CMSISRTOS(OtaEventContext_t *pEventCtx);
/**
* @brief Start timer.
*
* This function starts the timer or resets it if it is already started on CMSIS RTOS platforms.
*
* @param[otaTimerId] Timer ID of type otaTimerId_t.
*
* @param[pTimerName] Timer name.
*
* @param[timeout] Timeout for the timer.
*
* @param[callback] Callback to be called when timer expires.
*
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure.
*/
OtaOsStatus_t OtaStartTimer_CMSISRTOS(OtaTimerId_t otaTimerId,
const char *const pTimerName,
const uint32_t timeout,
OtaTimerCallback_t callback);
/**
* @brief Stop timer.
*
* This function stops the timer on CMSIS RTOS platforms.
*
* @param[otaTimerId] Timer ID of type otaTimerId_t.
*
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure.
*/
OtaOsStatus_t OtaStopTimer_CMSISRTOS(OtaTimerId_t otaTimerId);
/**
* @brief Delete a timer.
*
* This function deletes a timer for POSIX platforms.
*
* @param[otaTimerId] Timer ID of type otaTimerId_t.
*
* @return OtaOsStatus_t, OtaOsSuccess if success , other error code on failure.
*/
OtaOsStatus_t OtaDeleteTimer_CMSISRTOS(OtaTimerId_t otaTimerId);
/**
* @brief Allocate memory.
*
* This function allocates the requested memory and returns a pointer to it on CMSIS RTOS platforms.
*
* @param[size] This is the size of the memory block, in bytes..
*
* @return This function returns a pointer to the allocated memory, or NULL if
* the request fails.
*/
void *Malloc_CMSISRTOS(size_t size);
/**
* @brief Free memory.
*
* This function deallocates the memory previously allocated by a call to allocation
* function of type OtaMalloc_t on CMSIS RTOS platforms.
*
* @param[size] This is the pointer to a memory block previously allocated with function
* of type OtaMalloc_t. If a null pointer is passed as an argument, no action occurs.
*
* @return None.
*/
void Free_CMSISRTOS(void *ptr);
#endif /* ifndef _OTA_OS_CMSISRTOS_H_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment