/* SNC Version 2.0.11: Sat Mar 20 16:04:59 2010: sncpac.i */ /* Event flags */ #define changeWfsEvent 1 #define changeCwfsEvent 2 /* Program "sncpac" */ #include "seqCom.h" #define NUM_SS 1 #define NUM_CHANNELS 17 #define NUM_EVENTS 2 #define NUM_QUEUES 0 #define MAX_STRING_SIZE 40 #define ASYNC_OPT FALSE #define CONN_OPT TRUE #define DEBUG_OPT FALSE #define MAIN_OPT FALSE #define NEWEF_OPT TRUE #define REENT_OPT FALSE extern struct seqProgram sncpac; /* Variable declarations */ static int opState; static int calibCtrl; static int wfSelection; static int cwfSelection; static int trigMode; static int loadingWf; static int loadingCwf; static int rescaleIbyAmplitude; static int rescaleQbyAmplitude; static int loadIRefFromFile; static int loadQRefFromFile; static int loadICalRefFromFile; static int loadQCalRefFromFile; static int updateOpsIFPGA; static int updateOpsQFPGA; static int updateCalIFPGA; static int updateCalQFPGA; /* Not used (avoids compilation warnings) */ struct UserVar { int dummy; }; /* C code definitions */ # line 4 "../sncpac.st" #include "pacMacros.h" # line 5 "../sncpac.st" #include "drvPac.h" /* Entry handler */ static void entry_handler(SS_ID ssId, struct UserVar *pVar) { } /* Code for state "init" in state set "pac" */ /* Entry function for state "init" in state set "pac" */ static void I_pac_init(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 78 "../sncpac.st" printf("sncpac: init\n"); } /* Delay function for state "init" in state set "pac" */ static void D_pac_init(SS_ID ssId, struct UserVar *pVar) { # line 82 "../sncpac.st" seq_delayInit(ssId, 0, (1)); } /* Event function for state "init" in state set "pac" */ static long E_pac_init(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 82 "../sncpac.st" if (seq_delay(ssId, 0) && (opState == PAC_STARTING)) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "pac" */ static void A_pac_init(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 81 "../sncpac.st" printf("sncpac: operation state set to start-up\n"); } return; } } /* Code for state "startup" in state set "pac" */ /* Entry function for state "startup" in state set "pac" */ static void I_pac_startup(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 87 "../sncpac.st" opState = PAC_STARTING; # line 88 "../sncpac.st" seq_pvPut(ssId, 0 /* opState */, 0); # line 89 "../sncpac.st" calibCtrl = PAC_CAL_IDLE; # line 90 "../sncpac.st" seq_pvPut(ssId, 1 /* calibCtrl */, 0); # line 91 "../sncpac.st" printf("sncpac: startup\n"); } /* Delay function for state "startup" in state set "pac" */ static void D_pac_startup(SS_ID ssId, struct UserVar *pVar) { # line 99 "../sncpac.st" seq_delayInit(ssId, 0, (1)); # line 103 "../sncpac.st" seq_delayInit(ssId, 1, (5)); } /* Event function for state "startup" in state set "pac" */ static long E_pac_startup(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 99 "../sncpac.st" if (seq_delay(ssId, 0) && (seq_efTest(ssId, changeWfsEvent))) { *pNextState = 3; *pTransNum = 0; return TRUE; } # line 103 "../sncpac.st" if (seq_delay(ssId, 1)) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "startup" in state set "pac" */ static void A_pac_startup(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 97 "../sncpac.st" printf("sncpac: startup detects changeWfsEvent to load initial reference waveforms.\n"); seq_efClear(ssId, changeWfsEvent); } return; case 1: { # line 102 "../sncpac.st" printf("sncpac: startup sequence unable to complete. Select a waveform pair\n"); } return; } } /* Code for state "running" in state set "pac" */ /* Entry function for state "running" in state set "pac" */ static void I_pac_running(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 110 "../sncpac.st" printf("sncpac: running. reloading ops waveforms into FPGA\n"); # line 111 "../sncpac.st" updateOpsIFPGA = 1; # line 112 "../sncpac.st" seq_pvPut(ssId, 13 /* updateOpsIFPGA */, 0); # line 113 "../sncpac.st" updateOpsQFPGA = 1; # line 114 "../sncpac.st" seq_pvPut(ssId, 14 /* updateOpsQFPGA */, 0); # line 116 "../sncpac.st" printf("sncpac: running. using external trigger mode\n"); # line 117 "../sncpac.st" opState = PAC_RUNNING; # line 118 "../sncpac.st" seq_pvPut(ssId, 0 /* opState */, 0); # line 119 "../sncpac.st" trigMode = PAC_EXT_TRIG_MODE; # line 120 "../sncpac.st" seq_pvPut(ssId, 4 /* trigMode */, 0); } /* Delay function for state "running" in state set "pac" */ static void D_pac_running(SS_ID ssId, struct UserVar *pVar) { # line 125 "../sncpac.st" seq_delayInit(ssId, 0, (1)); # line 130 "../sncpac.st" seq_delayInit(ssId, 1, (1)); } /* Event function for state "running" in state set "pac" */ static long E_pac_running(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 125 "../sncpac.st" if (seq_delay(ssId, 0) && (calibCtrl == PAC_CAL_RQST)) { *pNextState = 4; *pTransNum = 0; return TRUE; } # line 130 "../sncpac.st" if (seq_delay(ssId, 1) && (seq_efTest(ssId, changeWfsEvent))) { *pNextState = 3; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "running" in state set "pac" */ static void A_pac_running(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 124 "../sncpac.st" printf("sncpac: calibration requested\n"); } return; case 1: { # line 128 "../sncpac.st" printf("sncpac: running. detects event to change wfs\n"); seq_efClear(ssId, changeWfsEvent); } return; } } /* Code for state "changing_wf" in state set "pac" */ /* Entry function for state "changing_wf" in state set "pac" */ static void I_pac_changing_wf(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 136 "../sncpac.st" opState = PAC_CHANGING_WFS; # line 137 "../sncpac.st" seq_pvPut(ssId, 0 /* opState */, 0); # line 138 "../sncpac.st" printf("sncpac: changing to waveforms %d. using internal trigger mode\n", wfSelection); # line 148 "../sncpac.st" loadIRefFromFile = 1; # line 149 "../sncpac.st" seq_pvPut(ssId, 9 /* loadIRefFromFile */, 0); # line 150 "../sncpac.st" loadQRefFromFile = 1; # line 151 "../sncpac.st" seq_pvPut(ssId, 10 /* loadQRefFromFile */, 0); # line 152 "../sncpac.st" printf("sncpac: forcing processing of I_REF and Q_REF\n"); } /* Delay function for state "changing_wf" in state set "pac" */ static void D_pac_changing_wf(SS_ID ssId, struct UserVar *pVar) { # line 158 "../sncpac.st" seq_delayInit(ssId, 0, (.5)); } /* Event function for state "changing_wf" in state set "pac" */ static long E_pac_changing_wf(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 158 "../sncpac.st" if (seq_delay(ssId, 0) && (loadingWf == 0)) { *pNextState = 2; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "changing_wf" in state set "pac" */ static void A_pac_changing_wf(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 157 "../sncpac.st" printf("sncpac: new wfs loaded. resume running\n"); } return; } } /* Code for state "calibrating" in state set "pac" */ /* Entry function for state "calibrating" in state set "pac" */ static void I_pac_calibrating(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 163 "../sncpac.st" printf("sncpac: calibrating. reloading cal waveforms into FPGA\n"); # line 164 "../sncpac.st" updateCalIFPGA = 1; # line 165 "../sncpac.st" seq_pvPut(ssId, 15 /* updateCalIFPGA */, 0); # line 166 "../sncpac.st" updateCalQFPGA = 1; # line 167 "../sncpac.st" seq_pvPut(ssId, 16 /* updateCalQFPGA */, 0); # line 169 "../sncpac.st" opState = PAC_CALIBRATING; # line 170 "../sncpac.st" seq_pvPut(ssId, 0 /* opState */, 0); # line 171 "../sncpac.st" trigMode = PAC_INT_TRIG_MODE; # line 172 "../sncpac.st" seq_pvPut(ssId, 4 /* trigMode */, 0); # line 173 "../sncpac.st" printf("sncpac: doing calibration. using internal trigger mode\n"); } /* Delay function for state "calibrating" in state set "pac" */ static void D_pac_calibrating(SS_ID ssId, struct UserVar *pVar) { # line 178 "../sncpac.st" seq_delayInit(ssId, 0, (1)); # line 183 "../sncpac.st" seq_delayInit(ssId, 1, (1)); } /* Event function for state "calibrating" in state set "pac" */ static long E_pac_calibrating(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 178 "../sncpac.st" if (seq_delay(ssId, 0) && (calibCtrl == PAC_CAL_DONE)) { *pNextState = 6; *pTransNum = 0; return TRUE; } # line 183 "../sncpac.st" if (seq_delay(ssId, 1) && (seq_efTest(ssId, changeCwfsEvent))) { *pNextState = 5; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "calibrating" in state set "pac" */ static void A_pac_calibrating(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 177 "../sncpac.st" printf("sncpac: calibration done. resume running...\n"); } return; case 1: { # line 181 "../sncpac.st" printf("sncpac: calibrating. detects event to change cwfs\n"); seq_efClear(ssId, changeCwfsEvent); } return; } } /* Code for state "changing_cwf" in state set "pac" */ /* Entry function for state "changing_cwf" in state set "pac" */ static void I_pac_changing_cwf(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 189 "../sncpac.st" opState = PAC_CHANGING_CWFS; # line 190 "../sncpac.st" seq_pvPut(ssId, 0 /* opState */, 0); # line 191 "../sncpac.st" printf("sncpac: changing calibration waveforms\n"); # line 192 "../sncpac.st" printf("sncpac: changing to %d. using internal trigger mode\n", cwfSelection); # line 193 "../sncpac.st" loadICalRefFromFile = 1; # line 194 "../sncpac.st" seq_pvPut(ssId, 11 /* loadICalRefFromFile */, 0); # line 195 "../sncpac.st" loadQCalRefFromFile = 1; # line 196 "../sncpac.st" seq_pvPut(ssId, 12 /* loadQCalRefFromFile */, 0); # line 197 "../sncpac.st" printf("sncpac: forcing processing of ICAL_REF and QCAL_REF\n"); } /* Delay function for state "changing_cwf" in state set "pac" */ static void D_pac_changing_cwf(SS_ID ssId, struct UserVar *pVar) { # line 202 "../sncpac.st" seq_delayInit(ssId, 0, (.5)); } /* Event function for state "changing_cwf" in state set "pac" */ static long E_pac_changing_cwf(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 202 "../sncpac.st" if (seq_delay(ssId, 0) && (loadingCwf == 0)) { *pNextState = 4; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "changing_cwf" in state set "pac" */ static void A_pac_changing_cwf(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 201 "../sncpac.st" printf("sncpac: assume new cal wfs finished loading. resume calibrating\n"); } return; } } /* Code for state "calibration_done" in state set "pac" */ /* Entry function for state "calibration_done" in state set "pac" */ static void I_pac_calibration_done(SS_ID ssId, struct UserVar *pVar) { /* Entry 1: */ # line 207 "../sncpac.st" opState = PAC_CALIBRATION_DONE; # line 208 "../sncpac.st" seq_pvPut(ssId, 0 /* opState */, 0); } /* Delay function for state "calibration_done" in state set "pac" */ static void D_pac_calibration_done(SS_ID ssId, struct UserVar *pVar) { # line 213 "../sncpac.st" seq_delayInit(ssId, 0, (1)); } /* Event function for state "calibration_done" in state set "pac" */ static long E_pac_calibration_done(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 213 "../sncpac.st" if (seq_delay(ssId, 0)) { *pNextState = 2; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "calibration_done" in state set "pac" */ static void A_pac_calibration_done(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 211 "../sncpac.st" calibCtrl = PAC_CAL_IDLE; seq_pvPut(ssId, 1 /* calibCtrl */, 0); } return; } } /* Exit handler */ static void exit_handler(SS_ID ssId, struct UserVar *pVar) { } /************************ Tables ***********************/ /* Database Blocks */ static struct seqChan seqChan[NUM_CHANNELS] = { {"{PRIM}:{LOCA}:{UNIT}:{PAC}_C_STATE", (void *)&opState, "opState", "int", 1, 3, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_C_CALIB", (void *)&calibCtrl, "calibCtrl", "int", 1, 4, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_WF", (void *)&wfSelection, "wfSelection", "int", 1, 5, 1, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_CWF", (void *)&cwfSelection, "cwfSelection", "int", 1, 6, 2, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_TRG_MODE", (void *)&trigMode, "trigMode", "int", 1, 7, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_WF.PACT", (void *)&loadingWf, "loadingWf", "int", 1, 8, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_CWF.PACT", (void *)&loadingCwf, "loadingCwf", "int", 1, 9, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_ICAL.PROC", (void *)&rescaleIbyAmplitude, "rescaleIbyAmplitude", "int", 1, 10, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_QCAL.PROC", (void *)&rescaleQbyAmplitude, "rescaleQbyAmplitude", "int", 1, 11, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_I_REF.PROC", (void *)&loadIRefFromFile, "loadIRefFromFile", "int", 1, 12, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_Q_REF.PROC", (void *)&loadQRefFromFile, "loadQRefFromFile", "int", 1, 13, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_ICAL_REF.PROC", (void *)&loadICalRefFromFile, "loadICalRefFromFile", "int", 1, 14, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_QCAL_REF.PROC", (void *)&loadQCalRefFromFile, "loadQCalRefFromFile", "int", 1, 15, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_I_UP_FP.PROC", (void *)&updateOpsIFPGA, "updateOpsIFPGA", "int", 1, 16, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_Q_UP_FP.PROC", (void *)&updateOpsQFPGA, "updateOpsQFPGA", "int", 1, 17, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_IC_UP_FP.PROC", (void *)&updateCalIFPGA, "updateCalIFPGA", "int", 1, 18, 0, 1, 0, 0, 0}, {"{PRIM}:{LOCA}:{UNIT}:{PAC}_QC_UP_FP.PROC", (void *)&updateCalQFPGA, "updateCalQFPGA", "int", 1, 19, 0, 1, 0, 0, 0}, }; /* Event masks for state set pac */ /* Event mask for state init: */ static bitMask EM_pac_init[] = { 0x00000008, }; /* Event mask for state startup: */ static bitMask EM_pac_startup[] = { 0x00000002, }; /* Event mask for state running: */ static bitMask EM_pac_running[] = { 0x00000012, }; /* Event mask for state changing_wf: */ static bitMask EM_pac_changing_wf[] = { 0x00000100, }; /* Event mask for state calibrating: */ static bitMask EM_pac_calibrating[] = { 0x00000014, }; /* Event mask for state changing_cwf: */ static bitMask EM_pac_changing_cwf[] = { 0x00000200, }; /* Event mask for state calibration_done: */ static bitMask EM_pac_calibration_done[] = { 0x00000000, }; /* State Blocks */ static struct seqState state_pac[] = { /* State "init" */ { /* state name */ "init", /* action function */ (ACTION_FUNC) A_pac_init, /* event function */ (EVENT_FUNC) E_pac_init, /* delay function */ (DELAY_FUNC) D_pac_init, /* entry function */ (ENTRY_FUNC) I_pac_init, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_init, /* state options */ (0)}, /* State "startup" */ { /* state name */ "startup", /* action function */ (ACTION_FUNC) A_pac_startup, /* event function */ (EVENT_FUNC) E_pac_startup, /* delay function */ (DELAY_FUNC) D_pac_startup, /* entry function */ (ENTRY_FUNC) I_pac_startup, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_startup, /* state options */ (0)}, /* State "running" */ { /* state name */ "running", /* action function */ (ACTION_FUNC) A_pac_running, /* event function */ (EVENT_FUNC) E_pac_running, /* delay function */ (DELAY_FUNC) D_pac_running, /* entry function */ (ENTRY_FUNC) I_pac_running, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_running, /* state options */ (0)}, /* State "changing_wf" */ { /* state name */ "changing_wf", /* action function */ (ACTION_FUNC) A_pac_changing_wf, /* event function */ (EVENT_FUNC) E_pac_changing_wf, /* delay function */ (DELAY_FUNC) D_pac_changing_wf, /* entry function */ (ENTRY_FUNC) I_pac_changing_wf, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_changing_wf, /* state options */ (0)}, /* State "calibrating" */ { /* state name */ "calibrating", /* action function */ (ACTION_FUNC) A_pac_calibrating, /* event function */ (EVENT_FUNC) E_pac_calibrating, /* delay function */ (DELAY_FUNC) D_pac_calibrating, /* entry function */ (ENTRY_FUNC) I_pac_calibrating, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_calibrating, /* state options */ (0)}, /* State "changing_cwf" */ { /* state name */ "changing_cwf", /* action function */ (ACTION_FUNC) A_pac_changing_cwf, /* event function */ (EVENT_FUNC) E_pac_changing_cwf, /* delay function */ (DELAY_FUNC) D_pac_changing_cwf, /* entry function */ (ENTRY_FUNC) I_pac_changing_cwf, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_changing_cwf, /* state options */ (0)}, /* State "calibration_done" */ { /* state name */ "calibration_done", /* action function */ (ACTION_FUNC) A_pac_calibration_done, /* event function */ (EVENT_FUNC) E_pac_calibration_done, /* delay function */ (DELAY_FUNC) D_pac_calibration_done, /* entry function */ (ENTRY_FUNC) I_pac_calibration_done, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_pac_calibration_done, /* state options */ (0)}, }; /* State Set Blocks */ static struct seqSS seqSS[NUM_SS] = { /* State set "pac" */ { /* ss name */ "pac", /* ptr to state block */ state_pac, /* number of states */ 7, /* error state */ -1}, }; /* Program parameter list */ static char prog_param[] = ""; /* State Program table (global) */ struct seqProgram sncpac = { /* magic number */ 20000315, /* *name */ "sncpac", /* *pChannels */ seqChan, /* numChans */ NUM_CHANNELS, /* *pSS */ seqSS, /* numSS */ NUM_SS, /* user variable size */ 0, /* *pParams */ prog_param, /* numEvents */ NUM_EVENTS, /* encoded options */ (0 | OPT_CONN | OPT_NEWEF), /* entry handler */ (ENTRY_FUNC) entry_handler, /* exit handler */ (EXIT_FUNC) exit_handler, /* numQueues */ NUM_QUEUES, }; /* Register sequencer commands and program */ void sncpacRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&sncpac); } epicsExportRegistrar(sncpacRegistrar);