From 330958f9d6882835b47c85c1a59520269abf80cc Mon Sep 17 00:00:00 2001 From: Christopher Collins Date: Wed, 14 Dec 2016 18:07:50 -0800 Subject: [PATCH] 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 --- nimble/controller/include/controller/ble_ll.h | 3 -- nimble/controller/pkg.yml | 3 -- nimble/controller/src/ble_ll.c | 4 ++- nimble/host/include/host/ble_hs.h | 1 - nimble/host/pkg.yml | 3 -- .../ans/include/services/ans/ble_svc_ans.h | 2 -- nimble/host/services/ans/pkg.yml | 3 -- nimble/host/services/ans/src/ble_svc_ans.c | 4 ++- .../bleuart/include/bleuart/bleuart.h | 2 -- nimble/host/services/bleuart/pkg.yml | 3 -- nimble/host/services/bleuart/src/bleuart.c | 4 ++- .../gap/include/services/gap/ble_svc_gap.h | 2 -- nimble/host/services/gap/pkg.yml | 3 -- nimble/host/services/gap/src/ble_svc_gap.c | 4 ++- .../gatt/include/services/gatt/ble_svc_gatt.h | 1 - nimble/host/services/gatt/pkg.yml | 3 -- nimble/host/services/gatt/src/ble_svc_gatt.c | 4 ++- .../ias/include/services/ias/ble_svc_ias.h | 1 - nimble/host/services/ias/pkg.yml | 3 -- nimble/host/services/ias/src/ble_svc_ias.c | 4 ++- .../tps/include/services/tps/ble_svc_tps.h | 4 --- nimble/host/services/tps/pkg.yml | 3 -- nimble/host/services/tps/src/ble_svc_tps.c | 4 ++- nimble/host/src/ble_hs.c | 6 ++-- nimble/host/store/ram/pkg.yml | 3 -- nimble/host/store/ram/src/ble_store_ram.c | 4 ++- nimble/transport/ram/pkg.yml | 3 -- nimble/transport/ram/src/ble_hci_ram.c | 4 ++- .../include/transport/uart/ble_hci_uart.h | 33 ------------------- nimble/transport/uart/pkg.yml | 3 -- nimble/transport/uart/src/ble_hci_uart.c | 8 ++--- 31 files changed, 34 insertions(+), 98 deletions(-) delete mode 100644 nimble/transport/uart/include/transport/uart/ble_hci_uart.h mode change 100755 => 100644 nimble/transport/uart/src/ble_hci_uart.c diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h index e349d7116..c17b67bfc 100644 --- a/nimble/controller/include/controller/ble_ll.h +++ b/nimble/controller/include/controller/ble_ll.h @@ -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); diff --git a/nimble/controller/pkg.yml b/nimble/controller/pkg.yml index 7761c53cd..a60d2d745 100644 --- a/nimble/controller/pkg.yml +++ b/nimble/controller/pkg.yml @@ -33,6 +33,3 @@ pkg.deps: - kernel/os - sys/stats - net/nimble - -pkg.init_function: ble_ll_init -pkg.init_stage: 2 diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c index 63b3cacd1..db7272945 100644 --- a/nimble/controller/src/ble_ll.c +++ b/nimble/controller/src/ble_ll.c @@ -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) diff --git a/nimble/host/include/host/ble_hs.h b/nimble/host/include/host/ble_hs.h index 4ee6c7939..d227d2cf7 100644 --- a/nimble/host/include/host/ble_hs.h +++ b/nimble/host/include/host/ble_hs.h @@ -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 } diff --git a/nimble/host/pkg.yml b/nimble/host/pkg.yml index 4341d0339..aba87ea40 100644 --- a/nimble/host/pkg.yml +++ b/nimble/host/pkg.yml @@ -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 diff --git a/nimble/host/services/ans/include/services/ans/ble_svc_ans.h b/nimble/host/services/ans/include/services/ans/ble_svc_ans.h index 8d3e3cf01..3b84b2115 100644 --- a/nimble/host/services/ans/include/services/ans/ble_svc_ans.h +++ b/nimble/host/services/ans/include/services/ans/ble_svc_ans.h @@ -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 diff --git a/nimble/host/services/ans/pkg.yml b/nimble/host/services/ans/pkg.yml index 41a738ce5..91a92c686 100644 --- a/nimble/host/services/ans/pkg.yml +++ b/nimble/host/services/ans/pkg.yml @@ -29,6 +29,3 @@ pkg.keywords: pkg.deps: - net/nimble/host - -pkg.init_function: ble_svc_ans_init -pkg.init_stage: 3 diff --git a/nimble/host/services/ans/src/ble_svc_ans.c b/nimble/host/services/ans/src/ble_svc_ans.c index ca4ee8a02..b6704832e 100644 --- a/nimble/host/services/ans/src/ble_svc_ans.c +++ b/nimble/host/services/ans/src/ble_svc_ans.c @@ -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); diff --git a/nimble/host/services/bleuart/include/bleuart/bleuart.h b/nimble/host/services/bleuart/include/bleuart/bleuart.h index a8c29c15a..d8b1c5947 100644 --- a/nimble/host/services/bleuart/include/bleuart/bleuart.h +++ b/nimble/host/services/bleuart/include/bleuart/bleuart.h @@ -24,8 +24,6 @@ extern "C" { #endif -void -bleuart_init(void); int bleuart_svc_register(void); int diff --git a/nimble/host/services/bleuart/pkg.yml b/nimble/host/services/bleuart/pkg.yml index 985012593..46ed1e682 100644 --- a/nimble/host/services/bleuart/pkg.yml +++ b/nimble/host/services/bleuart/pkg.yml @@ -32,6 +32,3 @@ pkg.deps: pkg.req_apis: - console - -pkg.init_function: bleuart_init -pkg.init_stage: 5 diff --git a/nimble/host/services/bleuart/src/bleuart.c b/nimble/host/services/bleuart/src/bleuart.c index 3c26ffc31..83b81959f 100644 --- a/nimble/host/services/bleuart/src/bleuart.c +++ b/nimble/host/services/bleuart/src/bleuart.c @@ -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); diff --git a/nimble/host/services/gap/include/services/gap/ble_svc_gap.h b/nimble/host/services/gap/include/services/gap/ble_svc_gap.h index cb8d62593..142b96d44 100644 --- a/nimble/host/services/gap/include/services/gap/ble_svc_gap.h +++ b/nimble/host/services/gap/include/services/gap/ble_svc_gap.h @@ -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 diff --git a/nimble/host/services/gap/pkg.yml b/nimble/host/services/gap/pkg.yml index 376a555b7..b84e8161d 100644 --- a/nimble/host/services/gap/pkg.yml +++ b/nimble/host/services/gap/pkg.yml @@ -29,6 +29,3 @@ pkg.keywords: pkg.deps: - net/nimble/host - -pkg.init_function: ble_svc_gap_init -pkg.init_stage: 3 diff --git a/nimble/host/services/gap/src/ble_svc_gap.c b/nimble/host/services/gap/src/ble_svc_gap.c index e0ccd7ca1..b00a84a20 100644 --- a/nimble/host/services/gap/src/ble_svc_gap.c +++ b/nimble/host/services/gap/src/ble_svc_gap.c @@ -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); diff --git a/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h b/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h index 06c44784a..1cf885707 100644 --- a/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h +++ b/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h @@ -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 } diff --git a/nimble/host/services/gatt/pkg.yml b/nimble/host/services/gatt/pkg.yml index ec0eb1eb8..b8fdabe12 100644 --- a/nimble/host/services/gatt/pkg.yml +++ b/nimble/host/services/gatt/pkg.yml @@ -29,6 +29,3 @@ pkg.keywords: pkg.deps: - net/nimble/host - -pkg.init_function: ble_svc_gatt_init -pkg.init_stage: 3 diff --git a/nimble/host/services/gatt/src/ble_svc_gatt.c b/nimble/host/services/gatt/src/ble_svc_gatt.c index 666e67244..ecab64b63 100644 --- a/nimble/host/services/gatt/src/ble_svc_gatt.c +++ b/nimble/host/services/gatt/src/ble_svc_gatt.c @@ -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); diff --git a/nimble/host/services/ias/include/services/ias/ble_svc_ias.h b/nimble/host/services/ias/include/services/ias/ble_svc_ias.h index b63b458fa..c6a6d8170 100644 --- a/nimble/host/services/ias/include/services/ias/ble_svc_ias.h +++ b/nimble/host/services/ias/include/services/ias/ble_svc_ias.h @@ -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 diff --git a/nimble/host/services/ias/pkg.yml b/nimble/host/services/ias/pkg.yml index 38799062c..1badb0017 100644 --- a/nimble/host/services/ias/pkg.yml +++ b/nimble/host/services/ias/pkg.yml @@ -29,6 +29,3 @@ pkg.keywords: pkg.deps: - net/nimble/host - -pkg.init_function: ble_svc_ias_init -pkg.init_stage: 3 diff --git a/nimble/host/services/ias/src/ble_svc_ias.c b/nimble/host/services/ias/src/ble_svc_ias.c index 5644ccd30..27194832d 100644 --- a/nimble/host/services/ias/src/ble_svc_ias.c +++ b/nimble/host/services/ias/src/ble_svc_ias.c @@ -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); diff --git a/nimble/host/services/tps/include/services/tps/ble_svc_tps.h b/nimble/host/services/tps/include/services/tps/ble_svc_tps.h index ec4cd790a..d43d09d6f 100644 --- a/nimble/host/services/tps/include/services/tps/ble_svc_tps.h +++ b/nimble/host/services/tps/include/services/tps/ble_svc_tps.h @@ -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 diff --git a/nimble/host/services/tps/pkg.yml b/nimble/host/services/tps/pkg.yml index 17b2b8741..f22a3957e 100644 --- a/nimble/host/services/tps/pkg.yml +++ b/nimble/host/services/tps/pkg.yml @@ -29,6 +29,3 @@ pkg.keywords: pkg.deps: - net/nimble/host - -pkg.init_function: ble_svc_tps_init -pkg.init_stage: 3 diff --git a/nimble/host/services/tps/src/ble_svc_tps.c b/nimble/host/services/tps/src/ble_svc_tps.c index 74c2df46d..7287d77b2 100644 --- a/nimble/host/services/tps/src/ble_svc_tps.c +++ b/nimble/host/services/tps/src/ble_svc_tps.c @@ -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); diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index 0d35a88c7..1e2b42651 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -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); diff --git a/nimble/host/store/ram/pkg.yml b/nimble/host/store/ram/pkg.yml index afa638faf..f43e7a55a 100644 --- a/nimble/host/store/ram/pkg.yml +++ b/nimble/host/store/ram/pkg.yml @@ -29,6 +29,3 @@ pkg.keywords: pkg.deps: - net/nimble/host - -pkg.init_function: ble_store_ram_init -pkg.init_stage: 5 diff --git a/nimble/host/store/ram/src/ble_store_ram.c b/nimble/host/store/ram/src/ble_store_ram.c index 65a76cc66..16dcd5891 100644 --- a/nimble/host/store/ram/src/ble_store_ram.c +++ b/nimble/host/store/ram/src/ble_store_ram.c @@ -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); diff --git a/nimble/transport/ram/pkg.yml b/nimble/transport/ram/pkg.yml index 60d9d96c2..f66eae0a2 100644 --- a/nimble/transport/ram/pkg.yml +++ b/nimble/transport/ram/pkg.yml @@ -31,6 +31,3 @@ pkg.deps: pkg.apis: - ble_transport - -pkg.init_function: ble_hci_ram_pkg_init -pkg.init_stage: 1 diff --git a/nimble/transport/ram/src/ble_hci_ram.c b/nimble/transport/ram/src/ble_hci_ram.c index 1c0cc6a01..fd356edfc 100644 --- a/nimble/transport/ram/src/ble_hci_ram.c +++ b/nimble/transport/ram/src/ble_hci_ram.c @@ -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); diff --git a/nimble/transport/uart/include/transport/uart/ble_hci_uart.h b/nimble/transport/uart/include/transport/uart/ble_hci_uart.h deleted file mode 100644 index d54fd6674..000000000 --- a/nimble/transport/uart/include/transport/uart/ble_hci_uart.h +++ /dev/null @@ -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 diff --git a/nimble/transport/uart/pkg.yml b/nimble/transport/uart/pkg.yml index be76509c7..b3a7f6881 100644 --- a/nimble/transport/uart/pkg.yml +++ b/nimble/transport/uart/pkg.yml @@ -33,6 +33,3 @@ pkg.deps: pkg.apis: - ble_transport - -pkg.init_function: ble_hci_uart_init -pkg.init_stage: 5 diff --git a/nimble/transport/uart/src/ble_hci_uart.c b/nimble/transport/uart/src/ble_hci_uart.c old mode 100755 new mode 100644 index 1ace2b0b6..fb6433ed4 --- a/nimble/transport/uart/src/ble_hci_uart.c +++ b/nimble/transport/uart/src/ble_hci_uart.c @@ -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);