ACQ400_XRM (xrmIoc)
Loading...
Searching...
No Matches
acq400_Permit.h
1/*
2 * acq400_Permit.h: one acq400_Permit per site, first site master
3 *
4 * Created on: 14 Aug 2026
5 * Author: pgm
6 */
7
8#ifndef XRMIOCAPP_SRC_ACQ400_PERMIT_H_
9#define XRMIOCAPP_SRC_ACQ400_PERMIT_H_
10
11#include "acq400_asyn_common.h"
12#include "acq400_FMT_rx.h"
13#include "xrm_structs.h"
14#include "SamplePrams.h"
15#include <map>
16#include <bitset>
17
18#include <epicsGuard.h>
19#include <epicsMutex.h>
20
21#define FIRST_SITE 1
22#define LAST_SITE 6
23
24#define MAX_SITES 6
25#define MAX_ADDR (MAX_SITES+1) // site 0 and selection of 1..6
26
27
28#define FIRST_AI_SITE 1
29#define FIRST_DI_SITE 5
30
31#define PS_PERMIT_TRG_STAT "PERMIT_TRG_STAT" /**<< latched status addr 1..6, perhaps 0: vector? */
32#define PS_PERMIT_TRG_LIVE "PERMIT_TRG_LIVE" /**<< live status addr 1..6, perhaps 0: ALL? */
33#define PS_PERMIT_ATD_MODE "PERMIT_ATD_MODE"
34#define PS_PERMIT_ATD_L1 "PERMIT_ATD_L1"
35#define PS_PERMIT_ATD_L2 "PERMIT_ATD_L2"
36
37#define PS_PERMIT_DI_CH_ACTIVE "PERMIT_DI_CH_ACTIVE"
38#define PS_PERMIT_DI_CH_VALUE "PERMIT_DI_CH_VALUE"
39
40/* commit knob is really for testing */
41#define PS_PERMIT_COMMIT "PERMIT_COMMIT" /**<< set values for next cycle 1: L_CACHE, 2:R_CACHE, 3:BOTH */
42#define PS_PERMIT_LOCK "PERMIT_LOCK" /**<< update L_CACHE without touching R_CACHE (non-atomic params), also, untimed */
43
44struct ATD {
45 enum ATD_MODE { ATD_OFF, ATD_RISING, ATD_FALLING, ATD_INSIDE, ATD_OUTSIDE } atd_mode;
46 float atd_v1; /**<< start voltage, all modes */
47 float atd_v2; /**<< second level, ATD_INSIDE, ATD_OUTSIDE */
48 unsigned char atd_hysteresis_pc; /**<<hysteresis percentage FS */
49};
50
51/** Permit if (dtd_active&value) == (dtd_value&value) */
52struct DTD {
53 unsigned dtd_active; /**<< bitmask of active channels CH01=1<<0, CH32=1<<31 */
54 unsigned dtd_value; /**<< bitmask of permit levels */
55
56 DTD() {
58 }
59};
60
61#define MAP_LEN 0x10000
62#define DSP1_GLBASE 0x80000000
63#define DSP_TH_BASE 0xE000
64#define DSP_TH_SIZE 0x0300
65
66#define DSP_TH_ELEMENTS (DSP_TH_SIZE/sizeof(unsigned))
67
68#define L_CACHE_ELEMENTS (6*32)
69
70
71class PermitDSP {
72/**< Singleton */
73
74private:
75
76 struct REGS {
77 static const unsigned MODID = 0x0000;
78 static const unsigned PCR = 0x0004;
79 static const unsigned PICR = 0x0018;
80 static const unsigned PTSITE = 0x0070;
81
82 static const unsigned PTLAT(const int site) { return 0x0100 + (site-1)*0x10; }
83 static const unsigned PTLIV(const int site) { return 0x0104 + (site-1)*0x10; }
84 } REGS;
85
86 unsigned* _get_regp(unsigned reg);
87 unsigned get(unsigned reg);
88 void set(unsigned reg, unsigned value);
89 void set_bits(unsigned reg, unsigned mask);
90 void clr_bits(unsigned reg, unsigned mask);
91
92 static int verbose;
93
94 struct FILEMAP {
95 int fd;
96 char* map_base;
97 } fpga, shadow;
98
99
100 unsigned element_offset(int site){
101 return (site-1)*0x080;
102 }
103 unsigned* th_base(int site) {
104 return (unsigned*)(fpga.map_base + DSP_TH_BASE + element_offset(site));
105 }
106 unsigned R_cache[DSP_TH_ELEMENTS];
107 unsigned R_cache_map[MAX_SITES];
108
109 void map_fpga();
110 void map_shadow();
111
112 void fill_shadow();
113
114 void close_map(struct FILEMAP& fm);
115 PermitDSP();
116 ~PermitDSP();
117
118 void load_site(unsigned *dst, unsigned** ppsrc, int nu);
119 /**< load data for site, updating src pointer */
120
121
122 struct SITE_DEF {
123 bool is_ai;
124 unsigned char site; /**<< 1..6 */
125 unsigned char nelem; /**<< DI:2, AI16:16, AI32:32 */
126 };
127 SITE_DEF sites[MAX_SITES+1]; /**< address from 1 */
128public:
129 epicsMutex L_CACHE_lock;
130
131 void enable(bool en);
132 void reset();
133 unsigned active_mask(); /**<< set bits show active site 0..5 -> 1..6 */
134 unsigned status(int addr); /**<< latched status site 1..6 0:ALL? */
135 unsigned live(int addr); /**<< live status site 1..6 0:ALL? */
136
137 bool isActiveSite(int site){
138 assert(site >=1 && site <= MAX_SITES);
139 return sites[site].site != 0;
140 }
141 void setElement(int site, int ch_off, unsigned element)
142 {
143 R_cache[element_offset(site)+ch_off];
144 R_cache_map[site] |= 1<<ch_off;
145 }
146 /**<< set element u32 return true on Success */
147
148 unsigned get_permit_latch(int site) const;
149 unsigned get_permit_live(int site) const;
150
151 unsigned clear_permit_latch(int site, unsigned mask) const;
152
153 bool defineSite(int site, bool is_ai, int nelem);
154 /**< as each site is enumerated, declare it */
155 void commit();
156 /**< commit all values to TH RAM */
157
158 void full_load(
159 epicsInt16* ai_th_pairs,/**< agg NCHAN LOW, HI pairs */
160 epicsInt32* di_pairs); /**< agg NDI32 VALUE, ACTIVE pairs */
161
162
163 void _refresh_shadow_element(unsigned offset, unsigned lenw);
164 void refresh_shadow();
165
166 static PermitDSP& instance();
167};
168
169class acq400_Permit: public acq400_asynPortDriver {
170
171
172 static int nice;
173
174 static std::map<int, acq400_Permit*> peers;
175
176 virtual void task();
177 static void task_runner(void *drvPvt);
178 virtual void shadow_task();
179 static void shadow_task_runner(void *drvPvt);
180
181 int P_PERMIT_TRG_STAT; /**<< latched status addr 1..6, perhaps 0: vector? */
182 int P_PERMIT_TRG_LIVE; /**<< live status addr 1..6, perhaps 0: ALL? */
183 int P_PERMIT_COMMIT; /**<< set values for next cycle */
184 int P_PERMIT_LOCK;
185
186
187protected:
188 static int verbose;
189 unsigned dirty_L_CACHE;
190 PermitDSP& dsp;
191 acq400_Permit(const char *portName, int site, bool is_ai, int nchan);
192
193 acq400_FMT_rx* FMT_rx;
194 void check_if_fmt_event_trigger(const FMT& fmt);
195
196 void flush();
197
198 virtual void update_callbacks(bool call_array_callbacks);
199public:
200 virtual void flush_L_CACHE(void) = 0;
201
202 const int site;
203 const int nchan;
204
205 virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
206 virtual asynStatus writeUInt32Digital(asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask);
207
208 static void create_instance(const char *portName, int site, bool is_ai, int nchan);
209};
210
211
212#endif /* XRMIOCAPP_SRC_ACQ400_PERMIT_H_ */
defines SamplePrams, sample geometry definition struct.
define FMT receiver class
Definition acq400_Permit.h:71
void setElement(int site, int ch_off, unsigned element)
Definition acq400_Permit.h:141
void full_load(epicsInt16 *ai_th_pairs, epicsInt32 *di_pairs)
Definition acq400_Permit.cpp:141
unsigned active_mask()
void commit()
Definition acq400_Permit.cpp:115
unsigned status(int addr)
unsigned live(int addr)
bool defineSite(int site, bool is_ai, int nelem)
Definition acq400_Permit.cpp:105
Definition acq400_FMT_rx.h:24
acq400_asynPortDriver(const char *portName, int maxAddr, int interfaceMask, int interruptMask, int asynFlags, int autoConnect, int priority, int stackSize)
Definition acq400_asynPortDriver.cpp:16
Definition acq400_Permit.h:44
unsigned char atd_hysteresis_pc
Definition acq400_Permit.h:48
float atd_v1
Definition acq400_Permit.h:46
float atd_v2
Definition acq400_Permit.h:47
unsigned dtd_active
Definition acq400_Permit.h:53
unsigned dtd_value
Definition acq400_Permit.h:54
Declarations for key XRM structures for internal and wire (external) use.
struct FMT_ROW FMT[FMT_ROWS]
FMT : FNAL Multicast Table.
Definition xrm_structs.h:57