Modbus Vault v1.0
Loading...
Searching...
No Matches
event_bus.h File Reference

Event bus component. More...

#include "esp_err.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for event_bus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  event_bus_t
 Event bus type structure. More...
 

Macros

#define EVENT_BUS_TASK_NAME   ("EVENT_BUS")
 
#define EVENT_BUS_TASK_STACK_DEPTH   (2024U)
 
#define EVENT_BUS_TASK_PRIORITY   (3U)
 
#define EVENT_BUS_TASK_CPU_AFFINITY   (0U)
 
#define EVENT_BUS_TASK_NOTIFY_STOP_BIT   (1U << 0U)
 
#define EVENT_BUS_TASK_NOTIFY_event_available_BIT   (1U << 1U)
 

Typedefs

typedef void(* event_bus_cb_t) (const event_bus_t *event, void *ctx)
 

Enumerations

enum  event_bus_event_t { EVENT_BUS_EVENT_ERROR }
 Event bus event type enum. More...
 

Functions

esp_err_t event_bus_init (size_t queue_size)
 Initialize event bus.
 
bool event_bus_publish (const event_bus_t *event_ptr)
 Publish an event.
 
int8_t event_bus_subscribe (event_bus_event_t type, event_bus_cb_t cb, void *ctx)
 Subscribe to event.
 
bool event_bus_unsubscribe (int8_t slot)
 Unsubscribe from event.
 
void event_bus_deinit (void)
 deinitialize event bus
 

Detailed Description

Event bus component.

Author
Abanoub Salah
  • Provides lightweight event bus to
    • Publish different system events
    • Decouple components
    • Provide subscribers access to event

Macro Definition Documentation

◆ EVENT_BUS_TASK_CPU_AFFINITY

#define EVENT_BUS_TASK_CPU_AFFINITY   (0U)

CPU affinity

◆ EVENT_BUS_TASK_NAME

#define EVENT_BUS_TASK_NAME   ("EVENT_BUS")

Task name

◆ EVENT_BUS_TASK_NOTIFY_event_available_BIT

#define EVENT_BUS_TASK_NOTIFY_event_available_BIT   (1U << 1U)

Task notify for event bit

◆ EVENT_BUS_TASK_NOTIFY_STOP_BIT

#define EVENT_BUS_TASK_NOTIFY_STOP_BIT   (1U << 0U)

Task stop bit

◆ EVENT_BUS_TASK_PRIORITY

#define EVENT_BUS_TASK_PRIORITY   (3U)

Priority

◆ EVENT_BUS_TASK_STACK_DEPTH

#define EVENT_BUS_TASK_STACK_DEPTH   (2024U)

Stack depth

Typedef Documentation

◆ event_bus_cb_t

typedef void(* event_bus_cb_t) (const event_bus_t *event, void *ctx)

Callback for when event trigger

Enumeration Type Documentation

◆ event_bus_event_t

Event bus event type enum.

Enumerator
EVENT_BUS_EVENT_ERROR 

Error event

Function Documentation

◆ event_bus_init()

esp_err_t event_bus_init ( size_t  queue_size)

Initialize event bus.

Parameters
queue_sizeSize of the event queue
Returns
esp_err_t Initialize result
Return values
ESP_OKInitialize success
BLACKBOX_FAILFailed to create event task
ESP_ERR_INVALID_ARGProvided invalid argument(s)
ESP_ERR_NO_MEMNo available memory for resource allocation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ event_bus_publish()

bool event_bus_publish ( const event_bus_t event_ptr)

Publish an event.

Publish an event by queue it to the event bus queue

Parameters
event_ptrPointer to an event
Returns
bool true on publish false otherwise
Here is the caller graph for this function:

◆ event_bus_subscribe()

int8_t event_bus_subscribe ( event_bus_event_t  type,
event_bus_cb_t  cb,
void *  ctx 
)

Subscribe to event.

Parameters
typeEvent type
cbCallback for when event happens
ctxContext for the callback
Returns
int8_t Subscription slot number and '-1' On fail

< Maximum possible subscribers

Here is the caller graph for this function:

◆ event_bus_unsubscribe()

bool event_bus_unsubscribe ( int8_t  slot)

Unsubscribe from event.

Parameters
slotSubscription slot number
Returns
true on unsubscription false otherwise

< Maximum possible subscribers