DA14580 --- 广播开始分析

1.目的

     分析代码程序是如何执行开启广播的

2.分析


3.平台:

协议栈版本:DA1458x_SDK

编译软件:keil 4.72

硬件平台:开发板

例子:DA1458x_SDK5.0.3\DA1458x_SDK5.0.3\DA1458x_SDK\5.0.3\projects\target_apps\ble_examples\prox_reporter\Keil_4

4.步骤

    首先看函数


 

void app_init(void)
{
    // Reset the environment
    memset(&app_env[0], 0, sizeof(app_env));

    bool security_default_val = true;

    uint8_t length = NVDS_LEN_SECURITY_ENABLE;
    // Get the security enable from the storage
    if (nvds_get(NVDS_TAG_SECURITY_ENABLE, &length, (uint8_t *)&security_default_val) != NVDS_OK)
    {
        // Set true by default (several profiles requires security)
        security_default_val = true;
    }

    for (uint8_t i = 0; i< APP_EASY_MAX_ACTIVE_CONNECTION; i++)
    {
        // Set true by default (several profiles requires security)
        app_env[i].sec_en = true;
    }

    // Create APP task
    ke_task_create(TASK_APP, &TASK_DESC_APP);

    // Initialize Task state
    ke_state_set(TASK_APP, APP_DISABLED);
}
这里看 ke_task_create(TASK_APP, &TASK_DESC_APP);  查看 TASK_DESC_APP

/// Application Task Descriptor
static const struct ke_task_desc TASK_DESC_APP = {NULL,
                                                  &app_default_handler,
                                                  app_state,
                                                  APP_STATE_MAX,
                                                  APP_IDX_MAX};

查看app_default_handler  

/* Default State handlers definition. */
const struct ke_msg_handler app_default_state[] =
{   
    {KE_MSG_DEFAULT_HANDLER,                (ke_msg_func_t)app_entry_point_handler},
};

/* Specifies the message handlers that are common to all states. */
const struct ke_state_handler app_default_handler = KE_STATE_HANDLER(app_default_state);

可以看到app_default_state是一个结构体 

查看 app_entry_point_handler可以看到

                                         
const process_event_func_t app_process_handlers[] = {

#if (!EXCLUDE_DLG_GAP)
     (process_event_func_t) app_gap_process_handler,
#endif

#if (!EXCLUDE_DLG_TIMER)
    (process_event_func_t) app_timer_api_process_handler,
#endif

#if (!EXCLUDE_DLG_MSG)
    (process_event_func_t) app_msg_utils_api_process_handler,
#endif

#if ((BLE_APP_SEC) && (!EXCLUDE_DLG_SEC))
    (process_event_func_t) app_sec_process_handler,
#endif

#if ((BLE_DIS_SERVER) && (!EXCLUDE_DLG_DISS))
    (process_event_func_t) app_dis_process_handler,
#endif

#if ((BLE_PROX_REPORTER) && (!EXCLUDE_DLG_PROXR))
    (process_event_func_t) app_proxr_process_handler,
#endif
#if ((BLE_BAS_SERVER) && (!EXCLUDE_DLG_BASS))
    (process_event_func_t) app_bass_process_handler,
#endif
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
#if (((BLE_FINDME_TARGET)&& (!EXCLUDE_DLG_FINDT)) || ((BLE_FINDME_LOCATOR)&& (!EXCLUDE_FINDL)))  
    (process_event_func_t) app_findme_process_handler,
#endif //BLE_FINDME_LOCATOR

#if ((BLE_SPOTA_RECEIVER) && (!EXCLUDE_DLG_SPOTAR))
    (process_event_func_t) app_spota_process_handler,
#endif

#if ((BLE_CUSTOM1_SERVER) && (!EXCLUDE_DLG_CUSTS1))
    (process_event_func_t) app_custs1_process_handler,
#endif

};
int app_entry_point_handler (ke_msg_id_t const msgid,
                                         void const *param,
                                         ke_task_id_t const dest_id,
                                         ke_task_id_t const src_id)
{
    int i=0;
    enum ke_msg_status_tag process_msg_handling_result;
    
    while (i<sizeof(app_process_handlers)/sizeof(process_event_func_t))
    {
        ASSERT_ERR(app_process_handlers[i]);        if (app_process_handlers[i](msgid,param,dest_id,src_id, &process_msg_handling_result)==PR_EVENT_HANDLED)
               return (process_msg_handling_result);
         i++;
    }

    //user cannot do anything else than consume the message
    if (app_process_catch_rest_cb!=NULL)
    {
        app_process_catch_rest_cb(msgid,param,dest_id,src_id);
    }
    
    return (KE_MSG_CONSUMED);
    
};
  while (i<sizeof(app_process_handlers)/sizeof(process_event_func_t))
    {
        ASSERT_ERR(app_process_handlers[i]);
         if (app_process_handlers[i](msgid,param,dest_id,src_id, &process_msg_handling_result)==PR_EVENT_HANDLED)
               return (process_msg_handling_result);
         i++;
    }
