REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
back_panel.cpp
Go to the documentation of this file.
1#include "back_panel.h"
2
4 4'000'000, LSBFIRST, SPI_MODE3 /* Chip expects MODE0, CLK is inverted on the way */};
5
6FLASHMEM
8 : f_meta(block_address),
9 f_temperature(bus::replace_function_idx(block_address, 1)),
10 f_id{bus::replace_function_idx(block_address, 2), F_ID_SPI_SETTINGS} {}
11
12FLASHMEM
13uint16_t platform::BackPanelHAL::read_backplane_and_slot_id() const { return f_id.transfer16(0); }
14
15FLASHMEM
17 bus::addr_t block_address) {
18 if (!classifier or classifier.class_enum != CLASS_)
19 return nullptr;
20
21 auto *new_block = new platform::REDACBackPanel(new platform::BackPanelHAL(block_address));
22 new_block->classifier = classifier;
23 return new_block;
24}
25
26FLASHMEM
28 return hardware ? hardware->get_entity_eui() : metadata::eui_t();
29}
30
31FLASHMEM
33 return hardware ? hardware->read_backplane_and_slot_id() : 0;
34}
35
36FLASHMEM
38 : Entity("BP"), hardware(hardware){
39 classifier.class_enum = CLASS_;
40}
41
42// Binary encoded decimal to native binary number
43FLASHMEM uint16_t bcd2decimal(uint16_t bcd) {
44 uint16_t decimal = 0;
45 uint16_t multiplier = 1;
46
47 while (bcd > 0) {
48 decimal += (bcd & 0xF) * multiplier;
49 bcd >>= 4;
50 multiplier *= 10;
51 }
52
53 return decimal;
54}
55
56// This algorithm was "read off" the ./test/hardware/components/test_backplane/test.cpp
57// No testing was done, it is probably wrong.
60
61 bool parity_bit = raw & (1<<3);
62 if(!parity_bit) {
63 id.is_valid = false;
64 return id;
65 }
66
67 id.backpanel_slot = 0b111 & raw;
68 uint16_t inverted_binary_encoded_decimal = raw >> 3;
69 id.backpanel_id = bcd2decimal(~inverted_binary_encoded_decimal);
70
71 return id;
72}
73
74FLASHMEM void platform::convertToJson(const BackPanelIdentifier &id, JsonObject dst) {
75 dst["backpanel_id"] = id.backpanel_id;
76 dst["backpanel_slot"] = id.backpanel_slot;
77 dst["is_valid"] = id.is_valid;
78}
FLASHMEM uint16_t bcd2decimal(uint16_t bcd)
EntityClassifier classifier
Definition base.h:217
Base HAL class Backplane.
Definition back_panel.h:34
static const SPISettings F_ID_SPI_SETTINGS
Definition back_panel.h:3
uint16_t read_backplane_and_slot_id() const
BackPanelHAL(bus::addr_t block_address)
Definition back_panel.cpp:7
uint16_t read_backplane_and_slot_id() const
metadata::eui_t get_entity_eui() const override
static REDACBackPanel * from_entity_classifier(entities::EntityClassifier classifier, __attribute__((__unused__)) bus::addr_t block_address)
static constexpr auto CLASS_
Definition back_panel.h:50
REDACBackPanel(BackPanelHAL *hardware)
Definition bus.h:22
uint16_t addr_t
Definition bus.h:27
std::array< uint8_t, 8 > eui_t
Definition base.h:20
void convertToJson(const BackPanelIdentifier &id, JsonObject dst)
static BackPanelIdentifier fromRaw(uint16_t raw)