aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32-wpan/src/wba/ll_sys/ll_sys_startup.rs
blob: 074aaeafe42e9d7cd830e31a8f4311c1f314b0b3 (plain)
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
use crate::bindings::link_layer::{
    _NULL as NULL, LL_SYS_STATUS_T_LL_SYS_OK, ble_buff_hdr_p, hci_dispatch_tbl, hci_get_dis_tbl, hst_cbk, ll_intf_init,
    ll_intf_rgstr_hst_cbk, ll_intf_rgstr_hst_cbk_ll_queue_full, ll_sys_assert, ll_sys_bg_process_init,
    ll_sys_config_params, ll_sys_dp_slp_init, ll_sys_status_t,
};
use crate::bindings::mac::ST_MAC_preInit;
// /**
//   ******************************************************************************
//   * @file    ll_sys_startup.c
//   * @author  MCD Application Team
//   * @brief   Link Layer IP system interface startup module
//   ******************************************************************************
//   * @attention
//   *
//   * Copyright (c) 2022 STMicroelectronics.
//   * All rights reserved.
//   *
//   * This software is licensed under terms that can be found in the LICENSE file
//   * in the root directory of this software component.
//   * If no LICENSE file comes with this software, it is provided AS-IS.
//   *
//   ******************************************************************************
//   */
//
// #include "ll_fw_config.h"
// #include "ll_sys.h"
// #include "ll_intf.h"
// #include "ll_sys_startup.h"
// #include "common_types.h"
// #if defined(MAC)
// #ifndef OPENTHREAD_CONFIG_FILE
// /* Projects with MAC Layer (i.e. 15.4 except Thread) */
// #include "st_mac_802_15_4_sap.h"
// #endif /* OPENTHREAD_CONFIG_FILE */
// #endif /* MAC */
//

#[allow(dead_code)]
/**
 * @brief  Missed HCI event flag
 */
static mut MISSED_HCI_EVENT_FLAG: u8 = 0;

// static void ll_sys_dependencies_init(void);
// #if SUPPORT_BLE

#[cfg(feature = "wba_ble")]
#[allow(dead_code)]
unsafe extern "C" fn ll_sys_event_missed_cb(_ptr_evnt_hdr: ble_buff_hdr_p) {
    MISSED_HCI_EVENT_FLAG = 1;
}

#[cfg(feature = "wba_ble")]
/**
 * @brief  Initialize the Link Layer IP BLE controller
 * @param  None
 * @retval None
 */
#[unsafe(no_mangle)]
unsafe extern "C" fn ll_sys_ble_cntrl_init(host_callback: hst_cbk) {
    let p_hci_dis_tbl: *const hci_dispatch_tbl = NULL as *const _;

    hci_get_dis_tbl(&p_hci_dis_tbl as *const *const _ as *mut *const _);

    ll_intf_init(p_hci_dis_tbl);

    ll_intf_rgstr_hst_cbk(host_callback);

    ll_intf_rgstr_hst_cbk_ll_queue_full(Some(ll_sys_event_missed_cb));

    ll_sys_dependencies_init();
}
// #endif /* SUPPORT_BLE */
// #if defined(MAC)
// #ifndef OPENTHREAD_CONFIG_FILE
#[cfg(feature = "wba_mac")]
/**
 * @brief  Initialize the Link Layer IP 802.15.4 MAC controller
 * @param  None
 * @retval None
 */
#[unsafe(no_mangle)]
unsafe extern "C" fn ll_sys_mac_cntrl_init() {
    ST_MAC_preInit();
    ll_sys_dependencies_init();
}
// #endif /* OPENTHREAD_CONFIG_FILE */
// #endif /* MAC */
/**
 * @brief  Start the Link Layer IP in OpenThread configuration
 * @param  None
 * @retval None
 */
#[unsafe(no_mangle)]
unsafe extern "C" fn ll_sys_thread_init() {
    ll_sys_dependencies_init();
}

/**
 * @brief  Initialize the Link Layer resources for startup.
 *         This includes: - Deep Sleep feature resources
 *                        - Link Layer background task
 * @param  None
 * @retval None
 */
unsafe fn ll_sys_dependencies_init() {
    static mut IS_LL_INITIALIZED: u8 = 0;
    let dp_slp_status: ll_sys_status_t;

    /* Ensure Link Layer resources are created only once */
    if IS_LL_INITIALIZED == 1 {
        return;
    }
    IS_LL_INITIALIZED = 1;

    /* Deep sleep feature initialization */
    dp_slp_status = ll_sys_dp_slp_init();
    ll_sys_assert((dp_slp_status == LL_SYS_STATUS_T_LL_SYS_OK) as u8);

    /* Background task initialization */
    ll_sys_bg_process_init();

    /* Link Layer user parameters application */
    ll_sys_config_params();
}