mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-14 21:20:06 +00:00
MYNEWT-512 Replace gen. sysinit with linker sect
OLD MECHANISM:
* pkg.yml file specifies "init_function" and "init_stage"
* newt generates sysinit C files which call the packages' init functions in
the specified order.
NEW MECHANISM:
* Each package defines an "init entry" struct containing:
* pointer to init function
* uint8_t stage
* Init entry structs are placed in a special section.
* At startup, the sysinit() function walks the list of entries in the
special section and calls their corresponding init functions in the
correct order.
INTERFACE:
/* Package initialization function. */
typedef void sysinit_init_fn(struct sysinit_init_ctxt *ctxt);
struct sysinit_entry {
/* Initializes a package. */
sysinit_init_fn *init_fn;
/* Specifies when the init function gets called. 0=first, 1=next, etc. */
uint8_t stage;
};
struct sysinit_init_ctxt {
/* Corresponds to the init function currently executing. */
const struct sysinit_entry *entry;
/* The stage that sysinit is currently processing. */
uint8_t cur_stage;
};
/**
* Registers a package initialization function
*
* @param init_cb Pointer to the init function to register.
* @param init_stage Indicates when this init function gets called,
* relative to other init functions. 0=first,
* 1=next, etc.
*/
#define SYSINIT_REGISTER_INIT(init_cb, init_stage) /* ... */
EXAMPLE:
static void
my_pkg_init(struct sysinit_init_ctxt *ctxt)
{
/* ... */
}
SYSINIT_REGISTER(my_pkg_init, 2);
X-Original-Commit: 43a5ef8860cbf4bc5bf43fde8a29fe74361536fa
This commit is contained in:
@@ -288,9 +288,6 @@ struct ble_dev_addr
|
||||
#define BLE_CONNECT_REQ_PDU_LEN (BLE_CONNECT_REQ_LEN + BLE_LL_PDU_HDR_LEN)
|
||||
|
||||
/*--- External API ---*/
|
||||
/* Initialize the Link Layer */
|
||||
void ble_ll_init(void);
|
||||
|
||||
/* Reset the Link Layer */
|
||||
int ble_ll_reset(void);
|
||||
|
||||
|
||||
@@ -33,6 +33,3 @@ pkg.deps:
|
||||
- kernel/os
|
||||
- sys/stats
|
||||
- net/nimble
|
||||
|
||||
pkg.init_function: ble_ll_init
|
||||
pkg.init_stage: 2
|
||||
|
||||
@@ -1211,7 +1211,7 @@ ble_ll_seed_prng(void)
|
||||
* @return int
|
||||
*/
|
||||
void
|
||||
ble_ll_init(void)
|
||||
ble_ll_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
uint8_t features;
|
||||
@@ -1323,6 +1323,8 @@ ble_ll_init(void)
|
||||
ble_hci_trans_cfg_ll(ble_ll_hci_cmd_rx, NULL, ble_ll_hci_acl_rx, NULL);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_ll_init, 2);
|
||||
|
||||
#ifdef BLE_LL_LOG
|
||||
void
|
||||
ble_ll_log_dump_index(int i)
|
||||
|
||||
@@ -153,7 +153,6 @@ extern struct ble_hs_cfg ble_hs_cfg;
|
||||
int ble_hs_synced(void);
|
||||
int ble_hs_start(void);
|
||||
void ble_hs_evq_set(struct os_eventq *evq);
|
||||
void ble_hs_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -41,6 +41,3 @@ pkg.deps.BLE_SM_SC:
|
||||
pkg.req_apis:
|
||||
- ble_transport
|
||||
- console
|
||||
|
||||
pkg.init_function: "ble_hs_init"
|
||||
pkg.init_stage: 2
|
||||
|
||||
@@ -79,7 +79,5 @@ int ble_svc_ans_new_alert_add(uint8_t cat_id,
|
||||
const char * info_str);
|
||||
int ble_svc_ans_unr_alert_add(uint8_t cat_id);
|
||||
|
||||
void ble_svc_ans_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,6 +29,3 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_svc_ans_init
|
||||
pkg.init_stage: 3
|
||||
|
||||
@@ -441,7 +441,7 @@ ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
|
||||
* @return 0 on success, non-zero error code otherwise.
|
||||
*/
|
||||
void
|
||||
ble_svc_ans_init(void)
|
||||
ble_svc_ans_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -457,3 +457,5 @@ ble_svc_ans_init(void)
|
||||
ble_svc_ans_new_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_NEW_ALERT_CAT);
|
||||
ble_svc_ans_unr_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_UNR_ALERT_CAT);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_svc_ans_init, 3);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
bleuart_init(void);
|
||||
int
|
||||
bleuart_svc_register(void);
|
||||
int
|
||||
|
||||
@@ -32,6 +32,3 @@ pkg.deps:
|
||||
|
||||
pkg.req_apis:
|
||||
- console
|
||||
|
||||
pkg.init_function: bleuart_init
|
||||
pkg.init_stage: 5
|
||||
|
||||
@@ -189,7 +189,7 @@ bleuart_set_conn_handle(uint16_t conn_handle) {
|
||||
* @param Maximum input
|
||||
*/
|
||||
void
|
||||
bleuart_init(void)
|
||||
bleuart_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -202,3 +202,5 @@ bleuart_init(void)
|
||||
console_buf = malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
|
||||
SYSINIT_PANIC_ASSERT(console_buf != NULL);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(bleuart_init, 5);
|
||||
|
||||
@@ -38,8 +38,6 @@ struct ble_hs_cfg;
|
||||
const char *ble_svc_gap_device_name(void);
|
||||
int ble_svc_gap_device_name_set(const char *name);
|
||||
|
||||
void ble_svc_gap_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,3 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_svc_gap_init
|
||||
pkg.init_stage: 3
|
||||
|
||||
@@ -151,7 +151,7 @@ ble_svc_gap_device_name_set(const char *name)
|
||||
}
|
||||
|
||||
void
|
||||
ble_svc_gap_init(void)
|
||||
ble_svc_gap_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -164,3 +164,5 @@ ble_svc_gap_init(void)
|
||||
rc = ble_gatts_add_svcs(ble_svc_gap_defs);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_svc_gap_init, 3);
|
||||
|
||||
@@ -31,7 +31,6 @@ struct ble_hs_cfg;
|
||||
#define BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16 0x2a05
|
||||
|
||||
void ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle);
|
||||
void ble_svc_gatt_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -29,6 +29,3 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_svc_gatt_init
|
||||
pkg.init_stage: 3
|
||||
|
||||
@@ -93,7 +93,7 @@ ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle)
|
||||
}
|
||||
|
||||
void
|
||||
ble_svc_gatt_init(void)
|
||||
ble_svc_gatt_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -106,3 +106,5 @@ ble_svc_gatt_init(void)
|
||||
rc = ble_gatts_add_svcs(ble_svc_gatt_defs);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_svc_gatt_init, 3);
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
typedef int ble_svc_ias_event_fn(uint8_t alert_level);
|
||||
|
||||
void ble_svc_ias_set_cb(ble_svc_ias_event_fn *cb);
|
||||
void ble_svc_ias_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,6 +29,3 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_svc_ias_init
|
||||
pkg.init_stage: 3
|
||||
|
||||
@@ -132,7 +132,7 @@ ble_svc_ias_set_cb(ble_svc_ias_event_fn *cb)
|
||||
* Initialize the IAS package.
|
||||
*/
|
||||
void
|
||||
ble_svc_ias_init(void)
|
||||
ble_svc_ias_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -145,3 +145,5 @@ ble_svc_ias_init(void)
|
||||
rc = ble_gatts_add_svcs(ble_svc_ias_defs);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_svc_ias_init, 3);
|
||||
|
||||
@@ -20,12 +20,8 @@
|
||||
#ifndef H_BLE_SVC_TPS_
|
||||
#define H_BLE_SVC_TPS_
|
||||
|
||||
struct ble_hs_cfg;
|
||||
|
||||
#define BLE_SVC_TPS_UUID16 0x1804
|
||||
#define BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL 0x2a07
|
||||
|
||||
void ble_svc_tps_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,6 +29,3 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_svc_tps_init
|
||||
pkg.init_stage: 3
|
||||
|
||||
@@ -92,7 +92,7 @@ ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
* Initialize the TPS
|
||||
*/
|
||||
void
|
||||
ble_svc_tps_init(void)
|
||||
ble_svc_tps_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -105,3 +105,5 @@ ble_svc_tps_init(void)
|
||||
rc = ble_gatts_add_svcs(ble_svc_tps_defs);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_svc_tps_init, 3);
|
||||
|
||||
@@ -538,15 +538,13 @@ ble_hs_tx_data(struct os_mbuf *om)
|
||||
* NimBLE by processing events generated by the host.
|
||||
*/
|
||||
void
|
||||
ble_hs_init(void)
|
||||
ble_hs_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Ensure this function only gets called by sysinit. */
|
||||
SYSINIT_ASSERT_ACTIVE();
|
||||
|
||||
log_init();
|
||||
|
||||
/* Create memory pool of OS events */
|
||||
rc = os_mempool_init(&ble_hs_hci_ev_pool, BLE_HS_HCI_EVT_COUNT,
|
||||
sizeof (struct os_event), ble_hs_hci_os_event_buf,
|
||||
@@ -607,3 +605,5 @@ ble_hs_init(void)
|
||||
/* Configure the HCI transport to communicate with a host. */
|
||||
ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_hs_init, 2);
|
||||
|
||||
@@ -29,6 +29,3 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_store_ram_init
|
||||
pkg.init_stage: 5
|
||||
|
||||
@@ -469,7 +469,7 @@ ble_store_ram_delete(int obj_type, union ble_store_key *key)
|
||||
}
|
||||
|
||||
void
|
||||
ble_store_ram_init(void)
|
||||
ble_store_ram_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
/* Ensure this function only gets called by sysinit. */
|
||||
SYSINIT_ASSERT_ACTIVE();
|
||||
@@ -483,3 +483,5 @@ ble_store_ram_init(void)
|
||||
ble_store_ram_num_peer_secs = 0;
|
||||
ble_store_ram_num_cccds = 0;
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_store_ram_init, 5);
|
||||
|
||||
@@ -31,6 +31,3 @@ pkg.deps:
|
||||
|
||||
pkg.apis:
|
||||
- ble_transport
|
||||
|
||||
pkg.init_function: ble_hci_ram_pkg_init
|
||||
pkg.init_stage: 1
|
||||
|
||||
@@ -241,7 +241,7 @@ err:
|
||||
}
|
||||
|
||||
void
|
||||
ble_hci_ram_pkg_init(void)
|
||||
ble_hci_ram_pkg_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -251,3 +251,5 @@ ble_hci_ram_pkg_init(void)
|
||||
rc = ble_hci_ram_init();
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_hci_ram_pkg_init, 1);
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef H_BLE_HCI_UART_
|
||||
#define H_BLE_HCI_UART_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ble_hci_uart_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -33,6 +33,3 @@ pkg.deps:
|
||||
|
||||
pkg.apis:
|
||||
- ble_transport
|
||||
|
||||
pkg.init_function: ble_hci_uart_init
|
||||
pkg.init_stage: 5
|
||||
|
||||
Executable → Regular
+4
-4
@@ -37,8 +37,6 @@
|
||||
#include "nimble/hci_common.h"
|
||||
#include "nimble/ble_hci_trans.h"
|
||||
|
||||
#include "transport/uart/ble_hci_uart.h"
|
||||
|
||||
#define BLE_HCI_UART_EVT_COUNT \
|
||||
(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
|
||||
|
||||
@@ -959,8 +957,8 @@ ble_hci_trans_reset(void)
|
||||
* @return 0 on success;
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
int
|
||||
ble_hci_uart_init(void)
|
||||
void
|
||||
ble_hci_uart_init(struct sysinit_init_ctxt *ctxt)
|
||||
{
|
||||
int acl_data_length;
|
||||
int acl_block_size;
|
||||
@@ -1062,3 +1060,5 @@ err:
|
||||
ble_hci_uart_free_mem();
|
||||
return rc;
|
||||
}
|
||||
|
||||
SYSINIT_REGISTER_INIT(ble_hci_uart_init, 5);
|
||||
|
||||
Reference in New Issue
Block a user