4343/* Private macro -------------------------------------------------------------*/
4444
4545/* Private function prototypes -----------------------------------------------*/
46- static int get_next_state (fsm_trans_list_t * trans_list , int current_state ,
47- uint32_t elapsed_ms );
48- static void execute_action (int current_state , fsm_actions_list_t * actions_list ,
46+ static uint8_t get_next_state (fsm_trans_list_t * trans_list ,
47+ uint8_t current_state , uint32_t elapsed_ms );
48+ static void execute_action (uint8_t current_state ,
49+ fsm_actions_list_t * actions_list ,
4950 fsm_action_type_t type );
5051static bool eval_events (fsm_trans_t * trans );
5152static bool eval_timeout (fsm_trans_t * trans , uint32_t elapsed_time );
@@ -56,7 +57,7 @@ static bool eval_timeout(fsm_trans_t *trans, uint32_t elapsed_time);
5657/**
5758 * @brief Function to initialize a FSM instance.
5859 */
59- fsm_err_t fsm_init (fsm_t * const me , int init_state , fsm_time_t get_ms ) {
60+ fsm_err_t fsm_init (fsm_t * const me , uint8_t init_state , fsm_time_t get_ms ) {
6061 /* Check if the FSM instance is valid */
6162 if (me == NULL ) {
6263 return FSM_ERR_INVALID_PARAM ;
@@ -80,7 +81,7 @@ fsm_err_t fsm_init(fsm_t *const me, int init_state, fsm_time_t get_ms) {
8081 * @brief Function to add a transition betwen state to FSM instance.
8182 */
8283fsm_err_t fsm_add_transition (fsm_t * const me , fsm_trans_t * * trans ,
83- int from_state , int next_state ) {
84+ uint8_t from_state , uint8_t next_state ) {
8485 /* Check if the FSM instance is valid */
8586 if (me == NULL ) {
8687 return FSM_ERR_INVALID_PARAM ;
@@ -139,8 +140,8 @@ fsm_err_t fsm_set_event_op(fsm_t *const me, fsm_trans_t *trans, fsm_op_t op) {
139140/**
140141 * @brief Function to add an event for a transition for a FSM instance.
141142 */
142- fsm_err_t fsm_add_event_cmp (fsm_t * const me , fsm_trans_t * trans , int * val , int cmp ,
143- fsm_eval_t eval ) {
143+ fsm_err_t fsm_add_event_cmp (fsm_t * const me , fsm_trans_t * trans , int * val ,
144+ int cmp , fsm_eval_t eval ) {
144145 /* Check if the FSM instance is valid */
145146 if (me == NULL ) {
146147 return FSM_ERR_INVALID_PARAM ;
@@ -242,19 +243,14 @@ fsm_err_t fsm_register_trans_action(fsm_t *const me, fsm_trans_t *trans,
242243/**
243244 * @brief Function to register callbacks for a FSM state.
244245 */
245- fsm_err_t fsm_register_state_actions (fsm_t * const me , int state ,
246+ fsm_err_t fsm_register_state_actions (fsm_t * const me , uint8_t state ,
246247 fsm_action_t enter , fsm_action_t update ,
247248 fsm_action_t exit ) {
248249 /* Check if the FSM instance is valid */
249250 if (me == NULL ) {
250251 return FSM_ERR_INVALID_PARAM ;
251252 }
252253
253- /* Check if the FSM state is valid */
254- if (state < 0 ) {
255- return FSM_ERR_INVALID_PARAM ;
256- }
257-
258254 if (state >= me -> actions_list .len ) {
259255 /* Allocate */
260256 fsm_action_t (* ptr )[3 ] =
@@ -302,7 +298,7 @@ fsm_err_t fsm_run(fsm_t *const me) {
302298
303299 /* Evaluate the transition event and get the next FSM state. If the current
304300 FSM state change then execute the exit action */
305- int next_state =
301+ uint8_t next_state =
306302 get_next_state (& me -> trans_list , me -> current_state , now_ms - me -> entry_ms );
307303
308304 if (next_state != me -> current_state ) {
@@ -316,8 +312,8 @@ fsm_err_t fsm_run(fsm_t *const me) {
316312}
317313
318314/* Private functions ---------------------------------------------------------*/
319- static int get_next_state (fsm_trans_list_t * trans_list , int current_state ,
320- uint32_t elapsed_ms ) {
315+ static uint8_t get_next_state (fsm_trans_list_t * trans_list ,
316+ uint8_t current_state , uint32_t elapsed_ms ) {
321317 for (size_t i = 0 ; i < trans_list -> len ; i ++ ) {
322318 /* Find coincidences for current state */
323319 fsm_trans_t * trans = & trans_list -> trans [i ];
@@ -360,7 +356,8 @@ static int get_next_state(fsm_trans_list_t *trans_list, int current_state,
360356 return current_state ;
361357}
362358
363- static void execute_action (int current_state , fsm_actions_list_t * actions_list ,
359+ static void execute_action (uint8_t current_state ,
360+ fsm_actions_list_t * actions_list ,
364361 fsm_action_type_t type ) {
365362 /* Check if actions type is valid*/
366363 if (type < FSM_ACTION_TYPE_ENTRY || type >= FSM_ACTION_TYPE_MAX ) {
0 commit comments