1 /**
2   ******************************************************************************
3   * @file    ll_sys_startup.c
4   * @author  MCD Application Team
5   * @brief   Link Layer IP system interface startup module
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 #include "ll_fw_config.h"
20 #include "ll_sys.h"
21 #include "ll_intf.h"
22 #include "ll_sys_startup.h"
23 #include "common_types.h"
24 #if defined(MAC) && (SUPPORT_OPENTHREAD_1_2 == 0)
25 /* Projects with MAC Layer (i.e. 15.4 except Thread) */
26 #include "st_mac_802_15_4_sap.h"
27 #endif /* MAC */
28 
29 /**
30   * @brief  Missed HCI event flag
31   */
32 uint8_t missed_hci_event_flag = 0;
33 
34 static void ll_sys_dependencies_init(void);
35 #ifdef BLE
ll_sys_event_missed_cb(ble_buff_hdr_t * ptr_evnt_hdr)36 static void ll_sys_event_missed_cb( ble_buff_hdr_t* ptr_evnt_hdr )
37 {
38   missed_hci_event_flag = 1;
39 }
40 
41 /**
42   * @brief  Initialize the Link Layer IP BLE controller
43   * @param  None
44   * @retval None
45   */
ll_sys_ble_cntrl_init(hst_cbk hostCallback)46 void ll_sys_ble_cntrl_init(hst_cbk hostCallback)
47 {
48   const struct hci_dispatch_tbl* p_hci_dis_tbl = NULL;
49 
50   hci_get_dis_tbl( &p_hci_dis_tbl );
51 
52   ll_intf_init(p_hci_dis_tbl);
53 
54   ll_intf_rgstr_hst_cbk(hostCallback);
55 
56   ll_intf_rgstr_hst_cbk_ll_queue_full( ll_sys_event_missed_cb );
57 
58   ll_sys_dependencies_init();
59 }
60 #endif /* BLE */
61 #if defined(MAC) && (SUPPORT_OPENTHREAD_1_2 == 0)
62 /**
63   * @brief  Initialize the Link Layer IP 802.15.4 MAC controller
64   * @param  None
65   * @retval None
66   */
ll_sys_mac_cntrl_init(void)67 void ll_sys_mac_cntrl_init(void)
68 {
69   ST_MAC_preInit();
70   ll_sys_dependencies_init();
71 }
72 #endif /* MAC */
73 
74 /**
75   * @brief  Start the Link Layer IP in OpenThread configuration
76   * @param  None
77   * @retval None
78   */
ll_sys_thread_init(void)79 void ll_sys_thread_init(void)
80 {
81   ll_sys_dependencies_init();
82 }
83 
84 /**
85   * @brief  Initialize the Link Layer resources for startup.
86   *         This includes: - Deep Sleep feature resources
87   *                        - Link Layer background task
88   * @param  None
89   * @retval None
90   */
ll_sys_dependencies_init(void)91 static void ll_sys_dependencies_init(void)
92 {
93   static uint8_t is_ll_initialized = 0;
94   ll_sys_status_t dp_slp_status;
95 
96   /* Ensure Link Layer resources are created only once */
97   if (is_ll_initialized == 1) {
98     return;
99   }
100   is_ll_initialized = 1;
101 
102   /* Deep sleep feature initialization */
103   dp_slp_status = ll_sys_dp_slp_init();
104   ll_sys_assert(dp_slp_status == LL_SYS_OK);
105 
106   /* Background task initialization */
107   ll_sys_bg_process_init();
108 
109   /* Link Layer user parameters application */
110   ll_sys_config_params();
111 }