14 #include "pulserdriverh8.h"
15 #include "charinterface.h"
17 REGISTER_TYPE(
XDriverList, H8Pulser,
"NMR pulser handmade-H8");
19 #define MAX_PATTERN_SIZE 2048u
21 #define TIMER_PERIOD (1.0/(25.0e3))
23 #define MIN_PULSE_WIDTH 0.001
29 return MIN_PULSE_WIDTH;
32 XH8Pulser::XH8Pulser(
const char *name,
bool runtime,
33 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
36 interface()->setEOS(
"\r\n");
37 interface()->setSerialBaudRate(115200);
38 interface()->setSerialStopBits(2);
41 PORTSEL_GATE, PORTSEL_PREGATE, PORTSEL_TRIG1, PORTSEL_TRIG2,
42 PORTSEL_QPSK_A, PORTSEL_QPSK_B, PORTSEL_ASW, PORTSEL_UNSEL,
43 PORTSEL_PULSE1, PORTSEL_PULSE2, PORTSEL_COMB, PORTSEL_UNSEL,
44 PORTSEL_QPSK_OLD_PSGATE, PORTSEL_QPSK_OLD_NONINV, PORTSEL_QPSK_OLD_INV, PORTSEL_COMB_FM
47 for(
unsigned int i = 0; i <
sizeof(ports)/
sizeof(
int); i++) {
48 tr[ *portSel(i)] = ports[i];
60 tr[ *
this].m_zippedPatterns.clear();
61 for(Payload::RelPatList::const_iterator it = shot[ *
this].relPatList().begin();
62 it != shot[ *
this].relPatList().end(); it++) {
63 pulseAdd(tr, it->toappear, (uint16_t)(it->pattern & PAT_DO_MASK));
68 static_assert(
sizeof(
long long) == 8,
"");
70 term = std::max(term, (uint64_t)lrint(MIN_PULSE_WIDTH / TIMER_PERIOD));
72 uint32_t ulen = (uint32_t)((term - 1) / 0x8000uLL);
73 uint32_t llen = (uint32_t)((term - 1) % 0x8000uLL);
80 tr[ *
this].m_zippedPatterns.push_back(x);
81 x.msb = pattern / 0x100;
82 x.lsb = pattern % 0x100;
83 tr[ *
this].m_zippedPatterns.push_back(x);
86 x.msb = (ulen % 0x8000u + 0x8000u) / 0x100;
87 x.lsb = (ulen % 0x8000u + 0x8000u) % 0x100;
88 tr[ *
this].m_zippedPatterns.push_back(x);
89 x.msb = (ulen / 0x8000u) / 0x100;
90 x.lsb = (ulen / 0x8000u) % 0x100;
91 tr[ *
this].m_zippedPatterns.push_back(x);
92 x.msb = (llen + 0x8000u) / 0x100;
93 x.lsb = (llen + 0x8000u) % 0x100;
94 tr[ *
this].m_zippedPatterns.push_back(x);
95 x.msb = pattern / 0x100;
96 x.lsb = pattern % 0x100;
97 tr[ *
this].m_zippedPatterns.push_back(x);
102 static uint16_t makesum(
unsigned char *start, uint32_t bytes) {
105 for(; bytes > 0; bytes--)
112 if( !interface()->isOpened())
116 if(shot[ *
this].m_zippedPatterns.empty() |
117 (shot[ *
this].m_zippedPatterns.size() >= MAX_PATTERN_SIZE ))
119 for(
unsigned int retry = 0; ; retry++) {
121 interface()->sendf(
"$poff %x", blankpattern);
122 interface()->send(
"$pclear");
123 unsigned int size = shot[ *
this].m_zippedPatterns.size();
124 unsigned int pincr = size;
125 interface()->sendf(
"$pload %x %x", size, pincr);
126 interface()->receive();
127 interface()->write(
">", 1);
129 for(
unsigned int j=0; j < size; j += pincr) {
131 (
char *) &shot[ *
this].m_zippedPatterns[j], pincr * 2);
133 makesum((
unsigned char *) &shot[ *
this].m_zippedPatterns[j], pincr * 2);
135 nsum.lsb = sum % 0x100; nsum.msb = sum / 0x100;
136 interface()->write((
char *)&nsum, 2);
138 interface()->write(
" \n", 5);
139 interface()->receive();
141 if(interface()->scanf(
"%x", &ret) != 1)
147 if(retry > 0)
throw e;
148 e.print(
getLabel() +
": " + i18n(
"try to continue") +
", ");
155 interface()->sendf(
"$poff %x", blankpattern);