1. Overview
Gki to Library libbt-brcm_gki.so (Static Lib?) In the form provided to bluedroid use
This layer is an adaptation layer that is adaptable to OS-related processes, memory-related management, and can also be used to pass messages between threads
The unified management of process is realized mainly through variable GKI_CB
typedef struct {pthread_mutex_t Gki_mutex;
pthread_t Thread_id[gki_max_tasks];
pthread_mutex_t Thread_evt_mutex[gki_max_tasks];
pthread_cond_t Thread_evt_cond[gki_max_tasks];
pthread_mutex_t Thread_timeout_mutex[gki_max_tasks];
pthread_cond_t Thread_timeout_cond[gki_max_tasks]; int no_timer_suspend;
/* 1:no suspend, 0 stop calling Gki_timer_update () */pthread_mutex_t Gki_timer_mutex;
pthread_cond_t Gki_timer_cond;
#if (Gki_debug = = TRUE) pthread_mutex_t Gki_trace_mutex;
#endif} Tgki_os;
typedef struct {... UINT8 *osstack[gki_max_tasks]; /* Pointer to beginning of stacks */UINT16 osstacksize[gki_max_tasks]; /* Stack size available to each task */INT8 *ostname[gki_max_tasks]; /* Name of the task */UINT8 osrdytbl[gki_max_tasks]; /* Current state of the task */UINT16 oswaitevt[gki_max_tasks]; /* Events that hasTo is processed by the task */UINT16 oswaitforevt[gki_max_tasks]; /* Events The task is waiting for*/UINT32 osticks; /* System ticks from Start */UINT32 osidlecnt; /* Idle counter */INT16 osdisablenesting; /* counter to keep track of interrupt disable nesting */INT16 oslocknesting; /* counter to keep track of sched lock nesting */INT16 osintnesting; /* counter to keep track of interrupt nesting */* Timer Related variables */INT32 ostickstilexp; /* Number of ticks till next timer expires */#if (defined (gki_delay_stop_sys_tick) && (Gki_delay_stop_sys_tick &G T 0)) UINT32 ostickstilstop; /* Inactivity delay timer; OS Ticks till stopping system tick */#endif INT32 osnumorigticks; /* Number of ticks between last timer expiration to the next one */INT32 OSWAITTMR [gki_max_tasks]; /* Ticks the TASK has-to-wait, for specific events */.../* Buffer related variables */buffer_hdr_t *ostaskqfirst[g Ki_max_tasks][num_task_mbox]; /* Array of pointers to the first event in the task mailbox */buffer_hdr_t *ostaskqlast [gki_max_tasks][num_task_m BOX];
/* Array of pointers to the last event in the task mailbox *//* Define the buffer pool management variables */
free_queue_t Freeq[gki_num_total_buf_pools];
UINT16 Pool_buf_size[gki_num_total_buf_pools];
UINT16 Pool_max_count[gki_num_total_buf_pools];
UINT16 Pool_additions[gki_num_total_buf_pools]; /* Define The buffer pool start addresses */UINT8 *pool_start[gki_num_total_buf_pools]; /* Array of pointers to the start of each buffer pool */UINT8 *pool_end[gki_num_total_buf_pools]; /* Array of pointers to the end of each buffer pool */UINT16 pool_size[gki_num_total_buf_pools]; /* Actual size of the buffers in a pool */* Define the BUffer Pool access Control variables */void *p_user_mempool; /* User O/S Memory pool */UINT16 pool_access_mask; /* Bits is set if the corresponding buffer pool is a restricted pool */UINT8 Pool_list[gki_num_total_buf_pools ]; /* Buffer pools arranged in the order of size */UINT8 curr_total_no_of_pools; /* Number of fixed buf pools + current number of dynamic pools */BOOLEAN timer_nesting; /* flag to prevent timer interrupt nesting */* Time queue Arrays */Timer_list_q *timer_queues[gki_max_timer_qu
Eues];
/* System Tick callback */System_tick_cback *P_TICK_CB; BOOLEAN system_tick_running; /* TRUE If system tick is running. Valid only if P_TICK_CB are not NULL */#if (Gki_debug = = TRUE) UINT16 exceptioncnt; /* Number of GKI exceptions that has happened */exception_t Exception[gki_max_excePtion];
#endif} TGKI_COM_CB;
typedef struct {Tgki_os OS;
TGKI_COM_CB COM;
} TGKI_CB; TGKI_CB GKI_CB
2. Threads
2.1 Main Functions
-Gki_init () Initialize variable GKI_CB
-Gki_create_task () Create thread
-Gki_destroy_task () Destroy thread
-Gki_run () Time-dependent execution function, currently not known what effect 2.2 features
Threading-related features using the Pthread library
Gki Management of three threads
#define BTU_TASK 0
#define BTIF_TASK 1
#define A2DP_MEDIA_TASK 2
3. Events
3.1 main Functions
-gki_wait () wait for the event to occur
-Gki_send_event () sends an event to the specified process
-GKI_SEND_MSG () sends buffer to the specified process
-Gki_read_mbox () read the buffer 3.2 function from the mailbox
Tgki_cb.os.thread_evt_mutex[] The condition variable of the mutex
tgki_cb.os.thread_evt_cond[] event for the event
tgki_cb.com.oswaitevt[ ] represents the event of the current process
tgki_cb.com.ostaskqfirst[][] The first event in the mailbox of the process
tgki_cb.com.ostaskqlast[][] point to the last event in the mailbox of a process
First we want to understand the use of POSIX mutexes and condition variables
Tip: It is worth mentioning that the pthread_cond_wait () function unlocks the mutex in the parameter after it has been invoked until it is awakened and re-locks the mutex
The principle of the Gki event
The event/mbox event is sent through the gki_send_event ()/gki_send_msg (), and the receiving thread can detect the occurrence of events through gki_wait () and handle different events differently
For mbox events, you need to loop the call Gki_read_mbox () to get the mbox Buffer
Tip: Events can be sent to this thread in addition to other threads
Each thread has four mailbox
There are 16 events (EVT:0~15)
-4 retention events for receiving evt:0~3 of mailbox messages
-4 Retention events for timeout evt:4~7
-8 common events for all apps using evt:8~15
can be obtained by Event_mask (EVT) in turn