diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-21 21:23:18 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-21 21:23:18 +0000 |
commit | d9714b556703561a0abcbe71970b1cd6922168a6 (patch) | |
tree | 70b7893243b8ee2e6b8b5fd95106c4ab962699c5 /apps/modbus/functions/mbutils.c | |
parent | ebf70f8a79eb8ef23bc1d99938768ef06c466119 (diff) | |
download | nuttx-d9714b556703561a0abcbe71970b1cd6922168a6.tar.gz nuttx-d9714b556703561a0abcbe71970b1cd6922168a6.tar.bz2 nuttx-d9714b556703561a0abcbe71970b1cd6922168a6.zip |
Use NuttX types in FreeModBus port; Add FreeModBus demo at apps/examples/modbus; Add new termios APIs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4964 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/modbus/functions/mbutils.c')
-rw-r--r-- | apps/modbus/functions/mbutils.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/apps/modbus/functions/mbutils.c b/apps/modbus/functions/mbutils.c index 992333565..cbe02872b 100644 --- a/apps/modbus/functions/mbutils.c +++ b/apps/modbus/functions/mbutils.c @@ -42,69 +42,69 @@ #include <apps/modbus/mbproto.h> /* ----------------------- Defines ------------------------------------------*/ -#define BITS_UCHAR 8U +#define BITS_uint8_t 8U /* ----------------------- Start implementation -----------------------------*/ void -xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits, - UCHAR ucValue ) +xMBUtilSetBits( uint8_t * ucByteBuf, uint16_t usBitOffset, uint8_t ucNBits, + uint8_t ucValue ) { - USHORT usWordBuf; - USHORT usMask; - USHORT usByteOffset; - USHORT usNPreBits; - USHORT usValue = ucValue; + uint16_t usWordBuf; + uint16_t usMask; + uint16_t usByteOffset; + uint16_t usNPreBits; + uint16_t usValue = ucValue; ASSERT( ucNBits <= 8 ); - ASSERT( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 ); + ASSERT( ( size_t )BITS_uint8_t == sizeof( uint8_t ) * 8 ); /* Calculate byte offset for first byte containing the bit values starting * at usBitOffset. */ - usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR ); + usByteOffset = ( uint16_t )( ( usBitOffset ) / BITS_uint8_t ); /* How many bits precede our bits to set. */ - usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR ); + usNPreBits = ( uint16_t )( usBitOffset - usByteOffset * BITS_uint8_t ); /* Move bit field into position over bits to set */ usValue <<= usNPreBits; /* Prepare a mask for setting the new bits. */ - usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 ); - usMask <<= usBitOffset - usByteOffset * BITS_UCHAR; + usMask = ( uint16_t )( ( 1 << ( uint16_t ) ucNBits ) - 1 ); + usMask <<= usBitOffset - usByteOffset * BITS_uint8_t; /* copy bits into temporary storage. */ usWordBuf = ucByteBuf[usByteOffset]; - usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR; + usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_uint8_t; /* Zero out bit field bits and then or value bits into them. */ - usWordBuf = ( USHORT )( ( usWordBuf & ( ~usMask ) ) | usValue ); + usWordBuf = ( uint16_t )( ( usWordBuf & ( ~usMask ) ) | usValue ); /* move bits back into storage */ - ucByteBuf[usByteOffset] = ( UCHAR )( usWordBuf & 0xFF ); - ucByteBuf[usByteOffset + 1] = ( UCHAR )( usWordBuf >> BITS_UCHAR ); + ucByteBuf[usByteOffset] = ( uint8_t )( usWordBuf & 0xFF ); + ucByteBuf[usByteOffset + 1] = ( uint8_t )( usWordBuf >> BITS_uint8_t ); } -UCHAR -xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits ) +uint8_t +xMBUtilGetBits( uint8_t * ucByteBuf, uint16_t usBitOffset, uint8_t ucNBits ) { - USHORT usWordBuf; - USHORT usMask; - USHORT usByteOffset; - USHORT usNPreBits; + uint16_t usWordBuf; + uint16_t usMask; + uint16_t usByteOffset; + uint16_t usNPreBits; /* Calculate byte offset for first byte containing the bit values starting * at usBitOffset. */ - usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR ); + usByteOffset = ( uint16_t )( ( usBitOffset ) / BITS_uint8_t ); /* How many bits precede our bits to set. */ - usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR ); + usNPreBits = ( uint16_t )( usBitOffset - usByteOffset * BITS_uint8_t ); /* Prepare a mask for setting the new bits. */ - usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 ); + usMask = ( uint16_t )( ( 1 << ( uint16_t ) ucNBits ) - 1 ); /* copy bits into temporary storage. */ usWordBuf = ucByteBuf[usByteOffset]; - usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR; + usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_uint8_t; /* throw away unneeded bits. */ usWordBuf >>= usNPreBits; @@ -112,7 +112,7 @@ xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits ) /* mask away bits above the requested bitfield. */ usWordBuf &= usMask; - return ( UCHAR ) usWordBuf; + return ( uint8_t ) usWordBuf; } eMBException |