这里把app_process_handlers结构体里面的函数都执行了一边。

来分析下

  #if (!EXCLUDE_DLG_GAP)
     (process_event_func_t) app_gap_process_handler,
#endif

这里是GAP层的初始化

  

static const struct ke_msg_handler app_gap_process_handlers[]=
{
    {GAPM_DEVICE_READY_IND,                 (ke_msg_func_t)gapm_device_ready_ind_handler},
    {GAPM_CMP_EVT,                          (ke_msg_func_t)gapm_cmp_evt_handler},
    {GAPC_CMP_EVT,                          (ke_msg_func_t)gapc_cmp_evt_handler},
    {GAPC_CONNECTION_REQ_IND,               (ke_msg_func_t)gapc_connection_req_ind_handler},
    {GAPC_DISCONNECT_IND,                   (ke_msg_func_t)gapc_disconnect_ind_handler},
    {APP_MODULE_INIT_CMP_EVT,               (ke_msg_func_t)app_module_init_cmp_evt_handler},
    {GAPM_ADV_REPORT_IND,                   (ke_msg_func_t)gapm_adv_report_ind_handler},   
};
enum process_event_response app_gap_process_handler (ke_msg_id_t const msgid,
                                         void const *param,
                                         ke_task_id_t const dest_id,
                                         ke_task_id_t const src_id, 
                                         enum ke_msg_status_tag *msg_ret)
{
    return (app_std_process_event(msgid, param,src_id,dest_id,msg_ret, app_gap_process_handlers,
                                         sizeof(app_gap_process_handlers)/sizeof(struct ke_msg_handler)));
}

这里对应的事件会执行对应的函数,比如 gapm_cmp_evt_handler事件

int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation)
    {
        // reset completed
        case GAPM_RESET:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
                // set device configuration
                app_easy_gap_dev_configure ();
            }int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation)
    {
        // reset completed
        case GAPM_RESET:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
                // set device configuration
                app_easy_gap_dev_configure ();
            }int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation)
    {
        // reset completed
        case GAPM_RESET:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
                // set device configuration
                app_easy_gap_dev_configure ();
            }      }
        break;

        // device configuration updated
        case GAPM_SET_DEV_CONFIG:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
                EXECUTE_CALLBACK_VOID(app_on_set_dev_config_complete);
            }
        }        break;

        // Advertising finished
        case GAPM_ADV_UNDIRECT:
        {
           EXECUTE_CALLBACK_PARAM(app_on_adv_undirect_complete, param->status); 
        }
        break;
        
        // Directed advertising finished
        case GAPM_ADV_DIRECT:
        {
            EXECUTE_CALLBACK_PARAM(app_on_adv_direct_complete, param->status);
        }
      break;

        case GAPM_SCAN_ACTIVE:
        case GAPM_SCAN_PASSIVE:
        {
            EXECUTE_CALLBACK_VOID(app_on_scanning_completed);
        }
        break;
        
        case GAPM_CONNECTION_DIRECT:            if (param->status == GAP_ERR_CANCELED)
            {
                EXECUTE_CALLBACK_VOID(app_on_connect_failed);
            }
        break;

        case GAPM_CANCEL:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            if (app_process_catch_rest_cb!=NULL)
            {               app_process_catch_rest_cb(msgid,param,dest_id,src_id);
            }
         }
        break;
         
        default:
            if (app_process_catch_rest_cb!=NULL)
            {
                app_process_catch_rest_cb(msgid,param,dest_id,src_id);
            }    
        break;
    }

    return (KE_MSG_CONSUMED);
}

比如

        // device configuration updated
        case GAPM_SET_DEV_CONFIG:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
                EXECUTE_CALLBACK_VOID(app_on_set_dev_config_complete);
            }
        }
        break;

app_on_set_dev_config_complete 这里是设置广播开始 ==》    .app_on_set_dev_config_complete = default_app_on_set_dev_config_complete,

void default_app_on_set_dev_config_complete( void )
{
    // Add the first required service in the database
    if (app_db_init_start())
    {
        // No service to add in the DB -> Start Advertising
        EXECUTE_DEFAULT_OPERATION_VOID(default_operation_adv);
    }
 
    return;
}

default_operation_adv  ======》

// Default Handler Operations
static const struct default_app_operations user_default_app_operations = {
    .default_operation_adv = default_advertise_operation,
};

===》

void default_advertise_operation(void)
{
        if (user_default_hnd_conf.adv_scenario==DEF_ADV_FOREVER)
            app_easy_gap_undirected_advertise_start();
        else if (user_default_hnd_conf.adv_scenario==DEF_ADV_WITH_TIMEOUT)
            app_easy_gap_undirected_advertise_with_timeout_start(user_default_hnd_conf.advertise_period,NULL);
}

开始广播了


疑问:参数是怎么传进去的?????????

比如  if (app_process_handlers[i](msgid,param,dest_id,src_id, &process_msg_handling_result)==PR_EVENT_HANDLED) 里面这些参数怎么来的。没看明白



  



©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值