Skip to content

Commit

Permalink
Add 5_aplication example
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanManuelCruz committed Feb 7, 2020
1 parent 84e3698 commit 3f67386
Show file tree
Hide file tree
Showing 11 changed files with 1,078 additions and 0 deletions.
492 changes: 492 additions & 0 deletions examples/c/sapi/statecharts/5_application/Application.sct

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions examples/c/sapi/statecharts/5_application/Application.sgen
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
18 changes: 18 additions & 0 deletions examples/c/sapi/statecharts/5_application/config.mk
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions examples/c/sapi/statecharts/5_application/gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!readme.md
1 change: 1 addition & 0 deletions examples/c/sapi/statecharts/5_application/gen/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Folder for Yakindu SCT generated source files.
1 change: 1 addition & 0 deletions examples/c/sapi/statecharts/5_application/inc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sc_types.h
56 changes: 56 additions & 0 deletions examples/c/sapi/statecharts/5_application/inc/TimerTicks.h
Original file line number Diff line number Diff line change
@@ -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_ */
69 changes: 69 additions & 0 deletions examples/c/sapi/statecharts/5_application/inc/main.h
Original file line number Diff line number Diff line change
@@ -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_ */
27 changes: 27 additions & 0 deletions examples/c/sapi/statecharts/5_application/readme.md
Original file line number Diff line number Diff line change
@@ -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.
147 changes: 147 additions & 0 deletions examples/c/sapi/statecharts/5_application/src/TimerTicks.c
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
Loading

0 comments on commit 3f67386

Please sign in to comment.