NfcAdaptation.h revision b58ba0e89a3767e6174c42d3e90540d1eae10f81
1/****************************************************************************** 2 * 3 * Copyright (C) 2011-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18#pragma once 19#include <pthread.h> 20#ifndef UINT32 21typedef unsigned long UINT32; 22#endif 23#include "nfc_hal_api.h" 24#include <hardware/nfc.h> 25 26 27class ThreadMutex 28{ 29public: 30 ThreadMutex(); 31 virtual ~ThreadMutex(); 32 void lock(); 33 void unlock(); 34 operator pthread_mutex_t* () {return &mMutex;} 35private: 36 pthread_mutex_t mMutex; 37}; 38 39class ThreadCondVar : public ThreadMutex 40{ 41public: 42 ThreadCondVar(); 43 virtual ~ThreadCondVar(); 44 void signal(); 45 void wait(); 46 operator pthread_cond_t* () {return &mCondVar;} 47 operator pthread_mutex_t* () {return ThreadMutex::operator pthread_mutex_t*();} 48private: 49 pthread_cond_t mCondVar; 50}; 51 52class AutoThreadMutex 53{ 54public: 55 AutoThreadMutex(ThreadMutex &m); 56 virtual ~AutoThreadMutex(); 57 operator ThreadMutex& () {return mm;} 58 operator pthread_mutex_t* () {return (pthread_mutex_t*)mm;} 59private: 60 ThreadMutex &mm; 61}; 62 63class NfcAdaptation 64{ 65public: 66 virtual ~NfcAdaptation(); 67 void Initialize(); 68 void Finalize(); 69 static NfcAdaptation& GetInstance(); 70 tHAL_NFC_ENTRY* GetHalEntryFuncs (); 71 72private: 73 NfcAdaptation(); 74 void signal(); 75 static NfcAdaptation* mpInstance; 76 static ThreadMutex sLock; 77 ThreadCondVar mCondVar; 78 pthread_t mThreadId; 79 tHAL_NFC_ENTRY mHalEntryFuncs; // function pointers for HAL entry points 80 static nfc_nci_device_t* mHalDeviceContext; 81 static tHAL_NFC_CBACK* mHalCallback; 82 83 static UINT32 NFCA_TASK (UINT32 arg); 84 static UINT32 Thread (UINT32 arg); 85 void InitializeHalDeviceContext (); 86 static void HalDeviceContextCallback (nfc_event_t event, nfc_event_data_t* p_data); 87 88 static void HalInitialize (); 89 static void HalTerminate (); 90 static void HalOpen (tHAL_NFC_CBACK* p_hal_cback); 91 static void HalClose (); 92 static void HalCoreInitialized (UINT8* p_core_init_rsp_params); 93 static void HalWrite (UINT16 data_len, UINT8* p_data); 94 static BOOLEAN HalPrediscover (); 95 static void HalControlGranted (); 96 static void HalPowerCycle (); 97}; 98 99