SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
msg_arbiter.hpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS MCU software
3 *
4 * Copyright (C) 2023, Libre Space Foundation <http://libre.space>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GNU General Public License v3.0 or later
20 */
21
22#pragma once
23
24#include "scoped_lock.hpp"
25#include "tests/test.hpp"
26#include <cstddef>
27#include <cstdint>
28#include <cstring>
29#include <zephyr/kernel.h>
30
31namespace satnogs::comms
32{
33
72{
73public:
74 static constexpr size_t mtu = CONFIG_MAX_MTU;
75 static constexpr size_t rx_msgq_size = CONFIG_RX_MSGQ_SIZE;
76 static constexpr size_t can1_tx_msgq_size = CONFIG_CAN1_TX_MSGQ_SIZE;
77 static constexpr size_t can2_tx_msgq_size = CONFIG_CAN2_TX_MSGQ_SIZE;
78 static constexpr size_t uhf_tx_msgq_size = CONFIG_UHF_TX_MSGQ_SIZE;
79 static constexpr size_t sband_tx_msgq_size = CONFIG_SBAND_TX_MSGQ_SIZE;
80
89 static msg_arbiter &
91 {
92 static msg_arbiter instance;
93 return instance;
94 }
95
103 enum class subsys : uint8_t
104 {
105 CAN1 = 0,
106 CAN2 = 1,
109 SPI = 4,
111 };
112
117 class msg
118 {
119 public:
120 alignas(16) uint8_t data[mtu];
122 size_t len;
123 };
124
125 /* Singleton */
126 msg_arbiter(msg_arbiter const &) = delete;
127
128 void
129 operator=(msg_arbiter const &) = delete;
130
131 int
132 push(const msg_arbiter::msg &m,
133 k_timeout_t wait = K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS));
134
135 int
137 k_timeout_t wait = K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS));
138
139 int
140 fwd(const msg_arbiter::msg &m, subsys s,
141 k_timeout_t wait = K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS));
142
143 int
144 fwd(uint8_t mapid, uint8_t vcid, const msg_arbiter::msg &m, subsys s,
145 k_timeout_t wait = K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS));
146
147 uint32_t
149
150 void
151 start();
152
153private:
154 static void
155 parse_thread(void *arg1, void *arg2, void *arg3);
156
157 msg_arbiter();
158
159 msg_arbiter::msg m_msg;
160 k_tid_t m_tid;
161 struct k_mutex m_mtx;
162};
163
164} // namespace satnogs::comms
uint8_t data[mtu]
Buffer to hold the data.
size_t len
Data size in bytes.
subsys iface
The interface from which the msg was received.
static constexpr size_t rx_msgq_size
void operator=(msg_arbiter const &)=delete
uint32_t backpressure(subsys s)
Returns the number of messages that are waiting in the message queue of a specific subsystem.
int pull(msg_arbiter::msg &m, subsys s, k_timeout_t wait=K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS))
Pulls a message for a specific IO interface.
static constexpr size_t mtu
static constexpr size_t uhf_tx_msgq_size
int fwd(const msg_arbiter::msg &m, subsys s, k_timeout_t wait=K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS))
Forward a received message for processing.
static msg_arbiter & get_instance()
Singleton access to a unique and global msg_arbiter instance.
subsys
Peripheral identifier.
static constexpr size_t sband_tx_msgq_size
void start()
Starts the processing task for incoming messages handling.
msg_arbiter(msg_arbiter const &)=delete
static constexpr size_t can2_tx_msgq_size
int push(const msg_arbiter::msg &m, k_timeout_t wait=K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS))
Push a received message for processing.
static constexpr size_t can1_tx_msgq_size