/* Generated by itemis CREATE code generator. */


#include "../inc/sc_types.h"

#include "../inc/sc_prefix.h"
#include "../inc/sc_prefix_required.h"

/*! \file
Implementation of the state machine 'sc_prefix'
*/

#ifndef SC_UNUSED
#define SC_UNUSED(P) (void)(P)
#endif

/* prototypes of all internal functions */
static void enact_Button_A_ST_BUTTON_UP(Sc_prefix* handle);
static void enact_Button_A_ST_BUTTON_FALLING(Sc_prefix* handle);
static void enact_Button_A_ST_BUTTON_DOWN(Sc_prefix* handle);
static void enact_Button_A_ST_BUTTON_RISING(Sc_prefix* handle);
static void enact_Led_A_ST_LED_OFF(Sc_prefix* handle);
static void enact_Led_A_ST_LED_ON(Sc_prefix* handle);
static void enact_Led_A_ST_LED_BLINK_r1_ST_LED_ON(Sc_prefix* handle);
static void enact_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(Sc_prefix* handle);
static void exact_Button_A_ST_BUTTON_UP(Sc_prefix* handle);
static void exact_Button_A_ST_BUTTON_FALLING(Sc_prefix* handle);
static void exact_Button_A_ST_BUTTON_DOWN(Sc_prefix* handle);
static void exact_Button_A_ST_BUTTON_RISING(Sc_prefix* handle);
static void exact_Led_A_ST_LED_BLINK_r1_ST_LED_ON(Sc_prefix* handle);
static void exact_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(Sc_prefix* handle);
static void enseq_Button_A_ST_BUTTON_UP_default(Sc_prefix* handle);
static void enseq_Button_A_ST_BUTTON_FALLING_default(Sc_prefix* handle);
static void enseq_Button_A_ST_BUTTON_DOWN_default(Sc_prefix* handle);
static void enseq_Button_A_ST_BUTTON_RISING_default(Sc_prefix* handle);
static void enseq_System_ST_SYSTEM_IDLE_default(Sc_prefix* handle);
static void enseq_System_ST_SYSTEM_ACTIVE_default(Sc_prefix* handle);
static void enseq_Led_A_ST_LED_OFF_default(Sc_prefix* handle);
static void enseq_Led_A_ST_LED_ON_default(Sc_prefix* handle);
static void enseq_Led_A_ST_LED_BLINK_default(Sc_prefix* handle);
static void enseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON_default(Sc_prefix* handle);
static void enseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_default(Sc_prefix* handle);
static void enseq_Button_A_default(Sc_prefix* handle);
static void enseq_System_default(Sc_prefix* handle);
static void enseq_Led_A_default(Sc_prefix* handle);
static void enseq_Led_A_ST_LED_BLINK_r1_default(Sc_prefix* handle);
static void exseq_Button_A_ST_BUTTON_UP(Sc_prefix* handle);
static void exseq_Button_A_ST_BUTTON_FALLING(Sc_prefix* handle);
static void exseq_Button_A_ST_BUTTON_DOWN(Sc_prefix* handle);
static void exseq_Button_A_ST_BUTTON_RISING(Sc_prefix* handle);
static void exseq_System_ST_SYSTEM_IDLE(Sc_prefix* handle);
static void exseq_System_ST_SYSTEM_ACTIVE(Sc_prefix* handle);
static void exseq_Led_A_ST_LED_OFF(Sc_prefix* handle);
static void exseq_Led_A_ST_LED_ON(Sc_prefix* handle);
static void exseq_Led_A_ST_LED_BLINK(Sc_prefix* handle);
static void exseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON(Sc_prefix* handle);
static void exseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(Sc_prefix* handle);
static void exseq_Button_A(Sc_prefix* handle);
static void exseq_System(Sc_prefix* handle);
static void exseq_Led_A(Sc_prefix* handle);
static void exseq_Led_A_ST_LED_BLINK_r1(Sc_prefix* handle);
static void react_Button_A__choice_0(Sc_prefix* handle);
static void react_Button_A__choice_1(Sc_prefix* handle);
static void react_Button_A__choice_2(Sc_prefix* handle);
static void react_Button_A__choice_3(Sc_prefix* handle);
static void react_Button_A__entry_Default(Sc_prefix* handle);
static void react_System__entry_Default(Sc_prefix* handle);
static void react_Led_A__entry_Default(Sc_prefix* handle);
static void react_Led_A_ST_LED_BLINK_r1__entry_Default(Sc_prefix* handle);

/*! The reactions of state ST_BUTTON_UP. */
static sc_integer Button_A_ST_BUTTON_UP_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_BUTTON_FALLING. */
static sc_integer Button_A_ST_BUTTON_FALLING_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_BUTTON_DOWN. */
static sc_integer Button_A_ST_BUTTON_DOWN_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_BUTTON_RISING. */
static sc_integer Button_A_ST_BUTTON_RISING_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_SYSTEM_IDLE. */
static sc_integer System_ST_SYSTEM_IDLE_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_SYSTEM_ACTIVE. */
static sc_integer System_ST_SYSTEM_ACTIVE_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_LED_OFF. */
static sc_integer Led_A_ST_LED_OFF_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_LED_ON. */
static sc_integer Led_A_ST_LED_ON_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_LED_BLINK. */
static sc_integer Led_A_ST_LED_BLINK_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_LED_ON. */
static sc_integer Led_A_ST_LED_BLINK_r1_ST_LED_ON_react(Sc_prefix* handle, const sc_integer transitioned_before);

/*! The reactions of state ST_LED_OFF. */
static sc_integer Led_A_ST_LED_BLINK_r1_ST_LED_OFF_react(Sc_prefix* handle, const sc_integer transitioned_before);


static void clear_in_events(Sc_prefix* handle);

static void clear_internal_events(Sc_prefix* handle);

static void micro_step(Sc_prefix* handle);

/*! Performs a 'run to completion' step. */
static void run_cycle(Sc_prefix* handle);



