Port of the FreeModbus Libary for mbed, copied from https://developer.mbed.org/users/cam/code/Modbus/ and upgraded to mbed 5

Dependents:   NUCLEO-F401-printf

Committer:
Rajit Singh
Date:
Wed Aug 16 17:31:26 2017 +0100
Revision:
1:3e360cf155b6
Parent:
0:9db3bed8fffd
Remove main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rajit Singh 0:9db3bed8fffd 1 /*
Rajit Singh 0:9db3bed8fffd 2 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
Rajit Singh 0:9db3bed8fffd 3 * Copyright (c) 2006 Christian Walter <wolti@sil.at>
Rajit Singh 0:9db3bed8fffd 4 * All rights reserved.
Rajit Singh 0:9db3bed8fffd 5 *
Rajit Singh 0:9db3bed8fffd 6 * Redistribution and use in source and binary forms, with or without
Rajit Singh 0:9db3bed8fffd 7 * modification, are permitted provided that the following conditions
Rajit Singh 0:9db3bed8fffd 8 * are met:
Rajit Singh 0:9db3bed8fffd 9 * 1. Redistributions of source code must retain the above copyright
Rajit Singh 0:9db3bed8fffd 10 * notice, this list of conditions and the following disclaimer.
Rajit Singh 0:9db3bed8fffd 11 * 2. Redistributions in binary form must reproduce the above copyright
Rajit Singh 0:9db3bed8fffd 12 * notice, this list of conditions and the following disclaimer in the
Rajit Singh 0:9db3bed8fffd 13 * documentation and/or other materials provided with the distribution.
Rajit Singh 0:9db3bed8fffd 14 * 3. The name of the author may not be used to endorse or promote products
Rajit Singh 0:9db3bed8fffd 15 * derived from this software without specific prior written permission.
Rajit Singh 0:9db3bed8fffd 16 *
Rajit Singh 0:9db3bed8fffd 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Rajit Singh 0:9db3bed8fffd 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Rajit Singh 0:9db3bed8fffd 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Rajit Singh 0:9db3bed8fffd 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Rajit Singh 0:9db3bed8fffd 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Rajit Singh 0:9db3bed8fffd 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Rajit Singh 0:9db3bed8fffd 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Rajit Singh 0:9db3bed8fffd 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Rajit Singh 0:9db3bed8fffd 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Rajit Singh 0:9db3bed8fffd 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Rajit Singh 0:9db3bed8fffd 27 *
Rajit Singh 0:9db3bed8fffd 28 * File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
Rajit Singh 0:9db3bed8fffd 29 */
Rajit Singh 0:9db3bed8fffd 30
Rajit Singh 0:9db3bed8fffd 31 #ifndef _MB_UTILS_H
Rajit Singh 0:9db3bed8fffd 32 #define _MB_UTILS_H
Rajit Singh 0:9db3bed8fffd 33
Rajit Singh 0:9db3bed8fffd 34 #ifdef __cplusplus
Rajit Singh 0:9db3bed8fffd 35 PR_BEGIN_EXTERN_C
Rajit Singh 0:9db3bed8fffd 36 #endif
Rajit Singh 0:9db3bed8fffd 37 /*! \defgroup modbus_utils Utilities
Rajit Singh 0:9db3bed8fffd 38 *
Rajit Singh 0:9db3bed8fffd 39 * This module contains some utility functions which can be used by
Rajit Singh 0:9db3bed8fffd 40 * the application. It includes some special functions for working with
Rajit Singh 0:9db3bed8fffd 41 * bitfields backed by a character array buffer.
Rajit Singh 0:9db3bed8fffd 42 *
Rajit Singh 0:9db3bed8fffd 43 */
Rajit Singh 0:9db3bed8fffd 44 /*! \addtogroup modbus_utils
Rajit Singh 0:9db3bed8fffd 45 * @{
Rajit Singh 0:9db3bed8fffd 46 */
Rajit Singh 0:9db3bed8fffd 47 /*! \brief Function to set bits in a byte buffer.
Rajit Singh 0:9db3bed8fffd 48 *
Rajit Singh 0:9db3bed8fffd 49 * This function allows the efficient use of an array to implement bitfields.
Rajit Singh 0:9db3bed8fffd 50 * The array used for storing the bits must always be a multiple of two
Rajit Singh 0:9db3bed8fffd 51 * bytes. Up to eight bits can be set or cleared in one operation.
Rajit Singh 0:9db3bed8fffd 52 *
Rajit Singh 0:9db3bed8fffd 53 * \param ucByteBuf A buffer where the bit values are stored. Must be a
Rajit Singh 0:9db3bed8fffd 54 * multiple of 2 bytes. No length checking is performed and if
Rajit Singh 0:9db3bed8fffd 55 * usBitOffset / 8 is greater than the size of the buffer memory contents
Rajit Singh 0:9db3bed8fffd 56 * is overwritten.
Rajit Singh 0:9db3bed8fffd 57 * \param usBitOffset The starting address of the bits to set. The first
Rajit Singh 0:9db3bed8fffd 58 * bit has the offset 0.
Rajit Singh 0:9db3bed8fffd 59 * \param ucNBits Number of bits to modify. The value must always be smaller
Rajit Singh 0:9db3bed8fffd 60 * than 8.
Rajit Singh 0:9db3bed8fffd 61 * \param ucValues Thew new values for the bits. The value for the first bit
Rajit Singh 0:9db3bed8fffd 62 * starting at <code>usBitOffset</code> is the LSB of the value
Rajit Singh 0:9db3bed8fffd 63 * <code>ucValues</code>
Rajit Singh 0:9db3bed8fffd 64 *
Rajit Singh 0:9db3bed8fffd 65 * \code
Rajit Singh 0:9db3bed8fffd 66 * ucBits[2] = {0, 0};
Rajit Singh 0:9db3bed8fffd 67 *
Rajit Singh 0:9db3bed8fffd 68 * // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
Rajit Singh 0:9db3bed8fffd 69 * xMBUtilSetBits( ucBits, 4, 1, 1 );
Rajit Singh 0:9db3bed8fffd 70 *
Rajit Singh 0:9db3bed8fffd 71 * // Set bit 7 to 1 and bit 8 to 0.
Rajit Singh 0:9db3bed8fffd 72 * xMBUtilSetBits( ucBits, 7, 2, 0x01 );
Rajit Singh 0:9db3bed8fffd 73 *
Rajit Singh 0:9db3bed8fffd 74 * // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
Rajit Singh 0:9db3bed8fffd 75 * xMBUtilSetBits( ucBits, 8, 8, 0x5A);
Rajit Singh 0:9db3bed8fffd 76 * \endcode
Rajit Singh 0:9db3bed8fffd 77 */
Rajit Singh 0:9db3bed8fffd 78 void xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset,
Rajit Singh 0:9db3bed8fffd 79 UCHAR ucNBits, UCHAR ucValues );
Rajit Singh 0:9db3bed8fffd 80
Rajit Singh 0:9db3bed8fffd 81 /*! \brief Function to read bits in a byte buffer.
Rajit Singh 0:9db3bed8fffd 82 *
Rajit Singh 0:9db3bed8fffd 83 * This function is used to extract up bit values from an array. Up to eight
Rajit Singh 0:9db3bed8fffd 84 * bit values can be extracted in one step.
Rajit Singh 0:9db3bed8fffd 85 *
Rajit Singh 0:9db3bed8fffd 86 * \param ucByteBuf A buffer where the bit values are stored.
Rajit Singh 0:9db3bed8fffd 87 * \param usBitOffset The starting address of the bits to set. The first
Rajit Singh 0:9db3bed8fffd 88 * bit has the offset 0.
Rajit Singh 0:9db3bed8fffd 89 * \param ucNBits Number of bits to modify. The value must always be smaller
Rajit Singh 0:9db3bed8fffd 90 * than 8.
Rajit Singh 0:9db3bed8fffd 91 *
Rajit Singh 0:9db3bed8fffd 92 * \code
Rajit Singh 0:9db3bed8fffd 93 * UCHAR ucBits[2] = {0, 0};
Rajit Singh 0:9db3bed8fffd 94 * UCHAR ucResult;
Rajit Singh 0:9db3bed8fffd 95 *
Rajit Singh 0:9db3bed8fffd 96 * // Extract the bits 3 - 10.
Rajit Singh 0:9db3bed8fffd 97 * ucResult = xMBUtilGetBits( ucBits, 3, 8 );
Rajit Singh 0:9db3bed8fffd 98 * \endcode
Rajit Singh 0:9db3bed8fffd 99 */
Rajit Singh 0:9db3bed8fffd 100 UCHAR xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset,
Rajit Singh 0:9db3bed8fffd 101 UCHAR ucNBits );
Rajit Singh 0:9db3bed8fffd 102
Rajit Singh 0:9db3bed8fffd 103 /*! @} */
Rajit Singh 0:9db3bed8fffd 104
Rajit Singh 0:9db3bed8fffd 105 #ifdef __cplusplus
Rajit Singh 0:9db3bed8fffd 106 PR_END_EXTERN_C
Rajit Singh 0:9db3bed8fffd 107 #endif
Rajit Singh 0:9db3bed8fffd 108 #endif