Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require float-save-restore in esp-wifi #2322

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ portable_atomic_enum = { version = "0.3.1", features = ["portable-atomic"] }
bt-hci = { version = "0.1.1", optional = true }
esp-config = { version = "0.1.0", path = "../esp-config" }

xtensa-lx-rt = { version = "0.17.1", path = "../xtensa-lx-rt", optional = true }

[build-dependencies]
esp-build = { version = "0.1.0", path = "../esp-build" }
esp-config = { version = "0.1.0", path = "../esp-config", features = ["build"] }
Expand Down Expand Up @@ -83,16 +85,19 @@ esp32h2 = [
esp32 = [
"esp-hal/esp32",
"esp-wifi-sys/esp32",
"xtensa-lx-rt/float-save-restore",
]
# Target the ESP32-S2.
esp32s2 = [
"esp-hal/esp32s2",
"esp-wifi-sys/esp32s2",
"xtensa-lx-rt/float-save-restore",
]
# Target the ESP32-S3.
esp32s3 = [
"esp-hal/esp32s3",
"esp-wifi-sys/esp32s3",
"xtensa-lx-rt/float-save-restore",
]

## Enable Async support
Expand Down
4 changes: 2 additions & 2 deletions esp-wifi/src/preempt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn allocate_main_task() -> *mut Context {
}

let ptr = malloc(size_of::<Context>() as u32) as *mut Context;
core::ptr::write_bytes(ptr, 0, 1);
core::ptr::write(ptr, Context::new());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really should be Box::new but I'm not ready to go down that rabbit hole yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would do construct-in-place

(*ptr).next = ptr;
*ctx_now = ptr;
ptr
Expand All @@ -37,7 +37,7 @@ fn allocate_task() -> *mut Context {
}

let ptr = malloc(size_of::<Context>() as u32) as *mut Context;
core::ptr::write_bytes(ptr, 0, 1);
core::ptr::write(ptr, Context::new());
(*ptr).next = (**ctx_now).next;
(**ctx_now).next = ptr;
ptr
Expand Down
11 changes: 11 additions & 0 deletions esp-wifi/src/preempt/preempt_riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ pub struct Context {
pub allocated_stack: *const u8,
}

impl Context {
pub fn new() -> Self {
Context {
trap_frame: TrapFrame::default(),
thread_semaphore: 0,
next: core::ptr::null_mut(),
allocated_stack: core::ptr::null(),
}
}
}

pub fn task_create(
task: extern "C" fn(*mut c_types::c_void),
param: *mut c_types::c_void,
Expand Down
13 changes: 12 additions & 1 deletion esp-wifi/src/preempt/preempt_xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ pub struct Context {
pub allocated_stack: *const u8,
}

impl Context {
pub fn new() -> Self {
Context {
trap_frame: TrapFrame::new(),
thread_semaphore: 0,
next: core::ptr::null_mut(),
allocated_stack: core::ptr::null(),
}
}
}

pub fn task_create(
task: extern "C" fn(*mut c_types::c_void),
param: *mut c_types::c_void,
Expand All @@ -28,7 +39,7 @@ pub fn task_create(

// stack must be aligned by 16
let task_stack_ptr = stack as usize + task_stack_size;
let stack_ptr = task_stack_ptr - (task_stack_ptr % 0x10);
let stack_ptr = task_stack_ptr - (task_stack_ptr % 16);
(*ctx).trap_frame.A1 = stack_ptr as u32;

(*ctx).trap_frame.PS = 0x00040000 | (1 & 3) << 16; // For windowed ABI set WOE and CALLINC (pretend task was 'call4'd).
Expand Down
4 changes: 4 additions & 0 deletions hil-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,21 @@ esp32c3 = [
"esp-hal/esp32c3",
"esp-hal-embassy/esp32c3",
"esp-wifi?/esp32c3",
"esp-wifi?/phy-enable-usb",
]
esp32c6 = [
"esp-backtrace/esp32c6",
"esp-hal/esp32c6",
"esp-hal-embassy/esp32c6",
"esp-wifi?/esp32c6",
"esp-wifi?/phy-enable-usb",
]
esp32h2 = [
"esp-backtrace/esp32h2",
"esp-hal/esp32h2",
"esp-hal-embassy/esp32h2",
"esp-wifi?/esp32h2",
"esp-wifi?/phy-enable-usb",
]
esp32s2 = [
"embedded-test/xtensa-semihosting",
Expand All @@ -271,6 +274,7 @@ esp32s3 = [
"esp-hal/esp32s3",
"esp-hal-embassy/esp32s3",
"esp-wifi?/esp32s3",
"esp-wifi?/phy-enable-usb",
]
# Async & Embassy:
embassy = [
Expand Down
1 change: 0 additions & 1 deletion hil-test/tests/esp_wifi_floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

//% CHIPS: esp32 esp32s2 esp32s3
//% FEATURES: esp-wifi esp-alloc
//% FEATURES: esp-wifi esp-alloc xtensa-lx-rt/float-save-restore

#![no_std]
#![no_main]
Expand Down