[r3527]: branches / Gxsm-2x3-transition-sig / plug-ins / hard / sranger_mk3_hwi.h Maximize Restore History

Download this file

sranger_mk3_hwi.h    340 lines (286 with data), 12.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* Gxsm - Gnome X Scanning Microscopy
* universal STM/AFM/SARLS/SPALEED/... controlling and
* data analysis software
*
* Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
*
* Authors: Percy Zahl <zahl@users.sf.net>
* additional features: Andreas Klust <klust@users.sf.net>
* WWW Home: http://gxsm.sf.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
#ifndef __SRANGER_MK3_HWI_H
#define __SRANGER_MK3_HWI_H
#include "MK3-A810_spmcontrol/FB_spm_dataexchange.h" // SRanger data exchange structs and consts
#include "MK3-A810_spmcontrol/dsp_signals.h" // SRanger data exchange structs and consts
#include "sranger_mk23common_hwi.h"
#define DSP_UINT32 guint32
#define DSP_INT32 gint32
typedef struct{
DSP_UINT32 r_position; /* read pos (Gxsm) (always in word size) (WO) by host =WO */
DSP_UINT32 w_position; /* write pos (DSP) (always in word size) (RO) by host =RO */
DSP_UINT32 current_section_head_position; /* resync/verify and status info =RO */
DSP_UINT32 current_section_index; /* index of current section =RO */
DSP_UINT32 fill; /* filled indicator = max num to read =RO */
DSP_UINT32 stall; /* number of fifo stalls =RO */
DSP_UINT32 length; /* constant, buffer size =RO */
DSP_UINT32 p_buffer_base; /* pointer to external memory, buffer start =RO */
DSP_UINT32 p_buffer_w; /* pointer to external memory =RO */
DSP_UINT32 p_buffer_l;
} DATA_FIFO_EXTERN_PCOPY_MK3;
typedef struct{
DSP_UINT32 srcs;
DSP_UINT32 n;
DSP_UINT32 time;
DSP_INT16 x_offset;
DSP_INT16 y_offset;
DSP_INT16 z_offset;
DSP_INT16 x_scan;
DSP_INT16 y_scan;
DSP_INT16 z_scan;
DSP_INT16 u_scan;
DSP_INT16 section;
} PROBE_SECTION_HEADER_MK3;
// reference
extern DSPControl *DSPControlClass;
// MK3 translation interface
class sranger_mk3_hwi_dev : public sranger_common_hwi_dev{
public:
friend class DSPControl;
friend class DSPPACControl;
sranger_mk3_hwi_dev();
virtual ~sranger_mk3_hwi_dev();
/* Parameter */
virtual long GetMaxPointsPerLine(){ return AIC_max_points; };
virtual long GetMaxLines(){ return AIC_max_points; };
virtual gchar* get_info();
/* Hardware realtime monitoring -- all optional */
/* default properties are
* "X" -> current realtime tip position in X, inclusive rotation and offset
* "Y" -> current realtime tip position in Y, inclusive rotation and offset
* "Z" -> current realtime tip position in Z
* "xy" -> X and Y
* "zxy" -> Z, X, Y
* "U" -> current bias
*/
virtual gint RTQuery (const gchar *property, double &val) { return FALSE; };
virtual gint RTQuery (const gchar *property, double &val1, double &val2) { return FALSE; };
virtual gint RTQuery (const gchar *property, double &val1, double &val2, double &val3) { return FALSE; };
virtual gint RTQuery (const gchar *property, gchar **val) { return FALSE; };
virtual double GetUserParam (gint n, gchar *id=NULL);
virtual gint SetUserParam (gint n, gchar *id=NULL, double value=0.);
virtual gint RTQuery () { return fifo_data_y_index; }; // actual progress on scan -- y-index mirror from FIFO read
virtual void ExecCmd(int Cmd) {};
virtual void SetMode(int mode) {};
virtual void ClrMode(int mode) {};
virtual void set_ldc (double dxdt=0., double dydt=0., double dzdt=0.) {};
// SRanger format conversions and endianess adaptions
void swap (guint16 *addr);
void swap (gint16 *addr);
void swap (gint32 *addr);
void check_and_swap (gint16 &data) {
};
void check_and_swap (guint16 &data) {
};
void check_and_swap (guint32 &data) {
};
void check_and_swap (gint32 &data) {
};
gint32 float_2_sranger_q15 (double x);
gint32 float_2_sranger_q31 (double x);
gint32 int_2_sranger_int (gint32 x);
guint32 uint_2_sranger_uint (guint32 x);
gint32 long_2_sranger_long (gint32 x);
virtual int start_fifo_read (int y_start,
int num_srcs0, int num_srcs1, int num_srcs2, int num_srcs3,
Mem2d **Mob0, Mem2d **Mob1, Mem2d **Mob2, Mem2d **Mob3);
virtual int ReadLineFromFifo (int y_index);
virtual int ReadProbeFifo (int dspdev, int control=0);
int probe_fifo_thread_active;
int fifo_data_y_index;
int fifo_data_num_srcs[4]; // 0: XP, 1: XM, 2: 2ND_XP, 3: 2ND_XM
Mem2d **fifo_data_Mobp[4]; // 0: XP, 1: XM, 2: 2ND_XP, 3: 2ND_XM
int probe_thread_dsp; // connection to SRanger used by probe thread
#if 0
void g_mem_dumpbuffer_U32 (unsigned char *buffer, int size, gchar *dest){
int i,j;
gchar *tmp=NULL;
for(i=0; i<size; i+=16){
tmp=g_strdup_print("W %06X:",(i>>1)&DATAFIFO_MASK);
g_strdup_...
for(j=0; (j<16) && (i+j)<size; j++)
g_print(" %02x",buffer[(((i>>1)&DATAFIFO_MASK)<<1) + j]);
}
}
#endif
inline void sr_read (int fh, void *d, size_t n, const gchar *dbg=NULL){
ssize_t ret;
if ((ret = read (fh, d, n)) < 0){
gchar *details = g_strdup_printf ("[N=%d], ret=%d, %s\nDbgInfo: %s", (int)n, (int)ret, strerror(ret), dbg?dbg:"NA");
gapp->alert (N_("DSP read error"), N_("Error reading data from DSP."), details, 1);
g_free (details);
}
};
inline void sr_write (int fh, const void *d, size_t n, const gchar *dbg=NULL){
ssize_t ret;
if ((ret = write (fh, d, n)) < 0){
gchar *details = g_strdup_printf ("[N=%d], ret=%d, %s\nDbgInfo: %s",(int)n, (int)ret, strerror(ret), dbg?dbg:"NA");
gapp->alert (N_("DSP write error"), N_("Error writing data to DSP."), details, 1);
g_free (details);
}
};
virtual void read_dsp_state (gint32 &mode); // FB on/off
virtual void write_dsp_state (gint32 mode);
virtual void conv_dsp_feedback ();
virtual void read_dsp_feedback (); // cp, cp, setpoint
virtual void write_dsp_feedback (
double set_point[4], double factor[4], double gain[4], double level[4], int transform_mode[4],
double IIR_I_crossover, double IIR_f0_max[4], double IIR_f0_min, double LOG_I_offset, int IIR_flag,
double z_servo[3], double m_servo[3], double pllref=0.);
void conv_dsp_analog ();
virtual void read_dsp_analog (); // bias
virtual void write_dsp_analog (double bias, double motor) ;
void conv_dsp_scan ();
virtual void read_dsp_scan (gint32 &pflg);
virtual void write_dsp_scan () ;
virtual void recalculate_dsp_scan_speed_parameters ();
virtual void recalculate_dsp_scan_slope_parameters ();
void conv_dsp_scan_event_trigger ();
virtual void read_dsp_scan_event_trigger (int &pflg, int i_xp[], int i_xm[], double sp_xp[], double sp_xm[]);
virtual void write_dsp_scan_event_trigger (int &pflg, int i_xp[], int i_xm[], double sp_xp[], double sp_xm[]);
virtual void conv_dsp_probe ();
virtual void read_dsp_lockin (double &AC_amp, double &AC_frq, double &AC_phaseA, double &AC_phaseB, gint32 &AC_lockin_avg_cycels);
virtual void write_dsp_lockin_probe_final (double AC_amp, double AC_frq, double AC_phaseA, double AC_phaseB, gint32 AC_lockin_avg_cycels, double VP_lim_val, double noise_amp, int start=0);
virtual int dsp_lockin_state(int set);
void conv_dsp_vector ();
virtual void read_dsp_vector (int index, PROBE_VECTOR_GENERIC *__dsp_vector);
virtual void write_dsp_vector (int index, PROBE_VECTOR_GENERIC *__dsp_vector);
int read_pll_symbols ();
double read_pll_variable32 (gint64 address);
gint32 read_pll_variable32i (gint64 address);
void write_pll_variable32 (gint64 address, double x);
void write_pll_variable32 (gint64 address, gint32 x);
double read_pll_variable64 (gint64 address);
void write_pll_variable64 (gint64 address, double x);
void write_pll_variable64 (gint64 address, gint64 x);
void read_pll_array32 (gint64 address, int n, gint32 *arr);
void write_pll_array32 (gint64 address, int n, gint32 *arr);
virtual int check_pac () { return 0; } // returns 0 if PAC/PLL capability available, else -1
virtual int read_pll (PAC_control &pll, PLL_GROUP group=PLL_ALL);
virtual int write_pll (PAC_control &pll, PLL_GROUP group, int enable=0);
virtual int read_pll_signal1 (PAC_control &pll, int n, double scale=1., gint flag=FALSE);
virtual int read_pll_signal2 (PAC_control &pll, int n, double scale=1., gint flag=FALSE);
void set_scope (int s1, int s2);
void set_blcklen (int len=1024);
void setup_step_response (double dPhase, double dAmplitude);
// SIGNAL MANAGEMENT
virtual void read_dsp_signals () { read_signal_lookup (); read_actual_module_configuration (); };
virtual int lookup_signal_by_ptr(gint64 sigptr);
virtual const gchar *lookup_signal_name_by_index(int i);
virtual const gchar *lookup_signal_unit_by_index(int i);
virtual double lookup_signal_scale_by_index(int i);
virtual int change_signal_input(int signal_index, gint32 input_id);
virtual int query_module_signal_input(gint32 input_id);
int read_signal_lookup ();
int read_actual_module_configuration ();
protected:
int dsp; // connection to SRanger
int dsp_alternative; // 2nd connection to SRanger
int thread_dsp; // connection to SRanger used by thread
// add data shared w upper spm class here
SPM_MAGIC_DATA_LOCATIONS_MK3 magic_data;
int target;
int swap_flg;
private:
GThread *fifo_read_thread;
GThread *probe_fifo_read_thread;
int FifoRead (int start, int end, int &xi, int num_srcs, int len, float *buffer_f, DSP_UINT32 *fifo_l);
LNG bz_unpack (int i, DSP_UINT32 *fifo_l, int &q, int &count);
gchar *productid;
int AIC_max_points;
gint32 bz_last[BZ_MAX_CHANNELS];
int bz_byte_pos;
int bz_need_reswap;
double bz_scale;
gint32 bz_dsp_srcs;
gint32 bz_dsp_ns;
guint32 bz_push_mode;
protected:
gint32 tmp_nx_pre;
gint32 tmp_fs_dx;
gint32 tmp_fs_dy;
gint32 tmp_dnx;
gint32 tmp_dny;
gint32 tmp_fast_return;
gint32 tmp_sRe;
gint32 tmp_sIm;
SPM_STATEMACHINE_MK3 dsp_state;
ANALOG_VALUES_MK3 dsp_analog;
SIGNAL_MONITOR_MK3 dsp_signal_monitor;
SERVO_MK3 dsp_z_servo;
SERVO_MK3 dsp_m_servo;
FEEDBACK_MIXER_MK3 dsp_feedback_mixer;
AREA_SCAN_MK3 dsp_scan;
MOVE_OFFSET_MK3 dsp_move;
SCAN_EVENT_TRIGGER_MK3 dsp_scan_event_trigger;
PROBE_MK3 dsp_probe;
DATA_FIFO_MK3 dsp_fifo;
CR_OUT_PULSE_MK3 dsp_cr_out_pulse; // IO puls engine
CR_GENERIC_IO_MK3 dsp_cr_generic_io; // IO and Counter control
PROBE_VECTOR_MK3 dsp_vector;
PLL_LOOKUP dsp_pll; // PLL controls (MK3-Pro only A810 or A810/TCO high precision)
};
/*
* SPM hardware abstraction class for use with Signal Ranger compatible hardware
* ======================================================================
*/
class sranger_mk3_hwi_spm : public sranger_mk3_hwi_dev{
public:
sranger_mk3_hwi_spm();
virtual ~sranger_mk3_hwi_spm();
/* Hardware realtime monitoring -- all optional */
/* default properties are
* "X" -> current realtime tip position in X, inclusive rotation and offset
* "Y" -> current realtime tip position in Y, inclusive rotation and offset
* "Z" -> current realtime tip position in Z
* "xy" -> X and Y
* "zxy" -> Z, X, Y
* "U" -> current bias
*/
virtual gint RTQuery (const gchar *property, double &val) { return FALSE; };
virtual gint RTQuery (const gchar *property, double &val1, double &val2) { return FALSE; };
virtual gint RTQuery (const gchar *property, double &val1, double &val2, double &val3);
virtual gint RTQuery (const gchar *property, gchar **val) { return FALSE; };
virtual void SetOffset(long x, long y);
virtual void StartScan2D();
virtual void ScanLineM(int yindex, int xdir, int muxmode,
Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0=0 );
virtual void EndScan2D();
virtual void PauseScan2D();
virtual void ResumeScan2D();
virtual void KillScan2D(){ KillFlg=TRUE; };
virtual void ExecCmd(int Cmd);
virtual void SetMode(int mode);
virtual void ClrMode(int mode);
virtual void set_ldc (double dxdt=0., double dydt=0., double dzdt=0.);
void reset_scandata_fifo (int stall=0); //!< reset scan data FIFO buffer
void tip_to_origin (double x=0., double y=0.); //!< move tip to origin (default) or position in scan coordinate system
protected:
private:
DSPControl *dc;
};
#endif