use super::cmd::CmdPacket; use super::consts::TlPacketType; use super::{sys, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE, TL_SYS_TABLE}; const SCHI_OPCODE_BLE_INIT: u16 = 0xfc66; #[derive(Debug, Clone, Copy)] #[repr(C, packed)] pub struct ShciBleInitCmdParam { /// NOT USED CURRENTLY pub p_ble_buffer_address: u32, /// Size of the Buffer allocated in pBleBufferAddress pub ble_buffer_size: u32, pub num_attr_record: u16, pub num_attr_serv: u16, pub attr_value_arr_size: u16, pub num_of_links: u8, pub extended_packet_length_enable: u8, pub pr_write_list_size: u8, pub mb_lock_count: u8, pub att_mtu: u16, pub slave_sca: u16, pub master_sca: u8, pub ls_source: u8, pub max_conn_event_length: u32, pub hs_startup_time: u16, pub viterbi_enable: u8, pub ll_only: u8, pub hw_version: u8, } impl Default for ShciBleInitCmdParam { fn default() -> Self { Self { p_ble_buffer_address: 0, ble_buffer_size: 0, num_attr_record: 68, num_attr_serv: 8, attr_value_arr_size: 1344, num_of_links: 2, extended_packet_length_enable: 1, pr_write_list_size: 0x3A, mb_lock_count: 0x79, att_mtu: 156, slave_sca: 500, master_sca: 0, ls_source: 1, max_conn_event_length: 0xFFFFFFFF, hs_startup_time: 0x148, viterbi_enable: 1, ll_only: 0, hw_version: 0, } } } #[derive(Debug, Clone, Copy, Default)] #[repr(C, packed)] pub struct ShciHeader { metadata: [u32; 3], } #[derive(Debug, Clone, Copy)] #[repr(C, packed)] pub struct ShciBleInitCmdPacket { header: ShciHeader, param: ShciBleInitCmdParam, } pub const TL_BLE_EVT_CS_PACKET_SIZE: usize = TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE; #[allow(dead_code)] // Not used currently but reserved const TL_BLE_EVT_CS_BUFFER_SIZE: usize = TL_PACKET_HEADER_SIZE + TL_BLE_EVT_CS_PACKET_SIZE; pub fn shci_ble_init(param: ShciBleInitCmdParam) { debug!("sending SHCI"); let mut packet = ShciBleInitCmdPacket { header: ShciHeader::default(), param, }; let packet_ptr: *mut _ = &mut packet; unsafe { let cmd_ptr: *mut CmdPacket = packet_ptr.cast(); (*cmd_ptr).cmdserial.cmd.cmd_code = SCHI_OPCODE_BLE_INIT; (*cmd_ptr).cmdserial.cmd.payload_len = core::mem::size_of::() as u8; let mut p_cmd_buffer = &mut *(*TL_SYS_TABLE.as_mut_ptr()).pcmd_buffer; core::ptr::write(p_cmd_buffer, *cmd_ptr); p_cmd_buffer.cmdserial.ty = TlPacketType::SysCmd as u8; sys::Sys::send_cmd(); } }