WXK
2025-02-05 961c1174bbf1aaae5fa2f672806ed4eaf2f917be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*****************************************************************************
 * @file     pan_ble_stack.h
 * @version  V1.00
 * $Revision: 1$
 * $Date: 20/04/14 14:34 $ 
 * @brief    PN108 BLE Stack header file
 *
 * @note
 * Copyright (C) 2020 Panchip Technology Corp. All rights reserved.
 *****************************************************************************/
 
#ifndef __PAN_BLE_STACK_H__
#define __PAN_BLE_STACK_H__
 
/* Includes -----------------------------------------------------------------*/
#include <stdint.h>
#ifndef NIMBLE_SPARK_SUP
#include "stack/controller/lhci_api.h"
#endif
 
#include "stack/ant/ant_api.h"
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* Exported  Defines --------------------------------------------------------*/
enum sleep_clock_source_t {
    SLEEP_CLOCK_SOURCE_RCL      = 0,
    SLEEP_CLOCK_SOURCE_XTL      = 1,
    SLEEP_CLOCK_SOURCE_ACT32K   = 2, // sleep disabled
};
 
enum sleep_clock_accuracy_t {
    SLEEP_CLOCK_ACCUARCY_500PPM = 0,
    SLEEP_CLOCK_ACCUARCY_250PPM = 1,
    SLEEP_CLOCK_ACCUARCY_150PPM = 2,
    SLEEP_CLOCK_ACCUARCY_100PPM = 3,
    SLEEP_CLOCK_ACCUARCY_75PPM  = 4,
    SLEEP_CLOCK_ACCUARCY_50PPM  = 5,
    SLEEP_CLOCK_ACCUARCY_30PPM  = 6,
    SLEEP_CLOCK_ACCUARCY_20PPM  = 7,
};
 
typedef struct {
    uint8_t    sleep_clock_source;
    uint16_t   sleep_clock_accuracy;
    uint8_t    max_num_of_states;
    int8_t     tx_power;
 
    void *     (*pf_mem_init)(uint32_t size);
    
    // NOT Release
    uint8_t     link_layer_debug;
    struct {
        uint8_t os_drift_time;
        uint8_t reg_time;
    } timings;
 
    uint8_t     agc_cfg_mode;
 
    uint8_t     wlNum;
    uint8_t     rlNum;
    uint8_t     mstMargin;
    uint8_t     numMoreData;
    uint8_t     maxMst;
    uint8_t     maxSlv;
    uint8_t     maxAclLen;
    uint8_t     numRxBufs;
    uint8_t     numTxBufs;
    uint16_t    llEncTime;
 
    uint8_t     pmEnable;
    uint8_t     connCreateTo;
    uint8_t     authPyldTimeoutEn;
 
    uint8_t     numAdvSet;
    uint16_t    extAdvDataLen;
    uint16_t    extScanRspDataLen;
    uint8_t     advMargin;
} pan_ble_cfg;
 
typedef struct {
    uint8_t   major;
    uint8_t   minor;
    uint16_t  patch;
    uint32_t  commit_id;
} pan_ble_version_t;
 
typedef int (*PanMdcSemphrGiveCback_t)(void);
typedef void (*pan_conn_evt_close_cb_t)(uint16_t connHandle, uint8_t state);
typedef void (*pan_app_irq_handler_cb_t)(void);
typedef void (*pan_32k_clk_track_start_cb_t)(uint32_t clk_32k_cnt);
typedef uint32_t (*pan_32k_clk_track_value_get_cb_t)(void);
 
#define PAN_BLE_STACK_API __attribute__((visibility ("default")))
 
typedef void (*pan_ble_hci_evt_cbk)(uint8_t *p_evt, uint16_t evt_len);
typedef void (*pan_ble_hci_acl_cbk)(uint8_t *p_acl, uint16_t acl_len);
 
