RISC-V/V203/usb/scope/firmware/structures.h

133 lines
3 KiB
C
Raw Normal View History

2024-10-21 10:26:41 +02:00
#ifndef STRUCTURES_DEFINE_H
#define STRUCTURES_DEFINE_H
#include <stdint.h>
enum ADC_CHANNELS : uint16_t {
V1_VSENSE = 0,
V2_VSENSE,
ADC_MAXCHANNELS, // interní konstanta - počet kanálů
};
typedef uint16_t SAMPLE;
union DATA_BLOCK {
SAMPLE channels [ADC_MAXCHANNELS];
uint32_t common_data;
};
enum TRIGER_MODE : uint16_t {
TRIGER_MODE_AUTO = 0,
TRIGER_MODE_NORMAL,
TRIGER_MODE_SINGLE
};
struct TrigerSettings {
uint16_t value;
uint16_t offset;
TRIGER_MODE mode;
ADC_CHANNELS channel;
bool rising;
explicit TrigerSettings () noexcept : value(0x80u), offset(100u), mode(TRIGER_MODE_AUTO), channel(V1_VSENSE), rising(false) {}
};
static_assert (sizeof(TrigerSettings) == 10, "TrigerSettings error");
2024-11-08 20:56:19 +01:00
enum VOLTAGE_SCALE {
2024-11-30 11:03:21 +01:00
S100mV = 0b1100, // 1:1 x10
S200mV = 0b1110, // 1:1 x5
S500mV = 0b1101, // 1:1 x2
2024-11-08 20:56:19 +01:00
S1V = 0b0000, // 1:10 x10
2024-11-30 11:03:21 +01:00
S2V = 0b0010, // 1:10 x5
S5V = 0b0001, // 1:10 x2
2024-11-08 20:56:19 +01:00
2024-11-30 11:03:21 +01:00
S10V = 0b1000, // 1:100x10
S20V = 0b1010, // 1:100x5
2024-11-08 20:56:19 +01:00
S50V = 0b1001, // 1:100x2
};
union ChannelVoltage {
struct {
uint8_t a : 4;
uint8_t b : 4;
};
uint8_t value;
char common [1];
explicit ChannelVoltage () noexcept : value (0u) {}
};
static_assert (sizeof(ChannelVoltage) == 1, "ChannelVoltage error");
2024-10-26 12:22:17 +02:00
union AllSettings {
struct _x {
TrigerSettings trg;
uint16_t tim;
2024-11-08 20:56:19 +01:00
uint8_t asc,bsc;
2024-10-26 12:22:17 +02:00
} part;
uint8_t common [sizeof (_x)];
2024-11-08 20:56:19 +01:00
explicit AllSettings (const TrigerSettings & ts, const unsigned n, const ChannelVoltage chv) noexcept {
2024-10-26 12:22:17 +02:00
part.trg.value = ts.value;
part.trg.offset = ts.offset;
part.trg.mode = ts.mode;
part.trg.channel = ts.channel;
part.trg.rising = ts.rising;
part.tim = n;
2024-11-08 20:56:19 +01:00
part.asc = chv.a;
part.bsc = chv.b;
2024-10-26 12:22:17 +02:00
}
};
2024-11-08 20:56:19 +01:00
static_assert (sizeof(AllSettings) == 14, "TrigerSettings error");
2024-10-21 10:26:41 +02:00
union SendHeader {
struct s_bits {
uint16_t pack_len : 15;
uint16_t trig_flg : 1;
} bits;
uint16_t common;
};
static_assert (sizeof(SendHeader) == 2, "SendHeader error");
enum DESTINATION {
DEST_CHA = 0,
DEST_CHB,
DEST_TRIG,
DEST_BASE,
};
enum TRIGGER_CMD {
TRIGGER_CMD_MODE = 0,
TRIGGER_CMD_VALUE,
TRIGGER_CMD_OFSET,
};
union TriggerModeUnion {
struct s_bits {
uint16_t mode : 2;
uint16_t channel : 1;
uint16_t rissing : 1;
uint16_t unused : 12;
} bits;
uint16_t common;
};
static_assert (sizeof(TriggerModeUnion) == 2, "TriggerModeUnion error");
union RcvdHeader {
struct s_bits {
uint16_t cmd_value : 12;
uint16_t cmd_type : 2;
uint16_t destinat : 2;
} bits;
uint16_t common;
};
static_assert (sizeof(RcvdHeader) == 2, "RcvdHeader error");
enum MOVE_ITEMS {
MOVE_VALUE = 0,
MOVE_OFSET,
MOVE_MARKERA,
MOVE_MARKERB,
TIME_ZOOM,
2024-11-10 15:39:03 +01:00
OFSET_A,
OFSET_B,
2024-10-21 10:26:41 +02:00
};
enum TIME_BASE_MODE {
TIME_BASE_TRIGERED = 0,
TIME_BASE_CONTINUOUS,
};
struct TimeBaseDescriptor {
uint16_t divider;
uint16_t presc;
TIME_BASE_MODE mode;
};
#endif // STRUCTURES_DEFINE_H