I am working on an event driven portion of a project utilizing the use of the Zephyr Project. I am relatively new to Zephyr so I apologize if I am going about this wrong. My goal is to have a forever thread responsible for determining if any events have occurred. In the ESP-IDF I had done this by having task handlers monitor for interrupts and then set each individual event bit in an event group and have a main task poll constantly for those event flags.
I would like to have something similar be done in the Zephyr OS but am having trouble getting there. I have gotten threads to run and monitor for button pushes and set specific GPIOs high but want to transition into working with k_event.
For example K_EVENT_DEFINE(event_flag);
is how I am setting up an event struct following Zephyr's documentation. I am then using:
static void detect_press_open(void *args)
{
gpio_pin_configure_dt(&led1, GPIO_OUTPUT);
gpio_pin_configure_dt(&button1, GPIO_INPUT);
while(1)
{
if (gpio_pin_get_dt(&button1) != 0)
{
printf("Button1 press open detected\n");
gpio_pin_set_dt(&led1, 1);
k_event_post(&event_flag, 1);
}
else{
gpio_pin_set_dt(&led1, 0);
}
k_msleep(1000);
//need to have thread yield
}
}
This is an example function I am using to take the button press from turning on an led to essentially triggering an event that will then be checked by a thread to poll for the event and handle setting the GPIO to high.
When I attempt to build this in terminal I get this error src/main.c:92: undefined reference to z_impl_k_event_post collect2: error: ld returned 1 exit status
.
To try to sum it up and be more clear.
I would like to have a nudge in the right direction as to how to develop an event driven system in the Zephyr OS. As in should I use Queues and Semaphores, or stick with Events or use Polling?
If I am to use k_events, how would I solve the error I am getting?
Am I making any sense or do I need to restructure my question?
I had the same compiler error with usage of k_event_post, k_event_wait, and k_event_set and found that it was due to the kconfig option CONFIG_EVENTS=y not being set. Hope this helps anyone in the future.