• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2020-2021 NXP
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 
19 #pragma once
20 #include <NfccTransport.h>
21 
22 #define NFC_MAGIC 0xE9
23 /*
24  * NFCC power control via ioctl
25  * NFC_SET_PWR(0): power off
26  * NFC_SET_PWR(1): power on
27  * NFC_SET_PWR(2): reset and power on with firmware download enabled
28  */
29 #define NFC_SET_PWR _IOW(NFC_MAGIC, 0x01, uint32_t)
30 /*
31  * 1. SPI Request NFCC to enable ESE power, only in param
32  *   Only for SPI
33  *   level 1 = Enable power
34  *   level 0 = Disable power
35  * 2. NFC Request the eSE cold reset, only with MODE_ESE_COLD_RESET
36  */
37 #define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, uint32_t)
38 
39 /*
40  * SPI or DWP can call this ioctl to get the current
41  * power state of ESE
42  */
43 #define ESE_GET_PWR _IOR(NFC_MAGIC, 0x03, uint32_t)
44 
45 extern phTmlNfc_i2cfragmentation_t fragmentation_enabled;
46 
47 class NfccI2cTransport : public NfccTransport {
48  private:
49   bool_t bFwDnldFlag = false;
50   sem_t mTxRxSemaphore;
51 
52 
53  public:
54   /*****************************************************************************
55   **
56   ** Function         Close
57   **
58   ** Description      Closes NFCC device
59   **
60   ** Parameters       pDevHandle - device handle
61   **
62   ** Returns          None
63   **
64   *****************************************************************************/
65   void Close(void* pDevHandle);
66 
67   /*****************************************************************************
68    **
69    ** Function         OpenAndConfigure
70    **
71    ** Description      Open and configure NFCC device
72    **
73    ** Parameters       pConfig     - hardware information
74    **                  pLinkHandle - device handle
75    **
76    ** Returns          NFC status:
77    **                  NFCSTATUS_SUCCESS - open_and_configure operation success
78    **                  NFCSTATUS_INVALID_DEVICE - device open operation failure
79    **
80    ****************************************************************************/
81   NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, void** pLinkHandle);
82 
83   /*****************************************************************************
84    **
85    ** Function         Read
86    **
87    ** Description      Reads requested number of bytes from NFCC device into
88    *given
89    **                  buffer
90    **
91    ** Parameters       pDevHandle       - valid device handle
92    **                  pBuffer          - buffer for read data
93    **                  nNbBytesToRead   - number of bytes requested to be read
94    **
95    ** Returns          numRead   - number of successfully read bytes
96    **                  -1        - read operation failure
97    **
98    ****************************************************************************/
99   int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead);
100 
101   /*****************************************************************************
102   **
103   ** Function         Write
104   **
105   ** Description      Writes requested number of bytes from given buffer into
106   **                  NFCC device
107   **
108   ** Parameters       pDevHandle       - valid device handle
109   **                  pBuffer          - buffer for read data
110   **                  nNbBytesToWrite  - number of bytes requested to be
111   *written
112   **
113   ** Returns          numWrote   - number of successfully written bytes
114   **                  -1         - write operation failure
115   **
116   *****************************************************************************/
117   int Write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite);
118 
119   /*****************************************************************************
120    **
121    ** Function         Reset
122    **
123    ** Description      Reset NFCC device, using VEN pin
124    **
125    ** Parameters       pDevHandle     - valid device handle
126    **                  level          - reset level
127    **
128    ** Returns           0   - reset operation success
129    **                  -1   - reset operation failure
130    **
131    ****************************************************************************/
132   int NfccReset(void* pDevHandle, NfccResetType eType);
133 
134   /*****************************************************************************
135    **
136    ** Function         EseReset
137    **
138    ** Description      Request NFCC to reset the eSE
139    **
140    ** Parameters       pDevHandle     - valid device handle
141    **                  eType          - EseResetType
142    **
143    ** Returns           0   - reset operation success
144    **                  else - reset operation failure
145    **
146    ****************************************************************************/
147   int EseReset(void* pDevHandle, EseResetType eType);
148 
149   /*****************************************************************************
150    **
151    ** Function         EseGetPower
152    **
153    ** Description      Request NFCC to reset the eSE
154    **
155    ** Parameters       pDevHandle     - valid device handle
156    **                  level          - reset level
157    **
158    ** Returns           0   - reset operation success
159    **                  else - reset operation failure
160    **
161    ****************************************************************************/
162   int EseGetPower(void* pDevHandle, uint32_t level);
163 
164   /*****************************************************************************
165    **
166    ** Function         EnableFwDnldMode
167    **
168    ** Description      updates the state to Download mode
169    **
170    ** Parameters       True/False
171    **
172    ** Returns          None
173    ****************************************************************************/
174   void EnableFwDnldMode(bool mode);
175 
176   /*****************************************************************************
177    **
178    ** Function         IsFwDnldModeEnabled
179    **
180    ** Description      Returns the current mode
181    **
182    ** Parameters       none
183    **
184    ** Returns           Current mode download/NCI
185    ****************************************************************************/
186   bool_t IsFwDnldModeEnabled(void);
187 
188   /*******************************************************************************
189   **
190   ** Function         Flushdata
191   **
192   ** Description      Reads payload of FW rsp from NFCC device into given
193   *buffer
194   **
195   ** Parameters       pConfig     - hardware information
196   **
197   ** Returns          True(Success)/False(Fail)
198   **
199   *******************************************************************************/
200   bool Flushdata(pphTmlNfc_Config_t pConfig);
201 };
202