const uint32_t SC_PREFIX_SC_PREFIXIFACE_BTN_A = 0;
const uint32_t SC_PREFIX_SC_PREFIXIFACE_BTN_B = 1;
const uint32_t SC_PREFIX_SC_PREFIXIFACE_BTN_C = 2;
const uint32_t SC_PREFIX_SC_PREFIXIFACE_BTN_UP = 0;
const uint32_t SC_PREFIX_SC_PREFIXIFACE_LED_A = 0;
const uint32_t SC_PREFIX_SC_PREFIXIFACE_LED_B = 1;
const uint32_t SC_PREFIX_SC_PREFIXIFACE_LED_C = 2;

static void sc_prefix_internal_set_vi_button(Sc_prefix* handle, uint32_t value)
;
static void sc_prefix_internal_set_vi_system(Sc_prefix* handle, uint32_t value)
;


static void sc_prefix_eventqueue_init(sc_prefix_eventqueue * eq, sc_prefix_event *buffer, sc_integer capacity);
static sc_integer sc_prefix_eventqueue_size(sc_prefix_eventqueue * eq);
static void sc_prefix_event_init(sc_prefix_event * ev, Sc_prefixEventID name);
static sc_prefix_event sc_prefix_eventqueue_pop(sc_prefix_eventqueue * eq);
static sc_boolean sc_prefix_eventqueue_push(sc_prefix_eventqueue * eq, sc_prefix_event ev);
static void sc_prefix_add_event_to_queue(sc_prefix_eventqueue * eq, Sc_prefixEventID name);
static sc_boolean sc_prefix_dispatch_event(Sc_prefix* handle, const sc_prefix_event * event);
static sc_prefix_event sc_prefix_get_next_event(Sc_prefix* handle);
static sc_boolean sc_prefix_dispatch_next_event(Sc_prefix* handle);
static Sc_prefixEventID sc_prefix_get_timed_event_name(Sc_prefix* handle, sc_eventid evid);


void sc_prefix_init(Sc_prefix* handle)
{
	sc_integer i;
	
	for (i = 0; i < SC_PREFIX_MAX_ORTHOGONAL_STATES; ++i)
	{
		handle->stateConfVector[i] = Sc_prefix_last_state;
	}
	
				
	clear_in_events(handle);
	clear_internal_events(handle);
	
	
	/* Default init sequence for statechart sc_prefix */
	sc_prefix_internal_set_vi_button(handle, 0);
	sc_prefix_internal_set_vi_system(handle, 0);
	
	handle->isExecuting = bool_false;
	sc_prefix_eventqueue_init(&handle->internal_event_queue, handle->internal_buffer, SC_PREFIX_INTERNAL_EVENTQUEUE_BUFFERSIZE);
	sc_prefix_eventqueue_init(&handle->in_event_queue, handle->in_buffer, SC_PREFIX_IN_EVENTQUEUE_BUFFERSIZE);
}

void sc_prefix_enter(Sc_prefix* handle)
{
	/* Activates the state machine. */
	if (handle->isExecuting == bool_true)
	{ 
		return;
	} 
	handle->isExecuting = bool_true;
	/* Default enter sequence for statechart sc_prefix */
	enseq_Button_A_default(handle);
	enseq_System_default(handle);
	enseq_Led_A_default(handle);
	handle->isExecuting = bool_false;
}

void sc_prefix_exit(Sc_prefix* handle)
{
	/* Deactivates the state machine. */
	if (handle->isExecuting == bool_true)
	{ 
		return;
	} 
	handle->isExecuting = bool_true;
	/* Default exit sequence for statechart sc_prefix */
	exseq_Button_A(handle);
	handle->stateConfVector[0] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 0;
	exseq_System(handle);
	handle->stateConfVector[1] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 1;
	exseq_Led_A(handle);
	handle->stateConfVector[2] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 2;
	handle->isExecuting = bool_false;
}

/*!
Can be used by the client code to trigger a run to completion step without raising an event.
*/
void sc_prefix_trigger_without_event(Sc_prefix* handle) {
	run_cycle(handle);
}


sc_boolean sc_prefix_is_active(const Sc_prefix* handle)
{
	sc_boolean result = bool_false;
	sc_integer i;
	
	for(i = 0; i < SC_PREFIX_MAX_ORTHOGONAL_STATES; i++)
	{
		result = result || handle->stateConfVector[i] != Sc_prefix_last_state;
	}
	
	return result;
}

/* 
 * Always returns 'false' since this state machine can never become final.
 */
sc_boolean sc_prefix_is_final(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return bool_false;
}

void sc_prefix_raise_time_event(Sc_prefix* handle, sc_eventid evid)
{
	if ( ((sc_intptr_t)evid) >= ((sc_intptr_t)&(handle->timeEvents))
		&&  ((sc_intptr_t)evid) < ((sc_intptr_t)&(handle->timeEvents)) + (unsigned)sizeof(Sc_prefixTimeEvents))
	{
		sc_prefix_add_event_to_queue(&(handle->in_event_queue), sc_prefix_get_timed_event_name(handle, evid));
		run_cycle(handle);
	}
}

