phDal4Nfc.c revision 5ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28
15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* 25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors 35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License"); 55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License. 65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at 75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * http://www.apache.org/licenses/LICENSE-2.0 95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software 115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS, 125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and 145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License. 155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \file phDalNfc.c 195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL Implementation for linux 205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: Trusted NFC Linux Lignt 225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Date: 07 aug 2009 245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Author: Jonathan roux 255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Revision: 1.0 $ 265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define _DAL_4_NFC_C 305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <unistd.h> 325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <pthread.h> 33e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas#include <stdlib.h> 345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ANDROID 355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <linux/ipc.h> 364812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly#include <cutils/log.h> 374812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly#include <cutils/properties.h> // for property_get 385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else 395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <sys/msg.h> 405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 41e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton#include <semaphore.h> 425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc.h> 435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h> 445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcStatus.h> 455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_DeferredCall.h> 465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_debug.h> 475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_uart.h> 485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_i2c.h> 495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_link.h> 505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_messageQueueLib.h> 515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------------- 535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly MISC DEFINITIONS 545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly------------------------------------------------------------------------------------*/ 555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define DEFAULT_LINK_TYPE ENUM_DAL_LINK_TYPE_COM1 565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------------- 585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly TYPES 595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly------------------------------------------------------------------------------------*/ 605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*structure holds members related for both read and write operations*/ 615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellytypedef struct Dal_RdWr_st 625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Read members */ 645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_t nReadThread; /* Read thread Hanlde */ 655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t * pReadBuffer; /* Read local buffer */ 665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int nNbOfBytesToRead; /* Number of bytes to read */ 675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int nNbOfBytesRead; /* Number of read bytes */ 685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nReadBusy; /* Read state machine */ 695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nReadThreadAlive; /* Read state machine */ 705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nWaitingOnRead; /* Read state machine */ 715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Read wait members */ 735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t * pReadWaitBuffer; /* Read wait local Buffer */ 745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int nNbOfBytesToReadWait; /* Number of bytes to read */ 755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int nNbOfBytesReadWait; /* Number of read bytes */ 765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nReadWaitBusy; /* Read state machine */ 775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nWaitingOnReadWait; /* Read state machine */ 785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nCancelReadWait; /* Read state machine */ 795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Write members */ 815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_t nWriteThread; /* Write thread Hanlde */ 825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t * pWriteBuffer; /* Write local buffer */ 833e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton uint8_t * pTempWriteBuffer; /* Temp Write local buffer */ 845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int nNbOfBytesToWrite; /* Number of bytes to write */ 855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int nNbOfBytesWritten; /* Number of bytes written */ 865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nWaitingOnWrite; /* Write state machine */ 875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nWriteThreadAlive; /* Write state machine */ 885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char nWriteBusy; /* Write state machine */ 895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} phDal4Nfc_RdWr_t; 905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellytypedef void (*pphDal4Nfc_DeferFuncPointer_t) (void * ); 925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellytypedef void * (*pphDal4Nfc_thread_handler_t) (void * pParam); 935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------------- 965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly VARIABLES 975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly------------------------------------------------------------------------------------*/ 985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic phDal4Nfc_RdWr_t gReadWriteContext; 995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic phDal4Nfc_SContext_t gDalContext; 1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic pphDal4Nfc_SContext_t pgDalContext; 1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic phHal_sHwReference_t * pgDalHwContext; 102e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamiltonstatic sem_t nfc_read_sem; 1034812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pellystatic int low_level_traces; 1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef USE_MQ_MESSAGE_QUEUE 1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic phDal4Nfc_DeferredCall_Msg_t nDeferedMessage; 1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic mqd_t nDeferedCallMessageQueueId; 1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else 1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyint nDeferedCallMessageQueueId = 0; 1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic phDal4Nfc_link_cbk_interface_t gLinkFunc; 1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------------- 1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PROTOTYPES 1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly------------------------------------------------------------------------------------*/ 1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phDal4Nfc_DeferredCb (void *params); 1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phDal4Nfc_StartThreads (void); 1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phDal4Nfc_FillMsg (phDal4Nfc_Message_t *pDalMsg, phOsalNfc_Message_t *pOsalMsg); 1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------------- 1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL API IMPLEMENTATION 1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly------------------------------------------------------------------------------------*/ 1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1234812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pellystatic void refresh_low_level_traces() { 12423482d091c046310ef4c57f625c67e0d0e776500Nick Pelly#ifdef LOW_LEVEL_TRACES 12523482d091c046310ef4c57f625c67e0d0e776500Nick Pelly low_level_traces = 1; 12623482d091c046310ef4c57f625c67e0d0e776500Nick Pelly return; 12723482d091c046310ef4c57f625c67e0d0e776500Nick Pelly#else 12823482d091c046310ef4c57f625c67e0d0e776500Nick Pelly 1294812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly#ifdef ANDROID 13023482d091c046310ef4c57f625c67e0d0e776500Nick Pelly char value[PROPERTY_VALUE_MAX]; 13123482d091c046310ef4c57f625c67e0d0e776500Nick Pelly 13223482d091c046310ef4c57f625c67e0d0e776500Nick Pelly property_get("ro.debuggable", value, ""); 13323482d091c046310ef4c57f625c67e0d0e776500Nick Pelly if (!value[0] || !atoi(value)) { 13423482d091c046310ef4c57f625c67e0d0e776500Nick Pelly low_level_traces = 0; // user build, do not allow debug 13523482d091c046310ef4c57f625c67e0d0e776500Nick Pelly return; 13623482d091c046310ef4c57f625c67e0d0e776500Nick Pelly } 13723482d091c046310ef4c57f625c67e0d0e776500Nick Pelly 1385ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly property_get("debug.nfc.LOW_LEVEL_TRACES", value, "0"); 1394812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly if (value[0]) { 1405ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly low_level_traces = atoi(value); 14123482d091c046310ef4c57f625c67e0d0e776500Nick Pelly return; 1424812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly } 1434812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly#endif 14423482d091c046310ef4c57f625c67e0d0e776500Nick Pelly low_level_traces = 0; 1454812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly#endif 1464812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly} 1474812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly 1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Register 1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL register function. 1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Register( phNfcIF_sReference_t *psRefer, 1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfcIF_sCallBack_t if_cb, void *psIFConf ) 1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL != psRefer) && 1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (NULL != psRefer->plower_if) && 1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (NULL != if_cb.receive_complete) && 1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (NULL != if_cb.send_complete) 1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Register the LLC functions to the upper layer */ 1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->init = phDal4Nfc_Init; 1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->release = phDal4Nfc_Shutdown; 1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->send = phDal4Nfc_Write; 1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->receive = phDal4Nfc_Read; 1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->receive_wait = phDal4Nfc_ReadWait; 1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->transact_abort = phDal4Nfc_ReadWaitCancel; 1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->unregister = phDal4Nfc_Unregister; 1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (NULL != pgDalContext) 1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Copy the DAL context to the upper layer */ 1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRefer->plower_if->pcontext = pgDalContext; 1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Register the callback function from the upper layer */ 1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.receive_complete = if_cb.receive_complete; 1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.send_complete = if_cb.send_complete; 1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.notify = if_cb.notify; 1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the upper layer context */ 1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.pif_ctxt = if_cb.pif_ctxt; 1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the error state */ 1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_SUCCESS; 1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 1905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_NOT_INITIALISED); 1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else /*Input parameters invalid*/ 1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_PARAMETER); 1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Unregister 2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL unregister function. 2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Unregister(void *pContext, void *pHwRef ) 2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL == pContext) && (NULL == pHwRef)) 2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_PARAMETER); 2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (NULL != pgDalContext) 2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Register the callback function from the upper layer */ 2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.receive_complete = NULL; 2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.send_complete = NULL ; 2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.notify = NULL ; 2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the upper layer context */ 2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.pif_ctxt = NULL ; 2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_NOT_INITIALISED); 2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Init 2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL Init function. 2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Init(void *pContext, void *pHwRef ) 2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2474812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly refresh_low_level_traces(); 2484812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly 2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL != pContext) && (NULL != pHwRef)) 2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pContext = pgDalContext; 2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalHwContext = (phHal_sHwReference_t *)pHwRef; 2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ( gDalContext.hw_valid == TRUE ) 2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* The link has been opened from the application interface */ 2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.open_from_handle(pgDalHwContext); 2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (!gLinkFunc.is_opened()) 2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE); 2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Clear link buffers */ 2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.flush(); 2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static phDal4Nfc_sConfig_t hw_config; 2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly hw_config.nLinkType = DEFAULT_LINK_TYPE; 2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = phDal4Nfc_Config(&hw_config, pHwRef ); 2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else /*Input parametrs invalid*/ 2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_INVALID_PARAMETER; 2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Shutdown 2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL Shutdown function. 2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Shutdown( void *pContext, void *pHwRef) 2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void * pThreadReturn; 2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly// if (pContext == NULL) 2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly// return NFCSTATUS_INVALID_PARAMETER; 2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (gDalContext.hw_valid == TRUE) 3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Flush the link */ 3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.flush(); 3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Close the message queue */ 3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef USE_MQ_MESSAGE_QUEUE 3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly mq_close(nDeferedCallMessageQueueId); 3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 315df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMASNFCSTATUS phDal4Nfc_ConfigRelease(void *pHwRef) 3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void * pThreadReturn; 320e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 321e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT("phDal4Nfc_ConfigRelease "); 3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (gDalContext.hw_valid == TRUE) 3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 325df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS /* Signal the read and write threads to exit. NOTE: there 326df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS actually is no write thread! :) */ 327df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_PRINT("Stop Reader Thread"); 328df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS gReadWriteContext.nReadThreadAlive = 0; 329df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS gReadWriteContext.nWriteThreadAlive = 0; 330df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS 331df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS /* Wake up the read thread so it can exit */ 332df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_PRINT("Release Read Semaphore"); 333df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS sem_post(&nfc_read_sem); 334df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS 335df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_DEBUG("phDal4Nfc_ConfigRelease - doing pthread_join(%d)", 336df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS gReadWriteContext.nReadThread); 337df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS if (pthread_join(gReadWriteContext.nReadThread, &pThreadReturn) != 0) 338df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS { 339df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED); 340df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_PRINT("phDal4Nfc_ConfigRelease KO"); 341df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS } 3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Close the message queue */ 3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef USE_MQ_MESSAGE_QUEUE 3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly mq_close(nDeferedCallMessageQueueId); 3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3485e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas /* Shutdown NFC Chip */ 3495e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas phDal4Nfc_Reset(0); 3505e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Close the link */ 3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.close(); 3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 354e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Reset the Read Writer context to NULL */ 3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext)); 3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the DAL context values to NULL */ 3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memset((void *)&gDalContext,0,sizeof(gDalContext)); 3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gDalContext.hw_valid = FALSE; 3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_DEBUG("phDal4Nfc_ConfigRelease(): %04x\n", result); 3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3645e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Write 3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL Write function. 3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 375e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Write( void *pContext, void *pHwRef,uint8_t *pBuffer, uint16_t length) 3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 379e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton static int MsgType= PHDAL4NFC_WRITE_MESSAGE; 380e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton int * pmsgType=&MsgType; 381e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton phDal4Nfc_Message_t sMsg; 382e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton phOsalNfc_Message_t OsalMsg; 383e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL != pContext) && (NULL != pHwRef)&& 3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (NULL != pBuffer) && (0 != length)) 3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( gDalContext.hw_valid== TRUE) 3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((!gReadWriteContext.nWriteBusy)&& 3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (!gReadWriteContext.nWaitingOnWrite)) 391e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 392e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT("phDal4Nfc_Write() : Temporary buffer !! \n"); 3933e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton gReadWriteContext.pTempWriteBuffer = (uint8_t*)malloc(length * sizeof(uint8_t)); 394e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Make a copy of the passed arguments */ 3953e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton memcpy(gReadWriteContext.pTempWriteBuffer,pBuffer,length); 3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_DEBUG("phDal4Nfc_Write(): %d\n", length); 3973e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton gReadWriteContext.pWriteBuffer = gReadWriteContext.pTempWriteBuffer; 3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nNbOfBytesToWrite = length; 3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Change the write state so that thread can take over the write */ 4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nWriteBusy = TRUE; 4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Just set variable here. This is the trigger for the Write thread */ 4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nWaitingOnWrite = TRUE; 4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the error state */ 4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_PENDING; 405e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Send Message and perform physical write in the DefferedCallback */ 406e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* read completed immediately */ 407e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton sMsg.eMsgType= PHDAL4NFC_WRITE_MESSAGE; 408e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Update the state */ 409e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton phDal4Nfc_FillMsg(&sMsg,&OsalMsg); 410e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton phDal4Nfc_DeferredCall((pphDal4Nfc_DeferFuncPointer_t)phDal4Nfc_DeferredCb,(void *)pmsgType); 411e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton memset(&sMsg,0,sizeof(phDal4Nfc_Message_t)); 412e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton memset(&OsalMsg,0,sizeof(phOsalNfc_Message_t)); 4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Driver is BUSY with previous Write */ 4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_PRINT("phDal4Nfc_Write() : Busy \n"); 4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_BUSY) ; 4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* TBD :Additional error code : NOT_INITIALISED */ 4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE); 4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*end if-Input parametrs valid-check*/ 4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_INVALID_PARAMETER; 4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Read 4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL Read function. 4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Read( void *pContext, void *pHwRef,uint8_t *pBuffer, uint16_t length) 4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL != pContext) && (NULL != pHwRef)&& 4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (NULL != pBuffer) && (0 != length)) 4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ( gDalContext.hw_valid== TRUE) 4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((!gReadWriteContext.nReadBusy)&& 4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (!gReadWriteContext.nWaitingOnRead)) 4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_DEBUG("*****DAl Read called length : %d\n", length); 456e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Make a copy of the passed arguments */ 4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.pReadBuffer = pBuffer; 4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nNbOfBytesToRead = length; 4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Change the Read state so that thread can take over the read */ 4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nReadBusy = TRUE; 4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Just set variable here. This is the trigger for the Reader thread */ 4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nWaitingOnRead = TRUE; 464e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Update the return state */ 4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_PENDING; 466e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* unlock reader thread */ 467e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton sem_post(&nfc_read_sem); 4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Driver is BUSY with prev Read */ 4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_PRINT("DAL BUSY\n"); 4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Make a copy of the passed arguments */ 4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.pReadBuffer = pBuffer; 4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nNbOfBytesToRead = length; 4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_PENDING; 4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* TBD :Additional error code : NOT_INITIALISED */ 4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE); 4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*end if-Input parametrs valid-check*/ 4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly result = NFCSTATUS_INVALID_PARAMETER; 4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_DEBUG("*****DAl Read called result : %x\n", result); 4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return result; 4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_ReadWait 4975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: DAL Read wait function. 4995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_ReadWait(void *pContext, void *pHwRef,uint8_t *pBuffer, uint16_t length) 5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 504e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* not used */ 505e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT("phDal4Nfc_ReadWait"); 506e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton return 0; 5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_ReadWaitCancel 5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: Cancel the Read wait function. 5135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_ReadWaitCancel( void *pContext, void *pHwRef) 5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 51873fcd52e49db49449613035a3bce8b04d9890f72daniel_Tomas DAL_PRINT("phDal4Nfc_ReadWaitCancel"); 51973fcd52e49db49449613035a3bce8b04d9890f72daniel_Tomas 52073fcd52e49db49449613035a3bce8b04d9890f72daniel_Tomas /* unlock read semaphore */ 52173fcd52e49db49449613035a3bce8b04d9890f72daniel_Tomas sem_post(&nfc_read_sem); 52273fcd52e49db49449613035a3bce8b04d9890f72daniel_Tomas 5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return 0; 5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------- 5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyFUNCTION: phDal4Nfc_Config 5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyPURPOSE: Configure the serial port. 5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly-----------------------------------------------------------------------------*/ 5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref) 5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS retstatus = NFCSTATUS_SUCCESS; 5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_PRINT("phDal4Nfc_Config"); 5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((config == NULL) || (phwref == NULL) || (config->nClientId == -1)) 5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return NFCSTATUS_INVALID_PARAMETER; 5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Register the link callbacks */ 5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memset(&gLinkFunc, 0, sizeof(phDal4Nfc_link_cbk_interface_t)); 5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(config->nLinkType) 5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_COM1: 5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_COM2: 5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_COM3: 5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_COM4: 5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_COM5: 5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_USB: 5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5533e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton DAL_PRINT("UART link Config"); 5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Uart link interface */ 5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.init = phDal4Nfc_uart_initialize; 5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.open_from_handle = phDal4Nfc_uart_set_open_from_handle; 5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.is_opened = phDal4Nfc_uart_is_opened; 5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.flush = phDal4Nfc_uart_flush; 5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.close = phDal4Nfc_uart_close; 5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.open_and_configure = phDal4Nfc_uart_open_and_configure; 5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.read = phDal4Nfc_uart_read; 5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.write = phDal4Nfc_uart_write; 5635e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas gLinkFunc.reset = phDal4Nfc_uart_reset; 5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case ENUM_DAL_LINK_TYPE_I2C: 5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5693e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton DAL_PRINT("I2C link Config"); 5703e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton /* i2c link interface */ 5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.init = phDal4Nfc_i2c_initialize; 5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.open_from_handle = phDal4Nfc_i2c_set_open_from_handle; 5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.is_opened = phDal4Nfc_i2c_is_opened; 5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.flush = phDal4Nfc_i2c_flush; 5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.close = phDal4Nfc_i2c_close; 5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.open_and_configure = phDal4Nfc_i2c_open_and_configure; 5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.read = phDal4Nfc_i2c_read; 5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.write = phDal4Nfc_i2c_write; 5795e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas gLinkFunc.reset = phDal4Nfc_i2c_reset; 5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Shound not happen : Bad parameter */ 5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_PARAMETER); 5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gLinkFunc.init(); /* So that link interface can initialize its internal state */ 5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly retstatus = gLinkFunc.open_and_configure(config, phwref); 5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (retstatus != NFCSTATUS_SUCCESS) 5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return retstatus; 5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Iniatilize the DAL context */ 5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memset(&gDalContext,0,sizeof(phDal4Nfc_SContext_t)); 5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext = &gDalContext; 598e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the Reader Thread values to NULL */ 6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext)); 6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nReadThreadAlive = TRUE; 602e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nWriteBusy = FALSE; 603e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nWaitingOnWrite = FALSE; 604e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Prepare the message queue for the defered calls */ 6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef USE_MQ_MESSAGE_QUEUE 6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedCallMessageQueueId = mq_open(MQ_NAME_IDENTIFIER, O_CREAT|O_RDWR, 0666, &MQ_QUEUE_ATTRIBUTES); 6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else 6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedCallMessageQueueId = config->nClientId; 6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Start Read and Write Threads */ 6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NFCSTATUS_SUCCESS != phDal4Nfc_StartThreads()) 6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED); 6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gDalContext.hw_valid = TRUE; 6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 619df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS phDal4Nfc_Reset(1); 6203e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton phDal4Nfc_Reset(0); 6213e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton phDal4Nfc_Reset(1); 6223e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return NFCSTATUS_SUCCESS; 6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6263e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton/*----------------------------------------------------------------------------- 6273e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6283e98767aaf73b4779a2bb39601806045b2ba1739Jeff HamiltonFUNCTION: phDal4Nfc_Reset 6293e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6303e98767aaf73b4779a2bb39601806045b2ba1739Jeff HamiltonPURPOSE: Reset the PN544, using the VEN pin 6313e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6323e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton-----------------------------------------------------------------------------*/ 6333e98767aaf73b4779a2bb39601806045b2ba1739Jeff HamiltonNFCSTATUS phDal4Nfc_Reset(long level) 6343e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton{ 6353e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton NFCSTATUS retstatus = NFCSTATUS_SUCCESS; 6363e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 63734ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly DAL_DEBUG("phDal4Nfc_Reset: VEN to %ld",level); 6383e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6393e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton retstatus = gLinkFunc.reset(level); 6403e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6413e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton return retstatus; 6423e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton} 6433e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6443e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton/*----------------------------------------------------------------------------- 6453e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6463e98767aaf73b4779a2bb39601806045b2ba1739Jeff HamiltonFUNCTION: phDal4Nfc_Download 6473e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6483e98767aaf73b4779a2bb39601806045b2ba1739Jeff HamiltonPURPOSE: Put the PN544 in download mode, using the GPIO4 pin 6493e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6503e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton-----------------------------------------------------------------------------*/ 6515e97605ca8d83414b122bae72e65ea388b66718adaniel_TomasNFCSTATUS phDal4Nfc_Download() 6523e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton{ 6533e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton NFCSTATUS retstatus = NFCSTATUS_SUCCESS; 6543e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6555e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas DAL_DEBUG("phDal4Nfc_Download: GPIO4 to %d",1); 6563e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6575e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas usleep(10000); 6585e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas retstatus = phDal4Nfc_Reset(2); 6593e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton 6603e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton return retstatus; 6613e98767aaf73b4779a2bb39601806045b2ba1739Jeff Hamilton} 6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*----------------------------------------------------------------------------------- 6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL INTERNAL IMPLEMENTATION 6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly------------------------------------------------------------------------------------*/ 6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL Reader thread handler 6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function manages the reads from the link interface. The reads are done from 6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * this thread to create the asynchronous mecanism. When calling the synchronous 6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * function phDal4Nfc_Read, the nWaitingOnRead mutex is unlocked and the read 6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * can be done. Then a client callback is called to send the result. 6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] pArg A custom argument that can be passed to the thread (not used) 6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval TRUE Thread exiting. 6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 684e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyint phDal4Nfc_ReaderThread(void * pArg) 6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly char retvalue; 6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS result = NFCSTATUS_SUCCESS; 6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t retry_cnt=0; 6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void * memsetRet; 6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static int MsgType= PHDAL4NFC_READ_MESSAGE; 6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int * pmsgType=&MsgType; 6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_Message_t sMsg; 6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_Message_t OsalMsg ; 6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int i; 69892c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly int i2c_error_count; 6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7008763a1998eee9b43169bf0824a77b00b3b88a938Nick Pelly pthread_setname_np(pthread_self(), "reader"); 7018763a1998eee9b43169bf0824a77b00b3b88a938Nick Pelly 7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Create the overlapped event. Must be closed before exiting 7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly to avoid a handle leak. This event is used READ API and the Reader thread*/ 7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_PRINT("RX Thread \n"); 706e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_DEBUG("\nRX Thread nReadThreadAlive = %d",gReadWriteContext.nReadThreadAlive); 707e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_DEBUG("\nRX Thread nWaitingOnRead = %d",gReadWriteContext.nWaitingOnRead); 7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while(gReadWriteContext.nReadThreadAlive) /* Thread Loop */ 7095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Check for the read request from user */ 711e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT("RX Thread Sem Lock\n"); 712e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton sem_wait(&nfc_read_sem); 713e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT("RX Thread Sem UnLock\n"); 714df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS 715df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS if (!gReadWriteContext.nReadThreadAlive) 716df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS { 717df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS /* got the signal that we should exit. NOTE: we don't 718df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS attempt to read below, since the read may block */ 719df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS break; 720df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS } 721df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS 722e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Issue read operation.*/ 72392c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly 72492c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly i2c_error_count = 0; 72592c7e0144b84a27b4573043fef718a8ba458d062Nick Pellyretry: 726e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nNbOfBytesRead=0; 727df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_DEBUG("RX Thread *New *** *****Request Length = %d",gReadWriteContext.nNbOfBytesToRead); 728e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton memsetRet=memset(gReadWriteContext.pReadBuffer,0,gReadWriteContext.nNbOfBytesToRead); 729e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 730e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Wait for IRQ !!! */ 731e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas gReadWriteContext.nNbOfBytesRead = gLinkFunc.read(gReadWriteContext.pReadBuffer, gReadWriteContext.nNbOfBytesToRead); 732e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas 733e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas /* TODO: Remove this hack 734e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas * Reading the value 0x57 indicates a HW I2C error at I2C address 0x57 735e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas * (pn544). There should not be false positives because a read of length 1 736e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas * must be a HCI length read, and a length of 0x57 is impossible (max is 33). 737e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas */ 738e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas if(gReadWriteContext.nNbOfBytesToRead == 1 && gReadWriteContext.pReadBuffer[0] == 0x57) 739e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas { 74092c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly i2c_error_count++; 741df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_DEBUG("RX Thread Read 0x57 %d times\n", i2c_error_count); 74292c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly if (i2c_error_count < 5) { 74392c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly usleep(2000); 74492c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly goto retry; 74592c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly } 746df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_PRINT("RX Thread NOTHING TO READ, RECOVER"); 747e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); 748e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas } 749e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas else 750e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas { 75192c7e0144b84a27b4573043fef718a8ba458d062Nick Pelly i2c_error_count = 0; 7524812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly 7534812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly if (low_level_traces) 7544812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly { 7555ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly phOsalNfc_PrintData("RECV", (uint16_t)gReadWriteContext.nNbOfBytesRead, 7565ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly gReadWriteContext.pReadBuffer, low_level_traces); 7574812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly } 758df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_DEBUG("RX Thread Read ok. nbToRead=%d\n", gReadWriteContext.nNbOfBytesToRead); 759df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_DEBUG("RX Thread NbReallyRead=%d\n", gReadWriteContext.nNbOfBytesRead); 76071b688d07db1e7fd32a1e02f29b9779f0d0db377Jeff Hamilton/* DAL_PRINT("RX Thread ReadBuff[]={ "); 761e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton for (i = 0; i < gReadWriteContext.nNbOfBytesRead; i++) 7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 763df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_DEBUG("RX Thread 0x%x ", gReadWriteContext.pReadBuffer[i]); 7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 76571b688d07db1e7fd32a1e02f29b9779f0d0db377Jeff Hamilton DAL_PRINT("RX Thread }\n"); */ 766e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 767e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas /* read completed immediately */ 768e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas sMsg.eMsgType= PHDAL4NFC_READ_MESSAGE; 769e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas /* Update the state */ 770e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas phDal4Nfc_FillMsg(&sMsg,&OsalMsg); 771e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas phDal4Nfc_DeferredCall((pphDal4Nfc_DeferFuncPointer_t)phDal4Nfc_DeferredCb,(void *)pmsgType); 772e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas memsetRet=memset(&sMsg,0,sizeof(phDal4Nfc_Message_t)); 773e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas memsetRet=memset(&OsalMsg,0,sizeof(phOsalNfc_Message_t)); 774e5201c1575b080d023a36ed36edd8017f5c4ce28Daniel Tomas } 775e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } /* End of thread Loop*/ 777df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS 778df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS DAL_PRINT("RX Thread exiting"); 779df82c4dd7c6d5ad232b5628edf73aa9ea3f8c2c0Daniel TOMAS 7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return TRUE; 7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 7825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 7885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL Start threads function 7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function is called from phDal4Nfc_Config and is responsible of creating the 790e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton * reader thread. 7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval NFCSTATUS_SUCCESS If success. 7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval NFCSTATUS_FAILED Can not create thread or retreive its attributes 7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phDal4Nfc_StartThreads(void) 7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_attr_t nReadThreadAttributes; 7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_attr_t nWriteThreadAttributes; 7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int ret; 8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 801e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton if(sem_init(&nfc_read_sem, 0, 0) == -1) 802e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 803e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT("NFC Init Semaphore creation Error"); 804e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton return -1; 805e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton } 8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ret = pthread_create(&gReadWriteContext.nReadThread, NULL, (pphDal4Nfc_thread_handler_t)phDal4Nfc_ReaderThread, (void*) "dal_read_thread"); 8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(ret != 0) 8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return(PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED)); 810e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return NFCSTATUS_SUCCESS; 8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL fill message function 8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Internal messages management. This function fills message structure 8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * depending on message types. 8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in, out] pDalMsg DAL message to fill 8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in, out] pOsalMsg OSAL message to fill 8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phDal4Nfc_FillMsg(phDal4Nfc_Message_t *pDalMsg,phOsalNfc_Message_t *pOsalMsg) 8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != pgDalHwContext) 8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pDalMsg->eMsgType == PHDAL4NFC_WRITE_MESSAGE) 8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.length = (uint8_t)gReadWriteContext.nNbOfBytesWritten; 8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.buffer = NULL; 8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.status = NFCSTATUS_SUCCESS; 8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->pHwRef = pgDalHwContext; 8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->writeCbPtr = pgDalContext->cb_if.send_complete; 8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pOsalMsg->eMsgType = PH_DAL4NFC_MESSAGE_BASE; 8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pOsalMsg->pMsgData = pDalMsg; 8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if(pDalMsg->eMsgType == PHDAL4NFC_READ_MESSAGE) 8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.length = (uint8_t)gReadWriteContext.nNbOfBytesRead; 8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.buffer = gReadWriteContext.pReadBuffer; 8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->pContext= pgDalContext->cb_if.pif_ctxt; 8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.length = (uint8_t)gReadWriteContext.nNbOfBytesReadWait; 8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.buffer = gReadWriteContext.pReadWaitBuffer; 8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->pContext= pgDalContext; 8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->transactInfo.status = NFCSTATUS_SUCCESS; 8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->pHwRef = pgDalHwContext; 8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDalMsg->readCbPtr = pgDalContext->cb_if.receive_complete; 8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*map to OSAL msg format*/ 8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pOsalMsg->eMsgType = PH_DAL4NFC_MESSAGE_BASE; 8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pOsalMsg->pMsgData = pDalMsg; 8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL deferred callback function 8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Generic handler function called by a client thread when reading a message from the queue. 8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Will function will directly call the client function (same context). See phDal4Nfc_DeferredCall 8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] params Parameter that will be passed to the client function. 8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phDal4Nfc_DeferredCb (void *params) 8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int* pParam=NULL; 875e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton int i; 8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sTransactionInfo_t TransactionInfo; 8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pParam=(int*)params; 8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(*pParam) 8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHDAL4NFC_READ_MESSAGE: 8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_PRINT(" Dal deferred read called \n"); 8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly TransactionInfo.buffer=gReadWriteContext.pReadBuffer; 8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesRead; 8865ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly if (gReadWriteContext.nNbOfBytesRead == gReadWriteContext.nNbOfBytesToRead) { 8875ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly TransactionInfo.status=NFCSTATUS_SUCCESS; 8885ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly } else { 8895ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly TransactionInfo.status=NFCSTATUS_READ_FAILED; 8905ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly } 8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nReadBusy = FALSE; 892e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 893e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset flag so that another opertion can be issued.*/ 8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gReadWriteContext.nWaitingOnRead = FALSE; 8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL != pgDalContext) && (NULL != pgDalContext->cb_if.receive_complete)) 8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.receive_complete(pgDalContext->cb_if.pif_ctxt, 8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalHwContext,&TransactionInfo); 9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 901e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHDAL4NFC_WRITE_MESSAGE: 9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly DAL_PRINT(" Dal deferred write called \n"); 905c1f33130d9d2100e6232f8f3c782949c75205be6Daniel Tomas 9064812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly if(low_level_traces) 9074812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly { 9085ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly phOsalNfc_PrintData("SEND", (uint16_t)gReadWriteContext.nNbOfBytesToWrite, 9095ea62ad25e2050f543d8e2104f5ffc1bb2c1ef28Nick Pelly gReadWriteContext.pWriteBuffer, low_level_traces); 9104812a72ceaada294477b4c2015c42cb8bcbe93a4Nick Pelly } 911c1f33130d9d2100e6232f8f3c782949c75205be6Daniel Tomas 9125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* DAL_DEBUG("dalMsg->transactInfo.length : %d\n", dalMsg->transactInfo.length); */ 913e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Make a Physical WRITE */ 91474decc93d868ec1a8f3975a4ce3d1548c6ec6d8fNick Pelly /* NOTE: need to usleep(3000) here if the write is for SWP */ 91599141cdd942973bc0cb8ef208ef717b14eb73b8eNick Pelly usleep(500); /* NXP advise 500us sleep required between I2C writes */ 916e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nNbOfBytesWritten = gLinkFunc.write(gReadWriteContext.pWriteBuffer, gReadWriteContext.nNbOfBytesToWrite); 917e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton if (gReadWriteContext.nNbOfBytesWritten != gReadWriteContext.nNbOfBytesToWrite) 918e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 919e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* controller may be in standby. do it again! */ 920e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton usleep(10000); /* wait 10 ms */ 921e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nNbOfBytesWritten = gLinkFunc.write(gReadWriteContext.pWriteBuffer, gReadWriteContext.nNbOfBytesToWrite); 922e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton } 923e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton if (gReadWriteContext.nNbOfBytesWritten != gReadWriteContext.nNbOfBytesToWrite) 924e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 925e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Report write failure or timeout */ 926e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT(" Physical Write Error !!! \n"); 927e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesWritten; 928e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton TransactionInfo.status = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_BOARD_COMMUNICATION_ERROR); 929e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton } 930e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton else 931e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 932e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_PRINT(" Physical Write Success \n"); 933e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesWritten; 934e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton TransactionInfo.status=NFCSTATUS_SUCCESS; 93534ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly/* DAL_PRINT("WriteBuff[]={ "); 936e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton for (i = 0; i < gReadWriteContext.nNbOfBytesWritten; i++) 937e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 938e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton DAL_DEBUG("0x%x ", gReadWriteContext.pWriteBuffer[i]); 939e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton } 94034ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly DAL_PRINT("}\n"); */ 9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 942e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton // Free TempWriteBuffer 943e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton if(gReadWriteContext.pTempWriteBuffer != NULL) 944e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton { 945e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton free(gReadWriteContext.pTempWriteBuffer); 946e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton } 947e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton } 948e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* Reset Write context */ 949e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nWriteBusy = FALSE; 950e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton gReadWriteContext.nWaitingOnWrite = FALSE; 951e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton 952e7f38d39c75da44b181ef924d215411e048a5848Jeff Hamilton /* call LLC callback */ 9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NULL != pgDalContext) && (NULL != pgDalContext->cb_if.send_complete)) 9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalContext->cb_if.send_complete(pgDalContext->cb_if.pif_ctxt, 9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pgDalHwContext,&TransactionInfo); 9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL deferred call function 9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function will enable to call the callback client asyncronously and in the client context. 9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * It will post a message in a queue that will be processed by a client thread. 9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] func The function to call when message is read from the queue 9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] param Parameter that will be passed to the 'func' function. 9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phDal4Nfc_DeferredCall(pphDal4Nfc_DeferFuncPointer_t func, void *param) 9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly int retvalue = 0; 9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_Message_Wrapper_t nDeferedMessageWrapper; 9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_DeferredCall_Msg_t *pDeferedMessage; 9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static phDal4Nfc_DeferredCall_Msg_t nDeferedMessageRead; 9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static phDal4Nfc_DeferredCall_Msg_t nDeferedMessageWrite; 9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef USE_MQ_MESSAGE_QUEUE 9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessage.eMsgType = PH_DAL4NFC_MESSAGE_BASE; 9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessage.def_call = func; 9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessage.params = param; 9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly retvalue = (int)mq_send(nDeferedCallMessageQueueId, (char *)&nDeferedMessage, sizeof(phDal4Nfc_DeferredCall_Msg_t), 0); 9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else 9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(PHDAL4NFC_READ_MESSAGE==(* (int*)param)) 9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDeferedMessage = &nDeferedMessageRead; 9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDeferedMessage = &nDeferedMessageWrite; 9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessageWrapper.mtype = 1; 9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessageWrapper.msg.eMsgType = PH_DAL4NFC_MESSAGE_BASE; 9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDeferedMessage->pCallback = func; 10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pDeferedMessage->pParameter = param; 10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessageWrapper.msg.pMsgData = pDeferedMessage; 10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nDeferedMessageWrapper.msg.Size = sizeof(phDal4Nfc_DeferredCall_Msg_t); 10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly retvalue = phDal4Nfc_msgsnd(nDeferedCallMessageQueueId, (struct msgbuf *)&nDeferedMessageWrapper, sizeof(phLibNfc_Message_t), 0); 10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 10075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#undef _DAL_4_NFC_C 1009