/* SNC Version 2.0.11: Fri May 27 10:07:33 2011: sncTds3x.i */ /* Event flags */ #define chRdFlg 1 #define acqEv 2 #define clrREv 3 #define setpEv 4 #define rstrEv 5 /* Program "sncTds3x" */ #include "seqCom.h" #define NUM_SS 4 #define NUM_CHANNELS 24 #define NUM_EVENTS 5 #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 sncTds3x; /* Variable declarations */ static short dochan[4]; static short chanrd[4]; static short chanwt[4]; static short acqur; static short clrR; static short ops; static short cts; static int busy[4]; static char spath[128]; static char setup[4000]; static short rstor; static char wfRst[4000]; static int count = 0; static int i; static int j; static int chRdOld[4]; static int flg1[4]; static int flg2[4]; static char *fname; /* Not used (avoids compilation warnings) */ struct UserVar { int dummy; }; /* C code definitions */ # line 6 "../sncTds3x.st" #include # line 7 "../sncTds3x.st" #include # line 46 "../sncTds3x.st" # line 47 "../sncTds3x.st" static int rdFile( char* msg,char* fn){ # line 48 "../sncTds3x.st" # line 49 "../sncTds3x.st" # line 50 "../sncTds3x.st" # line 51 "../sncTds3x.st" FILE* fd; char str[32]; # line 52 "../sncTds3x.st" # line 53 "../sncTds3x.st" strcpy( str,msg); strcat( str,":rdFile"); # line 54 "../sncTds3x.st" fd=fopen( fn,"r"); # line 55 "../sncTds3x.st" if(!fd) printf( "%s:rdFile: failed to open %s\n",msg,fn); # line 56 "../sncTds3x.st" else{ # line 57 "../sncTds3x.st" printf( "%s:rdFile:opened %s\n",msg,fn); # line 58 "../sncTds3x.st" fgets( wfRst,4000 -1,fd); wfRst[4000 -1]=0; # line 59 "../sncTds3x.st" printf( "sncTds3x:rdFile:strlen(wfRst)=%d\n",strlen(wfRst)); # line 60 "../sncTds3x.st" if(ferror( fd)){ perror( str); return(-1);} # line 61 "../sncTds3x.st" } # line 62 "../sncTds3x.st" return(0); # line 63 "../sncTds3x.st" } # line 64 "../sncTds3x.st" static void wtFile( char* msg,char* fn){ # line 65 "../sncTds3x.st" # line 66 "../sncTds3x.st" # line 67 "../sncTds3x.st" # line 68 "../sncTds3x.st" FILE* fd; int stat; # line 69 "../sncTds3x.st" # line 70 "../sncTds3x.st" fd=fopen( fn,"w"); # line 71 "../sncTds3x.st" if(!fd) printf( "%s:wtFile: failed to open %s\n",msg,fn); # line 72 "../sncTds3x.st" else{ # line 73 "../sncTds3x.st" setup[4000 -1]=0; # line 74 "../sncTds3x.st" stat=fputs( setup,fd); # line 75 "../sncTds3x.st" if(stat==EOF) printf( "%s:wtFile:fputs: failed to write\n",msg); # line 76 "../sncTds3x.st" else printf( "%s:wtFile: wrote to %s\n",msg,fn); # line 77 "../sncTds3x.st" fclose( fd); # line 78 "../sncTds3x.st" } # line 79 "../sncTds3x.st" } # line 79 "../sncTds3x.st" /* Entry handler */ static void entry_handler(SS_ID ssId, struct UserVar *pVar) { } /* Code for state "init" in state set "savRest" */ /* Delay function for state "init" in state set "savRest" */ static void D_savRest_init(SS_ID ssId, struct UserVar *pVar) { # line 91 "../sncTds3x.st" } /* Event function for state "init" in state set "savRest" */ static long E_savRest_init(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 91 "../sncTds3x.st" if (1) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "savRest" */ static void A_savRest_init(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 84 "../sncTds3x.st" fname = seq_macValueGet(ssId, "FN"); # line 86 "../sncTds3x.st" strncpy( spath,fname,128 -1); # line 86 "../sncTds3x.st" spath[128 - 1] = 0; seq_pvPut(ssId, 20 /* spath */, 0); seq_efClear(ssId, setpEv); seq_efClear(ssId, rstrEv); printf("sncTds3x:savRest: file path initialized\n"); } return; } } /* Code for state "save" in state set "savRest" */ /* Delay function for state "save" in state set "savRest" */ static void D_savRest_save(SS_ID ssId, struct UserVar *pVar) { # line 96 "../sncTds3x.st" # line 97 "../sncTds3x.st" seq_delayInit(ssId, 0, (0.1)); } /* Event function for state "save" in state set "savRest" */ static long E_savRest_save(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 96 "../sncTds3x.st" if (seq_efTestAndClear(ssId, setpEv)) { *pNextState = 2; *pTransNum = 0; return TRUE; } # line 97 "../sncTds3x.st" if (seq_delay(ssId, 0)) { *pNextState = 2; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "save" in state set "savRest" */ static void A_savRest_save(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 95 "../sncTds3x.st" wtFile("sncTds3x", spath); } return; case 1: { } return; } } /* Code for state "restore" in state set "savRest" */ /* Delay function for state "restore" in state set "savRest" */ static void D_savRest_restore(SS_ID ssId, struct UserVar *pVar) { # line 102 "../sncTds3x.st" # line 103 "../sncTds3x.st" seq_delayInit(ssId, 0, (0.5)); } /* Event function for state "restore" in state set "savRest" */ static long E_savRest_restore(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 102 "../sncTds3x.st" if (seq_efTestAndClear(ssId, rstrEv)) { *pNextState = 1; *pTransNum = 0; return TRUE; } # line 103 "../sncTds3x.st" if (seq_delay(ssId, 0)) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "restore" in state set "savRest" */ static void A_savRest_restore(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 101 "../sncTds3x.st" if (!rdFile("sncTds3x", spath)) seq_pvPut(ssId, 23 /* wfRst */, 0); } return; case 1: { } return; } } /* Code for state "init" in state set "acquire" */ /* Delay function for state "init" in state set "acquire" */ static void D_acquire_init(SS_ID ssId, struct UserVar *pVar) { # line 118 "../sncTds3x.st" } /* Event function for state "init" in state set "acquire" */ static long E_acquire_init(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 118 "../sncTds3x.st" if (1) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "acquire" */ static void A_acquire_init(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 116 "../sncTds3x.st" for (i = 0; i < 4; i++) { flg1[i] = flg2[i] = 0; busy[i] = 0; seq_pvPut(ssId, 16 /* busy */ + (0), 0); } # line 117 "../sncTds3x.st" printf("sncTds3x:acquire:init\n"); } return; } } /* Code for state "doIt" in state set "acquire" */ /* Delay function for state "doIt" in state set "acquire" */ static void D_acquire_doIt(SS_ID ssId, struct UserVar *pVar) { # line 144 "../sncTds3x.st" # line 145 "../sncTds3x.st" seq_delayInit(ssId, 0, (0.05)); } /* Event function for state "doIt" in state set "acquire" */ static long E_acquire_doIt(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 144 "../sncTds3x.st" if (seq_efTestAndClear(ssId, acqEv)) { *pNextState = 1; *pTransNum = 0; return TRUE; } # line 145 "../sncTds3x.st" if (seq_delay(ssId, 0)) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "doIt" in state set "acquire" */ static void A_acquire_doIt(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 129 "../sncTds3x.st" for (i = 0; i < 4; i++) { if (chanrd[count]) { flg1[count] = 1; break; } else if (flg2[count]) break; if ((++count) >= 4) count = 0; } # line 130 "../sncTds3x.st" seq_pvGet(ssId, 16 /* busy */ + (count), 0); # line 142 "../sncTds3x.st" if (!busy[count]) { if (flg1[count] || flg2[count]) { busy[count] = 1; seq_pvPut(ssId, 16 /* busy */ + (count), 0); dochan[count] = 1; seq_pvPut(ssId, 0 /* dochan */ + (count), 0); } if (flg1[count]) { flg1[count] = 0; flg2[count] = 1; } else if (flg2[count]) flg2[count] = 0; } # line 143 "../sncTds3x.st" if ((++count) >= 4) count = 0; } return; case 1: { } return; } } /* Code for state "chkChanInit" in state set "chkChan" */ /* Delay function for state "chkChanInit" in state set "chkChan" */ static void D_chkChan_chkChanInit(SS_ID ssId, struct UserVar *pVar) { # line 159 "../sncTds3x.st" } /* Event function for state "chkChanInit" in state set "chkChan" */ static long E_chkChan_chkChanInit(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 159 "../sncTds3x.st" if (1) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "chkChanInit" in state set "chkChan" */ static void A_chkChan_chkChanInit(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 158 "../sncTds3x.st" for (j = 0; j < 4; j++) { seq_pvGet(ssId, 4 /* chanrd */ + (j), 0); if (chanrd[j]) { chanwt[j] = 1; seq_pvPut(ssId, 8 /* chanwt */ + (j), 0); } chRdOld[j] = chanrd[j]; } } return; } } /* Code for state "chkChanDo" in state set "chkChan" */ /* Delay function for state "chkChanDo" in state set "chkChan" */ static void D_chkChan_chkChanDo(SS_ID ssId, struct UserVar *pVar) { # line 170 "../sncTds3x.st" # line 171 "../sncTds3x.st" seq_delayInit(ssId, 0, (0.05)); } /* Event function for state "chkChanDo" in state set "chkChan" */ static long E_chkChan_chkChanDo(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 170 "../sncTds3x.st" if (seq_efTestAndClear(ssId, chRdFlg)) { *pNextState = 1; *pTransNum = 0; return TRUE; } # line 171 "../sncTds3x.st" if (seq_delay(ssId, 0)) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "chkChanDo" in state set "chkChan" */ static void A_chkChan_chkChanDo(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 169 "../sncTds3x.st" for (j = 0; j < 4; j++) { if (chanrd[j] != chRdOld[j]) { chanwt[j] = chanrd[j]; seq_pvPut(ssId, 8 /* chanwt */ + (j), 0); chRdOld[j] = chanrd[j]; } } } return; case 1: { } return; } } /* Code for state "doClr" in state set "doRate" */ /* Delay function for state "doClr" in state set "doRate" */ static void D_doRate_doClr(SS_ID ssId, struct UserVar *pVar) { # line 181 "../sncTds3x.st" # line 182 "../sncTds3x.st" seq_delayInit(ssId, 0, (0.5)); } /* Event function for state "doClr" in state set "doRate" */ static long E_doRate_doClr(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 181 "../sncTds3x.st" if (seq_efTestAndClear(ssId, clrREv)) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 182 "../sncTds3x.st" if (seq_delay(ssId, 0)) { *pNextState = 0; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "doClr" in state set "doRate" */ static void A_doRate_doClr(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 179 "../sncTds3x.st" ops = 1; # line 179 "../sncTds3x.st" seq_pvPut(ssId, 14 /* ops */, 0); cts = 1; # line 180 "../sncTds3x.st" seq_pvPut(ssId, 15 /* cts */, 0); } return; case 1: { } return; } } /* Exit handler */ static void exit_handler(SS_ID ssId, struct UserVar *pVar) { } /************************ Tables ***********************/ /* Database Blocks */ static struct seqChan seqChan[NUM_CHANNELS] = { {"{P}SQ_CH1_UPD_WF.PROC", (void *)&dochan[0], "dochan[0]", "short", 1, 6, 0, 0, 0, 0, 0}, {"{P}SQ_CH2_UPD_WF.PROC", (void *)&dochan[1], "dochan[1]", "short", 1, 7, 0, 0, 0, 0, 0}, {"{P}SQ_CH3_UPD_WF.PROC", (void *)&dochan[2], "dochan[2]", "short", 1, 8, 0, 0, 0, 0, 0}, {"{P}SQ_CH4_UPD_WF.PROC", (void *)&dochan[3], "dochan[3]", "short", 1, 9, 0, 0, 0, 0, 0}, {"{P}R_CH1_ENABLE", (void *)&chanrd[0], "chanrd[0]", "short", 1, 10, 1, 1, 0, 0, 0}, {"{P}R_CH2_ENABLE", (void *)&chanrd[1], "chanrd[1]", "short", 1, 11, 1, 1, 0, 0, 0}, {"{P}R_CH3_ENABLE", (void *)&chanrd[2], "chanrd[2]", "short", 1, 12, 1, 1, 0, 0, 0}, {"{P}R_CH4_ENABLE", (void *)&chanrd[3], "chanrd[3]", "short", 1, 13, 1, 1, 0, 0, 0}, {"{P}W_CH1_ENABLE", (void *)&chanwt[0], "chanwt[0]", "short", 1, 14, 0, 0, 0, 0, 0}, {"{P}W_CH2_ENABLE", (void *)&chanwt[1], "chanwt[1]", "short", 1, 15, 0, 0, 0, 0, 0}, {"{P}W_CH3_ENABLE", (void *)&chanwt[2], "chanwt[2]", "short", 1, 16, 0, 0, 0, 0, 0}, {"{P}W_CH4_ENABLE", (void *)&chanwt[3], "chanwt[3]", "short", 1, 17, 0, 0, 0, 0, 0}, {"{P}COUNT", (void *)&acqur, "acqur", "short", 1, 18, 2, 1, 0, 0, 0}, {"{P}CLR_RATE", (void *)&clrR, "clrR", "short", 1, 19, 3, 1, 0, 0, 0}, {"{P}1PER_SECOND.VAL", (void *)&ops, "ops", "short", 1, 20, 0, 0, 0, 0, 0}, {"{P}COUNT_GETS.VAL", (void *)&cts, "cts", "short", 1, 21, 0, 0, 0, 0, 0}, {"{P}C_CH1_BUSY.VAL", (void *)&busy[0], "busy[0]", "int", 1, 22, 0, 0, 0, 0, 0}, {"{P}C_CH2_BUSY.VAL", (void *)&busy[1], "busy[1]", "int", 1, 23, 0, 0, 0, 0, 0}, {"{P}C_CH3_BUSY.VAL", (void *)&busy[2], "busy[2]", "int", 1, 24, 0, 0, 0, 0, 0}, {"{P}C_CH4_BUSY.VAL", (void *)&busy[3], "busy[3]", "int", 1, 25, 0, 0, 0, 0, 0}, {"{P}SAV_PATH", (void *)&spath[0], "spath[0]", "char", 128, 26, 0, 1, 0, 0, 0}, {"{P}R_SETUP", (void *)&setup[0], "setup[0]", "char", 4000, 27, 4, 1, 0, 0, 0}, {"{P}RESTORE", (void *)&rstor, "rstor", "short", 1, 28, 5, 1, 0, 0, 0}, {"{P}W_SETUP", (void *)&wfRst[0], "wfRst[0]", "char", 4000, 29, 0, 0, 0, 0, 0}, }; /* Event masks for state set savRest */ /* Event mask for state init: */ static bitMask EM_savRest_init[] = { 0x00000000, }; /* Event mask for state save: */ static bitMask EM_savRest_save[] = { 0x00000010, }; /* Event mask for state restore: */ static bitMask EM_savRest_restore[] = { 0x00000020, }; /* State Blocks */ static struct seqState state_savRest[] = { /* State "init" */ { /* state name */ "init", /* action function */ (ACTION_FUNC) A_savRest_init, /* event function */ (EVENT_FUNC) E_savRest_init, /* delay function */ (DELAY_FUNC) D_savRest_init, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_savRest_init, /* state options */ (0)}, /* State "save" */ { /* state name */ "save", /* action function */ (ACTION_FUNC) A_savRest_save, /* event function */ (EVENT_FUNC) E_savRest_save, /* delay function */ (DELAY_FUNC) D_savRest_save, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_savRest_save, /* state options */ (0)}, /* State "restore" */ { /* state name */ "restore", /* action function */ (ACTION_FUNC) A_savRest_restore, /* event function */ (EVENT_FUNC) E_savRest_restore, /* delay function */ (DELAY_FUNC) D_savRest_restore, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_savRest_restore, /* state options */ (0)}, }; /* Event masks for state set acquire */ /* Event mask for state init: */ static bitMask EM_acquire_init[] = { 0x00000000, }; /* Event mask for state doIt: */ static bitMask EM_acquire_doIt[] = { 0x00000004, }; /* State Blocks */ static struct seqState state_acquire[] = { /* State "init" */ { /* state name */ "init", /* action function */ (ACTION_FUNC) A_acquire_init, /* event function */ (EVENT_FUNC) E_acquire_init, /* delay function */ (DELAY_FUNC) D_acquire_init, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_acquire_init, /* state options */ (0)}, /* State "doIt" */ { /* state name */ "doIt", /* action function */ (ACTION_FUNC) A_acquire_doIt, /* event function */ (EVENT_FUNC) E_acquire_doIt, /* delay function */ (DELAY_FUNC) D_acquire_doIt, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_acquire_doIt, /* state options */ (0)}, }; /* Event masks for state set chkChan */ /* Event mask for state chkChanInit: */ static bitMask EM_chkChan_chkChanInit[] = { 0x00000000, }; /* Event mask for state chkChanDo: */ static bitMask EM_chkChan_chkChanDo[] = { 0x00000002, }; /* State Blocks */ static struct seqState state_chkChan[] = { /* State "chkChanInit" */ { /* state name */ "chkChanInit", /* action function */ (ACTION_FUNC) A_chkChan_chkChanInit, /* event function */ (EVENT_FUNC) E_chkChan_chkChanInit, /* delay function */ (DELAY_FUNC) D_chkChan_chkChanInit, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_chkChan_chkChanInit, /* state options */ (0)}, /* State "chkChanDo" */ { /* state name */ "chkChanDo", /* action function */ (ACTION_FUNC) A_chkChan_chkChanDo, /* event function */ (EVENT_FUNC) E_chkChan_chkChanDo, /* delay function */ (DELAY_FUNC) D_chkChan_chkChanDo, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_chkChan_chkChanDo, /* state options */ (0)}, }; /* Event masks for state set doRate */ /* Event mask for state doClr: */ static bitMask EM_doRate_doClr[] = { 0x00000008, }; /* State Blocks */ static struct seqState state_doRate[] = { /* State "doClr" */ { /* state name */ "doClr", /* action function */ (ACTION_FUNC) A_doRate_doClr, /* event function */ (EVENT_FUNC) E_doRate_doClr, /* delay function */ (DELAY_FUNC) D_doRate_doClr, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_doRate_doClr, /* state options */ (0)}, }; /* State Set Blocks */ static struct seqSS seqSS[NUM_SS] = { /* State set "savRest" */ { /* ss name */ "savRest", /* ptr to state block */ state_savRest, /* number of states */ 3, /* error state */ -1}, /* State set "acquire" */ { /* ss name */ "acquire", /* ptr to state block */ state_acquire, /* number of states */ 2, /* error state */ -1}, /* State set "chkChan" */ { /* ss name */ "chkChan", /* ptr to state block */ state_chkChan, /* number of states */ 2, /* error state */ -1}, /* State set "doRate" */ { /* ss name */ "doRate", /* ptr to state block */ state_doRate, /* number of states */ 1, /* error state */ -1}, }; /* Program parameter list */ static char prog_param[] = "P=TDS:,FN=/afs/slac/g/esb/ilc/restore/tds3000.txt"; /* State Program table (global) */ struct seqProgram sncTds3x = { /* magic number */ 20000315, /* *name */ "sncTds3x", /* *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 sncTds3xRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&sncTds3x); } epicsExportRegistrar(sncTds3xRegistrar);