REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
cblock.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
4
5#include <block/cblock.h>
6#include <chips/AD5452.h>
7#include <utils/logging.h>
8
9#include "teensy/cblock.h"
10
11blocks::CBlock *blocks::CBlock::from_entity_classifier(entities::EntityClassifier classifier,
12 const bus::addr_t block_address) {
13 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != TYPE)
14 return nullptr;
15
16 if (classifier.version < entities::Version(1, 0))
17 return nullptr;
18 if (classifier.version < entities::Version(1, 1)) {
19 auto *new_block = new CBlock(new CBlockHAL_V_1_0_X(block_address));
20 new_block->classifier = classifier;
21 return new_block;
22 }
23 if (classifier.version < entities::Version(1, 2)) {
24 auto *new_block = new CBlock(new CBlockHAL_V_1_1_X(block_address));
25 new_block->classifier = classifier;
26 return new_block;
27 }
28 if (classifier.version < entities::Version(1, 3)) {
29 auto *new_block = new CBlock(new CBlockHAL_V_1_2_X(block_address));
30 new_block->classifier = classifier;
31 return new_block;
32 }
33
34 // Any unknown versuin results in a nullptr here.
35 return nullptr;
36}
37
38std::array<functions::AD5452, 32> blocks::CBlockHAL_Common::make_f_coeffs(
39 bus::addr_t block_address, std::array<const uint8_t, 32> f_coeffs_cs, uint8_t alt_function_idx) {
40 return {functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[0]), alt_function_idx),
41 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[1]), alt_function_idx),
42 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[2]), alt_function_idx),
43 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[3]), alt_function_idx),
44 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[4]), alt_function_idx),
45 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[5]), alt_function_idx),
46 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[6]), alt_function_idx),
47 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[7]), alt_function_idx),
48 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[8]), alt_function_idx),
49 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[9]), alt_function_idx),
50 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[10]), alt_function_idx),
51 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[11]), alt_function_idx),
52 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[12]), alt_function_idx),
53 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[13]), alt_function_idx),
54 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[14]), alt_function_idx),
55 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[15]), alt_function_idx),
56 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[16]), alt_function_idx),
57 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[17]), alt_function_idx),
58 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[18]), alt_function_idx),
59 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[19]), alt_function_idx),
60 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[20]), alt_function_idx),
61 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[21]), alt_function_idx),
62 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[22]), alt_function_idx),
63 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[23]), alt_function_idx),
64 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[24]), alt_function_idx),
65 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[25]), alt_function_idx),
66 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[26]), alt_function_idx),
67 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[27]), alt_function_idx),
68 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[28]), alt_function_idx),
69 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[29]), alt_function_idx),
70 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[30]), alt_function_idx),
71 functions::AD5452(bus::replace_function_idx(block_address, f_coeffs_cs[31]), alt_function_idx)};
72}
73
74
75blocks::CBlockHAL_Common::CBlockHAL_Common(bus::addr_t block_address, bus::addr_t temperature_sensor_address,
76 std::array<const uint8_t, 32> f_coeffs_cs, uint8_t alt_function_idx)
77 : blocks::CBlockHAL_Parent(/*f_meta*/ block_address,
78 /*temperature_sensor*/ temperature_sensor_address, alt_function_idx),
79 f_coeffs(make_f_coeffs(block_address, f_coeffs_cs, alt_function_idx)) {}
80
81bool blocks::CBlockHAL_Common::write_factor(uint8_t idx, float value) {
82 if (idx >= 32)
83 return false;
84 // NOTE: The current hardware does not allow any error detection here.
85 f_coeffs[idx].set_scale(value);
86 return true;
87}
88
90 /*
91 * Due to wrong order of connections on IC2, the addresses are mixed up
92 * - FADDR[0...15] = CS[0...15] = [EEPROM, Coeffs[0...14]]
93 * - FADDR[32+0...32+15] = CS[16...31] = Coeffs[15...30]
94 * - FADDR[16+0...16+3] = CS[32+0...32+3] = [Coeff31, TMP127, UNUSED, UNUSED]
95 * - but also FADDR[16+4+0...16+4+3] = FADDR[16+8+0...16+8+3] = FADDR[16+8+4+0...16+8+4+3],
96 * because 2nd & 3rd bit of FADDR is not decoded
97 * - FADDR >= 48 are decoded correctly but not used
98 */
99 : CBlockHAL_Common(block_address, bus::replace_function_idx(block_address, 17),
100 {1, 2, 3, 4, 5, 6, 7, 8,
101 9, 10, 11, 12, 13, 14, 15, 32 + 0,
102 32 + 1, 32 + 2, 32 + 3, 32 + 4, 32 + 5, 32 + 6, 32 + 7, 32 + 8,
103 32 + 9, 32 + 10, 32 + 11, 32 + 12, 32 + 13, 32 + 14, 32 + 15, 16},
104 48) {}
105
107 /*
108 * Wrong oder of connection on IC2 was fixed, the addresses are
109 * - FADDR[0...35] = CS[0...35]
110 * - but also FADDR[32+4+0...32+4+3] = FADDR[32+8+0...32+8+3] = FADDR[32+8+4+0...32+8+4+3] = CS[32..35],
111 * because 2nd & 3rd bit of FADDR is not decoded
112 * - FADDR >= 48 are decoded correctly but not used
113 */
114 : CBlockHAL_Common(block_address, bus::replace_function_idx(block_address, 33),
115 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
116 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32},
117 48) {}
118
120 : CBlockHAL_Common(block_address, bus::replace_function_idx(block_address, 33),
121 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
122 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32},
123 0xff) {}
static std::array< functions::AD5452, 32 > make_f_coeffs(bus::addr_t block_address, std::array< const uint8_t, 32 > f_coeffs_cs, uint8_t alt_function_idx)
Definition cblock.cpp:38
bool write_factor(uint8_t idx, float value) override
Definition cblock.cpp:81
std::array< functions::AD5452, 32 > f_coeffs
Definition cblock.h:18
CBlockHAL_Common(bus::addr_t block_address, bus::addr_t temperature_sensor_address, std::array< const uint8_t, 32 > f_coeffs_cs, uint8_t alt_function_idx)
Definition cblock.cpp:75
CBlockHAL_V_1_0_X(bus::addr_t block_address)
Definition cblock.cpp:89
CBlockHAL_V_1_1_X(bus::addr_t block_address)
Definition cblock.cpp:106
CBlockHAL_V_1_2_X(bus::addr_t block_address)
Definition cblock.cpp:119
The AD5452 is the 12-Bit Multiplying DAC, used in the C-Block (one AD5452 per lane).
Definition AD5452.h:16
entities::EntitySharedHardware< CBlockHAL > CBlockHAL_Parent
Definition cblock.h:13
Definition bus.h:21