2015-04-07 23:57:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/modbus/nuttx/portserial.c
|
2012-07-21 16:56:21 +02:00
|
|
|
*
|
2015-04-08 00:48:09 +02:00
|
|
|
* FreeModbus Library: NuttX Port
|
2015-04-07 23:57:52 +02:00
|
|
|
* Copyright (c) 2006 Christian Walter <wolti@sil.at>
|
|
|
|
* All rights reserved.
|
2012-07-21 16:56:21 +02:00
|
|
|
*
|
2015-04-07 23:57:52 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
2012-07-21 16:56:21 +02:00
|
|
|
*
|
2015-04-07 23:57:52 +02:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2012-07-21 16:56:21 +02:00
|
|
|
*
|
2015-04-07 23:57:52 +02:00
|
|
|
****************************************************************************/
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2012-07-21 16:56:21 +02:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/select.h>
|
2015-02-15 22:18:35 +01:00
|
|
|
#include <sys/time.h>
|
2012-07-21 16:56:21 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2012-07-21 18:18:16 +02:00
|
|
|
#include <assert.h>
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-23 17:37:13 +02:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
2012-07-22 19:41:19 +02:00
|
|
|
# include <termios.h>
|
|
|
|
#endif
|
|
|
|
|
2012-07-21 16:56:21 +02:00
|
|
|
#include "port.h"
|
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "modbus/mb.h"
|
|
|
|
#include "modbus/mbport.h"
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2012-07-21 16:56:21 +02:00
|
|
|
#ifdef CONFIG_MB_ASCII_ENABLED
|
|
|
|
#define BUF_SIZE 513 /* must hold a complete ASCII frame. */
|
|
|
|
#else
|
|
|
|
#define BUF_SIZE 256 /* must hold a complete RTU frame. */
|
|
|
|
#endif
|
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2012-07-21 16:56:21 +02:00
|
|
|
static int iSerialFd = -1;
|
2012-07-21 23:23:18 +02:00
|
|
|
static bool bRxEnabled;
|
|
|
|
static bool bTxEnabled;
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-21 23:23:18 +02:00
|
|
|
static uint32_t ulTimeoutMs;
|
|
|
|
static uint8_t ucBuffer[BUF_SIZE];
|
2012-07-21 16:56:21 +02:00
|
|
|
static int uiRxBufferPos;
|
|
|
|
static int uiTxBufferPos;
|
|
|
|
|
2012-07-23 17:37:13 +02:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
2012-07-21 16:56:21 +02:00
|
|
|
static struct termios xOldTIO;
|
2012-07-22 19:41:19 +02:00
|
|
|
#endif
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool prvbMBPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes,
|
|
|
|
uint16_t *usNBytesRead);
|
|
|
|
static bool prvbMBPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool prvbMBPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes,
|
|
|
|
uint16_t *usNBytesRead)
|
|
|
|
{
|
|
|
|
bool bResult = true;
|
|
|
|
ssize_t res;
|
|
|
|
fd_set rfds;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 50000;
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
FD_SET(iSerialFd, &rfds);
|
|
|
|
|
|
|
|
/* Wait until character received or timeout. Recover in case of an
|
|
|
|
* interrupted read system call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (select(iSerialFd + 1, &rfds, NULL, NULL, &tv) == -1)
|
|
|
|
{
|
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
bResult = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FD_ISSET(iSerialFd, &rfds))
|
|
|
|
{
|
|
|
|
if ((res = read(iSerialFd, pucBuffer, usNBytes)) == -1)
|
|
|
|
{
|
|
|
|
bResult = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*usNBytesRead = (uint16_t)res;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*usNBytesRead = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (bResult == true);
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool prvbMBPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes)
|
|
|
|
{
|
|
|
|
ssize_t res;
|
|
|
|
size_t left = (size_t) usNBytes;
|
|
|
|
size_t done = 0;
|
|
|
|
|
|
|
|
while (left > 0)
|
|
|
|
{
|
|
|
|
if ((res = write(iSerialFd, pucBuffer + done, left)) == -1)
|
|
|
|
{
|
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call write again because of interrupted system call. */
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
done += res;
|
|
|
|
left -= res;
|
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
return left == 0 ? true : false;
|
|
|
|
}
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
void vMBPortSerialEnable(bool bEnableRx, bool bEnableTx)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
/* it is not allowed that both receiver and transmitter are enabled. */
|
|
|
|
|
2018-08-24 14:19:35 +02:00
|
|
|
DEBUGASSERT(!bEnableRx || !bEnableTx);
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
if (bEnableRx)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-23 17:37:13 +02:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
2020-01-02 13:09:50 +01:00
|
|
|
tcflush(iSerialFd, TCIFLUSH);
|
2012-07-22 19:41:19 +02:00
|
|
|
#endif
|
|
|
|
uiRxBufferPos = 0;
|
|
|
|
bRxEnabled = true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
bRxEnabled = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
if (bEnableTx)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
bTxEnabled = true;
|
|
|
|
uiTxBufferPos = 0;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
bTxEnabled = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:10:21 +02:00
|
|
|
bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate,
|
2012-07-22 19:41:19 +02:00
|
|
|
uint8_t ucDataBits, eMBParity eParity)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
char szDevice[16];
|
|
|
|
bool bStatus = true;
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-23 17:37:13 +02:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
|
|
|
struct termios xNewTIO;
|
2012-07-22 19:41:19 +02:00
|
|
|
#endif
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
snprintf(szDevice, 16, "/dev/ttyS%d", ucPort);
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
if ((iSerialFd = open(szDevice, O_RDWR | O_NOCTTY)) < 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't open serial port %s: %d\n",
|
|
|
|
szDevice, errno);
|
2016-03-16 13:31:48 +01:00
|
|
|
bStatus = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2012-07-23 17:37:13 +02:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
2012-07-22 19:41:19 +02:00
|
|
|
else if (tcgetattr(iSerialFd, &xOldTIO) != 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n",
|
|
|
|
szDevice, errno);
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2017-02-16 22:58:15 +01:00
|
|
|
memset(&xNewTIO, 0, sizeof(struct termios));
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
xNewTIO.c_iflag |= IGNBRK | INPCK;
|
|
|
|
xNewTIO.c_cflag |= CREAD | CLOCAL;
|
|
|
|
switch (eParity)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
case MB_PAR_NONE:
|
2012-07-21 16:56:21 +02:00
|
|
|
break;
|
2015-04-07 23:57:52 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
case MB_PAR_EVEN:
|
2012-07-21 16:56:21 +02:00
|
|
|
xNewTIO.c_cflag |= PARENB;
|
|
|
|
break;
|
2015-04-07 23:57:52 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
case MB_PAR_ODD:
|
2012-07-21 16:56:21 +02:00
|
|
|
xNewTIO.c_cflag |= PARENB | PARODD;
|
|
|
|
break;
|
2015-04-07 23:57:52 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
default:
|
2012-07-21 23:23:18 +02:00
|
|
|
bStatus = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
switch (ucDataBits)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
case 8:
|
2012-07-21 16:56:21 +02:00
|
|
|
xNewTIO.c_cflag |= CS8;
|
|
|
|
break;
|
2015-04-07 23:57:52 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
case 7:
|
2012-07-21 16:56:21 +02:00
|
|
|
xNewTIO.c_cflag |= CS7;
|
|
|
|
break;
|
2015-04-07 23:57:52 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
default:
|
2012-07-21 23:23:18 +02:00
|
|
|
bStatus = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
if (bStatus)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-24 17:10:21 +02:00
|
|
|
/* Set the new baud. The following might be compatible with other
|
|
|
|
* OSs for the following reason.
|
|
|
|
*
|
|
|
|
* (1) In NuttX, cfset[i|o]speed always return OK so failures will
|
|
|
|
* really only be reported when tcsetattr() is called.
|
|
|
|
* (2) NuttX does not support separate input and output speeds so it
|
|
|
|
* is not necessary to call both cfsetispeed() and
|
|
|
|
* cfsetospeed(), and
|
|
|
|
* (3) In NuttX, the input value to cfiset[i|o]speed is not
|
|
|
|
* encoded, but is the absolute baud value. The following might
|
2014-04-14 00:24:28 +02:00
|
|
|
* not be
|
2012-07-23 17:37:13 +02:00
|
|
|
*/
|
|
|
|
|
2012-07-24 17:10:21 +02:00
|
|
|
if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
|
|
|
ulBaudRate, szDevice, errno);
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else if (tcsetattr(iSerialFd, TCSANOW, &xNewTIO) != 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set settings for port %s: %d\n",
|
|
|
|
szDevice, errno);
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortSerialEnable(false, false);
|
|
|
|
bStatus = true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return bStatus;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
bool xMBPortSerialSetTimeout(uint32_t ulNewTimeoutMs)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (ulNewTimeoutMs > 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
ulTimeoutMs = ulNewTimeoutMs;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
ulTimeoutMs = 1;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
return true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
void vMBPortClose(void)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (iSerialFd != -1)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-23 17:37:13 +02:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
2020-01-02 13:09:50 +01:00
|
|
|
tcsetattr(iSerialFd, TCSANOW, &xOldTIO);
|
2012-07-22 19:41:19 +02:00
|
|
|
#endif
|
2020-01-02 13:09:50 +01:00
|
|
|
close(iSerialFd);
|
2012-07-22 19:41:19 +02:00
|
|
|
iSerialFd = -1;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
bool xMBPortSerialPoll(void)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
bool bStatus = true;
|
|
|
|
uint16_t usBytesRead;
|
|
|
|
int i;
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
while (bRxEnabled)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
if (prvbMBPortSerialRead(&ucBuffer[0], BUF_SIZE, &usBytesRead))
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
if (usBytesRead == 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
/* timeout with no bytes. */
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
break;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2015-04-07 23:57:52 +02:00
|
|
|
else if (usBytesRead > 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
for (i = 0; i < usBytesRead; i++)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
/* Call the modbus stack and let him fill the buffers. */
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
pxMBFrameCBByteReceived();
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2015-04-07 23:57:52 +02:00
|
|
|
|
|
|
|
uiRxBufferPos = 0;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-07 23:57:52 +02:00
|
|
|
else
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-POLL", "read failed on serial device: %d\n",
|
|
|
|
errno);
|
|
|
|
bStatus = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-07 23:57:52 +02:00
|
|
|
|
|
|
|
if (bTxEnabled)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
while (bTxEnabled)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2020-01-02 13:09:50 +01:00
|
|
|
pxMBFrameCBTransmitterEmpty();
|
2015-04-07 23:57:52 +02:00
|
|
|
|
|
|
|
/* Call the modbus stack to let him fill the buffer. */
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2015-04-07 23:57:52 +02:00
|
|
|
|
|
|
|
if (!prvbMBPortSerialWrite(&ucBuffer[0], uiTxBufferPos))
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2015-04-07 23:57:52 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-POLL", "write failed on serial device: %d\n",
|
|
|
|
errno);
|
|
|
|
bStatus = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
return bStatus;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
bool xMBPortSerialPutByte(int8_t ucByte)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2018-08-24 14:19:35 +02:00
|
|
|
DEBUGASSERT(uiTxBufferPos < BUF_SIZE);
|
2015-04-07 23:57:52 +02:00
|
|
|
ucBuffer[uiTxBufferPos] = ucByte;
|
|
|
|
uiTxBufferPos++;
|
|
|
|
return true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 23:57:52 +02:00
|
|
|
bool xMBPortSerialGetByte(int8_t *pucByte)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2018-08-24 14:19:35 +02:00
|
|
|
DEBUGASSERT(uiRxBufferPos < BUF_SIZE);
|
2015-04-07 23:57:52 +02:00
|
|
|
*pucByte = ucBuffer[uiRxBufferPos];
|
|
|
|
uiRxBufferPos++;
|
|
|
|
return true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|