sc_boolean sc_prefix_is_state_active(const Sc_prefix* handle, Sc_prefixStates state)
{
	sc_boolean result = bool_false;
	switch (state)
	{
		case Sc_prefix_Button_A_ST_BUTTON_UP :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_BUTTON_A_ST_BUTTON_UP] == Sc_prefix_Button_A_ST_BUTTON_UP
			);
				break;
		case Sc_prefix_Button_A_ST_BUTTON_FALLING :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_BUTTON_A_ST_BUTTON_FALLING] == Sc_prefix_Button_A_ST_BUTTON_FALLING
			);
				break;
		case Sc_prefix_Button_A_ST_BUTTON_DOWN :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_BUTTON_A_ST_BUTTON_DOWN] == Sc_prefix_Button_A_ST_BUTTON_DOWN
			);
				break;
		case Sc_prefix_Button_A_ST_BUTTON_RISING :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_BUTTON_A_ST_BUTTON_RISING] == Sc_prefix_Button_A_ST_BUTTON_RISING
			);
				break;
		case Sc_prefix_System_ST_SYSTEM_IDLE :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_SYSTEM_ST_SYSTEM_IDLE] == Sc_prefix_System_ST_SYSTEM_IDLE
			);
				break;
		case Sc_prefix_System_ST_SYSTEM_ACTIVE :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_SYSTEM_ST_SYSTEM_ACTIVE] == Sc_prefix_System_ST_SYSTEM_ACTIVE
			);
				break;
		case Sc_prefix_Led_A_ST_LED_OFF :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_LED_A_ST_LED_OFF] == Sc_prefix_Led_A_ST_LED_OFF
			);
				break;
		case Sc_prefix_Led_A_ST_LED_ON :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_LED_A_ST_LED_ON] == Sc_prefix_Led_A_ST_LED_ON
			);
				break;
		case Sc_prefix_Led_A_ST_LED_BLINK :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_LED_A_ST_LED_BLINK] >= Sc_prefix_Led_A_ST_LED_BLINK
				&& handle->stateConfVector[SCVI_SC_PREFIX_LED_A_ST_LED_BLINK] <= Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF);
				break;
		case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_LED_A_ST_LED_BLINK_R1_ST_LED_ON] == Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON
			);
				break;
		case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF :
			result = (sc_boolean) (handle->stateConfVector[SCVI_SC_PREFIX_LED_A_ST_LED_BLINK_R1_ST_LED_OFF] == Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF
			);
				break;
			default:
				result = bool_false;
				break;
		}
		return result;
	}

static void clear_in_events(Sc_prefix* handle)
{
	handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised = bool_false;
	handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised = bool_false;
	handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised = bool_false;
	handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised = bool_false;
	handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised = bool_false;
	handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised = bool_false;
}

static void clear_internal_events(Sc_prefix* handle)
{
	handle->internal.ev_button_a_down_raised = bool_false;
	handle->internal.ev_button_a_up_raised = bool_false;
	handle->internal.ev_led_a_blink_raised = bool_false;
	handle->internal.ev_led_a_on_raised = bool_false;
	handle->internal.ev_led_a_off_raised = bool_false;
}

static void micro_step(Sc_prefix* handle)
{
 			sc_integer transitioned = -1;
	handle->stateConfVectorPosition = 0;
	switch(handle->stateConfVector[ 0 ])
	{
		case Sc_prefix_Button_A_ST_BUTTON_UP :
		{
			transitioned = Button_A_ST_BUTTON_UP_react(handle,transitioned);
			break;
		}
		case Sc_prefix_Button_A_ST_BUTTON_FALLING :
		{
			transitioned = Button_A_ST_BUTTON_FALLING_react(handle,transitioned);
			break;
		}
		case Sc_prefix_Button_A_ST_BUTTON_DOWN :
		{
			transitioned = Button_A_ST_BUTTON_DOWN_react(handle,transitioned);
			break;
		}
		case Sc_prefix_Button_A_ST_BUTTON_RISING :
		{
			transitioned = Button_A_ST_BUTTON_RISING_react(handle,transitioned);
			break;
		}
		default: 
			/* do nothing */
			break;
	}
	if ((handle->stateConfVectorPosition) < (1))
	{ 
		switch(handle->stateConfVector[ 1 ])
		{
			case Sc_prefix_System_ST_SYSTEM_IDLE :
			{
				transitioned = System_ST_SYSTEM_IDLE_react(handle,transitioned);
				break;
			}
			case Sc_prefix_System_ST_SYSTEM_ACTIVE :
			{
				transitioned = System_ST_SYSTEM_ACTIVE_react(handle,transitioned);
				break;
			}
			default: 
				/* do nothing */
				break;
		}
	} if ((handle->stateConfVectorPosition) < (2))
	{ 
		switch(handle->stateConfVector[ 2 ])
		{
			case Sc_prefix_Led_A_ST_LED_OFF :
			{
				Led_A_ST_LED_OFF_react(handle,transitioned);
				break;
			}
			case Sc_prefix_Led_A_ST_LED_ON :
			{
				Led_A_ST_LED_ON_react(handle,transitioned);
				break;
			}
			case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON :
			{
				Led_A_ST_LED_BLINK_r1_ST_LED_ON_react(handle,transitioned);
				break;
			}
			case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF :
			{
				Led_A_ST_LED_BLINK_r1_ST_LED_OFF_react(handle,transitioned);
				break;
			}
			default: 
				/* do nothing */
				break;
		}
	} 
}

static void run_cycle(Sc_prefix* handle)
{
	/* Performs a 'run to completion' step. */
	if (handle->isExecuting == bool_true)
	{ 
		return;
	} 
	handle->isExecuting = bool_true;
	sc_prefix_dispatch_next_event(handle);
	do
	{ 
		micro_step(handle);
		clear_in_events(handle);
		clear_internal_events(handle);
	} while (sc_prefix_dispatch_next_event(handle) == bool_true);
	handle->isExecuting = bool_false;
}




uint32_t sc_prefix_get_bTN_A(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_BTN_A;
}
uint32_t sc_prefix_get_bTN_B(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_BTN_B;
}
uint32_t sc_prefix_get_bTN_C(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_BTN_C;
}
uint32_t sc_prefix_get_bTN_UP(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_BTN_UP;
}
uint32_t sc_prefix_get_lED_A(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_LED_A;
}
uint32_t sc_prefix_get_lED_B(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_LED_B;
}
uint32_t sc_prefix_get_lED_C(const Sc_prefix* handle)
{
	SC_UNUSED(handle);
	return SC_PREFIX_SC_PREFIXIFACE_LED_C;
}

static void sc_prefix_internal_set_vi_button(Sc_prefix* handle, uint32_t value)
{
	handle->internal.vi_button = value;
}
static void sc_prefix_internal_set_vi_system(Sc_prefix* handle, uint32_t value)
{
	handle->internal.vi_system = value;
}


/* implementations of all internal functions */

/* Entry action for state 'ST_BUTTON_UP'. */
static void enact_Button_A_ST_BUTTON_UP(Sc_prefix* handle)
{
	/* Entry action for state 'ST_BUTTON_UP'. */
	sc_prefix_set_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised) , ((sc_time) 1), bool_false);
}

