add EMBEDDED_IN_VM compilation flag to remove debugging and signal handling

This commit is contained in:
Ksenia Balistreri 2015-04-08 19:20:07 +02:00
parent 232136f4fa
commit 9e72562f27
2 changed files with 99 additions and 112 deletions

View File

@ -4,7 +4,7 @@ AR = ar
RANLIB = ranlib
SIZE = size
CFLAGS = -O3 -Wall
CFLAGS += -O3 -Wall
LIB1 = libpigpio.a
OBJ1 = pigpio.o command.o
@ -89,4 +89,3 @@ pigpiod_if.o: pigpiod_if.c pigpio.h command.h pigpiod_if.h
pigs.o: pigs.c pigpio.h command.h
x_pigpio.o: x_pigpio.c pigpio.h
x_pigpiod_if.o: x_pigpiod_if.c pigpiod_if.h pigpio.h

116
pigpio.c
View File

@ -190,77 +190,65 @@ bit 0 READ_LAST_NOT_SET_ERROR
#define BIT (1<<(gpio&0x1F))
#define CHECK_INITED \
do \
{ \
if (!libInitialised) \
{ \
fprintf(stderr, \
"%s %s: pigpio uninitialised, call gpioInitialise()\n",\
myTimeStamp(), __FUNCTION__); \
return PI_NOT_INITIALISED; \
} \
} \
while (0)
#ifndef EMBEDDED_IN_VM
#define DBG(level, format, arg...) DO_DBG(level, format, ## arg)
#else
#define DBG(level, format, arg...)
#endif
#define CHECK_INITED_RET_NULL_PTR \
do \
{ \
if (!libInitialised) \
{ \
fprintf(stderr, \
"%s %s: pigpio uninitialised, call gpioInitialise()\n",\
myTimeStamp(), __FUNCTION__); \
return (NULL); \
} \
} \
while (0)
#define CHECK_INITED_RET_NIL \
do \
{ \
if (!libInitialised) \
{ \
fprintf(stderr, \
"%s %s: pigpio uninitialised, call gpioInitialise()\n",\
myTimeStamp(), __FUNCTION__); \
} \
} \
while (0)
#define CHECK_NOT_INITED \
do \
{ \
if (libInitialised) \
{ \
fprintf(stderr, \
"%s %s: pigpio initialised, call gpioTerminate()\n", \
myTimeStamp(), __FUNCTION__); \
return PI_INITIALISED; \
} \
} \
while (0)
#define DBG(level, format, arg...) \
do \
#define DO_DBG(level, format, arg...) \
{ \
if (gpioCfg.dbgLevel >= level) \
fprintf(stderr, "%s %s: " format "\n" , \
myTimeStamp(), __FUNCTION__ , ## arg); \
}
#define CHECK_INITED \
{ \
if (!libInitialised) \
{ \
DBG(DBG_ALWAYS, \
"pigpio uninitialised, call gpioInitialise()"); \
return PI_NOT_INITIALISED; \
} \
} \
#define CHECK_INITED_RET_NULL_PTR \
{ \
if (!libInitialised) \
{ \
DBG(DBG_ALWAYS, \
"pigpio uninitialised, call gpioInitialise()"); \
return (NULL); \
} \
} \
#define CHECK_INITED_RET_NIL \
{ \
if (!libInitialised) \
{ \
DBG(DBG_ALWAYS, \
"pigpio uninitialised, call gpioInitialise()"); \
} \
} \
#define CHECK_NOT_INITED \
{ \
if (libInitialised) \
{ \
DBG(DBG_ALWAYS, \
"pigpio initialised, call gpioTerminate()"); \
return PI_INITIALISED; \
} \
} \
while (0)
#define SOFT_ERROR(x, format, arg...) \
do \
{ \
fprintf(stderr, "%s %s: " format "\n", \
myTimeStamp(), __FUNCTION__ , ## arg); \
DBG(DBG_ALWAYS, format, ## arg); \
return x; \
} \
while (0)
#define TIMER_ADD(a, b, result) \
do \
{ \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
@ -270,10 +258,8 @@ bit 0 READ_LAST_NOT_SET_ERROR
(result)->tv_nsec -= BILLION; \
} \
} \
while (0)
#define TIMER_SUB(a, b, result) \
do \
{ \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
@ -283,7 +269,6 @@ bit 0 READ_LAST_NOT_SET_ERROR
(result)->tv_nsec += BILLION; \
} \
} \
while (0)
#define PI_PERI_BUS 0x7E000000
@ -5809,13 +5794,13 @@ static int initCheckPermitted(void)
if ((fdMem = open("/dev/mem", O_RDWR | O_SYNC) ) < 0)
{
fprintf(stderr,
DBG(DBG_STARTUP,
"\n" \
"+---------------------------------------------------------+\n" \
"|Sorry, you don't have permission to run this program. |\n" \
"|Try running as root, e.g. precede the command with sudo. |\n" \
"+---------------------------------------------------------+\n\n");
exit(-1);
return -1;
}
return 0;
}
@ -6685,7 +6670,9 @@ int initInitialise(void)
gpioMaskSet = 1;
}
#ifndef EMBEDDED_IN_VM
sigSetHandler();
#endif
if (initPeripherals() < 0) return PI_INIT_FAILED;
@ -7003,6 +6990,7 @@ void gpioTerminate(void)
dmaIn[DMA_CS] = DMA_CHANNEL_RESET;
dmaOut[DMA_CS] = DMA_CHANNEL_RESET;
#ifndef EMBEDDED_IN_VM
if (gpioCfg.showStats)
{
fprintf(stderr,
@ -7033,6 +7021,7 @@ void gpioTerminate(void)
fprintf(stderr,
"#####################################################\n");
}
#endif
}
initReleaseResources();
@ -9674,4 +9663,3 @@ int gpioCfgInternals(unsigned cfgWhat, int cfgVal)
/* include any user customisations */
#include "custom.cext"