-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcin_power.c
279 lines (208 loc) · 7.32 KB
/
cin_power.c
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
#include <stdio.h>
#include <unistd.h> /* for sleep() */
#include <string.h>
#include <stdlib.h>
#include "cin.h"
#include <iocsh.h>
#include <epicsExport.h>
#include "cin_register_map.h"
// Set HARDWARE to 1 on real system
#define HARDWARE 1
//#undef HARDWARE
#define LOCAL static
#define kSTR_UNINITIALIZED "---"
//LOCAL char fccd_config_dir[]= "/home/jfarrington/Documents/cin_config/";
//LOCAL char fpga_configfile[]= "top_frame_fpga-v1019j.bit";
//LOCAL char cin_configfile_waveform[]= "2013_Nov_30-200MHz_CCD_timing.txt";
//LOCAL char cin_configfile_fcric[]= "2013_Nov_25-200MHz_fCRIC_timing.txt";
//LOCAL char cin_configfile_bias[]= "2013_Nov_05_Bias_Settings.txt";
LOCAL char cin_fpga_config[1024] = kSTR_UNINITIALIZED;
LOCAL char cin_waveform_config[1024] = kSTR_UNINITIALIZED;
LOCAL char cin_fcric_config[1024] = kSTR_UNINITIALIZED;
LOCAL char cin_bias_config[1024] = kSTR_UNINITIALIZED;
LOCAL struct cin_port cp[2];
static const iocshArg FCCD_Config_Dirs_Arg = {"Path", iocshArgString};
static const iocshArg * const FCCD_ConfigDirsArgs[] =
{&FCCD_Config_Dirs_Arg, &FCCD_Config_Dirs_Arg, &FCCD_Config_Dirs_Arg,
&FCCD_Config_Dirs_Arg, &FCCD_Config_Dirs_Arg };
static const iocshFuncDef configFCCD_Dirs = {"FCCD_ConfigDirs", 5, FCCD_ConfigDirsArgs};
void cin_power_up (){
int ret_fpga,ret_fclk;
printf("***cin_power_up\n");// debug
cin_init_ctl_port(&cp[0], 0, 0);
cin_init_ctl_port(&cp[1], 0,49202);
printf("***cp[0] srvaddr = %s, cliaddr = %s, srvport = %d cliport = %d\r\n",
cp[0].srvaddr, cp[0].cliaddr, cp[0].srvport, cp[0].cliport);
printf("***cp[1] srvaddr = %s, cliaddr = %s, srvport = %d cliport = %d\r\n",
cp[1].srvaddr, cp[1].cliaddr, cp[1].srvport, cp[1].cliport);
printf("***Control ports initialized\n");// debug
// Check that file paths have been initialized
if (strcmp(cin_fpga_config,kSTR_UNINITIALIZED) == 0)
{
fprintf(stdout,"\n!Severe Error. File Path cin_fpga_config has not been set!\n\n");
return; // ****** error out *********
}
if (strcmp(cin_waveform_config,kSTR_UNINITIALIZED) == 0)
{
fprintf(stdout,"\n!Severe Error. File Path cin_waveform_config has not been set!\n\n");
return; // ****** error out *********
}
if (strcmp(cin_fcric_config,kSTR_UNINITIALIZED) == 0)
{
fprintf(stdout,"\n!Severe Error. File Path cin_fcric_config has not been set!\n\n");
return; // ****** error out *********
}
if (strcmp(cin_bias_config,kSTR_UNINITIALIZED) == 0)
{
fprintf(stdout,"/n!Severe Error. File Path cin_bias_config has not been set!/n/n");
return; // ****** error out *********
}
#ifdef HARDWARE
cin_off(&cp[0]);
sleep(5);
cin_on(&cp[0]);
sleep(5);
cin_fp_on(&cp[0]);
sleep(5);
cin_load_firmware(&cp[0],&cp[1],cin_fpga_config);
sleep(5);
// Set CIN DATA IP address to 10.23.5.127
#define LOWER_IP_ADDRESS 0x057F // 5.127
#define UPPER_IP_ADDRESS 0x0A17 // 10.23
cin_ctl_write(&cp[0],REG_IF_IP_FAB1B0, LOWER_IP_ADDRESS);
usleep(1000);
cin_ctl_write(&cp[0],REG_IF_IP_FAB1B1, UPPER_IP_ADDRESS);
usleep(1000);
ret_fpga=cin_get_cfg_fpga_status(&cp[0]);
sleep(1);
ret_fclk=cin_get_fclk_status(&cp[0]);
sleep(1);
cin_get_power_status(&cp[0]);
sleep(1);
/************************* FCCD Configuration **************************/
cin_load_config(&cp[0],cin_waveform_config); //Load FCCD clock configuration
sleep(3);
/*
cin_load_config(&cp[0],cin_fcric_config); //Load CIN fcric Configuration
sleep(3);
cin_load_config(&cp[0],cin_bias_config); //Load FCCD bias Configuration
sleep(3);
*/
/**********************************************************************/
fprintf(stdout,"\nCIN startup complete!!\n");
if (ret_fpga==0){fprintf(stdout," *FPGA Status: OK\n");}
else{fprintf(stdout," *FPGA Status: ERROR\n");}
if (ret_fclk==0){fprintf(stdout," *FCLK Status: OK\n");}
else{fprintf(stdout," *FCLK Status: ERROR\n");}
#endif
}
void cin_power_down(){
struct cin_port cp[2];
// debug
printf("***cin_power_down\n");
#ifdef HARDWARE
// Should add a check that cp is valid...
fprintf(stdout,"Turning off clock and bias.......\n");
cin_set_bias(&cp[0],0); //Turn OFF camera CCD bias
sleep(1);
cin_set_clocks(&cp[0],0); //Turn OFF camera CCD bias
sleep(1);
cin_fp_off(&cp[0]); //Power OFF CIN front Panel
sleep(2);
cin_off(&cp[0]); //Power OFF CIN
sleep(4);
fprintf(stdout,"Closing ports.......\n");
cin_close_ctl_port(&cp[0]); //Close Control port
cin_close_ctl_port(&cp[1]); //Close Stream-in port
sleep(1);
fprintf(stdout,"CIN shutdown complete!!\n");
#endif
}
// Public wrappers to cin_api functions
int CIN_set_bias(int val)
{
printf("CIN_set_bias:%d\n", val);
return cin_set_bias(cp,val);
}
int CIN_set_clocks(int val)
{
printf("CIN_set_clocks:%d\n", val);
return cin_set_clocks(cp, val);
}
//val:{0-Internal, 1-External1, 2-External2, 3-External 1 or 2}
int CIN_set_trigger(int val)
{
printf("CIN_set_trigger:%d\n", val);
return cin_set_trigger(cp,val);
}
//Return:{0-Internal, 1-External1, 2-External2, 3-External 1 or 2}
int CIN_get_trigger_status()
{
return cin_get_trigger_status(cp);
}
//val: {1-single, 0-continuous, N>1 is Multiple N Images)
int CIN_set_trigger_mode(int val)
{
printf("CIN_set_trigger_mode :%d\n", val);
return cin_set_trigger_mode(cp, val);
}
//Starts a single trigger or continuous triggers
// depending on previous call to set_trigger_mode
int CIN_trigger_start()
{
printf("CIN_trigger_start\n");
return cin_trigger_start(cp);
}
//Stops triggers
int CIN_trigger_stop()
{
printf("CIN_trigger_stop\n");
return cin_trigger_stop(cp);
}
// Set the Camera exposure time
// Input:e_time (ms)
int CIN_set_exposure_time(float e_time)
{
return cin_set_exposure_time(cp,e_time);
}
//Set the trigger delay time
//Input:t_time (ms)
int CIN_set_trigger_delay(float t_time)
{
return cin_set_trigger_delay(cp,t_time);
}
//Set the Camera cyle time time
//Input:c_time (ms)
int CIN_set_cycle_time(float c_time)
{
return cin_set_cycle_time(cp,c_time);
}
//extern "C" {
static void configFCCD_DirsCallFunc(const iocshArgBuf *args)
{
FCCD_ConfigDirs(args[0].sval, args[1].sval, args[2].sval, args[3].sval, args[4].sval);
}
static void FCCD_Dirs_Register(void)
{
iocshRegister(&configFCCD_Dirs, configFCCD_DirsCallFunc);
}
int FCCD_ConfigDirs(
const char *fccd_config_dir,
const char *fpga_configfile,
const char *cin_configfile_waveform ,
const char *cin_configfile_fcric,
const char *cin_configfile_bias)
{
printf("fccd_config_dir: %s\n", fccd_config_dir);
printf("fpga_configfile: %s\n", fpga_configfile);
printf("cin_configfile_waveform: %s\n", cin_configfile_waveform);
printf("cin_configfile_fcric: %s\n", cin_configfile_fcric);
printf("cin_configfile_bias: %s\n", cin_configfile_bias);
sprintf(cin_fpga_config,"%s%s", fccd_config_dir,fpga_configfile);
sprintf(cin_waveform_config,"%s%s", fccd_config_dir,cin_configfile_waveform);
sprintf(cin_fcric_config,"%s%s", fccd_config_dir,cin_configfile_fcric);
sprintf(cin_bias_config,"%s%s", fccd_config_dir,cin_configfile_bias);
return(0);
}
epicsExportRegistrar(FCCD_Dirs_Register);
//}