• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2010-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  *  Registration/deregistration functions for inter-module callbacks
22  *
23  ******************************************************************************/
24 #include <android-base/stringprintf.h>
25 #include <base/logging.h>
26 
27 #include "nfa_sys.h"
28 #include "nfa_sys_int.h"
29 
30 using android::base::StringPrintf;
31 
32 extern bool nfc_debug_enabled;
33 
34 /*******************************************************************************
35 **
36 ** Function         nfa_sys_cback_reg_enable_complete
37 **
38 ** Description      Called to register an initialization complete callback
39 **                  function
40 **
41 ** Returns          void
42 **
43 *******************************************************************************/
nfa_sys_cback_reg_enable_complete(tNFA_SYS_ENABLE_CBACK * p_cback)44 void nfa_sys_cback_reg_enable_complete(tNFA_SYS_ENABLE_CBACK* p_cback) {
45   nfa_sys_cb.p_enable_cback = p_cback;
46   nfa_sys_cb.enable_cplt_flags = 0;
47 }
48 
49 /*******************************************************************************
50 **
51 ** Function         nfa_sys_cback_notify_enable_complete
52 **
53 ** Description      Called by other NFA subsystems to notify initialization is
54 **                  complete
55 **
56 ** Returns          void
57 **
58 *******************************************************************************/
nfa_sys_cback_notify_enable_complete(uint8_t id)59 void nfa_sys_cback_notify_enable_complete(uint8_t id) {
60   nfa_sys_cb.enable_cplt_flags |= (0x0001 << id);
61 
62   DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
63       "enable_cplt_flags=0x%x, enable_cplt_mask=0x%x",
64       nfa_sys_cb.enable_cplt_flags, nfa_sys_cb.enable_cplt_mask);
65 
66   if ((nfa_sys_cb.enable_cplt_flags == nfa_sys_cb.enable_cplt_mask) &&
67       (nfa_sys_cb.p_enable_cback)) {
68     nfa_sys_cb.p_enable_cback();
69     nfa_sys_cb.p_enable_cback = nullptr;
70   }
71 }
72 
73 /*******************************************************************************
74 **
75 ** Function         nfa_sys_cback_reg_nfcc_power_mode_proc_complete
76 **
77 ** Description      Called to register a callback function for complete of
78 **                  processing NFCC power mode change from NFA sub-systems
79 **
80 ** Returns          void
81 **
82 *******************************************************************************/
nfa_sys_cback_reg_nfcc_power_mode_proc_complete(tNFA_SYS_PROC_NFCC_PWR_MODE_CMPL * p_cback)83 void nfa_sys_cback_reg_nfcc_power_mode_proc_complete(
84     tNFA_SYS_PROC_NFCC_PWR_MODE_CMPL* p_cback) {
85   nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback = p_cback;
86   nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags = 0;
87 }
88 
89 /*******************************************************************************
90 **
91 ** Function         nfa_sys_cback_notify_nfcc_power_mode_proc_complete
92 **
93 ** Description      Called by other NFA subsystems to notify processing NFCC
94 **                  power mode is complete
95 **
96 ** Returns          void
97 **
98 *******************************************************************************/
nfa_sys_cback_notify_nfcc_power_mode_proc_complete(uint8_t id)99 void nfa_sys_cback_notify_nfcc_power_mode_proc_complete(uint8_t id) {
100   nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags |= (0x0001 << id);
101 
102   DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
103       "flags=0x%x, mask=0x%x", nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags,
104       nfa_sys_cb.proc_nfcc_pwr_mode_cplt_mask);
105 
106   /* except SYS */
107   if ((nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags ==
108        nfa_sys_cb.proc_nfcc_pwr_mode_cplt_mask) &&
109       (nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback)) {
110     nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback();
111     nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback = nullptr;
112   }
113 }
114