REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
tblock.cpp
Go to the documentation of this file.
1#include "teensy/tblock.h"
2
3using namespace blocks;
4
6 4'000'000, MSBFIRST,
7 SPI_MODE2 /* Chip expects MODE0, CLK is inverted on the way, but MOSI is not, thus CLK must be shifted */};
8
9FLASHMEM TBlockHAL_V_1_0_X::TBlockHAL_V_1_0_X(bus::addr_t block_address)
10 : TBlockHAL_Parent(block_address), f_set_mux_disable{bus::replace_function_idx(block_address, 5)},
11 f_reset_mux_disable{bus::replace_function_idx(block_address, 6)},
12 f_reset_connections{bus::replace_function_idx(block_address, 4)},
13 f_connections{bus::replace_function_idx(block_address, 2), F_CONNECTION_SPI_SETTINGS},
14 f_connections_sync{bus::replace_function_idx(block_address, 3)} {}
15
17
19
20FLASHMEM bool TBlockHAL_V_1_0_X::write_muxes(std::array<uint8_t, 96> muxes) {
21 // Order of muxes in function argument is sources for output [bpl_ch0, cl0_ch0, cl1_ch0, cl2_ch0, bpl_ch1,
22 // ... cl2_ch23]
23 std::array<uint8_t, 24> data{};
24 for (auto idx = 0u; idx < data.size(); idx++) {
25 // Fill up MOSI buffer in reverse because MSBFirst flag doesnt mirror the byte order but only the bytes
26 // alone
27 data[data.size() - 1 - idx] =
28 (muxes[idx * 4 + 3] << 6) | (muxes[idx * 4 + 2] << 4) | (muxes[idx * 4 + 1] << 2) | muxes[idx * 4 + 0];
29 }
30
31 auto success = f_connections.transfer(data.data(), nullptr, data.size());
33 return success;
34}
35
38#ifdef ANABRID_PEDANTIC
39 std::array<uint8_t, 24> data{0};
40 f_connections.transfer(data.data(), data.data(), data.size());
41 return std::all_of(data.begin(), data.end(), [](auto value) { return value == 0; });
42#else
43 return true;
44#endif
45}
46
47FLASHMEM
48TBlock *TBlock::from_entity_classifier(entities::EntityClassifier classifier, bus::addr_t block_address) {
49 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != TYPE)
50 return nullptr;
51
52 if (classifier.version < entities::Version(1, 0, 2))
53 // Version 1.0.1 was manufactured without any muxers on them :)
54 return nullptr;
55 if (classifier.version < entities::Version(1, 1)) {
56 auto *new_tblock = new TBlock(new TBlockHAL_V_1_0_X(block_address));
57 new_tblock->classifier = classifier;
58 return new_tblock;
59 }
60 return nullptr;
61}
HAL class for TBlock version 1.0.1.
Definition tblock.h:19
const functions::TriggerFunction f_reset_mux_disable
Definition tblock.h:22
TBlockHAL_V_1_0_X(bus::addr_t block_address)
Definition tblock.cpp:9
static const SPISettings F_CONNECTION_SPI_SETTINGS
Definition tblock.h:27
bool write_muxes(std::array< uint8_t, 96 > muxes)
Definition tblock.cpp:20
bool reset_muxes() override
Definition tblock.cpp:36
void reset_mux_disable() override
Definition tblock.cpp:18
const functions::TriggerFunction f_set_mux_disable
Definition tblock.h:21
const functions::TriggerFunction f_connections_sync
Definition tblock.h:25
const functions::TriggerFunction f_reset_connections
Definition tblock.h:23
const functions::SR74HCT595 f_connections
Definition tblock.h:24
void set_mux_disable() override
Definition tblock.cpp:16
bool transfer(const void *mosi_buf, void *miso_buf, size_t count) const
static constexpr int success
Definition flasher.cpp:275
Definition bus.h:21