mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-07-14 14:34:19 +00:00
TimerService: clippy findings
Change-Id: I024582343a38760d4c83b9b78c783ea170dff1b4 GitOrigin-RevId: 24315ccd139f19ced79aaf6703530f6e56437c3c
This commit is contained in:
parent
588fb66af6
commit
c4563fabfb
@ -1,5 +1,6 @@
|
||||
//! The Timer Service provides multiplexed access to a hardware timer.
|
||||
#![no_std]
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
|
||||
use core::time::Duration;
|
||||
use kata_os_common::allocator;
|
||||
@ -10,28 +11,24 @@ use kata_timer_service::TIMER_SRV;
|
||||
use log::trace;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn pre_init() {
|
||||
pub unsafe extern "C" fn pre_init() {
|
||||
static KATA_LOGGER: KataLogger = KataLogger;
|
||||
log::set_logger(&KATA_LOGGER).unwrap();
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
|
||||
// TODO(jesionowski): temp until we integrate with seL4
|
||||
static mut HEAP_MEMORY: [u8; 4 * 1024] = [0; 4 * 1024];
|
||||
unsafe {
|
||||
allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
||||
trace!(
|
||||
"setup heap: start_addr {:p} size {}",
|
||||
HEAP_MEMORY.as_ptr(),
|
||||
HEAP_MEMORY.len()
|
||||
);
|
||||
}
|
||||
allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
||||
trace!(
|
||||
"setup heap: start_addr {:p} size {}",
|
||||
HEAP_MEMORY.as_ptr(),
|
||||
HEAP_MEMORY.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn timer__init() {
|
||||
unsafe {
|
||||
TIMER_SRV.lock().init();
|
||||
}
|
||||
pub unsafe extern "C" fn timer__init() {
|
||||
TIMER_SRV.lock().init();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@ -39,63 +36,61 @@ extern "C" {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn timer_completed_timers() -> u32 {
|
||||
unsafe {
|
||||
let client_id = timer_get_sender_id();
|
||||
return TIMER_SRV.lock().completed_timers(client_id);
|
||||
}
|
||||
pub unsafe extern "C" fn timer_completed_timers() -> u32 {
|
||||
let client_id = timer_get_sender_id();
|
||||
return TIMER_SRV.lock().completed_timers(client_id);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn timer_oneshot(timer_id: TimerId, duration_ms: u32) -> TimerServiceError {
|
||||
pub unsafe extern "C" fn timer_oneshot(
|
||||
timer_id: TimerId,
|
||||
duration_ms: u32
|
||||
) -> TimerServiceError {
|
||||
let duration = Duration::from_millis(duration_ms as u64);
|
||||
let is_periodic = false;
|
||||
unsafe {
|
||||
let client_id = timer_get_sender_id();
|
||||
match TIMER_SRV
|
||||
.lock()
|
||||
.add(client_id, timer_id, duration, is_periodic)
|
||||
{
|
||||
Err(e) => e,
|
||||
Ok(()) => TimerServiceError::TimerOk,
|
||||
}
|
||||
let client_id = timer_get_sender_id();
|
||||
match TIMER_SRV
|
||||
.lock()
|
||||
.add(client_id, timer_id, duration, is_periodic)
|
||||
{
|
||||
Err(e) => e,
|
||||
Ok(()) => TimerServiceError::TimerOk,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn timer_periodic(timer_id: TimerId, duration_ms: u32) -> TimerServiceError {
|
||||
pub unsafe extern "C" fn timer_periodic(
|
||||
timer_id: TimerId,
|
||||
duration_ms: u32
|
||||
) -> TimerServiceError {
|
||||
let duration = Duration::from_millis(duration_ms as u64);
|
||||
let is_periodic = true;
|
||||
unsafe {
|
||||
let client_id = timer_get_sender_id();
|
||||
match TIMER_SRV
|
||||
.lock()
|
||||
.add(client_id, timer_id, duration, is_periodic)
|
||||
{
|
||||
Err(e) => e,
|
||||
Ok(()) => TimerServiceError::TimerOk,
|
||||
}
|
||||
let client_id = timer_get_sender_id();
|
||||
match TIMER_SRV
|
||||
.lock()
|
||||
.add(client_id, timer_id, duration, is_periodic)
|
||||
{
|
||||
Err(e) => e,
|
||||
Ok(()) => TimerServiceError::TimerOk,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn timer_cancel(timer_id: TimerId) -> TimerServiceError {
|
||||
unsafe {
|
||||
let client_id = timer_get_sender_id();
|
||||
match TIMER_SRV.lock().cancel(client_id, timer_id) {
|
||||
Err(e) => e,
|
||||
Ok(()) => TimerServiceError::TimerOk,
|
||||
}
|
||||
pub unsafe extern "C" fn timer_cancel(
|
||||
timer_id: TimerId
|
||||
) -> TimerServiceError {
|
||||
let client_id = timer_get_sender_id();
|
||||
match TIMER_SRV.lock().cancel(client_id, timer_id) {
|
||||
Err(e) => e,
|
||||
Ok(()) => TimerServiceError::TimerOk,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn timer_interrupt_handle() {
|
||||
pub unsafe extern "C" fn timer_interrupt_handle() {
|
||||
extern "C" {
|
||||
fn timer_interrupt_acknowledge() -> u32;
|
||||
}
|
||||
unsafe {
|
||||
TIMER_SRV.lock().service_interrupt();
|
||||
}
|
||||
assert!(unsafe { timer_interrupt_acknowledge() == 0 });
|
||||
TIMER_SRV.lock().service_interrupt();
|
||||
assert!(timer_interrupt_acknowledge() == 0);
|
||||
}
|
||||
|
@ -72,8 +72,7 @@ impl KataTimerService {
|
||||
if self
|
||||
.events
|
||||
.iter()
|
||||
.find(|(_, ev)| ev.client_id == client_id && ev.timer_id == timer_id)
|
||||
.is_some()
|
||||
.any(|(_, ev)| ev.client_id == client_id && ev.timer_id == timer_id)
|
||||
{
|
||||
return Err(TimerServiceError::TimerAlreadyExists);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user