Add LPC1768

Dependencies:   mbed-rtos mbed Xbus

Fork of MTi-1_example by Xsens

Embed: (wiki syntax)

« Back to documentation index

main.cpp File Reference

main.cpp File Reference

Go to the source code of this file.

Functions

static Serial pc (PC_TX, PC_RX)
 Serial port for communication with the host PC.
static I2C mt (MT_SDA, MT_SCL)
 I2C master used for communication with the MT.
static SPI mt (MT_MOSI, MT_MISO, MT_SCLK)
 SPI master used for communication with the MT.
static DigitalOut cs (MT_nCS, 1)
 Chip select line for the MT.
static RawSerial mt (MT_TX, MT_RX)
 Serial port for communication with the MT.
static InterruptIn drdy (MT_DRDY)
 Interrput line used by MT to signal that data is available.
static DigitalOut mtReset (MT_NRESET, 0)
 MT reset line.
static void * allocateMessageData (size_t bufSize)
 Allocate message data buffer from the message data pool.
static void deallocateMessageData (void const *buffer)
 Deallocate message data previously allocated from the message data pool.
static void configureMtCommunicationInterface (void)
 Configure the serial port used for communication with the motion tracker.
static void sendMessage (XbusMessage const *m)
 Send a message to the MT.
static void mtLowLevelHandler (void)
 RX Interrupt handler for the MT serial port.
static XbusMessage const * doTransaction (XbusMessage const *m)
 Send a message to the MT and wait for a response.
static void dumpResponse (XbusMessage const *response)
 Dump information from a message to the PC serial port.
static void sendCommand (XsMessageId cmdId)
 Send a command to the MT and wait for a response.
static void handlePcCommand (char cmd)
 Handle a command from the PC.
static void mtMessageHandler (struct XbusMessage const *message)
 XbusParser callback function to handle received messages.
static void configurePcInterface (void)
 Configure the serial port used to communicate with the host PC.
static uint32_t readDeviceId (void)
 Read the device ID of the motion tracker.
static bool setOutputConfiguration (OutputConfiguration const *conf, uint8_t elements)
 Sets MT output configuration.
static bool configureMotionTracker (void)
 Sets the motion tracker output configuration based on the function of the attached device.
bool waitForWakeup (uint32_t timeout)
 Wait for a wakeup message from the MTi.
void sendWakeupAck (void)
 Send wakeup acknowledge message to MTi.
void restoreCommunication (void)
 Restore communication with the MTi.
static bool wakeupMotionTracker (void)
 Releases the MTi reset line and waits for a wakeup message.
static void printMessageData (struct XbusMessage const *message)
 Output the contents of a data message to the PC serial port.

Variables

static XbusParser * xbusParser
 XbusParser used to parse incoming Xbus messages from the MT.
MemoryPool< XbusMessage,
MEMORY_POOL_SIZE > 
g_messagePool
 Memory pool used for storing Xbus messages when passing them to the main thread.
MemoryPool< uint8_t[MAX_XBUS_DATA_SIZE],
MEMORY_POOL_SIZE > 
g_messageDataPool
 Memory pool used for storing the payload of Xbus messages.
Queue< XbusMessage,
DATA_QUEUE_SIZE > 
g_dataQueue
 Queue used to pass data messages to the main thread for processing.
Queue< XbusMessage,
RESPONSE_QUEUE_SIZE > 
g_responseQueue
 Queue used for passing all other messages to the main thread for processing.

Detailed Description

Copyright (C) Xsens Technologies B.V., 2015.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file main.cpp.


Function Documentation

static void* allocateMessageData ( size_t  bufSize ) [static]

Allocate message data buffer from the message data pool.

Definition at line 285 of file main.cpp.

static bool configureMotionTracker ( void   ) [static]

Sets the motion tracker output configuration based on the function of the attached device.

The output configuration depends on the type of MTi-1 device connected. An MTI-1 (IMU) device does not have an onboard orientation filter so cannot output quaternion data, only inertial and magnetic measurement data. MTi-2 and MTi-3 devices have an onboard filter so can send quaternions.

Definition at line 704 of file main.cpp.

static void configureMtCommunicationInterface ( void   ) [static]

Configure the serial port used for communication with the motion tracker.

Definition at line 340 of file main.cpp.

static void configurePcInterface ( void   ) [static]

Configure the serial port used to communicate with the host PC.

Definition at line 629 of file main.cpp.

static DigitalOut cs ( MT_nCS  ,
 
) [static]

Chip select line for the MT.

static void deallocateMessageData ( void const *  buffer ) [static]

Deallocate message data previously allocated from the message data pool.

Definition at line 294 of file main.cpp.

static XbusMessage const* doTransaction ( XbusMessage const *  m ) [static]

Send a message to the MT and wait for a response.

Returns:
Response message from the MT, or NULL is no response received within 500ms.

Blocking behaviour is implemented by waiting for a response to be written to the response queue by the XbusParser.

Definition at line 496 of file main.cpp.

static InterruptIn drdy ( MT_DRDY   ) [static]

Interrput line used by MT to signal that data is available.

static void dumpResponse ( XbusMessage const *  response ) [static]

