You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tock_workshop/index.md
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,3 +245,69 @@ pub unsafe fn main() {
245
245
// ...
246
246
}
247
247
```
248
+
249
+
### Writing an application
250
+
251
+
To test the capsule we just created, we will need an application. This app will check if the driver is present in the kernel configuration, then it will issue a *"print"* command to the driver every second.
252
+
253
+
The simplest way to do this is to create a new entry in the `examples` directory, then import the `Makefile` from the `blink` example. We will also need to create an API for issuing commands to the capsule. This is usually done in a separate `.c` file, and further exposed in a header file to be used by application developers, but for the task at hand, defining them in `main.c` will work.
254
+
255
+
```c title="examples/ws-mock-test/main.c"
256
+
#include<libtock/tock.h>
257
+
258
+
#defineMOCK_DRIVER_NUM 0x9000A
259
+
#define MOCK_EXIST 0x0
260
+
#define MOCK_PRINT 0x1
261
+
262
+
intcheck_mock_driver_exists(void);
263
+
int mock_print(void);
264
+
265
+
int check_mock_driver_exists(void) {
266
+
syscall_return_t ret = command(MOCK_DRIVER_NUM, MOCK_EXIST, 0, 0);
The `syscall_return_t` type is the representation of the `CommandReturn` type seen in kernel. Tock supports returning either a success or error response to system calls, along with a payload of up to two `u32`s in size. The developer must be aware of the return type used by a respective command of a driver to correctly decode the response message. In our case, both commands used return no payload so the `tock_command_return_novalue_to_returncode`.
281
+
:::
282
+
283
+
Now, we need to complete the implementation of the main function.
284
+
285
+
```c title="example/ws-mock-test/main.c"
286
+
#include <libtock/tock.h>
287
+
288
+
#include <libtock-sync/services/alarm.h>
289
+
290
+
// Headers for `printf`
291
+
#include <stdio.h>
292
+
#include <stdlib.h>
293
+
#include <string.h>
294
+
#include <unistd.h>
295
+
296
+
// ...
297
+
298
+
int main(void) {
299
+
printf("Mock capsule test\n");
300
+
301
+
int err = check_mock_driver_exists();
302
+
if (err < 0) {
303
+
printf("Mock capsule missing");
304
+
return err;
305
+
}
306
+
307
+
while (true) {
308
+
mock_print();
309
+
// This delay uses an underlying alarm in the kernel.
0 commit comments