LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
engine_cmd_msg.h File Reference
#include "juno/ds/array_api.h"
#include "juno/memory/pointer_api.h"
#include "juno/module.h"
#include "juno/sb/broker_api.h"
#include "juno/status.h"
Include dependency graph for engine_cmd_msg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ENGINE_CMD_MSG_TAG
 

Macros

#define ENGINE_CMD_MSG_MID   (0x1800)
 
#define EngineCmdMsg_PointerInit(addr)   JunoMemory_PointerInit(&gtEngineCmdMsgPointerApi, ENGINE_CMD_MSG_T, addr)
 
#define EngineCmdMsg_PointerVerify(tPointer)   JunoMemory_PointerVerifyType(tPointer, ENGINE_CMD_MSG_T, gtEngineCmdMsgPointerApi)
 

Typedefs

typedef struct ENGINE_CMD_MSG_TAG ENGINE_CMD_MSG_T
 

Functions

struct ENGINE_CMD_MSG_ARRAY_TAG JUNO_MODULE_DERIVE (JUNO_DS_ARRAY_ROOT_T, ENGINE_CMD_MSG_T *ptArrEngineCmdMsgBuffer;) ENGINE_CMD_MSG_ARRAY_T
 
JUNO_STATUS_T EngineCmdMsg_ArrayInit (ENGINE_CMD_MSG_ARRAY_T *ptEngineCmdMsgPipe, ENGINE_CMD_MSG_T *ptArrEngineCmdMsgBuffer, size_t iCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvUserData)
 

Variables

const JUNO_POINTER_API_T gtEngineCmdMsgPointerApi
 

Macro Definition Documentation

◆ ENGINE_CMD_MSG_MID

#define ENGINE_CMD_MSG_MID   (0x1800)

DOC This file is auto-generated from a LibJuno script (scripts/create_msg.py). Similarly the engine_tlm_msg.h and engine_tlm_msg.c files are also auto-generated. We will only go over the command file since it's identical to the telemetry file in terms of architecture.

Engine Application Commands

In LibJuno the software bus is operated on a single thread. A single broker is implemented for each thread of execution and the broker distributes messages to various queues that are subscribed on the software bus. These queues are called pipes. Pipes are derived LibJuno queues with a message ID subscription.

The message ID is a unique identifier for the type of message. Each message type will have its own message ID. In this example the engine command MID is 0x1800. This number can be arbitrary. The only requirement is the MIDs are unique for every message type.

◆ EngineCmdMsg_PointerInit

#define EngineCmdMsg_PointerInit (   addr)    JunoMemory_PointerInit(&gtEngineCmdMsgPointerApi, ENGINE_CMD_MSG_T, addr)

DOC We also define convenience macros for initializing and verifying this type of pointer. This makes working with LibJuno pointers easy.

◆ EngineCmdMsg_PointerVerify

#define EngineCmdMsg_PointerVerify (   tPointer)    JunoMemory_PointerVerifyType(tPointer, ENGINE_CMD_MSG_T, gtEngineCmdMsgPointerApi)

Typedef Documentation

◆ ENGINE_CMD_MSG_T

DOC The command message contains the RPM. Another application can send this command on the software bus and tell the engine what RPM it should be set to. The engine app will then control the engine so it's set to the new RPM.

Function Documentation

◆ EngineCmdMsg_ArrayInit()

JUNO_STATUS_T EngineCmdMsg_ArrayInit ( ENGINE_CMD_MSG_ARRAY_T *  ptEngineCmdMsgPipe,
ENGINE_CMD_MSG_T ptArrEngineCmdMsgBuffer,
size_t  iCapacity,
JUNO_FAILURE_HANDLER_T  pfcnFailureHdlr,
JUNO_USER_DATA_T pvUserData 
)

DOC Finally we define a Pipe Init function for this pipe type. This function will initialize the pipe with the message buffer and capacity.

DOC

Pipe Init

We also implement the pipe init function, which sets the API pointer as well as the message buffer and capacity.

◆ JUNO_MODULE_DERIVE()

struct ENGINE_CMD_MSG_ARRAY_TAG JUNO_MODULE_DERIVE ( JUNO_DS_ARRAY_ROOT_T  ,
ENGINE_CMD_MSG_T *ptArrEngineCmdMsgBuffer;   
)

DOC

Engine Command Pipe

Below is the definition for the engine command pipe. This is derived from the JUNO_SB_PIPE_T using the DERIVE_WITH_API macro. This macro enables users to specify which API they are using. The inheritance for a pipe is as follows:

struct JUNO_DS_ARRAY_ROOT_TAG JUNO_DS_ARRAY_ROOT_T
Opaque array root carrying capacity and API pointer.
Definition array_api.h:58
struct JUNO_SB_PIPE_TAG JUNO_SB_PIPE_T
Definition broker_api.h:67
struct JUNO_DS_QUEUE_ROOT_TAG JUNO_DS_QUEUE_ROOT_T
The queue root module.
Definition queue_api.h:65

Because this is a longer chain of inheritance, it's convenient to specify the API for ease-of-use. In this case we are specifying the QUEUE api.

The pipe holds a pointer to a command buffer, which is specific to the command message type defined earlier. This enables the derived pipe to have specific type information (vs using a void pointer in the pipe).

Variable Documentation

◆ gtEngineCmdMsgPointerApi

const JUNO_POINTER_API_T gtEngineCmdMsgPointerApi
extern

DOC The queue api relies on LibJuno pointers. This enables the modules to write generic code safely without specific type information. As a result, we need to specify a pointer API implementation for this command type.

DOC These function will provide an interface to our specific message type and enable users to write type-safe code within LibJuno.

We need to forward-declare these API functions so we can use the API pointer to verify the type of the queue and pointer.

Below we will instantiate the pointer and pipe API tables.