From e7dc2425d6c38b98508e1daf1d0c10756f14dab7 Mon Sep 17 00:00:00 2001 From: "benjamin.franksen" <benjamin.franksen@helmholtz-berlin.de> Date: Tue, 24 Sep 2013 18:36:21 +0000 Subject: [PATCH] moved non-API internals from seqCom.h to new seq_snc.h Another one of the long overdue re-factorings. The new header file seq_snc.h contains all the definitions that are shared between the snc generated code and the run-time library. What remains in seqCom.h is the public API for C code that wants to interact with an SNL program. --- src/seq/Makefile | 1 + src/seq/seqCom.h | 110 +++--------------------------------- src/seq/seqPvt.h | 2 +- src/seq/seq_snc.h | 132 +++++++++++++++++++++++++++++++++++++++++++ src/snc/gen_code.c | 2 +- src/snc/gen_tables.c | 2 +- 6 files changed, 144 insertions(+), 105 deletions(-) create mode 100644 src/seq/seq_snc.h diff --git a/src/seq/Makefile b/src/seq/Makefile index ee5e8c14..e74c0990 100644 --- a/src/seq/Makefile +++ b/src/seq/Makefile @@ -6,6 +6,7 @@ include $(TOP)/configure/CONFIG # Include files INC += seqCom.h +INC += seq_snc.h INC += seq_release.h INC += seq_static_assert.h INC += seq_prim_types.h diff --git a/src/seq/seqCom.h b/src/seq/seqCom.h index 50881795..04757b21 100644 --- a/src/seq/seqCom.h +++ b/src/seq/seqCom.h @@ -2,12 +2,12 @@ Copyright (c) 1993 The Regents of the University of California and the University of Chicago. Los Alamos National Laboratory -Copyright (c) 2010-2012 Helmholtz-Zentrum Berlin f. Materialien +Copyright (c) 2010-2013 Helmholtz-Zentrum Berlin f. Materialien und Energie GmbH, Germany (HZB) This file is distributed subject to a Software License Agreement found in the file LICENSE that is included with this distribution. \*************************************************************************/ -/* External interface to the sequencer run-time library +/* Public interface to the sequencer run-time library * * Author: Andy Kozubal * Date: 01mar94 @@ -27,42 +27,18 @@ in the file LICENSE that is included with this distribution. #ifndef INCLseqComh #define INCLseqComh -#include "shareLib.h" -#include "pvAlarm.h" +#include "epicsTypes.h" #include "epicsThread.h" #include "epicsTime.h" +#include "shareLib.h" +#include "pvAlarm.h" #include "seq_release.h" #ifdef __cplusplus extern "C" { #endif -/* Bit encoding for run-time options */ -#define OPT_DEBUG ((seqMask)1u<<0) /* turn on debugging */ -#define OPT_ASYNC ((seqMask)1u<<1) /* use async. gets */ -#define OPT_CONN ((seqMask)1u<<2) /* wait for all connections */ -#define OPT_REENT ((seqMask)1u<<3) /* generate reentrant code */ -#define OPT_NEWEF ((seqMask)1u<<4) /* new event flag mode */ -#define OPT_SAFE ((seqMask)1u<<5) /* safe mode */ - -/* Bit encoding for State Specific Options */ -#define OPT_NORESETTIMERS ((seqMask)1u<<0) /* Don't reset timers on */ - /* entry to state from same state */ -#define OPT_DOENTRYFROMSELF ((seqMask)1u<<1) /* Do entry{} even if from same state */ -#define OPT_DOEXITTOSELF ((seqMask)1u<<2) /* Do exit{} even if to same state */ - -/* seqMask macros */ -#define NBITS (8*sizeof(seqMask)) /* # bits in seqMask word */ -#define NWORDS(maxBitNum) (1+(maxBitNum)/NBITS) /* # words in seqMask */ - -#define bitSet(words, bitnum) ( words[(bitnum)/NBITS] |= (1u<<((bitnum)%NBITS))) -#define bitClear(words, bitnum) ( words[(bitnum)/NBITS] &= ~(1u<<((bitnum)%NBITS))) -#define bitTest(words, bitnum) ((words[(bitnum)/NBITS] & (1u<<((bitnum)%NBITS))) != 0) - -#define optTest(sp,opt) (((sp)->options & (opt)) != 0) - /* test if opt is set in program instance sp */ - #define NOEVFLAG 0 /* argument to pvSync to remove sync */ #define DEFAULT_QUEUE_SIZE 2 /* default queue size (elements) */ @@ -74,90 +50,18 @@ enum compType { SYNC }; -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif - typedef struct state_set *const SS_ID; /* state set id, opaque */ -typedef struct program_instance *const PROG_ID; /* program id, opaque */ typedef struct _seq_var SEQ_VARS; /* defined by program, opaque */ typedef char string[MAX_STRING_SIZE]; /* the string typedef */ typedef SEQ_VARS USER_VAR; /* for compatibility */ /* these typedefs make the code more self documenting */ -typedef epicsUInt32 seqMask; /* for event masks and options */ typedef unsigned EV_ID; /* identifier for an event */ typedef unsigned VAR_ID; /* identifier for a pv */ typedef int seqBool; -/* Prototypes for functions generated by snc */ -typedef void SEQ_TRANS_FUNC(SS_ID ssId, SEQ_VARS *const var, int transNum, int *nextState); -typedef seqBool SEQ_EVENT_FUNC(SS_ID ssId, SEQ_VARS *const var, int *transNum, int *nextState); -typedef void SEQ_SS_FUNC(SS_ID ssId, SEQ_VARS *const var); -typedef void SEQ_PROG_FUNC(PROG_ID progId, SEQ_VARS *const vars); - -typedef const struct seqChan seqChan; -typedef const struct seqState seqState; -typedef const struct seqSS seqSS; -typedef struct seqProgram seqProgram; - -/* Static information about a channel */ -struct seqChan -{ - const char *chName; /* assigned channel name */ - size_t offset; /* offset to value */ - const char *varName; /* variable name, including subscripts*/ - const char *varType; /* variable type, e.g. "int" */ - unsigned count; /* element count for arrays */ - unsigned eventNum; /* event number for this channel */ - EV_ID efId; /* event flag id if synced */ - seqBool monitored; /* whether channel should be monitored */ - unsigned queueSize; /* syncQ queue size (0=not queued) */ - unsigned queueIndex; /* syncQ queue index */ -}; - -/* Static information about a state */ -struct seqState -{ - const char *stateName; /* state name */ - SEQ_TRANS_FUNC *actionFunc; /* action routine for this state */ - SEQ_EVENT_FUNC *eventFunc; /* event routine for this state */ - SEQ_SS_FUNC *entryFunc; /* statements performed on entry to state */ - SEQ_SS_FUNC *exitFunc; /* statements performed on exit from state */ - const seqMask *eventMask; /* event mask for this state */ - seqMask options; /* state option mask */ -}; - -/* Static information about a state set */ -struct seqSS -{ - const char *ssName; /* state set name */ - seqState *states; /* array of state blocks */ - unsigned numStates; /* number of states in this state set */ -}; - -/* Static information about a state program */ -struct seqProgram -{ - unsigned magic; /* magic number */ - const char *progName; /* program name (for debugging) */ - seqChan *chan; /* table of channels */ - unsigned numChans; /* number of db channels */ - seqSS *ss; /* array of state set info structs */ - unsigned numSS; /* number of state sets */ - unsigned varSize; /* # bytes in user variable area */ - const char *params; /* program paramters */ - unsigned numEvFlags; /* number of event flags */ - seqMask options; /* program option mask */ - SEQ_PROG_FUNC *initFunc; /* init function */ - SEQ_SS_FUNC *entryFunc; /* entry function */ - SEQ_SS_FUNC *exitFunc; /* exit function */ - unsigned numQueues; /* number of syncQ queues */ -}; +typedef struct seqProgram seqProgram; /* program object, opaque */ /* * Function declarations for interface between state program & sequencer. @@ -207,6 +111,7 @@ epicsShareFunc void seq_pvFlush(SS_ID); epicsShareFunc seqBool seq_delay(SS_ID, double); epicsShareFunc char *seq_macValueGet(SS_ID, const char *); epicsShareFunc void seq_exit(SS_ID); + /* global info */ epicsShareFunc unsigned seq_pvChannelCount(SS_ID); epicsShareFunc unsigned seq_pvConnectCount(SS_ID); @@ -220,6 +125,7 @@ epicsShareFunc void seqcar(int level); epicsShareFunc void seqQueueShow(epicsThreadId); epicsShareFunc void seqStop(epicsThreadId); epicsShareFunc epicsThreadId seq(seqProgram *, const char *, unsigned); + /* called by generated main and registrar routines */ epicsShareFunc void seqRegisterSequencerProgram(seqProgram *p); epicsShareFunc void seqRegisterSequencerCommands(void); diff --git a/src/seq/seqPvt.h b/src/seq/seqPvt.h index ab3ff6db..a3a6bdf5 100644 --- a/src/seq/seqPvt.h +++ b/src/seq/seqPvt.h @@ -33,7 +33,7 @@ in the file LICENSE that is included with this distribution. #ifndef INCLseqPvth #define INCLseqPvth -#include "seqCom.h" +#include "seq_snc.h" #define boolean seqBool #define bitMask seqMask diff --git a/src/seq/seq_snc.h b/src/seq/seq_snc.h new file mode 100644 index 00000000..5e41283f --- /dev/null +++ b/src/seq/seq_snc.h @@ -0,0 +1,132 @@ +/*************************************************************************\ +Copyright (c) 1993 The Regents of the University of California + and the University of Chicago. + Los Alamos National Laboratory +Copyright (c) 2010-2013 Helmholtz-Zentrum Berlin f. Materialien + und Energie GmbH, Germany (HZB) +This file is distributed subject to a Software License Agreement found +in the file LICENSE that is included with this distribution. +\*************************************************************************/ +/* Interface between snc generated code and run-time library + * + * Author: Andy Kozubal + * Date: 01mar94 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + */ +#ifndef INCLseqsnch +#define INCLseqsnch + +#include "seqCom.h" + +typedef epicsUInt32 seqMask; /* for event masks and options */ + +/* Bit encoding for run-time options */ +#define OPT_DEBUG ((seqMask)1u<<0) /* turn on debugging */ +#define OPT_ASYNC ((seqMask)1u<<1) /* use async. gets */ +#define OPT_CONN ((seqMask)1u<<2) /* wait for all connections */ +#define OPT_REENT ((seqMask)1u<<3) /* generate reentrant code */ +#define OPT_NEWEF ((seqMask)1u<<4) /* new event flag mode */ +#define OPT_SAFE ((seqMask)1u<<5) /* safe mode */ + +/* Bit encoding for State Specific Options */ +#define OPT_NORESETTIMERS ((seqMask)1u<<0) /* Don't reset timers on */ + /* entry to state from same state */ +#define OPT_DOENTRYFROMSELF ((seqMask)1u<<1) /* Do entry{} even if from same state */ +#define OPT_DOEXITTOSELF ((seqMask)1u<<2) /* Do exit{} even if to same state */ + +/* seqMask macros */ +#define NBITS (8*sizeof(seqMask)) /* # bits in seqMask word */ +#define NWORDS(maxBitNum) (1+(maxBitNum)/NBITS) /* # words in seqMask */ + +#define bitSet(words, bitnum) ( words[(bitnum)/NBITS] |= (1u<<((bitnum)%NBITS))) +#define bitClear(words, bitnum) ( words[(bitnum)/NBITS] &= ~(1u<<((bitnum)%NBITS))) +#define bitTest(words, bitnum) ((words[(bitnum)/NBITS] & (1u<<((bitnum)%NBITS))) != 0) + +#define optTest(sp,opt) (((sp)->options & (opt)) != 0) + /* test if opt is set in program instance sp */ + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +typedef struct program_instance *const PROG_ID; + +/* Prototypes for functions generated by snc */ +typedef void SEQ_TRANS_FUNC(SS_ID ssId, SEQ_VARS *const var, int transNum, int *nextState); +typedef seqBool SEQ_EVENT_FUNC(SS_ID ssId, SEQ_VARS *const var, int *transNum, int *nextState); +typedef void SEQ_SS_FUNC(SS_ID ssId, SEQ_VARS *const var); +typedef void SEQ_PROG_FUNC(PROG_ID progId, SEQ_VARS *const vars); + +typedef const struct seqChan seqChan; +typedef const struct seqState seqState; +typedef const struct seqSS seqSS; + +/* Static information about a channel */ +struct seqChan +{ + const char *chName; /* assigned channel name */ + size_t offset; /* offset to value */ + const char *varName; /* variable name, including subscripts*/ + const char *varType; /* variable type, e.g. "int" */ + unsigned count; /* element count for arrays */ + unsigned eventNum; /* event number for this channel */ + EV_ID efId; /* event flag id if synced */ + seqBool monitored; /* whether channel should be monitored */ + unsigned queueSize; /* syncQ queue size (0=not queued) */ + unsigned queueIndex; /* syncQ queue index */ +}; + +/* Static information about a state */ +struct seqState +{ + const char *stateName; /* state name */ + SEQ_TRANS_FUNC *actionFunc; /* action routine for this state */ + SEQ_EVENT_FUNC *eventFunc; /* event routine for this state */ + SEQ_SS_FUNC *entryFunc; /* statements performed on entry to state */ + SEQ_SS_FUNC *exitFunc; /* statements performed on exit from state */ + const seqMask *eventMask; /* event mask for this state */ + seqMask options; /* state option mask */ +}; + +/* Static information about a state set */ +struct seqSS +{ + const char *ssName; /* state set name */ + seqState *states; /* array of state blocks */ + unsigned numStates; /* number of states in this state set */ +}; + +/* Static information about a state program */ +struct seqProgram +{ + unsigned magic; /* magic number */ + const char *progName; /* program name (for debugging) */ + seqChan *chan; /* table of channels */ + unsigned numChans; /* number of db channels */ + seqSS *ss; /* array of state set info structs */ + unsigned numSS; /* number of state sets */ + unsigned varSize; /* # bytes in user variable area */ + const char *params; /* program paramters */ + unsigned numEvFlags; /* number of event flags */ + seqMask options; /* program option mask */ + SEQ_PROG_FUNC *initFunc; /* init function */ + SEQ_SS_FUNC *entryFunc; /* entry function */ + SEQ_SS_FUNC *exitFunc; /* exit function */ + unsigned numQueues; /* number of syncQ queues */ +}; + +#endif /*INCLseqsnch*/ diff --git a/src/snc/gen_code.c b/src/snc/gen_code.c index 0fde7a3a..305bce78 100644 --- a/src/snc/gen_code.c +++ b/src/snc/gen_code.c @@ -64,7 +64,6 @@ void generate_code(Program *p, const char *header_name) gen_code("#define INCL%sh\n", p->name); /* Includes */ - gen_code("#include \"epicsTypes.h\"\n"); gen_code("#include \"seqCom.h\"\n"); /* Generate literal C code intermixed with global definitions */ @@ -96,6 +95,7 @@ void generate_code(Program *p, const char *header_name) gen_code("#include <stdio.h>\n"); gen_code("#include <limits.h>\n"); gen_code("\n"); + gen_code("#include \"seq_snc.h\"\n"); gen_code("#include \"%s\"\n", header_name); if (!p->options.reent) diff --git a/src/snc/gen_tables.c b/src/snc/gen_tables.c index 196a0b75..b5f39d57 100644 --- a/src/snc/gen_tables.c +++ b/src/snc/gen_tables.c @@ -21,7 +21,7 @@ in the file LICENSE that is included with this distribution. # include <alloca.h> #endif -#include "seqCom.h" +#include "seq_snc.h" #include "analysis.h" #include "main.h" #include "sym_table.h" -- GitLab