Skip to main content

counter-alarm

Open a counter, set an alarm for N ticks in the future, fire a callback. The minimal demo for <alp/counter.h>.

Source: examples/counter-alarm/.

board.yaml

som:
sku: E1M-AEN701

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: [counter]

diagnostics:
log_level: info

Source (abbreviated)

#include <alp/counter.h>
#include <alp/e1m_pinout.h>

static void on_alarm(alp_counter_t *c, uint32_t ticks, void *user) {
printk("[counter] alarm fired at ticks=%u\n", ticks);
}

int main(void) {
alp_counter_t *cnt = alp_counter_open(&(alp_counter_config_t){
.counter_id = ALP_E1M_COUNTER0,
});
if (cnt == NULL) return -1;

alp_counter_start(cnt);
alp_counter_set_alarm(cnt, /* ticks_from_now */ 1000000u, on_alarm, NULL);

k_msleep(2000);
alp_counter_close(cnt);
return 0;
}

See also

Questions about this page? Discuss in Community Forum