versadac  1
versadac - Scalable Recorder Firmware
eio_t25srm.h
1 /*******************************************************************************
2 FILE : eio_t25srm.h
3 VERSION : $Id$
4 AUTHOR : David Cozens
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains The t2500 module classes
7 
8  Modified for 8hz execution (for Scalable Recorder)
9 
10 *******************************************************************************/
11 #ifndef __EIO_T25SRM_H
12 #define __EIO_T25SRM_H
13 
14 #include "prjParams.h"
15 #include "eio.h"
16 #include "eiot2cal.h"
17 #include "rst_ssm.h"
18 #include "wdLib.h"
19 #include "../eurotherm_drv/h/sysEurothermRedundant.h"
20 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 extern EioAIMeasuredValueData *eioT2500AIMeasuredValueData;
27 extern EioAIPointConfig *eioT2500AIPointConfig;
28 extern EioDIData *eioT2500DiData;
29 extern EioUint32 *eioT2500DiDebounceuS;
30 extern EioDoPointConfig *eioT2500DoPointConfig;
31 extern EioDoPointRuntime *eioT2500DoPointRuntime;
32 extern EioAOData *eioT2500AOData;
33 extern EioAOConfig *eioT2500AOConfig;
34 extern EioAICalibrationData *eioT2500AICalData;
35 extern EioAOCalibrationData *eioT2500AOCalData;
36 extern EioFIData *eioT2500FIData;
37 extern EioBoolean *eioT2500FISecondaryUpdate;
38 extern EioFIConfig *eioT2500FIConfig;
39 
40 #define EIO_T2500_MAX_NUMBER_OF_IO_SLOTS 16
41 
42 enum ChannelLedState
43 {
44  CHANNEL_LED_OFF,
45  CHANNEL_LED_ON,
46  CHANNEL_LED_FLASHING,
47  CHANNEL_LED_BLINKING_ON,
48  CHANNEL_LED_BLINKING_OFF,
49  CHANNEL_LED_DEBUG,
50  CHANNEL_LED_FAST_FLASH,
51  NUMBER_OF_CHANNEL_LED_STATES
52 };
53 
54 // this is the base class for all T2500 IO modules
55 // There are two callbacks for each module that are made after 62.5mS and 125mS
56 // into the IO cycle. On a newly created module the system is managed such that
57 // the first callback made is always the 62.5mS one.
59 {
60  public:
61  EioT2500Module(unsigned char moduleNumber, EioModuleType z_type, EioT2500CycleEnum z_cycleNumber);
62  virtual ~EioT2500Module();
63 
64  static void initialise();
65 
66  static bool setExpectedModule(unsigned char z_moduleNumber, EioModuleType z_type, EioUint8 cycleNumber);
67  static EioModuleType getExpectedModule( unsigned char z_moduleNumber );
68  static void setUpdateCycleCompleteHookAdd( EioSystem *ioSystem, EioUint8 cycleNumber, void(*hook)(EioUint8 cycleNumber, EioUint32 count));
69  static void setApplicationCycleCompleteCheckHookAdd( EioSystem *ioSystem, EioUint8 cycleNumber, EioBoolean(*hook)(EioUint8 cycleNumber));
70 
71  static void callbackFast();
72  static void callback62_5mS();
73  static void callback125mS();
74 
75  static IdentSpiScheduledMessage *getIdentMessage(int moduleNumber);
76  static ResetSpiScheduledMessage *getResetMessage(int moduleNumber);
77  static void incTickCount()
78  {
79  tickCount += ticksPerFastTask;
80  if (tickCount >= EUROTHERM_SPI_MESSAGE_SCHEDULER_NUMBER_OF_SLOTS)
81  tickCount=0;
82  };
83  static EioUint16 getTicksPerFastTask(){return ticksPerFastTask;};
84  static void setTicksPerFastTask(EioUint16 ticks){ticksPerFastTask = ticks;};
85  static void resetTickCount(){tickCount=0;};
86  static EioUint16 getTickCount(){return tickCount;};
87  static bool controlsIOBus(){return m_controlsIoBus &&
88  /* See lin:#19571 */
89  SysEurothermRedundantGetA_PRIMARY();};
90  static void setOperatingMode( EioOperatingMode mode );
91  static EioOperatingMode getOperatingMode();
92  static void secondaryHasIO();
93  static EioBoolean readyToRun();
94  static EioBoolean getSystemFailed();
95  static void setSystemFailed();
96  static void setFastOverrun();
97  static void setSlowOverrun();
98  static void setTickCountProblem();
99  static EioBoolean calIsPointRangeCalibrated(EioUint8 module, EioUint8 channel, EioAICalType calType, EioUint8 rangeNumber);
100  static void setCycleRateDivisor(EioUint8 cycleNumber, EioUint32 divisor);
101 
102  protected:
103  virtual void updateFast(unsigned short slot);
104  virtual void update62_5mS();
105  virtual void update125mS();
106  virtual void updateBuffers125ms();
107  virtual void updateFastBuffers(unsigned int z_thisSlot);
108  virtual void cycleComplete125mS();
109  virtual void cycleCompleteFast(unsigned int z_thisSlot);
110  virtual void setModuleOperatingMode( EioOperatingMode mode );
111  virtual EioBoolean getCalibrated(EioUint8 channel, EioAICalType calType, EioUint8 rangeNumber);
112  void updateResetEnable125mS();
113  static EioT2500Module * factory(unsigned char z_moduleNumber, EioModuleType z_type, EioT2500CycleEnum z_cycleNumber);
114  // each module is allowed to use 4 time slots starting from here in the first 62.5mS of a 125mS cycle
115  unsigned int getFirstSlot62_5mS(){return m_moduleNumber*4;};
116  static unsigned int getFirstSlot62_5mSForModule(int moduleNumber){return moduleNumber*4;};
117  // each module is allowed to use 4 time slots starting from here in the second 62.5mS of a 125mS cycle
118  // the 4th slot will also contain the module ident message
119  unsigned int getFirstSlot125mS(){return EUROTHERM_SPI_MESSAGE_SCHEDULER_NUMBER_OF_SLOTS/2 + m_moduleNumber*4;};
120  static unsigned int getFirstSlot125mSForModule(int moduleNumber){return EUROTHERM_SPI_MESSAGE_SCHEDULER_NUMBER_OF_SLOTS/2 + moduleNumber*4;};
121 
122  unsigned int getFirstSlotFast(){return ((m_moduleNumber * 2) + 1) % EIO_T2500_FAST_MODULE_TICK_INTERLIEVE;};
123 
124  static unsigned int getFirstSlotFastForModule(int moduleNumber){return moduleNumber % EIO_T2500_FAST_MODULE_TICK_INTERLIEVE;};
125 
126  // given the first slot of the fast tick being processed (z_thisSlot) this function returns the first slot to be updated for output
127  unsigned int getFirstFastOutputSlot(unsigned int z_thisSlot){return (z_thisSlot+1+getTicksPerFastTask()+((m_moduleNumber+EIO_T2500_FAST_MODULE_TICK_INTERLIEVE-1) % EIO_T2500_FAST_MODULE_TICK_INTERLIEVE)) % EUROTHERM_SPI_MESSAGE_SCHEDULER_NUMBER_OF_SLOTS;};
128  // given the first slot of the fast tick being processed (z_thisSlot) this function returns the first slot be processed for input
129  unsigned int getFirstFastInputSlot(unsigned int z_thisSlot){return (z_thisSlot+EUROTHERM_SPI_MESSAGE_SCHEDULER_NUMBER_OF_SLOTS-getTicksPerFastTask()+getFirstSlotFast()) % EUROTHERM_SPI_MESSAGE_SCHEDULER_NUMBER_OF_SLOTS;};
130  static bool ledMapState( ChannelLedState led_state );
131 
132  EioModuleType m_expectedType;
133  EioT2500CycleEnum m_expectedCycleNumber;
134  bool m_expectedModuleChanged;
135  EioOperatingMode m_moduleOperatingMode;
136  unsigned char m_moduleNumber;
137  unsigned char m_fastSubslotNumber;
138  static EioT2500Module **m_modules;
139  static unsigned char m_numberOfModules;
140  static IdentSpiScheduledMessage *m_identMessages[EIO_T2500_MAX_NUMBER_OF_IO_SLOTS];
141  static EioUint32 cycleCountFast;
142  static EioUint32 cycleCount125mS;
143 
144  private:
145  static ResetSpiScheduledMessage *m_resetMessages[EIO_T2500_MAX_NUMBER_OF_IO_SLOTS];
146  static void (*updateCycleCompleteFastHook)(EioUint8 cycleNumber, EioUint32 count);
147  static EioBoolean (*applicationCycleCompleteCheckFastHook)(EioUint8 cycleNumber);
148  static void (*updateCycleComplete125mSHook)(EioUint8 cycleNumber, EioUint32 count);
149  static EioBoolean (*applicationCycleCompleteCheck125mSHook)(EioUint8 cycleNumber);
150  static void secondaryLostSync();
151  static void secondaryResync();
152  static void secondaryLostBackplane();
153  static EioUint8 ledTestTimer;
154  static EioUint16 ledCurrentMask;
155  static EioUint16 ledStateTable[NUMBER_OF_CHANNEL_LED_STATES];
156  static EioUint16 ticksPerFastTask;
157  static EioSint16 tickCount;
158  static bool m_controlsIoBus;
159  static EioOperatingMode m_operatingMode;
160  static bool m_operatingModeChanged;
161  static WDOG_ID m_resyncWatchdog;
162  static WDOG_ID m_timeoutWatchdog;
163  static WDOG_ID m_lostBackplaneWatchdog;
164  static int m_secondaryResyncCount;
165  static int m_secondaryNextModule;
166  static bool m_secondaryInSync;
167  static EioBoolean m_readyToRun;
168  static bool m_systemFailed;
169  static bool m_fastOverrun;
170  static bool m_slowOverrun;
171  static bool m_tickCountProblem;
172  static bool m_lostBackplane;
173  static int m_ignoringStartupCycles;
174  static bool m_primaryPollsModuleIdent;
175  static EioUint32 m_cycleRateDivisor[EIO_T2500_NUMBER_OF_CYCLES];
176  static EioUint32 m_cycleRateCounter[EIO_T2500_NUMBER_OF_CYCLES];
177 };
178 
179 #ifdef __cplusplus
180 } /* extern "C" */
181 #endif
182 #endif /*__EIO_T25SRM_H */
183 
Definition: eio_t25srm.h:58
Definition: eio_ai.h:44
Definition: eio_syst.h:52
Definition: eio_ao.h:46
Definition: rst_ssm.h:14
Definition: id_ssm.h:55
Definition: eiot2cal.h:36
Definition: eio_ai.h:76
Definition: eio_di.h:38
Definition: eio_do.h:89
Definition: eiot2cal.h:61
Definition: eio_fi.h:52
Definition: eio_fi.h:39
Definition: eio_ao.h:38
Definition: eio_do.h:102