File tree Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ feature( alloc) ]
2+ #![ no_std]
3+
4+ extern crate alloc;
5+ extern crate tock;
6+
7+ use alloc:: boxed:: Box ;
8+ use alloc:: string:: String ;
9+ use alloc:: vec:: Vec ;
10+ use tock:: console:: Console ;
11+ use tock:: ipc_cs;
12+ use tock:: ipc_cs:: ServerHandle ;
13+ use tock:: timer;
14+ use tock:: timer:: Duration ;
15+
16+ fn main ( ) {
17+ let mut buf: Box < [ u8 ] > = ipc_cs:: reserve_shared_buffer ( ) ;
18+ let mut console = Console :: new ( ) ;
19+ timer:: sleep ( Duration :: from_ms ( 3000 ) ) ;
20+
21+ console. write ( String :: from ( "[test-results]\n " ) ) ;
22+ let mut string = String :: from ( "heap_test = \" Heap " ) ;
23+ string. push_str ( "works.\" \n " ) ;
24+ console. write ( string) ;
25+
26+ let mut server = ServerHandle :: discover_service ( String :: from ( "hardware_test_server" ) ) . unwrap ( ) ;
27+ let mut payload: [ u8 ; 32 ] = [ 0 ; 32 ] ;
28+ let m = String :: from ( "client" ) ;
29+ let b = m. as_bytes ( ) ;
30+ let l = b. len ( ) ;
31+ payload[ ..l] . clone_from_slice ( b) ;
32+
33+ server. share ( & mut buf, & mut payload) ;
34+
35+ server. subscribe_callback ( |_: usize , _: usize | {
36+ let filtered = buf. to_vec ( )
37+ . iter ( )
38+ . filter ( |& x| * x != 0 )
39+ . map ( |x| * x)
40+ . collect :: < Vec < u8 > > ( ) ;
41+ let s = String :: from_utf8_lossy ( & filtered) ;
42+ console. write ( String :: from ( s) . clone ( ) ) ;
43+ console. write ( String :: from ( "test=\" done\" \n " ) ) ;
44+ } ) ;
45+ server. notify ( ) ;
46+
47+ for _ in 0 .. {
48+ timer:: sleep ( Duration :: from_ms ( 500 ) )
49+ }
50+ }
Original file line number Diff line number Diff line change 1+ #![ feature( alloc) ]
2+ #![ no_std]
3+ extern crate alloc;
4+ extern crate tock;
5+
6+ use alloc:: string:: String ;
7+ use alloc:: vec:: Vec ;
8+ use tock:: ipc_cs;
9+ use tock:: ipc_cs:: IpcServerDriver ;
10+
11+ #[ allow( unreachable_code) ]
12+ // Prints the payload and adds one to the first byte.
13+ fn main ( ) {
14+ let cb = & mut |pid : usize , _: usize , message : & mut [ u8 ] | {
15+ let filtered = message
16+ . to_vec ( )
17+ . iter ( )
18+ . filter ( |& x| * x != 0 )
19+ . map ( |x| * x)
20+ . collect :: < Vec < u8 > > ( ) ;
21+ let s = String :: from_utf8_lossy ( & filtered) ;
22+ if s == String :: from ( "client" ) {
23+ let m = String :: from ( "test_ipc = \" passed\" \n " ) ;
24+ let b = m. as_bytes ( ) ;
25+ let l = b. len ( ) ;
26+ message[ ..l] . clone_from_slice ( b) ;
27+ ipc_cs:: notify_client ( pid) ;
28+ }
29+ } ;
30+ #[ allow( unused_variables) ]
31+ let server = IpcServerDriver :: start ( cb) ;
32+
33+ loop {
34+ tock:: syscalls:: yieldk ( ) ;
35+ }
36+ server. unwrap ( ) ;
37+ }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # Examples only run on a NRF52DK board
4+
5+ set -eux
6+
7+ yes 0| tockloader uninstall --jtag --arch cortex-m4 --board nrf52-dk --jtag-device nrf52 --app-address 0x20000 || true
8+
9+ ./run_example.sh hardware_test_server --dont-clear-apps
10+ ./run_example.sh hardware_test --dont-clear-apps
You can’t perform that action at this time.
0 commit comments