Skip to content

Commit

Permalink
hack in Ariel threads support
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Feb 6, 2025
1 parent a120ab1 commit 89c59ca
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 11 deletions.
3 changes: 3 additions & 0 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ esp-config = { version = "0.3.0", path = "../esp-config" }
xtensa-lx-rt = { version = "0.18.0", path = "../xtensa-lx-rt", optional = true }
serde = { version = "1.0.217", default-features = false, features = ["derive"], optional = true }

ariel-os-threads = { version = "0.1.0", optional = true, path = "/home/kaspar/src/own/rust/ariel-os/src/ariel-os-threads" }

[build-dependencies]
esp-build = { version = "0.2.0", path = "../esp-build" }
esp-config = { version = "0.3.0", path = "../esp-config", features = ["build"] }
Expand Down Expand Up @@ -134,6 +136,7 @@ utils = ["smoltcp"]

# Disable internal scheduler
preempt-custom = []
ariel-os = ["dep:ariel-os-threads", "preempt-custom"]

# Implement serde Serialize / Deserialize
serde = ["dep:serde", "enumset?/serde", "heapless/serde"]
Expand Down
47 changes: 36 additions & 11 deletions esp-wifi/src/preempt_custom.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
use ariel_os_threads::{create_raw, current_tid, yield_same, THREAD_COUNT};
use esp_wifi_sys::include::malloc;

use crate::binary::c_types;

static THREAD_SEMAPHORES: [usize; THREAD_COUNT] = [0; THREAD_COUNT];

pub(crate) fn setup(_timer: crate::TimeBase) {
todo!()
info!("{}:{} setup()", file!(), line!());
}

pub(crate) fn disable() {
todo!()
info!("{}:{} disable()", file!(), line!());
}

pub(crate) fn yield_task() {
todo!()
yield_same();
}

pub(crate) fn current_task() -> *mut c_types::c_void {
todo!()
usize::from(current_tid().unwrap()) as *mut c_types::c_void
}

pub(crate) fn task_create(
_task: extern "C" fn(*mut c_types::c_void),
_param: *mut c_types::c_void,
_task_stack_size: usize,
task: extern "C" fn(*mut c_types::c_void),
param: *mut c_types::c_void,
task_stack_size: usize,
) -> *mut c_types::c_void {
todo!()
}
info!("{}:{} task_create()", file!(), line!());
let stack = unsafe { malloc(task_stack_size as u32) };
let stack_slice: &'static mut [u8] =
unsafe { core::slice::from_raw_parts_mut(stack as *mut u8, task_stack_size as usize) };

pub(crate) fn delete_all_tasks() {
todo!()
let prio = 8; // same as ariel executor thread
let core_affinity = None;
let tid = unsafe {
create_raw(
task as usize,
param as usize,
stack_slice,
prio,
core_affinity,
)
};
usize::from(tid) as *const usize as *mut c_types::c_void
}

pub(crate) fn schedule_task_deletion(_task_handle: *mut c_types::c_void) {
info!("{}:{} schedule_task_deletion()", file!(), line!());
todo!()
}

pub(crate) fn current_task_thread_semaphore() -> *mut c_types::c_void {
info!("{}:{} current_task_thread_semaphore()", file!(), line!());
let tid = usize::from(current_tid().unwrap());
&THREAD_SEMAPHORES[tid] as *const usize as *mut c_types::c_void
}
38 changes: 38 additions & 0 deletions esp-wifi/src/preempt_custom_skeleton.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::binary::c_types;

pub(crate) struct ThreadHandle {
pub thread_semaphore: usize,
}

pub(crate) fn setup(_timer: crate::TimeBase) {
info!("{}:{}", file!(), line!());
todo!()
}

pub(crate) fn disable() {
info!("{}:{}", file!(), line!());
todo!()
}

pub(crate) fn yield_task() {
info!("{}:{}", file!(), line!());
todo!()
}

pub(crate) fn current_task() -> *mut ThreadHandle {
info!("{}:{}", file!(), line!());
todo!()
}
pub(crate) fn task_create(
_task: extern "C" fn(*mut c_types::c_void),
_param: *mut c_types::c_void,
_task_stack_size: usize,
) -> *mut c_types::c_void {
info!("{}:{}", file!(), line!());
todo!()
}

pub(crate) fn schedule_task_deletion(_task_handle: *mut ThreadHandle) {
info!("{}:{}", file!(), line!());
todo!()
}

0 comments on commit 89c59ca

Please sign in to comment.