Skip to content

Commit

Permalink
vsfsm update for prototype implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vsfos committed Oct 13, 2014
1 parent cb230ce commit 8681818
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
42 changes: 14 additions & 28 deletions vsf/framework/vsfsm/vsfsm.c
Expand Up @@ -372,25 +372,6 @@ vsf_err_t vsfsm_post_evt_pending(struct vsfsm_t *sm, vsfsm_evt_t evt)

#if VSFSM_CFG_PT_EN
#include "interfaces.h"
static void vsfsm_pt_run(struct vsfsm_pt_t *pt)
{
#if VSFSM_CFG_PT_STACK_EN
uint32_t stack = interfaces->core.get_stack();
if (pt->stack != NULL)
{
interfaces->core.set_stack((uint32_t)pt->stack);
}
#endif

pt->evt_waiting = pt->thread(pt);

#if VSFSM_CFG_PT_STACK_EN
if (pt->stack != NULL)
{
interfaces->core.set_stack(stack);
}
#endif
}

struct vsfsm_state_t * vsfsm_pt_evt_handler(struct vsfsm_t *sm, vsfsm_evt_t evt)
{
Expand All @@ -400,20 +381,25 @@ struct vsfsm_state_t * vsfsm_pt_evt_handler(struct vsfsm_t *sm, vsfsm_evt_t evt)
{
case VSFSM_EVT_INIT:
pt->state = 0;
pt->evt_waiting = VSFSM_EVT_INIT;
// fall through
default:
if (evt == pt->evt_waiting)
{
vsfsm_pt_run(pt);
if (pt->evt_waiting < 0)
#if VSFSM_CFG_PT_STACK_EN
uint32_t stack = interfaces->core.get_stack();
if (pt->stack != NULL)
{
// event < 0 indicates failure
interfaces->core.set_stack((uint32_t)pt->stack);
}
}
else
{
// unwanted event
#endif

pt->thread(pt, evt);

#if VSFSM_CFG_PT_STACK_EN
if (pt->stack != NULL)
{
interfaces->core.set_stack(stack);
}
#endif
}
}
return NULL;
Expand Down
19 changes: 10 additions & 9 deletions vsf/framework/vsfsm/vsfsm.h
Expand Up @@ -116,7 +116,7 @@ struct vsfsm_t
#if VSFSM_CFG_PT_EN
struct vsfsm_pt_t
{
vsfsm_evt_t (*thread)(struct vsfsm_pt_t *pt);
vsf_err_t (*thread)(struct vsfsm_pt_t *pt, vsfsm_evt_t evt);
void *user_data;

#if VSFSM_CFG_PT_STACK_EN
Expand All @@ -128,26 +128,27 @@ struct vsfsm_pt_t
// protected
int state;
struct vsfsm_t *sm;

// private
vsfsm_evt_t evt_waiting;
};

vsf_err_t vsfsm_pt_init(struct vsfsm_t *sm, struct vsfsm_pt_t *pt,
bool add_to_top);
#define vsfsm_pt_begin(pt) switch ((pt)->state) { case 0:
#define vsfsm_pt_entry(pt) (pt)->state = __LINE__; case __LINE__:
// wait for event
#define vsfsm_pt_wfe(pt, evt) (pt)->state = __LINE__; return (evt); case __LINE__:
#define vsfsm_pt_wfe(pt, e) do {\
vsfsm_pt_entry(pt);\
if (evt != (e)) return VSFERR_NOT_READY;\
} while (0)
// wait for pt, slave pt uses the same stack as the master pt
#define vsfsm_pt_wfpt(pt, ptslave) do {\
(ptslave)->state = 0;\
(ptslave)->sm = (pt)->sm;\
(pt)->state = __LINE__; case __LINE__:\
vsfsm_pt_entry(pt);\
{\
vsfsm_evt_t __evt = (ptslave)->thread(ptslave);\
if (__evt != VSFSM_EVT_NONE)\
vsf_err_t __err = (ptslave)->thread(ptslave);\
if (__err != VSFERR_NONE)\
{\
return __evt;\
return __err;\
}\
}\
} while (0)
Expand Down

0 comments on commit 8681818

Please sign in to comment.