• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "nfc_task_helpers.h"
2 
3 #include <android-base/logging.h>
4 
5 #include "gki.h"
6 #include "nfa_hci_int.h"
7 #include "nfa_sys.h"
8 #include "nfc_int.h"
9 
10 void nfa_hci_check_api_requests(void);
11 void nfc_process_timer_evt(void);
12 
nfc_process_nci_messages()13 bool nfc_process_nci_messages() {
14   bool found_work = false;
15   NFC_HDR* p_msg;
16   bool free_buf;
17 
18   /* Process all incoming NCI messages */
19   while ((p_msg = (NFC_HDR*)GKI_read_mbox(NFC_MBOX_ID)) != nullptr) {
20     found_work = true;
21     free_buf = true;
22 
23     /* Determine the input message type. */
24     switch (p_msg->event & NFC_EVT_MASK) {
25       case BT_EVT_TO_NFC_NCI:
26         free_buf = nfc_ncif_process_event(p_msg);
27         break;
28 
29       case BT_EVT_TO_START_TIMER:
30         /* Start nfc_task 1-sec resolution timer */
31         GKI_start_timer(NFC_TIMER_ID, GKI_SECS_TO_TICKS(1), true);
32         break;
33 
34       case BT_EVT_TO_START_QUICK_TIMER:
35         /* Quick-timer is required for LLCP */
36         GKI_start_timer(NFC_QUICK_TIMER_ID,
37                         ((GKI_SECS_TO_TICKS(1) / QUICK_TIMER_TICKS_PER_SEC)),
38                         true);
39         break;
40 
41       case BT_EVT_TO_NFC_MSGS:
42         nfc_main_handle_hal_evt((tNFC_HAL_EVT_MSG*)p_msg);
43         break;
44 
45       default:
46         // Unknown message type
47         CHECK(false);
48         break;
49     }
50 
51     if (free_buf) {
52       GKI_freebuf(p_msg);
53     }
54   }
55   return found_work;
56 }
57 
nfc_process_nfa_messages()58 void nfc_process_nfa_messages() {
59   NFC_HDR* p_msg;
60   while ((p_msg = (NFC_HDR*)GKI_read_mbox(NFA_MBOX_ID)) != nullptr) {
61     nfa_sys_event(p_msg);
62   }
63 }
64 
DoAllTasks(bool do_timers)65 void DoAllTasks(bool do_timers) {
66 start:
67   bool found_work = false;
68   while (nfc_process_nci_messages()) {
69     found_work = true;
70   }
71 
72   nfc_process_nfa_messages();
73 
74   if (do_timers) {
75     nfc_process_timer_evt();
76     nfc_process_quick_timer_evt();
77   }
78 
79   nfa_hci_check_api_requests();
80 
81   nfa_sys_timer_update();
82 
83   if (nfa_hci_cb.hci_state == NFA_HCI_STATE_IDLE &&
84       !GKI_queue_is_empty(&nfa_hci_cb.hci_api_q)) {
85     found_work = true;
86   }
87 
88   if (found_work) {
89     goto start;
90   }
91 }
92