use esp_idf_hal::task::thread::ThreadSpawnConfiguration;
pub fn task_spawn<F, T>(name: &'static str, core: usize, stack_size: usize, f: F)
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
let cname = name.as_bytes();
assert_eq!(cname[cname.len() - 1], b'\0');
ThreadSpawnConfiguration::set(&ThreadSpawnConfiguration {
name: Some(cname),
inherit: true,
stack_size,
priority: 5,
pin_to_core: Some((core as i32).into()),
})
.expect("Failed to set thread configuration.");
std::thread::Builder::new()
.name(name[..name.len() - 1].to_string())
.stack_size(stack_size)
.spawn(f)
.expect("Failed to spawn timeslice_sched thread.");
ThreadSpawnConfiguration::set(&Default::default())
.expect("Failed to set thread configuration.");
}