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

57 lines
2 KiB
C
Raw Normal View History

2024-10-21 10:26:41 +02:00
#ifndef SAMPLERING_H
#define SAMPLERING_H
#include <stdint.h>
#include "structures.h"
#include "baselayer.h"
2024-11-26 17:37:48 +01:00
#include "spisim.h"
2024-10-21 10:26:41 +02:00
static constexpr unsigned RING_BIT = 10;
static constexpr unsigned RING_LEN = 1u << RING_BIT;
static constexpr unsigned RING_MSK = RING_LEN - 1u;
static constexpr unsigned DATA_HALF_LEN = 1024u;
static constexpr unsigned DATA_FULL_LEN = DATA_HALF_LEN * 2u;
static constexpr unsigned RCVD_BUFLEN = 16;
enum RCVD_STATUS {
RCVD_IDLE = 0,
RCVD_DATA,
};
class SampleRing : public BaseLayer {
2024-11-26 17:37:48 +01:00
SpiSim spi;
2024-11-08 20:56:19 +01:00
ChannelVoltage voltage;
2024-10-21 10:26:41 +02:00
[[gnu::aligned(4)]]DATA_BLOCK ring_buffer [RING_LEN];
TrigerSettings m_settings;
volatile unsigned m_head, m_tail;
volatile unsigned m_lenght;
bool m_old_triger;
bool m_trigered;
volatile bool m_finished;
2024-10-22 20:05:15 +02:00
TIME_BASE_MODE m_mode, o_mode;
2024-10-26 12:22:17 +02:00
unsigned m_time_base_order;
2024-10-21 10:26:41 +02:00
[[gnu::aligned(4)]]char rcvd_buffer [RCVD_BUFLEN];
unsigned rcvd_counter;
RCVD_STATUS rcvd_status;
public:
2024-11-08 20:56:19 +01:00
explicit SampleRing () noexcept : BaseLayer(), spi(), voltage(), m_settings(), m_head(0), m_tail(0), m_lenght(0),
2024-10-22 17:07:37 +02:00
m_old_triger(false), m_trigered(false), m_finished(false),
2024-10-26 12:22:17 +02:00
m_mode (TIME_BASE_TRIGERED), o_mode (TIME_BASE_TRIGERED), m_time_base_order(6u),
2024-11-26 17:37:48 +01:00
rcvd_counter(0u), rcvd_status (RCVD_IDLE) { };
2024-10-22 17:07:37 +02:00
uint32_t Up (const char * data, const uint32_t len) override;
2024-10-21 10:26:41 +02:00
void write (DATA_BLOCK const * data);
void pass ();
protected:
uint32_t BlockSend (const char * buf, const uint32_t len);
uint32_t SendPrefix ();
uint32_t SendData (const DATA_BLOCK & data);
bool read (DATA_BLOCK & sample);
void CmdReceived ();
void CommandPass (const unsigned cmd);
void ReloadTimer (const unsigned n);
2024-10-26 12:22:17 +02:00
void SendSettings();
2024-10-21 10:26:41 +02:00
};
#endif // SAMPLERING_H