Basic implementation of Xbus message parsing and generation for embedded processors. The code has no dependencies and should also work for other MCU architectures than ARM provided a C99 compiler is available.

Dependents:   MTi-1_example_LPC1768 MTi-1_rikbeun MTi-1_example MTi-1_example

For an example of using the Xbus library to communicate with an MTi-1 series device using a full-duplex UART see:

Import programMTi-1_example

Example of using Xbus library to communicate with an MTi-1 series device using a full-duplex UART connection.

Committer:
tjerkhofmeijer
Date:
Fri Oct 02 16:22:33 2015 +0200
Revision:
1:c24f69a2eff4
Parent:
0:eb25b1785ee4
Xbus library is updated to support MTi 1-series' I2C and SPI interfaces

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tjerkhofmeijer 1:c24f69a2eff4 1 /*!
tjerkhofmeijer 1:c24f69a2eff4 2 * \file
tjerkhofmeijer 1:c24f69a2eff4 3 * \copyright Copyright (C) Xsens Technologies B.V., 2015.
tjerkhofmeijer 1:c24f69a2eff4 4 *
tjerkhofmeijer 1:c24f69a2eff4 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
tjerkhofmeijer 1:c24f69a2eff4 6 * use this file except in compliance with the License. You may obtain a copy
tjerkhofmeijer 1:c24f69a2eff4 7 * of the License at
tjerkhofmeijer 1:c24f69a2eff4 8 *
tjerkhofmeijer 1:c24f69a2eff4 9 * http://www.apache.org/licenses/LICENSE-2.0
tjerkhofmeijer 1:c24f69a2eff4 10 *
tjerkhofmeijer 1:c24f69a2eff4 11 * Unless required by applicable law or agreed to in writing, software
tjerkhofmeijer 1:c24f69a2eff4 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
tjerkhofmeijer 1:c24f69a2eff4 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
tjerkhofmeijer 1:c24f69a2eff4 14 * License for the specific language governing permissions and limitations
tjerkhofmeijer 1:c24f69a2eff4 15 * under the License.
tjerkhofmeijer 1:c24f69a2eff4 16 */
tjerkhofmeijer 1:c24f69a2eff4 17
tjerkhofmeijer 1:c24f69a2eff4 18 #ifndef __XBUSMESSAGE_H
tjerkhofmeijer 1:c24f69a2eff4 19 #define __XBUSMESSAGE_H
tjerkhofmeijer 1:c24f69a2eff4 20
tjerkhofmeijer 1:c24f69a2eff4 21 #include <stddef.h>
tjerkhofmeijer 1:c24f69a2eff4 22 #include <stdint.h>
tjerkhofmeijer 1:c24f69a2eff4 23 #include <stdbool.h>
tjerkhofmeijer 1:c24f69a2eff4 24
tjerkhofmeijer 1:c24f69a2eff4 25 #ifdef __cplusplus
tjerkhofmeijer 1:c24f69a2eff4 26 extern "C" {
tjerkhofmeijer 1:c24f69a2eff4 27 #endif
tjerkhofmeijer 1:c24f69a2eff4 28
tjerkhofmeijer 1:c24f69a2eff4 29 /*! \brief Xbus message IDs. */
tjerkhofmeijer 1:c24f69a2eff4 30 enum XsMessageId
tjerkhofmeijer 1:c24f69a2eff4 31 {
tjerkhofmeijer 1:c24f69a2eff4 32 XMID_Wakeup = 0x3E,
tjerkhofmeijer 1:c24f69a2eff4 33 XMID_WakeupAck = 0x3F,
tjerkhofmeijer 1:c24f69a2eff4 34 XMID_ReqDid = 0x00,
tjerkhofmeijer 1:c24f69a2eff4 35 XMID_DeviceId = 0x01,
tjerkhofmeijer 1:c24f69a2eff4 36 XMID_GotoConfig = 0x30,
tjerkhofmeijer 1:c24f69a2eff4 37 XMID_GotoConfigAck = 0x31,
tjerkhofmeijer 1:c24f69a2eff4 38 XMID_GotoMeasurement = 0x10,
tjerkhofmeijer 1:c24f69a2eff4 39 XMID_GotoMeasurementAck = 0x11,
tjerkhofmeijer 1:c24f69a2eff4 40 XMID_MtData2 = 0x36,
tjerkhofmeijer 1:c24f69a2eff4 41 XMID_ReqOutputConfig = 0xC0,
tjerkhofmeijer 1:c24f69a2eff4 42 XMID_SetOutputConfig = 0xC0,
tjerkhofmeijer 1:c24f69a2eff4 43 XMID_OutputConfig = 0xC1,
tjerkhofmeijer 1:c24f69a2eff4 44 XMID_Reset = 0x40,
tjerkhofmeijer 1:c24f69a2eff4 45 XMID_ResetAck = 0x41,
tjerkhofmeijer 1:c24f69a2eff4 46 XMID_Error = 0x42,
tjerkhofmeijer 1:c24f69a2eff4 47 };
tjerkhofmeijer 1:c24f69a2eff4 48
tjerkhofmeijer 1:c24f69a2eff4 49 /*! \brief Xbus data message type IDs. */
tjerkhofmeijer 1:c24f69a2eff4 50 enum XsDataIdentifier
tjerkhofmeijer 1:c24f69a2eff4 51 {
tjerkhofmeijer 1:c24f69a2eff4 52 XDI_PacketCounter = 0x1020,
tjerkhofmeijer 1:c24f69a2eff4 53 XDI_SampleTimeFine = 0x1060,
tjerkhofmeijer 1:c24f69a2eff4 54 XDI_Quaternion = 0x2010,
tjerkhofmeijer 1:c24f69a2eff4 55 XDI_DeltaV = 0x4010,
tjerkhofmeijer 1:c24f69a2eff4 56 XDI_Acceleration = 0x4020,
tjerkhofmeijer 1:c24f69a2eff4 57 XDI_RateOfTurn = 0x8020,
tjerkhofmeijer 1:c24f69a2eff4 58 XDI_DeltaQ = 0x8030,
tjerkhofmeijer 1:c24f69a2eff4 59 XDI_MagneticField = 0xC020,
tjerkhofmeijer 1:c24f69a2eff4 60 XDI_StatusWord = 0xE020,
tjerkhofmeijer 1:c24f69a2eff4 61 };
tjerkhofmeijer 1:c24f69a2eff4 62
tjerkhofmeijer 1:c24f69a2eff4 63 /*!
tjerkhofmeijer 1:c24f69a2eff4 64 * \brief Low level format to use when formating Xbus messages for transmission.
tjerkhofmeijer 1:c24f69a2eff4 65 */
tjerkhofmeijer 1:c24f69a2eff4 66 enum XbusLowLevelFormat
tjerkhofmeijer 1:c24f69a2eff4 67 {
tjerkhofmeijer 1:c24f69a2eff4 68 /*! \brief Format for use with I2C interface. */
tjerkhofmeijer 1:c24f69a2eff4 69 XLLF_I2c,
tjerkhofmeijer 1:c24f69a2eff4 70 /*! \brief Format for use with SPI interface. */
tjerkhofmeijer 1:c24f69a2eff4 71 XLLF_Spi,
tjerkhofmeijer 1:c24f69a2eff4 72 /*! \brief Format for use with UART interface. */
tjerkhofmeijer 1:c24f69a2eff4 73 XLLF_Uart
tjerkhofmeijer 1:c24f69a2eff4 74 };
tjerkhofmeijer 1:c24f69a2eff4 75
tjerkhofmeijer 1:c24f69a2eff4 76 /*!
tjerkhofmeijer 1:c24f69a2eff4 77 * \brief An Xbus message structure with optional payload.
tjerkhofmeijer 1:c24f69a2eff4 78 */
tjerkhofmeijer 1:c24f69a2eff4 79 struct XbusMessage
tjerkhofmeijer 1:c24f69a2eff4 80 {
tjerkhofmeijer 1:c24f69a2eff4 81 /*! \brief The message ID of the message. */
tjerkhofmeijer 1:c24f69a2eff4 82 enum XsMessageId mid;
tjerkhofmeijer 1:c24f69a2eff4 83 /*!
tjerkhofmeijer 1:c24f69a2eff4 84 * \brief The length of the payload.
tjerkhofmeijer 1:c24f69a2eff4 85 *
tjerkhofmeijer 1:c24f69a2eff4 86 * \note The meaning of the length is message dependent. For example,
tjerkhofmeijer 1:c24f69a2eff4 87 * for XMID_OutputConfig messages it is the number of OutputConfiguration
tjerkhofmeijer 1:c24f69a2eff4 88 * elements in the configuration array.
tjerkhofmeijer 1:c24f69a2eff4 89 */
tjerkhofmeijer 1:c24f69a2eff4 90 uint16_t length;
tjerkhofmeijer 1:c24f69a2eff4 91 /*! \brief Pointer to the payload data. */
tjerkhofmeijer 1:c24f69a2eff4 92 void* data;
tjerkhofmeijer 1:c24f69a2eff4 93 };
tjerkhofmeijer 1:c24f69a2eff4 94
tjerkhofmeijer 1:c24f69a2eff4 95 /*!
tjerkhofmeijer 1:c24f69a2eff4 96 * \brief Output configuration structure.
tjerkhofmeijer 1:c24f69a2eff4 97 */
tjerkhofmeijer 1:c24f69a2eff4 98 struct OutputConfiguration
tjerkhofmeijer 1:c24f69a2eff4 99 {
tjerkhofmeijer 1:c24f69a2eff4 100 /*! \brief Data type of the output. */
tjerkhofmeijer 1:c24f69a2eff4 101 enum XsDataIdentifier dtype;
tjerkhofmeijer 1:c24f69a2eff4 102 /*!
tjerkhofmeijer 1:c24f69a2eff4 103 * \brief The output frequency in Hz, or 65535 if the value should be
tjerkhofmeijer 1:c24f69a2eff4 104 * included in every data message.
tjerkhofmeijer 1:c24f69a2eff4 105 */
tjerkhofmeijer 1:c24f69a2eff4 106 uint16_t freq;
tjerkhofmeijer 1:c24f69a2eff4 107 };
tjerkhofmeijer 1:c24f69a2eff4 108
tjerkhofmeijer 1:c24f69a2eff4 109 size_t XbusMessage_format(uint8_t* raw, struct XbusMessage const* message, enum XbusLowLevelFormat format);
tjerkhofmeijer 1:c24f69a2eff4 110 bool XbusMessage_getDataItem(void* item, enum XsDataIdentifier id, struct XbusMessage const* message);
tjerkhofmeijer 1:c24f69a2eff4 111 char const* XbusMessage_dataDescription(enum XsDataIdentifier id);
tjerkhofmeijer 1:c24f69a2eff4 112
tjerkhofmeijer 1:c24f69a2eff4 113 #ifdef __cplusplus
tjerkhofmeijer 1:c24f69a2eff4 114 }
tjerkhofmeijer 1:c24f69a2eff4 115 #endif // extern "C"
tjerkhofmeijer 1:c24f69a2eff4 116
tjerkhofmeijer 1:c24f69a2eff4 117 #endif // __XBUSMESSAGE_H