Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
PPSi
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
47
Issues
47
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
PPSi
Commits
fa17b6c7
Commit
fa17b6c7
authored
Jun 15, 2016
by
Davide Ciminaghi
Committed by
Alessandro Rubini
Sep 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fsm: reduce indentation level
parent
07e328e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
29 deletions
+40
-29
fsm.c
fsm.c
+40
-29
No files found.
fsm.c
View file @
fa17b6c7
...
...
@@ -62,6 +62,19 @@ static void pp_diag_fsm(struct pp_instance *ppi, char *name, int sequence,
name
,
ppi
->
next_state
);
}
static
struct
pp_state_table_item
*
get_current_state_table_item
(
struct
pp_instance
*
ppi
)
{
struct
pp_state_table_item
*
ip
;
struct
pp_state_table_item
*
out
=
NULL
;
/* a linear search is affordable up to a few dozen items */
for
(
ip
=
pp_state_table
;
ip
->
state
!=
PPS_END_OF_TABLE
&&
!
out
;
ip
++
)
if
(
ip
->
state
==
ppi
->
state
)
out
=
ip
;
return
out
;
}
/*
* This is the state machine code. i.e. the extension-independent
* function that runs the machine. Errors are managed and reported
...
...
@@ -103,34 +116,32 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
state
=
ppi
->
state
;
/* a linear search is affordable up to a few dozen items */
for
(
ip
=
pp_state_table
;
ip
->
state
!=
PPS_END_OF_TABLE
;
ip
++
)
{
if
(
ip
->
state
!=
state
)
continue
;
/* found: handle this state */
ppi
->
next_state
=
state
;
ppi
->
next_delay
=
0
;
if
(
ppi
->
is_new_state
)
pp_diag_fsm
(
ppi
,
ip
->
name
,
STATE_ENTER
,
plen
);
err
=
ip
->
f1
(
ppi
,
packet
,
plen
);
if
(
err
)
pp_printf
(
"fsm for %s: Error %i in %s
\n
"
,
ppi
->
port_name
,
err
,
ip
->
name
);
/* done: if new state mark it, and enter it now (0 ms) */
if
(
ppi
->
state
!=
ppi
->
next_state
)
{
ppi
->
state
=
ppi
->
next_state
;
ppi
->
is_new_state
=
1
;
pp_timeout_setall
(
ppi
);
ppi
->
flags
&=
~
PPI_FLAGS_WAITING
;
pp_diag_fsm
(
ppi
,
ip
->
name
,
STATE_LEAVE
,
0
);
return
0
;
/* next_delay unused: go to new state now */
}
ppi
->
is_new_state
=
0
;
pp_diag_fsm
(
ppi
,
ip
->
name
,
STATE_LOOP
,
0
);
return
ppi
->
next_delay
;
ip
=
get_current_state_table_item
(
ppi
);
if
(
!
ip
)
{
pp_printf
(
"fsm: Unknown state for port %s
\n
"
,
ppi
->
port_name
);
return
10000
;
/* No way out. Repeat message every 10s */
}
/* found: handle this state */
ppi
->
next_state
=
state
;
ppi
->
next_delay
=
0
;
if
(
ppi
->
is_new_state
)
pp_diag_fsm
(
ppi
,
ip
->
name
,
STATE_ENTER
,
plen
);
err
=
ip
->
f1
(
ppi
,
packet
,
plen
);
if
(
err
)
pp_printf
(
"fsm for %s: Error %i in %s
\n
"
,
ppi
->
port_name
,
err
,
ip
->
name
);
/* done: if new state mark it, and enter it now (0 ms) */
if
(
ppi
->
state
!=
ppi
->
next_state
)
{
ppi
->
state
=
ppi
->
next_state
;
ppi
->
is_new_state
=
1
;
pp_timeout_setall
(
ppi
);
ppi
->
flags
&=
~
PPI_FLAGS_WAITING
;
pp_diag_fsm
(
ppi
,
ip
->
name
,
STATE_LEAVE
,
0
);
return
0
;
/* next_delay unused: go to new state now */
}
/* Unknwon state, can't happen */
pp_
printf
(
"fsm: Unknown state for port %s
\n
"
,
ppi
->
port_name
);
return
10000
;
/* No way out. Repeat message every 10s */
ppi
->
is_new_state
=
0
;
pp_
diag_fsm
(
ppi
,
ip
->
name
,
STATE_LOOP
,
0
);
return
ppi
->
next_delay
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment