This program acquires data from an ADIS16355 IMU via the SPI bus and sends the data to a host computer via UDP over Ethernet.
Dependencies: mbed StrippedDownNetServices
imu-spi.h@0:79f663186c05, 2012-05-31 (annotated)
- Committer:
- yahugh
- Date:
- Thu May 31 18:37:12 2012 +0000
- Revision:
- 0:79f663186c05
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yahugh | 0:79f663186c05 | 1 | // |
yahugh | 0:79f663186c05 | 2 | // imu-spi.h |
yahugh | 0:79f663186c05 | 3 | // |
yahugh | 0:79f663186c05 | 4 | // copyright 2010 Hugh Shane |
yahugh | 0:79f663186c05 | 5 | // |
yahugh | 0:79f663186c05 | 6 | |
yahugh | 0:79f663186c05 | 7 | class ImuSpi { |
yahugh | 0:79f663186c05 | 8 | private: |
yahugh | 0:79f663186c05 | 9 | const static int dataSize = 7; |
yahugh | 0:79f663186c05 | 10 | const static int bufferSize = dataSize+1; // we need to leave room for one junk data |
yahugh | 0:79f663186c05 | 11 | int8_t imuRegs[bufferSize]; |
yahugh | 0:79f663186c05 | 12 | int16_t buffer[2][bufferSize]; // ping-pong IMU data buffer |
yahugh | 0:79f663186c05 | 13 | int8_t pingpong; |
yahugh | 0:79f663186c05 | 14 | bool bufferReady; |
yahugh | 0:79f663186c05 | 15 | SPI spi; |
yahugh | 0:79f663186c05 | 16 | DigitalOut cs; |
yahugh | 0:79f663186c05 | 17 | DigitalOut reset; |
yahugh | 0:79f663186c05 | 18 | DigitalOut diag; |
yahugh | 0:79f663186c05 | 19 | InterruptIn imuDataReady; |
yahugh | 0:79f663186c05 | 20 | void InitImu(void); |
yahugh | 0:79f663186c05 | 21 | void IMUDataReadyISR(void); |
yahugh | 0:79f663186c05 | 22 | int16_t ReadSynch(char); |
yahugh | 0:79f663186c05 | 23 | void WriteSynch(char, char); |
yahugh | 0:79f663186c05 | 24 | void SendReadCmd(int8_t); |
yahugh | 0:79f663186c05 | 25 | void TogglePingpong() {pingpong = (~pingpong) & 0x01;}; |
yahugh | 0:79f663186c05 | 26 | int16_t* GetBufferWritePtr() {return &buffer[pingpong][0];}; |
yahugh | 0:79f663186c05 | 27 | volatile int imuCmdIndex; |
yahugh | 0:79f663186c05 | 28 | volatile int imuReadIndex; |
yahugh | 0:79f663186c05 | 29 | Timeout writeTrigger; |
yahugh | 0:79f663186c05 | 30 | int16_t* wp; |
yahugh | 0:79f663186c05 | 31 | void WriteTriggerTimeoutISR(void); |
yahugh | 0:79f663186c05 | 32 | void SSP0ISR(void); |
yahugh | 0:79f663186c05 | 33 | static void _ssp0isr(void); |
yahugh | 0:79f663186c05 | 34 | int sequenceNumber; |
yahugh | 0:79f663186c05 | 35 | InterruptIn onePPS; |
yahugh | 0:79f663186c05 | 36 | public: |
yahugh | 0:79f663186c05 | 37 | ImuSpi(void); |
yahugh | 0:79f663186c05 | 38 | void StartBurstRead(void); |
yahugh | 0:79f663186c05 | 39 | int16_t* GetBufferReadPtr() {return buffer[(~pingpong) & 0x01];}; |
yahugh | 0:79f663186c05 | 40 | bool IsBufferReady(void); |
yahugh | 0:79f663186c05 | 41 | int GetBufferSize(void) {return bufferSize*sizeof(int16_t);}; |
yahugh | 0:79f663186c05 | 42 | }; |