/* C code for program mrLlrfInterlock, generated by snc from ../sncLlrfInterlock.stt */ #include #include #include #include #include "seq_snc.h" # line 10 "../sncLlrfInterlock.stt" #include #define MANUAL 0 #define FULLAUTO 1 #define BYPASS 2 #define HVON 1 #define HVOFF 0 #define NOFAULT 0 #define FAULT 1 #define RESET 1 #define RAMP_DONE 2 #define RAMP_UP 1 #define RAMP_STOP 0 /* for trigger control */ #define TRIG_DISABLE 0 #define TRIG_STDBYONLY 1 #define TRIG_NORMALOP 2 #define STATUS1_WAIT 0 #define STATUS1_FAULT 1 #define STATUS1_RAMPUP 2 #define STATUS2_WAIT 0 #define STATUS2_RAMPUP 1 #define FINALMODE_STANDBY 0 #define FINALMODE_ACCELERATE1 1 #define FINALMODE_ACCELERATE2 2 /* Variable declarations */ struct seqg_vars { # line 46 "../sncLlrfInterlock.stt" int reset; # line 49 "../sncLlrfInterlock.stt" int status1; # line 51 "../sncLlrfInterlock.stt" int status2; # line 53 "../sncLlrfInterlock.stt" int mode; # line 56 "../sncLlrfInterlock.stt" double ramp_time; # line 59 "../sncLlrfInterlock.stt" int ramp_up; # line 62 "../sncLlrfInterlock.stt" int fault_out; # line 65 "../sncLlrfInterlock.stt" int fault_clear; # line 67 "../sncLlrfInterlock.stt" int trig_control; # line 69 "../sncLlrfInterlock.stt" double corrscale_control; # line 71 "../sncLlrfInterlock.stt" int mod_status; # line 75 "../sncLlrfInterlock.stt" int final_mode; # line 79 "../sncLlrfInterlock.stt" double stored_corrscale; }; /* Function declarations */ #define seqg_var (*(struct seqg_vars *const *)seqg_env) /* Program init func */ static void seqg_init(PROG_ID seqg_env) { } /****** Code for state "wait" in state set "recovery" ******/ /* Entry function for state "wait" in state set "recovery" */ static void seqg_entry_recovery_0_wait(SS_ID seqg_env) { # line 90 "../sncLlrfInterlock.stt" seqg_var->status1 = STATUS1_WAIT; # line 91 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 1/*status1*/, DEFAULT, DEFAULT_TIMEOUT); } /* Event function for state "wait" in state set "recovery" */ static seqBool seqg_event_recovery_0_wait(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 94 "../sncLlrfInterlock.stt" if (seqg_var->mode == BYPASS) { *seqg_pnst = 0; *seqg_ptrn = 0; return TRUE; } # line 96 "../sncLlrfInterlock.stt" if (seqg_var->fault_out == FAULT || seqg_var->mod_status == HVOFF) { *seqg_pnst = 1; *seqg_ptrn = 1; return TRUE; } return FALSE; } /* Action function for state "wait" in state set "recovery" */ static void seqg_action_recovery_0_wait(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { # line 97 "../sncLlrfInterlock.stt" seqg_var->trig_control = TRIG_STDBYONLY; # line 98 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 8/*trig_control*/, DEFAULT, DEFAULT_TIMEOUT); # line 100 "../sncLlrfInterlock.stt" seq_pvGetTmo(seqg_env, 9/*corrscale_control*/, DEFAULT, DEFAULT_TIMEOUT); # line 101 "../sncLlrfInterlock.stt" seqg_var->stored_corrscale = seqg_var->corrscale_control; # line 102 "../sncLlrfInterlock.stt" seqg_var->corrscale_control = 0.; # line 103 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 9/*corrscale_control*/, DEFAULT, DEFAULT_TIMEOUT); } return; } } /****** Code for state "fault" in state set "recovery" ******/ /* Entry function for state "fault" in state set "recovery" */ static void seqg_entry_recovery_0_fault(SS_ID seqg_env) { # line 115 "../sncLlrfInterlock.stt" seqg_var->status1 = STATUS1_FAULT; # line 116 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 1/*status1*/, DEFAULT, DEFAULT_TIMEOUT); # line 117 "../sncLlrfInterlock.stt" seqg_var->trig_control = TRIG_STDBYONLY; # line 118 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 8/*trig_control*/, DEFAULT, DEFAULT_TIMEOUT); # line 119 "../sncLlrfInterlock.stt" seqg_var->corrscale_control = 0.; # line 120 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 9/*corrscale_control*/, DEFAULT, DEFAULT_TIMEOUT); } /* Event function for state "fault" in state set "recovery" */ static seqBool seqg_event_recovery_0_fault(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 122 "../sncLlrfInterlock.stt" if (seqg_var->reset == RESET) { *seqg_pnst = 0; *seqg_ptrn = 0; return TRUE; } # line 123 "../sncLlrfInterlock.stt" if (seqg_var->mode == BYPASS) { *seqg_pnst = 0; *seqg_ptrn = 1; return TRUE; } # line 124 "../sncLlrfInterlock.stt" if (seqg_var->mode == MANUAL) { *seqg_pnst = 1; *seqg_ptrn = 2; return TRUE; } # line 126 "../sncLlrfInterlock.stt" if (seqg_var->mod_status == HVON) { *seqg_pnst = 2; *seqg_ptrn = 3; return TRUE; } return FALSE; } /* Action function for state "fault" in state set "recovery" */ static void seqg_action_recovery_0_fault(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { } return; case 2: { } return; case 3: { # line 127 "../sncLlrfInterlock.stt" seqg_var->fault_clear = 1; # line 128 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 7/*fault_clear*/, DEFAULT, DEFAULT_TIMEOUT); epicsThreadSleep(1.); # line 130 "../sncLlrfInterlock.stt" seqg_var->fault_clear = 0; # line 131 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 7/*fault_clear*/, DEFAULT, DEFAULT_TIMEOUT); } return; } } /****** Code for state "ramp" in state set "recovery" ******/ /* Entry function for state "ramp" in state set "recovery" */ static void seqg_entry_recovery_0_ramp(SS_ID seqg_env) { # line 142 "../sncLlrfInterlock.stt" seqg_var->status1 = STATUS1_RAMPUP; # line 143 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 1/*status1*/, DEFAULT, DEFAULT_TIMEOUT); # line 144 "../sncLlrfInterlock.stt" seqg_var->ramp_up = RAMP_UP; # line 145 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 5/*ramp_up*/, DEFAULT, DEFAULT_TIMEOUT); } /* Event function for state "ramp" in state set "recovery" */ static seqBool seqg_event_recovery_0_ramp(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 148 "../sncLlrfInterlock.stt" if (seqg_var->reset == RESET) { *seqg_pnst = 0; *seqg_ptrn = 0; return TRUE; } # line 149 "../sncLlrfInterlock.stt" if (seqg_var->mode == BYPASS) { *seqg_pnst = 0; *seqg_ptrn = 1; return TRUE; } # line 150 "../sncLlrfInterlock.stt" if (seqg_var->fault_out == FAULT || seqg_var->mod_status == HVOFF) { *seqg_pnst = 1; *seqg_ptrn = 2; return TRUE; } # line 155 "../sncLlrfInterlock.stt" if (seqg_var->corrscale_control >= seqg_var->stored_corrscale) { *seqg_pnst = 0; *seqg_ptrn = 3; return TRUE; } # line 168 "../sncLlrfInterlock.stt" if (seqg_var->fault_out == NOFAULT) { *seqg_pnst = 2; *seqg_ptrn = 4; return TRUE; } return FALSE; } /* Action function for state "ramp" in state set "recovery" */ static void seqg_action_recovery_0_ramp(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { } return; case 2: { # line 151 "../sncLlrfInterlock.stt" seqg_var->ramp_up = RAMP_STOP; # line 152 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 5/*ramp_up*/, DEFAULT, DEFAULT_TIMEOUT); } return; case 3: { # line 156 "../sncLlrfInterlock.stt" if (seqg_var->final_mode == FINALMODE_STANDBY) { # line 157 "../sncLlrfInterlock.stt" seqg_var->trig_control = TRIG_STDBYONLY; # line 158 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 8/*trig_control*/, DEFAULT, DEFAULT_TIMEOUT); } # line 161 "../sncLlrfInterlock.stt" if (seqg_var->final_mode == FINALMODE_ACCELERATE1 || seqg_var->final_mode == FINALMODE_ACCELERATE2) { # line 162 "../sncLlrfInterlock.stt" seqg_var->trig_control = TRIG_NORMALOP; # line 163 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 8/*trig_control*/, DEFAULT, DEFAULT_TIMEOUT); } } return; case 4: { } return; } } /****** Code for state "wait" in state set "rampup" ******/ /* Entry function for state "wait" in state set "rampup" */ static void seqg_entry_rampup_1_wait(SS_ID seqg_env) { # line 182 "../sncLlrfInterlock.stt" seqg_var->status2 = STATUS2_WAIT; # line 183 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 2/*status2*/, DEFAULT, DEFAULT_TIMEOUT); } /* Event function for state "wait" in state set "rampup" */ static seqBool seqg_event_rampup_1_wait(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 186 "../sncLlrfInterlock.stt" if (seqg_var->mode == BYPASS) { *seqg_pnst = 0; *seqg_ptrn = 0; return TRUE; } # line 188 "../sncLlrfInterlock.stt" if (seqg_var->ramp_up == RAMP_UP) { *seqg_pnst = 1; *seqg_ptrn = 1; return TRUE; } return FALSE; } /* Action function for state "wait" in state set "rampup" */ static void seqg_action_rampup_1_wait(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { } return; } } /****** Code for state "ramp" in state set "rampup" ******/ /* Entry function for state "ramp" in state set "rampup" */ static void seqg_entry_rampup_1_ramp(SS_ID seqg_env) { # line 196 "../sncLlrfInterlock.stt" seqg_var->status2 = STATUS2_RAMPUP; # line 197 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 2/*status2*/, DEFAULT, DEFAULT_TIMEOUT); } /* Event function for state "ramp" in state set "rampup" */ static seqBool seqg_event_rampup_1_ramp(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 200 "../sncLlrfInterlock.stt" if (seqg_var->reset == RESET) { *seqg_pnst = 0; *seqg_ptrn = 0; return TRUE; } # line 201 "../sncLlrfInterlock.stt" if (seqg_var->mode == BYPASS) { *seqg_pnst = 0; *seqg_ptrn = 1; return TRUE; } # line 202 "../sncLlrfInterlock.stt" if (seqg_var->ramp_up == RAMP_STOP) { *seqg_pnst = 0; *seqg_ptrn = 2; return TRUE; } # line 204 "../sncLlrfInterlock.stt" if (seqg_var->corrscale_control >= seqg_var->stored_corrscale) { *seqg_pnst = 0; *seqg_ptrn = 3; return TRUE; } # line 209 "../sncLlrfInterlock.stt" if (seq_delay(seqg_env, seqg_var->ramp_time / 10.)) { *seqg_pnst = 1; *seqg_ptrn = 4; return TRUE; } return FALSE; } /* Action function for state "ramp" in state set "rampup" */ static void seqg_action_rampup_1_ramp(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { } return; case 2: { } return; case 3: { # line 205 "../sncLlrfInterlock.stt" seqg_var->ramp_up = RAMP_DONE; # line 206 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 5/*ramp_up*/, DEFAULT, DEFAULT_TIMEOUT); } return; case 4: { # line 210 "../sncLlrfInterlock.stt" seqg_var->corrscale_control += (seqg_var->stored_corrscale / 10.); # line 211 "../sncLlrfInterlock.stt" if (seqg_var->corrscale_control >= seqg_var->stored_corrscale) # line 211 "../sncLlrfInterlock.stt" seqg_var->corrscale_control = seqg_var->stored_corrscale; # line 212 "../sncLlrfInterlock.stt" seq_pvPutTmo(seqg_env, 9/*corrscale_control*/, DEFAULT, DEFAULT_TIMEOUT); } return; } } #undef seqg_var /************************ Tables ************************/ /* Channel table */ static seqChan seqg_chans[] = { /* chName, offset, varName, varType, count, eventNum, efId, monitored, queueSize, queueIndex */ {"{PRIMARY}:{MICRO}:{UNIT}:FAULTSEQ:RESET", offsetof(struct seqg_vars, reset), "reset", P_INT, 1, 1, 0, 1, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:FAULTSEQ:STATUS1", offsetof(struct seqg_vars, status1), "status1", P_INT, 1, 2, 0, 0, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:FAULTSEQ:STATUS2", offsetof(struct seqg_vars, status2), "status2", P_INT, 1, 3, 0, 0, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:FAULTSEQ:MODE", offsetof(struct seqg_vars, mode), "mode", P_INT, 1, 4, 0, 1, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:FAULTSEQ:RAMPTIME", offsetof(struct seqg_vars, ramp_time), "ramp_time", P_DOUBLE, 1, 5, 0, 1, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:FAULTSEQ:RAMPUP", offsetof(struct seqg_vars, ramp_up), "ramp_up", P_INT, 1, 6, 0, 1, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:RTM:FAULTOUT", offsetof(struct seqg_vars, fault_out), "fault_out", P_INT, 1, 7, 0, 1, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:RTM:CLEARFAULT", offsetof(struct seqg_vars, fault_clear), "fault_clear", P_INT, 1, 8, 0, 0, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:TRIGMODE", offsetof(struct seqg_vars, trig_control), "trig_control", P_INT, 1, 9, 0, 0, 0, 0}, {"{PRIMARY}:{MICRO}:{UNIT}:CORRSCALE", offsetof(struct seqg_vars, corrscale_control), "corrscale_control", P_DOUBLE, 1, 10, 0, 0, 0, 0}, {"{MODFAULT}", offsetof(struct seqg_vars, mod_status), "mod_status", P_INT, 1, 11, 0, 1, 0, 0}, {"{FINAL_MODE}", offsetof(struct seqg_vars, final_mode), "final_mode", P_INT, 1, 12, 0, 1, 0, 0}, }; /* Event masks for state set "recovery" */ static const seqMask seqg_mask_recovery_0_wait[] = { 0x00000890, }; static const seqMask seqg_mask_recovery_0_fault[] = { 0x00000812, }; static const seqMask seqg_mask_recovery_0_ramp[] = { 0x00000c92, }; /* State table for state set "recovery" */ static seqState seqg_states_recovery[] = { { /* state name */ "wait", /* action function */ seqg_action_recovery_0_wait, /* event function */ seqg_event_recovery_0_wait, /* entry function */ seqg_entry_recovery_0_wait, /* exit function */ 0, /* event mask array */ seqg_mask_recovery_0_wait, /* state options */ (0) }, { /* state name */ "fault", /* action function */ seqg_action_recovery_0_fault, /* event function */ seqg_event_recovery_0_fault, /* entry function */ seqg_entry_recovery_0_fault, /* exit function */ 0, /* event mask array */ seqg_mask_recovery_0_fault, /* state options */ (0) }, { /* state name */ "ramp", /* action function */ seqg_action_recovery_0_ramp, /* event function */ seqg_event_recovery_0_ramp, /* entry function */ seqg_entry_recovery_0_ramp, /* exit function */ 0, /* event mask array */ seqg_mask_recovery_0_ramp, /* state options */ (0) }, }; /* Event masks for state set "rampup" */ static const seqMask seqg_mask_rampup_1_wait[] = { 0x00000050, }; static const seqMask seqg_mask_rampup_1_ramp[] = { 0x00000472, }; /* State table for state set "rampup" */ static seqState seqg_states_rampup[] = { { /* state name */ "wait", /* action function */ seqg_action_rampup_1_wait, /* event function */ seqg_event_rampup_1_wait, /* entry function */ seqg_entry_rampup_1_wait, /* exit function */ 0, /* event mask array */ seqg_mask_rampup_1_wait, /* state options */ (0) }, { /* state name */ "ramp", /* action function */ seqg_action_rampup_1_ramp, /* event function */ seqg_event_rampup_1_ramp, /* entry function */ seqg_entry_rampup_1_ramp, /* exit function */ 0, /* event mask array */ seqg_mask_rampup_1_ramp, /* state options */ (0) }, }; /* State set table */ static seqSS seqg_statesets[] = { { /* state set name */ "recovery", /* states */ seqg_states_recovery, /* number of states */ 3 }, { /* state set name */ "rampup", /* states */ seqg_states_rampup, /* number of states */ 2 }, }; /* Program table (global) */ seqProgram mrLlrfInterlock = { /* magic number */ 2002004, /* program name */ "mrLlrfInterlock", /* channels */ seqg_chans, /* num. channels */ 12, /* state sets */ seqg_statesets, /* num. state sets */ 2, /* user var size */ sizeof(struct seqg_vars), /* param */ "", /* num. event flags */ 0, /* encoded options */ (0 | OPT_CONN | OPT_NEWEF | OPT_REENT), /* init func */ seqg_init, /* entry func */ 0, /* exit func */ 0, /* num. queues */ 0 }; /* Register sequencer commands and program */ #include "epicsExport.h" static void mrLlrfInterlockRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&mrLlrfInterlock); } epicsExportRegistrar(mrLlrfInterlockRegistrar);