Verified Commit 73d53d94 authored by Vincent Coubard's avatar Vincent Coubard
Browse files

Convert mqtt agent to CMSIS RTOS


Signed-off-by: Vincent Coubard's avatarVincent Coubard <vincent.coubard@arm.com>
parent 39c5e25c
/*
* Amazon FreeRTOS V1.4.8
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. 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
......@@ -31,7 +32,7 @@
#ifndef _AWS_MQTT_AGENT_CONFIG_H_
#define _AWS_MQTT_AGENT_CONFIG_H_
#include "FreeRTOS.h"
#include "cmsis_os2.h"
/**
* @brief Controls whether or not to report usage metrics to the
......
/*
* FreeRTOS V202104.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. 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
......@@ -33,10 +34,6 @@
#include <string.h>
#include <stdio.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "semphr.h"
/* Header include. */
#include "freertos_agent_message.h"
#include "core_mqtt_agent_message_interface.h"
......@@ -47,14 +44,14 @@ bool Agent_MessageSend( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t * const * pCommandToSend,
uint32_t blockTimeMs )
{
BaseType_t queueStatus = pdFAIL;
osStatus_t queueStatus = osError;
if( ( pMsgCtx != NULL ) && ( pCommandToSend != NULL ) )
{
queueStatus = xQueueSendToBack( pMsgCtx->queue, pCommandToSend, pdMS_TO_TICKS( blockTimeMs ) );
queueStatus = osMessageQueuePut( pMsgCtx->queue, pCommandToSend, 0U, pdMS_TO_TICKS( blockTimeMs ) );
}
return ( queueStatus == pdPASS ) ? true : false;
return ( queueStatus == osOK ) ? true : false;
}
/*-----------------------------------------------------------*/
......@@ -63,12 +60,12 @@ bool Agent_MessageReceive( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t ** pReceivedCommand,
uint32_t blockTimeMs )
{
BaseType_t queueStatus = pdFAIL;
osStatus_t queueStatus = osError;
if( ( pMsgCtx != NULL ) && ( pReceivedCommand != NULL ) )
{
queueStatus = xQueueReceive( pMsgCtx->queue, pReceivedCommand, pdMS_TO_TICKS( blockTimeMs ) );
queueStatus = osMessageQueueGet( pMsgCtx->queue, pReceivedCommand, NULL, pdMS_TO_TICKS( blockTimeMs ) );
}
return ( queueStatus == pdPASS ) ? true : false;
return ( queueStatus == osOK ) ? true : false;
}
/*
* FreeRTOS V202104.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. 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
......@@ -33,9 +34,8 @@
#include <string.h>
#include <stdio.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "semphr.h"
/* CMSIS includes. */
#include "cmsis_os2.h"
/* Header include. */
#include "freertos_command_pool.h"
......@@ -55,9 +55,8 @@ static MQTTAgentCommand_t commandStructurePool[ MQTT_COMMAND_CONTEXTS_POOL_SIZE
/**
* @brief The message context used to guard the pool of MQTTAgentCommand_t structures.
* For FreeRTOS, this is implemented with a queue. Structures may be
* obtained by receiving a pointer from the queue, and returned by
* sending the pointer back into it.
* This is implemented with a queue. Structures may be obtained by receiving a
* pointer from the queue, and returned by sending the pointer back into it.
*/
static MQTTAgentMessageContext_t commandStructMessageCtx;
......@@ -72,17 +71,14 @@ void Agent_InitializePool( void )
{
size_t i;
MQTTAgentCommand_t * pCommand;
static uint8_t staticQueueStorageArea[ MQTT_COMMAND_CONTEXTS_POOL_SIZE * sizeof( MQTTAgentCommand_t * ) ];
static StaticQueue_t staticQueueStructure;
bool commandAdded = false;
if( initStatus == QUEUE_NOT_INITIALIZED )
{
memset( ( void * ) commandStructurePool, 0x00, sizeof( commandStructurePool ) );
commandStructMessageCtx.queue = xQueueCreateStatic( MQTT_COMMAND_CONTEXTS_POOL_SIZE,
commandStructMessageCtx.queue = osMessageQueueNew( MQTT_COMMAND_CONTEXTS_POOL_SIZE,
sizeof( MQTTAgentCommand_t * ),
staticQueueStorageArea,
&staticQueueStructure );
NULL);
configASSERT( commandStructMessageCtx.queue );
/* Populate the queue. */
......
/*
* FreeRTOS V202104.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. 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
......@@ -35,9 +36,9 @@
#include <stdint.h>
#include <stdbool.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* CMSIS includes. */
#include "cmsis_os2.h"
#include "RTOS_config.h"
/* Include MQTT agent messaging interface. */
#include "core_mqtt_agent_message_interface.h"
......@@ -48,7 +49,7 @@
*/
struct MQTTAgentMessageContext
{
QueueHandle_t queue;
osMessageQueueId_t queue;
};
/*-----------------------------------------------------------*/
......
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