xref: /aosp_15_r20/system/nfc/src/nfa/sys/nfa_sys_cback.cc (revision 7eba2f3b06c51ae21384f6a4f14577b668a869b3)
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/logging.h>
25 #include <android-base/stringprintf.h>
26 
27 #include "nfa_sys.h"
28 #include "nfa_sys_int.h"
29 
30 using android::base::StringPrintf;
31 
32 /*******************************************************************************
33 **
34 ** Function         nfa_sys_cback_reg_enable_complete
35 **
36 ** Description      Called to register an initialization complete callback
37 **                  function
38 **
39 ** Returns          void
40 **
41 *******************************************************************************/
nfa_sys_cback_reg_enable_complete(tNFA_SYS_ENABLE_CBACK * p_cback)42 void nfa_sys_cback_reg_enable_complete(tNFA_SYS_ENABLE_CBACK* p_cback) {
43   nfa_sys_cb.p_enable_cback = p_cback;
44   nfa_sys_cb.enable_cplt_flags = 0;
45 }
46 
47 /*******************************************************************************
48 **
49 ** Function         nfa_sys_cback_notify_enable_complete
50 **
51 ** Description      Called by other NFA subsystems to notify initialization is
52 **                  complete
53 **
54 ** Returns          void
55 **
56 *******************************************************************************/
nfa_sys_cback_notify_enable_complete(uint8_t id)57 void nfa_sys_cback_notify_enable_complete(uint8_t id) {
58   nfa_sys_cb.enable_cplt_flags |= (0x0001 << id);
59 
60   LOG(VERBOSE) << StringPrintf("enable_cplt_flags=0x%x, enable_cplt_mask=0x%x",
61                              nfa_sys_cb.enable_cplt_flags,
62                              nfa_sys_cb.enable_cplt_mask);
63 
64   if ((nfa_sys_cb.enable_cplt_flags == nfa_sys_cb.enable_cplt_mask) &&
65       (nfa_sys_cb.p_enable_cback)) {
66     nfa_sys_cb.p_enable_cback();
67     nfa_sys_cb.p_enable_cback = nullptr;
68   }
69 }
70 
71 /*******************************************************************************
72 **
73 ** Function         nfa_sys_cback_notify_partial_enable_complete
74 **
75 ** Description      Called by other NFA SYS sub system to notify
76 **                  NFC initialisation  is done .
77 **
78 ** Returns          void
79 **
80 *******************************************************************************/
nfa_sys_cback_notify_partial_enable_complete(uint8_t id)81 void nfa_sys_cback_notify_partial_enable_complete(uint8_t id) {
82   if (nfa_sys_cb.p_enable_cback && id == NFA_ID_SYS) {
83     nfa_sys_cb.p_enable_cback();
84     nfa_sys_cb.p_enable_cback = nullptr;
85   }
86 }
87 
88 /*******************************************************************************
89 **
90 ** Function         nfa_sys_cback_reg_nfcc_power_mode_proc_complete
91 **
92 ** Description      Called to register a callback function for complete of
93 **                  processing NFCC power mode change from NFA sub-systems
94 **
95 ** Returns          void
96 **
97 *******************************************************************************/
nfa_sys_cback_reg_nfcc_power_mode_proc_complete(tNFA_SYS_PROC_NFCC_PWR_MODE_CMPL * p_cback)98 void nfa_sys_cback_reg_nfcc_power_mode_proc_complete(
99     tNFA_SYS_PROC_NFCC_PWR_MODE_CMPL* p_cback) {
100   nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback = p_cback;
101   nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags = 0;
102 }
103 
104 /*******************************************************************************
105 **
106 ** Function         nfa_sys_cback_notify_nfcc_power_mode_proc_complete
107 **
108 ** Description      Called by other NFA subsystems to notify processing NFCC
109 **                  power mode is complete
110 **
111 ** Returns          void
112 **
113 *******************************************************************************/
nfa_sys_cback_notify_nfcc_power_mode_proc_complete(uint8_t id)114 void nfa_sys_cback_notify_nfcc_power_mode_proc_complete(uint8_t id) {
115   nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags |= (0x0001 << id);
116 
117   LOG(VERBOSE) << StringPrintf("flags=0x%x, mask=0x%x",
118                              nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags,
119                              nfa_sys_cb.proc_nfcc_pwr_mode_cplt_mask);
120 
121   /* except SYS */
122   if ((nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags ==
123        nfa_sys_cb.proc_nfcc_pwr_mode_cplt_mask) &&
124       (nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback)) {
125     nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback();
126     nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback = nullptr;
127   }
128 }
129