/* Entry action for state 'ST_BUTTON_FALLING'. */
static void enact_Button_A_ST_BUTTON_FALLING(Sc_prefix* handle)
{
	/* Entry action for state 'ST_BUTTON_FALLING'. */
	sc_prefix_set_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised) , ((sc_time) 50), bool_false);
}

/* Entry action for state 'ST_BUTTON_DOWN'. */
static void enact_Button_A_ST_BUTTON_DOWN(Sc_prefix* handle)
{
	/* Entry action for state 'ST_BUTTON_DOWN'. */
	sc_prefix_set_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised) , ((sc_time) 1), bool_false);
}

/* Entry action for state 'ST_BUTTON_RISING'. */
static void enact_Button_A_ST_BUTTON_RISING(Sc_prefix* handle)
{
	/* Entry action for state 'ST_BUTTON_RISING'. */
	sc_prefix_set_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised) , ((sc_time) 50), bool_false);
}

/* Entry action for state 'ST_LED_OFF'. */
static void enact_Led_A_ST_LED_OFF(Sc_prefix* handle)
{
	/* Entry action for state 'ST_LED_OFF'. */
	op_led_off(SC_PREFIX_SC_PREFIXIFACE_LED_A);
}

/* Entry action for state 'ST_LED_ON'. */
static void enact_Led_A_ST_LED_ON(Sc_prefix* handle)
{
	/* Entry action for state 'ST_LED_ON'. */
	op_led_on(SC_PREFIX_SC_PREFIXIFACE_LED_A);
}

/* Entry action for state 'ST_LED_ON'. */
static void enact_Led_A_ST_LED_BLINK_r1_ST_LED_ON(Sc_prefix* handle)
{
	/* Entry action for state 'ST_LED_ON'. */
	sc_prefix_set_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised) , ((sc_time) 500), bool_false);
	op_led_on(SC_PREFIX_SC_PREFIXIFACE_LED_A);
}

/* Entry action for state 'ST_LED_OFF'. */
static void enact_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(Sc_prefix* handle)
{
	/* Entry action for state 'ST_LED_OFF'. */
	sc_prefix_set_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised) , ((sc_time) 500), bool_false);
	op_led_off(SC_PREFIX_SC_PREFIXIFACE_LED_A);
}

/* Exit action for state 'ST_BUTTON_UP'. */
static void exact_Button_A_ST_BUTTON_UP(Sc_prefix* handle)
{
	/* Exit action for state 'ST_BUTTON_UP'. */
	sc_prefix_unset_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised) );		
}

/* Exit action for state 'ST_BUTTON_FALLING'. */
static void exact_Button_A_ST_BUTTON_FALLING(Sc_prefix* handle)
{
	/* Exit action for state 'ST_BUTTON_FALLING'. */
	sc_prefix_unset_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised) );		
}

/* Exit action for state 'ST_BUTTON_DOWN'. */
static void exact_Button_A_ST_BUTTON_DOWN(Sc_prefix* handle)
{
	/* Exit action for state 'ST_BUTTON_DOWN'. */
	sc_prefix_unset_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised) );		
}

/* Exit action for state 'ST_BUTTON_RISING'. */
static void exact_Button_A_ST_BUTTON_RISING(Sc_prefix* handle)
{
	/* Exit action for state 'ST_BUTTON_RISING'. */
	sc_prefix_unset_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised) );		
}

/* Exit action for state 'ST_LED_ON'. */
static void exact_Led_A_ST_LED_BLINK_r1_ST_LED_ON(Sc_prefix* handle)
{
	/* Exit action for state 'ST_LED_ON'. */
	sc_prefix_unset_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised) );		
}

/* Exit action for state 'ST_LED_OFF'. */
static void exact_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(Sc_prefix* handle)
{
	/* Exit action for state 'ST_LED_OFF'. */
	sc_prefix_unset_timer(handle, (sc_eventid) &(handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised) );		
}

/* 'default' enter sequence for state ST_BUTTON_UP */
static void enseq_Button_A_ST_BUTTON_UP_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_BUTTON_UP */
	enact_Button_A_ST_BUTTON_UP(handle);
	handle->stateConfVector[0] = Sc_prefix_Button_A_ST_BUTTON_UP;
	handle->stateConfVectorPosition = 0;
}

/* 'default' enter sequence for state ST_BUTTON_FALLING */
static void enseq_Button_A_ST_BUTTON_FALLING_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_BUTTON_FALLING */
	enact_Button_A_ST_BUTTON_FALLING(handle);
	handle->stateConfVector[0] = Sc_prefix_Button_A_ST_BUTTON_FALLING;
	handle->stateConfVectorPosition = 0;
}

/* 'default' enter sequence for state ST_BUTTON_DOWN */
static void enseq_Button_A_ST_BUTTON_DOWN_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_BUTTON_DOWN */
	enact_Button_A_ST_BUTTON_DOWN(handle);
	handle->stateConfVector[0] = Sc_prefix_Button_A_ST_BUTTON_DOWN;
	handle->stateConfVectorPosition = 0;
}

/* 'default' enter sequence for state ST_BUTTON_RISING */
static void enseq_Button_A_ST_BUTTON_RISING_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_BUTTON_RISING */
	enact_Button_A_ST_BUTTON_RISING(handle);
	handle->stateConfVector[0] = Sc_prefix_Button_A_ST_BUTTON_RISING;
	handle->stateConfVectorPosition = 0;
}

/* 'default' enter sequence for state ST_SYSTEM_IDLE */
static void enseq_System_ST_SYSTEM_IDLE_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_SYSTEM_IDLE */
	handle->stateConfVector[1] = Sc_prefix_System_ST_SYSTEM_IDLE;
	handle->stateConfVectorPosition = 1;
}

/* 'default' enter sequence for state ST_SYSTEM_ACTIVE */
static void enseq_System_ST_SYSTEM_ACTIVE_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_SYSTEM_ACTIVE */
	handle->stateConfVector[1] = Sc_prefix_System_ST_SYSTEM_ACTIVE;
	handle->stateConfVectorPosition = 1;
}

