Skip to content

Commit

Permalink
Merge pull request #485 from tock/api-adc-exists
Browse files Browse the repository at this point in the history
api: adc: exists needs to handle number of channels
  • Loading branch information
jrvanwhy authored Aug 8, 2023
2 parents 83bb348 + 6c49c88 commit c2917b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion apis/adc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ impl<S: Syscalls> Adc<S> {
/// Returns Ok() if the driver was present.This does not necessarily mean
/// that the driver is working.
pub fn exists() -> Result<(), ErrorCode> {
S::command(DRIVER_NUM, EXISTS, 0, 0).to_result()
// Note! The "exists" command should return directly return `Result<(),
// ErrorCode>` (i.e. with no `.and()` call), but the current ADC driver
// in the kernel returns the number of ADC channels instead of just
// success. This will be fixed in a future release of Tock, but for now
// we workaround this issue.
//
// https://github.com/tock/tock/issues/3375
S::command(DRIVER_NUM, EXISTS, 0, 0)
.to_result::<u32, ErrorCode>()
.and(Ok(()))
}

// Initiate a sample reading
Expand Down
2 changes: 1 addition & 1 deletion unittest/src/fake/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl crate::fake::SyscallDriver for Adc {

fn command(&self, command_id: u32, _argument0: u32, _argument1: u32) -> CommandReturn {
match command_id {
EXISTS => crate::command_return::success(),
EXISTS => crate::command_return::success_u32(1),

SINGLE_SAMPLE => {
if self.busy.get() {
Expand Down
4 changes: 2 additions & 2 deletions unittest/src/fake/adc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use libtock_platform::{share, DefaultConfig, YieldNoWaitReturn};
fn command() {
let adc = Adc::new();

assert!(adc.command(EXISTS, 1, 2).is_success());
assert!(adc.command(EXISTS, 1, 2).is_success_u32());

assert!(adc.command(SINGLE_SAMPLE, 0, 0).is_success());

Expand All @@ -33,7 +33,7 @@ fn kernel_integration() {
let kernel = fake::Kernel::new();
let adc = Adc::new();
kernel.add_driver(&adc);
assert!(fake::Syscalls::command(DRIVER_NUM, EXISTS, 1, 2).is_success());
assert!(fake::Syscalls::command(DRIVER_NUM, EXISTS, 1, 2).is_success_u32());
assert!(fake::Syscalls::command(DRIVER_NUM, SINGLE_SAMPLE, 0, 0).is_success());
assert_eq!(
fake::Syscalls::command(DRIVER_NUM, SINGLE_SAMPLE, 0, 0).get_failure(),
Expand Down

0 comments on commit c2917b0

Please sign in to comment.