-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.rs
69 lines (61 loc) · 1.69 KB
/
gpio.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use super::*;
use lc3_traits::peripherals::gpio::{Gpio, GpioPin, GpioState};
use GpioState::*;
use GpioPin::*;
mod states {
use super::*;
single_test! {
input,
insns: [
{ AND R0, R0, #0 },
{ TRAP #0x30 },
{ TRAP #0x25 },
],
post: |i| {
let p = i.get_peripherals();
eq!(Gpio::get_state(p, G0), Input);
},
with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR
}
single_test! {
output,
insns: [
{ AND R0, R0, #0 },
{ TRAP #0x31 },
{ TRAP #0x25 },
],
post: |i| {
let p = i.get_peripherals();
eq!(Gpio::get_state(p, G0), Output);
},
with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR
}
// TODO: TRAP x32 -- INTERRUPT (requires triggering Gpio interrupt externally)
single_test! {
disabled,
insns: [
{ AND R0, R0, #0 },
{ TRAP #0x33 },
{ TRAP #0x25 },
],
pre: |p| { Gpio::set_state(p, G0, Output).unwrap() },
post: |i| {
let p = i.get_peripherals();
eq!(Gpio::get_state(p, G0), Disabled);
},
with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR
}
single_test! {
get_mode,
prefill: { 0x3004: 0 },
insns: [
{ AND R0, R0, #0 },
{ TRAP #0x34 },
{ ST R0, #1 },
{ TRAP #0x25 },
],
pre: |p| { Gpio::set_state(p, G0, Output).unwrap() },
post: |i| { eq!(i.get_word_unchecked(0x3004), 1); },
with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR
}
}