/* 'default' enter sequence for state ST_LED_OFF */
static void enseq_Led_A_ST_LED_OFF_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_LED_OFF */
	enact_Led_A_ST_LED_OFF(handle);
	handle->stateConfVector[2] = Sc_prefix_Led_A_ST_LED_OFF;
	handle->stateConfVectorPosition = 2;
}

/* 'default' enter sequence for state ST_LED_ON */
static void enseq_Led_A_ST_LED_ON_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_LED_ON */
	enact_Led_A_ST_LED_ON(handle);
	handle->stateConfVector[2] = Sc_prefix_Led_A_ST_LED_ON;
	handle->stateConfVectorPosition = 2;
}

/* 'default' enter sequence for state ST_LED_BLINK */
static void enseq_Led_A_ST_LED_BLINK_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_LED_BLINK */
	enseq_Led_A_ST_LED_BLINK_r1_default(handle);
}

/* 'default' enter sequence for state ST_LED_ON */
static void enseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_LED_ON */
	enact_Led_A_ST_LED_BLINK_r1_ST_LED_ON(handle);
	handle->stateConfVector[2] = Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON;
	handle->stateConfVectorPosition = 2;
}

/* 'default' enter sequence for state ST_LED_OFF */
static void enseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for state ST_LED_OFF */
	enact_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(handle);
	handle->stateConfVector[2] = Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF;
	handle->stateConfVectorPosition = 2;
}

/* 'default' enter sequence for region Button A */
static void enseq_Button_A_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for region Button A */
	react_Button_A__entry_Default(handle);
}

/* 'default' enter sequence for region System */
static void enseq_System_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for region System */
	react_System__entry_Default(handle);
}

/* 'default' enter sequence for region Led A */
static void enseq_Led_A_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for region Led A */
	react_Led_A__entry_Default(handle);
}

/* 'default' enter sequence for region r1 */
static void enseq_Led_A_ST_LED_BLINK_r1_default(Sc_prefix* handle)
{
	/* 'default' enter sequence for region r1 */
	react_Led_A_ST_LED_BLINK_r1__entry_Default(handle);
}

/* Default exit sequence for state ST_BUTTON_UP */
static void exseq_Button_A_ST_BUTTON_UP(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_BUTTON_UP */
	handle->stateConfVector[0] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 0;
	exact_Button_A_ST_BUTTON_UP(handle);
}

/* Default exit sequence for state ST_BUTTON_FALLING */
static void exseq_Button_A_ST_BUTTON_FALLING(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_BUTTON_FALLING */
	handle->stateConfVector[0] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 0;
	exact_Button_A_ST_BUTTON_FALLING(handle);
}

/* Default exit sequence for state ST_BUTTON_DOWN */
static void exseq_Button_A_ST_BUTTON_DOWN(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_BUTTON_DOWN */
	handle->stateConfVector[0] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 0;
	exact_Button_A_ST_BUTTON_DOWN(handle);
}

/* Default exit sequence for state ST_BUTTON_RISING */
static void exseq_Button_A_ST_BUTTON_RISING(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_BUTTON_RISING */
	handle->stateConfVector[0] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 0;
	exact_Button_A_ST_BUTTON_RISING(handle);
}

/* Default exit sequence for state ST_SYSTEM_IDLE */
static void exseq_System_ST_SYSTEM_IDLE(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_SYSTEM_IDLE */
	handle->stateConfVector[1] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 1;
}

/* Default exit sequence for state ST_SYSTEM_ACTIVE */
static void exseq_System_ST_SYSTEM_ACTIVE(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_SYSTEM_ACTIVE */
	handle->stateConfVector[1] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 1;
}

/* Default exit sequence for state ST_LED_OFF */
static void exseq_Led_A_ST_LED_OFF(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_LED_OFF */
	handle->stateConfVector[2] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 2;
}

/* Default exit sequence for state ST_LED_ON */
static void exseq_Led_A_ST_LED_ON(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_LED_ON */
	handle->stateConfVector[2] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 2;
}

/* Default exit sequence for state ST_LED_BLINK */
static void exseq_Led_A_ST_LED_BLINK(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_LED_BLINK */
	exseq_Led_A_ST_LED_BLINK_r1(handle);
	handle->stateConfVector[2] = Sc_prefix_last_state;
	handle->stateConfVectorPosition = 2;
}

/* Default exit sequence for state ST_LED_ON */
static void exseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_LED_ON */
	handle->stateConfVector[2] = Sc_prefix_Led_A_ST_LED_BLINK;
	handle->stateConfVectorPosition = 2;
	exact_Led_A_ST_LED_BLINK_r1_ST_LED_ON(handle);
}

/* Default exit sequence for state ST_LED_OFF */
static void exseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(Sc_prefix* handle)
{
	/* Default exit sequence for state ST_LED_OFF */
	handle->stateConfVector[2] = Sc_prefix_Led_A_ST_LED_BLINK;
	handle->stateConfVectorPosition = 2;
	exact_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(handle);
}

/* Default exit sequence for region Button A */
static void exseq_Button_A(Sc_prefix* handle)
{
	/* Default exit sequence for region Button A */
	/* Handle exit of all possible states (of sc_prefix.Button_A) at position 0... */
	switch(handle->stateConfVector[ 0 ])
	{
		case Sc_prefix_Button_A_ST_BUTTON_UP :
		{
			exseq_Button_A_ST_BUTTON_UP(handle);
			break;
		}
		case Sc_prefix_Button_A_ST_BUTTON_FALLING :
		{
			exseq_Button_A_ST_BUTTON_FALLING(handle);
			break;
		}
		case Sc_prefix_Button_A_ST_BUTTON_DOWN :
		{
			exseq_Button_A_ST_BUTTON_DOWN(handle);
			break;
		}
		case Sc_prefix_Button_A_ST_BUTTON_RISING :
		{
			exseq_Button_A_ST_BUTTON_RISING(handle);
			break;
		}
		default: 
			/* do nothing */
			break;
	}
}

