diff options
Diffstat (limited to 'apps/modbus/rtu')
-rw-r--r-- | apps/modbus/rtu/mbcrc.c | 16 | ||||
-rw-r--r-- | apps/modbus/rtu/mbcrc.h | 2 | ||||
-rw-r--r-- | apps/modbus/rtu/mbrtu.c | 68 | ||||
-rw-r--r-- | apps/modbus/rtu/mbrtu.h | 14 |
4 files changed, 50 insertions, 50 deletions
diff --git a/apps/modbus/rtu/mbcrc.c b/apps/modbus/rtu/mbcrc.c index 29b9ea765..82fe3c3fb 100644 --- a/apps/modbus/rtu/mbcrc.c +++ b/apps/modbus/rtu/mbcrc.c @@ -31,7 +31,7 @@ /* ----------------------- Platform includes --------------------------------*/ #include "port.h" -static const UCHAR aucCRCHi[] = { +static const uint8_t aucCRCHi[] = { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, @@ -56,7 +56,7 @@ static const UCHAR aucCRCHi[] = { 0x00, 0xC1, 0x81, 0x40 }; -static const UCHAR aucCRCLo[] = { +static const uint8_t aucCRCLo[] = { 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, @@ -81,18 +81,18 @@ static const UCHAR aucCRCLo[] = { 0x41, 0x81, 0x80, 0x40 }; -USHORT -usMBCRC16( UCHAR * pucFrame, USHORT usLen ) +uint16_t +usMBCRC16( uint8_t * pucFrame, uint16_t usLen ) { - UCHAR ucCRCHi = 0xFF; - UCHAR ucCRCLo = 0xFF; + uint8_t ucCRCHi = 0xFF; + uint8_t ucCRCLo = 0xFF; int iIndex; while( usLen-- ) { iIndex = ucCRCLo ^ *( pucFrame++ ); - ucCRCLo = ( UCHAR )( ucCRCHi ^ aucCRCHi[iIndex] ); + ucCRCLo = ( uint8_t )( ucCRCHi ^ aucCRCHi[iIndex] ); ucCRCHi = aucCRCLo[iIndex]; } - return ( USHORT )( ucCRCHi << 8 | ucCRCLo ); + return ( uint16_t )( ucCRCHi << 8 | ucCRCLo ); } diff --git a/apps/modbus/rtu/mbcrc.h b/apps/modbus/rtu/mbcrc.h index db227763f..9ff06e25d 100644 --- a/apps/modbus/rtu/mbcrc.h +++ b/apps/modbus/rtu/mbcrc.h @@ -31,6 +31,6 @@ #ifndef _MB_CRC_H #define _MB_CRC_H -USHORT usMBCRC16( UCHAR * pucFrame, USHORT usLen ); +uint16_t usMBCRC16( uint8_t * pucFrame, uint16_t usLen ); #endif diff --git a/apps/modbus/rtu/mbrtu.c b/apps/modbus/rtu/mbrtu.c index 8959b66f7..1c2f02a8b 100644 --- a/apps/modbus/rtu/mbrtu.c +++ b/apps/modbus/rtu/mbrtu.c @@ -71,25 +71,25 @@ typedef enum static volatile eMBSndState eSndState; static volatile eMBRcvState eRcvState; -volatile UCHAR ucRTUBuf[MB_SER_PDU_SIZE_MAX]; +volatile uint8_t ucRTUBuf[MB_SER_PDU_SIZE_MAX]; -static volatile UCHAR *pucSndBufferCur; -static volatile USHORT usSndBufferCount; +static volatile uint8_t *pucSndBufferCur; +static volatile uint16_t usSndBufferCount; -static volatile USHORT usRcvBufferPos; +static volatile uint16_t usRcvBufferPos; /* ----------------------- Start implementation -----------------------------*/ eMBErrorCode -eMBRTUInit( UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity ) +eMBRTUInit( uint8_t ucSlaveAddress, uint8_t ucPort, uint32_t ulBaudRate, eMBParity eParity ) { eMBErrorCode eStatus = MB_ENOERR; - ULONG usTimerT35_50us; + uint32_t usTimerT35_50us; ( void )ucSlaveAddress; ENTER_CRITICAL_SECTION( ); /* Modbus RTU uses 8 Databits. */ - if( xMBPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != TRUE ) + if( xMBPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != true ) { eStatus = MB_EPORTERR; } @@ -114,7 +114,7 @@ eMBRTUInit( UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity ePar */ usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate ); } - if( xMBPortTimersInit( ( USHORT ) usTimerT35_50us ) != TRUE ) + if( xMBPortTimersInit( ( uint16_t ) usTimerT35_50us ) != true ) { eStatus = MB_EPORTERR; } @@ -134,7 +134,7 @@ eMBRTUStart( void ) * modbus protocol stack until the bus is free. */ eRcvState = STATE_RX_INIT; - vMBPortSerialEnable( TRUE, FALSE ); + vMBPortSerialEnable( true, false ); vMBPortTimersEnable( ); EXIT_CRITICAL_SECTION( ); @@ -144,15 +144,15 @@ void eMBRTUStop( void ) { ENTER_CRITICAL_SECTION( ); - vMBPortSerialEnable( FALSE, FALSE ); + vMBPortSerialEnable( false, false ); vMBPortTimersDisable( ); EXIT_CRITICAL_SECTION( ); } eMBErrorCode -eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ) +eMBRTUReceive( uint8_t * pucRcvAddress, uint8_t ** pucFrame, uint16_t * pusLength ) { - BOOL xFrameReceived = FALSE; + bool xFrameReceived = false; eMBErrorCode eStatus = MB_ENOERR; ENTER_CRITICAL_SECTION( ); @@ -160,7 +160,7 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ) /* Length and CRC check */ if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN ) - && ( usMBCRC16( ( UCHAR * ) ucRTUBuf, usRcvBufferPos ) == 0 ) ) + && ( usMBCRC16( ( uint8_t * ) ucRTUBuf, usRcvBufferPos ) == 0 ) ) { /* Save the address field. All frames are passed to the upper layed * and the decision if a frame is used is done there. @@ -170,11 +170,11 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ) /* Total length of Modbus-PDU is Modbus-Serial-Line-PDU minus * size of address field and CRC checksum. */ - *pusLength = ( USHORT )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC ); + *pusLength = ( uint16_t )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC ); /* Return the start of the Modbus PDU to the caller. */ - *pucFrame = ( UCHAR * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF]; - xFrameReceived = TRUE; + *pucFrame = ( uint8_t * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF]; + xFrameReceived = true; } else { @@ -186,10 +186,10 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ) } eMBErrorCode -eMBRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength ) +eMBRTUSend( uint8_t ucSlaveAddress, const uint8_t * pucFrame, uint16_t usLength ) { eMBErrorCode eStatus = MB_ENOERR; - USHORT usCRC16; + uint16_t usCRC16; ENTER_CRITICAL_SECTION( ); @@ -200,7 +200,7 @@ eMBRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength ) if( eRcvState == STATE_RX_IDLE ) { /* First byte before the Modbus-PDU is the slave address. */ - pucSndBufferCur = ( UCHAR * ) pucFrame - 1; + pucSndBufferCur = ( uint8_t * ) pucFrame - 1; usSndBufferCount = 1; /* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */ @@ -208,13 +208,13 @@ eMBRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength ) usSndBufferCount += usLength; /* Calculate CRC16 checksum for Modbus-Serial-Line-PDU. */ - usCRC16 = usMBCRC16( ( UCHAR * ) pucSndBufferCur, usSndBufferCount ); - ucRTUBuf[usSndBufferCount++] = ( UCHAR )( usCRC16 & 0xFF ); - ucRTUBuf[usSndBufferCount++] = ( UCHAR )( usCRC16 >> 8 ); + usCRC16 = usMBCRC16( ( uint8_t * ) pucSndBufferCur, usSndBufferCount ); + ucRTUBuf[usSndBufferCount++] = ( uint8_t )( usCRC16 & 0xFF ); + ucRTUBuf[usSndBufferCount++] = ( uint8_t )( usCRC16 >> 8 ); /* Activate the transmitter. */ eSndState = STATE_TX_XMIT; - vMBPortSerialEnable( FALSE, TRUE ); + vMBPortSerialEnable( false, true ); } else { @@ -224,16 +224,16 @@ eMBRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength ) return eStatus; } -BOOL +bool xMBRTUReceiveFSM( void ) { - BOOL xTaskNeedSwitch = FALSE; - UCHAR ucByte; + bool xTaskNeedSwitch = false; + uint8_t ucByte; ASSERT( eSndState == STATE_TX_IDLE ); /* Always read the character. */ - ( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte ); + ( void )xMBPortSerialGetByte( ( int8_t * ) & ucByte ); switch ( eRcvState ) { @@ -284,10 +284,10 @@ xMBRTUReceiveFSM( void ) return xTaskNeedSwitch; } -BOOL +bool xMBRTUTransmitFSM( void ) { - BOOL xNeedPoll = FALSE; + bool xNeedPoll = false; ASSERT( eRcvState == STATE_RX_IDLE ); @@ -297,14 +297,14 @@ xMBRTUTransmitFSM( void ) * idle state. */ case STATE_TX_IDLE: /* enable receiver/disable transmitter. */ - vMBPortSerialEnable( TRUE, FALSE ); + vMBPortSerialEnable( true, false ); break; case STATE_TX_XMIT: /* check if we are finished. */ if( usSndBufferCount != 0 ) { - xMBPortSerialPutByte( ( CHAR )*pucSndBufferCur ); + xMBPortSerialPutByte( ( int8_t )*pucSndBufferCur ); pucSndBufferCur++; /* next byte in sendbuffer. */ usSndBufferCount--; } @@ -313,7 +313,7 @@ xMBRTUTransmitFSM( void ) xNeedPoll = xMBPortEventPost( EV_FRAME_SENT ); /* Disable transmitter. This prevents another transmit buffer * empty interrupt. */ - vMBPortSerialEnable( TRUE, FALSE ); + vMBPortSerialEnable( true, false ); eSndState = STATE_TX_IDLE; } break; @@ -322,10 +322,10 @@ xMBRTUTransmitFSM( void ) return xNeedPoll; } -BOOL +bool xMBRTUTimerT35Expired( void ) { - BOOL xNeedPoll = FALSE; + bool xNeedPoll = false; switch ( eRcvState ) { diff --git a/apps/modbus/rtu/mbrtu.h b/apps/modbus/rtu/mbrtu.h index 8d8bd1f0a..6a14654f0 100644 --- a/apps/modbus/rtu/mbrtu.h +++ b/apps/modbus/rtu/mbrtu.h @@ -34,16 +34,16 @@ #ifdef __cplusplus PR_BEGIN_EXTERN_C #endif - eMBErrorCode eMBRTUInit( UCHAR slaveAddress, UCHAR ucPort, ULONG ulBaudRate, + eMBErrorCode eMBRTUInit( uint8_t slaveAddress, uint8_t ucPort, uint32_t ulBaudRate, eMBParity eParity ); void eMBRTUStart( void ); void eMBRTUStop( void ); -eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ); -eMBErrorCode eMBRTUSend( UCHAR slaveAddress, const UCHAR * pucFrame, USHORT usLength ); -BOOL xMBRTUReceiveFSM( void ); -BOOL xMBRTUTransmitFSM( void ); -BOOL xMBRTUTimerT15Expired( void ); -BOOL xMBRTUTimerT35Expired( void ); +eMBErrorCode eMBRTUReceive( uint8_t * pucRcvAddress, uint8_t ** pucFrame, uint16_t * pusLength ); +eMBErrorCode eMBRTUSend( uint8_t slaveAddress, const uint8_t * pucFrame, uint16_t usLength ); +bool xMBRTUReceiveFSM( void ); +bool xMBRTUTransmitFSM( void ); +bool xMBRTUTimerT15Expired( void ); +bool xMBRTUTimerT35Expired( void ); #ifdef __cplusplus PR_END_EXTERN_C |