Replies: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
This waits for the button press event and ignores the timer event. You can't get past this line, unless you make it wait for either event. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I am trying to implement state machine in Zephyr using stm32f3 discovery board. I used the state machine example from the zephyr web page and added another state. In the new state I want the code to go back to the state 0 after the timer interrupt occurs. I have placed
k_event_post function in the work handler function for the timer interrupt. Interrupt occurs on time, but the state does not switch. Instead, it gets stuck in state 2 forever, even though interrupt occurs every 5s.
FSM & Events zephyr rtos stm32f3 discovery board
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/smf.h>
#include <zephyr/device.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/printk.h>
#include <inttypes.h>
#define SW0_NODE DT_ALIAS(sw0)
#define SLEEP_TIME_MS 1
/* List of events */
#define EVENT_BTN_PRESS 1
#define EVENT_TIMER 1
static const struct gpio_dt_spec button =
GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0});
static struct gpio_callback button_cb_data;
/* Forward declaration of state table */
static const struct smf_state demo_states[];
/* List of demo states */
enum demo_state { S0, S1 , S2};
/* User defined object /
static struct s_object {
/ This must be first */
struct smf_ctx ctx;
} s_obj;
void my_work_handler(struct k_work *work){
//gpio_pin_toggle_dt(&led);
//gpio_pin_toggle_dt(&led1);
printf("Timer interrupt!\n");
k_event_post(&s_obj.smf_event, EVENT_TIMER);
}
K_WORK_DEFINE(my_work, my_work_handler);
void my_timer_handler(struct k_timer *dummy)
{
k_work_submit(&my_work);
}
K_TIMER_DEFINE(my_timer, my_timer_handler, NULL);
/* State S0 */
static void s0_entry(void *o)
{
printk("STATE0\n");
}
static void s0_run(void *o)
{
struct s_object *s = (struct s_object *)o;
}
/* State S1 */
static void s1_entry(void *o)
{
printk("STATE1\n");
}
static void s1_run(void *o)
{
struct s_object *s = (struct s_object *)o;
}
/* State S2 */
static void s2_entry(void *o)
{
printk("STATE2\n");
}
static void s2_run(void *o)
{
struct s_object *s = (struct s_object *)o;
}
/* Populate state table */
static const struct smf_state demo_states[] = {
[S0] = SMF_CREATE_STATE(s0_entry, s0_run, NULL),
[S1] = SMF_CREATE_STATE(s1_entry, s1_run, NULL),
[S2] = SMF_CREATE_STATE(s2_entry, s2_run, NULL),
};
void button_pressed(const struct device *dev,
struct gpio_callback cb, uint32_t pins)
{
/ Generate Button Press Event */
k_event_post(&s_obj.smf_event, EVENT_BTN_PRESS);
}
int main(void)
{
k_timer_start(&my_timer, K_SECONDS(5), K_SECONDS(5));
}
Expected behavior
When the system is in the state 2 it should wait for the timer interrupt and then go to the state 0.
Environment (please complete the following information):
OS: Ubuntu
Board: STM32F3 DISCOVERY
Beta Was this translation helpful? Give feedback.
All reactions