debug tty
This commit is contained in:
@@ -128,19 +128,19 @@ static int chrg_tty_dev_open (struct chrg_tty_t *pTTY)
|
||||
* @param level - send mode level
|
||||
* @retval instance handle
|
||||
*/
|
||||
struct chrg_tty_t *chrg_tty_create (const char *name, int baudrate, int parity, int pin, int level)
|
||||
struct chrg_tty_t *chrg_tty_create (const char *devname, int baudrate, int parity, int pin, int level)
|
||||
{
|
||||
struct chrg_tty_t *pTTY = RT_NULL;
|
||||
rt_device_t dev;
|
||||
|
||||
dev = rt_device_find(name);
|
||||
dev = rt_device_find(devname);
|
||||
if (RT_NULL == dev) {
|
||||
LOG_E("tty device '%s' not found.", name);
|
||||
LOG_E("tty device '%s' not found.", devname);
|
||||
return (RT_NULL);
|
||||
}
|
||||
|
||||
if (RT_Device_Class_Char != dev->type) {
|
||||
LOG_E("tty device '%s' type is not char.", name);
|
||||
LOG_E("tty device '%s' type is not char.", devname);
|
||||
return (RT_NULL);
|
||||
}
|
||||
|
||||
@@ -150,14 +150,15 @@ struct chrg_tty_t *chrg_tty_create (const char *name, int baudrate, int parity,
|
||||
return (RT_NULL);
|
||||
}
|
||||
|
||||
pTTY->lock = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
|
||||
pTTY->devname = devname;
|
||||
pTTY->lock = rt_mutex_create(devname, RT_IPC_FLAG_FIFO);
|
||||
if (RT_NULL == pTTY->lock) {
|
||||
rt_free(pTTY);
|
||||
LOG_E("create mutex failed.");
|
||||
return (RT_NULL);
|
||||
}
|
||||
|
||||
pTTY->evt = rt_event_create(name, RT_IPC_FLAG_FIFO);
|
||||
pTTY->evt = rt_event_create(devname, RT_IPC_FLAG_FIFO);
|
||||
if (RT_NULL == pTTY->evt) {
|
||||
rt_mutex_delete(pTTY->lock);
|
||||
rt_free(pTTY);
|
||||
@@ -450,21 +451,19 @@ int chrg_tty_send (struct chrg_tty_t *pTTY, void *buf, int size)
|
||||
LOG_E("tty not connected.");
|
||||
return (-RT_ERROR);
|
||||
}
|
||||
rt_kprintf("%s %d\r\n", __func__, __LINE__);
|
||||
|
||||
ret = rt_mutex_take(pTTY->lock, RT_WAITING_FOREVER);
|
||||
if (RT_EOK != ret) {
|
||||
LOG_E("mutex take failed. [%d]", ret);
|
||||
return (-RT_ERROR);
|
||||
}
|
||||
rt_kprintf("%s %d size %d\r\n", __func__, __LINE__, size);
|
||||
|
||||
chrg_tty_mode_set(pTTY, 1);//set to send mode
|
||||
rt_kprintf("%s %d\r\n", __func__, __LINE__);
|
||||
send_len = rt_device_write(pTTY->dev, 0, buf, size);
|
||||
rt_kprintf("%s %d %d\r\n", __func__, __LINE__, send_len);
|
||||
chrg_tty_mode_set(pTTY, 0);//set to receive mode
|
||||
|
||||
rt_mutex_release(pTTY->lock);
|
||||
rt_kprintf("%s %d\r\n", __func__, __LINE__);
|
||||
|
||||
return send_len;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef enum {
|
||||
|
||||
struct chrg_tty_t {
|
||||
rt_device_t dev; // serial device handle
|
||||
const char *devname;
|
||||
rt_mutex_t lock; // mutex handle
|
||||
rt_event_t evt; // event handle
|
||||
rt_uint8_t status; // connect status
|
||||
|
||||
@@ -20,32 +20,19 @@ static enum {
|
||||
} eMBState = STATE_NOT_INITIALIZED;
|
||||
|
||||
|
||||
static peMBFrameSend peMBFrameSendCur;
|
||||
static pvMBFrameStart pvMBFrameStartCur;
|
||||
static pvMBFrameStop pvMBFrameStopCur;
|
||||
static peMBFrameReceive peMBFrameReceiveCur;
|
||||
static pvMBFrameClose pvMBFrameCloseCur;
|
||||
|
||||
rt_uint8_t (*pxMBFrameCBByteReceived)(void);
|
||||
rt_uint8_t (*pxMBFrameCBTransmitterEmpty)(void);
|
||||
rt_uint8_t (*pxMBPortCBTimerExpired)(void);
|
||||
|
||||
rt_uint8_t (*pxMBFrameCBReceiveFSMCur)(void);
|
||||
rt_uint8_t (*pxMBFrameCBTransmitFSMCur)(void);
|
||||
|
||||
#define MB_FUNC_HANDLERS_MAX (16)
|
||||
|
||||
static xMBFunctionHandler xFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
|
||||
{MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
|
||||
{MB_FUNC_READ_INPUT_REGISTER, eMBFuncReadInputRegister},
|
||||
{MB_FUNC_READ_HOLDING_REGISTER, eMBFuncReadHoldingRegister},
|
||||
{MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBFuncWriteMultipleHoldingRegister},
|
||||
{MB_FUNC_WRITE_REGISTER, eMBFuncWriteHoldingRegister},
|
||||
{MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBFuncReadWriteMultipleHoldingRegister},
|
||||
{MB_FUNC_READ_COILS, eMBFuncReadCoils},
|
||||
{MB_FUNC_WRITE_SINGLE_COIL, eMBFuncWriteCoil},
|
||||
{MB_FUNC_WRITE_MULTIPLE_COILS, eMBFuncWriteMultipleCoils},
|
||||
{MB_FUNC_READ_DISCRETE_INPUTS, eMBFuncReadDiscreteInputs},
|
||||
{MB_FUNC_READ_HOLDING_REGISTER, eMBFuncReadHoldingRegister},
|
||||
{MB_FUNC_READ_INPUT_REGISTER, eMBFuncReadInputRegister},
|
||||
{MB_FUNC_WRITE_SINGLE_COIL, eMBFuncWriteCoil},
|
||||
{MB_FUNC_WRITE_REGISTER, eMBFuncWriteHoldingRegister},
|
||||
{MB_FUNC_WRITE_MULTIPLE_COILS, eMBFuncWriteMultipleCoils},
|
||||
{MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBFuncWriteMultipleHoldingRegister},
|
||||
{MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
|
||||
{MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBFuncReadWriteMultipleHoldingRegister},
|
||||
};
|
||||
|
||||
eMBErrorCode eMBInit (rt_uint8_t ucSlaveAddress, rt_uint8_t ucPort,
|
||||
@@ -59,15 +46,6 @@ eMBErrorCode eMBInit (rt_uint8_t ucSlaveAddress, rt_uint8_t ucPort,
|
||||
} else {
|
||||
ucMBAddress = ucSlaveAddress;
|
||||
|
||||
pvMBFrameStartCur = eMBRTUStart;
|
||||
pvMBFrameStopCur = eMBRTUStop;
|
||||
peMBFrameSendCur = eMBRTUSend;
|
||||
peMBFrameReceiveCur = eMBRTUReceive;
|
||||
pvMBFrameCloseCur = NULL;
|
||||
pxMBFrameCBByteReceived = xMBRTUReceiveFSM;
|
||||
pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
|
||||
pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
|
||||
|
||||
eStatus = eMBRTUInit(ucMBAddress, ucPort, ulBaudRate, eParity);
|
||||
if (eStatus == MB_ENOERR) {
|
||||
if (!xMBPortEventInit()) {
|
||||
@@ -123,9 +101,6 @@ eMBErrorCode eMBClose (void)
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
|
||||
if (eMBState == STATE_DISABLED) {
|
||||
if (pvMBFrameCloseCur != NULL) {
|
||||
pvMBFrameCloseCur();
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EILLSTATE;
|
||||
}
|
||||
@@ -139,7 +114,7 @@ eMBErrorCode eMBEnable (void)
|
||||
|
||||
if (eMBState == STATE_DISABLED) {
|
||||
/* Activate the protocol stack. */
|
||||
pvMBFrameStartCur();
|
||||
eMBRTUStart();
|
||||
eMBState = STATE_ENABLED;
|
||||
} else {
|
||||
eStatus = MB_EILLSTATE;
|
||||
@@ -153,7 +128,7 @@ eMBErrorCode eMBDisable (void)
|
||||
eMBErrorCode eStatus;
|
||||
|
||||
if (eMBState == STATE_ENABLED) {
|
||||
pvMBFrameStopCur();
|
||||
eMBRTUStop();
|
||||
eMBState = STATE_DISABLED;
|
||||
eStatus = MB_ENOERR;
|
||||
} else if (eMBState == STATE_DISABLED) {
|
||||
@@ -190,7 +165,7 @@ eMBErrorCode eMBPoll (void)
|
||||
break;
|
||||
|
||||
case EV_FRAME_RECEIVED:
|
||||
eStatus = peMBFrameReceiveCur(&ucRcvAddress, &ucMBFrame, &usLength);
|
||||
eStatus = eMBRTUReceive(&ucRcvAddress, &ucMBFrame, &usLength);
|
||||
if (eStatus == MB_ENOERR) {
|
||||
/* Check if the frame is for us. If not ignore the frame. */
|
||||
if ((ucRcvAddress == ucMBAddress) || (ucRcvAddress == MB_ADDRESS_BROADCAST)) {
|
||||
@@ -215,13 +190,14 @@ eMBErrorCode eMBPoll (void)
|
||||
/* If the request was not sent to the broadcast address we
|
||||
* return a reply. */
|
||||
if (ucRcvAddress != MB_ADDRESS_BROADCAST) {
|
||||
if(eException != MB_EX_NONE) {
|
||||
if (eException != MB_EX_NONE) {
|
||||
/* An exception occured. Build an error frame. */
|
||||
usLength = 0;
|
||||
ucMBFrame[usLength++] = (rt_uint8_t)(ucFunctionCode | MB_FUNC_ERROR);
|
||||
ucMBFrame[usLength++] = eException;
|
||||
}
|
||||
eStatus = peMBFrameSendCur(ucMBAddress, ucMBFrame, usLength);
|
||||
|
||||
eStatus = eMBRTUSend(ucMBAddress, ucMBFrame, usLength);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -43,22 +43,23 @@ typedef enum {
|
||||
#define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
|
||||
#define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
|
||||
#define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
|
||||
#define MB_FUNC_NONE ( 0 )
|
||||
#define MB_FUNC_READ_COILS ( 1 )
|
||||
#define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
|
||||
#define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
|
||||
#define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
|
||||
#define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
|
||||
#define MB_FUNC_READ_INPUT_REGISTER ( 4 )
|
||||
#define MB_FUNC_WRITE_REGISTER ( 6 )
|
||||
#define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
|
||||
#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
|
||||
#define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
|
||||
#define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
|
||||
#define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
|
||||
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
|
||||
#define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
|
||||
#define MB_FUNC_ERROR ( 128 )
|
||||
|
||||
#define MB_FUNC_NONE (0x00)
|
||||
#define MB_FUNC_READ_COILS (0x01)
|
||||
#define MB_FUNC_READ_DISCRETE_INPUTS (0x02)
|
||||
#define MB_FUNC_READ_HOLDING_REGISTER (0x03)
|
||||
#define MB_FUNC_READ_INPUT_REGISTER (0x04)
|
||||
#define MB_FUNC_WRITE_SINGLE_COIL (0x05)
|
||||
#define MB_FUNC_WRITE_REGISTER (0x06)
|
||||
#define MB_FUNC_DIAG_READ_EXCEPTION (0x07)
|
||||
#define MB_FUNC_DIAG_DIAGNOSTIC (0x08)
|
||||
#define MB_FUNC_DIAG_GET_COM_EVENT_CNT (0x0B)
|
||||
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG (0x0C)
|
||||
#define MB_FUNC_WRITE_MULTIPLE_COILS (0x0F)
|
||||
#define MB_FUNC_WRITE_MULTIPLE_REGISTERS (0x10)
|
||||
#define MB_FUNC_OTHER_REPORT_SLAVEID (0x11)
|
||||
#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS (0x17)
|
||||
#define MB_FUNC_ERROR (0x80)
|
||||
|
||||
typedef enum {
|
||||
MB_EX_NONE = 0x00,
|
||||
@@ -173,18 +174,6 @@ eMBErrorCode eMBRegDiscreteCB (rt_uint8_t * pucRegBuffer, rt_uint16_t usAddress,
|
||||
#define MB_PDU_FUNC_WRITE_MUL_COILCNT_MAX (0x07B0)
|
||||
|
||||
|
||||
typedef void (*pvMBFrameStart) (void);
|
||||
|
||||
typedef void (*pvMBFrameStop) (void);
|
||||
|
||||
typedef eMBErrorCode(*peMBFrameReceive ) (rt_uint8_t * pucRcvAddress,
|
||||
rt_uint8_t ** pucFrame, rt_uint16_t * pusLength);
|
||||
|
||||
typedef eMBErrorCode(*peMBFrameSend) (rt_uint8_t slaveAddress,
|
||||
const rt_uint8_t * pucFrame, rt_uint16_t usLength);
|
||||
|
||||
typedef void(*pvMBFrameClose) (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@ static struct rt_event xSlaveOsEvent;
|
||||
|
||||
rt_uint8_t xMBPortEventInit (void)
|
||||
{
|
||||
rt_event_init(&xSlaveOsEvent,"slave event",RT_IPC_FLAG_PRIO);
|
||||
rt_event_init(&xSlaveOsEvent, "frame", RT_IPC_FLAG_PRIO);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
+336
-360
@@ -7,305 +7,7 @@
|
||||
#include "mb.h"
|
||||
|
||||
|
||||
#define MB_FUNC_OTHER_REP_SLAVEID_BUF (32)
|
||||
|
||||
static rt_uint8_t ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF];
|
||||
static rt_uint16_t usMBSlaveIDLen;
|
||||
|
||||
eMBErrorCode eMBSetSlaveID (rt_uint8_t ucSlaveID, rt_uint8_t xIsRunning,
|
||||
rt_uint8_t const *pucAdditional, rt_uint16_t usAdditionalLen)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
|
||||
/* the first byte and second byte in the buffer is reserved for
|
||||
* the parameter ucSlaveID and the running flag. The rest of
|
||||
* the buffer is available for additional data. */
|
||||
if (usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF) {
|
||||
usMBSlaveIDLen = 0;
|
||||
ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID;
|
||||
ucMBSlaveID[usMBSlaveIDLen++] = (rt_uint8_t)(xIsRunning ? 0xFF : 0x00);
|
||||
if (usAdditionalLen > 0) {
|
||||
memcpy(&ucMBSlaveID[usMBSlaveIDLen], pucAdditional, (size_t)usAdditionalLen);
|
||||
usMBSlaveIDLen += usAdditionalLen;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_ENORES;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReportSlaveID (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
{
|
||||
memcpy(&pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], (size_t)usMBSlaveIDLen);
|
||||
*usLen = (rt_uint16_t)(MB_PDU_DATA_OFF + usMBSlaveIDLen);
|
||||
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadInputRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usRegCount;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen == (MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
usRegCount = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8);
|
||||
usRegCount |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1]);
|
||||
|
||||
/* Check if the number of registers to read is valid. If not
|
||||
* return Modbus illegal data value exception.
|
||||
*/
|
||||
if ((usRegCount >= 1)
|
||||
&& (usRegCount < MB_PDU_FUNC_READ_REGCNT_MAX)) {
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READ_INPUT_REGISTER;
|
||||
*usLen += 1;
|
||||
|
||||
/* Second byte in the response contain the number of bytes. */
|
||||
*pucFrameCur++ = (rt_uint8_t)(usRegCount * 2);
|
||||
*usLen += 1;
|
||||
|
||||
eRegStatus = eMBRegInputCB(pucFrameCur, usRegAddress, usRegCount);
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
} else {
|
||||
*usLen += usRegCount * 2;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid read input register request because the length
|
||||
* is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncWriteHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen == (MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
/* Make callback to update the value. */
|
||||
eRegStatus = eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF], usRegAddress, 1, MB_REG_WRITE);
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid request because the length is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncWriteMultipleHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usRegCount;
|
||||
rt_uint8_t ucRegByteCount;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen >= (MB_PDU_FUNC_WRITE_MUL_SIZE_MIN + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8 );
|
||||
usRegAddress |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1] );
|
||||
usRegAddress++;
|
||||
|
||||
usRegCount = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF] << 8 );
|
||||
usRegCount |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF + 1] );
|
||||
|
||||
ucRegByteCount = pucFrame[MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF];
|
||||
|
||||
if ((usRegCount >= 1) &&
|
||||
(usRegCount <= MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX) &&
|
||||
(ucRegByteCount == (rt_uint8_t) (2 * usRegCount))) {
|
||||
/* Make callback to update the register values. */
|
||||
eRegStatus =
|
||||
eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_MUL_VALUES_OFF],
|
||||
usRegAddress, usRegCount, MB_REG_WRITE );
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
} else {
|
||||
/* The response contains the function code, the starting
|
||||
* address and the quantity of registers. We reuse the
|
||||
* old values in the buffer because they are still valid.
|
||||
*/
|
||||
*usLen = MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid request because the length is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usRegCount;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if ( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
|
||||
{
|
||||
usRegAddress = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
|
||||
usRegAddress |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
|
||||
usRegAddress++;
|
||||
|
||||
usRegCount = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
|
||||
usRegCount |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
|
||||
|
||||
/* Check if the number of registers to read is valid. If not
|
||||
* return Modbus illegal data value exception.
|
||||
*/
|
||||
if( ( usRegCount >= 1 ) && ( usRegCount <= MB_PDU_FUNC_READ_REGCNT_MAX ) )
|
||||
{
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READ_HOLDING_REGISTER;
|
||||
*usLen += 1;
|
||||
|
||||
/* Second byte in the response contain the number of bytes. */
|
||||
*pucFrameCur++ = ( rt_uint8_t ) ( usRegCount * 2 );
|
||||
*usLen += 1;
|
||||
|
||||
/* Make callback to fill the buffer. */
|
||||
eRegStatus = eMBRegHoldingCB( pucFrameCur, usRegAddress, usRegCount, MB_REG_READ );
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if( eRegStatus != MB_ENOERR )
|
||||
{
|
||||
eStatus = prveMBError2Exception( eRegStatus );
|
||||
}
|
||||
else
|
||||
{
|
||||
*usLen += usRegCount * 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Can't be a valid request because the length is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
|
||||
eMBException eMBFuncReadWriteMultipleHoldingRegister( rt_uint8_t * pucFrame, rt_uint16_t * usLen )
|
||||
{
|
||||
rt_uint16_t usRegReadAddress;
|
||||
rt_uint16_t usRegReadCount;
|
||||
rt_uint16_t usRegWriteAddress;
|
||||
rt_uint16_t usRegWriteCount;
|
||||
rt_uint8_t ucRegWriteByteCount;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if( *usLen >= ( MB_PDU_FUNC_READWRITE_SIZE_MIN + MB_PDU_SIZE_MIN ) )
|
||||
{
|
||||
usRegReadAddress = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF] << 8U );
|
||||
usRegReadAddress |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF + 1] );
|
||||
usRegReadAddress++;
|
||||
|
||||
usRegReadCount = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF] << 8U );
|
||||
usRegReadCount |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF + 1] );
|
||||
|
||||
usRegWriteAddress = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF] << 8U );
|
||||
usRegWriteAddress |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF + 1] );
|
||||
usRegWriteAddress++;
|
||||
|
||||
usRegWriteCount = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF] << 8U );
|
||||
usRegWriteCount |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF + 1] );
|
||||
|
||||
ucRegWriteByteCount = pucFrame[MB_PDU_FUNC_READWRITE_BYTECNT_OFF];
|
||||
|
||||
if( ( usRegReadCount >= 1 ) && ( usRegReadCount <= 0x7D ) &&
|
||||
( usRegWriteCount >= 1 ) && ( usRegWriteCount <= 0x79 ) &&
|
||||
( ( 2 * usRegWriteCount ) == ucRegWriteByteCount ) )
|
||||
{
|
||||
/* Make callback to update the register values. */
|
||||
eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF],
|
||||
usRegWriteAddress, usRegWriteCount, MB_REG_WRITE );
|
||||
|
||||
if( eRegStatus == MB_ENOERR )
|
||||
{
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
|
||||
*usLen += 1;
|
||||
|
||||
/* Second byte in the response contain the number of bytes. */
|
||||
*pucFrameCur++ = ( rt_uint8_t ) ( usRegReadCount * 2 );
|
||||
*usLen += 1;
|
||||
|
||||
/* Make the read callback. */
|
||||
eRegStatus =
|
||||
eMBRegHoldingCB( pucFrameCur, usRegReadAddress, usRegReadCount, MB_REG_READ );
|
||||
if( eRegStatus == MB_ENOERR )
|
||||
{
|
||||
*usLen += 2 * usRegReadCount;
|
||||
}
|
||||
}
|
||||
if( eRegStatus != MB_ENOERR )
|
||||
{
|
||||
eStatus = prveMBError2Exception( eRegStatus );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
}
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadCoils (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
eMBException eMBFuncReadCoils (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usCoilCount;
|
||||
@@ -369,7 +71,178 @@ eMBException eMBFuncReadCoils (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncWriteCoil (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
eMBException eMBFuncReadDiscreteInputs (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usDiscreteCnt;
|
||||
rt_uint8_t ucNBytes;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen == (MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
usDiscreteCnt = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF] << 8);
|
||||
usDiscreteCnt |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF + 1]);
|
||||
|
||||
/* Check if the number of registers to read is valid. If not
|
||||
* return Modbus illegal data value exception.
|
||||
*/
|
||||
if ((usDiscreteCnt >= 1) &&
|
||||
(usDiscreteCnt < MB_PDU_FUNC_READ_DISCCNT_MAX)) {
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READ_DISCRETE_INPUTS;
|
||||
*usLen += 1;
|
||||
|
||||
/* Test if the quantity of coils is a multiple of 8. If not last
|
||||
* byte is only partially field with unused coils set to zero. */
|
||||
if ((usDiscreteCnt & 0x0007) != 0) {
|
||||
ucNBytes = (rt_uint8_t)(usDiscreteCnt / 8 + 1);
|
||||
} else {
|
||||
ucNBytes = (rt_uint8_t)(usDiscreteCnt / 8);
|
||||
}
|
||||
|
||||
*pucFrameCur++ = ucNBytes;
|
||||
*usLen += 1;
|
||||
|
||||
eRegStatus = eMBRegDiscreteCB(pucFrameCur, usRegAddress, usDiscreteCnt);
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
} else {
|
||||
/* The response contains the function code, the starting address
|
||||
* and the quantity of registers. We reuse the old values in the
|
||||
* buffer because they are still valid. */
|
||||
*usLen += ucNBytes;;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid read coil register request because the length
|
||||
* is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usRegCount;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
usRegCount = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8);
|
||||
usRegCount |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1]);
|
||||
|
||||
/* Check if the number of registers to read is valid. If not
|
||||
* return Modbus illegal data value exception.
|
||||
*/
|
||||
if ((usRegCount >= 1) && (usRegCount <= MB_PDU_FUNC_READ_REGCNT_MAX)) {
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READ_HOLDING_REGISTER;
|
||||
*usLen += 1;
|
||||
|
||||
/* Second byte in the response contain the number of bytes. */
|
||||
*pucFrameCur++ = (rt_uint8_t)(usRegCount * 2);
|
||||
*usLen += 1;
|
||||
|
||||
/* Make callback to fill the buffer. */
|
||||
eRegStatus = eMBRegHoldingCB( pucFrameCur, usRegAddress, usRegCount, MB_REG_READ);
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
} else {
|
||||
*usLen += usRegCount * 2;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid request because the length is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadInputRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usRegCount;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen == (MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
usRegCount = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8);
|
||||
usRegCount |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1]);
|
||||
|
||||
/* Check if the number of registers to read is valid. If not
|
||||
* return Modbus illegal data value exception.
|
||||
*/
|
||||
if ((usRegCount >= 1)
|
||||
&& (usRegCount < MB_PDU_FUNC_READ_REGCNT_MAX)) {
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READ_INPUT_REGISTER;
|
||||
*usLen += 1;
|
||||
|
||||
/* Second byte in the response contain the number of bytes. */
|
||||
*pucFrameCur++ = (rt_uint8_t)(usRegCount * 2);
|
||||
*usLen += 1;
|
||||
|
||||
eRegStatus = eMBRegInputCB(pucFrameCur, usRegAddress, usRegCount);
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
} else {
|
||||
*usLen += usRegCount * 2;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid read input register request because the length
|
||||
* is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncWriteCoil (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint8_t ucBuf[2];
|
||||
@@ -409,8 +282,33 @@ eMBException eMBFuncWriteCoil (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncWriteHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
eMBException eMBFuncWriteMultipleCoils (rt_uint8_t * pucFrame, rt_uint16_t * usLen)
|
||||
if (*usLen == (MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
/* Make callback to update the value. */
|
||||
eRegStatus = eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF], usRegAddress, 1, MB_REG_WRITE);
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
}
|
||||
} else {
|
||||
/* Can't be a valid request because the length is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncWriteMultipleCoils (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usCoilCnt;
|
||||
@@ -464,86 +362,164 @@ eMBException eMBFuncWriteMultipleCoils (rt_uint8_t * pucFrame, rt_uint16_t * usL
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadDiscreteInputs( rt_uint8_t * pucFrame, rt_uint16_t * usLen )
|
||||
eMBException eMBFuncWriteMultipleHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usDiscreteCnt;
|
||||
rt_uint8_t ucNBytes;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
rt_uint16_t usRegAddress;
|
||||
rt_uint16_t usRegCount;
|
||||
rt_uint8_t ucRegByteCount;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
|
||||
{
|
||||
usRegAddress = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
|
||||
usRegAddress |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
|
||||
if (*usLen >= (MB_PDU_FUNC_WRITE_MUL_SIZE_MIN + MB_PDU_SIZE_MIN)) {
|
||||
usRegAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8);
|
||||
usRegAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1]);
|
||||
usRegAddress++;
|
||||
|
||||
usDiscreteCnt = ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF] << 8 );
|
||||
usDiscreteCnt |= ( rt_uint16_t )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF + 1] );
|
||||
usRegCount = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF] << 8);
|
||||
usRegCount |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF + 1]);
|
||||
|
||||
/* Check if the number of registers to read is valid. If not
|
||||
* return Modbus illegal data value exception.
|
||||
*/
|
||||
if( ( usDiscreteCnt >= 1 ) &&
|
||||
( usDiscreteCnt < MB_PDU_FUNC_READ_DISCCNT_MAX ) )
|
||||
{
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READ_DISCRETE_INPUTS;
|
||||
*usLen += 1;
|
||||
|
||||
/* Test if the quantity of coils is a multiple of 8. If not last
|
||||
* byte is only partially field with unused coils set to zero. */
|
||||
if( ( usDiscreteCnt & 0x0007 ) != 0 )
|
||||
{
|
||||
ucNBytes = ( rt_uint8_t ) ( usDiscreteCnt / 8 + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
ucNBytes = ( rt_uint8_t ) ( usDiscreteCnt / 8 );
|
||||
}
|
||||
*pucFrameCur++ = ucNBytes;
|
||||
*usLen += 1;
|
||||
ucRegByteCount = pucFrame[MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF];
|
||||
|
||||
if ((usRegCount >= 1) &&
|
||||
(usRegCount <= MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX) &&
|
||||
(ucRegByteCount == (rt_uint8_t) (2 * usRegCount))) {
|
||||
/* Make callback to update the register values. */
|
||||
eRegStatus =
|
||||
eMBRegDiscreteCB( pucFrameCur, usRegAddress, usDiscreteCnt );
|
||||
eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_WRITE_MUL_VALUES_OFF],
|
||||
usRegAddress, usRegCount, MB_REG_WRITE);
|
||||
|
||||
/* If an error occured convert it into a Modbus exception. */
|
||||
if( eRegStatus != MB_ENOERR )
|
||||
{
|
||||
eStatus = prveMBError2Exception( eRegStatus );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The response contains the function code, the starting address
|
||||
* and the quantity of registers. We reuse the old values in the
|
||||
* buffer because they are still valid. */
|
||||
*usLen += ucNBytes;;
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
} else {
|
||||
/* The response contains the function code, the starting
|
||||
* address and the quantity of registers. We reuse the
|
||||
* old values in the buffer because they are still valid.
|
||||
*/
|
||||
*usLen = MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Can't be a valid request because the length is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReadWriteMultipleHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
rt_uint16_t usRegReadAddress;
|
||||
rt_uint16_t usRegReadCount;
|
||||
rt_uint16_t usRegWriteAddress;
|
||||
rt_uint16_t usRegWriteCount;
|
||||
rt_uint8_t ucRegWriteByteCount;
|
||||
rt_uint8_t *pucFrameCur;
|
||||
|
||||
eMBException eStatus = MB_EX_NONE;
|
||||
eMBErrorCode eRegStatus;
|
||||
|
||||
if (*usLen >= ( MB_PDU_FUNC_READWRITE_SIZE_MIN + MB_PDU_SIZE_MIN)) {
|
||||
usRegReadAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF] << 8U);
|
||||
usRegReadAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF + 1]);
|
||||
usRegReadAddress++;
|
||||
|
||||
usRegReadCount = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF] << 8U);
|
||||
usRegReadCount |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF + 1]);
|
||||
|
||||
usRegWriteAddress = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF] << 8U);
|
||||
usRegWriteAddress |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF + 1]);
|
||||
usRegWriteAddress++;
|
||||
|
||||
usRegWriteCount = (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF] << 8U);
|
||||
usRegWriteCount |= (rt_uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF + 1]);
|
||||
|
||||
ucRegWriteByteCount = pucFrame[MB_PDU_FUNC_READWRITE_BYTECNT_OFF];
|
||||
|
||||
if ((usRegReadCount >= 1) && (usRegReadCount <= 0x7D) &&
|
||||
(usRegWriteCount >= 1) && (usRegWriteCount <= 0x79) &&
|
||||
((2 * usRegWriteCount) == ucRegWriteByteCount)) {
|
||||
/* Make callback to update the register values. */
|
||||
eRegStatus = eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF],
|
||||
usRegWriteAddress, usRegWriteCount, MB_REG_WRITE);
|
||||
|
||||
if (eRegStatus == MB_ENOERR) {
|
||||
/* Set the current PDU data pointer to the beginning. */
|
||||
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
|
||||
*usLen = MB_PDU_FUNC_OFF;
|
||||
|
||||
/* First byte contains the function code. */
|
||||
*pucFrameCur++ = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
|
||||
*usLen += 1;
|
||||
|
||||
/* Second byte in the response contain the number of bytes. */
|
||||
*pucFrameCur++ = (rt_uint8_t)(usRegReadCount * 2);
|
||||
*usLen += 1;
|
||||
|
||||
/* Make the read callback. */
|
||||
eRegStatus = eMBRegHoldingCB(pucFrameCur, usRegReadAddress,
|
||||
usRegReadCount, MB_REG_READ);
|
||||
if ( eRegStatus == MB_ENOERR ) {
|
||||
*usLen += 2 * usRegReadCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Can't be a valid read coil register request because the length
|
||||
* is incorrect. */
|
||||
eStatus = MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define MB_FUNC_OTHER_REP_SLAVEID_BUF (32)
|
||||
|
||||
static rt_uint8_t ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF];
|
||||
static rt_uint16_t usMBSlaveIDLen;
|
||||
|
||||
eMBErrorCode eMBSetSlaveID (rt_uint8_t ucSlaveID, rt_uint8_t xIsRunning,
|
||||
rt_uint8_t const *pucAdditional, rt_uint16_t usAdditionalLen)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
|
||||
/* the first byte and second byte in the buffer is reserved for
|
||||
* the parameter ucSlaveID and the running flag. The rest of
|
||||
* the buffer is available for additional data. */
|
||||
if (usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF) {
|
||||
usMBSlaveIDLen = 0;
|
||||
ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID;
|
||||
ucMBSlaveID[usMBSlaveIDLen++] = (rt_uint8_t)(xIsRunning ? 0xFF : 0x00);
|
||||
if (usAdditionalLen > 0) {
|
||||
memcpy(&ucMBSlaveID[usMBSlaveIDLen], pucAdditional, (size_t)usAdditionalLen);
|
||||
usMBSlaveIDLen += usAdditionalLen;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_ENORES;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBException eMBFuncReportSlaveID (rt_uint8_t *pucFrame, rt_uint16_t *usLen)
|
||||
{
|
||||
memcpy(&pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], (size_t)usMBSlaveIDLen);
|
||||
*usLen = (rt_uint16_t)(MB_PDU_DATA_OFF + usMBSlaveIDLen);
|
||||
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,25 +10,26 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
eMBException eMBFuncReportSlaveID (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
|
||||
eMBException eMBFuncReadInputRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncReadCoils (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncReadHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncReadDiscreteInputs (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncWriteHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncReadHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncWriteMultipleHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncReadInputRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncReadCoils (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncWriteCoil (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncWriteCoil (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncWriteHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncWriteMultipleCoils (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncWriteMultipleCoils (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncReadDiscreteInputs (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncWriteMultipleHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncReadWriteMultipleHoldingRegister (rt_uint8_t * pucFrame, rt_uint16_t * usLen);
|
||||
eMBException eMBFuncReportSlaveID (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
eMBException eMBFuncReadWriteMultipleHoldingRegister (rt_uint8_t *pucFrame, rt_uint16_t *usLen);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -59,12 +59,6 @@ void vMBPortTimersEnable (void);
|
||||
void vMBPortTimersDisable (void);
|
||||
|
||||
|
||||
extern rt_uint8_t (*pxMBFrameCBByteReceived) (void);
|
||||
|
||||
extern rt_uint8_t (*pxMBFrameCBTransmitterEmpty) (void);
|
||||
|
||||
extern rt_uint8_t (*pxMBPortCBTimerExpired) (void);
|
||||
|
||||
void EnterCriticalSection (void);
|
||||
void ExitCriticalSection (void);
|
||||
|
||||
|
||||
@@ -36,25 +36,22 @@ static volatile rt_uint16_t usSndBufferCount;
|
||||
|
||||
static volatile rt_uint16_t usRcvBufferPos;
|
||||
|
||||
eMBErrorCode eMBRTUInit( rt_uint8_t ucSlaveAddress, rt_uint8_t ucPort,
|
||||
rt_uint32_t ulBaudRate, eMBParity eParity )
|
||||
eMBErrorCode eMBRTUInit (rt_uint8_t ucSlaveAddress, rt_uint8_t ucPort,
|
||||
rt_uint32_t ulBaudRate, eMBParity eParity)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint32_t usTimerT35_50us;
|
||||
|
||||
( void )ucSlaveAddress;
|
||||
(void)ucSlaveAddress;
|
||||
EnterCriticalSection();
|
||||
|
||||
/* Modbus RTU uses 8 Databits. */
|
||||
/* If baudrate > 19200 then we should use the fixed timer values
|
||||
* t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
|
||||
*/
|
||||
if( ulBaudRate > 19200 )
|
||||
{
|
||||
if (ulBaudRate > 19200) {
|
||||
usTimerT35_50us = 35; /* 1800us. */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The timer reload value for a character is given by:
|
||||
*
|
||||
* ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
|
||||
@@ -63,23 +60,21 @@ eMBErrorCode eMBRTUInit( rt_uint8_t ucSlaveAddress, rt_uint8_t ucPort,
|
||||
* The reload for t3.5 is 1.5 times this value and similary
|
||||
* for t3.5.
|
||||
*/
|
||||
usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );
|
||||
usTimerT35_50us = (7UL * 220000UL) / (2UL * ulBaudRate);
|
||||
}
|
||||
|
||||
if( xMBPortTimersInit( ( rt_uint16_t ) usTimerT35_50us ) != TRUE )
|
||||
{
|
||||
eStatus = MB_EPORTERR;
|
||||
}
|
||||
else if( xMBPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != TRUE )
|
||||
{
|
||||
if (xMBPortTimersInit((rt_uint16_t)usTimerT35_50us) != TRUE) {
|
||||
eStatus = MB_EPORTERR;
|
||||
} else if (xMBPortSerialInit(ucPort, ulBaudRate, 8, eParity) != TRUE) {
|
||||
eStatus = MB_EPORTERR;
|
||||
}
|
||||
|
||||
ExitCriticalSection();
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
void eMBRTUStart( void )
|
||||
void eMBRTUStart (void)
|
||||
{
|
||||
EnterCriticalSection();
|
||||
/* Initially the receiver is in the state STATE_RX_INIT. we start
|
||||
@@ -88,16 +83,16 @@ void eMBRTUStart( void )
|
||||
* modbus protocol stack until the bus is free.
|
||||
*/
|
||||
eRcvState = STATE_RX_INIT;
|
||||
vMBPortSerialEnable( TRUE, FALSE );
|
||||
vMBPortSerialEnable(TRUE, FALSE);
|
||||
vMBPortTimersEnable();
|
||||
|
||||
ExitCriticalSection();
|
||||
}
|
||||
|
||||
void eMBRTUStop( void )
|
||||
void eMBRTUStop (void)
|
||||
{
|
||||
EnterCriticalSection();
|
||||
vMBPortSerialEnable( FALSE, FALSE );
|
||||
vMBPortSerialEnable(FALSE, FALSE);
|
||||
vMBPortTimersDisable();
|
||||
ExitCriticalSection();
|
||||
}
|
||||
@@ -107,12 +102,12 @@ eMBErrorCode eMBRTUReceive( rt_uint8_t * pucRcvAddress, rt_uint8_t ** pucFrame,
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
|
||||
EnterCriticalSection();
|
||||
|
||||
RT_ASSERT( usRcvBufferPos <= MB_SER_PDU_SIZE_MAX );
|
||||
|
||||
/* Length and CRC check */
|
||||
if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
|
||||
&& ( usMBCRC16( ( rt_uint8_t * ) ucRTUBuf, usRcvBufferPos ) == 0 ) )
|
||||
{
|
||||
if ((usRcvBufferPos >= MB_SER_PDU_SIZE_MIN)
|
||||
&& (usMBCRC16((rt_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.
|
||||
*/
|
||||
@@ -121,13 +116,11 @@ eMBErrorCode eMBRTUReceive( rt_uint8_t * pucRcvAddress, rt_uint8_t ** pucFrame,
|
||||
/* Total length of Modbus-PDU is Modbus-Serial-Line-PDU minus
|
||||
* size of address field and CRC checksum.
|
||||
*/
|
||||
*pusLength = ( rt_uint16_t )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC );
|
||||
*pusLength = (rt_uint16_t)(usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC);
|
||||
|
||||
/* Return the start of the Modbus PDU to the caller. */
|
||||
*pucFrame = ( rt_uint8_t * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF];
|
||||
}
|
||||
else
|
||||
{
|
||||
*pucFrame = (rt_uint8_t *)&ucRTUBuf[MB_SER_PDU_PDU_OFF];
|
||||
} else {
|
||||
eStatus = MB_EIO;
|
||||
}
|
||||
|
||||
@@ -136,9 +129,9 @@ eMBErrorCode eMBRTUReceive( rt_uint8_t * pucRcvAddress, rt_uint8_t ** pucFrame,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBErrorCode eMBRTUSend( rt_uint8_t ucSlaveAddress, const rt_uint8_t * pucFrame, rt_uint16_t usLength )
|
||||
eMBErrorCode eMBRTUSend (rt_uint8_t ucSlaveAddress, const rt_uint8_t * pucFrame, rt_uint16_t usLength)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t usCRC16;
|
||||
|
||||
EnterCriticalSection();
|
||||
@@ -147,10 +140,9 @@ eMBErrorCode eMBRTUSend( rt_uint8_t ucSlaveAddress, const rt_uint8_t * pucFrame,
|
||||
* slow with processing the received frame and the master sent another
|
||||
* frame on the network. We have to abort sending the frame.
|
||||
*/
|
||||
if( eRcvState == STATE_RX_IDLE )
|
||||
{
|
||||
if (eRcvState == STATE_RX_IDLE) {
|
||||
/* First byte before the Modbus-PDU is the slave address. */
|
||||
pucSndBufferCur = ( rt_uint8_t * ) pucFrame - 1;
|
||||
pucSndBufferCur = (rt_uint8_t *) pucFrame - 1;
|
||||
usSndBufferCount = 1;
|
||||
|
||||
/* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */
|
||||
@@ -158,16 +150,14 @@ eMBErrorCode eMBRTUSend( rt_uint8_t ucSlaveAddress, const rt_uint8_t * pucFrame,
|
||||
usSndBufferCount += usLength;
|
||||
|
||||
/* Calculate CRC16 checksum for Modbus-Serial-Line-PDU. */
|
||||
usCRC16 = usMBCRC16( ( rt_uint8_t * ) pucSndBufferCur, usSndBufferCount );
|
||||
ucRTUBuf[usSndBufferCount++] = ( rt_uint8_t )( usCRC16 & 0xFF );
|
||||
ucRTUBuf[usSndBufferCount++] = ( rt_uint8_t )( usCRC16 >> 8 );
|
||||
usCRC16 = usMBCRC16((rt_uint8_t *)pucSndBufferCur, usSndBufferCount);
|
||||
ucRTUBuf[usSndBufferCount++] = (rt_uint8_t)(usCRC16 & 0xFF);
|
||||
ucRTUBuf[usSndBufferCount++] = (rt_uint8_t)(usCRC16 >> 8);
|
||||
|
||||
/* Activate the transmitter. */
|
||||
eSndState = STATE_TX_XMIT;
|
||||
vMBPortSerialEnable( FALSE, TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
vMBPortSerialEnable(FALSE, TRUE);
|
||||
} else {
|
||||
eStatus = MB_EIO;
|
||||
}
|
||||
|
||||
@@ -176,18 +166,19 @@ eMBErrorCode eMBRTUSend( rt_uint8_t ucSlaveAddress, const rt_uint8_t * pucFrame,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
rt_uint8_t xMBRTUReceiveFSM( void )
|
||||
rt_uint8_t xMBRTUReceiveFSM (void)
|
||||
{
|
||||
rt_uint8_t xTaskNeedSwitch = FALSE;
|
||||
rt_uint8_t ucByte;
|
||||
rt_uint8_t xTaskNeedSwitch = FALSE;
|
||||
rt_uint8_t ucByte;
|
||||
|
||||
RT_ASSERT( eSndState == STATE_TX_IDLE );
|
||||
RT_ASSERT(eSndState == STATE_TX_IDLE);
|
||||
|
||||
/* Always read the character. */
|
||||
( void )xMBPortSerialGetByte((char *) &ucByte);
|
||||
(void)xMBPortSerialGetByte((char *)&ucByte);
|
||||
|
||||
switch ( eRcvState )
|
||||
{
|
||||
rt_kprintf("%02X ", ucByte);
|
||||
|
||||
switch (eRcvState) {
|
||||
/* If we have received a character in the init state we have to
|
||||
* wait until the frame is finished.
|
||||
*/
|
||||
@@ -221,12 +212,9 @@ rt_uint8_t xMBRTUReceiveFSM( void )
|
||||
* ignored.
|
||||
*/
|
||||
case STATE_RX_RCV:
|
||||
if( usRcvBufferPos < MB_SER_PDU_SIZE_MAX )
|
||||
{
|
||||
if (usRcvBufferPos < MB_SER_PDU_SIZE_MAX) {
|
||||
ucRTUBuf[usRcvBufferPos++] = ucByte;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
eRcvState = STATE_RX_ERROR;
|
||||
}
|
||||
vMBPortTimersEnable();
|
||||
@@ -235,36 +223,32 @@ rt_uint8_t xMBRTUReceiveFSM( void )
|
||||
return xTaskNeedSwitch;
|
||||
}
|
||||
|
||||
rt_uint8_t xMBRTUTransmitFSM( void )
|
||||
rt_uint8_t xMBRTUTransmitFSM (void)
|
||||
{
|
||||
rt_uint8_t xNeedPoll = FALSE;
|
||||
rt_uint8_t xNeedPoll = FALSE;
|
||||
|
||||
RT_ASSERT( eRcvState == STATE_RX_IDLE );
|
||||
RT_ASSERT(eRcvState == STATE_RX_IDLE);
|
||||
|
||||
switch ( eSndState )
|
||||
{
|
||||
switch (eSndState) {
|
||||
/* We should not get a transmitter event if the transmitter is in
|
||||
* 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 );
|
||||
if (usSndBufferCount != 0) {
|
||||
xMBPortSerialPutByte((char)*pucSndBufferCur);
|
||||
pucSndBufferCur++; /* next byte in sendbuffer. */
|
||||
usSndBufferCount--;
|
||||
}
|
||||
else
|
||||
{
|
||||
xNeedPoll = xMBPortEventPost( EV_FRAME_SENT );
|
||||
} else {
|
||||
xNeedPoll = xMBPortEventPost(EV_FRAME_SENT);
|
||||
/* Disable transmitter. This prevents another transmit buffer
|
||||
* empty interrupt. */
|
||||
eSndState = STATE_TX_IDLE;
|
||||
vMBPortSerialEnable( TRUE, FALSE );
|
||||
vMBPortSerialEnable(TRUE, FALSE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -272,21 +256,20 @@ rt_uint8_t xMBRTUTransmitFSM( void )
|
||||
return xNeedPoll;
|
||||
}
|
||||
|
||||
rt_uint8_t xMBRTUTimerT35Expired( void )
|
||||
rt_uint8_t xMBRTUTimerT35Expired (void)
|
||||
{
|
||||
rt_uint8_t xNeedPoll = FALSE;
|
||||
rt_uint8_t xNeedPoll = FALSE;
|
||||
|
||||
switch ( eRcvState )
|
||||
{
|
||||
switch (eRcvState) {
|
||||
/* Timer t35 expired. Startup phase is finished. */
|
||||
case STATE_RX_INIT:
|
||||
xNeedPoll = xMBPortEventPost( EV_READY );
|
||||
xNeedPoll = xMBPortEventPost(EV_READY);
|
||||
break;
|
||||
|
||||
/* A frame was received and t35 expired. Notify the listener that
|
||||
* a new frame was received. */
|
||||
case STATE_RX_RCV:
|
||||
xNeedPoll = xMBPortEventPost( EV_FRAME_RECEIVED );
|
||||
xNeedPoll = xMBPortEventPost(EV_FRAME_RECEIVED);
|
||||
break;
|
||||
|
||||
/* An error occured while receiving the frame. */
|
||||
@@ -295,8 +278,8 @@ rt_uint8_t xMBRTUTimerT35Expired( void )
|
||||
|
||||
/* Function called in an illegal state. */
|
||||
default:
|
||||
RT_ASSERT( ( eRcvState == STATE_RX_INIT ) ||
|
||||
( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
|
||||
RT_ASSERT((eRcvState == STATE_RX_INIT) ||
|
||||
(eRcvState == STATE_RX_RCV) || (eRcvState == STATE_RX_ERROR));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
eMBErrorCode eMBRTUInit( rt_uint8_t slaveAddress, rt_uint8_t ucPort,
|
||||
rt_uint32_t ulBaudRate, eMBParity eParity );
|
||||
void eMBRTUStart( void );
|
||||
void eMBRTUStop( void );
|
||||
eMBErrorCode eMBRTUReceive( rt_uint8_t * pucRcvAddress, rt_uint8_t ** pucFrame, rt_uint16_t * pusLength );
|
||||
eMBErrorCode eMBRTUSend( rt_uint8_t slaveAddress, const rt_uint8_t * pucFrame, rt_uint16_t usLength );
|
||||
rt_uint8_t xMBRTUReceiveFSM( void );
|
||||
rt_uint8_t xMBRTUTransmitFSM( void );
|
||||
rt_uint8_t xMBRTUTimerT15Expired( void );
|
||||
rt_uint8_t xMBRTUTimerT35Expired( void );
|
||||
eMBErrorCode eMBRTUInit (rt_uint8_t slaveAddress, rt_uint8_t ucPort,
|
||||
rt_uint32_t ulBaudRate, eMBParity eParity);
|
||||
void eMBRTUStart (void);
|
||||
void eMBRTUStop (void);
|
||||
eMBErrorCode eMBRTUReceive (rt_uint8_t * pucRcvAddress, rt_uint8_t ** pucFrame, rt_uint16_t * pusLength);
|
||||
eMBErrorCode eMBRTUSend (rt_uint8_t slaveAddress, const rt_uint8_t * pucFrame, rt_uint16_t usLength);
|
||||
rt_uint8_t xMBRTUReceiveFSM (void);
|
||||
rt_uint8_t xMBRTUTransmitFSM (void);
|
||||
|
||||
rt_uint8_t xMBRTUTimerT35Expired (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "mb.h"
|
||||
#include "mbport.h"
|
||||
|
||||
#include "mbrtu.h"
|
||||
|
||||
/* software simulation serial transmit IRQ handler thread stack */
|
||||
//rt_align(RT_ALIGN_SIZE)
|
||||
@@ -23,16 +23,49 @@ static struct rt_serial_device *serial;
|
||||
/* serial transmit event */
|
||||
#define EVENT_SERIAL_TRANS_START (1<<0)
|
||||
|
||||
static void prvvUARTTxReadyISR(void);
|
||||
static void prvvUARTRxISR(void);
|
||||
static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size);
|
||||
static void serial_soft_trans_irq(void* parameter);
|
||||
|
||||
rt_uint8_t xMBPortSerialInit(rt_uint8_t ucPORT, rt_uint32_t ulBaudRate,
|
||||
/**
|
||||
* This function is serial receive callback function
|
||||
*
|
||||
* @param dev the device of serial
|
||||
* @param size the data size that receive
|
||||
*
|
||||
* @return return RT_EOK
|
||||
*/
|
||||
static rt_err_t serial_rx_ind (rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
while (size--) {
|
||||
xMBRTUReceiveFSM();
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Software simulation serial transmit IRQ handler.
|
||||
*
|
||||
* @param parameter parameter
|
||||
*/
|
||||
static void serial_soft_trans_irq (void* parameter)
|
||||
{
|
||||
rt_uint32_t recved_event;
|
||||
|
||||
while (1) {
|
||||
/* waiting for serial transmit start */
|
||||
rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,
|
||||
RT_WAITING_FOREVER, &recved_event);
|
||||
|
||||
xMBRTUTransmitFSM();
|
||||
}
|
||||
}
|
||||
|
||||
rt_uint8_t xMBPortSerialInit (rt_uint8_t ucPORT, rt_uint32_t ulBaudRate,
|
||||
rt_uint8_t ucDataBits, eMBParity eParity)
|
||||
{
|
||||
rt_device_t dev = RT_NULL;
|
||||
char uart_name[20];
|
||||
|
||||
/**
|
||||
* set 485 mode receive and transmit control IO
|
||||
* @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user
|
||||
@@ -40,42 +73,44 @@ rt_uint8_t xMBPortSerialInit(rt_uint8_t ucPORT, rt_uint32_t ulBaudRate,
|
||||
#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
|
||||
rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
|
||||
#endif
|
||||
|
||||
/* set serial name */
|
||||
rt_snprintf(uart_name,sizeof(uart_name), "uart%d", ucPORT);
|
||||
|
||||
dev = rt_device_find(uart_name);
|
||||
if(dev == RT_NULL)
|
||||
{
|
||||
if(dev == RT_NULL) {
|
||||
/* can not find uart */
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
serial = (struct rt_serial_device*)dev;
|
||||
}
|
||||
|
||||
/* set serial configure parameter */
|
||||
serial->config.baud_rate = ulBaudRate;
|
||||
serial->config.stop_bits = STOP_BITS_1;
|
||||
switch(eParity){
|
||||
|
||||
switch (eParity) {
|
||||
case MB_PAR_NONE: {
|
||||
serial->config.data_bits = DATA_BITS_8;
|
||||
serial->config.parity = PARITY_NONE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MB_PAR_ODD: {
|
||||
serial->config.data_bits = DATA_BITS_9;
|
||||
serial->config.parity = PARITY_ODD;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MB_PAR_EVEN: {
|
||||
serial->config.data_bits = DATA_BITS_9;
|
||||
serial->config.parity = PARITY_EVEN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* set serial configure */
|
||||
serial->ops->configure(serial, &(serial->config));
|
||||
serial->ops->configure(serial, &serial->config);
|
||||
|
||||
/* open serial device */
|
||||
if (!rt_device_open(&serial->parent, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX)) {
|
||||
@@ -85,7 +120,7 @@ rt_uint8_t xMBPortSerialInit(rt_uint8_t ucPORT, rt_uint32_t ulBaudRate,
|
||||
}
|
||||
|
||||
/* software initialize */
|
||||
rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO);
|
||||
rt_event_init(&event_serial, "trans", RT_IPC_FLAG_PRIO);
|
||||
rt_thread_init(&thread_serial_soft_trans_irq,
|
||||
"thr.trans",
|
||||
serial_soft_trans_irq,
|
||||
@@ -98,9 +133,10 @@ rt_uint8_t xMBPortSerialInit(rt_uint8_t ucPORT, rt_uint32_t ulBaudRate,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void vMBPortSerialEnable(rt_uint8_t xRxEnable, rt_uint8_t xTxEnable)
|
||||
void vMBPortSerialEnable (rt_uint8_t xRxEnable, rt_uint8_t xTxEnable)
|
||||
{
|
||||
rt_uint32_t recved_event;
|
||||
|
||||
if (xRxEnable) {
|
||||
/* enable RX interrupt */
|
||||
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||
@@ -113,6 +149,7 @@ void vMBPortSerialEnable(rt_uint8_t xRxEnable, rt_uint8_t xTxEnable)
|
||||
#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
|
||||
rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
|
||||
#endif
|
||||
|
||||
/* disable RX interrupt */
|
||||
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||
}
|
||||
@@ -128,76 +165,26 @@ void vMBPortSerialEnable(rt_uint8_t xRxEnable, rt_uint8_t xTxEnable)
|
||||
}
|
||||
}
|
||||
|
||||
void vMBPortClose(void)
|
||||
void vMBPortClose (void)
|
||||
{
|
||||
serial->parent.close(&(serial->parent));
|
||||
serial->parent.close(&serial->parent);
|
||||
}
|
||||
|
||||
rt_uint8_t xMBPortSerialPutByte(char ucByte)
|
||||
rt_uint8_t xMBPortSerialPutByte (char ucByte)
|
||||
{
|
||||
serial->parent.write(&(serial->parent), 0, &ucByte, 1);
|
||||
serial->parent.write(&serial->parent, 0, &ucByte, 1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
rt_uint8_t xMBPortSerialGetByte(char * pucByte)
|
||||
rt_uint8_t xMBPortSerialGetByte (char * pucByte)
|
||||
{
|
||||
serial->parent.read(&(serial->parent), 0, pucByte, 1);
|
||||
serial->parent.read(&serial->parent, 0, pucByte, 1);
|
||||
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.
|
||||
*/
|
||||
void prvvUARTTxReadyISR(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.
|
||||
*/
|
||||
void prvvUARTRxISR(void)
|
||||
{
|
||||
pxMBFrameCBByteReceived();
|
||||
}
|
||||
|
||||
/**
|
||||
* Software simulation serial transmit IRQ handler.
|
||||
*
|
||||
* @param parameter parameter
|
||||
*/
|
||||
static void serial_soft_trans_irq(void* parameter) {
|
||||
rt_uint32_t recved_event;
|
||||
while (1)
|
||||
{
|
||||
/* waiting for serial transmit start */
|
||||
rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,
|
||||
RT_WAITING_FOREVER, &recved_event);
|
||||
/* execute modbus callback */
|
||||
prvvUARTTxReadyISR();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is serial receive callback function
|
||||
*
|
||||
* @param dev the device of serial
|
||||
* @param size the data size that receive
|
||||
*
|
||||
* @return return RT_EOK
|
||||
*/
|
||||
static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size) {
|
||||
while(size--)
|
||||
prvvUARTRxISR();
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,30 +3,26 @@
|
||||
|
||||
#include "mb.h"
|
||||
#include "mbport.h"
|
||||
#include "mbrtu.h"
|
||||
|
||||
static struct rt_timer timer;
|
||||
|
||||
void vMBPortTimersEnable()
|
||||
void vMBPortTimersEnable (void)
|
||||
{
|
||||
rt_timer_start(&timer);
|
||||
}
|
||||
|
||||
void vMBPortTimersDisable()
|
||||
void vMBPortTimersDisable (void)
|
||||
{
|
||||
rt_timer_stop(&timer);
|
||||
}
|
||||
|
||||
static void prvvTIMERExpiredISR(void)
|
||||
static void timer_timeout_ind (void* parameter)
|
||||
{
|
||||
(void)pxMBPortCBTimerExpired();
|
||||
xMBRTUTimerT35Expired();
|
||||
}
|
||||
|
||||
static void timer_timeout_ind(void* parameter)
|
||||
{
|
||||
prvvTIMERExpiredISR();
|
||||
}
|
||||
|
||||
rt_uint8_t xMBPortTimersInit(rt_uint16_t usTim1Timerout50us)
|
||||
rt_uint8_t xMBPortTimersInit (rt_uint16_t usTim1Timerout50us)
|
||||
{
|
||||
rt_timer_init(&timer, "tmr.mb",
|
||||
timer_timeout_ind, /* bind timeout callback function */
|
||||
|
||||
@@ -22,16 +22,16 @@ void xMBUtilSetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset,
|
||||
|
||||
/* Calculate byte offset for first byte containing the bit values starting
|
||||
* at usBitOffset. */
|
||||
usByteOffset = ( rt_uint16_t )( ( usBitOffset ) / BITS_UCHAR );
|
||||
usByteOffset = (rt_uint16_t)((usBitOffset) / BITS_UCHAR);
|
||||
|
||||
/* How many bits precede our bits to set. */
|
||||
usNPreBits = ( rt_uint16_t )( usBitOffset - usByteOffset * BITS_UCHAR );
|
||||
usNPreBits = (rt_uint16_t)(usBitOffset - usByteOffset * BITS_UCHAR);
|
||||
|
||||
/* Move bit field into position over bits to set */
|
||||
usValue <<= usNPreBits;
|
||||
|
||||
/* Prepare a mask for setting the new bits. */
|
||||
usMask = ( rt_uint16_t )( ( 1 << ( rt_uint16_t ) ucNBits ) - 1 );
|
||||
usMask = (rt_uint16_t)((1 << (rt_uint16_t)ucNBits) - 1);
|
||||
usMask <<= usBitOffset - usByteOffset * BITS_UCHAR;
|
||||
|
||||
/* copy bits into temporary storage. */
|
||||
@@ -39,11 +39,11 @@ void xMBUtilSetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset,
|
||||
usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR;
|
||||
|
||||
/* Zero out bit field bits and then or value bits into them. */
|
||||
usWordBuf = ( rt_uint16_t )( ( usWordBuf & ( ~usMask ) ) | usValue );
|
||||
usWordBuf = (rt_uint16_t)((usWordBuf & (~usMask)) | usValue);
|
||||
|
||||
/* move bits back into storage */
|
||||
ucByteBuf[usByteOffset] = ( rt_uint8_t )( usWordBuf & 0xFF );
|
||||
ucByteBuf[usByteOffset + 1] = ( rt_uint8_t )( usWordBuf >> BITS_UCHAR );
|
||||
ucByteBuf[usByteOffset] = (rt_uint8_t)(usWordBuf & 0xFF);
|
||||
ucByteBuf[usByteOffset + 1] = (rt_uint8_t)(usWordBuf >> BITS_UCHAR);
|
||||
}
|
||||
|
||||
rt_uint8_t xMBUtilGetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset, rt_uint8_t ucNBits)
|
||||
@@ -55,13 +55,13 @@ rt_uint8_t xMBUtilGetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset, rt_u
|
||||
|
||||
/* Calculate byte offset for first byte containing the bit values starting
|
||||
* at usBitOffset. */
|
||||
usByteOffset = ( rt_uint16_t )( ( usBitOffset ) / BITS_UCHAR );
|
||||
usByteOffset = (rt_uint16_t)((usBitOffset) / BITS_UCHAR);
|
||||
|
||||
/* How many bits precede our bits to set. */
|
||||
usNPreBits = ( rt_uint16_t )( usBitOffset - usByteOffset * BITS_UCHAR );
|
||||
usNPreBits = (rt_uint16_t)(usBitOffset - usByteOffset * BITS_UCHAR);
|
||||
|
||||
/* Prepare a mask for setting the new bits. */
|
||||
usMask = ( rt_uint16_t )( ( 1 << ( rt_uint16_t ) ucNBits ) - 1 );
|
||||
usMask = (rt_uint16_t)((1 << (rt_uint16_t)ucNBits) - 1);
|
||||
|
||||
/* copy bits into temporary storage. */
|
||||
usWordBuf = ucByteBuf[usByteOffset];
|
||||
@@ -73,32 +73,34 @@ rt_uint8_t xMBUtilGetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset, rt_u
|
||||
/* mask away bits above the requested bitfield. */
|
||||
usWordBuf &= usMask;
|
||||
|
||||
return ( rt_uint8_t ) usWordBuf;
|
||||
return (rt_uint8_t)usWordBuf;
|
||||
}
|
||||
|
||||
eMBException prveMBError2Exception( eMBErrorCode eErrorCode )
|
||||
eMBException prveMBError2Exception (eMBErrorCode eErrorCode)
|
||||
{
|
||||
eMBException eStatus;
|
||||
|
||||
switch ( eErrorCode ) {
|
||||
case MB_ENOERR:
|
||||
eStatus = MB_EX_NONE;
|
||||
break;
|
||||
switch (eErrorCode) {
|
||||
case MB_ENOERR:
|
||||
eStatus = MB_EX_NONE;
|
||||
break;
|
||||
|
||||
case MB_ENOREG:
|
||||
eStatus = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||
break;
|
||||
case MB_ENOREG:
|
||||
eStatus = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||
break;
|
||||
|
||||
case MB_ETIMEDOUT:
|
||||
eStatus = MB_EX_SLAVE_BUSY;
|
||||
break;
|
||||
case MB_ETIMEDOUT:
|
||||
eStatus = MB_EX_SLAVE_BUSY;
|
||||
break;
|
||||
|
||||
default:
|
||||
eStatus = MB_EX_SLAVE_DEVICE_FAILURE;
|
||||
break;
|
||||
default:
|
||||
eStatus = MB_EX_SLAVE_DEVICE_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "mb.h"
|
||||
#include "chrg_mb.h"
|
||||
#include "mbutils.h"
|
||||
#include "mbport.h"
|
||||
|
||||
#include "chrg_comm.h"
|
||||
|
||||
|
||||
@@ -10,39 +12,229 @@
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
|
||||
extern rt_uint16_t usSRegHoldBuf[S_REG_HOLDING_NREGS];
|
||||
//Slave mode:DiscreteInputs variables
|
||||
rt_uint16_t usSDiscInStart = S_DISCRETE_INPUT_START;
|
||||
rt_uint8_t ucSDiscInBuf[(S_DISCRETE_INPUT_NDISCRETES+7)/8];
|
||||
|
||||
//Slave mode:Coils variables
|
||||
rt_uint16_t usSCoilStart = S_COIL_START;
|
||||
rt_uint8_t ucSCoilBuf[(S_COIL_NCOILS+7)/8];
|
||||
|
||||
//Slave mode:InputRegister variables
|
||||
rt_uint16_t usSRegInStart = S_REG_INPUT_START;
|
||||
rt_uint16_t usSRegInBuf[S_REG_INPUT_NREGS];
|
||||
|
||||
//Slave mode:HoldingRegister variables
|
||||
rt_uint16_t usSRegHoldStart = S_REG_HOLDING_START;
|
||||
rt_uint16_t usSRegHoldBuf[S_REG_HOLDING_NREGS];
|
||||
|
||||
/**
|
||||
* Modbus slave input register callback function.
|
||||
*
|
||||
* @param pucRegBuffer input register buffer
|
||||
* @param usAddress input register address
|
||||
* @param usNRegs input register number
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegInputCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNRegs)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex;
|
||||
rt_uint16_t *pusRegInputBuf = usSRegInBuf;
|
||||
rt_uint16_t REG_INPUT_START = S_REG_INPUT_START;
|
||||
rt_uint16_t REG_INPUT_NREGS = S_REG_INPUT_NREGS;
|
||||
rt_uint16_t usRegInStart = usSRegInStart;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= REG_INPUT_START)
|
||||
&& (usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS)) {
|
||||
iRegIndex = usAddress - usRegInStart;
|
||||
while (usNRegs > 0) {
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegInputBuf[iRegIndex] >> 8);
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegInputBuf[iRegIndex] & 0xFF);
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave holding register callback function.
|
||||
*
|
||||
* @param pucRegBuffer holding register buffer
|
||||
* @param usAddress holding register address
|
||||
* @param usNRegs holding register number
|
||||
* @param eMode read or write
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegHoldingCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t usNRegs, eMBRegisterMode eMode)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex;
|
||||
rt_uint16_t *pusRegHoldingBuf = usSRegHoldBuf;
|
||||
rt_uint16_t REG_HOLDING_START = S_REG_HOLDING_START;
|
||||
rt_uint16_t REG_HOLDING_NREGS = S_REG_HOLDING_NREGS;
|
||||
rt_uint16_t usRegHoldStart = usSRegHoldStart;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= REG_HOLDING_START)
|
||||
&& (usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS)) {
|
||||
iRegIndex = usAddress - usRegHoldStart;
|
||||
switch (eMode) {
|
||||
/* read current register values from the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while (usNRegs > 0) {
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegHoldingBuf[iRegIndex] >> 8);
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegHoldingBuf[iRegIndex] & 0xFF);
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
break;
|
||||
|
||||
/* write current register values with new values from the protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while (usNRegs > 0) {
|
||||
pusRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
|
||||
pusRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave coils callback function.
|
||||
*
|
||||
* @param pucRegBuffer coils buffer
|
||||
* @param usAddress coils address
|
||||
* @param usNCoils coils number
|
||||
* @param eMode read or write
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegCoilsCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t usNCoils, eMBRegisterMode eMode)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex , iRegBitIndex , iNReg;
|
||||
rt_uint8_t *pucCoilBuf = ucSCoilBuf;
|
||||
rt_uint16_t COIL_START = S_COIL_START;
|
||||
rt_uint16_t COIL_NCOILS = S_COIL_NCOILS;
|
||||
rt_uint16_t usCoilStart = usSCoilStart;
|
||||
|
||||
iNReg = usNCoils / 8 + 1;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= COIL_START) &&
|
||||
(usAddress + usNCoils <= COIL_START + COIL_NCOILS)) {
|
||||
iRegIndex = (rt_uint16_t)(usAddress - usCoilStart) / 8;
|
||||
iRegBitIndex = (rt_uint16_t)(usAddress - usCoilStart) % 8;
|
||||
switch (eMode) {
|
||||
/* read current coil values from the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while (iNReg > 0) {
|
||||
*pucRegBuffer++ = xMBUtilGetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8);
|
||||
iNReg--;
|
||||
}
|
||||
pucRegBuffer--;
|
||||
/* last coils */
|
||||
usNCoils = usNCoils % 8;
|
||||
/* filling zero to high bit */
|
||||
*pucRegBuffer = *pucRegBuffer << (8 - usNCoils);
|
||||
*pucRegBuffer = *pucRegBuffer >> (8 - usNCoils);
|
||||
break;
|
||||
|
||||
/* write current coil values with new values from the protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while (iNReg > 1) {
|
||||
xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8, *pucRegBuffer++);
|
||||
iNReg--;
|
||||
}
|
||||
/* last coils */
|
||||
usNCoils = usNCoils % 8;
|
||||
/* xMBUtilSetBits has bug when ucNBits is zero */
|
||||
if (usNCoils != 0) {
|
||||
xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, usNCoils, *pucRegBuffer++);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave discrete callback function.
|
||||
*
|
||||
* @param pucRegBuffer discrete buffer
|
||||
* @param usAddress discrete address
|
||||
* @param usNDiscrete discrete number
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegDiscreteCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNDiscrete)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex , iRegBitIndex , iNReg;
|
||||
rt_uint8_t *pucDiscreteInputBuf = ucSDiscInBuf;
|
||||
rt_uint16_t DISCRETE_INPUT_START = S_DISCRETE_INPUT_START;
|
||||
rt_uint16_t DISCRETE_INPUT_NDISCRETES = S_DISCRETE_INPUT_NDISCRETES;
|
||||
rt_uint16_t usDiscreteInputStart = usSDiscInStart;
|
||||
iNReg = usNDiscrete / 8 + 1;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= DISCRETE_INPUT_START)
|
||||
&& ((usAddress + usNDiscrete) <= (DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))) {
|
||||
iRegIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) / 8;
|
||||
iRegBitIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) % 8;
|
||||
|
||||
while (iNReg > 0) {
|
||||
*pucRegBuffer++ = xMBUtilGetBits(&pucDiscreteInputBuf[iRegIndex++], iRegBitIndex, 8);
|
||||
iNReg--;
|
||||
}
|
||||
pucRegBuffer--;
|
||||
/* last discrete */
|
||||
usNDiscrete = usNDiscrete % 8;
|
||||
/* filling zero to high bit */
|
||||
*pucRegBuffer = *pucRegBuffer << (8 - usNDiscrete);
|
||||
*pucRegBuffer = *pucRegBuffer >> (8 - usNDiscrete);
|
||||
} else {
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
struct chrg_comm_t chrgcomm = {
|
||||
.tid_poll = RT_NULL,
|
||||
.tid_send = RT_NULL,
|
||||
.name_poll = THR_NAME_POLL,
|
||||
.name_send = THR_NAME_SEND,
|
||||
.tid = RT_NULL,
|
||||
.name = THR_NAME_POLL,
|
||||
.addr = MODBUS_ADDRESS_DEFAULT,
|
||||
|
||||
};
|
||||
|
||||
static void chrg_comm_send (void *pdata)
|
||||
{
|
||||
struct chrg_comm_t *pCOMM = (struct chrg_comm_t *)pdata;
|
||||
if (RT_NULL == pCOMM) {
|
||||
LOG_E("send null.");
|
||||
return ;
|
||||
}
|
||||
|
||||
rt_uint16_t *usRegHoldingBuf;
|
||||
usRegHoldingBuf = usSRegHoldBuf;
|
||||
rt_base_t level;
|
||||
|
||||
while (1) {
|
||||
level = rt_hw_interrupt_disable();
|
||||
usRegHoldingBuf[3] = (rt_uint16_t)(rt_tick_get() / 100);
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void chrg_comm_poll (void *pdata)
|
||||
{
|
||||
struct chrg_comm_t *pCOMM = (struct chrg_comm_t *)pdata;
|
||||
@@ -57,7 +249,7 @@ static void chrg_comm_poll (void *pdata)
|
||||
|
||||
while (1) {
|
||||
eMBPoll();
|
||||
rt_thread_mdelay(200);
|
||||
rt_thread_mdelay(100);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,21 +258,12 @@ static int chrg_comm_init (void)
|
||||
{
|
||||
struct chrg_comm_t *pCOMM = &chrgcomm;
|
||||
|
||||
pCOMM->tid_poll = rt_thread_create(pCOMM->name_poll, chrg_comm_poll,
|
||||
pCOMM->tid = rt_thread_create(pCOMM->name, chrg_comm_poll,
|
||||
pCOMM, 1024, RT_MAIN_THREAD_PRIORITY-1, 10);
|
||||
if (RT_NULL != pCOMM->tid_poll) {
|
||||
rt_thread_startup(pCOMM->tid_poll);
|
||||
if (RT_NULL != pCOMM->tid) {
|
||||
rt_thread_startup(pCOMM->tid);
|
||||
} else {
|
||||
LOG_E("create thread '%s' failed.", pCOMM->name_poll);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pCOMM->tid_send = rt_thread_create(pCOMM->name_send, chrg_comm_send,
|
||||
pCOMM, 1024, RT_MAIN_THREAD_PRIORITY-2, 10);
|
||||
if (RT_NULL != pCOMM->tid_send) {
|
||||
rt_thread_startup(pCOMM->tid_send);
|
||||
} else {
|
||||
LOG_E("create thread '%s' failed.", pCOMM->name_send);
|
||||
LOG_E("create thread '%s' failed.", pCOMM->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -90,5 +273,18 @@ static int chrg_comm_init (void)
|
||||
|
||||
INIT_APP_EXPORT(chrg_comm_init);
|
||||
|
||||
int rs485_test_send (int argc, char **argv)
|
||||
{
|
||||
char i = 0;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
xMBPortSerialPutByte(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(rs485_test_send, test rs485 send);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,12 +6,29 @@
|
||||
|
||||
#define MODBUS_ADDRESS_DEFAULT 0x01
|
||||
|
||||
struct chrg_comm_t {
|
||||
rt_thread_t tid_poll;
|
||||
rt_thread_t tid_send;
|
||||
#define S_DISCRETE_INPUT_START 0
|
||||
#define S_DISCRETE_INPUT_NDISCRETES 16
|
||||
#define S_COIL_START 0
|
||||
#define S_COIL_NCOILS 64
|
||||
#define S_REG_INPUT_START 0
|
||||
#define S_REG_INPUT_NREGS 100
|
||||
#define S_REG_HOLDING_START 0
|
||||
#define S_REG_HOLDING_NREGS 100
|
||||
|
||||
const char *name_poll;
|
||||
const char *name_send;
|
||||
/* salve mode: holding register's all address */
|
||||
#define S_HD_RESERVE 0
|
||||
/* salve mode: input register's all address */
|
||||
#define S_IN_RESERVE 0
|
||||
/* salve mode: coil's all address */
|
||||
#define S_CO_RESERVE 0
|
||||
/* salve mode: discrete's all address */
|
||||
#define S_DI_RESERVE 0
|
||||
|
||||
|
||||
|
||||
struct chrg_comm_t {
|
||||
rt_thread_t tid;
|
||||
const char *name;
|
||||
|
||||
rt_uint8_t addr; // slave address
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
struct chrg_north_t chrgnorth = {
|
||||
.name = THR_NAME_NORTH,
|
||||
.devname = DEV_NAME_NORTH,
|
||||
.tid = RT_NULL,
|
||||
.tty = RT_NULL,
|
||||
.rx_len = 0,
|
||||
@@ -94,7 +95,7 @@ static int chrg_north_init (void)
|
||||
rt_err_t ret;
|
||||
struct chrg_north_t *pNOR = &chrgnorth;
|
||||
|
||||
pNOR->tty = chrg_tty_create("uart3", 2000000, 0, -1, 1);
|
||||
pNOR->tty = chrg_tty_create(pNOR->devname, 2000000, 0, -1, 1);
|
||||
if (RT_NULL == pNOR->tty) {
|
||||
LOG_E("tty can't create.");
|
||||
return -1;
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
|
||||
|
||||
#define THR_NAME_NORTH "thr.nor"
|
||||
#define DEV_NAME_NORTH "uart3"
|
||||
|
||||
struct chrg_north_t {
|
||||
const char *name;
|
||||
const char *devname;
|
||||
struct rt_thread *tid;
|
||||
struct rt_mutex lock;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
struct chrg_south_t chrgsouth = {
|
||||
.name = THR_NAME_SOUTH,
|
||||
.devname = DEV_NAME_SOUTH,
|
||||
.tid = RT_NULL,
|
||||
.tty = RT_NULL,
|
||||
.rx_len = 0,
|
||||
@@ -93,7 +94,7 @@ static int chrg_south_init (void)
|
||||
rt_err_t ret;
|
||||
struct chrg_south_t *pSOU = &chrgsouth;
|
||||
|
||||
pSOU->tty = chrg_tty_create("uart6", 2000000, 0, -1, 1);
|
||||
pSOU->tty = chrg_tty_create(pSOU->devname, 2000000, 0, -1, 1);
|
||||
if (RT_NULL == pSOU->tty) {
|
||||
LOG_E("tty can't create.");
|
||||
return -1;
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
#include "chrg_switch.h"
|
||||
|
||||
#define THR_NAME_SOUTH "thr.sou"
|
||||
#define DEV_NAME_SOUTH "uart6"
|
||||
|
||||
struct chrg_south_t {
|
||||
const char *name;
|
||||
const char *devname;
|
||||
struct rt_thread *tid;
|
||||
struct rt_mutex lock;
|
||||
|
||||
|
||||
@@ -1,266 +0,0 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "mb.h"
|
||||
#include "mbutils.h"
|
||||
|
||||
#include "chrg_mb.h"
|
||||
|
||||
//Slave mode:DiscreteInputs variables
|
||||
rt_uint16_t usSDiscInStart = S_DISCRETE_INPUT_START;
|
||||
rt_uint8_t ucSDiscInBuf[(S_DISCRETE_INPUT_NDISCRETES+7)/8];
|
||||
|
||||
//Slave mode:Coils variables
|
||||
rt_uint16_t usSCoilStart = S_COIL_START;
|
||||
rt_uint8_t ucSCoilBuf[(S_COIL_NCOILS+7)/8];
|
||||
|
||||
//Slave mode:InputRegister variables
|
||||
rt_uint16_t usSRegInStart = S_REG_INPUT_START;
|
||||
rt_uint16_t usSRegInBuf[S_REG_INPUT_NREGS];
|
||||
|
||||
//Slave mode:HoldingRegister variables
|
||||
rt_uint16_t usSRegHoldStart = S_REG_HOLDING_START;
|
||||
rt_uint16_t usSRegHoldBuf[S_REG_HOLDING_NREGS];
|
||||
|
||||
/**
|
||||
* Modbus slave input register callback function.
|
||||
*
|
||||
* @param pucRegBuffer input register buffer
|
||||
* @param usAddress input register address
|
||||
* @param usNRegs input register number
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegInputCB(rt_uint8_t * pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNRegs )
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex;
|
||||
rt_uint16_t * pusRegInputBuf;
|
||||
rt_uint16_t REG_INPUT_START;
|
||||
rt_uint16_t REG_INPUT_NREGS;
|
||||
rt_uint16_t usRegInStart;
|
||||
|
||||
pusRegInputBuf = usSRegInBuf;
|
||||
REG_INPUT_START = S_REG_INPUT_START;
|
||||
REG_INPUT_NREGS = S_REG_INPUT_NREGS;
|
||||
usRegInStart = usSRegInStart;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= REG_INPUT_START)
|
||||
&& (usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS))
|
||||
{
|
||||
iRegIndex = usAddress - usRegInStart;
|
||||
while (usNRegs > 0)
|
||||
{
|
||||
*pucRegBuffer++ = (rt_uint8_t) (pusRegInputBuf[iRegIndex] >> 8);
|
||||
*pucRegBuffer++ = (rt_uint8_t) (pusRegInputBuf[iRegIndex] & 0xFF);
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave holding register callback function.
|
||||
*
|
||||
* @param pucRegBuffer holding register buffer
|
||||
* @param usAddress holding register address
|
||||
* @param usNRegs holding register number
|
||||
* @param eMode read or write
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegHoldingCB(rt_uint8_t * pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t usNRegs, eMBRegisterMode eMode)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex;
|
||||
rt_uint16_t * pusRegHoldingBuf;
|
||||
rt_uint16_t REG_HOLDING_START;
|
||||
rt_uint16_t REG_HOLDING_NREGS;
|
||||
rt_uint16_t usRegHoldStart;
|
||||
|
||||
pusRegHoldingBuf = usSRegHoldBuf;
|
||||
REG_HOLDING_START = S_REG_HOLDING_START;
|
||||
REG_HOLDING_NREGS = S_REG_HOLDING_NREGS;
|
||||
usRegHoldStart = usSRegHoldStart;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= REG_HOLDING_START)
|
||||
&& (usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS))
|
||||
{
|
||||
iRegIndex = usAddress - usRegHoldStart;
|
||||
switch (eMode)
|
||||
{
|
||||
/* read current register values from the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while (usNRegs > 0)
|
||||
{
|
||||
*pucRegBuffer++ = (rt_uint8_t) (pusRegHoldingBuf[iRegIndex] >> 8);
|
||||
*pucRegBuffer++ = (rt_uint8_t) (pusRegHoldingBuf[iRegIndex] & 0xFF);
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
break;
|
||||
|
||||
/* write current register values with new values from the protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while (usNRegs > 0)
|
||||
{
|
||||
pusRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
|
||||
pusRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave coils callback function.
|
||||
*
|
||||
* @param pucRegBuffer coils buffer
|
||||
* @param usAddress coils address
|
||||
* @param usNCoils coils number
|
||||
* @param eMode read or write
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegCoilsCB(rt_uint8_t * pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t usNCoils, eMBRegisterMode eMode)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex , iRegBitIndex , iNReg;
|
||||
rt_uint8_t * pucCoilBuf;
|
||||
rt_uint16_t COIL_START;
|
||||
rt_uint16_t COIL_NCOILS;
|
||||
rt_uint16_t usCoilStart;
|
||||
iNReg = usNCoils / 8 + 1;
|
||||
|
||||
pucCoilBuf = ucSCoilBuf;
|
||||
COIL_START = S_COIL_START;
|
||||
COIL_NCOILS = S_COIL_NCOILS;
|
||||
usCoilStart = usSCoilStart;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if( ( usAddress >= COIL_START ) &&
|
||||
( usAddress + usNCoils <= COIL_START + COIL_NCOILS ) )
|
||||
{
|
||||
iRegIndex = (rt_uint16_t) (usAddress - usCoilStart) / 8;
|
||||
iRegBitIndex = (rt_uint16_t) (usAddress - usCoilStart) % 8;
|
||||
switch ( eMode )
|
||||
{
|
||||
/* read current coil values from the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while (iNReg > 0)
|
||||
{
|
||||
*pucRegBuffer++ = xMBUtilGetBits(&pucCoilBuf[iRegIndex++],
|
||||
iRegBitIndex, 8);
|
||||
iNReg--;
|
||||
}
|
||||
pucRegBuffer--;
|
||||
/* last coils */
|
||||
usNCoils = usNCoils % 8;
|
||||
/* filling zero to high bit */
|
||||
*pucRegBuffer = *pucRegBuffer << (8 - usNCoils);
|
||||
*pucRegBuffer = *pucRegBuffer >> (8 - usNCoils);
|
||||
break;
|
||||
|
||||
/* write current coil values with new values from the protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while (iNReg > 1)
|
||||
{
|
||||
xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8,
|
||||
*pucRegBuffer++);
|
||||
iNReg--;
|
||||
}
|
||||
/* last coils */
|
||||
usNCoils = usNCoils % 8;
|
||||
/* xMBUtilSetBits has bug when ucNBits is zero */
|
||||
if (usNCoils != 0)
|
||||
{
|
||||
xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, usNCoils,
|
||||
*pucRegBuffer++);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave discrete callback function.
|
||||
*
|
||||
* @param pucRegBuffer discrete buffer
|
||||
* @param usAddress discrete address
|
||||
* @param usNDiscrete discrete number
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegDiscreteCB( rt_uint8_t * pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNDiscrete )
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex , iRegBitIndex , iNReg;
|
||||
rt_uint8_t * pucDiscreteInputBuf;
|
||||
rt_uint16_t DISCRETE_INPUT_START;
|
||||
rt_uint16_t DISCRETE_INPUT_NDISCRETES;
|
||||
rt_uint16_t usDiscreteInputStart;
|
||||
iNReg = usNDiscrete / 8 + 1;
|
||||
|
||||
pucDiscreteInputBuf = ucSDiscInBuf;
|
||||
DISCRETE_INPUT_START = S_DISCRETE_INPUT_START;
|
||||
DISCRETE_INPUT_NDISCRETES = S_DISCRETE_INPUT_NDISCRETES;
|
||||
usDiscreteInputStart = usSDiscInStart;
|
||||
|
||||
/* it already plus one in modbus function method. */
|
||||
usAddress--;
|
||||
|
||||
if ((usAddress >= DISCRETE_INPUT_START)
|
||||
&& (usAddress + usNDiscrete <= DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))
|
||||
{
|
||||
iRegIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) / 8;
|
||||
iRegBitIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) % 8;
|
||||
|
||||
while (iNReg > 0)
|
||||
{
|
||||
*pucRegBuffer++ = xMBUtilGetBits(&pucDiscreteInputBuf[iRegIndex++],
|
||||
iRegBitIndex, 8);
|
||||
iNReg--;
|
||||
}
|
||||
pucRegBuffer--;
|
||||
/* last discrete */
|
||||
usNDiscrete = usNDiscrete % 8;
|
||||
/* filling zero to high bit */
|
||||
*pucRegBuffer = *pucRegBuffer << (8 - usNDiscrete);
|
||||
*pucRegBuffer = *pucRegBuffer >> (8 - usNDiscrete);
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef __CHRG_MB_H__
|
||||
#define __CHRG_MB_H__
|
||||
|
||||
|
||||
#define S_DISCRETE_INPUT_START 0
|
||||
#define S_DISCRETE_INPUT_NDISCRETES 16
|
||||
#define S_COIL_START 0
|
||||
#define S_COIL_NCOILS 64
|
||||
#define S_REG_INPUT_START 0
|
||||
#define S_REG_INPUT_NREGS 100
|
||||
#define S_REG_HOLDING_START 0
|
||||
#define S_REG_HOLDING_NREGS 100
|
||||
|
||||
/* salve mode: holding register's all address */
|
||||
#define S_HD_RESERVE 0
|
||||
/* salve mode: input register's all address */
|
||||
#define S_IN_RESERVE 0
|
||||
/* salve mode: coil's all address */
|
||||
#define S_CO_RESERVE 0
|
||||
/* salve mode: discrete's all address */
|
||||
#define S_DI_RESERVE 0
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+165
-170
@@ -337,9 +337,9 @@
|
||||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define>__CLK_TCK=RT_TICK_PER_SECOND, __STDC_LIMIT_MACROS, __RTTHREAD__, RT_USING_LIBC, STM32F405xx, USE_HAL_DRIVER, RT_USING_ARMLIBC</Define>
|
||||
<Define>__STDC_LIMIT_MACROS, RT_USING_LIBC, RT_USING_ARMLIBC, USE_HAL_DRIVER, STM32F405xx, __RTTHREAD__, __CLK_TCK=RT_TICK_PER_SECOND</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>board\ports;applications\utils;..\..\libs\stm32f4\STM32F4_CMSIS\Include;..\..\rt-thread\components\fal\inc;..\..\rt-thread\components\libc\compilers\common\extension\fcntl\octal;..\..\rt-thread\components\drivers\include;..\..\libs\stm32f4\STM32F4_HAL\Inc\Legacy;..\..\rt-thread\components\finsh;..\..\rt-thread\components\drivers\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\config;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\compilers\common\include;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\posix\io\eventfd;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\drivers\include;.;..\..\rt-thread\components\drivers\phy;..\..\rt-thread\components\libc\posix\io\poll;..\..\libs\stm32f4\STM32F4_HAL\Inc;applications\bsp;..\..\rt-thread\components\drivers\smp_call;applications\mb;..\..\rt-thread\libcpu\arm\cortex-m4;..\..\rt-thread\components\drivers\include;..\..\libs\cmsis-core\Include;..\..\rt-thread\components\libc\posix\ipc;..\..\rt-thread\components\libc\posix\io\epoll;..\..\rt-thread\components\drivers\include;applications;board;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers;applications\thread;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers;..\..\rt-thread\components\libc\compilers\common\extension;..\..\rt-thread\include;board\CubeMX_Config\Inc;..\..\rt-thread\components\drivers\include;..\..\rt-thread\libcpu\arm\common;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\drv_flash</IncludePath>
|
||||
<IncludePath>..\..\rt-thread\components\drivers\phy;applications\mb;..\..\rt-thread\components\drivers\include;applications\thread;..\..\rt-thread\components\libc\compilers\common\extension\fcntl\octal;..\..\rt-thread\libcpu\arm\common;applications;..\..\rt-thread\components\libc\compilers\common\extension;..\..\rt-thread\components\drivers\include;.;applications\utils;..\..\libs\stm32f4\STM32F4_CMSIS\Include;..\..\rt-thread\include;board\ports;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\config;..\..\libs\stm32f4\STM32F4_HAL\Inc;..\..\rt-thread\components\libc\posix\ipc;..\..\rt-thread\components\libc\compilers\common\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers;..\..\rt-thread\components\libc\posix\io\epoll;board\CubeMX_Config\Inc;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\drv_flash;..\..\rt-thread\components\finsh;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\drivers\smp_call;..\..\rt-thread\libcpu\arm\cortex-m4;..\..\rt-thread\components\libc\posix\io\poll;..\..\rt-thread\components\fal\inc;..\..\libs\cmsis-core\Include;..\..\rt-thread\components\drivers\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\posix\io\eventfd;applications\bsp;..\..\rt-thread\components\drivers\include;..\..\libs\stm32f4\STM32F4_HAL\Inc\Legacy;board;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\drivers\include</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@@ -393,26 +393,6 @@
|
||||
<Group>
|
||||
<GroupName>Applications/bsp</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>chrg_fal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_fal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_clk.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_clk.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_wdt.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_wdt.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_intr.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_intr.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_switch.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -423,15 +403,25 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_tty.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_pin.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_pin.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_can.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_can.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_i2c.c</FileName>
|
||||
<FileName>chrg_fal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_i2c.c</FilePath>
|
||||
<FilePath>applications\bsp\chrg_fal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_intr.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_intr.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_tmr.c</FileName>
|
||||
@@ -439,35 +429,25 @@
|
||||
<FilePath>applications\bsp\chrg_tmr.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_pin.c</FileName>
|
||||
<FileName>chrg_wdt.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_pin.c</FilePath>
|
||||
<FilePath>applications\bsp\chrg_wdt.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_clk.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_clk.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_i2c.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_i2c.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Applications/mb</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>mbrtu.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbrtu.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbtimer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbtimer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbport.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbport.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mb.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mb.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbserial.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -478,21 +458,41 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbevent.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbport.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbport.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbutils.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbutils.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbcrc.c</FileName>
|
||||
<FileName>mb.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbcrc.c</FilePath>
|
||||
<FilePath>applications\mb\mb.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbrtu.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbrtu.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbtimer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbtimer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbfunc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbfunc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>mbcrc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\mb\mbcrc.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -508,40 +508,30 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_comm.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_south.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_south.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_north.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_north.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_south.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_south.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Applications/utils</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>chrg_sink.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_sink.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_source.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_source.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_pkg.c</FileName>
|
||||
<FileName>chrg_sink.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_pkg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_mb.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_mb.c</FilePath>
|
||||
<FilePath>applications\utils\chrg_sink.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_utils.c</FileName>
|
||||
@@ -553,6 +543,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_pcf8574.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_pkg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_pkg.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -1677,9 +1672,9 @@
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_partition.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal_rtt.c</FileName>
|
||||
<FileName>fal_flash.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_rtt.c</FilePath>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_flash.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal.c</FileName>
|
||||
@@ -1687,9 +1682,9 @@
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal_flash.c</FileName>
|
||||
<FileName>fal_rtt.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_flash.c</FilePath>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_rtt.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
@@ -1697,9 +1692,9 @@
|
||||
<GroupName>Finsh</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>shell.c</FileName>
|
||||
<FileName>msh.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\finsh\shell.c</FilePath>
|
||||
<FilePath>..\..\rt-thread\components\finsh\msh.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>msh_parse.c</FileName>
|
||||
@@ -1707,9 +1702,9 @@
|
||||
<FilePath>..\..\rt-thread\components\finsh\msh_parse.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>msh.c</FileName>
|
||||
<FileName>shell.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\finsh\msh.c</FilePath>
|
||||
<FilePath>..\..\rt-thread\components\finsh\shell.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>cmd.c</FileName>
|
||||
@@ -2566,21 +2561,16 @@
|
||||
<Group>
|
||||
<GroupName>klibc</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>kstdio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kstdio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>kerrno.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kerrno.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>kstring.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kstring.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>kstdio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kstdio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>rt_vsscanf.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -2591,6 +2581,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\rt_vsnprintf_tiny.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>kerrno.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kerrno.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -2626,111 +2621,46 @@
|
||||
<Group>
|
||||
<GroupName>STM32F4-CMSIS</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>system_stm32f4xx.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_CMSIS\Source\Templates\system_stm32f4xx.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>startup_stm32f405xx.s</FileName>
|
||||
<FileType>2</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_CMSIS\Source\Templates\arm\startup_stm32f405xx.s</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>system_stm32f4xx.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_CMSIS\Source\Templates\system_stm32f4xx.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>STM32F4-HAL</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_usart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_usart.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cortex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cortex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_iwdg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_iwdg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cryp.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_lptim.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_lptim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_i2c.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_i2c.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ramfunc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ramfunc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cec.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cec.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_wwdg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_wwdg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_tim_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_tim_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cryp_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_uart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_uart.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_gpio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_i2c_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_i2c_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_lptim.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_lptim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -2742,40 +2672,105 @@
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rcc.c</FileName>
|
||||
<FileName>stm32f4xx_hal_flash_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_can.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_can.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_crc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_crc.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_tim_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_tim_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ramfunc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ramfunc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rng.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rng.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cortex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cortex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_can.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_can.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_iwdg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_iwdg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_usart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_usart.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_crc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_crc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_tim.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_tim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_wwdg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_wwdg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_gpio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cryp_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rcc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cryp.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
</Groups>
|
||||
|
||||
Reference in New Issue
Block a user