API  2.3.0
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
nfc_read.c

This is an example about how manage the NFC read.

/* @file main.c
* @author TST
* @version 0.1
* @date 20/06/2012
* @brief This is an example about how to read a NFC card.
*
* This example uses a NFC devices to read a NFC card, when the card is read, this
* application turns on a LED for 1second. After that the application will wait for
* a new card to read.
*
* @note To run well this application user must use a Mifare Classic NFC card.
*
*/
/* Platform headers */
#include "tsmart.h"
/* @brief vNFC_read task
*
* This task waits for a new card, reads it and turns on a LED.
*
* @param pvParameters
*/
void vNCF_read(void *pvParameters) {
/* Variables */
/* Tag key */
uint8_t key[] = {0xff,0xff,0xff,0xff,0xff,0xff};
/* Reception buffer */
uint8_t receive_data[100];
/* Founded NFC card */
int8_t founded_nfc_card;
/* Wake up the NFC device */
TSMART_NFC_WakeUp(&tsmart_nfc, 100/portTICK_RATE_MS);
/* Configure device */
if( TSMART_NFC_SamConfiguration(&tsmart_nfc, TSMART_NFC_API_NORMAL_MODE, 0, TSMART_NFC_DISABLE, 100/portTICK_RATE_MS) != TSMART_NFC_PASS){
for(;;);
}
while(1){
do{
/* Check NFC card */
founded_nfc_card = TSMART_NFC_GetId(&tsmart_nfc, &id, 100/portTICK_RATE_MS);
vTaskDelay(500/portTICK_RATE_MS);
}while(founded_nfc_card != 1);
/* Select NFC card */
if( TSMART_NFC_InSelect(&tsmart_nfc, id.tg, 100/portTICK_RATE_MS) != TSMART_NFC_PASS){
for(;;);
}
/* Classic NFC cards need authentication */
if( TSMART_NFC_AuthenticateA(&tsmart_nfc, id, 16, key, 100/portTICK_RATE_MS) != TSMART_NFC_PASS){
for(;;);
}
/* Read a NFC card */
if( TSMART_NFC_ReadCard(&tsmart_nfc, receive_data, 16, 100/portTICK_RATE_MS) != TSMART_NFC_PASS){
for(;;);
}
/* Turn on LED */
/* Wait for 2 seconds */
vTaskDelay(2000/portTICK_RATE_MS);
/* Turn off LED */
}
}
/* @brief "Init()" function.
*
* This is the first thing that the user must do for using TSmarT.
* It initializes specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
portBASE_TYPE xReturn;
tsmart_dio_config_t dio_config;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* The specific hardware for this application: NFC and a DIO
*/
/* LED - DIO1 */
dio_config.mode = TSMART_DIO_OD;
TSMART_DIO_Init(&tsmart_dio7, &dio_config);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/*
* - NCF_read task: This task configures the NFC devices and read NFC cards
*
*/
xReturn = xTaskCreate(vNCF_read, "NCF_read", 256, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}