Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbutils.h
00001 /* 00002 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 00003 * Copyright (c) 2006 Christian Walter <wolti@sil.at> 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * 00028 * File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $ 00029 */ 00030 00031 #ifndef _MB_UTILS_H 00032 #define _MB_UTILS_H 00033 00034 #ifdef __cplusplus 00035 PR_BEGIN_EXTERN_C 00036 #endif 00037 /*! \defgroup modbus_utils Utilities 00038 * 00039 * This module contains some utility functions which can be used by 00040 * the application. It includes some special functions for working with 00041 * bitfields backed by a character array buffer. 00042 * 00043 */ 00044 /*! \addtogroup modbus_utils 00045 * @{ 00046 */ 00047 /*! \brief Function to set bits in a byte buffer. 00048 * 00049 * This function allows the efficient use of an array to implement bitfields. 00050 * The array used for storing the bits must always be a multiple of two 00051 * bytes. Up to eight bits can be set or cleared in one operation. 00052 * 00053 * \param ucByteBuf A buffer where the bit values are stored. Must be a 00054 * multiple of 2 bytes. No length checking is performed and if 00055 * usBitOffset / 8 is greater than the size of the buffer memory contents 00056 * is overwritten. 00057 * \param usBitOffset The starting address of the bits to set. The first 00058 * bit has the offset 0. 00059 * \param ucNBits Number of bits to modify. The value must always be smaller 00060 * than 8. 00061 * \param ucValues Thew new values for the bits. The value for the first bit 00062 * starting at <code>usBitOffset</code> is the LSB of the value 00063 * <code>ucValues</code> 00064 * 00065 * \code 00066 * ucBits[2] = {0, 0}; 00067 * 00068 * // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1) 00069 * xMBUtilSetBits( ucBits, 4, 1, 1 ); 00070 * 00071 * // Set bit 7 to 1 and bit 8 to 0. 00072 * xMBUtilSetBits( ucBits, 7, 2, 0x01 ); 00073 * 00074 * // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A; 00075 * xMBUtilSetBits( ucBits, 8, 8, 0x5A); 00076 * \endcode 00077 */ 00078 void xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, 00079 UCHAR ucNBits, UCHAR ucValues ); 00080 00081 /*! \brief Function to read bits in a byte buffer. 00082 * 00083 * This function is used to extract up bit values from an array. Up to eight 00084 * bit values can be extracted in one step. 00085 * 00086 * \param ucByteBuf A buffer where the bit values are stored. 00087 * \param usBitOffset The starting address of the bits to set. The first 00088 * bit has the offset 0. 00089 * \param ucNBits Number of bits to modify. The value must always be smaller 00090 * than 8. 00091 * 00092 * \code 00093 * UCHAR ucBits[2] = {0, 0}; 00094 * UCHAR ucResult; 00095 * 00096 * // Extract the bits 3 - 10. 00097 * ucResult = xMBUtilGetBits( ucBits, 3, 8 ); 00098 * \endcode 00099 */ 00100 UCHAR xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, 00101 UCHAR ucNBits ); 00102 00103 /*! @} */ 00104 00105 #ifdef __cplusplus 00106 PR_END_EXTERN_C 00107 #endif 00108 #endif
Generated on Tue Jul 12 2022 20:43:26 by
1.7.2