summaryrefslogtreecommitdiff
path: root/apps/modbus/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-07-21 21:23:18 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-07-21 21:23:18 +0000
commitd9714b556703561a0abcbe71970b1cd6922168a6 (patch)
tree70b7893243b8ee2e6b8b5fd95106c4ab962699c5 /apps/modbus/nuttx
parentebf70f8a79eb8ef23bc1d99938768ef06c466119 (diff)
downloadpx4-nuttx-d9714b556703561a0abcbe71970b1cd6922168a6.tar.gz
px4-nuttx-d9714b556703561a0abcbe71970b1cd6922168a6.tar.bz2
px4-nuttx-d9714b556703561a0abcbe71970b1cd6922168a6.zip
Use NuttX types in FreeModBus port; Add FreeModBus demo at apps/examples/modbus; Add new termios APIs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4964 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/modbus/nuttx')
-rw-r--r--apps/modbus/nuttx/port.h24
-rw-r--r--apps/modbus/nuttx/portevent.c24
-rw-r--r--apps/modbus/nuttx/portother.c4
-rw-r--r--apps/modbus/nuttx/portserial.c88
-rw-r--r--apps/modbus/nuttx/porttimer.c16
5 files changed, 75 insertions, 81 deletions
diff --git a/apps/modbus/nuttx/port.h b/apps/modbus/nuttx/port.h
index 6bb9ab1ba..d958791d9 100644
--- a/apps/modbus/nuttx/port.h
+++ b/apps/modbus/nuttx/port.h
@@ -43,12 +43,12 @@ PR_BEGIN_EXTERN_C
#define MB_PORT_HAS_CLOSE 1
-#ifndef TRUE
-# define TRUE true
+#ifndef true
+# define true true
#endif
-#ifndef FALSE
-# define FALSE false
+#ifndef false
+# define false false
#endif
/* ----------------------- Type definitions ---------------------------------*/
@@ -61,23 +61,15 @@ typedef enum
MB_LOG_DEBUG = 3
} eMBPortLogLevel;
-typedef bool BOOL;
-typedef uint8_t UCHAR;
-typedef int8_t CHAR;
-typedef uint16_t USHORT;
-typedef int16_t SHORT;
-typedef uint32_t ULONG;
-typedef int32_t LONG;
-
/* ----------------------- Function prototypes ------------------------------*/
void vMBPortEnterCritical(void);
void vMBPortExitCritical(void);
-void vMBPortLog(eMBPortLogLevel eLevel, const CHAR * szModule,
- const CHAR * szFmt, ...);
+void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule,
+ const char * szFmt, ...);
void vMBPortTimerPoll(void);
-BOOL xMBPortSerialPoll(void);
-BOOL xMBPortSerialSetTimeout(ULONG dwTimeoutMs);
+bool xMBPortSerialPoll(void);
+bool xMBPortSerialSetTimeout(uint32_t dwTimeoutMs);
#ifdef __cplusplus
PR_END_EXTERN_C
diff --git a/apps/modbus/nuttx/portevent.c b/apps/modbus/nuttx/portevent.c
index e96eb3d73..72c02f8ed 100644
--- a/apps/modbus/nuttx/portevent.c
+++ b/apps/modbus/nuttx/portevent.c
@@ -25,36 +25,38 @@
#include <apps/modbus/mb.h>
#include <apps/modbus/mbport.h>
+#include "port.h"
+
/* ----------------------- Variables ----------------------------------------*/
static eMBEventType eQueuedEvent;
-static BOOL xEventInQueue;
+static bool xEventInQueue;
/* ----------------------- Start implementation -----------------------------*/
-BOOL
+bool
xMBPortEventInit( void )
{
- xEventInQueue = FALSE;
- return TRUE;
+ xEventInQueue = false;
+ return true;
}
-BOOL
+bool
xMBPortEventPost( eMBEventType eEvent )
{
- xEventInQueue = TRUE;
+ xEventInQueue = true;
eQueuedEvent = eEvent;
- return TRUE;
+ return true;
}
-BOOL
+bool
xMBPortEventGet( eMBEventType * eEvent )
{
- BOOL xEventHappened = FALSE;
+ bool xEventHappened = false;
if( xEventInQueue )
{
*eEvent = eQueuedEvent;
- xEventInQueue = FALSE;
- xEventHappened = TRUE;
+ xEventInQueue = false;
+ xEventHappened = true;
}
else
{
diff --git a/apps/modbus/nuttx/portother.c b/apps/modbus/nuttx/portother.c
index d74d28de3..12f79defe 100644
--- a/apps/modbus/nuttx/portother.c
+++ b/apps/modbus/nuttx/portother.c
@@ -58,9 +58,9 @@ vMBPortLogFile( FILE * fNewLogFile )
}
void
-vMBPortLog( eMBPortLogLevel eLevel, const CHAR * szModule, const CHAR * szFmt, ... )
+vMBPortLog( eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ... )
{
- CHAR szBuf[512];
+ char szBuf[512];
int i;
va_list args;
FILE *fOutput = fLogFile == NULL ? stderr : fLogFile;
diff --git a/apps/modbus/nuttx/portserial.c b/apps/modbus/nuttx/portserial.c
index a30f7f4aa..f62166373 100644
--- a/apps/modbus/nuttx/portserial.c
+++ b/apps/modbus/nuttx/portserial.c
@@ -50,23 +50,23 @@
/* ----------------------- Static variables ---------------------------------*/
static int iSerialFd = -1;
-static BOOL bRxEnabled;
-static BOOL bTxEnabled;
+static bool bRxEnabled;
+static bool bTxEnabled;
-static ULONG ulTimeoutMs;
-static UCHAR ucBuffer[BUF_SIZE];
+static uint32_t ulTimeoutMs;
+static uint8_t ucBuffer[BUF_SIZE];
static int uiRxBufferPos;
static int uiTxBufferPos;
static struct termios xOldTIO;
/* ----------------------- Function prototypes ------------------------------*/
-static BOOL prvbMBPortSerialRead( UCHAR * pucBuffer, USHORT usNBytes, USHORT * usNBytesRead );
-static BOOL prvbMBPortSerialWrite( UCHAR * pucBuffer, USHORT usNBytes );
+static bool prvbMBPortSerialRead( uint8_t * pucBuffer, uint16_t usNBytes, uint16_t * usNBytesRead );
+static bool prvbMBPortSerialWrite( uint8_t * pucBuffer, uint16_t usNBytes );
/* ----------------------- Begin implementation -----------------------------*/
void
-vMBPortSerialEnable( BOOL bEnableRx, BOOL bEnableTx )
+vMBPortSerialEnable( bool bEnableRx, bool bEnableTx )
{
/* it is not allowed that both receiver and transmitter are enabled. */
ASSERT( !bEnableRx || !bEnableTx );
@@ -75,28 +75,28 @@ vMBPortSerialEnable( BOOL bEnableRx, BOOL bEnableTx )
{
( void )tcflush( iSerialFd, TCIFLUSH );
uiRxBufferPos = 0;
- bRxEnabled = TRUE;
+ bRxEnabled = true;
}
else
{
- bRxEnabled = FALSE;
+ bRxEnabled = false;
}
if( bEnableTx )
{
- bTxEnabled = TRUE;
+ bTxEnabled = true;
uiTxBufferPos = 0;
}
else
{
- bTxEnabled = FALSE;
+ bTxEnabled = false;
}
}
-BOOL
-xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
+bool
+xMBPortSerialInit( uint8_t ucPort, uint32_t ulBaudRate, uint8_t ucDataBits, eMBParity eParity )
{
- CHAR szDevice[16];
- BOOL bStatus = TRUE;
+ char szDevice[16];
+ bool bStatus = true;
struct termios xNewTIO;
speed_t xNewSpeed;
@@ -130,7 +130,7 @@ xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity e
xNewTIO.c_cflag |= PARENB | PARODD;
break;
default:
- bStatus = FALSE;
+ bStatus = false;
}
switch ( ucDataBits )
{
@@ -141,7 +141,7 @@ xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity e
xNewTIO.c_cflag |= CS7;
break;
default:
- bStatus = FALSE;
+ bStatus = false;
}
switch ( ulBaudRate )
{
@@ -161,7 +161,7 @@ xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity e
xNewSpeed = B115200;
break;
default:
- bStatus = FALSE;
+ bStatus = false;
}
if( bStatus )
{
@@ -182,16 +182,16 @@ xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity e
}
else
{
- vMBPortSerialEnable( FALSE, FALSE );
- bStatus = TRUE;
+ vMBPortSerialEnable( false, false );
+ bStatus = true;
}
}
}
return bStatus;
}
-BOOL
-xMBPortSerialSetTimeout( ULONG ulNewTimeoutMs )
+bool
+xMBPortSerialSetTimeout( uint32_t ulNewTimeoutMs )
{
if( ulNewTimeoutMs > 0 )
{
@@ -201,7 +201,7 @@ xMBPortSerialSetTimeout( ULONG ulNewTimeoutMs )
{
ulTimeoutMs = 1;
}
- return TRUE;
+ return true;
}
void
@@ -215,10 +215,10 @@ vMBPortClose( void )
}
}
-BOOL
-prvbMBPortSerialRead( UCHAR * pucBuffer, USHORT usNBytes, USHORT * usNBytesRead )
+bool
+prvbMBPortSerialRead( uint8_t * pucBuffer, uint16_t usNBytes, uint16_t * usNBytesRead )
{
- BOOL bResult = TRUE;
+ bool bResult = true;
ssize_t res;
fd_set rfds;
struct timeval tv;
@@ -236,18 +236,18 @@ prvbMBPortSerialRead( UCHAR * pucBuffer, USHORT usNBytes, USHORT * usNBytesRead
{
if( errno != EINTR )
{
- bResult = FALSE;
+ bResult = false;
}
}
else if( FD_ISSET( iSerialFd, &rfds ) )
{
if( ( res = read( iSerialFd, pucBuffer, usNBytes ) ) == -1 )
{
- bResult = FALSE;
+ bResult = false;
}
else
{
- *usNBytesRead = ( USHORT ) res;
+ *usNBytesRead = ( uint16_t ) res;
break;
}
}
@@ -257,12 +257,12 @@ prvbMBPortSerialRead( UCHAR * pucBuffer, USHORT usNBytes, USHORT * usNBytesRead
break;
}
}
- while( bResult == TRUE );
+ while( bResult == true );
return bResult;
}
-BOOL
-prvbMBPortSerialWrite( UCHAR * pucBuffer, USHORT usNBytes )
+bool
+prvbMBPortSerialWrite( uint8_t * pucBuffer, uint16_t usNBytes )
{
ssize_t res;
size_t left = ( size_t ) usNBytes;
@@ -282,14 +282,14 @@ prvbMBPortSerialWrite( UCHAR * pucBuffer, USHORT usNBytes )
done += res;
left -= res;
}
- return left == 0 ? TRUE : FALSE;
+ return left == 0 ? true : false;
}
-BOOL
+bool
xMBPortSerialPoll( )
{
- BOOL bStatus = TRUE;
- USHORT usBytesRead;
+ bool bStatus = true;
+ uint16_t usBytesRead;
int i;
while( bRxEnabled )
@@ -315,7 +315,7 @@ xMBPortSerialPoll( )
{
vMBPortLog( MB_LOG_ERROR, "SER-POLL", "read failed on serial device: %s\n",
strerror( errno ) );
- bStatus = FALSE;
+ bStatus = false;
}
}
if( bTxEnabled )
@@ -329,27 +329,27 @@ xMBPortSerialPoll( )
{
vMBPortLog( MB_LOG_ERROR, "SER-POLL", "write failed on serial device: %s\n",
strerror( errno ) );
- bStatus = FALSE;
+ bStatus = false;
}
}
return bStatus;
}
-BOOL
-xMBPortSerialPutByte( CHAR ucByte )
+bool
+xMBPortSerialPutByte( int8_t ucByte )
{
ASSERT( uiTxBufferPos < BUF_SIZE );
ucBuffer[uiTxBufferPos] = ucByte;
uiTxBufferPos++;
- return TRUE;
+ return true;
}
-BOOL
-xMBPortSerialGetByte( CHAR * pucByte )
+bool
+xMBPortSerialGetByte( int8_t * pucByte )
{
ASSERT( uiRxBufferPos < BUF_SIZE );
*pucByte = ucBuffer[uiRxBufferPos];
uiRxBufferPos++;
- return TRUE;
+ return true;
}
diff --git a/apps/modbus/nuttx/porttimer.c b/apps/modbus/nuttx/porttimer.c
index 3ff2d78ae..d688c4f52 100644
--- a/apps/modbus/nuttx/porttimer.c
+++ b/apps/modbus/nuttx/porttimer.c
@@ -37,14 +37,14 @@
/* ----------------------- Defines ------------------------------------------*/
/* ----------------------- Static variables ---------------------------------*/
-ULONG ulTimeOut;
-BOOL bTimeoutEnable;
+uint32_t ulTimeOut;
+bool bTimeoutEnable;
static struct timeval xTimeLast;
/* ----------------------- Start implementation -----------------------------*/
-BOOL
-xMBPortTimersInit( USHORT usTim1Timerout50us )
+bool
+xMBPortTimersInit( uint16_t usTim1Timerout50us )
{
ulTimeOut = usTim1Timerout50us / 20U;
if( ulTimeOut == 0 )
@@ -62,7 +62,7 @@ xMBPortTimersClose( )
void
vMBPortTimerPoll( )
{
- ULONG ulDeltaMS;
+ uint32_t ulDeltaMS;
struct timeval xTimeCur;
/* Timers are called from the serial layer because we have no high
@@ -79,7 +79,7 @@ vMBPortTimerPoll( )
( xTimeCur.tv_usec - xTimeLast.tv_usec ) * 1000L;
if( ulDeltaMS > ulTimeOut )
{
- bTimeoutEnable = FALSE;
+ bTimeoutEnable = false;
( void )pxMBPortCBTimerExpired( );
}
}
@@ -92,11 +92,11 @@ vMBPortTimersEnable( )
int res = gettimeofday( &xTimeLast, NULL );
ASSERT( res == 0 );
- bTimeoutEnable = TRUE;
+ bTimeoutEnable = true;
}
void
vMBPortTimersDisable( )
{
- bTimeoutEnable = FALSE;
+ bTimeoutEnable = false;
}