Skip to content

Commit

Permalink
Merge pull request #47 from JuanManuelCruz/master
Browse files Browse the repository at this point in the history
Add 1_toggle => Statechart example using sysTick
  • Loading branch information
epernia authored Mar 5, 2020
2 parents 4a8239a + 3f67386 commit 1a2a788
Show file tree
Hide file tree
Showing 53 changed files with 3,645 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/c/sapi/statecharts/1_toggle/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/1_toggle/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/1_toggle/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/1_toggle/inc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sc_types.h
69 changes: 69 additions & 0 deletions examples/c/sapi/statecharts/1_toggle/inc/main.h
Original file line number Diff line number Diff line change
@@ -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_ */
17 changes: 17 additions & 0 deletions examples/c/sapi/statecharts/1_toggle/readme.md
Original file line number Diff line number Diff line change
@@ -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.
157 changes: 157 additions & 0 deletions examples/c/sapi/statecharts/1_toggle/src/main.c
Original file line number Diff line number Diff line change
@@ -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]============================================*/
87 changes: 87 additions & 0 deletions examples/c/sapi/statecharts/1_toggle/toggle.sct
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
<sgraph:Statechart xmi:id="_IPEiAI_CEeaE_NItBGtDFQ" specification="/* Toggle LED3 EDU-CIAA-NXP */&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;/* For each event (evTick) an operation is done (opLED(LED3)) */&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;interface:&#xD;&#xA;&#xD;&#xA;in event evTick&#xD;&#xA;&#xD;&#xA;operation opLED(LEDNumber:integer): void&#xD;&#xA;&#xD;&#xA;//const LEDR: integer = 0&#xD;&#xA;//const LEDG: integer = 1&#xD;&#xA;//const LEDB: integer = 2&#xD;&#xA;//const LED1: integer = 3&#xD;&#xA;//const LED2: integer = 4&#xD;&#xA;const LED3: integer = 5&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;internal:&#xD;&#xA;" name="toggle">
<regions xmi:id="_IPEiA4_CEeaE_NItBGtDFQ" name="main region">
<vertices xsi:type="sgraph:Entry" xmi:id="_IPEiDY_CEeaE_NItBGtDFQ">
<outgoingTransitions xmi:id="_XlKfgBMaEeevvbhLDk5fag" specification="" target="_EvYFTRMaEeevvbhLDk5fag"/>
</vertices>
<vertices xsi:type="sgraph:State" xmi:id="_EvYFTRMaEeevvbhLDk5fag" specification="entry / opLED(LED3)" name="TOGGLE" incomingTransitions="_XlKfgBMaEeevvbhLDk5fag _qtMbcObiEemPo55lRtzgow">
<outgoingTransitions xmi:id="_qtMbcObiEemPo55lRtzgow" specification="evTick" target="_EvYFTRMaEeevvbhLDk5fag"/>
</vertices>
</regions>
</sgraph:Statechart>
<notation:Diagram xmi:id="_IPEiAY_CEeaE_NItBGtDFQ" type="org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor" element="_IPEiAI_CEeaE_NItBGtDFQ" measurementUnit="Pixel">
<children xmi:id="_IPEiBI_CEeaE_NItBGtDFQ" type="Region" element="_IPEiA4_CEeaE_NItBGtDFQ">
<children xsi:type="notation:DecorationNode" xmi:id="_IPEiB4_CEeaE_NItBGtDFQ" type="RegionName">
<styles xsi:type="notation:ShapeStyle" xmi:id="_IPEiCI_CEeaE_NItBGtDFQ"/>
<layoutConstraint xsi:type="notation:Location" xmi:id="_IPEiCY_CEeaE_NItBGtDFQ"/>
</children>
<children xsi:type="notation:Shape" xmi:id="_IPEiCo_CEeaE_NItBGtDFQ" type="RegionCompartment" fontName="Verdana" lineColor="4210752">
<children xmi:id="_IPEiDo_CEeaE_NItBGtDFQ" type="Entry" element="_IPEiDY_CEeaE_NItBGtDFQ">
<children xmi:id="_IPEiEY_CEeaE_NItBGtDFQ" type="BorderItemLabelContainer">
<children xsi:type="notation:DecorationNode" xmi:id="_IPEiFI_CEeaE_NItBGtDFQ" type="BorderItemLabel">
<styles xsi:type="notation:ShapeStyle" xmi:id="_IPEiFY_CEeaE_NItBGtDFQ"/>
<layoutConstraint xsi:type="notation:Location" xmi:id="_IPEiFo_CEeaE_NItBGtDFQ"/>
</children>
<styles xsi:type="notation:ShapeStyle" xmi:id="_IPEiEo_CEeaE_NItBGtDFQ" fontName="Verdana" lineColor="4210752"/>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_IPEiE4_CEeaE_NItBGtDFQ"/>
</children>
<styles xsi:type="notation:ShapeStyle" xmi:id="_IPEiD4_CEeaE_NItBGtDFQ" fontName="Verdana" lineColor="4210752"/>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_IPEiF4_CEeaE_NItBGtDFQ" x="24" width="15" height="15"/>
</children>
<children xmi:id="_EvYFQRMaEeevvbhLDk5fag" type="State" element="_EvYFTRMaEeevvbhLDk5fag">
<children xsi:type="notation:DecorationNode" xmi:id="_EvYFQhMaEeevvbhLDk5fag" type="StateName">
<styles xsi:type="notation:ShapeStyle" xmi:id="_EvYFQxMaEeevvbhLDk5fag"/>
<layoutConstraint xsi:type="notation:Location" xmi:id="_EvYFRBMaEeevvbhLDk5fag"/>
</children>
<children xsi:type="notation:Compartment" xmi:id="_EvYFRRMaEeevvbhLDk5fag" type="StateTextCompartment">
<children xsi:type="notation:Shape" xmi:id="_EvYFRhMaEeevvbhLDk5fag" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_EvYFRxMaEeevvbhLDk5fag"/>
</children>
</children>
<children xsi:type="notation:Compartment" xmi:id="_EvYFSBMaEeevvbhLDk5fag" type="StateFigureCompartment"/>
<styles xsi:type="notation:ShapeStyle" xmi:id="_EvYFSRMaEeevvbhLDk5fag" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
<styles xsi:type="notation:FontStyle" xmi:id="_EvYFShMaEeevvbhLDk5fag"/>
<styles xsi:type="notation:BooleanValueStyle" xmi:id="_EvYFSxMaEeevvbhLDk5fag" name="isHorizontal" booleanValue="true"/>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_EvYFTBMaEeevvbhLDk5fag" x="79" y="-23" width="161" height="63"/>
</children>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_IPEiC4_CEeaE_NItBGtDFQ"/>
</children>
<styles xsi:type="notation:ShapeStyle" xmi:id="_IPEiBY_CEeaE_NItBGtDFQ" fontName="Verdana" fillColor="15790320" lineColor="12632256"/>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_IPEiDI_CEeaE_NItBGtDFQ" x="290" y="-10" width="296" height="151"/>
</children>
<children xsi:type="notation:Shape" xmi:id="_IPEiMI_CEeaE_NItBGtDFQ" type="StatechartText" fontName="Verdana" lineColor="4210752">
<children xsi:type="notation:DecorationNode" xmi:id="_IPOTAI_CEeaE_NItBGtDFQ" type="StatechartName">
<styles xsi:type="notation:ShapeStyle" xmi:id="_IPOTAY_CEeaE_NItBGtDFQ"/>
<layoutConstraint xsi:type="notation:Location" xmi:id="_IPOTAo_CEeaE_NItBGtDFQ"/>
</children>
<children xsi:type="notation:Shape" xmi:id="_IPOTA4_CEeaE_NItBGtDFQ" type="StatechartTextExpression" fontName="Verdana" lineColor="4210752">
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_IPOTBI_CEeaE_NItBGtDFQ"/>
</children>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_IPOTBY_CEeaE_NItBGtDFQ" y="-10" width="291" height="371"/>
</children>
<styles xsi:type="notation:DiagramStyle" xmi:id="_IPEiAo_CEeaE_NItBGtDFQ"/>
<styles xsi:type="notation:BooleanValueStyle" xmi:id="_kGUDMEd7EeqIz_OtR4ro9Q" name="inlineDefinitionSection" booleanValue="true"/>
<edges xmi:id="_XlQmIBMaEeevvbhLDk5fag" type="Transition" element="_XlKfgBMaEeevvbhLDk5fag" source="_IPEiDo_CEeaE_NItBGtDFQ" target="_EvYFQRMaEeevvbhLDk5fag">
<children xsi:type="notation:DecorationNode" xmi:id="_XlQmJBMaEeevvbhLDk5fag" type="TransitionExpression">
<styles xsi:type="notation:ShapeStyle" xmi:id="_XlQmJRMaEeevvbhLDk5fag"/>
<layoutConstraint xsi:type="notation:Location" xmi:id="_XlQmJhMaEeevvbhLDk5fag" y="10"/>
</children>
<styles xsi:type="notation:ConnectorStyle" xmi:id="_XlQmIRMaEeevvbhLDk5fag" lineColor="4210752"/>
<styles xsi:type="notation:FontStyle" xmi:id="_XlQmIxMaEeevvbhLDk5fag" fontName="Verdana"/>
<bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_XlQmIhMaEeevvbhLDk5fag" points="[7, 0, -154, 12]$[162, 17, 1, 29]"/>
<targetAnchor xsi:type="notation:IdentityAnchor" xmi:id="_XlWswBMaEeevvbhLDk5fag" id="(0.005719330569629971,0.5303030303030303)"/>
</edges>
<edges xmi:id="_qtgkgObiEemPo55lRtzgow" type="Transition" element="_qtMbcObiEemPo55lRtzgow" source="_EvYFQRMaEeevvbhLDk5fag" target="_EvYFQRMaEeevvbhLDk5fag">
<children xsi:type="notation:DecorationNode" xmi:id="_qtjn0ObiEemPo55lRtzgow" type="TransitionExpression">
<styles xsi:type="notation:ShapeStyle" xmi:id="_qtjn0ebiEemPo55lRtzgow"/>
<layoutConstraint xsi:type="notation:Location" xmi:id="_qtkO4ObiEemPo55lRtzgow" x="22" y="12"/>
</children>
<styles xsi:type="notation:ConnectorStyle" xmi:id="_qtgkgebiEemPo55lRtzgow" routing="Rectilinear" lineColor="4210752"/>
<styles xsi:type="notation:FontStyle" xmi:id="_qthyoObiEemPo55lRtzgow" fontName="Verdana"/>
<bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_qthLkObiEemPo55lRtzgow" points="[12, 14, 12, 14]$[41, 14, 41, 14]$[41, 78, 41, 78]$[-64, 78, -64, 78]$[-64, 44, -64, 44]"/>
<sourceAnchor xsi:type="notation:IdentityAnchor" xmi:id="_qtqVgObiEemPo55lRtzgow" id="(0.9288402728769702,0.24242424242424243)"/>
<targetAnchor xsi:type="notation:IdentityAnchor" xmi:id="_qtq8kObiEemPo55lRtzgow" id="(0.9288402728769702,0.24242424242424243)"/>
</edges>
</notation:Diagram>
</xmi:XMI>
11 changes: 11 additions & 0 deletions examples/c/sapi/statecharts/1_toggle/toggle.sgen
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading

0 comments on commit 1a2a788

Please sign in to comment.