/* Default exit sequence for region System */
static void exseq_System(Sc_prefix* handle)
{
	/* Default exit sequence for region System */
	/* Handle exit of all possible states (of sc_prefix.System) at position 1... */
	switch(handle->stateConfVector[ 1 ])
	{
		case Sc_prefix_System_ST_SYSTEM_IDLE :
		{
			exseq_System_ST_SYSTEM_IDLE(handle);
			break;
		}
		case Sc_prefix_System_ST_SYSTEM_ACTIVE :
		{
			exseq_System_ST_SYSTEM_ACTIVE(handle);
			break;
		}
		default: 
			/* do nothing */
			break;
	}
}

/* Default exit sequence for region Led A */
static void exseq_Led_A(Sc_prefix* handle)
{
	/* Default exit sequence for region Led A */
	/* Handle exit of all possible states (of sc_prefix.Led_A) at position 2... */
	switch(handle->stateConfVector[ 2 ])
	{
		case Sc_prefix_Led_A_ST_LED_OFF :
		{
			exseq_Led_A_ST_LED_OFF(handle);
			break;
		}
		case Sc_prefix_Led_A_ST_LED_ON :
		{
			exseq_Led_A_ST_LED_ON(handle);
			break;
		}
		case Sc_prefix_Led_A_ST_LED_BLINK :
		{
			exseq_Led_A_ST_LED_BLINK(handle);
			break;
		}
		case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON :
		{
			exseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON(handle);
			break;
		}
		case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF :
		{
			exseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(handle);
			break;
		}
		default: 
			/* do nothing */
			break;
	}
}

/* Default exit sequence for region r1 */
static void exseq_Led_A_ST_LED_BLINK_r1(Sc_prefix* handle)
{
	/* Default exit sequence for region r1 */
	/* Handle exit of all possible states (of sc_prefix.Led_A.ST_LED_BLINK.r1) at position 2... */
	switch(handle->stateConfVector[ 2 ])
	{
		case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON :
		{
			exseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON(handle);
			break;
		}
		case Sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF :
		{
			exseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(handle);
			break;
		}
		default: 
			/* do nothing */
			break;
	}
}

/* The reactions of state null. */
static void react_Button_A__choice_0(Sc_prefix* handle)
{
	/* The reactions of state null. */
	if ((handle->internal.vi_button) != (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
	{ 
		enseq_Button_A_ST_BUTTON_FALLING_default(handle);
	}  else
	{
		if ((handle->internal.vi_button) == (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
		{ 
			enseq_Button_A_ST_BUTTON_UP_default(handle);
		}  else
		{
			enseq_Button_A_ST_BUTTON_UP_default(handle);
		}
	}
}

/* The reactions of state null. */
static void react_Button_A__choice_1(Sc_prefix* handle)
{
	/* The reactions of state null. */
	if ((handle->internal.vi_button) != (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
	{ 
		sc_prefix_add_event_to_queue(&(handle->internal_event_queue), Sc_prefix_internal_ev_button_a_up);
		enseq_Button_A_ST_BUTTON_DOWN_default(handle);
	}  else
	{
		if ((handle->internal.vi_button) == (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
		{ 
			enseq_Button_A_ST_BUTTON_UP_default(handle);
		}  else
		{
			enseq_Button_A_ST_BUTTON_UP_default(handle);
		}
	}
}

/* The reactions of state null. */
static void react_Button_A__choice_2(Sc_prefix* handle)
{
	/* The reactions of state null. */
	if ((handle->internal.vi_button) == (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
	{ 
		sc_prefix_add_event_to_queue(&(handle->internal_event_queue), Sc_prefix_internal_ev_button_a_down);
		enseq_Button_A_ST_BUTTON_UP_default(handle);
	}  else
	{
		if ((handle->internal.vi_button) != (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
		{ 
			enseq_Button_A_ST_BUTTON_DOWN_default(handle);
		}  else
		{
			enseq_Button_A_ST_BUTTON_DOWN_default(handle);
		}
	}
}

/* The reactions of state null. */
static void react_Button_A__choice_3(Sc_prefix* handle)
{
	/* The reactions of state null. */
	if ((handle->internal.vi_button) == (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
	{ 
		enseq_Button_A_ST_BUTTON_RISING_default(handle);
	}  else
	{
		if ((handle->internal.vi_button) != (SC_PREFIX_SC_PREFIXIFACE_BTN_UP))
		{ 
			enseq_Button_A_ST_BUTTON_DOWN_default(handle);
		}  else
		{
			enseq_Button_A_ST_BUTTON_DOWN_default(handle);
		}
	}
}

/* Default react sequence for initial entry  */
static void react_Button_A__entry_Default(Sc_prefix* handle)
{
	/* Default react sequence for initial entry  */
	enseq_Button_A_ST_BUTTON_UP_default(handle);
}

/* Default react sequence for initial entry  */
static void react_System__entry_Default(Sc_prefix* handle)
{
	/* Default react sequence for initial entry  */
	sc_prefix_internal_set_vi_system(handle, 0);
	sc_prefix_add_event_to_queue(&(handle->internal_event_queue), Sc_prefix_internal_ev_led_a_off);
	enseq_System_ST_SYSTEM_IDLE_default(handle);
}

/* Default react sequence for initial entry  */
static void react_Led_A__entry_Default(Sc_prefix* handle)
{
	/* Default react sequence for initial entry  */
	enseq_Led_A_ST_LED_OFF_default(handle);
}

/* Default react sequence for initial entry  */
static void react_Led_A_ST_LED_BLINK_r1__entry_Default(Sc_prefix* handle)
{
	/* Default react sequence for initial entry  */
	enseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON_default(handle);
}


static sc_integer Button_A_ST_BUTTON_UP_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_BUTTON_UP. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (0))
	{ 
		if (handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised == bool_true)
		{ 
			exseq_Button_A_ST_BUTTON_UP(handle);
			sc_prefix_internal_set_vi_button(handle, op_button_get(SC_PREFIX_SC_PREFIXIFACE_BTN_A));
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised = bool_false;
			react_Button_A__choice_0(handle);
			transitioned_after = 0;
		} 
	} 
	return transitioned_after;
}

static sc_integer Button_A_ST_BUTTON_FALLING_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_BUTTON_FALLING. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (0))
	{ 
		if (handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised == bool_true)
		{ 
			exseq_Button_A_ST_BUTTON_FALLING(handle);
			sc_prefix_internal_set_vi_button(handle, op_button_get(SC_PREFIX_SC_PREFIXIFACE_BTN_A));
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised = bool_false;
			react_Button_A__choice_1(handle);
			transitioned_after = 0;
		} 
	} 
	return transitioned_after;
}

static sc_integer Button_A_ST_BUTTON_DOWN_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_BUTTON_DOWN. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (0))
	{ 
		if (handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised == bool_true)
		{ 
			exseq_Button_A_ST_BUTTON_DOWN(handle);
			sc_prefix_internal_set_vi_button(handle, op_button_get(SC_PREFIX_SC_PREFIXIFACE_BTN_A));
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised = bool_false;
			react_Button_A__choice_3(handle);
			transitioned_after = 0;
		} 
	} 
	return transitioned_after;
}

static sc_integer Button_A_ST_BUTTON_RISING_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_BUTTON_RISING. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (0))
	{ 
		if (handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised == bool_true)
		{ 
			exseq_Button_A_ST_BUTTON_RISING(handle);
			sc_prefix_internal_set_vi_button(handle, op_button_get(SC_PREFIX_SC_PREFIXIFACE_BTN_A));
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised = bool_false;
			react_Button_A__choice_2(handle);
			transitioned_after = 0;
		} 
	} 
	return transitioned_after;
}

static sc_integer System_ST_SYSTEM_IDLE_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_SYSTEM_IDLE. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (1))
	{ 
		if (handle->internal.ev_button_a_up_raised == bool_true)
		{ 
			exseq_System_ST_SYSTEM_IDLE(handle);
			handle->internal.vi_system++;
			sc_prefix_add_event_to_queue(&(handle->internal_event_queue), Sc_prefix_internal_ev_led_a_blink);
			enseq_System_ST_SYSTEM_ACTIVE_default(handle);
			transitioned_after = 1;
		} 
	} 
	return transitioned_after;
}

static sc_integer System_ST_SYSTEM_ACTIVE_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_SYSTEM_ACTIVE. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (1))
	{ 
		if (handle->internal.ev_button_a_down_raised == bool_true)
		{ 
			exseq_System_ST_SYSTEM_ACTIVE(handle);
			sc_prefix_add_event_to_queue(&(handle->internal_event_queue), Sc_prefix_internal_ev_led_a_on);
			enseq_System_ST_SYSTEM_IDLE_default(handle);
			transitioned_after = 1;
		} 
	} 
	return transitioned_after;
}

static sc_integer Led_A_ST_LED_OFF_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_LED_OFF. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (2))
	{ 
		if (handle->internal.ev_led_a_blink_raised == bool_true)
		{ 
			exseq_Led_A_ST_LED_OFF(handle);
			enseq_Led_A_ST_LED_BLINK_default(handle);
			transitioned_after = 2;
		}  else
		{
			if (handle->internal.ev_led_a_on_raised == bool_true)
			{ 
				exseq_Led_A_ST_LED_OFF(handle);
				enseq_Led_A_ST_LED_ON_default(handle);
				transitioned_after = 2;
			} 
		}
	} 
	/* If no transition was taken */
	if ((transitioned_after) == (transitioned_before))
	{ 
		/* then execute local reactions. */
		transitioned_after = transitioned_before;
	} 
	return transitioned_after;
}

