• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 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 
19 /******************************************************************************
20  *
21  *  Vendor-specific handler for DM events
22  *
23  ******************************************************************************/
24 #include "nfc_hal_int.h"
25 #include "nfc_hal_post_reset.h"
26 #include "userial.h"
27 #include "upio.h"
28 
29 /*****************************************************************************
30 ** Constants and types
31 *****************************************************************************/
32 
33 #define NFC_HAL_I93_RW_CFG_LEN              (5)
34 #define NFC_HAL_I93_RW_CFG_PARAM_LEN        (3)
35 #define NFC_HAL_I93_AFI                     (0)
36 #define NFC_HAL_I93_ENABLE_SMART_POLL       (1)
37 
38 static UINT8 nfc_hal_dm_i93_rw_cfg[NFC_HAL_I93_RW_CFG_LEN] =
39 {
40     NCI_PARAM_ID_I93_DATARATE,
41     NFC_HAL_I93_RW_CFG_PARAM_LEN,
42     NFC_HAL_I93_FLAG_DATA_RATE,    /* Bit0:Sub carrier, Bit1:Data rate, Bit4:Enable/Disable AFI */
43     NFC_HAL_I93_AFI,               /* AFI if Bit 4 is set in the flag byte */
44     NFC_HAL_I93_ENABLE_SMART_POLL  /* Bit0:Enable/Disable smart poll */
45 };
46 
47 static UINT8 nfc_hal_dm_set_fw_fsm_cmd[NCI_MSG_HDR_SIZE + 1] =
48 {
49     NCI_MTS_CMD|NCI_GID_PROP,
50     NCI_MSG_SET_FWFSM,
51     0x01,
52     0x00,
53 };
54 #define NCI_SET_FWFSM_OFFSET_ENABLE      3
55 
56 const UINT8 nfc_hal_dm_core_reset_cmd[NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET] =
57 {
58     NCI_MTS_CMD|NCI_GID_CORE,
59     NCI_MSG_CORE_RESET,
60     NCI_CORE_PARAM_SIZE_RESET,
61     NCI_RESET_TYPE_RESET_CFG
62 };
63 
64 #define NCI_PROP_PARAM_SIZE_XTAL_INDEX      3       /* length of parameters in XTAL_INDEX CMD */
65 
66 const UINT8 nfc_hal_dm_get_build_info_cmd[NCI_MSG_HDR_SIZE] =
67 {
68     NCI_MTS_CMD|NCI_GID_PROP,
69     NCI_MSG_GET_BUILD_INFO,
70     0x00
71 };
72 #define NCI_BUILD_INFO_OFFSET_HWID  25  /* HW ID offset in build info RSP */
73 
74 const UINT8 nfc_hal_dm_get_patch_version_cmd [NCI_MSG_HDR_SIZE] =
75 {
76     NCI_MTS_CMD|NCI_GID_PROP,
77     NCI_MSG_GET_PATCH_VERSION,
78     0x00
79 };
80 #define NCI_PATCH_INFO_OFFSET_NVMTYPE  35  /* NVM Type offset in patch info RSP */
81 
82 /*****************************************************************************
83 ** Extern function prototypes
84 *****************************************************************************/
85 extern UINT8 *p_nfc_hal_dm_lptd_cfg;
86 extern UINT8 *p_nfc_hal_dm_pll_325_cfg;
87 extern UINT8 *p_nfc_hal_dm_start_up_cfg;
88 extern UINT8 *p_nfc_hal_dm_start_up_vsc_cfg;
89 
90 /*****************************************************************************
91 ** Local function prototypes
92 *****************************************************************************/
93 
94 /*******************************************************************************
95 **
96 ** Function         nfc_hal_dm_set_config
97 **
98 ** Description      Send NCI config items to NFCC
99 **
100 ** Returns          tHAL_NFC_STATUS
101 **
102 *******************************************************************************/
nfc_hal_dm_set_config(UINT8 tlv_size,UINT8 * p_param_tlvs,tNFC_HAL_NCI_CBACK * p_cback)103 tHAL_NFC_STATUS nfc_hal_dm_set_config (UINT8 tlv_size,
104                                        UINT8 *p_param_tlvs,
105                                        tNFC_HAL_NCI_CBACK *p_cback)
106 {
107     UINT8  *p_buff, *p;
108     UINT8  num_param = 0, param_len, rem_len, *p_tlv;
109     UINT16 cmd_len = NCI_MSG_HDR_SIZE + tlv_size + 1;
110     tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED;
111 
112     if ((tlv_size == 0)||(p_param_tlvs == NULL))
113     {
114         return status;
115     }
116 
117     if ((p_buff = (UINT8 *) GKI_getbuf ((UINT16)(NCI_MSG_HDR_SIZE + tlv_size))) != NULL)
118     {
119         p = p_buff;
120 
121         NCI_MSG_BLD_HDR0 (p, NCI_MT_CMD, NCI_GID_CORE);
122         NCI_MSG_BLD_HDR1 (p, NCI_MSG_CORE_SET_CONFIG);
123         UINT8_TO_STREAM  (p, (UINT8) (tlv_size + 1));
124 
125         rem_len = tlv_size;
126         p_tlv   = p_param_tlvs;
127         while (rem_len > 1)
128         {
129             num_param++;                /* number of params */
130 
131             p_tlv ++;                   /* param type   */
132             param_len = *p_tlv++;       /* param length */
133 
134             rem_len -= 2;               /* param type and length */
135             if (rem_len >= param_len)
136             {
137                 rem_len -= param_len;
138                 p_tlv   += param_len;   /* next param_type */
139 
140                 if (rem_len == 0)
141                 {
142                     status = HAL_NFC_STATUS_OK;
143                     break;
144                 }
145             }
146             else
147             {
148                 /* error found */
149                 break;
150             }
151         }
152 
153         if (status == HAL_NFC_STATUS_OK)
154         {
155             UINT8_TO_STREAM (p, num_param);
156             ARRAY_TO_STREAM (p, p_param_tlvs, tlv_size);
157 
158             nfc_hal_dm_send_nci_cmd (p_buff, cmd_len, p_cback);
159         }
160         else
161         {
162             NCI_TRACE_ERROR0 ("nfc_hal_dm_set_config ():Bad TLV");
163         }
164 
165         GKI_freebuf (p_buff);
166     }
167 
168     return status;
169 }
170 
171 /*******************************************************************************
172 **
173 ** Function         nfc_hal_dm_get_xtal_index
174 **
175 ** Description      Convert xtal frequency to index
176 **
177 ** Returns          xtal index
178 **
179 *******************************************************************************/
nfc_hal_dm_get_xtal_index(UINT16 xtal_freq)180 static tNFC_HAL_XTAL_INDEX nfc_hal_dm_get_xtal_index (UINT16 xtal_freq)
181 {
182     tNFC_HAL_XTAL_INDEX xtal_index;
183 
184     switch (xtal_freq)
185     {
186     case  9600: xtal_index = NFC_HAL_XTAL_INDEX_9600;  break;
187     case 13000: xtal_index = NFC_HAL_XTAL_INDEX_13000; break;
188     case 16200: xtal_index = NFC_HAL_XTAL_INDEX_16200; break;
189     case 19200: xtal_index = NFC_HAL_XTAL_INDEX_19200; break;
190     case 24000: xtal_index = NFC_HAL_XTAL_INDEX_24000; break;
191     case 26000: xtal_index = NFC_HAL_XTAL_INDEX_26000; break;
192     case 38400: xtal_index = NFC_HAL_XTAL_INDEX_38400; break;
193     case 52000: xtal_index = NFC_HAL_XTAL_INDEX_52000; break;
194     case 37400: xtal_index = NFC_HAL_XTAL_INDEX_37400; break;
195     default :   xtal_index = NFC_HAL_XTAL_INDEX_MAX;
196                 NCI_TRACE_DEBUG1 ("nfc_hal_dm_get_xtal_index ():No matched index for %d", xtal_freq);
197                 break;
198     }
199 
200     return xtal_index;
201 }
202 
203 /*******************************************************************************
204 **
205 ** Function         nfc_hal_dm_set_fw_fsm
206 **
207 ** Description      Enable or disable FW FSM
208 **
209 ** Returns          void
210 **
211 *******************************************************************************/
nfc_hal_dm_set_fw_fsm(BOOLEAN enable,tNFC_HAL_NCI_CBACK * p_cback)212 void nfc_hal_dm_set_fw_fsm (BOOLEAN enable, tNFC_HAL_NCI_CBACK *p_cback)
213 {
214     if (enable)
215         nfc_hal_dm_set_fw_fsm_cmd[NCI_SET_FWFSM_OFFSET_ENABLE] = 0x01; /* Enable, default is disabled */
216     else
217         nfc_hal_dm_set_fw_fsm_cmd[NCI_SET_FWFSM_OFFSET_ENABLE] = 0x00; /* Disable */
218 
219     nfc_hal_dm_send_nci_cmd (nfc_hal_dm_set_fw_fsm_cmd, NCI_MSG_HDR_SIZE + 1, p_cback);
220 }
221 
222 /*******************************************************************************
223 **
224 ** Function         nfc_hal_dm_config_nfcc_cback
225 **
226 ** Description      Callback for NCI vendor specific command complete
227 **
228 ** Returns          void
229 **
230 *******************************************************************************/
nfc_hal_dm_config_nfcc_cback(tNFC_HAL_NCI_EVT event,UINT16 data_len,UINT8 * p_data)231 void nfc_hal_dm_config_nfcc_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data)
232 {
233     if (nfc_hal_cb.dev_cb.next_dm_config == NFC_HAL_DM_CONFIG_NONE)
234     {
235         nfc_hal_hci_enable ();
236     }
237     else
238     {
239         nfc_hal_dm_config_nfcc ();
240     }
241 }
242 
243 /*******************************************************************************
244 **
245 ** Function         nfc_hal_dm_send_startup_vsc
246 **
247 ** Description      Send VS command before NFA start-up
248 **
249 ** Returns          None
250 **
251 *******************************************************************************/
nfc_hal_dm_send_startup_vsc(void)252 void nfc_hal_dm_send_startup_vsc (void)
253 {
254     UINT8  *p, *p_end;
255     UINT16 len;
256 
257     NCI_TRACE_DEBUG0 ("nfc_hal_dm_send_startup_vsc ()");
258 
259     /* VSC must have NCI header at least */
260     if (nfc_hal_cb.dev_cb.next_startup_vsc + NCI_MSG_HDR_SIZE - 1 <= *p_nfc_hal_dm_start_up_vsc_cfg)
261     {
262         p     = p_nfc_hal_dm_start_up_vsc_cfg + nfc_hal_cb.dev_cb.next_startup_vsc;
263         len   = *(p + 2);
264         p_end = p + NCI_MSG_HDR_SIZE - 1 + len;
265 
266         if (p_end <= p_nfc_hal_dm_start_up_vsc_cfg + *p_nfc_hal_dm_start_up_vsc_cfg)
267         {
268             /* move to next VSC */
269             nfc_hal_cb.dev_cb.next_startup_vsc += NCI_MSG_HDR_SIZE + len;
270 
271             /* if this is last VSC */
272             if (p_end == p_nfc_hal_dm_start_up_vsc_cfg + *p_nfc_hal_dm_start_up_vsc_cfg)
273                 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_NONE;
274 
275             nfc_hal_dm_send_nci_cmd (p, (UINT16)(NCI_MSG_HDR_SIZE + len), nfc_hal_dm_config_nfcc_cback);
276             return;
277         }
278     }
279 
280     NCI_TRACE_ERROR0 ("nfc_hal_dm_send_startup_vsc (): Bad start-up VSC");
281 
282     NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
283     nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
284 }
285 
286 /*******************************************************************************
287 **
288 ** Function         nfc_hal_dm_config_nfcc
289 **
290 ** Description      Send VS config before NFA start-up
291 **
292 ** Returns          void
293 **
294 *******************************************************************************/
nfc_hal_dm_config_nfcc(void)295 void nfc_hal_dm_config_nfcc (void)
296 {
297     UINT8   *p;
298     UINT8   xtal_index;
299 
300     NCI_TRACE_DEBUG1 ("nfc_hal_dm_config_nfcc (): next_dm_config = %d", nfc_hal_cb.dev_cb.next_dm_config);
301 
302     if ((p_nfc_hal_dm_lptd_cfg[0]) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_LPTD))
303     {
304         nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_PLL_325;
305 
306         if (nfc_hal_dm_set_config (p_nfc_hal_dm_lptd_cfg[0],
307                                    &p_nfc_hal_dm_lptd_cfg[1],
308                                    nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
309         {
310             return;
311         }
312         else
313         {
314             NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
315             nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
316             return;
317         }
318     }
319 
320     if ((p_nfc_hal_dm_pll_325_cfg) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_PLL_325))
321     {
322         xtal_index = nfc_hal_dm_get_xtal_index (nfc_post_reset_cb.dev_init_config.xtal_freq);
323         if (xtal_index < NFC_HAL_XTAL_INDEX_MAX)
324         {
325             nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_START_UP;
326             p = p_nfc_hal_dm_pll_325_cfg + (xtal_index * NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN);
327             if (nfc_hal_dm_set_config (NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN,
328                                        p,
329                                        nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
330             {
331                 return;
332             }
333             else
334             {
335                 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
336                 nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
337                 return;
338             }
339         }
340     }
341 
342     if ((p_nfc_hal_dm_start_up_cfg[0]) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_START_UP))
343     {
344         nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_I93_DATA_RATE;
345         if (nfc_hal_dm_set_config (p_nfc_hal_dm_start_up_cfg[0],
346                                    &p_nfc_hal_dm_start_up_cfg[1],
347                                    nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
348         {
349             return;
350         }
351         else
352         {
353             NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
354             nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
355             return;
356         }
357     }
358 
359 #if (NFC_HAL_I93_FLAG_DATA_RATE == NFC_HAL_I93_FLAG_DATA_RATE_HIGH)
360     if (nfc_hal_cb.dev_cb.next_dm_config  <= NFC_HAL_DM_CONFIG_I93_DATA_RATE)
361     {
362         nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_FW_FSM;
363         if (nfc_hal_dm_set_config (NFC_HAL_I93_RW_CFG_LEN,
364                                    nfc_hal_dm_i93_rw_cfg,
365                                    nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
366         {
367             return;
368         }
369         else
370         {
371             NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
372             nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
373             return;
374         }
375     }
376 #endif
377 
378     /* FW FSM is disabled as default in NFCC */
379     if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_FW_FSM)
380     {
381         nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_START_UP_VSC;
382         nfc_hal_dm_set_fw_fsm (NFC_HAL_DM_MULTI_TECH_RESP, nfc_hal_dm_config_nfcc_cback);
383         return;
384     }
385 
386     if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_START_UP_VSC)
387     {
388         if (p_nfc_hal_dm_start_up_vsc_cfg && *p_nfc_hal_dm_start_up_vsc_cfg)
389         {
390             nfc_hal_dm_send_startup_vsc ();
391             return;
392         }
393     }
394 
395     /* nothing to config */
396     nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_NONE;
397     nfc_hal_dm_config_nfcc_cback (0, 0, NULL);
398 }
399 
400 /*******************************************************************************
401 **
402 ** Function         nfc_hal_dm_set_xtal_freq_index
403 **
404 ** Description      Set crystal frequency index
405 **
406 ** Returns          void
407 **
408 *******************************************************************************/
nfc_hal_dm_set_xtal_freq_index(void)409 void nfc_hal_dm_set_xtal_freq_index (void)
410 {
411     UINT8 nci_brcm_xtal_index_cmd[NCI_MSG_HDR_SIZE + NCI_PROP_PARAM_SIZE_XTAL_INDEX];
412     UINT8 *p;
413     tNFC_HAL_XTAL_INDEX xtal_index;
414 
415     NCI_TRACE_DEBUG1 ("nfc_hal_dm_set_xtal_freq_index (): xtal_freq = %d", nfc_post_reset_cb.dev_init_config.xtal_freq);
416 
417     xtal_index = nfc_hal_dm_get_xtal_index (nfc_post_reset_cb.dev_init_config.xtal_freq);
418 
419     switch (xtal_index)
420     {
421     case NFC_HAL_XTAL_INDEX_9600:
422     case NFC_HAL_XTAL_INDEX_13000:
423     case NFC_HAL_XTAL_INDEX_19200:
424     case NFC_HAL_XTAL_INDEX_26000:
425     case NFC_HAL_XTAL_INDEX_38400:
426     case NFC_HAL_XTAL_INDEX_52000:
427 
428         {
429             /* no need to set xtal index for these frequency */
430             NCI_TRACE_DEBUG0 ("nfc_hal_dm_set_xtal_freq_index (): no need to set xtal index");
431 
432             nfc_post_reset_cb.dev_init_config.flags &= ~NFC_HAL_DEV_INIT_FLAGS_SET_XTAL_FREQ;
433             nfc_hal_dm_send_reset_cmd ();
434             return;
435         }
436         break;
437     }
438 
439     p = nci_brcm_xtal_index_cmd;
440     UINT8_TO_STREAM  (p, (NCI_MTS_CMD|NCI_GID_PROP));
441     UINT8_TO_STREAM  (p, NCI_MSG_GET_XTAL_INDEX_FROM_DH);
442     UINT8_TO_STREAM  (p, NCI_PROP_PARAM_SIZE_XTAL_INDEX);
443     UINT8_TO_STREAM  (p, xtal_index);
444     UINT16_TO_STREAM (p, nfc_post_reset_cb.dev_init_config.xtal_freq);
445 
446     NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_XTAL_SET);
447 
448     nfc_hal_dm_send_nci_cmd (nci_brcm_xtal_index_cmd, NCI_MSG_HDR_SIZE + NCI_PROP_PARAM_SIZE_XTAL_INDEX, NULL);
449 }
450 
451 /*******************************************************************************
452 **
453 ** Function         nfc_hal_dm_send_reset_cmd
454 **
455 ** Description      Send CORE RESET CMD
456 **
457 ** Returns          void
458 **
459 *******************************************************************************/
nfc_hal_dm_send_reset_cmd(void)460 void nfc_hal_dm_send_reset_cmd (void)
461 {
462     /* Proceed with start up sequence: send CORE_RESET_CMD */
463     NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_RESET);
464 
465     nfc_hal_dm_send_nci_cmd (nfc_hal_dm_core_reset_cmd, NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET, NULL);
466 }
467 
468 /*******************************************************************************
469 **
470 ** Function         nfc_hal_dm_proc_msg_during_init
471 **
472 ** Description      Process NCI message while initializing NFCC
473 **
474 ** Returns          void
475 **
476 *******************************************************************************/
nfc_hal_dm_proc_msg_during_init(NFC_HDR * p_msg)477 void nfc_hal_dm_proc_msg_during_init (NFC_HDR *p_msg)
478 {
479     UINT8 *p;
480     UINT8 reset_reason, reset_type;
481     UINT8 mt, pbf, gid, op_code;
482     UINT8 *p_old, old_gid, old_oid, old_mt;
483     tNFC_HAL_NCI_CBACK *p_cback = NULL;
484 
485     NCI_TRACE_DEBUG1 ("nfc_hal_dm_proc_msg_during_init(): init state:%d", nfc_hal_cb.dev_cb.initializing_state);
486 
487     p = (UINT8 *) (p_msg + 1) + p_msg->offset;
488 
489     NCI_MSG_PRS_HDR0 (p, mt, pbf, gid);
490     NCI_MSG_PRS_HDR1 (p, op_code);
491 
492     /* check if waiting for this response */
493     if (  (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_CMD)
494         ||(nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_VSC)  )
495     {
496         if (mt == NCI_MT_RSP)
497         {
498             p_old = nfc_hal_cb.ncit_cb.last_hdr;
499             NCI_MSG_PRS_HDR0 (p_old, old_mt, pbf, old_gid);
500             old_oid = ((*p_old) & NCI_OID_MASK);
501             /* make sure this is the RSP we are waiting for before updating the command window */
502             if ((old_gid == gid) && (old_oid == op_code))
503             {
504                 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE;
505                 p_cback = (tNFC_HAL_NCI_CBACK *)nfc_hal_cb.ncit_cb.p_vsc_cback;
506                 nfc_hal_cb.ncit_cb.p_vsc_cback  = NULL;
507                 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
508             }
509         }
510     }
511 
512     if (gid == NCI_GID_CORE)
513     {
514         if (op_code == NCI_MSG_CORE_RESET)
515         {
516             if (mt == NCI_MT_RSP)
517             {
518                 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_RE_INIT)
519                 {
520                     NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE);
521                     nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, nfc_hal_cb.p_reinit_cback);
522                 }
523                 else
524                 {
525                     NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_BUILD_INFO);
526 
527                     /* get build information to find out HW */
528                     nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_build_info_cmd, NCI_MSG_HDR_SIZE, NULL);
529                 }
530             }
531             else
532             {
533                 /* Call reset notification callback */
534                 p++;                                /* Skip over param len */
535                 STREAM_TO_UINT8 (reset_reason, p);
536                 STREAM_TO_UINT8 (reset_type, p);
537                 nfc_hal_prm_spd_reset_ntf (reset_reason, reset_type);
538             }
539         }
540         else if (p_cback)
541         {
542             (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code),
543                         p_msg->len,
544                         (UINT8 *) (p_msg + 1) + p_msg->offset);
545         }
546     }
547     else if (gid == NCI_GID_PROP) /* this is for download patch */
548     {
549         if (mt == NCI_MT_NTF)
550             op_code |= NCI_NTF_BIT;
551         else
552             op_code |= NCI_RSP_BIT;
553 
554         if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_XTAL_SET)
555         {
556             if (op_code == (NCI_RSP_BIT|NCI_MSG_GET_XTAL_INDEX_FROM_DH))
557             {
558                 /* wait for crystal setting in NFCC */
559                 GKI_delay (100);
560 
561                 /* Crytal frequency configured. Proceed with start up sequence: send CORE_RESET_CMD */
562                 nfc_hal_dm_send_reset_cmd ();
563             }
564         }
565         else if (  (op_code == NFC_VS_GET_BUILD_INFO_EVT)
566                  &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_BUILD_INFO)  )
567         {
568             p += NCI_BUILD_INFO_OFFSET_HWID;
569 
570             STREAM_TO_UINT32 (nfc_hal_cb.dev_cb.brcm_hw_id, p);
571 
572             NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO);
573 
574             nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL);
575         }
576         else if (  (op_code == NFC_VS_GET_PATCH_VERSION_EVT)
577                  &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_PATCH_INFO)  )
578         {
579             p += NCI_PATCH_INFO_OFFSET_NVMTYPE;
580 
581             NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE);
582 
583             /* let platform update baudrate or download patch */
584             nfc_hal_post_reset_init (nfc_hal_cb.dev_cb.brcm_hw_id, *p);
585         }
586         else if (p_cback)
587         {
588             (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code),
589                         p_msg->len,
590                         (UINT8 *) (p_msg + 1) + p_msg->offset);
591         }
592         else if (op_code == NFC_VS_SEC_PATCH_AUTH_EVT)
593         {
594             NCI_TRACE_DEBUG0 ("signature!!");
595             nfc_hal_prm_nci_command_complete_cback ((tNFC_HAL_NCI_EVT) (op_code),
596                                                     p_msg->len,
597                                                     (UINT8 *) (p_msg + 1) + p_msg->offset);
598         }
599     }
600 }
601 
602 /*******************************************************************************
603 **
604 ** Function         nfc_hal_dm_send_nci_cmd
605 **
606 ** Description      Send NCI command to NFCC while initializing BRCM NFCC
607 **
608 ** Returns          void
609 **
610 *******************************************************************************/
nfc_hal_dm_send_nci_cmd(const UINT8 * p_data,UINT16 len,tNFC_HAL_NCI_CBACK * p_cback)611 void nfc_hal_dm_send_nci_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_NCI_CBACK *p_cback)
612 {
613     NFC_HDR *p_buf;
614     UINT8  *ps;
615 
616     NCI_TRACE_DEBUG1 ("nfc_hal_dm_send_nci_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp);
617 
618     if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE)
619     {
620         NCI_TRACE_ERROR0 ("nfc_hal_dm_send_nci_cmd(): no command window");
621         return;
622     }
623 
624     if ((p_buf = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
625     {
626         nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_VSC;
627 
628         p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE;
629         p_buf->event  = NFC_HAL_EVT_TO_NFC_NCI;
630         p_buf->len    = len;
631 
632         memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len);
633 
634         /* Keep a copy of the command and send to NCI transport */
635 
636         /* save the message header to double check the response */
637         ps   = (UINT8 *)(p_buf + 1) + p_buf->offset;
638         memcpy(nfc_hal_cb.ncit_cb.last_hdr, ps, NFC_HAL_SAVED_HDR_SIZE);
639         memcpy(nfc_hal_cb.ncit_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_HAL_SAVED_CMD_SIZE);
640 
641         /* save the callback for NCI VSCs */
642         nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback;
643 
644         nfc_hal_nci_send_cmd (p_buf);
645 
646         /* start NFC command-timeout timer */
647         nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP),
648                                         ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
649     }
650 }
651 
652 /*******************************************************************************
653 **
654 ** Function         nfc_hal_dm_send_pend_cmd
655 **
656 ** Description      Send a command to NFCC
657 **
658 ** Returns          void
659 **
660 *******************************************************************************/
nfc_hal_dm_send_pend_cmd(void)661 void nfc_hal_dm_send_pend_cmd (void)
662 {
663     NFC_HDR *p_buf = nfc_hal_cb.ncit_cb.p_pend_cmd;
664     UINT8  *p;
665 
666     if (p_buf == NULL)
667         return;
668 
669     /* check low power mode state */
670     if (!nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TX_DATA_EVT))
671     {
672         return;
673     }
674 
675     if (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_PROP)
676     {
677 #if (NFC_HAL_TRACE_PROTOCOL == TRUE)
678         DispHciCmd (p_buf);
679 #endif
680 
681         /* save the message header to double check the response */
682         p = (UINT8 *)(p_buf + 1) + p_buf->offset;
683         memcpy(nfc_hal_cb.ncit_cb.last_hdr, p, NFC_HAL_SAVED_HDR_SIZE);
684 
685         /* add packet type for BT message */
686         p_buf->offset--;
687         p_buf->len++;
688 
689         p  = (UINT8 *) (p_buf + 1) + p_buf->offset;
690         *p = HCIT_TYPE_COMMAND;
691 
692         USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len);
693 
694         GKI_freebuf (p_buf);
695         nfc_hal_cb.ncit_cb.p_pend_cmd = NULL;
696 
697         /* start NFC command-timeout timer */
698         nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP),
699                                         ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
700 
701     }
702 }
703 
704 /*******************************************************************************
705 **
706 ** Function         nfc_hal_dm_send_bt_cmd
707 **
708 ** Description      Send BT message to NFCC while initializing BRCM NFCC
709 **
710 ** Returns          void
711 **
712 *******************************************************************************/
nfc_hal_dm_send_bt_cmd(const UINT8 * p_data,UINT16 len,tNFC_HAL_BTVSC_CPLT_CBACK * p_cback)713 void nfc_hal_dm_send_bt_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_BTVSC_CPLT_CBACK *p_cback)
714 {
715     NFC_HDR *p_buf;
716 
717     NCI_TRACE_DEBUG1 ("nfc_hal_dm_send_bt_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp);
718 
719     if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE)
720     {
721         NCI_TRACE_ERROR0 ("nfc_hal_dm_send_bt_cmd(): no command window");
722         return;
723     }
724 
725     if ((p_buf = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
726     {
727         nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_PROP;
728 
729         p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE;
730         p_buf->len    = len;
731 
732         memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len);
733 
734         /* save the callback for NCI VSCs)  */
735         nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback;
736 
737         nfc_hal_cb.ncit_cb.p_pend_cmd = p_buf;
738         if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_IDLE)
739         {
740             NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_W4_CONTROL_DONE);
741             nfc_hal_cb.p_stack_cback (HAL_NFC_REQUEST_CONTROL_EVT, HAL_NFC_STATUS_OK);
742             return;
743         }
744 
745         nfc_hal_dm_send_pend_cmd();
746     }
747 }
748 
749 /*******************************************************************************
750 **
751 ** Function         nfc_hal_dm_set_nfc_wake
752 **
753 ** Description      Set NFC_WAKE line
754 **
755 ** Returns          void
756 **
757 *******************************************************************************/
nfc_hal_dm_set_nfc_wake(UINT8 cmd)758 void nfc_hal_dm_set_nfc_wake (UINT8 cmd)
759 {
760     NCI_TRACE_DEBUG1 ("nfc_hal_dm_set_nfc_wake () %s",
761                       (cmd == NFC_HAL_ASSERT_NFC_WAKE ? "ASSERT" : "DEASSERT"));
762 
763     /*
764     **  nfc_wake_active_mode             cmd              result of voltage on NFC_WAKE
765     **
766     **  NFC_HAL_LP_ACTIVE_LOW (0)    NFC_HAL_ASSERT_NFC_WAKE (0)    pull down NFC_WAKE (GND)
767     **  NFC_HAL_LP_ACTIVE_LOW (0)    NFC_HAL_DEASSERT_NFC_WAKE (1)  pull up NFC_WAKE (VCC)
768     **  NFC_HAL_LP_ACTIVE_HIGH (1)   NFC_HAL_ASSERT_NFC_WAKE (0)    pull up NFC_WAKE (VCC)
769     **  NFC_HAL_LP_ACTIVE_HIGH (1)   NFC_HAL_DEASSERT_NFC_WAKE (1)  pull down NFC_WAKE (GND)
770     */
771 
772     if (cmd == nfc_hal_cb.dev_cb.nfc_wake_active_mode)
773         UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_OFF); /* pull down NFC_WAKE */
774     else
775         UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_ON);  /* pull up NFC_WAKE */
776 }
777 
778 /*******************************************************************************
779 **
780 ** Function         nfc_hal_dm_power_mode_execute
781 **
782 ** Description      If snooze mode is enabled in full power mode,
783 **                     Assert NFC_WAKE before sending data
784 **                     Deassert NFC_WAKE when idle timer expires
785 **
786 ** Returns          TRUE if DH can send data to NFCC
787 **
788 *******************************************************************************/
nfc_hal_dm_power_mode_execute(tNFC_HAL_LP_EVT event)789 BOOLEAN nfc_hal_dm_power_mode_execute (tNFC_HAL_LP_EVT event)
790 {
791     BOOLEAN send_to_nfcc = FALSE;
792 
793     NCI_TRACE_DEBUG1 ("nfc_hal_dm_power_mode_execute () event = %d", event);
794 
795     if (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL)
796     {
797         if (nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE)
798         {
799             /* if any transport activity */
800             if (  (event == NFC_HAL_LP_TX_DATA_EVT)
801                 ||(event == NFC_HAL_LP_RX_DATA_EVT)  )
802             {
803                 /* if idle timer is not running */
804                 if (nfc_hal_cb.dev_cb.lp_timer.in_use == FALSE)
805                 {
806                     nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE);
807                 }
808 
809                 /* start or extend idle timer */
810                 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00,
811                                                 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
812             }
813             else if (event == NFC_HAL_LP_TIMEOUT_EVT)
814             {
815                 /* let NFCC go to snooze mode */
816                 nfc_hal_dm_set_nfc_wake (NFC_HAL_DEASSERT_NFC_WAKE);
817             }
818         }
819 
820         send_to_nfcc = TRUE;
821     }
822 
823     return (send_to_nfcc);
824 }
825 
826 /*******************************************************************************
827 **
828 ** Function         nci_brcm_lp_timeout_cback
829 **
830 ** Description      callback function for low power timeout
831 **
832 ** Returns          void
833 **
834 *******************************************************************************/
nci_brcm_lp_timeout_cback(void * p_tle)835 static void nci_brcm_lp_timeout_cback (void *p_tle)
836 {
837     NCI_TRACE_DEBUG0 ("nci_brcm_lp_timeout_cback ()");
838 
839     nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TIMEOUT_EVT);
840 }
841 
842 /*******************************************************************************
843 **
844 ** Function         nfc_hal_dm_pre_init_nfcc
845 **
846 ** Description      This function initializes Broadcom specific control blocks for
847 **                  NCI transport
848 **
849 ** Returns          void
850 **
851 *******************************************************************************/
nfc_hal_dm_pre_init_nfcc(void)852 void nfc_hal_dm_pre_init_nfcc (void)
853 {
854     NCI_TRACE_DEBUG0 ("nfc_hal_dm_pre_init_nfcc ()");
855 
856     if (nfc_post_reset_cb.dev_init_config.flags & NFC_HAL_DEV_INIT_FLAGS_SET_XTAL_FREQ)
857     {
858         nfc_hal_dm_set_xtal_freq_index ();
859     }
860     else
861     {
862         /* Send RESET CMD if application registered callback for device initialization */
863         nfc_hal_dm_send_reset_cmd ();
864     }
865 }
866 
867 /*******************************************************************************
868 **
869 ** Function         nfc_hal_dm_shutting_down_nfcc
870 **
871 ** Description      This function initializes Broadcom specific control blocks for
872 **                  NCI transport
873 **
874 ** Returns          void
875 **
876 *******************************************************************************/
nfc_hal_dm_shutting_down_nfcc(void)877 void nfc_hal_dm_shutting_down_nfcc (void)
878 {
879     NCI_TRACE_DEBUG0 ("nfc_hal_dm_shutting_down_nfcc ()");
880 
881     nfc_hal_cb.dev_cb.initializing_state = NFC_HAL_INIT_STATE_CLOSING;
882 
883     /* reset low power mode variables */
884     if (  (nfc_hal_cb.dev_cb.power_mode  == NFC_HAL_POWER_MODE_FULL)
885         &&(nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE)  )
886     {
887         nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE);
888     }
889 
890     nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE;
891     nfc_hal_cb.hci_cb.b_check_clear_all_pipe_cmd = FALSE;
892 
893     nfc_hal_cb.dev_cb.power_mode  = NFC_HAL_POWER_MODE_FULL;
894     nfc_hal_cb.dev_cb.snooze_mode = NFC_HAL_LP_SNOOZE_MODE_NONE;
895 
896     /* Stop all timers */
897     nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
898     nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer);
899     nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer);
900     nfc_hal_main_stop_quick_timer (&nfc_hal_cb.hci_cb.hci_timer);
901 }
902 
903 /*******************************************************************************
904 **
905 ** Function         nfc_hal_dm_init
906 **
907 ** Description      This function initializes Broadcom specific control blocks for
908 **                  NCI transport
909 **
910 ** Returns          void
911 **
912 *******************************************************************************/
nfc_hal_dm_init(void)913 void nfc_hal_dm_init (void)
914 {
915     NCI_TRACE_DEBUG0 ("nfc_hal_dm_init ()");
916 
917     nfc_hal_cb.dev_cb.lp_timer.p_cback = nci_brcm_lp_timeout_cback;
918 
919     nfc_hal_cb.ncit_cb.nci_wait_rsp_timer.p_cback = nfc_hal_nci_cmd_timeout_cback;
920 
921     nfc_hal_cb.hci_cb.hci_timer.p_cback = nfc_hal_hci_timeout_cback;
922 
923 }
924 
925 /*******************************************************************************
926 **
927 ** Function         HAL_NfcDevInitDone
928 **
929 ** Description      Notify that pre-initialization of NFCC is complete
930 **
931 ** Returns          void
932 **
933 *******************************************************************************/
HAL_NfcPreInitDone(tHAL_NFC_STATUS status)934 void HAL_NfcPreInitDone (tHAL_NFC_STATUS status)
935 {
936     NCI_TRACE_DEBUG1 ("HAL_NfcPreInitDone () status=%d", status);
937 
938     if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE)
939     {
940         NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
941 
942         nfc_hal_main_pre_init_done (status);
943     }
944 }
945 
946 /*******************************************************************************
947 **
948 ** Function         HAL_NfcReInit
949 **
950 ** Description      This function is called to send an RESET and GET_PATCH_VERSION
951 **                  command to NFCC.
952 **
953 **                  p_cback         - The callback function to receive the command
954 **                                    status
955 **
956 ** Note             This function should be called only during the HAL init process
957 **
958 ** Returns          HAL_NFC_STATUS_OK if successfully initiated
959 **                  HAL_NFC_STATUS_FAILED otherwise
960 **
961 *******************************************************************************/
HAL_NfcReInit(tNFC_HAL_NCI_CBACK * p_cback)962 tHAL_NFC_STATUS HAL_NfcReInit (tNFC_HAL_NCI_CBACK *p_cback)
963 {
964     tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED;
965     NCI_TRACE_DEBUG1 ("HAL_NfcReInit () init st=0x%x", nfc_hal_cb.dev_cb.initializing_state);
966     if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE)
967     {
968         /* Proceed with start up sequence: send CORE_RESET_CMD */
969         NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_RE_INIT);
970         nfc_hal_cb.p_reinit_cback = p_cback;
971 
972         nfc_hal_dm_send_nci_cmd (nfc_hal_dm_core_reset_cmd, NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET, NULL);
973         status = HAL_NFC_STATUS_OK;
974     }
975     return status;
976 }
977 
978 /*******************************************************************************
979 **
980 ** Function         nfc_hal_dm_set_snooze_mode_cback
981 **
982 ** Description      This is baud rate update complete callback.
983 **
984 ** Returns          void
985 **
986 *******************************************************************************/
nfc_hal_dm_set_snooze_mode_cback(tNFC_HAL_BTVSC_CPLT * pData)987 static void nfc_hal_dm_set_snooze_mode_cback (tNFC_HAL_BTVSC_CPLT *pData)
988 {
989     UINT8             status = pData->p_param_buf[0];
990     tHAL_NFC_STATUS   hal_status;
991     tHAL_NFC_STATUS_CBACK *p_cback;
992 
993     /* if it is completed */
994     if (status == HCI_SUCCESS)
995     {
996         /* update snooze mode */
997         nfc_hal_cb.dev_cb.snooze_mode = nfc_hal_cb.dev_cb.new_snooze_mode;
998 
999         nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE);
1000 
1001         if ( nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE)
1002         {
1003             /* start idle timer */
1004             nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00,
1005                                             ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
1006         }
1007         else
1008         {
1009             nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer);
1010         }
1011         hal_status = HAL_NFC_STATUS_OK;
1012     }
1013     else
1014     {
1015         hal_status = HAL_NFC_STATUS_FAILED;
1016     }
1017 
1018     if (nfc_hal_cb.dev_cb.p_prop_cback)
1019     {
1020         p_cback = nfc_hal_cb.dev_cb.p_prop_cback;
1021         nfc_hal_cb.dev_cb.p_prop_cback = NULL;
1022         (*p_cback) (hal_status);
1023     }
1024 }
1025 
1026 /*******************************************************************************
1027 **
1028 ** Function         HAL_NfcSetSnoozeMode
1029 **
1030 ** Description      Set snooze mode
1031 **                  snooze_mode
1032 **                      NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled
1033 **                      NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART
1034 **                      NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C
1035 **
1036 **                  idle_threshold_dh/idle_threshold_nfcc
1037 **                      Idle Threshold Host in 100ms unit
1038 **
1039 **                  nfc_wake_active_mode/dh_wake_active_mode
1040 **                      NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting
1041 **                      NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting
1042 **
1043 **                  p_snooze_cback
1044 **                      Notify status of operation
1045 **
1046 ** Returns          tHAL_NFC_STATUS
1047 **
1048 *******************************************************************************/
HAL_NfcSetSnoozeMode(UINT8 snooze_mode,UINT8 idle_threshold_dh,UINT8 idle_threshold_nfcc,UINT8 nfc_wake_active_mode,UINT8 dh_wake_active_mode,tHAL_NFC_STATUS_CBACK * p_snooze_cback)1049 tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode,
1050                                       UINT8 idle_threshold_dh,
1051                                       UINT8 idle_threshold_nfcc,
1052                                       UINT8 nfc_wake_active_mode,
1053                                       UINT8 dh_wake_active_mode,
1054                                       tHAL_NFC_STATUS_CBACK *p_snooze_cback)
1055 {
1056     UINT8 cmd[NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH];
1057     UINT8 *p;
1058 
1059     NCI_TRACE_API1 ("HAL_NfcSetSnoozeMode (): snooze_mode = %d", snooze_mode);
1060 
1061     nfc_hal_cb.dev_cb.new_snooze_mode      = snooze_mode;
1062     nfc_hal_cb.dev_cb.nfc_wake_active_mode = nfc_wake_active_mode;
1063     nfc_hal_cb.dev_cb.p_prop_cback         = p_snooze_cback;
1064 
1065     p = cmd;
1066 
1067     /* Add the HCI command */
1068     UINT16_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE);
1069     UINT8_TO_STREAM  (p, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH);
1070 
1071     memset (p, 0x00, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH);
1072 
1073     UINT8_TO_STREAM  (p, snooze_mode);          /* Sleep Mode               */
1074 
1075     UINT8_TO_STREAM  (p, idle_threshold_dh);    /* Idle Threshold Host      */
1076     UINT8_TO_STREAM  (p, idle_threshold_nfcc);  /* Idle Threshold HC        */
1077     UINT8_TO_STREAM  (p, nfc_wake_active_mode); /* BT Wake Active Mode      */
1078     UINT8_TO_STREAM  (p, dh_wake_active_mode);  /* Host Wake Active Mode    */
1079 
1080     nfc_hal_dm_send_bt_cmd (cmd,
1081                             NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH,
1082                             nfc_hal_dm_set_snooze_mode_cback);
1083     return (NCI_STATUS_OK);
1084 }
1085 
1086 
1087 
1088 
1089 
1090 
1091 
1092 
1093