==> src/hello.c <==1/* hello: the smallest mesh program, for lifecycle tests. op 0: arg * 3 + 7.
2 * View: 0x0 magic "HELO" (set by init), 0x4 last arg, 0x8 last result.
3 * Counters: 0 tasks, 1 inits.
4 * Ported from alpha-rust-mesh programs/hello/src/lib.rs. */
5#include "mesh/rt.h"
6
7#define HELLO_MAGIC 0x4f4c4548u /* "HELO" */
8
9static void hello_init(const mesh_ctx *ctx) {
10 if (mesh_ctx_leader(ctx)) {
11 mesh_ctx_set_u32(ctx, 0x0, HELLO_MAGIC);
12 mesh_ctx_count(ctx, 1, 1);
13 }
14}
15
16static uint32_t hello_task(const mesh_ctx *ctx, uint32_t op, uint32_t arg) {
17 if (op != MESH_OP_TASK) return MESH_R_BAD_OP;
18 uint32_t r = arg * 3u + 7u;
19 if (mesh_ctx_leader(ctx)) {
20 mesh_ctx_set_u32(ctx, 0x4, arg);
21 mesh_ctx_set_u32(ctx, 0x8, r);
22 mesh_ctx_count(ctx, 0, 1);
23 }
24 return r;
25}
26
27MESH_PROGRAM(hello_init, hello_task);