2023-05-15 11:25:02 +02:00
|
|
|
use super::cmd::CmdPacket;
|
|
|
|
use super::consts::TlPacketType;
|
2023-06-08 17:26:47 +02:00
|
|
|
use super::{sys, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE, TL_SYS_TABLE};
|
2023-05-15 11:25:02 +02:00
|
|
|
|
|
|
|
const SCHI_OPCODE_BLE_INIT: u16 = 0xfc66;
|
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2023-05-15 11:25:02 +02:00
|
|
|
#[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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
#[derive(Debug, Clone, Copy, Default)]
|
2023-05-15 11:25:02 +02:00
|
|
|
#[repr(C, packed)]
|
|
|
|
pub struct ShciHeader {
|
|
|
|
metadata: [u32; 3],
|
|
|
|
}
|
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2023-05-15 11:25:02 +02:00
|
|
|
#[repr(C, packed)]
|
|
|
|
pub struct ShciBleInitCmdPacket {
|
|
|
|
header: ShciHeader,
|
|
|
|
param: ShciBleInitCmdParam,
|
|
|
|
}
|
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
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;
|
|
|
|
|
2023-05-26 10:56:55 +02:00
|
|
|
pub fn shci_ble_init(param: ShciBleInitCmdParam) {
|
2023-06-12 13:27:51 +02:00
|
|
|
debug!("sending SHCI");
|
2023-06-08 17:26:47 +02:00
|
|
|
|
2023-05-15 11:25:02 +02:00
|
|
|
let mut packet = ShciBleInitCmdPacket {
|
|
|
|
header: ShciHeader::default(),
|
|
|
|
param,
|
|
|
|
};
|
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
let packet_ptr: *mut _ = &mut packet;
|
2023-05-15 11:25:02 +02:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let cmd_ptr: *mut CmdPacket = packet_ptr.cast();
|
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
(*cmd_ptr).cmdserial.cmd.cmd_code = SCHI_OPCODE_BLE_INIT;
|
|
|
|
(*cmd_ptr).cmdserial.cmd.payload_len = core::mem::size_of::<ShciBleInitCmdParam>() as u8;
|
2023-05-15 11:25:02 +02:00
|
|
|
|
2023-06-12 16:07:46 +02:00
|
|
|
let p_cmd_buffer = &mut *(*TL_SYS_TABLE.as_mut_ptr()).pcmd_buffer;
|
2023-06-08 17:26:47 +02:00
|
|
|
core::ptr::write(p_cmd_buffer, *cmd_ptr);
|
2023-05-15 11:25:02 +02:00
|
|
|
|
2023-06-08 17:26:47 +02:00
|
|
|
p_cmd_buffer.cmdserial.ty = TlPacketType::SysCmd as u8;
|
2023-05-15 11:25:02 +02:00
|
|
|
|
2023-06-12 13:27:51 +02:00
|
|
|
sys::Sys::send_cmd();
|
2023-05-15 11:25:02 +02:00
|
|
|
}
|
|
|
|
}
|