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