PPG Client/Frontend
Classes and programs to interact with PPG
Loading...
Searching...
No Matches
PpgInterface.hh
1#ifndef PPGINTERFACE_HH
2#define PPGINTERFACE_HH
3#include <stdio.h>
4#include <stdlib.h> // exit()
5#include <string.h> // memcpy()
6#include <fcntl.h> // open()
7#include <unistd.h> // close()
8#include <sys/mman.h> // mmap()
9#include <stdexcept> // exceptions
10#include <stdint.h> // fixed size types
11#include <string>
12#include <vector>
13#include <thread>
14#include <atomic>
15
16#define PPG_STACKDEPTH 4000
17#define PPG_MAXSEQ 100
18
19// Qsys register space is mapped into memory (above real memory)
20// Address set by kernel driver? (1G DDR3 uses 0x4000_0000 addresses)
21#define ALT_STM_OFST 0xfc000000 // altera/socal/hps.h
22#define ALT_LWFPGASLVS_OFST 0xff200000 // altera/socal/hps.h
23
24#define HWREG_BASE (ALT_STM_OFST)
25#define HWREG_SPAN (0x04000000)
26#define HWREG_MASK (HWREG_SPAN - 1)
27
28#define ADDR_ADJ(addr) ((long)((addr) + ALT_LWFPGASLVS_OFST) & (long)(HWREG_MASK))
29
30// following are from platform-designer memory map ...
31#define SYSID_QSYS_BASE 0x01000
32#define PPG_BASE 0x10000
33
34class MemMapException : public std::runtime_error
35{
36public:
37 MemMapException() : std::runtime_error("MemMapException") {}
38};
39
86{
87private:
88 char *mmap_base;
89
90 const int csr = 0x04 * 0;
91 const int test = 0x04 * 1;
92 const int addr = 0x04 * 2;
93 const int setp = 0x04 * 3;
94 const int clrp = 0x04 * 4;
95 const int dly = 0x04 * 5;
96
109 const int inst = 0x04 * 6;
110 // const int invm = 0.04 * 7;
111 const int tstamp = 0x04 * 8;
112 const int flash = 0x04 * 9;
113 // const int serial = 0x04 * 10;
114 // const int modId = 0x04 * 11;
115 // const int clkCtrl = 0x04 * 12
116 const int gates = 0x04 * 16;
117 const int vetos = 0x04 * 17;
118
119 const int fpga_read32(int addr);
120 void fpga_write32(int addr, int data);
121 std::vector<std::string> seqstring;
122 std::thread *watchthread = nullptr;
123 std::atomic<bool> abort = false;
124
125public:
126 PpgInterface();
127 ~PpgInterface();
128 const int ReadSysID();
129 const int ReadSysTimeStamp();
130 const int ReadCSR();
131 const int ReadTest();
132 const int ReadTimeStamp();
133 const int ReadGates();
134
135 // Those registers are temporary, so cannot be read back after writing
136
137 void WriteTest(int val);
138 void WriteCSR(int val);
139
149 void WriteStep(int index, int setpatt, int clrpatt, int delay, int instr);
150
157 void WriteGates(uint16_t gatemask, uint8_t mode = 2); // mode: 0 = ignore gates, 1 = grandOR, 2 = grandAND
158 void WriteVetos(int vetomask);
159
167 int LoadSeqFromFile(std::string filename, unsigned int bufindex, uint64_t &duration);
168
169 const std::string GetSeqString(unsigned int i)
170 {
171 if (i < seqstring.size())
172 return seqstring[i];
173 else
174 return std::string();
175 }
176
182 void StartSeq(bool external = false);
183 void Abort();
184
185 enum state
186 {
187 idle,
188 waiting,
189 running
190 };
191
192 const state GetState();
193
202 void TurnOffExt();
203 void SetAddr(int index);
204};
205
206#endif
void StartSeq(bool external=false)
Start selected sequence.
Definition PpgInterface.cc:42
const std::string GetSeqString(unsigned int i)
Definition PpgInterface.hh:169
~PpgInterface()
Destructor.
Definition PpgInterface.cc:26
const int ReadTest()
Read Test register.
Definition PpgInterface.cc:151
void TurnOffExt()
Turn off external trigger once running.
Definition PpgInterface.cc:77
const state GetState()
Report if PPG is idle, waiting for trigger, or currently running.
Definition PpgInterface.cc:66
PpgInterface()
Constructor.
Definition PpgInterface.cc:9
void SetAddr(int index)
Select sequence to write/execute.
Definition PpgInterface.cc:176
void WriteTest(int val)
Write Test register, usually followed by ReadTest()
Definition PpgInterface.cc:166
const int ReadCSR()
Read Control and Status Register.
Definition PpgInterface.cc:146
void WriteGates(uint16_t gatemask, uint8_t mode=2)
Set bit patterns for enable gates.
Definition PpgInterface.cc:181
void WriteStep(int index, int setpatt, int clrpatt, int delay, int instr)
Write step insequence.
Definition PpgInterface.cc:127
const int ReadGates()
Read Gate enable bitmask.
Definition PpgInterface.cc:161
int LoadSeqFromFile(std::string filename, unsigned int bufindex, uint64_t &duration)
Load PPG sequence file, as generated by PPGCompiler.
Definition PpgInterface.cc:196
void WriteVetos(int vetomask)
Enable veto pins.
Definition PpgInterface.cc:191
void Abort()
Abort running sequence.
Definition PpgInterface.cc:60
void WriteCSR(int val)
Write Control and Status Register.
Definition PpgInterface.cc:171