Skip to content

Commit

Permalink
Fix init order
Browse files Browse the repository at this point in the history
Signed-off-by: Gerson Fernando Budke <[email protected]>
  • Loading branch information
nandojve authored and otavio committed Aug 8, 2024
1 parent aa4a88a commit 3643c9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
24 changes: 12 additions & 12 deletions samples/subsys/zephyrbt/dynamic/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ tests:
- "D: eval delay \\[decorator, 13\\]"
- "D: Deep: 1"
- "D: delay \\[decorator, 13\\]"
- "W: zephyrbt_action_ask_for_help_init stub function"
- "D: init: timeout \\[decorator, 1\\]"
- "W: zephyrbt_action_place_ball_init stub function"
- "W: zephyrbt_condition_ball_placed_init stub function"
- "W: zephyrbt_action_approch_bin_init stub function"
- "W: zephyrbt_condition_bin_close_init stub function"
- "W: zephyrbt_action_grasp_ball_init stub function"
- "W: zephyrbt_condition_ball_grasped_init stub function"
- "W: zephyrbt_action_approch_ball_init stub function"
- "W: zephyrbt_condition_ball_close_init stub function"
- "W: zephyrbt_action_find_ball_init stub function"
- "W: zephyrbt_condition_ball_found_init stub function"
- "D: init: delay \\[decorator, 19\\]"
- "W: zephyrbt_condition_ball_found_init stub function"
- "W: zephyrbt_action_find_ball_init stub function"
- "W: zephyrbt_condition_ball_close_init stub function"
- "W: zephyrbt_action_approch_ball_init stub function"
- "W: zephyrbt_condition_ball_grasped_init stub function"
- "W: zephyrbt_action_grasp_ball_init stub function"
- "W: zephyrbt_condition_bin_close_init stub function"
- "W: zephyrbt_action_approch_bin_init stub function"
- "W: zephyrbt_condition_ball_placed_init stub function"
- "W: zephyrbt_action_place_ball_init stub function"
- "D: init: timeout \\[decorator, 1\\]"
- "W: zephyrbt_action_ask_for_help_init stub function"
- "D: tick"
- "D: eval delay \\[decorator, 19\\]"
- "D: Deep: 1"
Expand Down
25 changes: 15 additions & 10 deletions subsys/zephyrbt/zephyrbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,28 @@ void zephyrbt_thread_func(void *zephyrbt_ctx, void *, void *)
}

#if defined(CONFIG_ZEPHYR_BEHAVIOUR_TREE_NODE_INIT)
int i = 0;
struct zephyrbt_node *root = zephyrbt_get_root(ctx);
struct zephyrbt_node *self = zephyrbt_get_node(ctx, i);
/*
* Initialization must be in the reverse order to ensure that
* dependencies will be initialized first. This allow a global
* context to be initialized at root or as close as root possible.
*/
for (int i = ctx->nodes - 1; i >= 0; --i) {
struct zephyrbt_node *self = zephyrbt_get_node(ctx, i);

if (self == NULL) {
LOG_ERR("Node %d is invalid", i);
continue;
}

while (self != NULL) {
#if defined(CONFIG_ZEPHYR_BEHAVIOUR_TREE_NODE_CONTEXT)
self->ctx = NULL;
#endif
if (self->init != NULL) {
self->init(ctx, self);
}

if (self == root) {
break;
if (self->init == NULL) {
continue;
}

self = zephyrbt_get_node(ctx, ++i);
self->init(ctx, self);
}
#endif

Expand Down

0 comments on commit 3643c9e

Please sign in to comment.