diff --git a/examples/c/sapi/statecharts/1_toggle/config.mk b/examples/c/sapi/statecharts/1_toggle/config.mk
new file mode 100644
index 00000000..dd54d2b5
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/config.mk
@@ -0,0 +1,18 @@
+# Compile options
+VERBOSE=n
+OPT=g
+USE_NANO=y
+SEMIHOST=n
+USE_FPU=y
+
+# Libraries
+USE_LPCOPEN=y
+USE_SAPI=y
+USE_FREERTOS=n
+FREERTOS_HEAP_TYPE=5
+LOAD_INRAM=n
+
+# Yakindu SCT - To Compile and Link Generated Sate Machine Code
+INCLUDES = -I$(PROGRAM_PATH_AND_NAME)/gen
+INCLUDES += -I$(PROGRAM_PATH_AND_NAME)/inc
+SRC = $(wildcard $(PROGRAM_PATH_AND_NAME)/gen/*.c)
diff --git a/examples/c/sapi/statecharts/1_toggle/gen/.gitignore b/examples/c/sapi/statecharts/1_toggle/gen/.gitignore
new file mode 100644
index 00000000..69a84b71
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/gen/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!readme.md
diff --git a/examples/c/sapi/statecharts/1_toggle/gen/readme.md b/examples/c/sapi/statecharts/1_toggle/gen/readme.md
new file mode 100644
index 00000000..c233ea9c
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/gen/readme.md
@@ -0,0 +1 @@
+Folder for Yakindu SCT generated source files.
diff --git a/examples/c/sapi/statecharts/1_toggle/inc/.gitignore b/examples/c/sapi/statecharts/1_toggle/inc/.gitignore
new file mode 100644
index 00000000..c88a1eb7
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/inc/.gitignore
@@ -0,0 +1 @@
+sc_types.h
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/1_toggle/inc/main.h b/examples/c/sapi/statecharts/1_toggle/inc/main.h
new file mode 100644
index 00000000..03f53d16
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/inc/main.h
@@ -0,0 +1,69 @@
+/* Copyright 2017, Pablo Ridolfi Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*==================[macros]=================================================*/
+
+/*==================[typedef]================================================*/
+
+/*==================[external data declaration]==============================*/
+
+/*==================[external functions declaration]=========================*/
+
+/** @brief main function
+ * @return main function should never return
+ */
+int main(void);
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} doxygen end group definition */
+/*==================[end of file]============================================*/
+#endif /* #ifndef _MAIN_H_ */
diff --git a/examples/c/sapi/statecharts/1_toggle/readme.md b/examples/c/sapi/statecharts/1_toggle/readme.md
new file mode 100644
index 00000000..9bf97539
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/readme.md
@@ -0,0 +1,17 @@
+# Statechart example using sysTick
+
+
+- Description: The Statechart example simply toggle an LED at a periodic rate using the sysTick timer.
+
+ - The sysTick Interrupt Handler only set a Flag.
+
+ - LED state is toggled in the main program.
+ - The uC sleeps waiting for an interruption.
+
+ - When a interrupt wakes to the uC, the main program validates it,
+ checking the waited Flag.
+ - Then reset its Flag.
+ - Then Raise an Event -> evTick => OK.
+ - Then Run an Cycle of Statechart.
+
+ - And then the uC sleeps again.
diff --git a/examples/c/sapi/statecharts/1_toggle/src/main.c b/examples/c/sapi/statecharts/1_toggle/src/main.c
new file mode 100644
index 00000000..884086bc
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/src/main.c
@@ -0,0 +1,157 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief This is a simple statechart example using Yakindu Statechart Tool
+ * Plug-in (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+#include "sapi.h" // <= sAPI header
+
+/* Include statechart header file. Be sure you run the statechart C code
+ * generation tool!
+ */
+#include "Toggle.h"
+
+
+/*==================[macros and definitions]=================================*/
+
+#define TICKRATE_1MS (1) /* 1000 ticks per second */
+#define TICKRATE_MS (TICKRATE_1MS) /* 1000 ticks per second */
+
+
+/*==================[internal data declaration]==============================*/
+
+volatile bool SysTick_Time_Flag = false;
+
+/*! This is a state machine */
+static Toggle statechart;
+
+
+/*==================[internal functions declaration]=========================*/
+
+/*==================[internal data definition]===============================*/
+
+/*==================[external data definition]===============================*/
+
+/*==================[internal functions definition]==========================*/
+
+/*==================[external functions definition]==========================*/
+
+/*! \file This header defines prototypes for all functions that are required
+ * by the state machine implementation.
+ *
+ * This state machine makes use of operations declared in the state machines
+ * interface or internal scopes. Thus the function prototypes:
+ * - toggleIface_opLED
+ * are defined.
+ *
+ * These functions will be called during a 'run to completion step' (runCycle)
+ * of the statechart.
+ * There are some constraints that have to be considered for the
+ * implementation of these functions:
+ * - never call the statechart API functions from within these functions.
+ * - make sure that the execution time is as short as possible.
+ */
+
+/** state machine user-defined external function (action)
+ *
+ * @param handle state machine instance
+ * @param LEDNumber number of LED
+ * @param onoff state machine operation parameter
+ */
+void toggleIface_opLED( Toggle* handle, sc_integer LEDNumber )
+{
+ gpioToggle( (LEDR + LEDNumber) );
+}
+
+
+/**
+ * @brief Hook on Handle interrupt from SysTick timer
+ * @return Nothing
+ */
+void myTickHook( void *ptr ){
+
+ /* The sysTick Interrupt Handler only set a Flag */
+ SysTick_Time_Flag = true;
+}
+
+
+/**
+ * @brief main routine for statechart example: EDU-CIAA-NXP - Toggle LED3
+ * @return Function should not exit.
+ */
+int main(void)
+{
+ /* Generic Initialization */
+ boardConfig();
+
+ /* Init Ticks counter => TICKRATE_MS */
+ tickConfig( TICKRATE_MS );
+
+ /* Add Tick Hook */
+ tickCallbackSet( myTickHook, (void*)NULL );
+
+ /* Statechart Initialization */
+ toggle_init( &statechart );
+ toggle_enter( &statechart );
+
+ /* LED state is toggled in the main program */
+ while (1) {
+ /* The uC sleeps waiting for an interruption */
+ __WFI();
+
+ /* When a interrupt wakes to the uC, the main program validates it,
+ * checking the waited Flag */
+ if (SysTick_Time_Flag == true) {
+
+ /* Then reset its Flag */
+ SysTick_Time_Flag = false;
+
+ /* Then Raise an Event -> evTick => OK */
+ toggleIface_raise_evTick( &statechart );
+
+ /* Then Run an Cycle of Statechart */
+ toggle_runCycle( &statechart );
+ }
+ }
+}
+
+
+/** @} doxygen end group definition */
+
+/*==================[end of file]============================================*/
diff --git a/examples/c/sapi/statecharts/1_toggle/toggle.sct b/examples/c/sapi/statecharts/1_toggle/toggle.sct
new file mode 100644
index 00000000..342b8be4
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/toggle.sct
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/c/sapi/statecharts/1_toggle/toggle.sgen b/examples/c/sapi/statecharts/1_toggle/toggle.sgen
new file mode 100644
index 00000000..84e83061
--- /dev/null
+++ b/examples/c/sapi/statecharts/1_toggle/toggle.sgen
@@ -0,0 +1,11 @@
+GeneratorModel for yakindu::c {
+
+ statechart toggle {
+
+ feature Outlet {
+ targetProject = "firmware_v3"
+ targetFolder = "examples/c/sapi/statecharts/1_toggle/gen"
+ libraryTargetFolder = "examples/c/sapi/statecharts/1_toggle/inc"
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/2_blink/blink.sct b/examples/c/sapi/statecharts/2_blink/blink.sct
new file mode 100644
index 00000000..b61a6be1
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/blink.sct
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/c/sapi/statecharts/2_blink/blink.sgen b/examples/c/sapi/statecharts/2_blink/blink.sgen
new file mode 100644
index 00000000..d1ad46aa
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/blink.sgen
@@ -0,0 +1,11 @@
+GeneratorModel for yakindu::c {
+
+ statechart blink {
+
+ feature Outlet {
+ targetProject = "firmware_v3"
+ targetFolder = "examples/c/sapi/statecharts/2_blink/gen"
+ libraryTargetFolder = "examples/c/sapi/statecharts/2_blink/inc"
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/2_blink/config.mk b/examples/c/sapi/statecharts/2_blink/config.mk
new file mode 100644
index 00000000..dd54d2b5
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/config.mk
@@ -0,0 +1,18 @@
+# Compile options
+VERBOSE=n
+OPT=g
+USE_NANO=y
+SEMIHOST=n
+USE_FPU=y
+
+# Libraries
+USE_LPCOPEN=y
+USE_SAPI=y
+USE_FREERTOS=n
+FREERTOS_HEAP_TYPE=5
+LOAD_INRAM=n
+
+# Yakindu SCT - To Compile and Link Generated Sate Machine Code
+INCLUDES = -I$(PROGRAM_PATH_AND_NAME)/gen
+INCLUDES += -I$(PROGRAM_PATH_AND_NAME)/inc
+SRC = $(wildcard $(PROGRAM_PATH_AND_NAME)/gen/*.c)
diff --git a/examples/c/sapi/statecharts/2_blink/gen/.gitignore b/examples/c/sapi/statecharts/2_blink/gen/.gitignore
new file mode 100644
index 00000000..69a84b71
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/gen/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!readme.md
diff --git a/examples/c/sapi/statecharts/2_blink/gen/readme.md b/examples/c/sapi/statecharts/2_blink/gen/readme.md
new file mode 100644
index 00000000..c233ea9c
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/gen/readme.md
@@ -0,0 +1 @@
+Folder for Yakindu SCT generated source files.
diff --git a/examples/c/sapi/statecharts/2_blink/inc/.gitignore b/examples/c/sapi/statecharts/2_blink/inc/.gitignore
new file mode 100644
index 00000000..c88a1eb7
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/inc/.gitignore
@@ -0,0 +1 @@
+sc_types.h
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/2_blink/inc/TimerTicks.h b/examples/c/sapi/statecharts/2_blink/inc/TimerTicks.h
new file mode 100644
index 00000000..b97f306d
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/inc/TimerTicks.h
@@ -0,0 +1,56 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TIMERTICKS_H_
+#define TIMERTICKS_H_
+
+
+typedef struct
+{
+ sc_eventid evid;
+ sc_uinteger time_ms;
+ sc_uinteger count;
+ sc_boolean periodic;
+ sc_boolean active;
+ sc_boolean evPending;
+} TimerTicks;
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len);
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic);
+sc_eventid UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid);
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void UpdateTimers(TimerTicks *list, uint32_t len);
+
+#endif /* TIMERTICKS_H_ */
diff --git a/examples/c/sapi/statecharts/2_blink/inc/main.h b/examples/c/sapi/statecharts/2_blink/inc/main.h
new file mode 100644
index 00000000..0b5f39b9
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/inc/main.h
@@ -0,0 +1,69 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcón, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*==================[macros]=================================================*/
+
+/*==================[typedef]================================================*/
+
+/*==================[external data declaration]==============================*/
+
+/*==================[external functions declaration]=========================*/
+
+/** @brief main function
+ * @return main function should never return
+ */
+int main(void);
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} doxygen end group definition */
+/*==================[end of file]============================================*/
+#endif /* #ifndef _MAIN_H_ */
diff --git a/examples/c/sapi/statecharts/2_blink/readme.md b/examples/c/sapi/statecharts/2_blink/readme.md
new file mode 100644
index 00000000..9c2d5cc7
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/readme.md
@@ -0,0 +1,20 @@
+# Statechart example using sysTick and Yakindu Time Events
+
+
+- Description: The Statechart example simply toggle an LED at a periodic rate using the sysTick timer and Yakindu Time Events (Timer Ticks).
+
+ - The sysTick Interrupt Handler only set a Flag.
+
+ - LED state is toggled in the main program.
+ - The uC sleeps waiting for an interruption.
+
+ - When a interrupt wakes to the uC, the main program validates it,
+ checking the waited Flag.
+ - Then reset its Flag.
+ - Then Update all Timer Ticks.
+ - Then Scan all Timer Ticks and if there are pending events
+ - Then Raise an Event -> Ticks.evid => OK
+ - Then Mark as Attached -> Ticks.evid => OK
+ - Then Run an Cycle of Statechart.
+
+ - And then the uC sleeps again.
diff --git a/examples/c/sapi/statecharts/2_blink/src/TimerTicks.c b/examples/c/sapi/statecharts/2_blink/src/TimerTicks.c
new file mode 100644
index 00000000..65dded07
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/src/TimerTicks.c
@@ -0,0 +1,147 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief These are the Timer Ticks functions for simple statechart example
+ * using Yakindu Statechart Tool Plug-in
+ * (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+#include "Blink.h"
+#include "TimerTicks.h"
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ }
+}
+
+
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic)
+{
+ uint32_t i;
+
+ sc_eventid ret = (sc_eventid)0;
+ for(i = 0; i < len; i++) {
+ if(!list[i].evid) {
+ list[i].time_ms = time_ms;
+ list[i].count = time_ms;
+ list[i].evid = evid;
+ list[i].periodic = periodic;
+ list[i].active = true;
+ list[i].evPending = false;
+ ret = evid;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void* UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+ sc_eventid ret = (sc_eventid)0;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ ret = id;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ int i;
+ sc_boolean ret = false;
+ for(i=0; i < len; i++) {
+ if((list[i].evid == id) && (list[i].evPending == true)) {
+ ret = true;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evPending = false;
+ break;
+ }
+ }
+}
+
+
+void UpdateTimers(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].active == true) {
+ if(list[i].count)
+ list[i].count--;
+ if(!list[i].count) {
+ if(list[i].periodic)
+ list[i].count = list[i].time_ms;
+ else
+ list[i].active = false;
+ list[i].evPending = true;
+ }
+ }
+ }
+}
diff --git a/examples/c/sapi/statecharts/2_blink/src/main.c b/examples/c/sapi/statecharts/2_blink/src/main.c
new file mode 100644
index 00000000..32960b40
--- /dev/null
+++ b/examples/c/sapi/statecharts/2_blink/src/main.c
@@ -0,0 +1,221 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief This is a simple statechart example using Yakindu Statechart Tool
+ * Plug-in (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+#include "main.h"
+
+#include "sapi.h" // <= sAPI header
+
+/* Include statechart header file. Be sure you run the statechart C code
+ * generation tool!
+ */
+#include "Blink.h"
+#include "TimerTicks.h"
+
+
+/*==================[macros and definitions]=================================*/
+
+#define TICKRATE_1MS (1) /* 1000 ticks per second */
+#define TICKRATE_MS (TICKRATE_1MS) /* 1000 ticks per second */
+
+
+/*==================[internal data declaration]==============================*/
+
+volatile bool SysTick_Time_Flag = false;
+
+/*! This is a state machine */
+static Blink statechart;
+
+/*! This is a timed state machine that requires timer services */
+#define NOF_TIMERS (sizeof(BlinkTimeEvents)/sizeof(sc_boolean))
+
+TimerTicks ticks[NOF_TIMERS];
+
+
+/*==================[internal functions declaration]=========================*/
+
+/*==================[internal data definition]===============================*/
+
+/*==================[external data definition]===============================*/
+
+/*==================[internal functions definition]==========================*/
+
+/*==================[external functions definition]==========================*/
+
+/*! \file This header defines prototypes for all functions that are required
+ * by the state machine implementation.
+ *
+ * This is a state machine uses time events which require access to a timing
+ * service. Thus the function prototypes:
+ * - blink_setTimer and
+ * - blink_unsetTimer
+ * are defined.
+ *
+ * This state machine makes use of operations declared in the state machines
+ * interface or internal scopes. Thus the function prototypes:
+ * - blinkIface_opLED
+ * are defined.
+ *
+ * These functions will be called during a 'run to completion step' (runCycle)
+ * of the statechart.
+ * There are some constraints that have to be considered for the
+ * implementation of these functions:
+ * - never call the statechart API functions from within these functions.
+ * - make sure that the execution time is as short as possible.
+ */
+
+/** state machine user-defined external function (action)
+ *
+ * @param handle state machine instance
+ * @param LEDNumber number of LED
+ * @param onoff state machine operation parameter
+ */
+void blinkIface_opLED( Blink* handle, sc_integer LEDNumber, sc_boolean State )
+{
+ gpioWrite( (LEDR + LEDNumber), State );
+}
+
+
+/*! * This is a timed state machine that requires timer services
+ */
+
+/*! This function has to set up timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be entered.
+ * \param evid An unique identifier of the event.
+ * \time_ms The time in milli seconds
+ * \periodic Indicates the the time event must be raised periodically until
+ * the timer is unset
+ */
+void blink_setTimer( Blink* handle, const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic )
+{
+ SetNewTimerTick(ticks, NOF_TIMERS, evid, time_ms, periodic);
+}
+
+/*! This function has to unset timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be left.
+ * \param evid An unique identifier of the event.
+ */
+void blink_unsetTimer( Blink* handle, const sc_eventid evid )
+{
+ UnsetTimerTick( ticks, NOF_TIMERS, evid );
+}
+
+
+/**
+ * @brief Hook on Handle interrupt from SysTick timer
+ * @return Nothing
+ */
+void myTickHook( void *ptr ){
+
+ /* The sysTick Interrupt Handler only set a Flag */
+ SysTick_Time_Flag = true;
+}
+
+
+/**
+ * @brief main routine for statechart example: EDU-CIAA-NXP - Blink LED3
+ * @return Function should not exit.
+ */
+int main(void)
+{
+ uint32_t i;
+
+ /* Generic Initialization */
+ boardConfig();
+
+ /* Init Ticks counter => TICKRATE_MS */
+ tickConfig( TICKRATE_MS );
+
+ /* Add Tick Hook */
+ tickCallbackSet( myTickHook, (void*)NULL );
+
+ /* Init Timer Ticks */
+ InitTimerTicks( ticks, NOF_TIMERS );
+
+ /* Statechart Initialization */
+ blink_init( &statechart );
+ blink_enter( &statechart );
+
+ /* LED state is toggled in the main program */
+ while (1) {
+ /* The uC sleeps waiting for an interruption */
+ __WFI();
+
+ /* When a interrupt wakes to the uC, the main program validates it,
+ * checking the waited Flag */
+ if (SysTick_Time_Flag == true) {
+
+ /* Then reset its Flag */
+ SysTick_Time_Flag = false;
+
+ /* Then Update all Timer Ticks */
+ UpdateTimers( ticks, NOF_TIMERS );
+
+ /* Then Scan all Timer Ticks */
+ for (i = 0; i < NOF_TIMERS; i++) {
+
+ /* Then if there are pending events */
+ if (IsPendEvent( ticks, NOF_TIMERS, ticks[i].evid ) == true) {
+
+ /* Then Raise an Event -> Ticks.evid => OK */
+ blink_raiseTimeEvent( &statechart, ticks[i].evid );
+
+ /* Then Mark as Attached -> Ticks.evid => OK */
+ MarkAsAttEvent( ticks, NOF_TIMERS, ticks[i].evid );
+ }
+ }
+
+ /* Then Run an Cycle of Statechart */
+ blink_runCycle(&statechart); // Run Cycle of Statechart
+ }
+ }
+}
+
+
+/** @} doxygen end group definition */
+
+/*==================[end of file]============================================*/
diff --git a/examples/c/sapi/statecharts/3_idleBlink/config.mk b/examples/c/sapi/statecharts/3_idleBlink/config.mk
new file mode 100644
index 00000000..dd54d2b5
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/config.mk
@@ -0,0 +1,18 @@
+# Compile options
+VERBOSE=n
+OPT=g
+USE_NANO=y
+SEMIHOST=n
+USE_FPU=y
+
+# Libraries
+USE_LPCOPEN=y
+USE_SAPI=y
+USE_FREERTOS=n
+FREERTOS_HEAP_TYPE=5
+LOAD_INRAM=n
+
+# Yakindu SCT - To Compile and Link Generated Sate Machine Code
+INCLUDES = -I$(PROGRAM_PATH_AND_NAME)/gen
+INCLUDES += -I$(PROGRAM_PATH_AND_NAME)/inc
+SRC = $(wildcard $(PROGRAM_PATH_AND_NAME)/gen/*.c)
diff --git a/examples/c/sapi/statecharts/3_idleBlink/gen/.gitignore b/examples/c/sapi/statecharts/3_idleBlink/gen/.gitignore
new file mode 100644
index 00000000..69a84b71
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/gen/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!readme.md
diff --git a/examples/c/sapi/statecharts/3_idleBlink/gen/readme.md b/examples/c/sapi/statecharts/3_idleBlink/gen/readme.md
new file mode 100644
index 00000000..c233ea9c
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/gen/readme.md
@@ -0,0 +1 @@
+Folder for Yakindu SCT generated source files.
diff --git a/examples/c/sapi/statecharts/3_idleBlink/idleBlink.sct b/examples/c/sapi/statecharts/3_idleBlink/idleBlink.sct
new file mode 100644
index 00000000..f0a72eb9
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/idleBlink.sct
@@ -0,0 +1,218 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/c/sapi/statecharts/3_idleBlink/idleBlink.sgen b/examples/c/sapi/statecharts/3_idleBlink/idleBlink.sgen
new file mode 100644
index 00000000..5319b608
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/idleBlink.sgen
@@ -0,0 +1,11 @@
+GeneratorModel for yakindu::c {
+
+ statechart idleBlink {
+
+ feature Outlet {
+ targetProject = "firmware_v3"
+ targetFolder = "examples/c/sapi/statecharts/3_idleBlink/gen"
+ libraryTargetFolder = "examples/c/sapi/statecharts/3_idleBlink/inc"
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/3_idleBlink/inc/.gitignore b/examples/c/sapi/statecharts/3_idleBlink/inc/.gitignore
new file mode 100644
index 00000000..c88a1eb7
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/inc/.gitignore
@@ -0,0 +1 @@
+sc_types.h
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/3_idleBlink/inc/TimerTicks.h b/examples/c/sapi/statecharts/3_idleBlink/inc/TimerTicks.h
new file mode 100644
index 00000000..b97f306d
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/inc/TimerTicks.h
@@ -0,0 +1,56 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TIMERTICKS_H_
+#define TIMERTICKS_H_
+
+
+typedef struct
+{
+ sc_eventid evid;
+ sc_uinteger time_ms;
+ sc_uinteger count;
+ sc_boolean periodic;
+ sc_boolean active;
+ sc_boolean evPending;
+} TimerTicks;
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len);
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic);
+sc_eventid UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid);
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void UpdateTimers(TimerTicks *list, uint32_t len);
+
+#endif /* TIMERTICKS_H_ */
diff --git a/examples/c/sapi/statecharts/3_idleBlink/inc/main.h b/examples/c/sapi/statecharts/3_idleBlink/inc/main.h
new file mode 100644
index 00000000..0b5f39b9
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/inc/main.h
@@ -0,0 +1,69 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcón, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*==================[macros]=================================================*/
+
+/*==================[typedef]================================================*/
+
+/*==================[external data declaration]==============================*/
+
+/*==================[external functions declaration]=========================*/
+
+/** @brief main function
+ * @return main function should never return
+ */
+int main(void);
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} doxygen end group definition */
+/*==================[end of file]============================================*/
+#endif /* #ifndef _MAIN_H_ */
diff --git a/examples/c/sapi/statecharts/3_idleBlink/readme.md b/examples/c/sapi/statecharts/3_idleBlink/readme.md
new file mode 100644
index 00000000..9c2d5cc7
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/readme.md
@@ -0,0 +1,20 @@
+# Statechart example using sysTick and Yakindu Time Events
+
+
+- Description: The Statechart example simply toggle an LED at a periodic rate using the sysTick timer and Yakindu Time Events (Timer Ticks).
+
+ - The sysTick Interrupt Handler only set a Flag.
+
+ - LED state is toggled in the main program.
+ - The uC sleeps waiting for an interruption.
+
+ - When a interrupt wakes to the uC, the main program validates it,
+ checking the waited Flag.
+ - Then reset its Flag.
+ - Then Update all Timer Ticks.
+ - Then Scan all Timer Ticks and if there are pending events
+ - Then Raise an Event -> Ticks.evid => OK
+ - Then Mark as Attached -> Ticks.evid => OK
+ - Then Run an Cycle of Statechart.
+
+ - And then the uC sleeps again.
diff --git a/examples/c/sapi/statecharts/3_idleBlink/src/TimerTicks.c b/examples/c/sapi/statecharts/3_idleBlink/src/TimerTicks.c
new file mode 100644
index 00000000..9e1db8b5
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/src/TimerTicks.c
@@ -0,0 +1,147 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief These are the Timer Ticks functions for simple statechart example
+ * using Yakindu Statechart Tool Plug-in
+ * (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+#include "IdleBlink.h"
+#include "TimerTicks.h"
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ }
+}
+
+
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic)
+{
+ uint32_t i;
+
+ sc_eventid ret = (sc_eventid)0;
+ for(i = 0; i < len; i++) {
+ if(!list[i].evid) {
+ list[i].time_ms = time_ms;
+ list[i].count = time_ms;
+ list[i].evid = evid;
+ list[i].periodic = periodic;
+ list[i].active = true;
+ list[i].evPending = false;
+ ret = evid;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void* UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+ sc_eventid ret = (sc_eventid)0;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ ret = id;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ int i;
+ sc_boolean ret = false;
+ for(i=0; i < len; i++) {
+ if((list[i].evid == id) && (list[i].evPending == true)) {
+ ret = true;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evPending = false;
+ break;
+ }
+ }
+}
+
+
+void UpdateTimers(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].active == true) {
+ if(list[i].count)
+ list[i].count--;
+ if(!list[i].count) {
+ if(list[i].periodic)
+ list[i].count = list[i].time_ms;
+ else
+ list[i].active = false;
+ list[i].evPending = true;
+ }
+ }
+ }
+}
diff --git a/examples/c/sapi/statecharts/3_idleBlink/src/main.c b/examples/c/sapi/statecharts/3_idleBlink/src/main.c
new file mode 100644
index 00000000..b4cc4fee
--- /dev/null
+++ b/examples/c/sapi/statecharts/3_idleBlink/src/main.c
@@ -0,0 +1,221 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief This is a simple statechart example using Yakindu Statechart Tool
+ * Plug-in (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+#include "main.h"
+
+#include "sapi.h" // <= sAPI header
+
+/* Include statechart header file. Be sure you run the statechart C code
+ * generation tool!
+ */
+#include "IdleBlink.h"
+#include "TimerTicks.h"
+
+
+/*==================[macros and definitions]=================================*/
+
+#define TICKRATE_1MS (1) /* 1000 ticks per second */
+#define TICKRATE_MS (TICKRATE_1MS) /* 1000 ticks per second */
+
+
+/*==================[internal data declaration]==============================*/
+
+volatile bool SysTick_Time_Flag = false;
+
+/*! This is a state machine */
+static IdleBlink statechart;
+
+/*! This is a timed state machine that requires timer services */
+#define NOF_TIMERS (sizeof(IdleBlinkTimeEvents)/sizeof(sc_boolean))
+
+TimerTicks ticks[NOF_TIMERS];
+
+
+/*==================[internal functions declaration]=========================*/
+
+/*==================[internal data definition]===============================*/
+
+/*==================[external data definition]===============================*/
+
+/*==================[internal functions definition]==========================*/
+
+/*==================[external functions definition]==========================*/
+
+/*! \file This header defines prototypes for all functions that are required
+ * by the state machine implementation.
+ *
+ * This is a state machine uses time events which require access to a timing
+ * service. Thus the function prototypes:
+ * - idleBlink_setTimer and
+ * - idleBlink_unsetTimer
+ * are defined.
+ *
+ * This state machine makes use of operations declared in the state machines
+ * interface or internal scopes. Thus the function prototypes:
+ * - idleBlinkIface_opLED
+ * are defined.
+ *
+ * These functions will be called during a 'run to completion step' (runCycle)
+ * of the statechart.
+ * There are some constraints that have to be considered for the
+ * implementation of these functions:
+ * - never call the statechart API functions from within these functions.
+ * - make sure that the execution time is as short as possible.
+ */
+
+/** state machine user-defined external function (action)
+ *
+ * @param handle state machine instance
+ * @param LEDNumber number of LED
+ * @param onoff state machine operation parameter
+ */
+void idleBlinkIface_opLED( IdleBlink* handle, sc_integer LEDNumber, sc_boolean State )
+{
+ gpioWrite( (LEDR + LEDNumber), State );
+}
+
+
+/*! * This is a timed state machine that requires timer services
+ */
+
+/*! This function has to set up timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be entered.
+ * \param evid An unique identifier of the event.
+ * \time_ms The time in milli seconds
+ * \periodic Indicates the the time event must be raised periodically until
+ * the timer is unset
+ */
+void idleBlink_setTimer( IdleBlink* handle, const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic )
+{
+ SetNewTimerTick(ticks, NOF_TIMERS, evid, time_ms, periodic);
+}
+
+/*! This function has to unset timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be left.
+ * \param evid An unique identifier of the event.
+ */
+void idleBlink_unsetTimer( IdleBlink* handle, const sc_eventid evid )
+{
+ UnsetTimerTick( ticks, NOF_TIMERS, evid );
+}
+
+
+/**
+ * @brief Hook on Handle interrupt from SysTick timer
+ * @return Nothing
+ */
+void myTickHook( void *ptr ){
+
+ /* The sysTick Interrupt Handler only set a Flag */
+ SysTick_Time_Flag = true;
+}
+
+
+/**
+ * @brief main routine for statechart example: EDU-CIAA-NXP - IdleBlink LED3
+ * @return Function should not exit.
+ */
+int main(void)
+{
+ uint32_t i;
+
+ /* Generic Initialization */
+ boardConfig();
+
+ /* Init Ticks counter => TICKRATE_MS */
+ tickConfig( TICKRATE_MS );
+
+ /* Add Tick Hook */
+ tickCallbackSet( myTickHook, (void*)NULL );
+
+ /* Init Timer Ticks */
+ InitTimerTicks( ticks, NOF_TIMERS );
+
+ /* Statechart Initialization */
+ idleBlink_init( &statechart );
+ idleBlink_enter( &statechart );
+
+ /* LED state is toggled in the main program */
+ while (1) {
+ /* The uC sleeps waiting for an interruption */
+ __WFI();
+
+ /* When a interrupt wakes to the uC, the main program validates it,
+ * checking the waited Flag */
+ if (SysTick_Time_Flag == true) {
+
+ /* Then reset its Flag */
+ SysTick_Time_Flag = false;
+
+ /* Then Update all Timer Ticks */
+ UpdateTimers( ticks, NOF_TIMERS );
+
+ /* Then Scan all Timer Ticks */
+ for (i = 0; i < NOF_TIMERS; i++) {
+
+ /* Then if there are pending events */
+ if (IsPendEvent( ticks, NOF_TIMERS, ticks[i].evid ) == true) {
+
+ /* Then Raise an Event -> Ticks.evid => OK */
+ idleBlink_raiseTimeEvent( &statechart, ticks[i].evid );
+
+ /* Then Mark as Attached -> Ticks.evid => OK */
+ MarkAsAttEvent( ticks, NOF_TIMERS, ticks[i].evid );
+ }
+ }
+
+ /* Then Run an Cycle of Statechart */
+ idleBlink_runCycle(&statechart); // Run Cycle of Statechart
+ }
+ }
+}
+
+
+/** @} doxygen end group definition */
+
+/*==================[end of file]============================================*/
diff --git a/examples/c/sapi/statecharts/4_buttons/Buttons.sct b/examples/c/sapi/statecharts/4_buttons/Buttons.sct
new file mode 100644
index 00000000..153520b9
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/Buttons.sct
@@ -0,0 +1,189 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/c/sapi/statecharts/4_buttons/Buttons.sgen b/examples/c/sapi/statecharts/4_buttons/Buttons.sgen
new file mode 100644
index 00000000..79716c65
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/Buttons.sgen
@@ -0,0 +1,11 @@
+GeneratorModel for yakindu::c {
+
+ statechart buttons {
+
+ feature Outlet {
+ targetProject = "firmware_v3"
+ targetFolder = "examples/c/sapi/statecharts/4_buttons/gen"
+ libraryTargetFolder = "examples/c/sapi/statecharts/4_buttons/inc"
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/4_buttons/config.mk b/examples/c/sapi/statecharts/4_buttons/config.mk
new file mode 100644
index 00000000..dd54d2b5
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/config.mk
@@ -0,0 +1,18 @@
+# Compile options
+VERBOSE=n
+OPT=g
+USE_NANO=y
+SEMIHOST=n
+USE_FPU=y
+
+# Libraries
+USE_LPCOPEN=y
+USE_SAPI=y
+USE_FREERTOS=n
+FREERTOS_HEAP_TYPE=5
+LOAD_INRAM=n
+
+# Yakindu SCT - To Compile and Link Generated Sate Machine Code
+INCLUDES = -I$(PROGRAM_PATH_AND_NAME)/gen
+INCLUDES += -I$(PROGRAM_PATH_AND_NAME)/inc
+SRC = $(wildcard $(PROGRAM_PATH_AND_NAME)/gen/*.c)
diff --git a/examples/c/sapi/statecharts/4_buttons/gen/.gitignore b/examples/c/sapi/statecharts/4_buttons/gen/.gitignore
new file mode 100644
index 00000000..69a84b71
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/gen/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!readme.md
diff --git a/examples/c/sapi/statecharts/4_buttons/gen/readme.md b/examples/c/sapi/statecharts/4_buttons/gen/readme.md
new file mode 100644
index 00000000..c233ea9c
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/gen/readme.md
@@ -0,0 +1 @@
+Folder for Yakindu SCT generated source files.
diff --git a/examples/c/sapi/statecharts/4_buttons/inc/.gitignore b/examples/c/sapi/statecharts/4_buttons/inc/.gitignore
new file mode 100644
index 00000000..c88a1eb7
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/inc/.gitignore
@@ -0,0 +1 @@
+sc_types.h
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/4_buttons/inc/TimerTicks.h b/examples/c/sapi/statecharts/4_buttons/inc/TimerTicks.h
new file mode 100644
index 00000000..b97f306d
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/inc/TimerTicks.h
@@ -0,0 +1,56 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TIMERTICKS_H_
+#define TIMERTICKS_H_
+
+
+typedef struct
+{
+ sc_eventid evid;
+ sc_uinteger time_ms;
+ sc_uinteger count;
+ sc_boolean periodic;
+ sc_boolean active;
+ sc_boolean evPending;
+} TimerTicks;
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len);
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic);
+sc_eventid UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid);
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void UpdateTimers(TimerTicks *list, uint32_t len);
+
+#endif /* TIMERTICKS_H_ */
diff --git a/examples/c/sapi/statecharts/4_buttons/inc/main.h b/examples/c/sapi/statecharts/4_buttons/inc/main.h
new file mode 100644
index 00000000..0b5f39b9
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/inc/main.h
@@ -0,0 +1,69 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcón, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*==================[macros]=================================================*/
+
+/*==================[typedef]================================================*/
+
+/*==================[external data declaration]==============================*/
+
+/*==================[external functions declaration]=========================*/
+
+/** @brief main function
+ * @return main function should never return
+ */
+int main(void);
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} doxygen end group definition */
+/*==================[end of file]============================================*/
+#endif /* #ifndef _MAIN_H_ */
diff --git a/examples/c/sapi/statecharts/4_buttons/readme.md b/examples/c/sapi/statecharts/4_buttons/readme.md
new file mode 100644
index 00000000..dc3e4875
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/readme.md
@@ -0,0 +1,27 @@
+# Statechart example using sysTick and Yakindu Time Events
+
+
+- Description: The Statechart example simply toggle an LED by pressing a button using the sysTick timer and Yakindu Time Events (Timer Ticks), include software debounce.
+
+ - The sysTick Interrupt Handler only set a Flag.
+
+ - LED state is toggled in the main program.
+ - The uC sleeps waiting for an interruption.
+
+ - When a interrupt wakes to the uC, the main program validates it,
+ checking the waited Flag.
+ - Then reset its Flag.
+ - Then Update all Timer Ticks.
+ - Then Scan all Timer Ticks and if there are pending events
+ - Then Raise an Event -> Ticks.evid => OK
+ - Then Mark as Attached -> Ticks.evid => OK
+
+ - Then Get status of buttons
+ - Then if there are a pressed button
+ - Then Raise an Event -> evTECXOprimodo => OK,
+ and Value of pressed button -> viTecla
+ - Then else Raise an Event -> evTECXNoOprimido => OK
+
+ - Then Run an Cycle of Statechart.
+
+ - And then the uC sleeps again.
diff --git a/examples/c/sapi/statecharts/4_buttons/src/TimerTicks.c b/examples/c/sapi/statecharts/4_buttons/src/TimerTicks.c
new file mode 100644
index 00000000..c926f7a0
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/src/TimerTicks.c
@@ -0,0 +1,147 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief These are the Timer Ticks functions for simple statechart example
+ * using Yakindu Statechart Tool Plug-in
+ * (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+#include "Buttons.h"
+#include "TimerTicks.h"
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ }
+}
+
+
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic)
+{
+ uint32_t i;
+
+ sc_eventid ret = (sc_eventid)0;
+ for(i = 0; i < len; i++) {
+ if(!list[i].evid) {
+ list[i].time_ms = time_ms;
+ list[i].count = time_ms;
+ list[i].evid = evid;
+ list[i].periodic = periodic;
+ list[i].active = true;
+ list[i].evPending = false;
+ ret = evid;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void* UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+ sc_eventid ret = (sc_eventid)0;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ ret = id;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ int i;
+ sc_boolean ret = false;
+ for(i=0; i < len; i++) {
+ if((list[i].evid == id) && (list[i].evPending == true)) {
+ ret = true;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evPending = false;
+ break;
+ }
+ }
+}
+
+
+void UpdateTimers(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].active == true) {
+ if(list[i].count)
+ list[i].count--;
+ if(!list[i].count) {
+ if(list[i].periodic)
+ list[i].count = list[i].time_ms;
+ else
+ list[i].active = false;
+ list[i].evPending = true;
+ }
+ }
+ }
+}
diff --git a/examples/c/sapi/statecharts/4_buttons/src/main.c b/examples/c/sapi/statecharts/4_buttons/src/main.c
new file mode 100644
index 00000000..7288cff7
--- /dev/null
+++ b/examples/c/sapi/statecharts/4_buttons/src/main.c
@@ -0,0 +1,252 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief This is a simple statechart example using Yakindu Statechart Tool
+ * Plug-in (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+#include "main.h"
+
+#include "sapi.h" // <= sAPI header
+
+/* Include statechart header file. Be sure you run the statechart C code
+ * generation tool!
+ */
+#include "Buttons.h"
+#include "TimerTicks.h"
+
+
+/*==================[macros and definitions]=================================*/
+
+#define TICKRATE_1MS (1) /* 1000 ticks per second */
+#define TICKRATE_MS (TICKRATE_1MS) /* 1000 ticks per second */
+
+
+/*==================[internal data declaration]==============================*/
+
+volatile bool SysTick_Time_Flag = false;
+
+/*! This is a state machine */
+static Buttons statechart;
+
+/*! This is a timed state machine that requires timer services */
+#define NOF_TIMERS (sizeof(ButtonsTimeEvents)/sizeof(sc_boolean))
+
+TimerTicks ticks[NOF_TIMERS];
+
+
+/*==================[internal functions declaration]=========================*/
+
+/*==================[internal data definition]===============================*/
+
+/*==================[external data definition]===============================*/
+
+/*==================[internal functions definition]==========================*/
+
+/*==================[external functions definition]==========================*/
+
+/*! \file This header defines prototypes for all functions that are required
+ * by the state machine implementation.
+ *
+ * This is a state machine uses time events which require access to a timing
+ * service. Thus the function prototypes:
+ * - buttons_setTimer and
+ * - buttons_unsetTimer
+ * are defined.
+ *
+ * This state machine makes use of operations declared in the state machines
+ * interface or internal scopes. Thus the function prototypes:
+ * - buttonsIface_opLED
+ * are defined.
+ *
+ * These functions will be called during a 'run to completion step' (runCycle)
+ * of the statechart.
+ * There are some constraints that have to be considered for the
+ * implementation of these functions:
+ * - never call the statechart API functions from within these functions.
+ * - make sure that the execution time is as short as possible.
+ */
+
+/** state machine user-defined external function (action)
+ *
+ * @param handle state machine instance
+ * @param LEDNumber number of LED
+ * @param onoff state machine operation parameter
+ */
+void buttonsIface_opLED( Buttons* handle, sc_integer LEDNumber )
+{
+ gpioToggle( (LEDR + LEDNumber) );
+}
+
+
+/*! * This is a timed state machine that requires timer services
+ */
+
+/*! This function has to set up timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be entered.
+ * \param evid An unique identifier of the event.
+ * \time_ms The time in milli seconds
+ * \periodic Indicates the the time event must be raised periodically until
+ * the timer is unset
+ */
+void buttons_setTimer( Buttons* handle, const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic )
+{
+ SetNewTimerTick(ticks, NOF_TIMERS, evid, time_ms, periodic);
+}
+
+/*! This function has to unset timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be left.
+ * \param evid An unique identifier of the event.
+ */
+void buttons_unsetTimer( Buttons* handle, const sc_eventid evid )
+{
+ UnsetTimerTick( ticks, NOF_TIMERS, evid );
+}
+
+
+/**
+ * @brief Hook on Handle interrupt from SysTick timer
+ * @return Nothing
+ */
+void myTickHook( void *ptr ){
+
+ /* The sysTick Interrupt Handler only set a Flag */
+ SysTick_Time_Flag = true;
+}
+
+
+/*! This function scan all EDU-CIAA-NXP buttons (TEC1, TEC2, TEC3 and TEC4),
+ * and return ID of pressed button (TEC1 or TEC2 or TEC3 or TEC4)
+ * or false if no button was pressed.
+ */
+uint32_t Buttons_GetStatus_(void) {
+ uint8_t ret = false;
+ uint32_t idx;
+
+ for (idx = 0; idx < 4; ++idx) {
+ if (gpioRead( TEC1 + idx ) == 0)
+ ret |= 1 << idx;
+ }
+ return ret;
+}
+
+
+/**
+ * @brief main routine for statechart example: EDU-CIAA-NXP - Buttons
+ * @return Function should not exit.
+ */
+int main(void)
+{
+ uint32_t i;
+
+ uint32_t BUTTON_Status;
+
+ /* Generic Initialization */
+ boardConfig();
+
+ /* Init Ticks counter => TICKRATE_MS */
+ tickConfig( TICKRATE_MS );
+
+ /* Add Tick Hook */
+ tickCallbackSet( myTickHook, (void*)NULL );
+
+ /* Init Timer Ticks */
+ InitTimerTicks( ticks, NOF_TIMERS );
+
+ /* Statechart Initialization */
+ buttons_init( &statechart );
+ buttons_enter( &statechart );
+
+ /* LED state is toggled in the main program */
+ while (1) {
+ /* The uC sleeps waiting for an interruption */
+ __WFI();
+
+ /* When a interrupt wakes to the uC, the main program validates it,
+ * checking the waited Flag */
+ if (SysTick_Time_Flag == true) {
+
+ /* Then reset its Flag */
+ SysTick_Time_Flag = false;
+
+ /* Then Update all Timer Ticks */
+ UpdateTimers( ticks, NOF_TIMERS );
+
+ /* Then Scan all Timer Ticks */
+ for (i = 0; i < NOF_TIMERS; i++) {
+
+ /* Then if there are pending events */
+ if (IsPendEvent( ticks, NOF_TIMERS, ticks[i].evid ) == true) {
+
+ /* Then Raise an Event -> Ticks.evid => OK */
+ buttons_raiseTimeEvent( &statechart, ticks[i].evid );
+
+ /* Then Mark as Attached -> Ticks.evid => OK */
+ MarkAsAttEvent( ticks, NOF_TIMERS, ticks[i].evid );
+ }
+ }
+
+ /* Then Get status of buttons */
+ BUTTON_Status = Buttons_GetStatus_();
+
+ /* Then if there are a pressed button */
+ if (BUTTON_Status != 0)
+
+ /* Then Raise an Event -> evTECXOprimodo => OK,
+ * and Value of pressed button -> viTecla */
+ buttonsIface_raise_evTECXOprimido(&statechart, BUTTON_Status);
+ else
+ /* Then else Raise an Event -> evTECXNoOprimido => OK */
+ buttonsIface_raise_evTECXNoOprimido(&statechart);
+
+ /* Then Run an Cycle of Statechart */
+ buttons_runCycle(&statechart); // Run Cycle of Statechart
+ }
+ }
+}
+
+
+/** @} doxygen end group definition */
+
+/*==================[end of file]============================================*/
diff --git a/examples/c/sapi/statecharts/5_application/Application.sct b/examples/c/sapi/statecharts/5_application/Application.sct
new file mode 100644
index 00000000..66a9961d
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/Application.sct
@@ -0,0 +1,492 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/c/sapi/statecharts/5_application/Application.sgen b/examples/c/sapi/statecharts/5_application/Application.sgen
new file mode 100644
index 00000000..0aa10ebb
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/Application.sgen
@@ -0,0 +1,11 @@
+GeneratorModel for yakindu::c {
+
+ statechart application {
+
+ feature Outlet {
+ targetProject = "firmware_v3"
+ targetFolder = "examples/c/sapi/statecharts/5_application/gen"
+ libraryTargetFolder = "examples/c/sapi/statecharts/5_application/inc"
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/5_application/config.mk b/examples/c/sapi/statecharts/5_application/config.mk
new file mode 100644
index 00000000..dd54d2b5
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/config.mk
@@ -0,0 +1,18 @@
+# Compile options
+VERBOSE=n
+OPT=g
+USE_NANO=y
+SEMIHOST=n
+USE_FPU=y
+
+# Libraries
+USE_LPCOPEN=y
+USE_SAPI=y
+USE_FREERTOS=n
+FREERTOS_HEAP_TYPE=5
+LOAD_INRAM=n
+
+# Yakindu SCT - To Compile and Link Generated Sate Machine Code
+INCLUDES = -I$(PROGRAM_PATH_AND_NAME)/gen
+INCLUDES += -I$(PROGRAM_PATH_AND_NAME)/inc
+SRC = $(wildcard $(PROGRAM_PATH_AND_NAME)/gen/*.c)
diff --git a/examples/c/sapi/statecharts/5_application/gen/.gitignore b/examples/c/sapi/statecharts/5_application/gen/.gitignore
new file mode 100644
index 00000000..69a84b71
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/gen/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!readme.md
diff --git a/examples/c/sapi/statecharts/5_application/gen/readme.md b/examples/c/sapi/statecharts/5_application/gen/readme.md
new file mode 100644
index 00000000..c233ea9c
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/gen/readme.md
@@ -0,0 +1 @@
+Folder for Yakindu SCT generated source files.
diff --git a/examples/c/sapi/statecharts/5_application/inc/.gitignore b/examples/c/sapi/statecharts/5_application/inc/.gitignore
new file mode 100644
index 00000000..c88a1eb7
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/inc/.gitignore
@@ -0,0 +1 @@
+sc_types.h
\ No newline at end of file
diff --git a/examples/c/sapi/statecharts/5_application/inc/TimerTicks.h b/examples/c/sapi/statecharts/5_application/inc/TimerTicks.h
new file mode 100644
index 00000000..b97f306d
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/inc/TimerTicks.h
@@ -0,0 +1,56 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TIMERTICKS_H_
+#define TIMERTICKS_H_
+
+
+typedef struct
+{
+ sc_eventid evid;
+ sc_uinteger time_ms;
+ sc_uinteger count;
+ sc_boolean periodic;
+ sc_boolean active;
+ sc_boolean evPending;
+} TimerTicks;
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len);
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic);
+sc_eventid UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid);
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid evid);
+void UpdateTimers(TimerTicks *list, uint32_t len);
+
+#endif /* TIMERTICKS_H_ */
diff --git a/examples/c/sapi/statecharts/5_application/inc/main.h b/examples/c/sapi/statecharts/5_application/inc/main.h
new file mode 100644
index 00000000..0b5f39b9
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/inc/main.h
@@ -0,0 +1,69 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcón, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*==================[macros]=================================================*/
+
+/*==================[typedef]================================================*/
+
+/*==================[external data declaration]==============================*/
+
+/*==================[external functions declaration]=========================*/
+
+/** @brief main function
+ * @return main function should never return
+ */
+int main(void);
+
+/*==================[cplusplus]==============================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} doxygen end group definition */
+/*==================[end of file]============================================*/
+#endif /* #ifndef _MAIN_H_ */
diff --git a/examples/c/sapi/statecharts/5_application/readme.md b/examples/c/sapi/statecharts/5_application/readme.md
new file mode 100644
index 00000000..5c5f405a
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/readme.md
@@ -0,0 +1,27 @@
+# Statechart example using sysTick and Yakindu Time Events
+
+
+- Description: The Statechart example simply "blink/turn ON/turn OFF" LEDs by pressing buttons using the sysTick timer and Yakindu Time Events (Timer Ticks), include software debounce.
+
+ - The sysTick Interrupt Handler only set a Flag.
+
+ - LED state is toggled in the main program.
+ - The uC sleeps waiting for an interruption.
+
+ - When a interrupt wakes to the uC, the main program validates it,
+ checking the waited Flag.
+ - Then reset its Flag.
+ - Then Update all Timer Ticks.
+ - Then Scan all Timer Ticks and if there are pending events
+ - Then Raise an Event -> Ticks.evid => OK
+ - Then Mark as Attached -> Ticks.evid => OK
+
+ - Then Get status of buttons
+ - Then if there are a pressed button
+ - Then Raise an Event -> evTECXOprimodo => OK,
+ and Value of pressed button -> viTecla
+ - Then else Raise an Event -> evTECXNoOprimido => OK
+
+ - Then Run an Cycle of Statechart.
+
+ - And then the uC sleeps again.
diff --git a/examples/c/sapi/statecharts/5_application/src/TimerTicks.c b/examples/c/sapi/statecharts/5_application/src/TimerTicks.c
new file mode 100644
index 00000000..fa3b54df
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/src/TimerTicks.c
@@ -0,0 +1,147 @@
+/* Copyright 2017, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief These are the Timer Ticks functions for simple statechart example
+ * using Yakindu Statechart Tool Plug-in
+ * (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+#include "Application.h"
+#include "TimerTicks.h"
+
+
+void InitTimerTicks(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ }
+}
+
+
+sc_eventid SetNewTimerTick(TimerTicks *list, uint32_t len, sc_eventid evid, sc_uinteger time_ms, sc_boolean periodic)
+{
+ uint32_t i;
+
+ sc_eventid ret = (sc_eventid)0;
+ for(i = 0; i < len; i++) {
+ if(!list[i].evid) {
+ list[i].time_ms = time_ms;
+ list[i].count = time_ms;
+ list[i].evid = evid;
+ list[i].periodic = periodic;
+ list[i].active = true;
+ list[i].evPending = false;
+ ret = evid;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void* UnsetTimerTick(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+ sc_eventid ret = (sc_eventid)0;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evid = (sc_eventid)0;
+ list[i].time_ms = 0;
+ list[i].count = 0;
+ list[i].periodic = false;
+ list[i].active = false;
+ list[i].evPending = false;
+ ret = id;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+sc_boolean IsPendEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ int i;
+ sc_boolean ret = false;
+ for(i=0; i < len; i++) {
+ if((list[i].evid == id) && (list[i].evPending == true)) {
+ ret = true;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+void MarkAsAttEvent(TimerTicks *list, uint32_t len, sc_eventid id)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].evid == id) {
+ list[i].evPending = false;
+ break;
+ }
+ }
+}
+
+
+void UpdateTimers(TimerTicks *list, uint32_t len)
+{
+ uint32_t i;
+
+ for(i = 0; i < len; i++) {
+ if(list[i].active == true) {
+ if(list[i].count)
+ list[i].count--;
+ if(!list[i].count) {
+ if(list[i].periodic)
+ list[i].count = list[i].time_ms;
+ else
+ list[i].active = false;
+ list[i].evPending = true;
+ }
+ }
+ }
+}
diff --git a/examples/c/sapi/statecharts/5_application/src/main.c b/examples/c/sapi/statecharts/5_application/src/main.c
new file mode 100644
index 00000000..b6d234ca
--- /dev/null
+++ b/examples/c/sapi/statecharts/5_application/src/main.c
@@ -0,0 +1,253 @@
+/* Copyright 2017, Pablo Ridolfi, Juan Esteban Alarcon, Juan Manuel Cruz
+ * All rights reserved.
+ *
+ * This file is part of Workspace.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/** @brief This is a simple statechart example using Yakindu Statechart Tool
+ * Plug-in (update site: http://updates.yakindu.org/sct/mars/releases/).
+ */
+
+/** \addtogroup statechart Simple UML Statechart example.
+ ** @{ */
+
+/*==================[inclusions]=============================================*/
+
+#include "main.h"
+
+#include "sapi.h" // <= sAPI header
+
+/* Include statechart header file. Be sure you run the statechart C code
+ * generation tool!
+ */
+#include "Application.h"
+#include "TimerTicks.h"
+
+
+/*==================[macros and definitions]=================================*/
+
+#define TICKRATE_1MS (1) /* 1000 ticks per second */
+#define TICKRATE_MS (TICKRATE_1MS) /* 1000 ticks per second */
+
+
+/*==================[internal data declaration]==============================*/
+
+volatile bool SysTick_Time_Flag = false;
+
+/*! This is a state machine */
+static Application statechart;
+
+/*! This is a timed state machine that requires timer services */
+#define NOF_TIMERS (sizeof(ApplicationTimeEvents)/sizeof(sc_boolean))
+
+TimerTicks ticks[NOF_TIMERS];
+
+
+/*==================[internal functions declaration]=========================*/
+
+/*==================[internal data definition]===============================*/
+
+/*==================[external data definition]===============================*/
+
+/*==================[internal functions definition]==========================*/
+
+/*==================[external functions definition]==========================*/
+
+/*! \file This header defines prototypes for all functions that are required
+ * by the state machine implementation.
+ *
+ * This is a state machine uses time events which require access to a timing
+ * service. Thus the function prototypes:
+ * - application_setTimer and
+ * - application_unsetTimer
+ * are defined.
+ *
+ * This state machine makes use of operations declared in the state machines
+ * interface or internal scopes. Thus the function prototypes:
+ * - applicationIface_opLED
+ * are defined.
+ *
+ * These functions will be called during a 'run to completion step' (runCycle)
+ * of the statechart.
+ * There are some constraints that have to be considered for the
+ * implementation of these functions:
+ * - never call the statechart API functions from within these functions.
+ * - make sure that the execution time is as short as possible.
+ */
+
+/** state machine user-defined external function (action)
+ *
+ * @param handle state machine instance
+ * @param LEDNumber number of LED
+ * @param onoff state machine operation parameter
+ */
+
+void applicationIface_opLED( Application* handle, sc_integer LEDNumber, sc_boolean State )
+{
+ gpioWrite( (LEDR + LEDNumber), State );
+}
+
+
+/*! * This is a timed state machine that requires timer services
+ */
+
+/*! This function has to set up timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be entered.
+ * \param evid An unique identifier of the event.
+ * \time_ms The time in milli seconds
+ * \periodic Indicates the the time event must be raised periodically until
+ * the timer is unset
+ */
+void application_setTimer( Application* handle, const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic )
+{
+ SetNewTimerTick(ticks, NOF_TIMERS, evid, time_ms, periodic);
+}
+
+/*! This function has to unset timers for the time events that are required
+ * by the state machine.
+ */
+/*! This function will be called for each time event that is relevant for a
+ * state when a state will be left.
+ * \param evid An unique identifier of the event.
+ */
+void application_unsetTimer( Application* handle, const sc_eventid evid )
+{
+ UnsetTimerTick( ticks, NOF_TIMERS, evid );
+}
+
+
+/**
+ * @brief Hook on Handle interrupt from SysTick timer
+ * @return Nothing
+ */
+void myTickHook( void *ptr ){
+
+ /* The sysTick Interrupt Handler only set a Flag */
+ SysTick_Time_Flag = true;
+}
+
+
+/*! This function scan all EDU-CIAA-NXP buttons (TEC1, TEC2, TEC3 and TEC4),
+ * and return ID of pressed button (TEC1 or TEC2 or TEC3 or TEC4)
+ * or false if no button was pressed.
+ */
+uint32_t Buttons_GetStatus_(void) {
+ uint8_t ret = false;
+ uint32_t idx;
+
+ for (idx = 0; idx < 4; ++idx) {
+ if (gpioRead( TEC1 + idx ) == 0)
+ ret |= 1 << idx;
+ }
+ return ret;
+}
+
+
+/**
+ * @brief main routine for statechart example: EDU-CIAA-NXP - Application
+ * @return Function should not exit.
+ */
+int main(void)
+{
+ uint32_t i;
+
+ uint32_t BUTTON_Status;
+
+ /* Generic Initialization */
+ boardConfig();
+
+ /* Init Ticks counter => TICKRATE_MS */
+ tickConfig( TICKRATE_MS );
+
+ /* Add Tick Hook */
+ tickCallbackSet( myTickHook, (void*)NULL );
+
+ /* Init Timer Ticks */
+ InitTimerTicks( ticks, NOF_TIMERS );
+
+ /* Statechart Initialization */
+ application_init( &statechart );
+ application_enter( &statechart );
+
+ /* LED state is toggled in the main program */
+ while (1) {
+ /* The uC sleeps waiting for an interruption */
+ __WFI();
+
+ /* When a interrupt wakes to the uC, the main program validates it,
+ * checking the waited Flag */
+ if (SysTick_Time_Flag == true) {
+
+ /* Then reset its Flag */
+ SysTick_Time_Flag = false;
+
+ /* Then Update all Timer Ticks */
+ UpdateTimers( ticks, NOF_TIMERS );
+
+ /* Then Scan all Timer Ticks */
+ for (i = 0; i < NOF_TIMERS; i++) {
+
+ /* Then if there are pending events */
+ if (IsPendEvent( ticks, NOF_TIMERS, ticks[i].evid ) == true) {
+
+ /* Then Raise an Event -> Ticks.evid => OK */
+ application_raiseTimeEvent( &statechart, ticks[i].evid );
+
+ /* Then Mark as Attached -> Ticks.evid => OK */
+ MarkAsAttEvent( ticks, NOF_TIMERS, ticks[i].evid );
+ }
+ }
+
+ /* Then Get status of buttons */
+ BUTTON_Status = Buttons_GetStatus_();
+
+ /* Then if there are a pressed button */
+ if (BUTTON_Status != 0)
+
+ /* Then Raise an Event -> evTECXOprimodo => OK,
+ * and Value of pressed button -> viTecla */
+ applicationIface_raise_evTECXOprimido(&statechart, BUTTON_Status);
+ else
+ /* Then else Raise an Event -> evTECXNoOprimido => OK */
+ applicationIface_raise_evTECXNoOprimido(&statechart);
+
+ /* Then Run an Cycle of Statechart */
+ application_runCycle(&statechart); // Run Cycle of Statechart
+ }
+ }
+}
+
+
+/** @} doxygen end group definition */
+
+/*==================[end of file]============================================*/