Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
14 changes: 3 additions & 11 deletions capsules/src/buzzer_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

use core::cmp;

use core::convert::TryFrom;
use core::mem;
use kernel::common::cells::OptionalCell;
use kernel::hil;
Expand Down Expand Up @@ -235,21 +234,14 @@ impl<'a, A: hil::time::Alarm<'a>> Driver for Buzzer<'a, A> {
1 => {
let frequency_hz = data1;
let duration_ms = cmp::min(data2, self.max_duration_ms);
let res = self.enqueue_command(
self.enqueue_command(
BuzzerCommand::Buzz {
frequency_hz,
duration_ms,
},
appid,
);
match res {
ReturnCode::SUCCESS => CommandResult::success(),
ReturnCode::SuccessWithValue { value } => {
CommandResult::success_u32(value as u32)
}
// unwrap may be used as res cannot be SUCCESS or SuccessWithValue
_ => CommandResult::failure(ErrorCode::try_from(res).unwrap()),
}
)
.into()
}

_ => CommandResult::failure(ErrorCode::NOSUPPORT),
Expand Down
8 changes: 2 additions & 6 deletions capsules/src/fm25cl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ impl<'a, S: hil::spi::SpiMasterDevice> FM25CL<'a, S> {
let res = self.spi.read_write_bytes(txbuffer, None, 1);
match res {
ReturnCode::SUCCESS => Ok(()),
rc => Err(rc
.try_into()
.expect("SPI read_write_bytes: unexpected SuccessWithValue")),
rc => Err(rc.try_into().unwrap()),
}
})
}
Expand Down Expand Up @@ -192,9 +190,7 @@ impl<'a, S: hil::spi::SpiMasterDevice> FM25CL<'a, S> {
.read_write_bytes(txbuffer, Some(rxbuffer), read_len + 3);
match res {
ReturnCode::SUCCESS => Ok(()),
rc => Err(rc
.try_into()
.expect("SPI read_write_bytes: unexpected SuccessWithValue")),
rc => Err(rc.try_into().unwrap()),
}
})
})
Expand Down
2 changes: 1 addition & 1 deletion capsules/src/net/udp/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl<'a> Driver for UDPDriver<'a> {
/// transmit can produce two different success values. If success is returned,
/// this simply means that the packet was queued. In this case, the app still
/// still needs to wait for a callback to check if any errors occurred before
/// the packet was passed to the radio. However, if SuccessWithValue
/// the packet was passed to the radio. However, if Success_U32
/// is returned with value 1, this means the the packet was successfully passed
/// the radio without any errors, which tells the userland application that it does
/// not need to wait for a callback to check if any errors occured while the packet
Expand Down
1 change: 0 additions & 1 deletion doc/Syscalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ in C from the `tock.h` header (prepended with `TOCK_`):

```rust
pub enum ReturnCode {
SuccessWithValue { value: usize }, // Success value must be >= 0
SUCCESS,
FAIL, //.......... Generic failure condition
EBUSY, //......... Underlying system is busy; retry
Expand Down
3 changes: 0 additions & 3 deletions kernel/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ impl From<ReturnCode> for CommandResult {
fn from(rc: ReturnCode) -> Self {
match rc {
ReturnCode::SUCCESS => CommandResult::success(),
ReturnCode::SuccessWithValue { .. } => {
panic!("SuccessWithValue is deprecated");
} //TODO: delete before Tock 2.0
_ => CommandResult::failure(ErrorCode::try_from(rc).unwrap()),
}
}
Expand Down
1 change: 0 additions & 1 deletion kernel/src/errorcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl TryFrom<ReturnCode> for ErrorCode {

fn try_from(rc: ReturnCode) -> Result<Self, Self::Error> {
match rc {
ReturnCode::SuccessWithValue { .. } => Err(()),
ReturnCode::SUCCESS => Err(()),
ReturnCode::FAIL => Ok(ErrorCode::FAIL),
ReturnCode::EBUSY => Ok(ErrorCode::BUSY),
Expand Down
4 changes: 1 addition & 3 deletions kernel/src/returncode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

/// Standard return errors in Tock.
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(isize)] // Code size optimization compared to #[repr(rust)]
pub enum ReturnCode {
/// Success value must be positive
SuccessWithValue { value: usize }, //TODO: Remove before Tock 2.0
/// Operation completed successfully
SUCCESS,
/// Generic failure condition
Expand Down Expand Up @@ -42,7 +41,6 @@ pub enum ReturnCode {
impl From<ReturnCode> for isize {
fn from(original: ReturnCode) -> isize {
match original {
ReturnCode::SuccessWithValue { value } => value as isize,
Copy link
Contributor

Choose a reason for hiding this comment

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

HURRAY!

ReturnCode::SUCCESS => 0,
ReturnCode::FAIL => -1,
ReturnCode::EBUSY => -2,
Expand Down