REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
mblock.h
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#pragma once
6
7#include <bitset>
8#include <cstdint>
9
10#include "block/base.h"
11#include "chips/AD840X.h"
12#include "chips/DAC60508.h"
13#include "chips/SR74HC16X.h"
14#include "chips/SR74HCT595.h"
15#include "daq/base.h"
16
17namespace platform {
18class Cluster;
19}
20
21namespace carrier {
22class Carrier;
23}
24
25namespace blocks {
26
28public:
29 virtual std::bitset<8> read_overload_flags() = 0;
30 virtual void reset_overload_flags() = 0;
31
32 bool init() override;
33};
34
43class MBlock : public FunctionBlock {
44public:
45 // Entity hardware identifier information.
46 static constexpr auto CLASS_ = entities::EntityClass::M_BLOCK;
47
48 enum class TYPES : uint8_t { UNKNOWN = 0, M_INT8_BLOCK = 1, M_MUL4_BLOCK = 2 };
49
50 static MBlock *from_entity_classifier(entities::EntityClassifier classifier, bus::addr_t block_address);
51
52 bool is_entity_type(TYPES type_) { return entities::Entity::is_entity_type(static_cast<uint8_t>(type_)); }
53
54public:
55 static constexpr uint8_t M0_IDX = bus::M0_BLOCK_IDX;
56 static constexpr uint8_t M1_IDX = bus::M1_BLOCK_IDX;
57
58 enum class SLOT : uint8_t { M0 = 0, M1 = 1 };
59
60 static constexpr std::array<uint8_t, 8> SLOT_INPUT_IDX_RANGE() { return {0, 1, 2, 3, 4, 5, 6, 7}; };
61
62 static constexpr std::array<uint8_t, 8> SLOT_OUTPUT_IDX_RANGE() { return {0, 1, 2, 3, 4, 5, 6, 7}; };
63
65 template <int n> static constexpr uint8_t M0_INPUT() {
66 static_assert(n < 8, "MBlock input must be less than 8.");
67 return n + 8;
68 }
69
71 static constexpr uint8_t M0_INPUT(uint8_t idx) { return idx + 8; }
72
74 template <int n> static constexpr uint8_t M0_OUTPUT() {
75 static_assert(n < 8, "MBlock output must be less than 8.");
76 return n + 8;
77 }
78
80 static constexpr uint8_t M0_OUTPUT(uint8_t idx) { return idx + 8; }
81
83 template <int n> static constexpr uint8_t M1_INPUT() {
84 static_assert(n < 8, "MBlock input must be less than 8.");
85 return n;
86 }
87
89 static constexpr uint8_t M1_INPUT(uint8_t idx) { return idx; }
90
92 template <int n> static constexpr uint8_t M1_OUTPUT() {
93 static_assert(n < 8, "MBlock output must be less than 8.");
94 return n;
95 }
96
98 static constexpr uint8_t M1_OUTPUT(uint8_t idx) { return idx; }
99
100public:
101 const SLOT slot;
103
104public:
105 explicit MBlock(SLOT slot, MBlockHAL *hardware);
106
107 uint8_t slot_to_global_io_index(uint8_t local) const;
108
109 // M Blocks generaly can't calibrate themselfs on their own, so they need the cluster and carrier they are
110 // installed in.
111 virtual bool calibrate(platform::Cluster *cluster, carrier::Carrier *carrier) { return true; }
112
113 void overload_flags_to_json(JsonArray msg_out) const;
114};
115
116class EmptyMBlock : public MBlock {
117public:
119
120 using MBlock::MBlock;
121
122protected:
123 utils::status config_self_from_json(JsonObjectConst cfg) override;
124};
125
126} // namespace blocks
utils::status config_self_from_json(JsonObjectConst cfg) override
Deserialize a new configuration for this entity from a JsonObject.
Definition mblock.cpp:71
utils::status write_to_hardware() override
returns true in case of success
Definition mblock.cpp:69
A function block represents one module in a cluster, such as an M-Block, C-Block, I-Block or U-Block.
Definition base.h:29
bool init() override
Definition mblock.cpp:75
virtual void reset_overload_flags()=0
virtual std::bitset< 8 > read_overload_flags()=0
A REDAC Math block (M-Block) is represented by this class.
Definition mblock.h:43
static MBlock * from_entity_classifier(entities::EntityClassifier classifier, bus::addr_t block_address)
Definition mblock.cpp:49
static constexpr uint8_t M0_INPUT(uint8_t idx)
M0 input signal specifier for dynamic usage, like MBlock::M0_INPUT(variable).
Definition mblock.h:71
static constexpr uint8_t M1_INPUT(uint8_t idx)
M1 input signal specifier for dynamic usage, like MBlock::M1_INPUT(variable).
Definition mblock.h:89
static constexpr uint8_t M0_IDX
Definition mblock.h:55
bool is_entity_type(TYPES type_)
Definition mblock.h:52
void overload_flags_to_json(JsonArray msg_out) const
Definition mblock.cpp:82
MBlockHAL * hardware
Definition mblock.h:102
static constexpr auto CLASS_
Definition mblock.h:46
static constexpr std::array< uint8_t, 8 > SLOT_INPUT_IDX_RANGE()
Definition mblock.h:60
static constexpr std::array< uint8_t, 8 > SLOT_OUTPUT_IDX_RANGE()
Definition mblock.h:62
static constexpr uint8_t M1_INPUT()
M1 input signal specifier for hard-coded usage, like MBlock::M1_INPUT<3>().
Definition mblock.h:83
static constexpr uint8_t M1_OUTPUT(uint8_t idx)
M1 output signal specifier for dynamic usage, like MBlock::M1_OUTPUT(variable).
Definition mblock.h:98
uint8_t slot_to_global_io_index(uint8_t local) const
Definition mblock.cpp:37
static constexpr uint8_t M0_INPUT()
M0 input signal specifier for hard-coded usage, like MBlock::M0_INPUT<3>().
Definition mblock.h:65
static constexpr uint8_t M1_IDX
Definition mblock.h:56
const SLOT slot
Definition mblock.h:101
virtual bool calibrate(platform::Cluster *cluster, carrier::Carrier *carrier)
Definition mblock.h:111
static constexpr uint8_t M0_OUTPUT()
M0 output signal specifier for hard-coded usage, like MBlock::M0_OUTPUT<3>().
Definition mblock.h:74
static constexpr uint8_t M0_OUTPUT(uint8_t idx)
M0 output signal specifier for dynamic usage, like MBlock::M0_OUTPUT(variable).
Definition mblock.h:80
static constexpr uint8_t M1_OUTPUT()
M1 output signal specifier for hard-coded usage, like MBlock::M1_OUTPUT<3>().
Definition mblock.h:92
Top-level hierarchy controlled by a single microcontroller.
Definition carrier.h:38
EntityClassifier classifier
Definition base.h:217
bool is_entity_type(uint8_t type_) const
Definition base.h:137
The Lucidac class represents a single cluster.
Definition cluster.h:20
A recoverable error, inspired from https://abseil.io/docs/cpp/guides/status and https://github....
Definition error.h:35
Definition base.h:10
constexpr uint8_t M1_BLOCK_IDX
Definition bus.h:61
constexpr uint8_t M0_BLOCK_IDX
Definition bus.h:60
uint16_t addr_t
Definition bus.h:27
This concept of Backpanel / Backplane refers to the address decoder and periphery reachable by every ...
Definition cblock.h:15