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 * Amazon FreeRTOS V1.4.8
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 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 * 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 * this software and associated documentation files (the "Software"), to deal in
...@@ -31,7 +32,7 @@ ...@@ -31,7 +32,7 @@
#ifndef _AWS_MQTT_AGENT_CONFIG_H_ #ifndef _AWS_MQTT_AGENT_CONFIG_H_
#define _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 * @brief Controls whether or not to report usage metrics to the
......
/* /*
* FreeRTOS V202104.00 * FreeRTOS V202104.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 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 * 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 * this software and associated documentation files (the "Software"), to deal in
...@@ -33,10 +34,6 @@ ...@@ -33,10 +34,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "semphr.h"
/* Header include. */ /* Header include. */
#include "freertos_agent_message.h" #include "freertos_agent_message.h"
#include "core_mqtt_agent_message_interface.h" #include "core_mqtt_agent_message_interface.h"
...@@ -47,14 +44,14 @@ bool Agent_MessageSend( MQTTAgentMessageContext_t * pMsgCtx, ...@@ -47,14 +44,14 @@ bool Agent_MessageSend( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t * const * pCommandToSend, MQTTAgentCommand_t * const * pCommandToSend,
uint32_t blockTimeMs ) uint32_t blockTimeMs )
{ {
BaseType_t queueStatus = pdFAIL; osStatus_t queueStatus = osError;
if( ( pMsgCtx != NULL ) && ( pCommandToSend != NULL ) ) 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, ...@@ -63,12 +60,12 @@ bool Agent_MessageReceive( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t ** pReceivedCommand, MQTTAgentCommand_t ** pReceivedCommand,
uint32_t blockTimeMs ) uint32_t blockTimeMs )
{ {
BaseType_t queueStatus = pdFAIL; osStatus_t queueStatus = osError;
if( ( pMsgCtx != NULL ) && ( pReceivedCommand != NULL ) ) 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 * FreeRTOS V202104.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 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 * 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 * this software and associated documentation files (the "Software"), to deal in
...@@ -33,9 +34,8 @@ ...@@ -33,9 +34,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
/* Kernel includes. */ /* CMSIS includes. */
#include "FreeRTOS.h" #include "cmsis_os2.h"
#include "semphr.h"
/* Header include. */ /* Header include. */
#include "freertos_command_pool.h" #include "freertos_command_pool.h"
...@@ -55,9 +55,8 @@ static MQTTAgentCommand_t commandStructurePool[ MQTT_COMMAND_CONTEXTS_POOL_SIZE ...@@ -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. * @brief The message context used to guard the pool of MQTTAgentCommand_t structures.
* For FreeRTOS, this is implemented with a queue. Structures may be * This is implemented with a queue. Structures may be obtained by receiving a
* obtained by receiving a pointer from the queue, and returned by * pointer from the queue, and returned by sending the pointer back into it.
* sending the pointer back into it.
*/ */
static MQTTAgentMessageContext_t commandStructMessageCtx; static MQTTAgentMessageContext_t commandStructMessageCtx;
...@@ -72,17 +71,14 @@ void Agent_InitializePool( void ) ...@@ -72,17 +71,14 @@ void Agent_InitializePool( void )
{ {
size_t i; size_t i;
MQTTAgentCommand_t * pCommand; MQTTAgentCommand_t * pCommand;
static uint8_t staticQueueStorageArea[ MQTT_COMMAND_CONTEXTS_POOL_SIZE * sizeof( MQTTAgentCommand_t * ) ];
static StaticQueue_t staticQueueStructure;
bool commandAdded = false; bool commandAdded = false;
if( initStatus == QUEUE_NOT_INITIALIZED ) if( initStatus == QUEUE_NOT_INITIALIZED )
{ {
memset( ( void * ) commandStructurePool, 0x00, sizeof( commandStructurePool ) ); 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 * ), sizeof( MQTTAgentCommand_t * ),
staticQueueStorageArea, NULL);
&staticQueueStructure );
configASSERT( commandStructMessageCtx.queue ); configASSERT( commandStructMessageCtx.queue );
/* Populate the queue. */ /* Populate the queue. */
......
/* /*
* FreeRTOS V202104.00 * FreeRTOS V202104.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 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 * 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 * this software and associated documentation files (the "Software"), to deal in
...@@ -35,9 +36,9 @@ ...@@ -35,9 +36,9 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
/* FreeRTOS includes. */ /* CMSIS includes. */
#include "FreeRTOS.h" #include "cmsis_os2.h"
#include "queue.h" #include "RTOS_config.h"
/* Include MQTT agent messaging interface. */ /* Include MQTT agent messaging interface. */
#include "core_mqtt_agent_message_interface.h" #include "core_mqtt_agent_message_interface.h"
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
*/ */
struct MQTTAgentMessageContext 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