Home | History | Annotate | Download | only in include
      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
     21 typedef unsigned long   UINT32;
     22 #endif
     23 #include "nfc_target.h"
     24 #include "nfc_hal_api.h"
     25 #include <hardware/nfc.h>
     26 
     27 
     28 class ThreadMutex
     29 {
     30 public:
     31     ThreadMutex();
     32     virtual ~ThreadMutex();
     33     void lock();
     34     void unlock();
     35     operator pthread_mutex_t* () {return &mMutex;}
     36 private:
     37     pthread_mutex_t mMutex;
     38 };
     39 
     40 class ThreadCondVar : public ThreadMutex
     41 {
     42 public:
     43     ThreadCondVar();
     44     virtual ~ThreadCondVar();
     45     void signal();
     46     void wait();
     47     operator pthread_cond_t* () {return &mCondVar;}
     48     operator pthread_mutex_t* () {return ThreadMutex::operator pthread_mutex_t*();}
     49 private:
     50     pthread_cond_t  mCondVar;
     51 };
     52 
     53 class AutoThreadMutex
     54 {
     55 public:
     56     AutoThreadMutex(ThreadMutex &m);
     57     virtual ~AutoThreadMutex();
     58     operator ThreadMutex& ()          {return mm;}
     59     operator pthread_mutex_t* () {return (pthread_mutex_t*)mm;}
     60 private:
     61     ThreadMutex  &mm;
     62 };
     63 
     64 class NfcAdaptation
     65 {
     66 public:
     67     virtual ~NfcAdaptation();
     68     void    Initialize();
     69     void    Finalize();
     70     static  NfcAdaptation& GetInstance();
     71     tHAL_NFC_ENTRY* GetHalEntryFuncs ();
     72     void    DownloadFirmware ();
     73 
     74 private:
     75     NfcAdaptation();
     76     void    signal();
     77     static  NfcAdaptation* mpInstance;
     78     static  ThreadMutex sLock;
     79     ThreadCondVar    mCondVar;
     80     pthread_t mThreadId;
     81     tHAL_NFC_ENTRY   mHalEntryFuncs; // function pointers for HAL entry points
     82     static nfc_nci_device_t* mHalDeviceContext;
     83     static tHAL_NFC_CBACK* mHalCallback;
     84     static tHAL_NFC_DATA_CBACK* mHalDataCallback;
     85     static ThreadCondVar mHalOpenCompletedEvent;
     86     static ThreadCondVar mHalCloseCompletedEvent;
     87 
     88     static UINT32 NFCA_TASK (UINT32 arg);
     89     static UINT32 Thread (UINT32 arg);
     90     void InitializeHalDeviceContext ();
     91     static void HalDeviceContextCallback (nfc_event_t event, nfc_status_t event_status);
     92     static void HalDeviceContextDataCallback (uint16_t data_len, uint8_t* p_data);
     93 
     94     static void HalInitialize ();
     95     static void HalTerminate ();
     96     static void HalOpen (tHAL_NFC_CBACK* p_hal_cback, tHAL_NFC_DATA_CBACK* p_data_cback);
     97     static void HalClose ();
     98     static void HalCoreInitialized (UINT8* p_core_init_rsp_params);
     99     static void HalWrite (UINT16 data_len, UINT8* p_data);
    100     static BOOLEAN HalPrediscover ();
    101     static void HalControlGranted ();
    102     static void HalPowerCycle ();
    103     static void HalDownloadFirmwareCallback (nfc_event_t event, nfc_status_t event_status);
    104     static void HalDownloadFirmwareDataCallback (uint16_t data_len, uint8_t* p_data);
    105 };
    106 
    107