68 lines
2.4 KiB
Rust
Raw Normal View History

2023-05-15 10:25:02 +01:00
use super::evt::EvtPacket;
2023-05-20 10:11:29 -05:00
use super::unsafe_linked_list::LinkedListNode;
use super::{
2023-05-15 10:25:02 +01:00
channels, MemManagerTable, BLE_SPARE_EVT_BUF, EVT_POOL, FREE_BUFF_QUEUE, LOCAL_FREE_BUF_QUEUE, POOL_SIZE,
SYS_SPARE_EVT_BUF, TL_MEM_MANAGER_TABLE, TL_REF_TABLE,
};
2023-05-27 15:05:23 -05:00
use crate::tl_mbox::ipcc::Ipcc;
pub struct MemoryManager;
impl MemoryManager {
2023-05-27 15:05:23 -05:00
pub fn enable() {
unsafe {
2023-05-20 10:11:29 -05:00
LinkedListNode::init_head(FREE_BUFF_QUEUE.as_mut_ptr());
LinkedListNode::init_head(LOCAL_FREE_BUF_QUEUE.as_mut_ptr());
2023-05-27 15:05:23 -05:00
TL_MEM_MANAGER_TABLE.as_mut_ptr().write_volatile(MemManagerTable {
spare_ble_buffer: BLE_SPARE_EVT_BUF.as_ptr().cast(),
spare_sys_buffer: SYS_SPARE_EVT_BUF.as_ptr().cast(),
ble_pool: EVT_POOL.as_ptr().cast(),
ble_pool_size: POOL_SIZE as u32,
pevt_free_buffer_queue: FREE_BUFF_QUEUE.as_mut_ptr(),
traces_evt_pool: core::ptr::null(),
traces_pool_size: 0,
});
}
}
2023-05-15 10:25:02 +01:00
2023-05-26 09:56:55 +01:00
pub fn evt_handler() {
Ipcc::c1_set_tx_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL, false);
2023-05-15 10:25:02 +01:00
Self::send_free_buf();
2023-05-26 09:56:55 +01:00
Ipcc::c1_set_flag_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL);
2023-05-15 10:25:02 +01:00
}
2023-05-26 09:56:55 +01:00
pub fn evt_drop(evt: *mut EvtPacket) {
2023-05-15 10:25:02 +01:00
unsafe {
let list_node = evt.cast();
2023-05-20 10:11:29 -05:00
LinkedListNode::remove_tail(LOCAL_FREE_BUF_QUEUE.as_mut_ptr(), list_node);
2023-05-15 10:25:02 +01:00
}
2023-05-26 09:56:55 +01:00
let channel_is_busy = Ipcc::c1_is_active_flag(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL);
2023-05-15 10:25:02 +01:00
// postpone event buffer freeing to IPCC interrupt handler
if channel_is_busy {
2023-05-26 09:56:55 +01:00
Ipcc::c1_set_tx_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL, true);
2023-05-15 10:25:02 +01:00
} else {
Self::send_free_buf();
2023-05-26 09:56:55 +01:00
Ipcc::c1_set_flag_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL);
2023-05-15 10:25:02 +01:00
}
}
fn send_free_buf() {
unsafe {
let mut node_ptr = core::ptr::null_mut();
let node_ptr_ptr: *mut _ = &mut node_ptr;
2023-05-20 10:11:29 -05:00
while !LinkedListNode::is_empty(LOCAL_FREE_BUF_QUEUE.as_mut_ptr()) {
LinkedListNode::remove_head(LOCAL_FREE_BUF_QUEUE.as_mut_ptr(), node_ptr_ptr);
LinkedListNode::insert_tail(
2023-05-15 10:25:02 +01:00
(*(*TL_REF_TABLE.as_ptr()).mem_manager_table).pevt_free_buffer_queue,
node_ptr,
);
}
}
}
}