static sc_integer Led_A_ST_LED_ON_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_LED_ON. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (2))
	{ 
		if (handle->internal.ev_led_a_off_raised == bool_true)
		{ 
			exseq_Led_A_ST_LED_ON(handle);
			enseq_Led_A_ST_LED_OFF_default(handle);
			transitioned_after = 2;
		}  else
		{
			if (handle->internal.ev_led_a_blink_raised == bool_true)
			{ 
				exseq_Led_A_ST_LED_ON(handle);
				enseq_Led_A_ST_LED_BLINK_default(handle);
				transitioned_after = 2;
			} 
		}
	} 
	/* If no transition was taken */
	if ((transitioned_after) == (transitioned_before))
	{ 
		/* then execute local reactions. */
		transitioned_after = transitioned_before;
	} 
	return transitioned_after;
}

static sc_integer Led_A_ST_LED_BLINK_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_LED_BLINK. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (2))
	{ 
		if (handle->internal.ev_led_a_off_raised == bool_true)
		{ 
			exseq_Led_A_ST_LED_BLINK(handle);
			enseq_Led_A_ST_LED_OFF_default(handle);
			transitioned_after = 2;
		}  else
		{
			if (handle->internal.ev_led_a_on_raised == bool_true)
			{ 
				exseq_Led_A_ST_LED_BLINK(handle);
				enseq_Led_A_ST_LED_ON_default(handle);
				transitioned_after = 2;
			} 
		}
	} 
	/* If no transition was taken */
	if ((transitioned_after) == (transitioned_before))
	{ 
		/* then execute local reactions. */
		transitioned_after = transitioned_before;
	} 
	return transitioned_after;
}

static sc_integer Led_A_ST_LED_BLINK_r1_ST_LED_ON_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_LED_ON. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (2))
	{ 
		if (handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised == bool_true)
		{ 
			exseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON(handle);
			handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised = bool_false;
			enseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_default(handle);
			Led_A_ST_LED_BLINK_react(handle,2);
			transitioned_after = 2;
		} 
	} 
	/* If no transition was taken */
	if ((transitioned_after) == (transitioned_before))
	{ 
		/* then execute local reactions. */
		transitioned_after = Led_A_ST_LED_BLINK_react(handle,transitioned_before);
	} 
	return transitioned_after;
}

