Skip to content

Commit

Permalink
Make RIOT examples compatible with new macros
Browse files Browse the repository at this point in the history
  • Loading branch information
LasseRosenow committed Oct 23, 2024
1 parent 50c59b8 commit 2ce4aa8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
21 changes: 15 additions & 6 deletions examples/riot/blinky/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,42 @@
#include "reactor-uc/reactor-uc.h"
#include <inttypes.h>

DEFINE_TIMER(MyTimer, 1, MSEC(0), MSEC(100))
DEFINE_REACTION(MyReactor, 0, 0)
/* Structs */
DEFINE_TIMER_STRUCT(MyTimer, 1)
DEFINE_REACTION_STRUCT(MyReactor, 0, 0)

typedef struct {
Reactor super;
MyReactor_0 my_reaction;
MyReactor_Reaction0 my_reaction;
MyTimer timer;
Reaction *_reactions[1];
Trigger *_triggers[1];
} MyReactor;

REACTION_BODY(MyReactor, 0, {
/* Reaction Bodies */
DEFINE_REACTION_BODY(MyReactor, 0) {
MyReactor *self = (MyReactor *)_self->parent;
Environment *env = self->super.env;
LED0_TOGGLE;
printf("Hello World @ %" PRId64 "\n", env->get_elapsed_physical_time(env));
})
}

/* Constructors */
DEFINE_TIMER_CTOR_FIXED(MyTimer, 1, MSEC(0), MSEC(100))
DEFINE_REACTION_CTOR(MyReactor, 0)

void MyReactor_ctor(MyReactor *self, Environment *env) {
self->_reactions[0] = (Reaction *)&self->my_reaction;
self->_triggers[0] = (Trigger *)&self->timer;

Reactor_ctor(&self->super, "MyReactor", env, NULL, NULL, 0, self->_reactions, 1, self->_triggers, 1);
MyReactor_0_ctor(&self->my_reaction, &self->super);
MyReactor_Reaction0_ctor(&self->my_reaction, &self->super);
MyTimer_ctor(&self->timer, &self->super);

TIMER_REGISTER_EFFECT(self->timer, self->my_reaction);
}

/* Application */
ENTRY_POINT(MyReactor, FOREVER, true)

int main(void) {
Expand Down
20 changes: 15 additions & 5 deletions examples/riot/hello/main.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
#include "reactor-uc/reactor-uc.h"
#include <inttypes.h>

DEFINE_TIMER(MyTimer, 1, 0, MSEC(100))
DEFINE_REACTION(MyReactor, 0, 0)
/* Structs */
DEFINE_TIMER_STRUCT(MyTimer, 1)
DEFINE_REACTION_STRUCT(MyReactor, 0, 0)

typedef struct {
Reactor super;
MyReactor_0 my_reaction;
MyReactor_Reaction0 my_reaction;
MyTimer timer;
Reaction *_reactions[1];
Trigger *_triggers[1];
} MyReactor;

REACTION_BODY(MyReactor, 0, { printf("Hello World @ %lld\n", env->get_elapsed_logical_time(env)); })
/* Reaction Bodies */
DEFINE_REACTION_BODY(MyReactor, 0) {
Environment *env = _self->parent->env;
printf("Hello World @ %" PRIi64 "\n", env->get_elapsed_logical_time(env));
}

/* Constructors */
DEFINE_TIMER_CTOR_FIXED(MyTimer, 1, 0, MSEC(100))
DEFINE_REACTION_CTOR(MyReactor, 0)

void MyReactor_ctor(MyReactor *self, Environment *env) {
self->_reactions[0] = (Reaction *)&self->my_reaction;
self->_triggers[0] = (Trigger *)&self->timer;
Reactor_ctor(&self->super, "MyReactor", env, NULL, NULL, 0, self->_reactions, 1, self->_triggers, 1);
MyReactor_0_ctor(&self->my_reaction, &self->super);
MyReactor_Reaction0_ctor(&self->my_reaction, &self->super);
Timer_ctor(&self->timer.super, &self->super, MSEC(0), MSEC(100), self->timer.effects, 1);
TIMER_REGISTER_EFFECT(self->timer, self->my_reaction);
}

/* Application */
ENTRY_POINT(MyReactor, FOREVER, true)

int main() {
Expand Down

0 comments on commit 2ce4aa8

Please sign in to comment.