/* Generated with snc from ../sncLlrfInterlock.stt */ /* Program "mrLlrfInterlock" */ #include #include #include #include #include "epicsTypes.h" #include "seqCom.h" /* Variable declarations */ struct UserVar { # 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; }; /* C code definitions */ # 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 /* Program init func */ static void G_prog_init(struct UserVar *pVar) { static struct UserVar pVarInit = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; *pVar = pVarInit; } /****** Code for state "wait" in state set "recovery" ******/ /* Entry function for state "wait" in state set "recovery" */ static void I_recovery_wait(SS_ID ssId, struct UserVar *pVar) { # line 90 "../sncLlrfInterlock.stt" pVar->status1 = STATUS1_WAIT; # line 91 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 1/*status1*/, 0); } /* Delay function for state "wait" in state set "recovery" */ static void D_recovery_wait(SS_ID ssId, struct UserVar *pVar) { } /* Event function for state "wait" in state set "recovery" */ static seqBool E_recovery_wait(SS_ID ssId, struct UserVar *pVar, int *pTransNum, int *pNextState) { # line 94 "../sncLlrfInterlock.stt" if (pVar->mode == BYPASS) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 96 "../sncLlrfInterlock.stt" if (pVar->fault_out == FAULT || pVar->mod_status == HVOFF) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "wait" in state set "recovery" */ static void A_recovery_wait(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { } return; case 1: { # line 97 "../sncLlrfInterlock.stt" pVar->trig_control = TRIG_STDBYONLY; # line 98 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 8/*trig_control*/, 0); # line 100 "../sncLlrfInterlock.stt" seq_pvGet(ssId, 9/*corrscale_control*/, 0); # line 101 "../sncLlrfInterlock.stt" pVar->stored_corrscale = pVar->corrscale_control; # line 102 "../sncLlrfInterlock.stt" pVar->corrscale_control = 0.; # line 103 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 9/*corrscale_control*/, 0); } return; } } /****** Code for state "fault" in state set "recovery" ******/ /* Entry function for state "fault" in state set "recovery" */ static void I_recovery_fault(SS_ID ssId, struct UserVar *pVar) { # line 115 "../sncLlrfInterlock.stt" pVar->status1 = STATUS1_FAULT; # line 116 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 1/*status1*/, 0); # line 117 "../sncLlrfInterlock.stt" pVar->trig_control = TRIG_STDBYONLY; # line 118 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 8/*trig_control*/, 0); # line 119 "../sncLlrfInterlock.stt" pVar->corrscale_control = 0.; # line 120 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 9/*corrscale_control*/, 0); } /* Delay function for state "fault" in state set "recovery" */ static void D_recovery_fault(SS_ID ssId, struct UserVar *pVar) { } /* Event function for state "fault" in state set "recovery" */ static seqBool E_recovery_fault(SS_ID ssId, struct UserVar *pVar, int *pTransNum, int *pNextState) { # line 122 "../sncLlrfInterlock.stt" if (pVar->reset == RESET) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 123 "../sncLlrfInterlock.stt" if (pVar->mode == BYPASS) { *pNextState = 0; *pTransNum = 1; return TRUE; } # line 124 "../sncLlrfInterlock.stt" if (pVar->mode == MANUAL) { *pNextState = 1; *pTransNum = 2; return TRUE; } # line 126 "../sncLlrfInterlock.stt" if (pVar->mod_status == HVON) { *pNextState = 2; *pTransNum = 3; return TRUE; } return FALSE; } /* Action function for state "fault" in state set "recovery" */ static void A_recovery_fault(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { } return; case 1: { } return; case 2: { } return; case 3: { # line 127 "../sncLlrfInterlock.stt" pVar->fault_clear = 1; # line 128 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 7/*fault_clear*/, 0); epicsThreadSleep(1.); # line 130 "../sncLlrfInterlock.stt" pVar->fault_clear = 0; # line 131 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 7/*fault_clear*/, 0); } return; } } /****** Code for state "ramp" in state set "recovery" ******/ /* Entry function for state "ramp" in state set "recovery" */ static void I_recovery_ramp(SS_ID ssId, struct UserVar *pVar) { # line 142 "../sncLlrfInterlock.stt" pVar->status1 = STATUS1_RAMPUP; # line 143 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 1/*status1*/, 0); # line 144 "../sncLlrfInterlock.stt" pVar->ramp_up = RAMP_UP; # line 145 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 5/*ramp_up*/, 0); } /* Delay function for state "ramp" in state set "recovery" */ static void D_recovery_ramp(SS_ID ssId, struct UserVar *pVar) { } /* Event function for state "ramp" in state set "recovery" */ static seqBool E_recovery_ramp(SS_ID ssId, struct UserVar *pVar, int *pTransNum, int *pNextState) { # line 148 "../sncLlrfInterlock.stt" if (pVar->reset == RESET) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 149 "../sncLlrfInterlock.stt" if (pVar->mode == BYPASS) { *pNextState = 0; *pTransNum = 1; return TRUE; } # line 150 "../sncLlrfInterlock.stt" if (pVar->fault_out == FAULT || pVar->mod_status == HVOFF) { *pNextState = 1; *pTransNum = 2; return TRUE; } # line 155 "../sncLlrfInterlock.stt" if (pVar->corrscale_control >= pVar->stored_corrscale) { *pNextState = 0; *pTransNum = 3; return TRUE; } # line 168 "../sncLlrfInterlock.stt" if (pVar->fault_out == NOFAULT) { *pNextState = 2; *pTransNum = 4; return TRUE; } return FALSE; } /* Action function for state "ramp" in state set "recovery" */ static void A_recovery_ramp(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { } return; case 1: { } return; case 2: { # line 151 "../sncLlrfInterlock.stt" pVar->ramp_up = RAMP_STOP; # line 152 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 5/*ramp_up*/, 0); } return; case 3: { # line 156 "../sncLlrfInterlock.stt" if (pVar->final_mode == FINALMODE_STANDBY) { # line 157 "../sncLlrfInterlock.stt" pVar->trig_control = TRIG_STDBYONLY; # line 158 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 8/*trig_control*/, 0); } # line 161 "../sncLlrfInterlock.stt" if (pVar->final_mode == FINALMODE_ACCELERATE1 || pVar->final_mode == FINALMODE_ACCELERATE2) { # line 162 "../sncLlrfInterlock.stt" pVar->trig_control = TRIG_NORMALOP; # line 163 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 8/*trig_control*/, 0); } } return; case 4: { } return; } } /****** Code for state "wait" in state set "rampup" ******/ /* Entry function for state "wait" in state set "rampup" */ static void I_rampup_wait(SS_ID ssId, struct UserVar *pVar) { # line 182 "../sncLlrfInterlock.stt" pVar->status2 = STATUS2_WAIT; # line 183 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 2/*status2*/, 0); } /* Delay function for state "wait" in state set "rampup" */ static void D_rampup_wait(SS_ID ssId, struct UserVar *pVar) { } /* Event function for state "wait" in state set "rampup" */ static seqBool E_rampup_wait(SS_ID ssId, struct UserVar *pVar, int *pTransNum, int *pNextState) { # line 186 "../sncLlrfInterlock.stt" if (pVar->mode == BYPASS) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 188 "../sncLlrfInterlock.stt" if (pVar->ramp_up == RAMP_UP) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "wait" in state set "rampup" */ static void A_rampup_wait(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { 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 I_rampup_ramp(SS_ID ssId, struct UserVar *pVar) { # line 196 "../sncLlrfInterlock.stt" pVar->status2 = STATUS2_RAMPUP; # line 197 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 2/*status2*/, 0); } /* Delay function for state "ramp" in state set "rampup" */ static void D_rampup_ramp(SS_ID ssId, struct UserVar *pVar) { # line 209 "../sncLlrfInterlock.stt" seq_delayInit(ssId, 0, (pVar->ramp_time / 10.)); } /* Event function for state "ramp" in state set "rampup" */ static seqBool E_rampup_ramp(SS_ID ssId, struct UserVar *pVar, int *pTransNum, int *pNextState) { # line 200 "../sncLlrfInterlock.stt" if (pVar->reset == RESET) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 201 "../sncLlrfInterlock.stt" if (pVar->mode == BYPASS) { *pNextState = 0; *pTransNum = 1; return TRUE; } # line 202 "../sncLlrfInterlock.stt" if (pVar->ramp_up == RAMP_STOP) { *pNextState = 0; *pTransNum = 2; return TRUE; } # line 204 "../sncLlrfInterlock.stt" if (pVar->corrscale_control >= pVar->stored_corrscale) { *pNextState = 0; *pTransNum = 3; return TRUE; } # line 209 "../sncLlrfInterlock.stt" if (seq_delay(ssId, 0)) { *pNextState = 1; *pTransNum = 4; return TRUE; } return FALSE; } /* Action function for state "ramp" in state set "rampup" */ static void A_rampup_ramp(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { } return; case 1: { } return; case 2: { } return; case 3: { # line 205 "../sncLlrfInterlock.stt" pVar->ramp_up = RAMP_DONE; # line 206 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 5/*ramp_up*/, 0); } return; case 4: { # line 210 "../sncLlrfInterlock.stt" pVar->corrscale_control += (pVar->stored_corrscale / 10.); # line 211 "../sncLlrfInterlock.stt" if (pVar->corrscale_control >= pVar->stored_corrscale) # line 211 "../sncLlrfInterlock.stt" pVar->corrscale_control = pVar->stored_corrscale; # line 212 "../sncLlrfInterlock.stt" seq_pvPut(ssId, 9/*corrscale_control*/, 0); } return; } } /************************ Tables ************************/ /* Channel table */ static seqChan G_channels[] = { /* chName, offset, varName, varType, count, eventNum, efId, monitored, queueSize, queueIndex */ {"{DEVICE}:FAULTSEQ:RESET", offsetof(struct UserVar, reset), "reset", "int", 1, 1, 0, 1, 0, 0}, {"{DEVICE}:FAULTSEQ:STATUS1", offsetof(struct UserVar, status1), "status1", "int", 1, 2, 0, 0, 0, 0}, {"{DEVICE}:FAULTSEQ:STATUS2", offsetof(struct UserVar, status2), "status2", "int", 1, 3, 0, 0, 0, 0}, {"{DEVICE}:FAULTSEQ:MODE", offsetof(struct UserVar, mode), "mode", "int", 1, 4, 0, 1, 0, 0}, {"{DEVICE}:FAULTSEQ:RAMPTIME", offsetof(struct UserVar, ramp_time), "ramp_time", "double", 1, 5, 0, 1, 0, 0}, {"{DEVICE}:FAULTSEQ:RAMPUP", offsetof(struct UserVar, ramp_up), "ramp_up", "int", 1, 6, 0, 1, 0, 0}, {"{RTMFAULT}", offsetof(struct UserVar, fault_out), "fault_out", "int", 1, 7, 0, 1, 0, 0}, {"{DEVICE}:RTM:CLEARFAULT", offsetof(struct UserVar, fault_clear), "fault_clear", "int", 1, 8, 0, 0, 0, 0}, {"{DEVICE}:TRIGMODE", offsetof(struct UserVar, trig_control), "trig_control", "int", 1, 9, 0, 0, 0, 0}, {"{DEVICE}:CORRSCALE", offsetof(struct UserVar, corrscale_control), "corrscale_control", "double", 1, 10, 0, 0, 0, 0}, {"{MODFAULT}", offsetof(struct UserVar, mod_status), "mod_status", "int", 1, 11, 0, 1, 0, 0}, {"{FINAL_MODE}", offsetof(struct UserVar, final_mode), "final_mode", "int", 1, 12, 0, 1, 0, 0} }; /* Event masks for state set "recovery" */ static const seqMask EM_recovery_wait[] = { 0x00000890, }; static const seqMask EM_recovery_fault[] = { 0x00000812, }; static const seqMask EM_recovery_ramp[] = { 0x00000c92, }; /* State table for state set "recovery" */ static seqState G_recovery_states[] = { { /* state name */ "wait", /* action function */ A_recovery_wait, /* event function */ E_recovery_wait, /* delay function */ D_recovery_wait, /* entry function */ I_recovery_wait, /* exit function */ 0, /* event mask array */ EM_recovery_wait, /* state options */ (0) }, { /* state name */ "fault", /* action function */ A_recovery_fault, /* event function */ E_recovery_fault, /* delay function */ D_recovery_fault, /* entry function */ I_recovery_fault, /* exit function */ 0, /* event mask array */ EM_recovery_fault, /* state options */ (0) }, { /* state name */ "ramp", /* action function */ A_recovery_ramp, /* event function */ E_recovery_ramp, /* delay function */ D_recovery_ramp, /* entry function */ I_recovery_ramp, /* exit function */ 0, /* event mask array */ EM_recovery_ramp, /* state options */ (0) }, }; /* Event masks for state set "rampup" */ static const seqMask EM_rampup_wait[] = { 0x00000050, }; static const seqMask EM_rampup_ramp[] = { 0x00000472, }; /* State table for state set "rampup" */ static seqState G_rampup_states[] = { { /* state name */ "wait", /* action function */ A_rampup_wait, /* event function */ E_rampup_wait, /* delay function */ D_rampup_wait, /* entry function */ I_rampup_wait, /* exit function */ 0, /* event mask array */ EM_rampup_wait, /* state options */ (0) }, { /* state name */ "ramp", /* action function */ A_rampup_ramp, /* event function */ E_rampup_ramp, /* delay function */ D_rampup_ramp, /* entry function */ I_rampup_ramp, /* exit function */ 0, /* event mask array */ EM_rampup_ramp, /* state options */ (0) }, }; /* State set table */ static seqSS G_state_sets[] = { { /* state set name */ "recovery", /* states */ G_recovery_states, /* number of states */ 3, /* number of delays */ 0 }, { /* state set name */ "rampup", /* states */ G_rampup_states, /* number of states */ 2, /* number of delays */ 1 }, }; /* Program table (global) */ seqProgram mrLlrfInterlock = { /* magic number */ 2001006, /* program name */ "mrLlrfInterlock", /* channels */ G_channels, /* num. channels */ 12, /* state sets */ G_state_sets, /* num. state sets */ 2, /* user var size */ sizeof(struct UserVar), /* param */ "", /* num. event flags */ 0, /* encoded options */ (0 | OPT_CONN | OPT_NEWEF | OPT_REENT), /* init func */ G_prog_init, /* entry func */ NULL, /* exit func */ NULL, /* num. queues */ 0 }; /* Register sequencer commands and program */ #include "epicsExport.h" static void mrLlrfInterlockRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&mrLlrfInterlock); } epicsExportRegistrar(mrLlrfInterlockRegistrar);