/* Exported functions -------------------------------------------------------*/
 
 
/**
 * @brief PAN BLE Stack Initialization.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_init(const pan_ble_cfg *cfg);
 
/**
 * @brief PAN BLE Stack De-initialize.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_uninit(void);
 
/**
 * @brief PAN BLE CFG Update.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_cfg_set(uint8_t phy_cfg);
 
/**
 * @brief Process the PAN BLE before sleep.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_sleep(uint32_t level);
 
/**
 * @brief Process the PAN BLE after wakeup.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_wakeup(uint32_t source);
 
/**
 * @brief Process the PAN BLE interrupt.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_irq(void);
 
/**
 * @brief Process the PAN BLE Stack.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_handle(void);
 
/**
 * @brief HCI Initialization.
 *
 * @param p_evt_cbk Pointer to the callback which process the 
 *      HCI event (exclude command status or command complete) 
 *      packet to the host.
 * @param p_acl_cbk Pointer to the callback which process the 
 *      HCI ACL packet to the host.
 * 
 * @return N/A
 */
PAN_BLE_STACK_API void pan_ble_hci_init(pan_ble_hci_evt_cbk p_evt_cbk,
                              pan_ble_hci_acl_cbk p_acl_cbk);
 
/**
 * @brief Process the HCI command packet from the host.
 *
 * @param p_cmd Pointer to the HCI command packet.
 * @param cmd_len Length of the HCI command packet.
 * @param p_evt Pointer to the HCI event (command status or command 
 *      complete) packet to host.
 * @param p_evt_len Pointer to the Length of the HCI event (command 
 *      status or command complete).
 *
 * Sample HCI_Reset_Command:
 *      input p_cmd "\x03\x0C\x00", cmd_len 3, 
 *      output p_evt "\x0E\x04\x01\x03\x0C\x00", *p_evt_len 6
 * 
 * @return Command status to be sent to the Host, 
 *      see @ble_error_codes.h.
 */
PAN_BLE_STACK_API uint32_t pan_ble_hci_cmd_handle(uint8_t  *p_cmd,
                                        uint16_t  cmd_len,
                                        uint8_t  *p_evt,
                                        uint16_t *p_evt_len);
/**
 * @brief Process the HCI ACL packet from the host.
 *
 * @param p_data Pointer to the HCI ACL packet.
 * @param data_len Length of the HCI ACL packet.
 * 
 * Sample HCI_ACL_Data:
 *      input p_data "00 00 01 00 00", data_len 5
 *      means LLID: Start, Payload Length: 1, Payload: "\x00"
 * 
 * @return Command status to be sent to the Host, 
 *      see @ble_error_codes.h.
 */
PAN_BLE_STACK_API uint32_t pan_ble_hci_acl_handle(uint8_t *p_data,
                                        uint16_t data_len);
 
//[GQ] add
PAN_BLE_STACK_API uint32_t pan_get_ll_idle_time(void);
PAN_BLE_STACK_API void pan_ll_pm_post_handler(void);
PAN_BLE_STACK_API void pan_update_stimer(void);
PAN_BLE_STACK_API void pan_ll_register_semphr_cback(PanMdcSemphrGiveCback_t func);
 
//ANT API
void pan_ant_init(void);
int  pan_ant_create(ab_event_node_t *pParam);
void pan_ant_delete(int id);
 
//misc API
extern void  pan_req_new_tx_power(int8_t txPower);
extern void  pan_misc_register_print(void *print);
extern void *pan_misc_malloc_ll_data_ram(uint32_t size);
extern void  pan_misc_upd_local_sca(uint16_t localSca);
extern void  pan_misc_set_bd_addr(uint8_t addr[6]);
extern void  pan_misc_get_bd_addr(uint8_t addr[6]);
extern uint32_t pan_misc_get_cur_sys_tick(void);
extern void  pan_misc_register_conn_evt_close_cb(pan_conn_evt_close_cb_t func);
extern void  pan_misc_register_app_irq_handler_cb(pan_app_irq_handler_cb_t func);
extern void  pan_misc_register_32k_track_cb(pan_32k_clk_track_start_cb_t clk_32k_track_start,
                                            pan_32k_clk_track_value_get_cb_t clk_32k_track_value_get);
extern void pan_misc_set_ll_rx_time_enable(uint8_t en);
 
 
PAN_BLE_STACK_API const pan_ble_version_t *pan_ble_get_version(void);
 
uint8_t event_can_handle(uint8_t hw_done);
void abstract_ll_event_register(void *event_node);
uint32_t abstract_ll_event_unregister(uint32_t event_handle);
void abstract_hw_completed(void *ptr_env_done);
uint8_t ab_event_on_air(void);
 
void event_time_init(void *p_event_time);
 
#ifdef __cplusplus
}
#endif
 
#endif /* __PAN_BLE_STACK_H__ */