Dump information from a message to the PC serial port.

Definition at line 535 of file main.cpp.

static void handlePcCommand ( char  cmd ) [static]

Handle a command from the PC.

The example application supports single character commands from the host PC to switch between configuration and measurement modes.

Definition at line 581 of file main.cpp.

static RawSerial mt ( MT_TX  ,
MT_RX   
) [static]

Serial port for communication with the MT.

We use a RawSerial port as the Stream inteface used by the regular Serial class can have problems with the RTOS when using interrupts.

static SPI mt ( MT_MOSI  ,
MT_MISO  ,
MT_SCLK   
) [static]

SPI master used for communication with the MT.

static I2C mt ( MT_SDA  ,
MT_SCL   
) [static]

I2C master used for communication with the MT.

static void mtLowLevelHandler ( void   ) [static]

RX Interrupt handler for the MT serial port.

Passes received data to an XbusParser to extract messages.

Definition at line 451 of file main.cpp.

static void mtMessageHandler ( struct XbusMessage const *  message ) [static]

XbusParser callback function to handle received messages.

Parameters:
messagePointer to the last received message.

In this example received messages are copied into one of two message queues for later handling by the main thread. Data messages are put in one queue, while all other responses are placed in the second queue. This is done so that data and other messages can be handled separately by the application code.

Definition at line 605 of file main.cpp.

static DigitalOut mtReset ( MT_NRESET  ,
 
) [static]

MT reset line.

MT is held in reset on startup.

static Serial pc ( PC_TX  ,
PC_RX   
) [static]

Serial port for communication with the host PC.

static void printMessageData ( struct XbusMessage const *  message ) [static]

Output the contents of a data message to the PC serial port.

Definition at line 850 of file main.cpp.

static uint32_t readDeviceId ( void   ) [static]

Read the device ID of the motion tracker.

Definition at line 638 of file main.cpp.

void restoreCommunication ( void   )

Restore communication with the MTi.

On bootup the MTi will listen for a magic byte to signal that it should return to default baudrate and output configuration. This can be used to recover from a bad or unknown configuration.

Definition at line 792 of file main.cpp.

static void sendCommand ( XsMessageId  cmdId ) [static]

Send a command to the MT and wait for a response.

Parameters:
cmdIdThe XsMessageId of the command to send.

Commands are simple messages without and payload data.

Definition at line 559 of file main.cpp.

static void sendMessage ( XbusMessage const *  m ) [static]

Send a message to the MT.

This function formats the message data and writes this to the MT I2C interface. It does not wait for any response.

This function formats the message data and writes this to the MT SPI interface. It does not wait for any response.

This function formats the message data and writes this to the MT serial port. It does not wait for any response.

Definition at line 356 of file main.cpp.

void sendWakeupAck ( void   )

Send wakeup acknowledge message to MTi.

Sending a wakeup acknowledge will cause the device to stay in configuration mode instead of automatically transitioning to measurement mode with the stored output configuration.

Definition at line 777 of file main.cpp.

static bool setOutputConfiguration ( OutputConfiguration const *  conf,
uint8_t  elements 
) [static]

Sets MT output configuration.

Parameters:
confPointer to an array of OutputConfiguration elements.
elementsThe number of elements in the configuration array.

The response from the device indicates the actual values that will be used by the motion tracker. These may differ from the requested parameters as the motion tracker validates the requested parameters before applying them.

Definition at line 664 of file main.cpp.

bool waitForWakeup ( uint32_t  timeout )

Wait for a wakeup message from the MTi.

Parameters:
timeoutTime to wait to receive the wakeup message.
Returns:
true if wakeup received within timeout, else false.

The MTi sends an XMID_Wakeup message once it has completed its bootup procedure. If this is acknowledged by an XMID_WakeupAck message then the MTi will stay in configuration mode. Otherwise it will automatically enter measurement mode with the stored output configuration.

Definition at line 758 of file main.cpp.

static bool wakeupMotionTracker ( void   ) [static]

Releases the MTi reset line and waits for a wakeup message.

If no wakeup message is received within 1 second the restore communications procedure is done to reset the MTi to default baudrate and output configuration.

Definition at line 816 of file main.cpp.


Variable Documentation

Queue<XbusMessage, DATA_QUEUE_SIZE> g_dataQueue

Queue used to pass data messages to the main thread for processing.

Definition at line 276 of file main.cpp.

MemoryPool<uint8_t[MAX_XBUS_DATA_SIZE], MEMORY_POOL_SIZE> g_messageDataPool

Memory pool used for storing the payload of Xbus messages.

Definition at line 272 of file main.cpp.

MemoryPool<XbusMessage, MEMORY_POOL_SIZE> g_messagePool

Memory pool used for storing Xbus messages when passing them to the main thread.

Definition at line 268 of file main.cpp.

Queue<XbusMessage, RESPONSE_QUEUE_SIZE> g_responseQueue

Queue used for passing all other messages to the main thread for processing.

Definition at line 280 of file main.cpp.

XbusParser* xbusParser [static]

XbusParser used to parse incoming Xbus messages from the MT.

Definition at line 262 of file main.cpp.