1 /** ----------------------------------------------------------------------
2  *
3  * Copyright (C) 2016 ST Microelectronics S.A.
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 #ifndef __HALCORE_H_
20 #define __HALCORE_H_
21 
22 #include <android/log.h>
23 #include <errno.h>
24 #include <pthread.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 
29 /* events sent from the callback */
30 #define HAL_EVENT_DSWRITE 1  /* write raw HAL data downstream   */
31 #define HAL_EVENT_DATAIND 2  /* new NCI frame received from CLF  */
32 #define HAL_EVENT_LINKLOST 3 /* connection/link lost             */
33 #define HAL_EVENT_ERROR 4    /* protocol got into an error state */
34 #define HAL_EVENT_JUNKRECEIVED \
35   5 /* protocol signals that junk has been received. resyncronization */
36 
37 #define HAL_EVENT_TIMER_TIMEOUT 6
38 
39 /* flags to be passed to HalCreate */
40 
41 #define HAL_WRAPPER_TIMEOUT_EVT 7
42 
43 #define HAL_FLAG_NO_DEBUG 0 /* disable debug output */
44 #define HAL_FLAG_DEBUG 1    /* enable debug output */
45 
46 typedef enum {
47   HAL_WRAPPER_STATE_CLOSED,
48   HAL_WRAPPER_STATE_OPEN,
49   HAL_WRAPPER_STATE_OPEN_CPLT,
50   HAL_WRAPPER_STATE_NFC_ENABLE_ON,
51   HAL_WRAPPER_STATE_PROP_CONFIG,
52   HAL_WRAPPER_STATE_READY,
53   HAL_WRAPPER_STATE_CLOSING,
54   HAL_WRAPPER_STATE_EXIT_HIBERNATE_INTERNAL,
55   HAL_WRAPPER_STATE_UPDATE,
56   HAL_WRAPPER_STATE_APPLY_CUSTOM_PARAM,
57   HAL_WRAPPER_STATE_APPLY_UWB_PARAM,
58   HAL_WRAPPER_STATE_SET_ACTIVERW_TIMER,
59 } hal_wrapper_state_e;
60 
61 /* callback function to communicate from HAL Core with the outside world */
62 typedef void (*HAL_CALLBACK)(void* context, uint32_t event, const void* data,
63                              size_t length);
64 
65 /* flags to be passed to HALCreate */
66 
67 typedef void* HALHANDLE;
68 
69 HALHANDLE HalCreate(void* context, HAL_CALLBACK callback, uint32_t flags);
70 
71 void HalDestroy(HALHANDLE hHAL);
72 
73 /* send an NCI frame from the HOST to the CLF */
74 bool HalSendDownstream(HALHANDLE hHAL, const uint8_t* data, size_t size);
75 
76 // HAL WRAPPER
77 bool HalSendDownstreamTimer(HALHANDLE hHAL, const uint8_t* data, size_t size,
78                             uint32_t duration);
79 bool HalSendDownstreamTimer(HALHANDLE hHAL, uint32_t duration);
80 bool HalSendDownstreamStopTimer(HALHANDLE hHAL);
81 
82 /* send a complete HDLC frame from the CLF to the HOST */
83 bool HalSendUpstream(HALHANDLE hHAL, const uint8_t* data, size_t size);
84 
85 void hal_wrapper_set_state(hal_wrapper_state_e new_wrapper_state);
86 void I2cResetPulse();
87 #endif
88