merge with master
[adaptation/devices/nfc-plugin-nxp.git] / src / phFriNfc_LlcpUtils.h
1 /*\r
2  * Copyright (C) 2010 NXP Semiconductors\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * \file  phFriNfc_LlcpUtils.h\r
19  * \brief NFC LLCP utils\r
20  *\r
21  * Project: NFC-FRI\r
22  *\r
23  */\r
24 \r
25 #ifndef PHFRINFC_LLCPUTILS_H\r
26 #define PHFRINFC_LLCPUTILS_H\r
27 \r
28 /*include files*/\r
29 #include <phNfcHalTypes.h>\r
30 #include <phNfcTypes.h>\r
31 #include <phNfcStatus.h>\r
32 #include <phFriNfc.h>\r
33 #include <phFriNfc_Llcp.h>\r
34 \r
35 /** \r
36  * \name NFC Forum Logical Link Control Protocol Utils\r
37  *\r
38  * File: \ref phFriNfc_LlcpUtils.h\r
39  *\r
40  */\r
41 \r
42 /**\r
43  * UTIL_FIFO_BUFFER - A Cyclic FIFO buffer\r
44  * If pIn == pOut the buffer is empty.\r
45  */\r
46 typedef struct UTIL_FIFO_BUFFER\r
47 {\r
48    uint8_t          *pBuffStart;    /* Points to first valid location in buffer */\r
49    uint8_t          *pBuffEnd;      /* Points to last valid location in buffer */\r
50    volatile uint8_t *pIn;           /* Points to 1 before where the next TU1 will enter buffer */\r
51    volatile uint8_t *pOut;          /* Points to 1 before where the next TU1 will leave buffer */\r
52    volatile bool_t  bFull;         /* TRUE if buffer is full */\r
53 }UTIL_FIFO_BUFFER, *P_UTIL_FIFO_BUFFER;\r
54 \r
55 \r
56 /** \defgroup grp_fri_nfc_llcp NFC Forum Logical Link Control Protocol Component\r
57  *\r
58  *  TODO\r
59  *\r
60  */\r
61 \r
62 NFCSTATUS phFriNfc_Llcp_DecodeTLV( phNfc_sData_t  *psRawData,\r
63                                    uint32_t       *pOffset,\r
64                                    uint8_t        *pType,\r
65                                    phNfc_sData_t  *psValueBuffer );\r
66 \r
67 NFCSTATUS phFriNfc_Llcp_EncodeTLV( phNfc_sData_t  *psValueBuffer,\r
68                                    uint32_t       *pOffset,\r
69                                    uint8_t        type,\r
70                                    uint8_t        length,\r
71                                    uint8_t        *pValue);\r
72 \r
73 void phFriNfc_Llcp_EncodeMIUX(uint16_t pMiux,\r
74                               uint8_t* pMiuxEncoded);\r
75 \r
76 void phFriNfc_Llcp_EncodeRW(uint8_t *pRw);\r
77 \r
78 /**\r
79  * Initializes a Fifo Cyclic Buffer to point to some allocated memory.\r
80  */\r
81 void phFriNfc_Llcp_CyclicFifoInit(P_UTIL_FIFO_BUFFER     sUtilFifo,\r
82                                   const uint8_t        *pBuffStart,\r
83                                   uint32_t             buffLength);\r
84 \r
85 /**\r
86  * Clears the Fifo Cyclic Buffer - loosing any data that was in it.\r
87  */\r
88 void phFriNfc_Llcp_CyclicFifoClear(P_UTIL_FIFO_BUFFER sUtilFifo);\r
89 \r
90 \r
91 /**\r
92  * Attempts to write dataLength bytes to the specified Fifo Cyclic Buffer.\r
93  */\r
94 uint32_t phFriNfc_Llcp_CyclicFifoWrite(P_UTIL_FIFO_BUFFER     sUtilFifo,\r
95                                        uint8_t              *pData,\r
96                                        uint32_t             dataLength);\r
97 \r
98 /**\r
99  * Attempts to read dataLength bytes from the specified  Fifo Cyclic Buffer.\r
100  */\r
101 uint32_t phFriNfc_Llcp_CyclicFifoFifoRead(P_UTIL_FIFO_BUFFER     sUtilFifo,\r
102                                           uint8_t              *pBuffer,\r
103                                           uint32_t             dataLength);\r
104 \r
105 /**\r
106  * Returns the number of bytes currently stored in Fifo Cyclic Buffer.\r
107  */\r
108 uint32_t phFriNfc_Llcp_CyclicFifoUsage(P_UTIL_FIFO_BUFFER sUtilFifo);\r
109 \r
110 /**\r
111  * Returns the available room for writing in Fifo Cyclic Buffer.\r
112  */\r
113 uint32_t phFriNfc_Llcp_CyclicFifoAvailable(P_UTIL_FIFO_BUFFER sUtilFifo);\r
114 \r
115 uint32_t phFriNfc_Llcp_Header2Buffer( phFriNfc_Llcp_sPacketHeader_t *psHeader,\r
116                                       uint8_t *pBuffer,\r
117                                       uint32_t nOffset );\r
118 \r
119 uint32_t phFriNfc_Llcp_Sequence2Buffer( phFriNfc_Llcp_sPacketSequence_t *psSequence,\r
120                                         uint8_t *pBuffer,\r
121                                         uint32_t nOffset );\r
122 \r
123 uint32_t phFriNfc_Llcp_Buffer2Header( uint8_t *pBuffer,\r
124                                       uint32_t nOffset,\r
125                                       phFriNfc_Llcp_sPacketHeader_t *psHeader );\r
126 \r
127 uint32_t phFriNfc_Llcp_Buffer2Sequence( uint8_t *pBuffer,\r
128                                         uint32_t nOffset,\r
129                                         phFriNfc_Llcp_sPacketSequence_t *psSequence );\r
130 \r
131 \r
132 #endif /* PHFRINFC_LLCPUTILS_H */\r