2012-07-21 16:56:21 +02:00
|
|
|
/*
|
2012-07-21 18:18:16 +02:00
|
|
|
* FreeModbus Libary: NuttX Port
|
|
|
|
* Based on the FreeModbus Linux port by:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Christian Walter <wolti@sil.at>
|
2012-07-21 16:56:21 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* File: $Id: portserial.c,v 1.3 2006/10/12 08:35:34 wolti Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------------- Standard includes --------------------------------*/
|
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>
|
|
|
|
#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"
|
|
|
|
|
|
|
|
/* ----------------------- Modbus includes ----------------------------------*/
|
2012-07-22 19:41:19 +02:00
|
|
|
|
2012-07-21 18:18:16 +02:00
|
|
|
#include <apps/modbus/mb.h>
|
|
|
|
#include <apps/modbus/mbport.h>
|
2012-07-21 16:56:21 +02:00
|
|
|
|
|
|
|
/* ----------------------- Defines -----------------------------------------*/
|
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
|
|
|
|
|
|
|
|
/* ----------------------- Static variables ---------------------------------*/
|
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
|
|
|
|
|
|
|
/* ----------------------- Function prototypes ------------------------------*/
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
static bool prvbMBPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes, uint16_t *usNBytesRead);
|
|
|
|
static bool prvbMBPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes);
|
2012-07-21 16:56:21 +02:00
|
|
|
|
|
|
|
/* ----------------------- Begin implementation -----------------------------*/
|
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. */
|
|
|
|
|
|
|
|
ASSERT(!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
|
2012-07-22 19:41:19 +02:00
|
|
|
(void)tcflush(iSerialFd, TCIFLUSH);
|
|
|
|
#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);
|
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
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
bzero(&xNewTIO, 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;
|
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;
|
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;
|
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;
|
2012-07-22 19:41:19 +02:00
|
|
|
case 7:
|
2012-07-21 16:56:21 +02:00
|
|
|
xNewTIO.c_cflag |= CS7;
|
|
|
|
break;
|
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
|
|
|
|
* 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
|
2012-07-22 19:41:19 +02:00
|
|
|
(void)tcsetattr(iSerialFd, TCSANOW, &xOldTIO);
|
|
|
|
#endif
|
|
|
|
(void)close(iSerialFd);
|
|
|
|
iSerialFd = -1;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
bool prvbMBPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes, uint16_t *usNBytesRead)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
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
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (select(iSerialFd + 1, &rfds, NULL, NULL, &tv) == -1)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (errno != EINTR)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
bResult = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else if (FD_ISSET(iSerialFd, &rfds))
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if ((res = read(iSerialFd, pucBuffer, usNBytes)) == -1)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
bResult = false;
|
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
|
|
|
*usNBytesRead = (uint16_t)res;
|
|
|
|
break;
|
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
|
|
|
*usNBytesRead = 0;
|
|
|
|
break;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
while(bResult == true);
|
|
|
|
return bResult;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
bool prvbMBPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
ssize_t res;
|
|
|
|
size_t left = (size_t) usNBytes;
|
|
|
|
size_t done = 0;
|
2012-07-21 16:56:21 +02:00
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
while(left > 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if ((res = write(iSerialFd, pucBuffer + done, left)) == -1)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (errno != EINTR)
|
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
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
/* call write again because of interrupted system call. */
|
|
|
|
continue;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
done += res;
|
|
|
|
left -= res;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
|
|
|
|
return left == 0 ? true : false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2012-07-21 23:23:18 +02:00
|
|
|
bool
|
2012-07-22 19:41:19 +02:00
|
|
|
xMBPortSerialPoll()
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-21 23:23:18 +02:00
|
|
|
bool bStatus = true;
|
|
|
|
uint16_t usBytesRead;
|
2012-07-21 16:56:21 +02:00
|
|
|
int i;
|
|
|
|
|
2012-07-22 19:41:19 +02:00
|
|
|
while(bRxEnabled)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (prvbMBPortSerialRead(&ucBuffer[0], BUF_SIZE, &usBytesRead))
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
if (usBytesRead == 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
|
|
|
/* timeout with no bytes. */
|
|
|
|
break;
|
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
else if (usBytesRead > 0)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
for(i = 0; i < usBytesRead; i++)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
|
|
|
/* Call the modbus stack and let him fill the buffers. */
|
2012-07-22 19:41:19 +02:00
|
|
|
(void)pxMBFrameCBByteReceived();
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
uiRxBufferPos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-POLL", "read failed on serial device: %d\n",
|
|
|
|
errno);
|
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 (bTxEnabled)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
while(bTxEnabled)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
(void)pxMBFrameCBTransmitterEmpty();
|
2012-07-21 16:56:21 +02:00
|
|
|
/* Call the modbus stack to let him fill the buffer. */
|
|
|
|
}
|
2012-07-22 19:41:19 +02:00
|
|
|
if (!prvbMBPortSerialWrite(&ucBuffer[0], uiTxBufferPos))
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
vMBPortLog(MB_LOG_ERROR, "SER-POLL", "write failed on serial device: %d\n",
|
|
|
|
errno);
|
2012-07-21 23:23:18 +02:00
|
|
|
bStatus = false;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bStatus;
|
|
|
|
}
|
|
|
|
|
2012-07-21 23:23:18 +02:00
|
|
|
bool
|
2012-07-22 19:41:19 +02:00
|
|
|
xMBPortSerialPutByte(int8_t ucByte)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
ASSERT(uiTxBufferPos < BUF_SIZE);
|
2012-07-21 16:56:21 +02:00
|
|
|
ucBuffer[uiTxBufferPos] = ucByte;
|
|
|
|
uiTxBufferPos++;
|
2012-07-21 23:23:18 +02:00
|
|
|
return true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|
|
|
|
|
2012-07-21 23:23:18 +02:00
|
|
|
bool
|
2012-07-22 19:41:19 +02:00
|
|
|
xMBPortSerialGetByte(int8_t *pucByte)
|
2012-07-21 16:56:21 +02:00
|
|
|
{
|
2012-07-22 19:41:19 +02:00
|
|
|
ASSERT(uiRxBufferPos < BUF_SIZE);
|
2012-07-21 16:56:21 +02:00
|
|
|
*pucByte = ucBuffer[uiRxBufferPos];
|
|
|
|
uiRxBufferPos++;
|
2012-07-21 23:23:18 +02:00
|
|
|
return true;
|
2012-07-21 16:56:21 +02:00
|
|
|
}
|