versadac  1
versadac - Scalable Recorder Firmware
eiot2srfi2.h
1 /*******************************************************************************
2 FILE : eiot2srfi2.h
3 VERSION : $Id$
4 AUTHOR : David Cozens
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains The t2500 FI2 module class
7 
8  Modification for 8Hz execution (for Scalable Recorder)
9 
10 *******************************************************************************/
11 
12 #ifndef __EIOT2SRFI2_H
13 #define __EIOT2SRFI2_H
14 /* The following section is needed by eio_t25sr.c */
15 
16 /* Capability discovery functions use FI2_NUMBER_OF_CHANNELS */
17 enum Fi2Channels
18 {
19  FI2_CHANNEL_1,
20  FI2_CHANNEL_2,
21  FI2_NUMBER_OF_CHANNELS
22 };
23 
24 // EIO_T2500_FI2_MAX_FREQUENCY is the highest we can measure allowing lots of margin for oversampling - it is our quoted max
25 #define EIO_T2500_FI2_MAX_FREQUENCY 40000.0F
26 // EIO_T2500_FI2_MAX_FREQUENCY_MEASURABLE is the highest we can measure - we will clamp frequencies to this limit
27 #define EIO_T2500_FI2_MAX_FREQUENCY_MEASURABLE 80000.0F
28 #define EIO_T2500_FI2_MIN_FREQUENCY_LOGIC 0.01F
29 #define EIO_T2500_FI2_MIN_FREQUENCY_MAGNETIC 10.0F
30 #define EIO_T2500_FI2_BURDEN_RESISTANCE 1000.0F
31 #define EIO_T2500_FI2_MIN_THRESHOLD_MILLIVOLTS 0.0F
32 #define EIO_T2500_FI2_MAX_THRESHOLD_MILLIVOLTS 20000.0F
33 #define EIO_T2500_FI2_MIN_THRESHOLD_MILLIAMPS 0.0F
34 #define EIO_T2500_FI2_MAX_THRESHOLD_MILLIAMPS 20.0F
35 
36 #define EIO_T2500_FI2_MAX_FILTER_TIME_US (999999999) /* 999.999999 seconds */
37 
38 // number of messages to holdoff the measurements from following a reset
39 #define EIO_FI2_HOLDOFF_COUNT 2
40 
41 enum
42 {
43  EIO_T2500_FI2_DEBOUNCE_CODE_OFF,
44  EIO_T2500_FI2_DEBOUNCE_CODE_5mS,
45  EIO_T2500_FI2_DEBOUNCE_CODE_10mS,
46  EIO_T2500_FI2_DEBOUNCE_CODE_20mS,
47  EIO_T2500_FI2_DEBOUNCE_CODE_50mS,
48  EIO_T2500_FI2_NUMBER_OF_DEBOUNCE_CODES
49 };
50 
51 enum
52 {
53  EIO_T2500_FI2_PSU_8V_CODE,
54  EIO_T2500_FI2_PSU_12V_CODE,
55  EIO_T2500_FI2_PSU_24V_CODE,
56  EIO_T2500_FI2_NUMBER_OF_PSU_CODES
57 };
58 
59 extern unsigned char eioT2500FI2DebounceCodes[EIO_T2500_FI2_NUMBER_OF_DEBOUNCE_CODES];
60 extern unsigned char eioT2500FI2PSUCodes[EIO_T2500_FI2_NUMBER_OF_PSU_CODES];
61 
62 unsigned char eioT2500FI2GetDebounceEnum(EioUint32 debounce);
63 unsigned char eioT2500FI2GetPSUEnum(float requestedMillivolts);
64 
65 #ifdef __cplusplus
66 
67 /* This section must never be included from C */
68 
69 
70 #include "eio_t25srm.h"
71 #include "rst_ssm.h"
72 #include "led_ssm.h"
73 
75 
76 extern "C" {
77 
78 enum Fi2RunStates
79 {
80  EIO_T2500FI2_STATE_MODULE_NEEDS_RESET,
81  EIO_T2500FI2_STATE_INITIALISING,
82  EIO_T2500FI2_STATE_RUNTIME,
83  EIO_T2500FI2_STATE_DELETE,
84  EIO_T2500FI2_STATE_SECONDARY,
85  EIO_T2500FI2_STATE_BECOMING_PRIMARY,
86 };
87 
88 class EioT2500FI2Module:public EioT2500Module
89 {
90  public:
91  EioT2500FI2Module(unsigned char moduleNumber, EioT2500CycleEnum z_expectedCycleNumber);
92  virtual ~EioT2500FI2Module();
93 
94  protected:
95  virtual void update62_5mS();
96  virtual void update125mS();
97  virtual void updateBuffers125ms();
98  virtual void cycleComplete125mS();
99 
100  private:
101  void handleModuleError();
102  bool processUpdateMessage(FrequencyInputSpiScheduledMessage *message);
103  void configureUpdateMessages(int channel);
104  void driveModuleLEDs();
105  /*---------------------------------------------------------------------------
106  FUNCTION : filter
107  DESCRIPTION : This function implements a IIR filter. It is used for
108  filtering frequency.
109 
110  ARGUMENTS : sample - Raw value to include in filter
111  polep - filter pole
112  divisor - divider value to use. It is assumed that this has been checked and is valid!
113 
114  RETURN : New filtered value
115 
116  NOTES :
117 
118  ---------------------------------------------------------------------------*/
119  float filter( float sample, float polep, float divisor)
120  {
121  return polep + ( (sample - polep) / divisor );
122  }
123 
124  Fi2RunStates m_state;
125  bool m_messagesScheduled;
126  EioUint8 m_initialisingCount;
127  FrequencyInputSpiScheduledMessage * m_updateMessage[FI2_NUMBER_OF_CHANNELS];
128  EioFIData m_inputData[FI2_NUMBER_OF_CHANNELS];
129  EioFIConfig m_pointConfig[FI2_NUMBER_OF_CHANNELS];
130  bool m_badConfig[FI2_NUMBER_OF_CHANNELS];
131  bool m_resetFilter[FI2_NUMBER_OF_CHANNELS];
132  EioUint32 m_updatesSinceLastPulse[FI2_NUMBER_OF_CHANNELS];
133  float m_divisor[FI2_NUMBER_OF_CHANNELS];
134  float m_rawFrequency[FI2_NUMBER_OF_CHANNELS];
135  unsigned char m_holdoffCount[FI2_NUMBER_OF_CHANNELS];
136  EioFIStatus m_holdoffStatus[FI2_NUMBER_OF_CHANNELS];
137  EioUint8 m_moduleVersion;
138 
139  /* for dev use only */
140  EEWriteSpiScheduledMessage *m_identWriteMessage;
141  EEWriteEnableSpiScheduledMessage *m_identWriteEnableMessage;
142 };
143 } /* extern "C" */
144 #endif /* __cplusplus */
145 #endif /*__EIOT2SRFI2_H */
Definition: eio_t25srm.h:58
Definition: ee_ssm.h:113
Definition: fi_ssm.h:39
Definition: ee_ssm.h:126
Definition: eio_fi.h:52
Definition: eio_fi.h:39