Skip to content

YWF: Convert many more drivers#568

Merged
brghena merged 7 commits into
masterfrom
dev/ywf-remaining
Jul 2, 2026
Merged

YWF: Convert many more drivers#568
brghena merged 7 commits into
masterfrom
dev/ywf-remaining

Conversation

@bradjc

@bradjc bradjc commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Mostly done with Claude.

Want to see what happens with CI, and then try to test some of these changes.

@bradjc
bradjc force-pushed the dev/ywf-remaining branch from 7295c63 to b0c05bd Compare April 24, 2026 17:55
Using YWF with alarm is more nuanced because users might reasonably
expect to have both periodic timers and do a delay_ms.
@bradjc

bradjc commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

I reverted the changes to alarm.c as alarm needs more thought.

@bradjc

bradjc commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Ok I've tested a bunch of these, including the sensors using the hail app and the kv test app.

alevy
alevy previously approved these changes Jun 23, 2026

@brghena brghena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I read through all of this.

One tiny nit. Also two places where I'm very confused about the resulting behavior and I think something is wrong (although not necessarily this PR's fault or responsibility to fix).

Comment thread libtock-sync/interface/button.h
Comment thread libtock-sync/net/ieee802154.c
Comment thread libtock-sync/net/udp.c
Comment on lines 7 to +19
@@ -21,13 +13,8 @@ bool libtocksync_app_state_exists(void) {
returncode_t libtocksync_app_state_save(void) {
returncode_t err;

result.fired = false;

err = libtock_app_state_save(app_state_cb);
err = libtock_app_state_save(app_state_noop_cb);
if (err != RETURNCODE_SUCCESS) return err;

// Wait for the callback.
yield_for(&result.fired);

return result.ret;
return libtocksync_app_state_yield_wait_for();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong to me. There's a return code that's getting dropped here. Shouldn't that be in the ywf data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so this won't likely result in a bug. But it still seems weird to me that we're both registering for a callback and calling yield_wait_for.

Shouldn't we just be calling libtock_app_state_command_save() directly? https://github.com/tock/libtock-c/blob/master/libtock/storage/app_state.c#L61 (I guess with the init check before it)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't suggest here, but I think the code would be:

returncode_t libtocksync_app_state_save(void) {
  returncode_t err;

  if (!_app_state_inited) {
    err = app_state_init();
    if (err != RETURNCODE_SUCCESS) return err;
  }

  err = libtock_app_state_command_save((uint32_t) _app_state_flash_pointer);
  if (err != RETURNCODE_SUCCESS) return err;

  return libtocksync_app_state_yield_wait_for();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But app_state_init is static. Using the libtock function with a noop callback avoids copying or exposing the init function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think that a refactor would improve the app state driver, but that's out-of-scope for this PR

Co-authored-by: Branden Ghena <branden.ghena@gmail.com>
@brghena
brghena added this pull request to the merge queue Jul 2, 2026
Merged via the queue into master with commit 8948609 Jul 2, 2026
6 checks passed
@brghena
brghena deleted the dev/ywf-remaining branch July 2, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants