BOOL xMBPortSerialPutByte( CHAR ucByte ) { /* Put a byte in the UARTs transmit buffer. This function is called * by the protocol stack if pxMBFrameCBTransmitterEmpty( ) has been * called. */ LL_USART_TransmitData8(USART1, (uint8_t)ucByte); return TRUE; }
BOOL xMBPortSerialGetByte( CHAR * pucByte ) { /* Return the byte in the UARTs receive buffer. This function is called * by the protocol stack after pxMBFrameCBByteReceived( ) has been called. */ *pucByte = LL_USART_ReceiveData8(USART1); return TRUE; }
/* Create an interrupt handler for the transmit buffer empty interrupt * (or an equivalent) for your target processor. This function should then * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that * a new character can be sent. The protocol stack will then call * xMBPortSerialPutByte( ) to send the character. */ voidprvvUARTTxReadyISR( void ) { pxMBFrameCBTransmitterEmpty( ); }
/* Create an interrupt handler for the receive interrupt for your target * processor. This function should then call pxMBFrameCBByteReceived( ). The * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the * character. */ voidprvvUARTRxISR( void ) { pxMBFrameCBByteReceived( ); }
/* Create an ISR which is called whenever the timer has expired. This function * must then call pxMBPortCBTimerExpired( ) to notify the protocol stack that * the timer has expired. */ voidprvvTIMERExpiredISR( void ) { ( void )pxMBPortCBTimerExpired( ); }
#ifdef __cplusplus PR_BEGIN_EXTERN_C #endif /* ----------------------- Defines ------------------------------------------*/ /*! \defgroup modbus_cfg Modbus Configuration * * Most modules in the protocol stack are completly optional and can be * excluded. This is specially important if target resources are very small * and program memory space should be saved.<br> * * All of these settings are available in the file <code>mbconfig.h</code> */ /*! \addtogroup modbus_cfg * @{ */ /*! \brief If Modbus ASCII support is enabled. */ #define MB_ASCII_ENABLED ( 0 )
/*! \brief If Modbus RTU support is enabled. */ #define MB_RTU_ENABLED ( 1 )
/*! \brief If Modbus TCP support is enabled. */ #define MB_TCP_ENABLED ( 0 )
/*! \brief The character timeout value for Modbus ASCII. * * The character timeout value is not fixed for Modbus ASCII and is therefore * a configuration option. It should be set to the maximum expected delay * time of the network. */ #define MB_ASCII_TIMEOUT_SEC ( 1 )
/*! \brief Timeout to wait in ASCII prior to enabling transmitter. * * If defined the function calls vMBPortSerialDelay with the argument * MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS to allow for a delay before * the serial transmitter is enabled. This is required because some * targets are so fast that there is no time between receiving and * transmitting the frame. If the master is to slow with enabling its * receiver then he will not receive the response correctly. */ #ifndef MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS #define MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS ( 0 ) #endif
/*! \brief Maximum number of Modbus functions codes the protocol stack * should support. * * The maximum number of supported Modbus functions must be greater than * the sum of all enabled functions in this file and custom function * handlers. If set to small adding more functions will fail. */ #define MB_FUNC_HANDLERS_MAX ( 16 )
/*! \brief Number of bytes which should be allocated for the <em>Report Slave ID * </em>command. * * This number limits the maximum size of the additional segment in the * report slave id function. See eMBSetSlaveID( ) for more information on * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED * is set to <code>1</code>. */ #define MB_FUNC_OTHER_REP_SLAVEID_BUF ( 32 )
/*! \brief If the <em>Report Slave ID</em> function should be enabled. */ #define MB_FUNC_OTHER_REP_SLAVEID_ENABLED ( 1 )
/*! \brief If the <em>Read Input Registers</em> function should be enabled. */ #define MB_FUNC_READ_INPUT_ENABLED ( 0 )
/*! \brief If the <em>Read Holding Registers</em> function should be enabled. */ #define MB_FUNC_READ_HOLDING_ENABLED ( 1 )
/*! \brief If the <em>Write Single Register</em> function should be enabled. */ #define MB_FUNC_WRITE_HOLDING_ENABLED ( 0 )
/*! \brief If the <em>Write Multiple registers</em> function should be enabled. */ #define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED ( 0 )
/*! \brief If the <em>Read Coils</em> function should be enabled. */ #define MB_FUNC_READ_COILS_ENABLED ( 0 )
/*! \brief If the <em>Write Coils</em> function should be enabled. */ #define MB_FUNC_WRITE_COIL_ENABLED ( 0 )
/*! \brief If the <em>Write Multiple Coils</em> function should be enabled. */ #define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED ( 0 )
/*! \brief If the <em>Read Discrete Inputs</em> function should be enabled. */ #define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED ( 0 )
/*! \brief If the <em>Read/Write Multiple Registers</em> function should be enabled. */ #define MB_FUNC_READWRITE_HOLDING_ENABLED ( 0 )