Skip to content

Commit

Permalink
Implement gettimeofday and __assert_func (esp-rs#304)
Browse files Browse the repository at this point in the history
* Implement gettimeofday

* Implement __assert_func

* Reimplement log_timestamp
  • Loading branch information
bugadani authored and bjoernQ committed May 23, 2024
1 parent 120311d commit 29cc491
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions esp-wifi/src/common_adapter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::binary::include::esp_event_base_t;
use crate::binary::include::esp_timer_create_args_t;
use crate::binary::include::esp_timer_get_time;
use crate::binary::include::esp_timer_handle_t;
use crate::binary::include::timeval;

use crate::compat::common::*;
use crate::compat::timer_compat::*;

use crate::hal;

use esp_wifi_sys::include::timespec;
use hal::system::RadioClockControl;
use hal::Rng;

Expand Down Expand Up @@ -373,12 +377,23 @@ static mut WIFI_EVENT: esp_event_base_t = unsafe { &EVT };
// stuff needed by wpa-supplicant
#[no_mangle]
pub unsafe extern "C" fn __assert_func(
_file: *const u8,
_line: u32,
_func: *const u8,
_failed_expr: *const u8,
file: *const u8,
line: u32,
func: *const u8,
failed_expr: *const u8,
) {
todo!("__assert_func");
let file = str_from_c(file);
let (func_pre, func) = if func.is_null() {
("", "")
} else {
(", function: ", str_from_c(func))
};
let expr = str_from_c(failed_expr);

panic!(
"assertion \"{}\" failed: file \"{}\", line {}{}{}",
expr, file, line, func_pre, func
);
}

#[no_mangle]
Expand Down Expand Up @@ -410,8 +425,16 @@ pub unsafe extern "C" fn ets_timer_arm(
}

#[no_mangle]
pub unsafe extern "C" fn gettimeofday(_tv: *const (), _tz: *const ()) {
todo!("gettimeofday");
pub unsafe extern "C" fn gettimeofday(tv: *mut timespec, _tz: *mut ()) -> i32 {
if !tv.is_null() {
unsafe {
let microseconds = esp_timer_get_time();
(*tv).tv_sec = (microseconds / 1_000_000) as i32;
(*tv).tv_nsec = (microseconds % 1_000_000) as i32 * 1000;
}
}

0
}

#[no_mangle]
Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/src/wifi/os_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ pub unsafe extern "C" fn log_writev(
*
****************************************************************************/
pub unsafe extern "C" fn log_timestamp() -> u32 {
(crate::timer::get_systimer_count() / (crate::timer::TICKS_PER_SECOND / 1_000)) as u32
crate::current_millis() as u32
}

/****************************************************************************
Expand Down

0 comments on commit 29cc491

Please sign in to comment.