Skip to content

Commit 0185515

Browse files
Add more porting instructions to README (#57)
1 parent abffd5c commit 0185515

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ To provide values for these configuration values, they must be either:
3232
**OR**
3333
* Passed as compile time preprocessor macros
3434

35+
## Porting the coreMQTT Agent Library
36+
In order to use the MQTT Agent library on a platform, you need to supply thread safe functions for the agent's [messaging interface](source/include/core_mqtt_agent_message_interface.h).
37+
38+
### Messaging Interface
39+
Each of the following functions must be thread safe.
40+
41+
| Function Pointer | Description |
42+
| :-: | --- |
43+
| `MQTTAgentMessageSend_t` | A function that sends commands (as `MQTTAgentCommand_t *` pointers) to be received by `MQTTAgent_CommandLoop`. This can be implemented by pushing to a thread safe queue. |
44+
| `MQTTAgentMessageRecv_t` | A function used by `MQTTAgent_CommandLoop` to receive `MQTTAgentCommand_t *` pointers that were sent by API functions. This can be implemented by receiving from a thread safe queue. |
45+
| `MQTTAgentCommandGet_t` | A function that returns a pointer to an allocated `MQTTAgentCommand_t` structure, which is used to hold information and arguments for a command to be executed in `MQTTAgent_CommandLoop()`. If using dynamic memory, this can be implemented using `malloc()`. |
46+
| `MQTTAgentCommandRelease_t` | A function called to indicate that a command structure that had been allocated with the `MQTTAgentCommandGet_t` function pointer will no longer be used by the agent, so it may be freed or marked as not in use. If using dynamic memory, this can be implemented with `free()`. |
47+
48+
Reference implementations for the interface functions can be found in the [reference examples](#reference-examples) below.
49+
### Additional Considerations
50+
51+
#### Static Memory
52+
If only static allocation is used, then the `MQTTAgentCommandGet_t` and `MQTTAgentCommandRelease_t` could instead be implemented with a pool of `MQTTAgentCommand_t` structures, with a queue or semaphore used to control access and provide thread safety. The below [reference examples](#reference-examples) use static memory with a command pool.
53+
54+
#### Subscription Management
55+
The MQTT Agent does not track subscriptions for MQTT topics. The receipt of any incoming PUBLISH packet will result in the invocation of a single `MQTTAgentIncomingPublishCallback_t` callback, which is passed to `MQTTAgent_Init()` for initialization. If it is desired for different handlers to be invoked for different incoming topics, then the publish callback will have to manage subscriptions and fan out messages. A platform independent subscription manager example is implemented in the [reference examples](#reference-examples) below.
56+
3557
## Building the Library
3658

3759
You can build the MQTT Agent source files that are in the [source](source/) directory, and add [source/include](source/include) to your compiler's include path. Additionally, the MQTT Agent library requires the coreMQTT library, whose files follow the same `source/` and `source/include` pattern as the agent library; its build instructions can be found [here](https://github.com/FreeRTOS/coreMQTT#building-the-library).

0 commit comments

Comments
 (0)