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