SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
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
31
namespace
satnogs::comms
32
{
33
71
class
msg_arbiter
72
{
73
public
:
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
&
90
get_instance
()
91
{
92
static
msg_arbiter
instance;
93
return
instance;
94
}
95
103
enum class
subsys
: uint8_t
104
{
105
CAN1
= 0,
106
CAN2
= 1,
107
RADIO_UHF
= 2,
108
RADIO_SBAND
= 3,
109
SPI
= 4,
110
UART_PC104
= 5
111
};
112
117
class
msg
118
{
119
public
:
120
alignas
(16) uint8_t
data
[
mtu
];
121
subsys
iface
;
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
136
pull
(
msg_arbiter::msg
&m,
subsys
s,
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
148
backpressure
(
subsys
s);
149
150
void
151
start
();
152
153
private
:
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
satnogs::comms::msg_arbiter::msg
Definition
msg_arbiter.hpp:118
satnogs::comms::msg_arbiter::msg::data
uint8_t data[mtu]
Buffer to hold the data.
Definition
msg_arbiter.hpp:120
satnogs::comms::msg_arbiter::msg::len
size_t len
Data size in bytes.
Definition
msg_arbiter.hpp:122
satnogs::comms::msg_arbiter::msg::iface
subsys iface
The interface from which the msg was received.
Definition
msg_arbiter.hpp:121
satnogs::comms::msg_arbiter::rx_msgq_size
static constexpr size_t rx_msgq_size
Definition
msg_arbiter.hpp:75
satnogs::comms::msg_arbiter::operator=
void operator=(msg_arbiter const &)=delete
satnogs::comms::msg_arbiter::backpressure
uint32_t backpressure(subsys s)
Returns the number of messages that are waiting in the message queue of a specific subsystem.
Definition
msg_arbiter.cpp:200
satnogs::comms::msg_arbiter::pull
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.
Definition
msg_arbiter.cpp:115
satnogs::comms::msg_arbiter::mtu
static constexpr size_t mtu
Definition
msg_arbiter.hpp:74
satnogs::comms::msg_arbiter::uhf_tx_msgq_size
static constexpr size_t uhf_tx_msgq_size
Definition
msg_arbiter.hpp:78
satnogs::comms::msg_arbiter::fwd
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.
Definition
msg_arbiter.cpp:145
satnogs::comms::msg_arbiter::get_instance
static msg_arbiter & get_instance()
Singleton access to a unique and global msg_arbiter instance.
Definition
msg_arbiter.hpp:90
satnogs::comms::msg_arbiter::subsys
subsys
Peripheral identifier.
Definition
msg_arbiter.hpp:104
satnogs::comms::msg_arbiter::subsys::CAN2
@ CAN2
Definition
msg_arbiter.hpp:106
satnogs::comms::msg_arbiter::subsys::SPI
@ SPI
Definition
msg_arbiter.hpp:109
satnogs::comms::msg_arbiter::subsys::RADIO_UHF
@ RADIO_UHF
Definition
msg_arbiter.hpp:107
satnogs::comms::msg_arbiter::subsys::CAN1
@ CAN1
Definition
msg_arbiter.hpp:105
satnogs::comms::msg_arbiter::subsys::UART_PC104
@ UART_PC104
Definition
msg_arbiter.hpp:110
satnogs::comms::msg_arbiter::subsys::RADIO_SBAND
@ RADIO_SBAND
Definition
msg_arbiter.hpp:108
satnogs::comms::msg_arbiter::sband_tx_msgq_size
static constexpr size_t sband_tx_msgq_size
Definition
msg_arbiter.hpp:79
satnogs::comms::msg_arbiter::start
void start()
Starts the processing task for incoming messages handling.
Definition
msg_arbiter.cpp:222
satnogs::comms::msg_arbiter::msg_arbiter
msg_arbiter(msg_arbiter const &)=delete
satnogs::comms::msg_arbiter::can2_tx_msgq_size
static constexpr size_t can2_tx_msgq_size
Definition
msg_arbiter.hpp:77
satnogs::comms::msg_arbiter::push
int push(const msg_arbiter::msg &m, k_timeout_t wait=K_MSEC(CONFIG_MSG_ARBITER_TIMEOUT_MS))
Push a received message for processing.
Definition
msg_arbiter.cpp:98
satnogs::comms::msg_arbiter::can1_tx_msgq_size
static constexpr size_t can1_tx_msgq_size
Definition
msg_arbiter.hpp:76
satnogs::comms
Definition
bsp.cpp:28
scoped_lock.hpp
test.hpp
src
msg_arbiter.hpp
Generated by
1.17.0