From 22e25a8b1e678ebd8723d157cc2d1b335a2df724 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 25 May 2011 10:25:17 +0000 Subject: [PATCH] chips/pn53x: drivers now uses pn53x_data_new() and pn53x_data_free() to handle strcut pn53x_data allocation, initialization and freeing. --- Makefile.am | 1 - libnfc/chips/pn53x.c | 9 +++++++++ libnfc/chips/pn53x.h | 1 + libnfc/drivers/acr122.c | 1 + libnfc/drivers/arygon.c | 9 ++++++--- libnfc/drivers/pn532_uart.c | 7 ++++--- libnfc/drivers/pn53x_usb.c | 1 + libnfc/nfc-device.c | 1 - 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index c606fc7..43aacf2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,6 @@ pkgconfig_DATA = libnfc.pc EXTRA_DIST = \ CMakeLists.txt \ Doxyfile \ - LICENSE \ README-Windows.txt \ pn53x.conf \ pn53x.rules diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 7937b27..a559101 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -2467,3 +2467,12 @@ pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io) CHIP_DATA (pnd)->wb_trigged = false; memset (CHIP_DATA (pnd)->wb_mask, 0x00, PN53X_CACHE_REGISTER_SIZE); } + +void +pn53x_data_free (nfc_device_t * pnd) +{ + if (CHIP_DATA (pnd)->current_target) { + free (CHIP_DATA (pnd)->current_target); + } + free (pnd->chip_data); +} diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 8e3468e..3fdda3f 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -337,5 +337,6 @@ bool pn53x_check_error_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, bool pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, const size_t szData); void pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io); +void pn53x_data_free (nfc_device_t * pnd); #endif // __NFC_CHIPS_PN53X_H__ diff --git a/libnfc/drivers/acr122.c b/libnfc/drivers/acr122.c index 4065d01..4ea502f 100644 --- a/libnfc/drivers/acr122.c +++ b/libnfc/drivers/acr122.c @@ -245,6 +245,7 @@ acr122_disconnect (nfc_device_t * pnd) SCardDisconnect (DRIVER_DATA (pnd)->hCard, SCARD_LEAVE_CARD); acr122_free_scardcontext (); + pn53x_data_free (pnd); nfc_device_free (pnd); } diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 9b6fb58..f724346 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -175,11 +175,13 @@ arygon_connect (const nfc_device_desc_t * pndd) pnd->driver_data = malloc(sizeof(struct arygon_data)); DRIVER_DATA (pnd)->port = sp; - pnd->chip_data = malloc(sizeof(struct pn53x_data)); + + // Alloc and init chip's data + pn53x_data_new (pnd, &arygon_tama_io); - // The PN53x chip connected to ARYGON MCU doesn't seems to be in SLEEP mode + // The PN53x chip connected to ARYGON MCU doesn't seems to be in LowVBat mode CHIP_DATA (pnd)->power_mode = NORMAL; - CHIP_DATA (pnd)->io = &arygon_tama_io; + // empirical tuning CHIP_DATA (pnd)->timer_correction = 46; pnd->driver = &arygon_driver; @@ -220,6 +222,7 @@ arygon_disconnect (nfc_device_t * pnd) close (DRIVER_DATA (pnd)->iAbortFds[1]); #endif + pn53x_data_free(pnd); nfc_device_free (pnd); } diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 5c011b6..30eda51 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -163,10 +163,11 @@ pn532_uart_connect (const nfc_device_desc_t * pndd) pnd->driver_data = malloc(sizeof(struct pn532_uart_data)); DRIVER_DATA(pnd)->port = sp; - pnd->chip_data = malloc(sizeof(struct pn53x_data)); - CHIP_DATA(pnd)->type = PN532; + // Alloc and init chip's data + pn53x_data_new (pnd, &pn532_uart_io); + // This device starts in LowVBat mode CHIP_DATA(pnd)->power_mode = LOWVBAT; - CHIP_DATA(pnd)->io = &pn532_uart_io; + // empirical tuning CHIP_DATA(pnd)->timer_correction = 48; pnd->driver = &pn532_uart_driver; diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 90e89ab..1f3a4e6 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -365,6 +365,7 @@ pn53x_usb_disconnect (nfc_device_t * pnd) if ((res = usb_close (DRIVER_DATA (pnd)->pudh)) < 0) { ERR ("usb_close failed (%i)", res); } + pn53x_data_free (pnd); nfc_device_free (pnd); } diff --git a/libnfc/nfc-device.c b/libnfc/nfc-device.c index f3d04ea..7cd5cb6 100644 --- a/libnfc/nfc-device.c +++ b/libnfc/nfc-device.c @@ -61,7 +61,6 @@ nfc_device_free (nfc_device_t *nfc_device) { if (nfc_device) { free (nfc_device->driver_data); - free (nfc_device->chip_data); free (nfc_device); } }