SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
radio.hpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS control library
3 *
4 * Copyright (C) 2023-2024, 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 <at86rf215.h>
25#include <etl/delegate.h>
26#include <etl/vector.h>
34#include <satnogs-comms-lib/version.hpp>
35
36namespace satnogs::comms::lib
37{
38
49{
50public:
51 pll_ls_exception(string_type file_name, numeric_type line)
52 : exception(exception::severity::MINOR, file_name, line,
53 error_msg{"PLL clock status unlocked", "pllerr", EPLL})
54 {
55 }
56};
57
64{
65public:
66 radio_exception(string_type file_name, numeric_type line)
67 : exception(exception::severity::MAJOR, file_name, line,
68 error_msg{"Radio error", "radioerr", ERADIO})
69 {
70 }
71
72 radio_exception(string_type file_name, numeric_type line, int err)
73 : exception(exception::severity::MAJOR, file_name, line,
74 error_msg{"Radio error", "radioerr", err})
75 {
76 }
77};
78
85{
86public:
87 unsupported_freq_exception(string_type file_name, numeric_type line)
88 : exception(exception::severity::MAJOR, file_name, line,
89 error_msg{"Unsupported frequency error", "freqerr", EBADFREQ})
90 {
91 }
92};
93
94/*
95 * This is a weak function of the AT86RF215 driver allowing user defined
96 * processing of the IRQs. We need to forward declare it here in order
97 * to define it as friend of the radio class.
98 * With this trick, this callback can access the private fields of the radio
99 * class. This eliminate the need for the radio class to expose at the public
100 * API, dangerous/unnecessary methods
101 */
102extern "C" int
103at86rf215_irq_user_callback(struct at86rf215 *h, uint8_t rf09_irqs,
104 uint8_t rf24_irqs, uint8_t bbc0_irqs,
105 uint8_t bbc1_irqs);
106
126class radio
127{
128public:
133 static const uint16_t UHF_AGC_VOUT_DAC_CH = 2;
134
139 static const uint16_t SBAND_AGC_VOUT_DAC_CH = 1;
140
146 {
147 public:
148 std::pair<uint32_t, uint32_t> freq;
150 uint64_t
153 };
154
156 {
157 public:
158 uint32_t tx;
159 uint32_t rx;
160 };
161
166 enum class clk_src : bool
167 {
170 };
171
176 enum class interface : uint8_t
177 {
178 UHF = 0,
179 SBAND = 1
180 };
181
185 enum class op_mode : uint8_t
186 {
189 };
190
195 enum class modulation : uint8_t
196 {
200 };
201
223
253
259 {
260 public:
261 at86rf215_fsk_srate_t rate;
262 float mod_idx;
265 float excess_bw;
266 };
267
273 {
274 public:
275 float rssi;
277 float edv;
278 uint32_t len;
279 interface iface;
280 };
281
288 class rx_msg
289 {
290 public:
291 uint8_t pdu[AT86RF215_MAX_PDU];
293 };
294
308
310 {
311 public:
312 uint32_t freq;
313 uint8_t preamble_len;
314 uint32_t sync;
316 float gain;
317 };
318
319 radio(const params &p, const io_conf &cnf, power &pwr,
320 bsp::imsgq<rx_msg> &rx_msgq);
321
322 static int
324
325 void
326 enable(bool yes = true);
327
328 void
329 enable(interface iface, bool yes = true);
330
331 bool
332 enabled() const;
333
334 void
335 stop(interface iface, size_t timeout_ms = 1000);
336
337 bool
338 enabled(interface iface) const;
339
341 direction(interface iface) const;
342
343 void
344 set_frequency(interface iface, rf_frontend::dir d, uint32_t freq);
345
346 uint32_t
347 frequency(interface iface, rf_frontend::dir d) const;
348
349 void
350 set_tx_gain(interface iface, float gain);
351
352 void
353 set_tx_conf(interface iface, const tx_conf &conf);
354
355 void
356 tx(interface iface, const uint8_t *b);
357
358 void
359 rx_async(interface iface, const rx_conf &conf);
360
361 bool
362 mixer_lock();
363
364 clk_src
365 get_clk_src() const;
366
368 uhf();
369
371 sband();
372
373 int
374 recv_msg(rx_msg &msg, size_t timeout_ms);
375
376 uint32_t
377 tx_len(interface iface) const;
378
379 uint32_t
380 rx_len(interface iface) const;
381
382 void
383 set_clk_src(clk_src src);
384
385 bool
386 get_pll_ls(interface iface);
387
388 void
389 register_rx_drop_callback(etl::delegate<void(interface)> callback);
390
391private:
392 /* None! */
393 static constexpr uint8_t TX_RF_IRQM = 0x0;
394 /* TXFE */
395 static constexpr uint8_t TX_BB_IRQM = bit<uint8_t, 4>();
396
397 /* None */
398 static constexpr uint8_t RX_RF_IRQM = 0x0;
399
400 /* RXFE */
401 static constexpr uint8_t RX_BB_IRQM = bit<uint8_t, 1>();
402
403 /* Clock source RF switch delay */
404 static constexpr uint32_t clk_rfsw_delay_us = 50;
405
406 /* Maximum delay for the PLL to lock after a channel switch request */
407 static constexpr uint32_t pll_ch_sw_delay_us = 100;
408
409 const frame_len m_frame_len[2];
410 bsp::spi &m_spi;
411 bsp::gpio &m_nrst;
412 bsp::gpio &m_en_ext_clk;
413 std::array<mixer_param, 2> m_tx_mixer_params;
414 std::array<mixer_param, 2> m_rx_mixer_params;
415 mutable struct at86rf215 m_at86;
416 bool m_iface_enabled[2];
417 rf_frontend09 m_rffe09;
418 rf_frontend24 m_rffe24;
419 bsp::chrono &m_chrono;
420 power &m_pwr;
421 bsp::imsgq<rx_msg> &m_rxq;
422 clk_src m_req_clk_src; // Requested clock source
423 clk_src m_clk_src; // Actual clock source
424 etl::delegate<void(interface)> m_rx_drop;
425
426 void
427 bsp_setup();
428
429 void
430 at86rf215_enable(bool enable = true);
431
432 friend int
433 at86rf215_irq_user_callback(struct at86rf215 *h, uint8_t rf09_irqs,
434 uint8_t rf24_irqs, uint8_t bbc0_irqs,
435 uint8_t bbc1_irqs);
436
437 uint32_t
438 iface_idx(interface iface) const;
439
440 void
441 set_rx_gain(interface iface, const rf_frontend::rx_gain_params &gain);
442
443 uint64_t
444 lo_freq(uint32_t rf_freq, rf_frontend::dir d) const;
445
446 uint32_t
447 if_freq(uint32_t rf_freq, rf_frontend::dir d) const;
448
449 void
450 enable_uhf(bool yes = true);
451
452 void
453 enable_sband(bool yes = true);
454};
455
457
458} // namespace satnogs::comms::lib
Chrono device abstraction.
Definition chrono.hpp:41
GPIO device abstraction.
Definition gpio.hpp:38
Message queue device abstraction.
Definition msgq.hpp:42
SPI device abstraction.
Definition spi.hpp:41
A class representing error messages in the SatNOGS-COMMS system.
Definition exception.hpp:83
severity
Severity levels of exceptions.
Definition exception.hpp:71
@ MINOR
Failure having minimal impact.
Definition exception.hpp:75
@ MAJOR
Failure causing minor mission degradation.
Definition exception.hpp:74
exception(severity sev, const char *file, int lineno, const error_msg &err_msg)
Constructor for the exception class.
pll_ls_exception(string_type file_name, numeric_type line)
Definition radio.hpp:51
Manages power supplies and monitors subsystem status.
Definition power.hpp:43
FSK configuration parameters.
Definition radio.hpp:259
at86rf215_fsk_srate_t rate
FSK data rate.
Definition radio.hpp:261
float excess_bw
FSK 3-dB bandwidth of the shaping filter.
Definition radio.hpp:265
IO configuration that is necessary for the radio to operate.
Definition radio.hpp:207
rf_frontend24::io_conf & rffe24_io
Definition radio.hpp:220
rf_frontend09::io_conf & rffe09_io
Definition radio.hpp:217
bsp::gpio & nreset
nRST signal for the AT86RF215
Definition radio.hpp:210
bsp::spi & spi_ctrl
SPI device controlling the AT86RF215.
Definition radio.hpp:209
Configuration parameters for the RF mixer.
Definition radio.hpp:146
std::pair< uint32_t, uint32_t > freq
Definition radio.hpp:148
Initialization parameters of the radio class.
Definition radio.hpp:240
std::array< mixer_param, 2 > rx_mixer_params
RF mixer parameters for the RX path.
Definition radio.hpp:249
frame_len uhf_len
The frame length of the UHF radio.
Definition radio.hpp:244
frame_len sband_len
The frame length of the UHF radio.
Definition radio.hpp:245
rf_frontend::params rffe24_params
Parameters of the S-Band frontend.
Definition radio.hpp:243
std::array< mixer_param, 2 > tx_mixer_params
RF mixer parameters for the TX path.
Definition radio.hpp:247
rf_frontend::params rffe09_params
Parameters of the UHF frontend.
Definition radio.hpp:242
RX configuration parameters.
Definition radio.hpp:299
fsk_conf fsk
FSK parameters.
Definition radio.hpp:304
uint32_t sync
The synchronization word.
Definition radio.hpp:303
rf_frontend::filter filter
Hardware filter selection.
Definition radio.hpp:306
uint32_t freq
The desired RX frequency to set.
Definition radio.hpp:301
rf_frontend::rx_gain_params gain
Gain settings to set.
Definition radio.hpp:305
uint8_t preamble_len
The length of the preamble in bytes.
Definition radio.hpp:302
Metadata for a received frame.
Definition radio.hpp:273
float edv
Not currently in use.
Definition radio.hpp:277
uint32_t len
The frame length.
Definition radio.hpp:278
The RX message accompanied by its metadata.
Definition radio.hpp:289
uint8_t pdu[AT86RF215_MAX_PDU]
Buffer to hold the received frame.
Definition radio.hpp:291
uint32_t sync
The synchronization word.
Definition radio.hpp:314
fsk_conf fsk
FSK parameters.
Definition radio.hpp:315
uint32_t freq
The desired RX frequency to set.
Definition radio.hpp:312
uint8_t preamble_len
The length of the preamble in bytes.
Definition radio.hpp:313
radio_exception(string_type file_name, numeric_type line, int err)
Definition radio.hpp:72
radio_exception(string_type file_name, numeric_type line)
Definition radio.hpp:66
void rx_async(interface iface, const rx_conf &conf)
Sets the radio in reception mode asynchronously.
Definition radio.cpp:845
rf_frontend::dir direction(interface iface) const
Fetches the current direction (RX/TX) of the specific interface.
Definition radio.cpp:435
op_mode
Radio Operational mode.
Definition radio.hpp:186
@ BASEBAND
The baseband core is active.
Definition radio.hpp:187
@ IQ
The IQ functionality is active.
Definition radio.hpp:188
static const uint16_t UHF_AGC_VOUT_DAC_CH
Definition radio.hpp:133
static int trx_irq_handler()
The IRQ handler of the AT86RF215 IRQ.
Definition radio.cpp:228
modulation
Supported modulation schemes.
Definition radio.hpp:196
void tx(interface iface, const uint8_t *b)
Performs a TX in blocking mode.
Definition radio.cpp:817
friend int at86rf215_irq_user_callback(struct at86rf215 *h, uint8_t rf09_irqs, uint8_t rf24_irqs, uint8_t bbc0_irqs, uint8_t bbc1_irqs)
Definition radio.cpp:110
rf_frontend09 & uhf()
Definition radio.cpp:945
void register_rx_drop_callback(etl::delegate< void(interface)> callback)
Registers a callback for the RX drop message event.
Definition radio.cpp:1147
void set_frequency(interface iface, rf_frontend::dir d, uint32_t freq)
Sets the frequency and the direction.
Definition radio.cpp:457
interface
Radio interface identifier.
Definition radio.hpp:177
bool mixer_lock()
Gets the status of the RF mixer lock.
Definition radio.cpp:935
clk_src
PLL Reference Clock identifier.
Definition radio.hpp:167
@ INTERNAL
Internal Crystal Oscillator.
Definition radio.hpp:168
@ EXTERNAL
External Reference Clock (TCXO).
Definition radio.hpp:169
uint32_t frequency(interface iface, rf_frontend::dir d) const
Returns the actual frequency that the hardware reports.
Definition radio.cpp:516
uint32_t rx_len(interface iface) const
Retrieves the configured RX frame size for a specific interface.
Definition radio.cpp:992
radio(const params &p, const io_conf &cnf, power &pwr, bsp::imsgq< rx_msg > &rx_msgq)
Construct a new radio::radio object.
Definition radio.cpp:197
void set_tx_conf(interface iface, const tx_conf &conf)
Performs the configuration of a specific interface for TX.
Definition radio.cpp:731
void stop(interface iface, size_t timeout_ms=1000)
Sets the FSM of the AT86RF215 interface to TRXOFF.
Definition radio.cpp:393
rf_frontend24 & sband()
Definition radio.cpp:955
bool get_pll_ls(interface iface)
Checks the PLL lock status of the AT86RF215 transceiver for the specified radio interface.
Definition radio.cpp:1118
static const uint16_t SBAND_AGC_VOUT_DAC_CH
Definition radio.hpp:139
void enable(bool yes=true)
Enable/disable the radio chain.
Definition radio.cpp:247
clk_src get_clk_src() const
Retrieves the current clock source of the AT86RF215 PLL.
Definition radio.cpp:1104
void set_tx_gain(interface iface, float gain)
Sets the TX gain of the AT86RF215.
Definition radio.cpp:532
int recv_msg(rx_msg &msg, size_t timeout_ms)
Gets an available message from the receive message queue.
Definition radio.cpp:968
uint32_t tx_len(interface iface) const
Retrieves the configured TX frame size for a specific interface.
Definition radio.cpp:980
bool enabled() const
Checks if the radio transceiver is in an operational state. This means that their powesr sources are ...
Definition radio.cpp:372
void set_clk_src(clk_src src)
Sets the clock source for the AT86RF215 PLL.
Definition radio.cpp:1094
RF-frontend for the UHF interface.
IO configuration for controlling the various peripherals of the S-Band frontend.
RF-frontend for the S-Band interface.
RF frontend initialization settings.
RX gain settings for the two different gain stages. Gain0 stage corresponds to the first stage (close...
unsupported_freq_exception(string_type file_name, numeric_type line)
Definition radio.hpp:87
#define ERADIO
Error in radio.
#define EPLL
PLL unlocked.
#define EBADFREQ
Unsupported frequency.
int at86rf215_irq_user_callback(struct at86rf215 *h, uint8_t rf09_irqs, uint8_t rf24_irqs, uint8_t bbc0_irqs, uint8_t bbc1_irqs)
Definition radio.cpp:110
scl::radio radio
Definition settings.cpp:30