diff options
Diffstat (limited to 'apps/modbus/nuttx/portother.c')
-rw-r--r-- | apps/modbus/nuttx/portother.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/apps/modbus/nuttx/portother.c b/apps/modbus/nuttx/portother.c index 12f79defe..fef826760 100644 --- a/apps/modbus/nuttx/portother.c +++ b/apps/modbus/nuttx/portother.c @@ -22,6 +22,7 @@ */ /* ----------------------- Standard includes --------------------------------*/ + #include <nuttx/config.h> #include <stdio.h> #include <stdlib.h> @@ -33,72 +34,73 @@ #include "port.h" /* ----------------------- Modbus includes ----------------------------------*/ + #include <apps/modbus/mb.h> #include <apps/modbus/mbport.h> /* ----------------------- Defines ------------------------------------------*/ -#define NELEMS( x ) ( sizeof( ( x ) )/sizeof( ( x )[0] ) ) + +#define NELEMS(x) (sizeof((x))/sizeof((x)[0])) /* ----------------------- Static variables ---------------------------------*/ + static FILE *fLogFile = NULL; static eMBPortLogLevel eLevelMax = MB_LOG_DEBUG; static pthread_mutex_t xLock = PTHREAD_MUTEX_INITIALIZER; /* ----------------------- Start implementation -----------------------------*/ -void -vMBPortLogLevel( eMBPortLogLevel eNewLevelMax ) + +void vMBPortLogLevel(eMBPortLogLevel eNewLevelMax) { - eLevelMax = eNewLevelMax; + eLevelMax = eNewLevelMax; } -void -vMBPortLogFile( FILE * fNewLogFile ) +void vMBPortLogFile(FILE * fNewLogFile) { - fLogFile = fNewLogFile; + fLogFile = fNewLogFile; } -void -vMBPortLog( eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ... ) +void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ...) { - char szBuf[512]; - int i; - va_list args; - FILE *fOutput = fLogFile == NULL ? stderr : fLogFile; + char szBuf[512]; + int i; + va_list args; + FILE *fOutput = fLogFile == NULL ? stderr : fLogFile; - static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" }; + static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" }; - i = snprintf( szBuf, NELEMS( szBuf ), "%s: %s: ", arszLevel2Str[eLevel], szModule ); + i = snprintf(szBuf, NELEMS(szBuf), "%s: %s: ", arszLevel2Str[eLevel], szModule); - if( i != 0 ) + if (i != 0) { - va_start( args, szFmt ); - i += vsnprintf( &szBuf[i], NELEMS( szBuf ) - i, szFmt, args ); - va_end( args ); + va_start(args, szFmt); + i += vsnprintf(&szBuf[i], NELEMS(szBuf) - i, szFmt, args); + va_end(args); } - if( i != 0 ) + if (i != 0) { - if( eLevel <= eLevelMax ) + if (eLevel <= eLevelMax) { - fputs( szBuf, fOutput ); + fputs(szBuf, fOutput); } } } -void -vMBPortEnterCritical( void ) +void vMBPortEnterCritical(void) { - if( pthread_mutex_lock( &xLock ) != 0 ) + int ret = pthread_mutex_lock(&xLock); + if (ret != 0) { - vMBPortLog( MB_LOG_ERROR, "OTHER", "Locking primitive failed: %s\n", strerror( errno ) ); + vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret); } } -void -vMBPortExitCritical( void ) +void vMBPortExitCritical(void) { - if( pthread_mutex_unlock( &xLock ) != 0 ) + int ret = pthread_mutex_unlock(&xLock); + if (ret != 0) { - vMBPortLog( MB_LOG_ERROR, "OTHER", "Locking primitive failed: %s\n", strerror( errno ) ); + vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret); } } |