SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
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>
27
28namespace satnogs::comms::lib
29{
30
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;
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
82void
84{
85 m_pwr.enable(power::subsys::FPGA_5V, en);
86}
87
94bool
96{
97 return m_pwr.enabled(power::subsys::FPGA_5V);
98}
99
100void
101fpga::write_reg(uint32_t reg, uint32_t val)
102{
103 // TODO
104}
105
106uint32_t
108{
109 // TODO
110 return 0;
111}
112
113void
114fpga::write_reg(reg r, uint32_t val)
115{
116 // TODO
117}
118
119uint32_t
121{
122 // TODO
123 return 0;
124}
125
126bool
128{
129 return m_fpga_done.get();
130}
131
132void
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
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
GPIO device abstraction.
Definition gpio.hpp:38
SPI device abstraction.
Definition spi.hpp:41
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
boot_mode get_boot_mode() const
Definition fpga.cpp:164
void set_boot_mode(boot_mode mode)
Definition fpga.cpp:133
uint32_t read_reg(uint32_t reg)
Definition fpga.cpp:107
void write_reg(uint32_t reg, uint32_t val)
Definition fpga.cpp:101
void enable(bool en=true)
Enable/disable the FPGA subsystem.
Definition fpga.cpp:83
bool get_fpga_done() const
Definition fpga.cpp:127
bool enabled() const
Returns the state of the FPGA.
Definition fpga.cpp:95
Generic exception indicating an invalid argument.
Manages power supplies and monitors subsystem status.
Definition power.hpp:43
const struct gpio_dt_spec fpga_done
Definition startup.cpp:46