|
| 1 | +use crate::binary::include::esp_bt_controller_config_t; |
| 2 | +use crate::common_adapter::RADIO_CLOCKS; |
| 3 | +use crate::hal::system::RadioClockController; |
| 4 | +use crate::hal::system::RadioPeripherals; |
| 5 | + |
| 6 | +pub(crate) static mut ISR_INTERRUPT_15: ( |
| 7 | + *mut crate::binary::c_types::c_void, |
| 8 | + *mut crate::binary::c_types::c_void, |
| 9 | +) = (core::ptr::null_mut(), core::ptr::null_mut()); |
| 10 | + |
| 11 | +pub(crate) static mut ISR_INTERRUPT_3: ( |
| 12 | + *mut crate::binary::c_types::c_void, |
| 13 | + *mut crate::binary::c_types::c_void, |
| 14 | +) = (core::ptr::null_mut(), core::ptr::null_mut()); |
| 15 | + |
| 16 | +pub(crate) static BLE_CONFIG: esp_bt_controller_config_t = esp_bt_controller_config_t { |
| 17 | + config_version: 0x20230113, |
| 18 | + ble_ll_resolv_list_size: 4, |
| 19 | + ble_hci_evt_hi_buf_count: 30, |
| 20 | + ble_hci_evt_lo_buf_count: 8, |
| 21 | + ble_ll_sync_list_cnt: 5, |
| 22 | + ble_ll_sync_cnt: 20, |
| 23 | + ble_ll_rsp_dup_list_count: 20, |
| 24 | + ble_ll_adv_dup_list_count: 20, |
| 25 | + ble_ll_tx_pwr_dbm: 9, |
| 26 | + rtc_freq: 32000, |
| 27 | + ble_ll_sca: 60, |
| 28 | + ble_ll_scan_phy_number: 1, |
| 29 | + ble_ll_conn_def_auth_pyld_tmo: 3000, |
| 30 | + ble_ll_jitter_usecs: 16, |
| 31 | + ble_ll_sched_max_adv_pdu_usecs: 376, |
| 32 | + ble_ll_sched_direct_adv_max_usecs: 502, |
| 33 | + ble_ll_sched_adv_max_usecs: 852, |
| 34 | + ble_scan_rsp_data_max_len: 31, |
| 35 | + ble_ll_cfg_num_hci_cmd_pkts: 1, |
| 36 | + ble_ll_ctrl_proc_timeout_ms: 40000, |
| 37 | + nimble_max_connections: 2, |
| 38 | + ble_whitelist_size: 12, |
| 39 | + ble_acl_buf_size: 255, |
| 40 | + ble_acl_buf_count: 24, |
| 41 | + ble_hci_evt_buf_size: 70, |
| 42 | + ble_multi_adv_instances: 1, |
| 43 | + ble_ext_adv_max_size: 31, |
| 44 | + controller_task_stack_size: 4096, |
| 45 | + controller_task_prio: 253, // ??? |
| 46 | + controller_run_cpu: 0, |
| 47 | + enable_qa_test: 0, |
| 48 | + enable_bqb_test: 0, |
| 49 | + enable_uart_hci: 0, |
| 50 | + ble_hci_uart_port: 0, |
| 51 | + ble_hci_uart_baud: 0, |
| 52 | + ble_hci_uart_data_bits: 0, |
| 53 | + ble_hci_uart_stop_bits: 0, |
| 54 | + ble_hci_uart_flow_ctrl: 0, |
| 55 | + ble_hci_uart_uart_parity: 0, |
| 56 | + enable_tx_cca: 0, |
| 57 | + cca_rssi_thresh: (256 - 50) as u8, |
| 58 | + sleep_en: 0, |
| 59 | + coex_phy_coded_tx_rx_time_limit: 0, |
| 60 | + dis_scan_backoff: 0, |
| 61 | + ble_scan_classify_filter_enable: 1, |
| 62 | + cca_drop_mode: 0, //??? |
| 63 | + cca_low_tx_pwr: 0, //??? |
| 64 | + main_xtal_freq: 32, |
| 65 | + ignore_wl_for_direct_adv: 0, |
| 66 | + config_magic: 0x5A5AA5A5, |
| 67 | + |
| 68 | + cpu_freq_mhz: 96, |
| 69 | + enable_pcl: 0, |
| 70 | + // version_num: 0, |
| 71 | +}; |
| 72 | + |
| 73 | +pub(crate) fn bt_periph_module_enable() { |
| 74 | + unsafe { |
| 75 | + unwrap!(RADIO_CLOCKS.as_mut()).enable(RadioPeripherals::Bt); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +pub(crate) fn disable_sleep_mode() { |
| 80 | + // nothing |
| 81 | +} |
| 82 | + |
| 83 | +pub(super) unsafe extern "C" fn esp_intr_alloc( |
| 84 | + source: u32, |
| 85 | + flags: u32, |
| 86 | + handler: *mut crate::binary::c_types::c_void, |
| 87 | + arg: *mut crate::binary::c_types::c_void, |
| 88 | + ret_handle: *mut *mut crate::binary::c_types::c_void, |
| 89 | +) -> i32 { |
| 90 | + debug!( |
| 91 | + "esp_intr_alloc {} {} {:?} {:?} {:?}", |
| 92 | + source, flags, handler, arg, ret_handle |
| 93 | + ); |
| 94 | + |
| 95 | + match source { |
| 96 | + 3 => ISR_INTERRUPT_3 = (handler, arg), |
| 97 | + 15 => ISR_INTERRUPT_15 = (handler, arg), |
| 98 | + _ => panic!("Unexpected interrupt source {}", source), |
| 99 | + } |
| 100 | + |
| 101 | + 0 |
| 102 | +} |
| 103 | + |
| 104 | +pub(super) fn ble_rtc_clk_init() { |
| 105 | + unsafe { |
| 106 | + unwrap!(RADIO_CLOCKS.as_mut()).ble_rtc_clk_init(); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +pub(super) unsafe extern "C" fn esp_reset_rpa_moudle() { |
| 111 | + trace!("esp_reset_rpa_moudle"); |
| 112 | + unsafe { |
| 113 | + unwrap!(RADIO_CLOCKS.as_mut()).reset_rpa(); |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +#[allow(improper_ctypes_definitions)] |
| 118 | +#[no_mangle] |
| 119 | +unsafe extern "C" fn jrand48( |
| 120 | + _xsubi: [crate::binary::c_types::c_ushort; 3], |
| 121 | +) -> crate::binary::c_types::c_long { |
| 122 | + // this is not very random but good enough for now - it's apparently not used for crypto |
| 123 | + unsafe { |
| 124 | + static mut VALUE: u32 = 0; |
| 125 | + VALUE = VALUE.wrapping_add(3); |
| 126 | + VALUE as i32 |
| 127 | + } |
| 128 | +} |
0 commit comments