Tezzeret  1
Tezzeret
GmMFAMSensor.hpp
1 #ifndef GM_TIVA_MFAM_SENSOR_HPP_
2 #define GM_TIVA_MFAM_SENSOR_HPP_
3 
4 #include <driverlib/ssi.h>
5 #include <ti/drivers/spi/SPITivaDMA.h>
6 #include <driverlib/udma.h>
7 #include "GmMFAMDataSource.hpp"
8 
9 #ifndef GMMFAMDATA_HPP_
10 #include <GmMfamData.hpp>
11 #endif
12 #include <GmRingBuffer.hpp>
13 
14 #define MFAM_SPI_DATA_SZ 24
15 #define OUT_MSG_LEN 32
16 #define MFAM_SPI_BUFFER_EXTRA 4
17 #define MFAM_SPI_TRANSACTION_SZ MFAM_SPI_DATA_SZ + MFAM_SPI_BUFFER_EXTRA
18 #define MBX_TIMEOUT 12
19 
20 // Error codes.
21 // As with all sensors, the base success code is
22 // GM_SENSOR_OK, defined in the base CSensor header.
23 #define MFAM_FAILED_INIT 1
24 #define MFAM_FAILED 2
25 
26 namespace Geometrics
27 {
35  class GmMfam : public GmMfamDataSource
36  {
37  public:
38  GmMfam (UInt8 iSubjectId,
40  int Initialize (int iSpiId, int enablePinIndex, ti_sysbios_knl_Swi_Handle iSwiId,Bool waitForQuietSpi);
41 
42  enum MfamTestStates {
43  MFAM_PASSED_STARTUP = 0,
44  MFAM_FAILED_TO_INITIALIZE,
45  MFAM_SYSTEM_DID_NOT_TRY_TO_START,
46  MFAM_NO_RECORDS,
47  MFAM_SPI_CHANNEL_FAILED,
48  MFAM_COMPASS_FAILED
49  };
50 
51  virtual void Halt ();
52  virtual int CheckCalibrate (Bool bForceCalibrate);
53  static Void GmGetMFAMSpiData (SPI_Handle handle,
54  SPI_Transaction *transaction);
55  int CalibrateSpiBufferError ();
56  int ReadDataForTest ();
57  void ReadDataInternal ();
58 protected:
59 
60  static void SetupSpiBuffers (bool isNull);
61  static void SetupSpiParameters (SPI_TransferMode tMode,
62  Bool IsNull);
63  static Bool m_static_pps_rx;
64 
65  // ========= SPI transaction stack ====================================
66  public:
67  enum BufferState { Normal = 0, /* Buffer is OK to add data */
68  Locked, /* Add no more data to the buffer */
69  Shrinking }; /* Let the buffer shrink back to lower threshold */
70  enum BufferState mBufferState;
71  static Bool sMfamIsInStartupTest;
72  static MfamTestStates sMfamPassedTest;
73  static SPI_Handle m_static_GmSpiHandle;
74  static SPI_Params m_static_GmSpiParams;
75  static SPI_Transaction m_static_RxTxnPing,
76  m_static_RxTxnPong;
77  static Bool m_static_BPing;
78  static int sCompassRetries;
79 
80  private:
81 
82  // --------- We use two buffers, Ping and Pong, to get the
83  // --------- data out of the SPI transaction, in the interrupt
84  // --------- service routines.
85  // It is NOT certain that we need the two buffers, but it seems
86  // safer, as we don't entirely know the internal workings of the
87  // SPI driver.
88  static uint8_t m_static_PingBuffer [MFAM_SPI_TRANSACTION_SZ];
89  static uint8_t m_static_PongBuffer [MFAM_SPI_TRANSACTION_SZ];
90  //m_static_PongTxBuffer [MFAM_SPI_TRANSACTION_SZ],
91  //m_static_PingTxBuffer [MFAM_SPI_TRANSACTION_SZ];
92 
93  public:
94  // This class is used as a singleton.
95  static GmMfam *m_static_msTheOneSensor;
96 
97  private:
98  static ti_sysbios_knl_Swi_Handle m_iSwiId;
99  };
100 
101 } // End of namespace
102 
103 #endif
Abstract class - the interface - to the MFAM sensor. This abstract layer was created in order to acco...
Definition: GmMFAMDataSource.hpp:36
The MFAM magnetometer sensor.
Definition: GmMFAMSensor.hpp:36
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47