static sc_integer Led_A_ST_LED_BLINK_r1_ST_LED_OFF_react(Sc_prefix* handle, const sc_integer transitioned_before)
{
	/* The reactions of state ST_LED_OFF. */
 			sc_integer transitioned_after = transitioned_before;
	if ((transitioned_after) < (2))
	{ 
		if (handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised == bool_true)
		{ 
			exseq_Led_A_ST_LED_BLINK_r1_ST_LED_OFF(handle);
			handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised = bool_false;
			enseq_Led_A_ST_LED_BLINK_r1_ST_LED_ON_default(handle);
			Led_A_ST_LED_BLINK_react(handle,2);
			transitioned_after = 2;
		} 
	} 
	/* If no transition was taken */
	if ((transitioned_after) == (transitioned_before))
	{ 
		/* then execute local reactions. */
		transitioned_after = Led_A_ST_LED_BLINK_react(handle,transitioned_before);
	} 
	return transitioned_after;
}




static void sc_prefix_eventqueue_init(sc_prefix_eventqueue * eq, sc_prefix_event *buffer, sc_integer capacity)
{
	eq->events = buffer;
	eq->capacity = capacity;
	eq->push_index = 0;
	eq->pop_index = 0;
	eq->size = 0;
}

static sc_integer sc_prefix_eventqueue_size(sc_prefix_eventqueue * eq)
{
	return eq->size;
}

static sc_prefix_event sc_prefix_eventqueue_pop(sc_prefix_eventqueue * eq)
{
	sc_prefix_event event;
	if(sc_prefix_eventqueue_size(eq) <= 0) {
		sc_prefix_event_init(&event, Sc_prefix_invalid_event);
	}
	else {
		event = eq->events[eq->pop_index];
		
		if(eq->pop_index < eq->capacity - 1) {
			eq->pop_index++;
		} 
		else {
			eq->pop_index = 0;
		}
		eq->size--;
	}
	return event;
}
static sc_boolean sc_prefix_eventqueue_push(sc_prefix_eventqueue * eq, sc_prefix_event ev)
{
	if(sc_prefix_eventqueue_size(eq) == eq->capacity) {
		return bool_false;
	}
	else {
		eq->events[eq->push_index] = ev;
		
		if(eq->push_index < eq->capacity - 1) {
			eq->push_index++;
		}
		else {
			eq->push_index = 0;
		}
		eq->size++;
		
		return bool_true;
	}
}
static void sc_prefix_event_init(sc_prefix_event * ev, Sc_prefixEventID name)
{
	ev->name = name;
}

static void sc_prefix_add_event_to_queue(sc_prefix_eventqueue * eq, Sc_prefixEventID name)
{
	sc_prefix_event event;
	sc_prefix_event_init(&event, name);
	sc_prefix_eventqueue_push(eq, event);
}

static sc_boolean sc_prefix_dispatch_event(Sc_prefix* handle, const sc_prefix_event * event) {
	switch(event->name) {
		case Sc_prefix_internal_ev_button_a_down:
		{
			handle->internal.ev_button_a_down_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_internal_ev_button_a_up:
		{
			handle->internal.ev_button_a_up_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_internal_ev_led_a_blink:
		{
			handle->internal.ev_led_a_blink_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_internal_ev_led_a_on:
		{
			handle->internal.ev_led_a_on_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_internal_ev_led_a_off:
		{
			handle->internal.ev_led_a_off_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_sc_prefix_Button_A_ST_BUTTON_UP_time_event_0:
		{
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_sc_prefix_Button_A_ST_BUTTON_FALLING_time_event_0:
		{
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_sc_prefix_Button_A_ST_BUTTON_DOWN_time_event_0:
		{
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_sc_prefix_Button_A_ST_BUTTON_RISING_time_event_0:
		{
			handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_time_event_0:
		{
			handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised = bool_true;
			return bool_true;
		}
		case Sc_prefix_sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_time_event_0:
		{
			handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised = bool_true;
			return bool_true;
		}
		default:
			return bool_false;
	}
}

static sc_prefix_event sc_prefix_get_next_event(Sc_prefix* handle)
{
	sc_prefix_event next_event;
	sc_prefix_event_init(&next_event, Sc_prefix_invalid_event);
	if(sc_prefix_eventqueue_size(&(handle->internal_event_queue)) > 0) {
		next_event = sc_prefix_eventqueue_pop(&(handle->internal_event_queue));
	}
	else if(sc_prefix_eventqueue_size(&(handle->in_event_queue)) > 0) {
		next_event = sc_prefix_eventqueue_pop(&(handle->in_event_queue));
	}
	return next_event;
}

static sc_boolean sc_prefix_dispatch_next_event(Sc_prefix* handle)
{
	sc_prefix_event nextEvent;
	nextEvent = sc_prefix_get_next_event(handle);
	return sc_prefix_dispatch_event(handle, &nextEvent);
}

static Sc_prefixEventID sc_prefix_get_timed_event_name(Sc_prefix* handle, sc_eventid evid)
{
	if(evid == &handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_UP_tev0_raised) {
		return Sc_prefix_sc_prefix_Button_A_ST_BUTTON_UP_time_event_0;
	}
	if(evid == &handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_FALLING_tev0_raised) {
		return Sc_prefix_sc_prefix_Button_A_ST_BUTTON_FALLING_time_event_0;
	}
	if(evid == &handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_DOWN_tev0_raised) {
		return Sc_prefix_sc_prefix_Button_A_ST_BUTTON_DOWN_time_event_0;
	}
	if(evid == &handle->timeEvents.sc_prefix_Button_A_ST_BUTTON_RISING_tev0_raised) {
		return Sc_prefix_sc_prefix_Button_A_ST_BUTTON_RISING_time_event_0;
	}
	if(evid == &handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_tev0_raised) {
		return Sc_prefix_sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_ON_time_event_0;
	}
	if(evid == &handle->timeEvents.sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_tev0_raised) {
		return Sc_prefix_sc_prefix_Led_A_ST_LED_BLINK_r1_ST_LED_OFF_time_event_0;
	}
	return Sc_prefix_invalid_event;
}

