Skip to content

Commit a23b2d3

Browse files
committed
architecture WIP
1 parent 86ba8b1 commit a23b2d3

1 file changed

Lines changed: 61 additions & 2 deletions

File tree

docs/tock_workshop/index.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,65 @@ pipx ensurepath
5858

5959
TODO: add board description and features
6060

61-
## Tock OS
61+
## Tock
6262

63-
TODO: add overview
63+
Tock is an open-source embedded operating system for microcontrollers written in Rust. The operating system is designed to isolate components so untrusted third-party applications can run in a protected environment. Tock supports multiple platforms, such as RISC-V, Cortex-M or X86.
64+
65+
### Architecture
66+
67+
Tock uses a microkernel architecture: complex drivers and services are often implemented as untrusted processes, which other processes, such as applications, can invoke through inter-process communication (IPC).
68+
Tock supports running multiple, independent applications written in any compiled language.
69+
70+
![Tock stack](https://book.tockos.org/imgs/tock-stack.png)
71+
72+
The above Figure shows Tock's architecture. Code falls into one of three categories: the **core kernel**, **capsules**, and **processes**.
73+
74+
The core kernel and capsules are both written in Rust. Rust is a type-safe systems language; other documents discuss the language and its implications to kernel design in greater detail, but the key idea is that Rust code can't use memory differently than intended (e.g., overflow buffers, forge pointers, or have pointers to dead stack frames). Because these restrictions prevent many things that an OS kernel has to do (such as access a peripheral that exists at a memory address specified in a datasheet), the very small core kernel is allowed to break them by using *"unsafe"* Rust code. Capsules, however, cannot use unsafe features. This means that the core kernel code is very small and carefully written, while new capsules added to the kernel are safe code and so do not have to be trusted.
75+
76+
Processes can be written in any language. The kernel protects itself and other processes from bad process code by using a hardware memory protection unit (MPU). If a process tries to access memory it's not allowed to, this triggers an exception. The kernel handles this exception and kills the process.
77+
78+
The kernel provides four major system calls:
79+
80+
* `command`: makes a call from the process into the kernel
81+
* `subscribe`: registers a callback in the process for an upcall from the kernel
82+
* `allow`: gives kernel access to memory in the process
83+
* `yield`: suspends process until after a callback is invoked
84+
85+
Every system call except yield is non-blocking. Commands that might take a long time (such as sending a message over a UART) return immediately and issue a callback when they complete. The yield system call blocks the process until a callback is invoked; userland code typically implements blocking functions by invoking a command and then using yield to wait until the callback completes.
86+
87+
The command, subscribe, and allow system calls all take a driver ID as their first parameter. This indicates which driver in the kernel that system call is intended for. Drivers are capsules that implement the system call.
88+
89+
### Capsule
90+
91+
A capsule is a kernel component acting as a device driver, or system service capsule. Capsules sit between the low-level drivers of the core kernel and use the HIL traits to interact with them, and the userspace applications, which utilize the `Syscall` interface.
92+
93+
## Hands-on Workshop
94+
95+
### Flashing the kernel
96+
97+
Initially, you will need to clone the Tock [repository](https://example.com). To compile the board kernel, you can use the `cargo flash` utility.
98+
99+
```shell
100+
cd boards/cy8cproto_62_4343_w
101+
cargo flash
102+
```
103+
104+
If you did everything correctly, you should be able to use the `tockloader listen` command to interact with the kernel. When prompted to select a serial port, pick the one that ends with `KitProg3 CMSIS-DAP`.
105+
106+
```shell
107+
tockloader listen
108+
[INFO ] No device name specified. Using default name "tock".
109+
[INFO ] No serial port with device name "tock" found.
110+
[INFO ] Found 2 serial ports.
111+
Multiple serial port options found. Which would you like to use?
112+
[0] /dev/cu.debug-console - n/a
113+
[1] /dev/cu.usbmodem1103 - KitProg3 CMSIS-DAP
114+
115+
Which option? [0] 1
116+
[INFO ] Using "/dev/cu.usbmodem1103 - KitProg3 CMSIS-DAP".
117+
[INFO ] Listening for serial output
118+
119+
$tock
120+
```
121+
122+
### Compiling an application

0 commit comments

Comments
 (0)