#ifndef ROUTE_MSG_H
#define ROUTE_MSG_H

#include <stdbool.h>
#include <stdint.h>

#include "FreeRTOS.h"
#include "queue.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef ROUTE_MSG_POOL_SIZE
#define ROUTE_MSG_POOL_SIZE   8u
#endif

#ifndef ROUTE_MSG_MAX_PAYLOAD
#define ROUTE_MSG_MAX_PAYLOAD 512u
#endif

typedef enum {
    ROUTE_CONN_UART1 = 0,
    ROUTE_CONN_UART2,
    ROUTE_CONN_UART3,
    ROUTE_CONN_S1,
    ROUTE_CONN_S2,
    ROUTE_CONN_C1,
    ROUTE_CONN_C2
} route_conn_type_t;

typedef struct {
    uint8_t src_id;
    uint8_t dst_mask;
    uint16_t len;
    uint8_t conn_type;
    uint8_t *data;
} route_msg_t;

void route_msg_init(void);
route_msg_t *route_msg_alloc(TickType_t wait_ticks);
route_msg_t *route_msg_alloc_from_isr(BaseType_t *xHigherPriorityTaskWoken);
void route_msg_free(route_msg_t *msg);
void route_msg_free_from_isr(route_msg_t *msg);
bool route_send(QueueHandle_t queue,
                uint8_t src_id,
                uint8_t dst_mask,
                uint8_t conn_type,
                const uint8_t *data,
                uint16_t len,
                TickType_t wait_ticks);
bool route_send_from_isr(QueueHandle_t queue,
                         uint8_t src_id,
                         uint8_t dst_mask,
                         uint8_t conn_type,
                         const uint8_t *data,
                         uint16_t len,
                         BaseType_t *xHigherPriorityTaskWoken);

#ifdef __cplusplus
}
#endif

#endif
