SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
Loading...
Searching...
No Matches
fpga.cpp
Go to the documentation of this file.
1
/*
2
* SatNOGS-COMMS control library
3
*
4
* Copyright (C) 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
#include <etl/array.h>
23
#include <
satnogs-comms-lib/board.hpp
>
24
#include <
satnogs-comms-lib/exception.hpp
>
25
#include <
satnogs-comms-lib/fpga.hpp
>
26
#include <
satnogs-comms-lib/power.hpp
>
27
28
namespace
satnogs::comms::lib
29
{
30
49
fpga::fpga
(
hw
h,
bsp::spi
&spi,
power
&pwr,
bsp::gpio
&
fpga_done
,
50
bsp::gpio
&boot_sel_1,
bsp::gpio
&boot_sel_0)
51
: m_hw(h),
52
m_spi(spi),
53
m_pwr(pwr),
54
m_fpga_done(
fpga_done
),
55
m_boot_sel_1(boot_sel_1),
56
m_boot_sel_0(boot_sel_0)
57
{
58
switch
(m_hw) {
59
case
hw::NONE
:
60
m_name =
"N/A"
;
61
break
;
62
case
hw::ALINX_AC7Z020
:
63
m_name =
"ALINX-AC7Z020"
;
64
break
;
65
case
hw::LIBREWAVE
:
66
m_name =
"LIBREWAVE"
;
67
break
;
68
default
:
69
throw
inval_arg_exception
(__FILE__, __LINE__);
70
}
71
enable
(
false
);
72
/* For now the default boot mode should be QSPI */
73
m_boot_sel_1.set(
true
);
74
m_boot_sel_0.set(
false
);
75
}
76
82
void
83
fpga::enable
(
bool
en)
84
{
85
m_pwr.enable(
power::subsys::FPGA_5V
, en);
86
}
87
94
bool
95
fpga::enabled
()
const
96
{
97
return
m_pwr.enabled(
power::subsys::FPGA_5V
);
98
}
99
100
void
101
fpga::write_reg
(uint32_t
reg
, uint32_t val)
102
{
103
// TODO
104
}
105
106
uint32_t
107
fpga::read_reg
(uint32_t
reg
)
108
{
109
// TODO
110
return
0;
111
}
112
113
void
114
fpga::write_reg
(
reg
r, uint32_t val)
115
{
116
// TODO
117
}
118
119
uint32_t
120
fpga::read_reg
(
reg
r)
121
{
122
// TODO
123
return
0;
124
}
125
126
bool
127
fpga::get_fpga_done
()
const
128
{
129
return
m_fpga_done.get();
130
}
131
132
void
133
fpga::set_boot_mode
(
boot_mode
mode)
134
{
135
switch
(mode) {
136
case
boot_mode::JTAG
:
137
// 0 0
138
m_boot_sel_1.set(
false
);
139
m_boot_sel_0.set(
false
);
140
break
;
141
142
case
boot_mode::NAND
:
143
// 0 1
144
m_boot_sel_1.set(
false
);
145
m_boot_sel_0.set(
true
);
146
break
;
147
148
case
boot_mode::EMMC
:
149
// 1 1
150
m_boot_sel_1.set(
true
);
151
m_boot_sel_0.set(
true
);
152
break
;
153
154
case
boot_mode::QSPI
:
155
default
:
156
// 1 0
157
m_boot_sel_1.set(
true
);
158
m_boot_sel_0.set(
false
);
159
break
;
160
};
161
}
162
163
fpga::boot_mode
164
fpga::get_boot_mode
()
const
165
{
166
bool
sel1 = m_boot_sel_1.get();
167
bool
sel0 = m_boot_sel_0.get();
168
169
if
(sel1 == 0) {
170
if
(sel0 == 0) {
171
// 0 0
172
return
boot_mode::JTAG
;
173
}
else
{
174
// 0 1
175
return
boot_mode::NAND
;
176
}
177
}
else
{
178
if
(sel0 == 0) {
179
// 1 0
180
return
boot_mode::QSPI
;
181
}
else
{
182
// 1 1
183
return
boot_mode::EMMC
;
184
}
185
}
186
}
187
188
}
// namespace satnogs::comms::lib
board.hpp
satnogs::comms::lib::bsp::gpio
GPIO device abstraction.
Definition
gpio.hpp:38
satnogs::comms::lib::bsp::spi
SPI device abstraction.
Definition
spi.hpp:41
satnogs::comms::lib::fpga::boot_mode
boot_mode
Definition
fpga.hpp:50
satnogs::comms::lib::fpga::boot_mode::NAND
@ NAND
Definition
fpga.hpp:52
satnogs::comms::lib::fpga::boot_mode::QSPI
@ QSPI
Definition
fpga.hpp:53
satnogs::comms::lib::fpga::boot_mode::EMMC
@ EMMC
Definition
fpga.hpp:54
satnogs::comms::lib::fpga::boot_mode::JTAG
@ JTAG
Definition
fpga.hpp:51
satnogs::comms::lib::fpga::fpga
fpga(hw h, bsp::spi &spi, power &pwr, bsp::gpio &fpga_done, bsp::gpio &boot_sel_1, bsp::gpio &boot_sel_0)
Construct a new fpga::fpga object and disables it to ensure now excess power is accidentally used dur...
Definition
fpga.cpp:49
satnogs::comms::lib::fpga::get_boot_mode
boot_mode get_boot_mode() const
Definition
fpga.cpp:164
satnogs::comms::lib::fpga::reg
reg
Definition
fpga.hpp:36
satnogs::comms::lib::fpga::set_boot_mode
void set_boot_mode(boot_mode mode)
Definition
fpga.cpp:133
satnogs::comms::lib::fpga::read_reg
uint32_t read_reg(uint32_t reg)
Definition
fpga.cpp:107
satnogs::comms::lib::fpga::hw
hw
Definition
fpga.hpp:43
satnogs::comms::lib::fpga::hw::ALINX_AC7Z020
@ ALINX_AC7Z020
Definition
fpga.hpp:45
satnogs::comms::lib::fpga::hw::LIBREWAVE
@ LIBREWAVE
Definition
fpga.hpp:46
satnogs::comms::lib::fpga::hw::NONE
@ NONE
Definition
fpga.hpp:44
satnogs::comms::lib::fpga::write_reg
void write_reg(uint32_t reg, uint32_t val)
Definition
fpga.cpp:101
satnogs::comms::lib::fpga::enable
void enable(bool en=true)
Enable/disable the FPGA subsystem.
Definition
fpga.cpp:83
satnogs::comms::lib::fpga::get_fpga_done
bool get_fpga_done() const
Definition
fpga.cpp:127
satnogs::comms::lib::fpga::enabled
bool enabled() const
Returns the state of the FPGA.
Definition
fpga.cpp:95
satnogs::comms::lib::inval_arg_exception
Generic exception indicating an invalid argument.
Definition
exception.hpp:180
satnogs::comms::lib::power
Manages power supplies and monitors subsystem status.
Definition
power.hpp:43
satnogs::comms::lib::power::subsys::FPGA_5V
@ FPGA_5V
FPGA 5V supply.
Definition
power.hpp:54
exception.hpp
fpga.hpp
satnogs::comms::lib
Definition
ad8318.hpp:30
satnogs::comms::fpga_done
const struct gpio_dt_spec fpga_done
Definition
startup.cpp:46
power.hpp
libsatnogs-comms
src
fpga.cpp
Generated by
1.17.0