Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event vs Hook API approach #26

Open
dave2 opened this issue Jul 1, 2014 · 0 comments
Open

Event vs Hook API approach #26

dave2 opened this issue Jul 1, 2014 · 0 comments

Comments

@dave2
Copy link
Owner

dave2 commented Jul 1, 2014

The current API model is to have a function hook specified as part of the setup or configuration functions, for example timer_init(timer_c0,timer_norm,31999,NULL,&timer_overflow_hook); where timer_overflow_hook is a user-defined function to do something on overflow.

This means for an interrupt we do a bunch of checking at run-time if the hook is defined, and then invoke it via the function pointer.

Some APIs instead use weak bound functions to provide an "event" system that you can simply define a function to handle, and the default function is to do nothing. So instead of passing the function pointer above, you would just provide a function in your code:

void EVENT_timer_c0_ovf(void) { ... }

As the event is defined in the library as weak, it should be replaced by the user function at linking.

I am not sure, however, if the pre-compiled objects in libkakapo.a can still be weakly linked so they can be replaced when final linking happens. It may depend on LTO, which is only in recent (>=4.8) avr-gcc versions, and may be a little buggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant