prf_disp_disconnect_reg(prf_dispatch_disconnect)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

prf_disp_disconnect_reg(prf_dispatch_disconnect)

416 Views
leaflee
Contributor III

I am developing a project on QN902x and on IAR ARM 8.11.3 platform.

There are some statements in the file of app_main.c:

...

static void prf_register(void)
{
prf_init_reg(prf_init);

prf_disp_disconnect_reg(prf_dispatch_disconnect);
}

...

"prf_disp_disconnect_reg()" should be a MACRO, and I trace it to the file of ble.h:

...

typedef void (*prf_disp_disconnect_cb)(uint8_t status, uint8_t reason, uint16_t conhdl, uint8_t idx);
typedef void (*p_prf_disp_disconnect_reg)(prf_disp_disconnect_cb app_func);
#define prf_disp_disconnect_reg ((p_prf_disp_disconnect_reg)(_prf_disp_disconnect_reg))

...

I think the statement of "prf_disp_disconnect_reg(prf_dispatch_disconnect);" should run the function in the file of prf_utils.c:

...

void prf_dispatch_disconnect(uint8_t status, uint8_t reason, uint16_t conhdl, uint8_t idx)
{

...

I have 2 questions:

1. How to translate "prf_disp_disconnect_reg()" to "prf_dispatch_disconnect()"

2. "prf_disp_disconnect_reg(prf_dispatch_disconnect);" has no aguments of "uint8_t status, uint8_t reason, uint16_t conhdl, uint8_t idx". If the MACRO run "prf_dispatch_disconnect(status, reason, conhdl, idx)", where are those 4 arguments from?

Labels (1)
0 Kudos
1 Reply

301 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Leag Lee,

1. How to translate "prf_disp_disconnect_reg()" to "prf_dispatch_disconnect()"

The typedef is doing the cast for the funtion pointer.

typedef void (*prf_disp_disconnect_cb)(uint8_t status, uint8_t reason, uint16_t conhdl, uint8_t idx);
typedef void (*p_prf_disp_disconnect_reg)(prf_disp_disconnect_cb app_func);
#define prf_disp_disconnect_reg ((p_prf_disp_disconnect_reg)(_prf_disp_disconnect_reg))

2. "prf_disp_disconnect_reg(prf_dispatch_disconnect);" has no aguments of "uint8_t status, uint8_t reason, uint16_t conhdl, uint8_t idx". If the MACRO run "prf_dispatch_disconnect(status, reason, conhdl, idx)", where are those 4 arguments from?

The BLE stack is calling this function in the scheduler, prf_disp_disconnect_reg receives the function pointer.

Mario

0 Kudos