Kconfig, include/debug.h, and drivers/contactless: Add debug macros for contactless. The various contactless device drivers currently define device specific debug macros within their local header files. This patch adds generic ctls[info|warn|err] macros for the overall contactless subsystem to be used in future drivers. Ported the two currently available contactless device drivers (mfrc522.c and pn532.c) to these generic logging macros and fixed some logging bugs
along the way.
This commit is contained in:
parent
a383a86e72
commit
469859b9f1
35
Kconfig
35
Kconfig
@ -598,6 +598,41 @@ config DEBUG_BINFMT_INFO
|
||||
|
||||
endif # DEBUG_BINFMT
|
||||
|
||||
config DEBUG_CONTACTLESS
|
||||
bool "Contactless Debug Features"
|
||||
default n
|
||||
depends on DRIVERS_CONTACTLESS
|
||||
---help---
|
||||
Enable debug features for contactless (aka RFID) subsystem.
|
||||
|
||||
if DEBUG_CONTACTLESS
|
||||
|
||||
config DEBUG_CONTACTLESS_ERROR
|
||||
bool "Contactless Error Output"
|
||||
default n
|
||||
depends on DEBUG_ERROR
|
||||
---help---
|
||||
Enable contactless (aka RFID) subsystem error output to
|
||||
SYSLOG.
|
||||
|
||||
config DEBUG_CONTACTLESS_WARN
|
||||
bool "Contactless Warnings Output"
|
||||
default n
|
||||
depends on DEBUG_ERROR
|
||||
---help---
|
||||
Enable contactless (aka RFID) subsystem warning output to
|
||||
SYSLOG.
|
||||
|
||||
config DEBUG_CONTACTLESS_INFO
|
||||
bool "Contactless Informational Output"
|
||||
default n
|
||||
depends on DEBUG_ERROR
|
||||
---help---
|
||||
Enable contactless (aka RFID) subsystem informational output
|
||||
to SYSLOG.
|
||||
|
||||
endif # DEBUG_CONTACTLESS
|
||||
|
||||
config DEBUG_CRYPTO
|
||||
bool "Crypto Debug Features"
|
||||
default n
|
||||
|
@ -19,20 +19,15 @@ config MFRC522_SPI_FREQ
|
||||
default 1000000
|
||||
depends on CL_MFRC522
|
||||
|
||||
config CL_MFRC522_DEBUG
|
||||
bool "Enable MFRC522 debug"
|
||||
default n
|
||||
depends on CL_MFRC522
|
||||
|
||||
config CL_MFRC522_DEBUG_TX
|
||||
bool "trace TX frames"
|
||||
default n
|
||||
depends on MFRC522_DEBUG
|
||||
depends on DEBUG_CONTACTLESS
|
||||
|
||||
config CL_MFRC522_DEBUG_RX
|
||||
bool "trace RX frames"
|
||||
default n
|
||||
depends on MFRC522_DEBUG
|
||||
depends on DEBUG_CONTACTLESS
|
||||
|
||||
endif # CL_MFRC522
|
||||
|
||||
@ -50,20 +45,15 @@ config PN532_SPI_FREQ
|
||||
default 1000000
|
||||
depends on CL_PN532
|
||||
|
||||
config CL_PN532_DEBUG
|
||||
bool "Enable PN532 debug"
|
||||
default n
|
||||
depends on CL_PN532
|
||||
|
||||
config CL_PN532_DEBUG_TX
|
||||
bool "trace TX frames"
|
||||
default n
|
||||
depends on CL_PN532_DEBUG
|
||||
depends on DEBUG_CONTACTLESS
|
||||
|
||||
config CL_PN532_DEBUG_RX
|
||||
bool "trace RX frames"
|
||||
default n
|
||||
depends on CL_PN532_DEBUG
|
||||
depends on DEBUG_CONTACTLESS
|
||||
|
||||
endif # CL_PN532
|
||||
endif # DRIVERS_CONTACTLESS
|
||||
|
@ -60,19 +60,6 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_CL_MFRC522_DEBUG
|
||||
# define mfrc522err _err
|
||||
# define mfrc522info _info
|
||||
#else
|
||||
# ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define mfrc522err(x...)
|
||||
# define mfrc522info(x...)
|
||||
# else
|
||||
# define mfrc522err (void)
|
||||
# define mfrc522info (void)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CL_MFRC522_DEBUG_TX
|
||||
# define tracetx errdumpbuffer
|
||||
#else
|
||||
@ -209,7 +196,7 @@ uint8_t mfrc522_readu8(FAR struct mfrc522_dev_s *dev, uint8_t regaddr)
|
||||
mfrc522_deselect(dev);
|
||||
mfrc522_unlock(dev->spi);
|
||||
|
||||
tracerx("read", regval, 1);
|
||||
tracerx("read", ®val, 1);
|
||||
return regval;
|
||||
}
|
||||
|
||||
@ -301,7 +288,7 @@ void mfrc522_readblk(FAR struct mfrc522_dev_s *dev, uint8_t regaddr,
|
||||
mfrc522_deselect(dev);
|
||||
mfrc522_unlock(dev->spi);
|
||||
|
||||
tracerx("readblk", regval, size);
|
||||
tracerx("readblk", regval, length);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -335,7 +322,7 @@ void mfrc522_writeblk(FAR struct mfrc522_dev_s *dev, uint8_t regaddr,
|
||||
mfrc522_deselect(dev);
|
||||
mfrc522_unlock(dev->spi);
|
||||
|
||||
tracerx("writeblk", regval, size);
|
||||
tracerx("writeblk", regval, length);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -693,7 +680,7 @@ int mfrc522_picc_reqa_wupa(FAR struct mfrc522_dev_s *dev, uint8_t command,
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
mfrc522info("buffer[0]=0x%02X | buffer[1]=0x%02X\n", buffer[0], buffer[1]);
|
||||
ctlsinfo("buffer[0]=0x%02X | buffer[1]=0x%02X\n", buffer[0], buffer[1]);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1402,7 +1389,7 @@ int mfrc522_selftest(FAR struct mfrc522_dev_s *dev)
|
||||
|
||||
mfrc522_writeu8(dev, MFRC522_AUTOTEST_REG, 0x00);
|
||||
|
||||
mfrc522info("Self Test Result:\n");
|
||||
ctlsinfo("Self Test Result:\n");
|
||||
|
||||
for (i = 0; i < 64; i += 8)
|
||||
{
|
||||
@ -1411,10 +1398,10 @@ int mfrc522_selftest(FAR struct mfrc522_dev_s *dev)
|
||||
(void)sprintf(&outbuf[k], " %02x", result[i + j]);
|
||||
}
|
||||
|
||||
mfrc522info(" %02x:%s\n", i, outbuf);
|
||||
ctlsinfo(" %02x:%s\n", i, outbuf);
|
||||
}
|
||||
|
||||
mfrc522info("Done!\n");
|
||||
ctlsinfo("Done!\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1499,7 +1486,7 @@ static ssize_t mfrc522_read(FAR struct file *filep, FAR char *buffer,
|
||||
|
||||
if (!mfrc522_picc_detect(dev))
|
||||
{
|
||||
mfrc522err("Card is not present!\n");
|
||||
ctlserr("Card is not present!\n");
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
@ -1608,7 +1595,7 @@ static int mfrc522_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
|
||||
default:
|
||||
{
|
||||
mfrc522err("ERROR: Unrecognized cmd: %d\n", cmd);
|
||||
ctlserr("ERROR: Unrecognized cmd: %d\n", cmd);
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
}
|
||||
@ -1651,7 +1638,7 @@ int mfrc522_register(FAR const char *devpath, FAR struct spi_dev_s *spi)
|
||||
dev = (FAR struct mfrc522_dev_s *)kmm_malloc(sizeof(struct mfrc522_dev_s));
|
||||
if (!dev)
|
||||
{
|
||||
mfrc522err("ERROR: Failed to allocate instance\n");
|
||||
ctlserr("ERROR: Failed to allocate instance\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@ -1679,13 +1666,13 @@ int mfrc522_register(FAR const char *devpath, FAR struct spi_dev_s *spi)
|
||||
|
||||
fwver = mfrc522_getfwversion(dev);
|
||||
|
||||
mfrc522info("MFRC522 Firmware Version: 0x%02X!\n", fwver);
|
||||
ctlsinfo("MFRC522 Firmware Version: 0x%02X!\n", fwver);
|
||||
|
||||
/* If returned firmware version is unknown don't register the device */
|
||||
|
||||
if (fwver != 0x90 && fwver != 0x91 && fwver != 0x92 && fwver != 0x88)
|
||||
{
|
||||
mfrc522err("None supported device detected!\n");
|
||||
ctlserr("None supported device detected!\n");
|
||||
goto firmware_error;
|
||||
}
|
||||
|
||||
@ -1694,7 +1681,7 @@ int mfrc522_register(FAR const char *devpath, FAR struct spi_dev_s *spi)
|
||||
ret = register_driver(devpath, &g_mfrc522fops, 0666, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
mfrc522err("ERROR: Failed to register driver: %d\n", ret);
|
||||
ctlserr("ERROR: Failed to register driver: %d\n", ret);
|
||||
kmm_free(dev);
|
||||
}
|
||||
|
||||
|
@ -70,19 +70,6 @@
|
||||
# warning This platform does not support SPI LSB-bit order
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CL_PN532_DEBUG
|
||||
# define pn532err _err
|
||||
# define pn532info _info
|
||||
#else
|
||||
# ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define pn532err(x...)
|
||||
# define pn532info(x...)
|
||||
# else
|
||||
# define pn532err (void)
|
||||
# define pn532info (void)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CL_PN532_DEBUG_TX
|
||||
# define tracetx errdumpbuffer
|
||||
#else
|
||||
@ -118,7 +105,7 @@ static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
static uint8_t pn532_checksum(uint8_t value);
|
||||
static uint8_t pn532_data_checksum(FAR uint8_t *data, int datalen);
|
||||
|
||||
int pn532_read(FAR struct pn532_dev_s *dev, uFAR int8_t *buff, uint8_t n);
|
||||
int pn532_read(FAR struct pn532_dev_s *dev, FAR uint8_t *buff, uint8_t n);
|
||||
|
||||
#if 0 /* TODO */
|
||||
/* IRQ Handling */
|
||||
@ -166,7 +153,7 @@ static void pn532_lock(FAR struct spi_dev_s *spi)
|
||||
ret = SPI_HWFEATURES(spi, HWFEAT_LSBFIRST);
|
||||
if (ret < 0)
|
||||
{
|
||||
pn532err("ERROR: SPI_HWFEATURES failed to set bit order: %d\n", ret);
|
||||
ctlserr("ERROR: SPI_HWFEATURES failed to set bit order: %d\n", ret);
|
||||
}
|
||||
|
||||
(void)SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ);
|
||||
@ -189,7 +176,7 @@ static inline void pn532_configspi(FAR struct spi_dev_s *spi)
|
||||
ret = SPI_HWFEATURES(spi, HWFEAT_LSBFIRST);
|
||||
if (ret < 0)
|
||||
{
|
||||
pn532err("ERROR: SPI_HWFEATURES failed to set bit order: %d\n", ret);
|
||||
ctlserr("ERROR: SPI_HWFEATURES failed to set bit order: %d\n", ret);
|
||||
}
|
||||
|
||||
(void)SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ);
|
||||
@ -259,7 +246,7 @@ bool pn532_rx_frame_is_valid(FAR struct pn532_frame *f, bool check_data)
|
||||
|
||||
if (f->start_code != PN532_SOF)
|
||||
{
|
||||
pn532err("ERROR: Frame startcode 0x%X != 0x%X\n",
|
||||
ctlserr("ERROR: Frame startcode 0x%X != 0x%X\n",
|
||||
PN532_SOF, f->start_code);
|
||||
return false;
|
||||
}
|
||||
@ -272,7 +259,7 @@ bool pn532_rx_frame_is_valid(FAR struct pn532_frame *f, bool check_data)
|
||||
chk = pn532_checksum(f->len);
|
||||
if (chk != f->lcs)
|
||||
{
|
||||
pn532err("ERROR: Frame data len checksum failed");
|
||||
ctlserr("ERROR: Frame data len checksum failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -281,7 +268,7 @@ bool pn532_rx_frame_is_valid(FAR struct pn532_frame *f, bool check_data)
|
||||
chk = pn532_data_checksum(&f->tfi, f->len);
|
||||
if (chk != f->data[f->len-1])
|
||||
{
|
||||
pn532err("ERROR: Frame data checksum failed: calc=0x%X != 0x%X",
|
||||
ctlserr("ERROR: Frame data checksum failed: calc=0x%X != 0x%X",
|
||||
chk, f->data[f->len-1]);
|
||||
return false;
|
||||
}
|
||||
@ -338,7 +325,7 @@ static int pn532_wait_rx_ready(FAR struct pn532_dev_s *dev, int timeout)
|
||||
{
|
||||
if (--timeout == 0x00)
|
||||
{
|
||||
pn532err("ERROR: wait RX timeout!\n");
|
||||
ctlserr("ERROR: wait RX timeout!\n");
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
@ -449,7 +436,7 @@ int pn532_read_ack(FAR struct pn532_dev_s *dev)
|
||||
}
|
||||
else
|
||||
{
|
||||
pn532info("ACK NOK");
|
||||
ctlsinfo("ACK NOK");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
@ -495,7 +482,7 @@ int pn532_write_frame(FAR struct pn532_dev_s *dev, FAR struct pn532_frame *f)
|
||||
{
|
||||
if (!pn532_read_ack(dev))
|
||||
{
|
||||
pn532err("ERROR: command FAILED\n");
|
||||
ctlserr("ERROR: command FAILED\n");
|
||||
res = -EIO;
|
||||
}
|
||||
}
|
||||
@ -617,7 +604,7 @@ int pn532_get_fw_version(FAR struct pn532_dev_s *dev,
|
||||
if (f->data[0] == PN532_COMMAND_GETFIRMWAREVERSION + 1)
|
||||
{
|
||||
fw = (FAR struct pn_firmware_version *) &f->data[1];
|
||||
pn532info("FW: %d.%d on IC:0x%X (Features: 0x%X)\n",
|
||||
ctlsinfo("FW: %d.%d on IC:0x%X (Features: 0x%X)\n",
|
||||
fw->ver, fw->rev, fw->ic, fw->support);
|
||||
if (fv)
|
||||
{
|
||||
@ -648,7 +635,7 @@ int pn532_write_gpio(FAR struct pn532_dev_s *dev, uint8_t p3, uint8_t p7)
|
||||
{
|
||||
pn532_read(dev, cmd_buffer, 10);
|
||||
tracetx("Resp:", cmd_buffer, 10);
|
||||
pn532info("TFI=%x, data0=%X", f->tfi, f->data[0]);
|
||||
ctlsinfo("TFI=%x, data0=%X", f->tfi, f->data[0]);
|
||||
if ((f->tfi == PN532_PN532TOHOST) &&
|
||||
(f->data[0] == PN532_COMMAND_WRITEGPIO + 1))
|
||||
{
|
||||
@ -685,7 +672,7 @@ uint32_t pn532_write_passive_data(FAR struct pn532_dev_s *dev,
|
||||
{
|
||||
dev->state = PN532_STATE_IDLE;
|
||||
f = (FAR struct pn532_frame *) resp;
|
||||
tracerx("passive target id resp:", f, f->len+6);
|
||||
tracerx("passive target id resp:", (FAR uint8_t *)f, f->len+6);
|
||||
|
||||
if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE+1)
|
||||
{
|
||||
@ -721,7 +708,7 @@ uint32_t pn532_read_passive_data(FAR struct pn532_dev_s *dev, uint8_t address,
|
||||
{
|
||||
dev->state = PN532_STATE_IDLE;
|
||||
f = (FAR struct pn532_frame *) resp;
|
||||
tracerx("passive target id resp:", f, f->len+6);
|
||||
tracerx("passive target id resp:", (FAR uint8_t *)f, f->len+6);
|
||||
|
||||
if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE+1)
|
||||
{
|
||||
@ -759,7 +746,7 @@ uint32_t pn532_read_passive_target_id(FAR struct pn532_dev_s *dev,
|
||||
f = (FAR struct pn532_frame *) resp;
|
||||
r = (FAR struct pn_poll_response *) &f->data[1];
|
||||
|
||||
tracerx("passive target id resp:", f, f->len+6);
|
||||
tracerx("passive target id resp:", (FAR uint8_t *)f, f->len+6);
|
||||
|
||||
if (f->data[0] == PN532_COMMAND_INLISTPASSIVETARGET+1)
|
||||
{
|
||||
@ -770,14 +757,14 @@ uint32_t pn532_read_passive_target_id(FAR struct pn532_dev_s *dev,
|
||||
FAR struct pn_target_type_a *t =
|
||||
(FAR struct pn_target_type_a *)&r->target_data;
|
||||
|
||||
pn532info("Found %d card(s)\n", r->nbtg);
|
||||
ctlsinfo("Found %d card(s)\n", r->nbtg);
|
||||
|
||||
/* now supports only type_a cards
|
||||
* if (poll_mode == PN532_POLL_MOD_106KBPS_A)
|
||||
*/
|
||||
|
||||
pn532info("sens:0x%x sel:0x%x", t->sens_res, t->sel_res);
|
||||
pn532info("idlen:0x%x ", t->nfcid_len);
|
||||
ctlsinfo("sens:0x%x sel:0x%x", t->sens_res, t->sel_res);
|
||||
ctlsinfo("idlen:0x%x ", t->nfcid_len);
|
||||
|
||||
/* generate 32bit cid from id (could be longer)
|
||||
* HACK: Using only top 4 bytes.
|
||||
@ -864,7 +851,7 @@ static int irq_handler(int irq, FAR void *context)
|
||||
(void)irq;
|
||||
(void)context;
|
||||
|
||||
pn532info("*IRQ*\n");
|
||||
ctlsinfo("*IRQ*\n");
|
||||
work_queue(HPWORK, &g_dev->irq_work, pn532_worker, dev, 0);
|
||||
|
||||
return OK;
|
||||
@ -1117,7 +1104,7 @@ static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
break;
|
||||
|
||||
default:
|
||||
pn532err("ERROR: Unrecognized cmd: %d\n", cmd);
|
||||
ctlserr("ERROR: Unrecognized cmd: %d\n", cmd);
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
@ -1158,7 +1145,7 @@ int pn532_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||
dev = (FAR struct pn532_dev_s *)kmm_malloc(sizeof(struct pn532_dev_s));
|
||||
if (!dev)
|
||||
{
|
||||
pn532err("ERROR: Failed to allocate instance\n");
|
||||
ctlserr("ERROR: Failed to allocate instance\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@ -1176,7 +1163,7 @@ int pn532_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||
ret = register_driver(devpath, &g_pn532fops, 0666, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
pn532err("ERROR: Failed to register driver: %d\n", ret);
|
||||
ctlserr("ERROR: Failed to register driver: %d\n", ret);
|
||||
kmm_free(dev);
|
||||
}
|
||||
|
||||
|
@ -287,6 +287,24 @@
|
||||
# define finfo(x...)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS_ERROR
|
||||
# define ctlserr(format, ...) _err(format, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ctlserr(x...)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS_WARN
|
||||
# define ctlswarn(format, ...) _warn(format, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ctlswarn(x...)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS_INFO
|
||||
# define ctlsinfo(format, ...) _info(format, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ctlsinfo(x...)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CRYPTO_ERROR
|
||||
# define crypterr(format, ...) _err(format, ##__VA_ARGS__)
|
||||
#else
|
||||
@ -867,6 +885,24 @@
|
||||
# define finfo (void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS_ERROR
|
||||
# define ctlserr _err
|
||||
#else
|
||||
# define ctlserr (void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS_WARN
|
||||
# define ctlswarn _warn
|
||||
#else
|
||||
# define ctlswarn (void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS_INFO
|
||||
# define ctlsinfo _info
|
||||
#else
|
||||
# define ctlsinfo (void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CRYPTO_ERROR
|
||||
# define crypterr _err
|
||||
#else
|
||||
@ -1363,6 +1399,14 @@
|
||||
# define finfodumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CONTACTLESS
|
||||
# define ctlserrdumpbuffer(m,b,n) errdumpbuffer(m,b,n)
|
||||
# define ctlinfodumpbuffer(m,b,n) infodumpbuffer(m,b,n)
|
||||
#else
|
||||
# define ctlserrferrdumpbuffer(m,b,n)
|
||||
# define ctlinfodumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_INPUT
|
||||
# define ierrdumpbuffer(m,b,n) errdumpbuffer(m,b,n)
|
||||
# define iinfodumpbuffer(m,b,n) infodumpbuffer(m,b,n)
|
||||
|
Loading…
Reference in New Issue
Block a user