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:
alexandery
Date:
Tue Jun 16 07:54:23 2015 +0000
Revision:
0:eb25b1785ee4
Make Xbus code into a library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexandery 0:eb25b1785ee4 1 /*!
alexandery 0:eb25b1785ee4 2 * \file
alexandery 0:eb25b1785ee4 3 * \copyright Copyright (C) Xsens Technologies B.V., 2015.
alexandery 0:eb25b1785ee4 4 *
alexandery 0:eb25b1785ee4 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
alexandery 0:eb25b1785ee4 6 * use this file except in compliance with the License. You may obtain a copy
alexandery 0:eb25b1785ee4 7 * of the License at
alexandery 0:eb25b1785ee4 8 *
alexandery 0:eb25b1785ee4 9 * http://www.apache.org/licenses/LICENSE-2.0
alexandery 0:eb25b1785ee4 10 *
alexandery 0:eb25b1785ee4 11 * Unless required by applicable law or agreed to in writing, software
alexandery 0:eb25b1785ee4 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
alexandery 0:eb25b1785ee4 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
alexandery 0:eb25b1785ee4 14 * License for the specific language governing permissions and limitations
alexandery 0:eb25b1785ee4 15 * under the License.
alexandery 0:eb25b1785ee4 16 */
alexandery 0:eb25b1785ee4 17
alexandery 0:eb25b1785ee4 18 #ifndef __XBUSPARSER_H
alexandery 0:eb25b1785ee4 19 #define __XBUSPARSER_H
alexandery 0:eb25b1785ee4 20
alexandery 0:eb25b1785ee4 21 #include <stddef.h>
alexandery 0:eb25b1785ee4 22 #include <stdint.h>
alexandery 0:eb25b1785ee4 23 #include "xbusmessage.h"
alexandery 0:eb25b1785ee4 24
alexandery 0:eb25b1785ee4 25 #ifdef __cplusplus
alexandery 0:eb25b1785ee4 26 extern "C" {
alexandery 0:eb25b1785ee4 27 #endif
alexandery 0:eb25b1785ee4 28
alexandery 0:eb25b1785ee4 29 struct XbusParser;
alexandery 0:eb25b1785ee4 30
alexandery 0:eb25b1785ee4 31 /*!
alexandery 0:eb25b1785ee4 32 * \brief Callback function structure for use with the XbusParser.
alexandery 0:eb25b1785ee4 33 */
alexandery 0:eb25b1785ee4 34 struct XbusParserCallback
alexandery 0:eb25b1785ee4 35 {
alexandery 0:eb25b1785ee4 36 /*!
alexandery 0:eb25b1785ee4 37 * \brief Allocate a buffer for message reception.
alexandery 0:eb25b1785ee4 38 * \param bufSize The size of the buffer to allocate.
alexandery 0:eb25b1785ee4 39 * \returns Pointer to buffer to use for message reception, or NULL if
alexandery 0:eb25b1785ee4 40 * a buffer cannot be allocated.
alexandery 0:eb25b1785ee4 41 *
alexandery 0:eb25b1785ee4 42 * \note It is the resposibility of the user to deallocate the message
alexandery 0:eb25b1785ee4 43 * data buffers pointed to by XbusMessage structures passed to the
alexandery 0:eb25b1785ee4 44 * handleMessage() callback function.
alexandery 0:eb25b1785ee4 45 */
alexandery 0:eb25b1785ee4 46 void* (*allocateBuffer)(size_t bufSize);
alexandery 0:eb25b1785ee4 47
alexandery 0:eb25b1785ee4 48 /*!
alexandery 0:eb25b1785ee4 49 * \brief Deallocate a buffer that was previously allocated by a call to
alexandery 0:eb25b1785ee4 50 * allocateBuffer.
alexandery 0:eb25b1785ee4 51 */
alexandery 0:eb25b1785ee4 52 void (*deallocateBuffer)(void const* buffer);
alexandery 0:eb25b1785ee4 53
alexandery 0:eb25b1785ee4 54 /*!
alexandery 0:eb25b1785ee4 55 * \brief Handle a received message.
alexandery 0:eb25b1785ee4 56 *
alexandery 0:eb25b1785ee4 57 * \note If the passed XbusMessage structure has a non-null data pointer
alexandery 0:eb25b1785ee4 58 * then it is the responsibility of the user to free this once handling
alexandery 0:eb25b1785ee4 59 * of the message is complete.
alexandery 0:eb25b1785ee4 60 */
alexandery 0:eb25b1785ee4 61 void (*handleMessage)(struct XbusMessage const* message);
alexandery 0:eb25b1785ee4 62 };
alexandery 0:eb25b1785ee4 63
alexandery 0:eb25b1785ee4 64 size_t XbusParser_mem(void);
alexandery 0:eb25b1785ee4 65 struct XbusParser* XbusParser_create(struct XbusParserCallback const* callback);
alexandery 0:eb25b1785ee4 66 void XbusParser_destroy(struct XbusParser* parser);
alexandery 0:eb25b1785ee4 67 struct XbusParser* XbusParser_init(void* parserMem, struct XbusParserCallback const* callback);
alexandery 0:eb25b1785ee4 68
alexandery 0:eb25b1785ee4 69 void XbusParser_parseByte(struct XbusParser* parser, uint8_t byte);
alexandery 0:eb25b1785ee4 70 void XbusParser_parseBuffer(struct XbusParser* parser, uint8_t const* buf, size_t bufSize);
alexandery 0:eb25b1785ee4 71
alexandery 0:eb25b1785ee4 72 #ifdef __cplusplus
alexandery 0:eb25b1785ee4 73 }
alexandery 0:eb25b1785ee4 74 #endif // extern "C"
alexandery 0:eb25b1785ee4 75
alexandery 0:eb25b1785ee4 76 #endif // __XBUSPARSER_H