mirror of
https://github.com/QuantumLeaps/qpc.git
synced 2025-01-28 07:03:10 +08:00
5.2.0
This commit is contained in:
parent
bc74ea0139
commit
eed870ce9d
@ -735,6 +735,7 @@ WARN_LOGFILE =
|
||||
|
||||
INPUT = ./qpc.txt \
|
||||
./qpc_rev.txt \
|
||||
./qpc_metrics.txt \
|
||||
./qp_macros.h \
|
||||
../include \
|
||||
../qep/source \
|
||||
@ -1066,7 +1067,7 @@ HTML_HEADER =
|
||||
# that doxygen normally uses.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_FOOTER =
|
||||
HTML_FOOTER = ./qpc_footer.html
|
||||
|
||||
# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
|
||||
# sheet that is used by each HTML page. It can be used to fine-tune the look of
|
||||
|
@ -736,6 +736,7 @@ WARN_LOGFILE =
|
||||
INPUT = ./qpc.txt \
|
||||
./qpc_rev.txt \
|
||||
./qp_macros.h \
|
||||
./qpc_metrics.txt \
|
||||
../include \
|
||||
../qep/source \
|
||||
../qf/source \
|
||||
@ -1066,7 +1067,7 @@ HTML_HEADER =
|
||||
# that doxygen normally uses.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_FOOTER =
|
||||
HTML_FOOTER = ./qpc_footer.html
|
||||
|
||||
# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
|
||||
# sheet that is used by each HTML page. It can be used to fine-tune the look of
|
||||
|
62
doxygen/make.bat
Normal file
62
doxygen/make.bat
Normal file
@ -0,0 +1,62 @@
|
||||
@echo off
|
||||
:: ==========================================================================
|
||||
:: Product: QP/C script for generating Doxygen documentation
|
||||
:: Last Updated for Version: 5.2.0
|
||||
:: Date of the Last Update: Dec 20, 2013
|
||||
::
|
||||
:: Q u a n t u m L e a P s
|
||||
:: ---------------------------
|
||||
:: innovating embedded systems
|
||||
::
|
||||
:: Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
::
|
||||
:: This program is open source software: you can redistribute it and/or
|
||||
:: modify it under the terms of the GNU General Public License as published
|
||||
:: by the Free Software Foundation, either version 3 of the License, or
|
||||
:: (at your option) any later version.
|
||||
::
|
||||
:: Alternatively, this program may be distributed and modified under the
|
||||
:: terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
:: the GNU General Public License and are specifically designed for
|
||||
:: licensees interested in retaining the proprietary status of their code.
|
||||
::
|
||||
:: This program is distributed in the hope that it will be useful,
|
||||
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
:: GNU General Public License for more details.
|
||||
::
|
||||
:: You should have received a copy of the GNU General Public License
|
||||
:: along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
::
|
||||
:: Contact information:
|
||||
:: Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
:: http://www.state-machine.com
|
||||
:: e-mail: info@quantum-leaps.com
|
||||
:: ==========================================================================
|
||||
setlocal
|
||||
|
||||
echo usage:
|
||||
echo make
|
||||
echo make -CHM
|
||||
|
||||
set VERSION=5.2.0
|
||||
|
||||
set DOXHOME="C:\tools\Doxygen\bin\Release64"
|
||||
set RCMHOME="C:\tools\MSquared\M2 RSM"
|
||||
|
||||
set RSM_OUTPUT=qpc_metrics.txt
|
||||
set RSM_INPUT=..\include\*.h ..\qep\source\*.h ..\qep\source\*.c ..\qf\source\*.h ..\qf\source\*.c ..\qk\source\*.h ..\qk\source\*.c ..\qs\source\*.h ..\qs\source\*.c
|
||||
|
||||
echo /** \page metrics Code Metrics > %RSM_OUTPUT%
|
||||
echo.>> %RSM_OUTPUT%
|
||||
echo \code >> %RSM_OUTPUT%
|
||||
echo Standard Code Metrics for QP/C %VERSION% >> %RSM_OUTPUT%
|
||||
|
||||
%RCMHOME%\rsm.exe -fd -xNOCOMMAND -xNOCONFIG -u"File cfg rsm_qpc.cfg" %RSM_INPUT% >> %RSM_OUTPUT%
|
||||
|
||||
echo \endcode >> %RSM_OUTPUT%
|
||||
echo */ >> %RSM_OUTPUT%
|
||||
|
||||
%DOXHOME%\doxygen.exe Doxyfile%1
|
||||
|
||||
endlocal
|
@ -8,7 +8,7 @@
|
||||
|
||||
\image html qp_components.jpg
|
||||
|
||||
All QP™ frameworks can run on "bare-metal" single-chip microcontrollers, completely replacing a traditional Real-Time Operating System (RTOS). Ports and ready-to-use examples are provided for most major <a href="http://www.state-machine.com/downloads/index.php#QDK">CPU families</a>. QP/C and QP/C++ can also work with a traditional OS/RTOS, such as: <a href="http://www.state-machine.com/linux/">POSIX (Linux, QNX)</a>, <a href="http://www.state-machine.com/win32/">Windows</a>, <a href="http://www.state-machine.com/android/">Android-NDK</a>, <a href="http://www.state-machine.com/threadx/">ThreadX</a>, <a href="http://www.state-machine.com/ucos2/">MicroC/OS</a>, <a href="http://www.state-machine.com/freertos/">FreeRTOS</a>, etc.
|
||||
All QP™ frameworks can run on "bare-metal" single-chip microcontrollers, completely replacing a traditional Real-Time Operating System (RTOS). Ports and ready-to-use examples are provided for most major <a href="http://www.state-machine.com/downloads/index.php#QDK">CPU families</a>. QP/C and QP/C++ can also work with a traditional OS/RTOS, such as: <a href="http://www.state-machine.com/linux/">POSIX (Linux, embedded Linux, QNX, INTEGRITY)</a>, <a href="http://www.state-machine.com/win32/">Windows (Windows embedded, Windows CE)</a>, <a href="http://www.state-machine.com/android/">Android-NDK</a>, <a href="http://www.state-machine.com/threadx/">ThreadX</a>, <a href="http://www.state-machine.com/ucos2/">MicroC/OS</a>, etc.
|
||||
|
||||
The behavior of active objects is specified in QP by means of <a href="http://en.wikipedia.org/wiki/UML_state_machine">hierarchical state machines (UML statecharts)</a>. The frameworks support manual coding of UML state machines in C or C++ as well as fully automatic code generation by means of the free graphical <a href="http://www.state-machine.com/qm/">QM™ modeling tool</a>.
|
||||
|
||||
@ -22,8 +22,7 @@ For more information about QP, please visit:
|
||||
<a href="http://www.state-machine.com/qp"><strong>state-machine.com/qp</strong></a>
|
||||
|
||||
<HR>
|
||||
QP/C Licensing
|
||||
==============
|
||||
\section licensing QP/C Licensing
|
||||
|
||||
QP/C is licensed under the increasingly popular dual licensing model, in which both the open source software distribution mechanism and traditional closed source software distribution models are combined.
|
||||
|
||||
@ -38,8 +37,8 @@ Closed Source Projects:
|
||||
If you are developing and distributing traditional closed source applications, you can purchase one of Quantum Leaps commercial licenses, which are specifically designed for users interested in retaining the proprietary status of their code. All Quantum Leaps commercial licenses expressly supersede the GPL open source license. This means that when you license Quantum Leaps software under a commercial license, you specifically do not use the software under the open source license and therefore you are not subject to any of its terms.
|
||||
|
||||
<HR>
|
||||
Contact Information
|
||||
===================
|
||||
\section contact Contact Information
|
||||
|
||||
- Quantum Leaps Web site: http://www.state-machine.com
|
||||
- Quantum Leaps licensing: http://www.state-machine.com/licensing
|
||||
- QP/QM on SourceForge.net: http://sourceforge.net/projects/qpc
|
||||
@ -161,9 +160,9 @@ qpc\ - QP/C root directory
|
||||
| | | | | +-rel\ - Release build
|
||||
| | | | | +-spy\ - Spy build (with software instrumentation)
|
||||
| | | | | +-make_cortex-m3_cs.bat - batch script for building QP libraries
|
||||
| | | | | +-qep_port.h - QEP platform-dependent include file
|
||||
| | | | | +-qf_port.h - QF platform-dependent include file
|
||||
| | | | | +-qs_port.h - QS platform-dependent include file
|
||||
| | | | | +-qep_port.h - QEP platform-independent include file
|
||||
| | | | | +-qf_port.h - QF platform-independent include file
|
||||
| | | | | +-qs_port.h - QS platform-independent include file
|
||||
| | | | | +-qp_port.h - QP platform-dependent include file
|
||||
| | | . . .
|
||||
| | +-qk\ - Ports to the preemptive QK kernel
|
||||
|
8
doxygen/qpc_footer.html
Normal file
8
doxygen/qpc_footer.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!-- start footer part -->
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="footer"><a href="http://www.state-machine.com">© Quantum Leaps</a>
|
||||
QP/C 5.2.0
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
3481
doxygen/qpc_metrics.txt
Normal file
3481
doxygen/qpc_metrics.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,88 @@
|
||||
/**
|
||||
\page rev_page Revision History
|
||||
|
||||
\section qpc_5_2_0 Version 5.2.0, Release date: Dec 26, 2013
|
||||
|
||||
This release matches the new QM 3.0.0, for which it provides model
|
||||
examples based on the new QMsm/QMActive classes. This, in turn
|
||||
demonstrates the new state machine code generation that QM3 was
|
||||
specifically designed to do.
|
||||
|
||||
This release also provides consistent API for late-binding ("virtual"
|
||||
functions) introduced in QP 5.0.0, as opposed to using regular linking
|
||||
(early-binding) for direct function calls, such as QHsm_dispatch(). A
|
||||
clearly separated API compatibility layer is provided, whereas you can
|
||||
configure a level of backwards compatibility by means of the
|
||||
#QP_API_VERSION macro. This facilitates migrating existing QP
|
||||
applications to the newer API.
|
||||
|
||||
An cyclomatic complexity (McCabe V(G)) analysis of this version has been
|
||||
performed and the maximum V(G) complexity per function has been reduced
|
||||
to 15 by breaking up the QHsm_dispatch_() function. The code metrics
|
||||
report, including cyclomatic complexity by function as well as other
|
||||
standard code metrics (e.g., lines of code), is now included in the
|
||||
"QP/C Reference Manual", see
|
||||
http://www.state-machine.com/qp/qpc/metrics.html
|
||||
|
||||
Finally, this release demonstrates safer stack allocation and safer
|
||||
exception handlers in all ARM Cortex-M examples. The techniques are
|
||||
described in the Embedded.com article "Are We Shooting Ourselves in the
|
||||
Foot with Stack Overflow?".
|
||||
|
||||
Changes in detail:
|
||||
|
||||
1. In file qep.h renamed the implementation functions, such as
|
||||
QHsm_init() and QHsm_dispatch() to QHsm_init_() and QHsm_dispatch_()
|
||||
(note the underscore, which means that the functions should not be
|
||||
called directly by the application code). The only correct way of
|
||||
calling the functions is through the macros QMSM_INIT() and
|
||||
QMSM_DISPATCH(), respectively. The latter macros implement late-binding
|
||||
("virtual" functions in C).
|
||||
|
||||
2. In file qf.h renamed the implementation functions, such as
|
||||
QActive_start(), QActive_post() and QActive_postLIFO() to
|
||||
QActive_start_(), QActive_post_(), and QActive_postLIFO_, respectively
|
||||
(note the underscore, which means that the functions should not be
|
||||
called directly by the application code). The only correct way of
|
||||
calling the functions is through the macros QACTIVE_START(),
|
||||
QACTIVE_POST(), and QACTIVE_POST_LIFO(), respectively. The latter macros
|
||||
implement late-binding ("virtual" functions in C).
|
||||
|
||||
3. for backwards compatibility, in file qp_port.h defined "API
|
||||
Compatibility Layer", which is controlled by the macro #QP_API_VERSION.
|
||||
For example, specifying QP_API_VERSION=500 chooses API compatible with
|
||||
QP version 5.0.0 or newer, but excludes APIs that became deprecated in
|
||||
the earlier versions. If the macro #QP_API_VERSION is not defined by the
|
||||
user (typically on the command line for the compiler), the default value
|
||||
of 0 is assumed. This default means maximum backwards compatibility
|
||||
(from version 0.0.0). On the other hand, higher values of
|
||||
#QP_API_VERSION mean less backwards compatibility. For example
|
||||
QP_API_VERSION=9999 will specify compatibility only with the latest
|
||||
version of QP.
|
||||
|
||||
The API Compatibility Layer for QP_API_VERSION < 500 provides macros:
|
||||
QHsm_init(), QHsm_dispatch(), QActive_start(), QActive_post() and
|
||||
QActive_postLIFO(). These macros resolve to QMSM_INIT() and
|
||||
QMSM_DISPATCH(), QACTIVE_START(), QACTIVE_POST() and QACTIVE_POST_LIFO()
|
||||
respectively, so that calls based on the older API also use late-binging.
|
||||
|
||||
4. In file qhsm_dis.c, broken up the function QHsm_dispatch() into two
|
||||
functions QHsm_dispatch_() and QHsm_tran_(). This has reduced the
|
||||
cyclomatic complexity from 25 for the original function, to 11 and 15
|
||||
for QHsm_dispatch_() and QHsm_tran_(), respectively.
|
||||
|
||||
5. In file qmsm_dis.c, broken up the function QMsm_dispatch() into two
|
||||
functions QMsm_dispatch_() and QMsm_tran_(). This has reduced the
|
||||
cyclomatic complexity from 15 for the original function, to 9 and 7 for
|
||||
QMsm_dispatch_() and QMsm_tran_(), respectively.
|
||||
|
||||
6. Updated all examples for ARM Cortex-M to use safer stack allocation
|
||||
and safer exception handlers in all ARM Cortex-M examples, as described
|
||||
in the Embedded.com article "Are We Shooting Ourselves in the Foot with
|
||||
Stack Overflow?".
|
||||
|
||||
|
||||
<HR>
|
||||
\section qpc_5_1_1 Version 5.1.1, Release date: Oct 10, 2013
|
||||
|
||||
This release fixes reversal of logic in the QF_noTimeEvtsActiveX()
|
||||
|
45
doxygen/rsm.bat
Normal file
45
doxygen/rsm.bat
Normal file
@ -0,0 +1,45 @@
|
||||
@echo off
|
||||
:: ==========================================================================
|
||||
:: Product: QP/C script for running MSquared Resource Standard Metrics (RSM)
|
||||
:: Last Updated for Version: 5.2.0
|
||||
:: Date of the Last Update: Dec 20, 2013
|
||||
::
|
||||
:: Q u a n t u m L e a P s
|
||||
:: ---------------------------
|
||||
:: innovating embedded systems
|
||||
::
|
||||
:: Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
::
|
||||
:: This program is open source software: you can redistribute it and/or
|
||||
:: modify it under the terms of the GNU General Public License as published
|
||||
:: by the Free Software Foundation, either version 3 of the License, or
|
||||
:: (at your option) any later version.
|
||||
::
|
||||
:: Alternatively, this program may be distributed and modified under the
|
||||
:: terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
:: the GNU General Public License and are specifically designed for
|
||||
:: licensees interested in retaining the proprietary status of their code.
|
||||
::
|
||||
:: This program is distributed in the hope that it will be useful,
|
||||
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
:: GNU General Public License for more details.
|
||||
::
|
||||
:: You should have received a copy of the GNU General Public License
|
||||
:: along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
::
|
||||
:: Contact information:
|
||||
:: Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
:: http://www.state-machine.com
|
||||
:: e-mail: info@quantum-leaps.com
|
||||
:: ==========================================================================
|
||||
setlocal
|
||||
|
||||
set RCMHOME="C:\tools\MSquared\M2 RSM"
|
||||
|
||||
set RSM_OUTPUT=qpc_metrics.txt
|
||||
set RSM_INPUT=..\include\*.h ..\qep\source\*.h ..\qep\source\*.c ..\qf\source\*.h ..\qf\source\*.c ..\qk\source\*.h ..\qk\source\*.c ..\qs\source\*.h ..\qs\source\*.c
|
||||
|
||||
%RCMHOME%\rsm.exe -fd -n -xNOCOMMAND -xNOCONFIG -u"File cfg rsm_qpc.cfg" %RSM_INPUT% > %RSM_OUTPUT%
|
||||
|
||||
endlocal
|
637
doxygen/rsm_qpc.cfg
Normal file
637
doxygen/rsm_qpc.cfg
Normal file
@ -0,0 +1,637 @@
|
||||
# ==========================================================================
|
||||
# Product: Configuration file for MSquared Resource Standard Metrics (RSM)
|
||||
# Last Updated for Version: 5.2.0
|
||||
# Date of the Last Update: Dec 20, 2013
|
||||
#
|
||||
# Q u a n t u m L e a P s
|
||||
# ---------------------------
|
||||
# innovating embedded systems
|
||||
#
|
||||
# Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
#
|
||||
# This program is open source software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Alternatively, this program may be distributed and modified under the
|
||||
# terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
# the GNU General Public License and are specifically designed for
|
||||
# licensees interested in retaining the proprietary status of their code.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Contact information:
|
||||
# Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
# http://www.state-machine.com
|
||||
# e-mail: info@quantum-leaps.com
|
||||
# ==========================================================================
|
||||
|
||||
####################################################################
|
||||
# RSM Operational Configuration ####################################
|
||||
|
||||
# Company Specific Header
|
||||
# This line will appear at the top of all reports
|
||||
# Typical uses include copyrights, security and project markings
|
||||
# You must specify both a text version for text and csv reports
|
||||
# and an HTML version.
|
||||
Report Header Active : No
|
||||
Report Header Text Line : Standard Metrics Report
|
||||
Report Header HTML Line : <font color="RED" size="+2"><B><I> Standard Metrics Report</I></B></font>
|
||||
|
||||
# Enable user defined configuration files.
|
||||
# The file rsm.cfg is read from the location of the rsm.lic file.
|
||||
# This file can enable this option to allow users to override the
|
||||
# operational configuration of RSM. This option is enabled by the
|
||||
# end user with the -u "File cfg path\file" option
|
||||
Enable user defined configuration files : Yes
|
||||
|
||||
# Windows 9x and DOS are case insensitive file systems.
|
||||
# Files like foo.c and foo.C are seen as C source files.
|
||||
# If *.C files are C++ files under these operating systems
|
||||
# or you are operating on NT or UNIX set this option to
|
||||
# case sensitivity equal to Yes.
|
||||
Source file names are case sensitive : No
|
||||
|
||||
# Show a progress indicator when processing files and
|
||||
# code differentials.
|
||||
Show progress indicator : Yes
|
||||
Detailed Progress Showing File Names : Yes
|
||||
|
||||
# Number of files which comprise a status marker when
|
||||
# status is indicated during lengthy operations.
|
||||
Progress status interval number of files: 10
|
||||
|
||||
# Show file dates when displaying file metrics.
|
||||
Show file date and size : No
|
||||
|
||||
# RSM will process only files with the following extensions.
|
||||
# The user may add to this list, but RSM is designed to process
|
||||
# only the C, C++, C# and Java languages.
|
||||
Validate file extensions for processing : Yes
|
||||
|
||||
# Specify the extensions for each type of supported language.
|
||||
# Files extensions are separated by commas and are case sensitive
|
||||
# if case sensitivity is specified in this file (comma separated,no spaces).
|
||||
C File Extensions : c
|
||||
C Header File Extensions : h
|
||||
C++ File Extensions : cc,cpp,cxx,h,hh,H,hxx
|
||||
C++ Header File Extensions : h,hh,H,hxx
|
||||
C# File Extensions : cs
|
||||
Java File Extensions : java
|
||||
# Other files are not officially supported by RSM
|
||||
# but lines will be counted as LOC
|
||||
Other File Extensions :
|
||||
|
||||
# When analyzing *.h files, treat header files as
|
||||
# both C and C++. If you use separate extensions for C++ and
|
||||
# C header files, then set this option to No.
|
||||
Treat C headers as C++ : Yes
|
||||
|
||||
# RSM will not process files when the path/file name contains
|
||||
# a pattern in the pattern list (comma separated,no spaces).
|
||||
Pattern Filter Active : No
|
||||
Pattern Filter : .designer.c
|
||||
|
||||
# RSM Code skip strings allow the RSM parser to skip
|
||||
# processing of all code between the start and stop
|
||||
# tokens. This is useful for machine generated code.
|
||||
# Code tokens are unique in the could base and if
|
||||
# found on a code line the rsm processing will be effected.
|
||||
# Start and stop tokens must match within a file and
|
||||
# cannot span files. A token cannot contain spaces and
|
||||
# must be alphnumeric and can contain the underscore.
|
||||
# Quality skip tokens turn off just quality notice checking.
|
||||
# i.e. // RSM_IGNORE_BEGIN
|
||||
# some code ....
|
||||
# // RSM_IGNORE_END
|
||||
RSM Code Skip Start Token : RSM_IGNORE_BEGIN
|
||||
RSM Code Skip End Token : RSM_IGNORE_END
|
||||
RSM Code Quality Skip Start Token : RSM_IGNORE_QUALITY_BEGIN
|
||||
RSM Code Quality Skip End Token : RSM_IGNORE_QUALITY_END
|
||||
Activate RSM code skip tokens : Yes
|
||||
|
||||
# RSM will not process files in local directories when this
|
||||
# flag is set. This will prevent recursive descent into
|
||||
# these directories (comma separated,no spaces).
|
||||
Do not process these local directories : No
|
||||
Local directory names not processed : test,sccs,cvs,rcs,svn
|
||||
|
||||
# Names in reports include file, namespace or package, class
|
||||
# and function names. These names can get quite long and will
|
||||
# extend beyond the report right margin. This setting will
|
||||
# wrap the name to the report right margin.
|
||||
Wrap long names in reports : Yes
|
||||
|
||||
####################################################################
|
||||
# RSM Configuration for Baseline Metrics Differentials #############
|
||||
|
||||
# The following path location specifies where work files
|
||||
# are to be created. The path must be a location with write
|
||||
# permissions. RSM will create work files in the current
|
||||
# directory if no path is specified.
|
||||
Work file location path :
|
||||
|
||||
# When processing code line differentials, ignore
|
||||
# blank line changes in the code.
|
||||
Ignore code differential blank lines : Yes
|
||||
|
||||
# When processing code line differentials, ignore
|
||||
# blanks and tab changes in the code.
|
||||
Ignore code differential white space : Yes
|
||||
|
||||
# Maximum number of lines in a file when using Longest Common Sequence
|
||||
# differential algorithm. This value establishes the line to line
|
||||
# comparison matrix size. This value has been set to the maximum allowed
|
||||
# under 32 bit operating systems. It is not advised to make this value >
|
||||
# than 10000. If you have a machine with very low physical memory you may
|
||||
# want to use a value of 6000 to 7000 where 10000 should be a maximum.
|
||||
# When file lengths exceed the matrix limits, the file is segmented to fit
|
||||
# the matrix size.
|
||||
Maximum LCS file size, number of lines : 10000
|
||||
|
||||
# Code differential metrics determine lines that are
|
||||
# different in the current baseline compared to the
|
||||
# older baseline. This metric can include
|
||||
# lines that are removed from the current baseline.
|
||||
Add removed older lines as modified : No
|
||||
|
||||
# When showing differential details for each file
|
||||
# using the switch -ws
|
||||
Show equal lines : Yes
|
||||
Show lines removed from older file : Yes
|
||||
Show lines added (mod) to newer file : Yes
|
||||
|
||||
# The following parameter, when set to Yes will cause
|
||||
# the files stored into work files to be relative to the
|
||||
# location specified by the -w"create top_dir", baseline
|
||||
# top directory.
|
||||
Relative Work Files : Yes
|
||||
|
||||
# User defined productivity values for determining works
|
||||
# rates for baseline metric differentials.
|
||||
Work Seconds per Hour : 3600
|
||||
Work Hours per Shift : 8
|
||||
Work Shifts per Day : 1
|
||||
Work Days per Week : 5
|
||||
Work Hours per Man Day : 8
|
||||
Work Hours per Man Week : 40
|
||||
Work Hours per Man Month : 160
|
||||
Work Hours per Man Year : 1960
|
||||
|
||||
#####################################################################
|
||||
# Function point conversion factors for LOC metrics
|
||||
#
|
||||
Header File Function Points per LOC : 0
|
||||
Header File Function Points per eLOC : 0
|
||||
Header File Function Points per lLOC : 0
|
||||
C File Function Points per LOC : 128
|
||||
C File Function Points per eLOC : 128
|
||||
C File Function Points per lLOC : 128
|
||||
C++ File Function Points per LOC : 53
|
||||
C++ File Function Points per eLOC : 53
|
||||
C++ File Function Points per lLOC : 53
|
||||
Java File Function Points per LOC : 53
|
||||
Java File Function Points per eLOC : 53
|
||||
Java File Function Points per lLOC : 53
|
||||
C# File Function Points per LOC : 53
|
||||
C# File Function Points per eLOC : 53
|
||||
C# File Function Points per lLOC : 53
|
||||
Other File Function Points per LOC : 0
|
||||
Other File Function Points per eLOC : 0
|
||||
Other File Function Points per lLOC : 0
|
||||
|
||||
####################################################################
|
||||
# RSM Configuration for cyclomatic complexity ######################
|
||||
#
|
||||
# McCabe Cyclomatic Complexity includes the following constructs in
|
||||
# the calculation.
|
||||
# function call + if + inline if + while + for + foreach
|
||||
# case + goto + logical or + Logical and
|
||||
#
|
||||
# You may tailor the cyclomatic complexity calculation to meet your
|
||||
# specific requirements.
|
||||
|
||||
Include 'function call' in cyclomatic complexity: Yes
|
||||
Include 'while' in cyclomatic complexity : Yes
|
||||
Include 'for' in cyclomatic complexity : Yes
|
||||
Include 'switch' in cyclomatic complexity : No
|
||||
Include 'case' in cyclomatic complexity : Yes
|
||||
Include 'if' in cyclomatic complexity : Yes
|
||||
Include 'else' in cyclomatic complexity : No
|
||||
Include '?' inlined if in cyclomatic complexity : Yes
|
||||
Include 'goto' in cyclomatic complexity : Yes
|
||||
Include '||' or 'or' in cyclomatic complexity : Yes
|
||||
Include '&&' or 'and' in cyclomatic complexity : Yes
|
||||
|
||||
####################################################################
|
||||
# RSM Quality Notices Configuration ################################
|
||||
|
||||
# User Defined Quality Notices UDQN
|
||||
# Specify the file name which contains the UDQN definitions
|
||||
# See this provided example for a tutorial on UDQN.
|
||||
RSM user defined quality notice file : rsm_udqn.cfg
|
||||
|
||||
# Re-order the quality notice format so that if a line number
|
||||
# is emitted, the line number precedes the notice number. This
|
||||
# option enables code editors to parse the notice line.
|
||||
Reorder notice, line in quality notices : No
|
||||
|
||||
# RSM Quality Notices For Code Style ###################################
|
||||
|
||||
# Quality Notice No. 1
|
||||
# Emit a quality notice when the physical line length
|
||||
# is greater than the specified number of characters.
|
||||
Quality Notice 1 : Yes
|
||||
Maximum Line Length : 80
|
||||
|
||||
# Quality Notice No. 2
|
||||
# Emit a quality notice when the function name length
|
||||
# is greater than the specified number of characters.
|
||||
Quality Notice 2 : Yes
|
||||
Maximum Function Name Length : 32
|
||||
|
||||
# Quality Notice No. 21
|
||||
# Emit a quality notice when a file does not contain
|
||||
# the specified key string.
|
||||
Quality Notice 21 : No
|
||||
RSM KEY String :
|
||||
|
||||
# RSM Quality Notices For Stability and Maintainability ################
|
||||
|
||||
# Quality Notice No. 3
|
||||
# Emit a quality notice when ellipsis '...' are identified
|
||||
# within a functions parameter list thus enabling variable
|
||||
# arguments.
|
||||
Quality Notice 3 : Yes
|
||||
|
||||
# Quality Notice No. 4
|
||||
# Emit a quality notice if there exists an assignment
|
||||
# operator '=' within a logical 'if' condition.
|
||||
Quality Notice 4 : Yes
|
||||
|
||||
# Quality Notice No. 5
|
||||
# Emit a quality notice if there exists an assignment
|
||||
# operator '=' within a logical 'while' condition.
|
||||
Quality Notice 5 : Yes
|
||||
|
||||
# Quality Notice No. 6
|
||||
# Emit a quality notice when a pre-decrement operator '--'
|
||||
# is identified within the code.
|
||||
Quality Notice 6 : No
|
||||
|
||||
# Quality Notice No. 7
|
||||
# Emit a quality notice when a pre-increment operator '++'
|
||||
# is identified within the code.
|
||||
Quality Notice 7 : No
|
||||
|
||||
# Quality Notice No. 8
|
||||
# Emit a quality notice when the 'realloc' function
|
||||
# is identified within the code.
|
||||
Quality Notice 8 : Yes
|
||||
|
||||
# Quality Notice No. 9
|
||||
# Emit a quality notice when the 'goto' function
|
||||
# is identified within the code.
|
||||
Quality Notice 9 : Yes
|
||||
|
||||
# Quality Notice No. 10
|
||||
# Emit a quality notice when the Non-ANSI function
|
||||
# prototype is identified within the code.
|
||||
Quality Notice 10 : Yes
|
||||
|
||||
# Quality Notice No. 11
|
||||
# Emit a quality notice when open and closed brackets
|
||||
# '[ ]' are not balance within a file.
|
||||
Quality Notice 11 : Yes
|
||||
|
||||
# Quality Notice No. 12
|
||||
# Emit a quality notice when open and closed parenthesis
|
||||
# '()' are not balance within a file.
|
||||
Quality Notice 12 : Yes
|
||||
|
||||
# Quality Notice No. 13
|
||||
# Emit a quality notice when a 'switch' statement does
|
||||
# not have a 'default' condition.
|
||||
Quality Notice 13 : Yes
|
||||
|
||||
# Quality Notice No. 14
|
||||
# Emit a quality notice when there are more 'case' conditions
|
||||
# than 'break' statements or 'fall through' comments.
|
||||
Use default in case/break comparison : Yes
|
||||
Quality Notice 14 : Yes
|
||||
|
||||
# Quality Notice No. 15
|
||||
# Emit a quality notice when a friend class
|
||||
# is identified within the code.
|
||||
Quality Notice 15 : Yes
|
||||
|
||||
# Quality Notice No. 22
|
||||
# Emit a quality notice when each if, else, for
|
||||
# or while is not bound by scope.
|
||||
Quality Notice 22 : Yes
|
||||
|
||||
# Quality Notice No. 23
|
||||
# Emit a quality notice when the '?' or the implied
|
||||
# if-then-else construct has been identified.
|
||||
Quality Notice 23 : Yes
|
||||
|
||||
# Quality Notice No. 24
|
||||
# Emit a quality notice when an ANSI C++ keyword
|
||||
# is identified within a *.c or a *.h file.
|
||||
Quality Notice 24 : Yes
|
||||
|
||||
# Quality Notice No. 26
|
||||
# Emit a quality notice when a void * is identified
|
||||
# within a source file.
|
||||
Quality Notice 26 : No
|
||||
|
||||
# Quality Notice No. 27
|
||||
# Emit a quality notice when the number of function
|
||||
# return points is greater than the specified maximum.
|
||||
Quality Notice 27 : Yes
|
||||
Maximum functional return points : 1
|
||||
Count goto as a function return point : Yes
|
||||
|
||||
# Quality Notice No. 28
|
||||
# Emit a quality notice when the cyclomatic complexity
|
||||
# of a function exceeds the specified maximum.
|
||||
Quality Notice 28 : Yes
|
||||
Maximum functional cyclomatic complexity: 10
|
||||
|
||||
# Quality Notice No. 29
|
||||
# Emit a quality notice when the number of function
|
||||
# input parameters exceeds the specified maximum.
|
||||
Quality Notice 29 : Yes
|
||||
Maximum functional interface complexity : 6
|
||||
|
||||
# Quality Notice No. 49
|
||||
# Emit a quality notice when function parameters
|
||||
# are blank or not specified, thus requiring void.
|
||||
Quality Notice 49 : Yes
|
||||
|
||||
# Quality Notice No. 30
|
||||
# Emit a quality notice when a TAB character is identified
|
||||
# within the source code. Indentation with TAB will create
|
||||
# editor and device dependent formatting.
|
||||
Quality Notice 30 : Yes
|
||||
|
||||
# Quality Notice No. 32
|
||||
# Emit a quality notice when 'using namespace'
|
||||
# has been identified in a C++ source file.
|
||||
Quality Notice 32 : Yes
|
||||
|
||||
# Quality Notice No. 33
|
||||
# Emit a quality notice when a class/struct definition
|
||||
# is identified within a function definition.
|
||||
Quality Notice 33 : Yes
|
||||
|
||||
# Quality Notice No. 34
|
||||
# Emit a quality notice when a class definition
|
||||
# contains a pointer to a data item.
|
||||
Quality Notice 34 : Yes
|
||||
|
||||
# Quality Notice No. 35
|
||||
# Emit a quality notice when a class definition
|
||||
# contains public data.
|
||||
Quality Notice 35 : Yes
|
||||
|
||||
# Reference Quality Notice No. 35
|
||||
# Ignore public data for specific types of data
|
||||
Ignore public event data : Yes
|
||||
Ignore public const data : Yes
|
||||
Ignore public delegate data : Yes
|
||||
|
||||
# Quality Notice No. 36
|
||||
# Emit a quality notice when a class definition
|
||||
# contains protected data.
|
||||
Quality Notice 36 : Yes
|
||||
|
||||
# Quality Notice No. 37
|
||||
# Emit a quality notice when a base class, with virtual
|
||||
# functions, does not contain a virtual destructor.
|
||||
Quality Notice 37 : Yes
|
||||
|
||||
# Quality Notice No. 38
|
||||
# Emit a quality notice when exception handling is
|
||||
# present within a function.
|
||||
Quality Notice 38 : Yes
|
||||
|
||||
# Quality Notice No. 39
|
||||
# Emit a quality notice when the number of class/struct methods
|
||||
# exceed the specified maximum (public, protected and private).
|
||||
Quality Notice 39 : Yes
|
||||
Maximum number of methods per class : 100
|
||||
|
||||
# Quality Notice No. 40
|
||||
# Emit a quality notice when the depth of the inheritance
|
||||
# tree exceeds the specified maximum value.
|
||||
Quality Notice 40 : Yes
|
||||
Maximum depth of inheritance tree : 4
|
||||
|
||||
# Quality Notice No. 41
|
||||
# Emit a quality notice when the number of direct derived
|
||||
# classes exceeds the specified maximum value.
|
||||
Quality Notice 41 : Yes
|
||||
Maximum number of derived child classes : 10
|
||||
|
||||
# Quality Notice No. 42
|
||||
# Emit a quality notice when the multiple inheritance
|
||||
# has been identified.
|
||||
Quality Notice 42 : Yes
|
||||
|
||||
# Quality Notice No. 43
|
||||
# Emit a quality notice when the keyword 'continue'
|
||||
# has been identified.
|
||||
Quality Notice 43 : Yes
|
||||
|
||||
# Quality Notice No. 44
|
||||
# Emit a quality notice when the keyword 'break'
|
||||
# has been identified outside a 'switch' logic
|
||||
# control structure.
|
||||
Quality Notice 44 : Yes
|
||||
|
||||
# Quality Notice No. 45
|
||||
# Emit a quality notice when a file does not
|
||||
# have equal counts of new and delete.
|
||||
Quality Notice 45 : Yes
|
||||
|
||||
# Quality Notice No. 50
|
||||
# Emit a quality notice when a variable is assigned
|
||||
# to a literal number and not a symbolic constant.
|
||||
Quality Notice 50 : No
|
||||
Include zero (0) as literal assignment : No
|
||||
|
||||
# Quality Notice No. 55
|
||||
# Emit a quality notice when the depth of scope
|
||||
# exceeds the specified maximum value. This condition
|
||||
# indicates complex logic and/or a maintenance concern.
|
||||
Quality Notice 55 : Yes
|
||||
Maximum depth of scope : 6
|
||||
|
||||
# Quality Notice No. 56
|
||||
# Emit a quality notice when sequential breaks are
|
||||
# identified without a respective case statement.
|
||||
Quality Notice 56 : Yes
|
||||
|
||||
# RSM Quality Notices for Functional/Struct and Class Content ##########
|
||||
|
||||
# Minimum LOC for content analysis for blank lines
|
||||
# comments, and white space.
|
||||
Min. Function LOC for content analysis : 5
|
||||
Min. Class/Struct LOC content analysis : 10
|
||||
|
||||
# Quality Notice No. 16
|
||||
# Emit a quality notice when function, struct, class
|
||||
# or interface white space percentage is less than
|
||||
# the specified minimum.
|
||||
Quality Notice 16 : Yes
|
||||
Minimum Function Whitespace Percent : 10.00
|
||||
|
||||
# Quality Notice No. 17
|
||||
# Emit a quality notice when function comment line
|
||||
# percentage is less than the specified minimum.
|
||||
Quality Notice 17 : No
|
||||
Minimum Function Comment Line Percent : 10.00
|
||||
|
||||
# Quality Notice No. 18
|
||||
# Emit a quality notice when the eLOC within a
|
||||
# function exceeds the specified maximum.
|
||||
Quality Notice 18 : Yes
|
||||
Maximum Function eLOC : 200
|
||||
|
||||
# Quality Notice No. 48
|
||||
# Emit a quality notice when the lLOC within a
|
||||
# function does not meet the specified minimum.
|
||||
# This notice serves to find nop functions.
|
||||
Quality Notice 48 : Yes
|
||||
Minimum Function lLOC : 0
|
||||
|
||||
# Quality Notice No. 31
|
||||
# Emit a quality notice when class/struct comment line
|
||||
# percentage is less than the specified minimum.
|
||||
Quality Notice 31 : Yes
|
||||
Minimum Class/Struct Comment Percent : 10.00
|
||||
|
||||
# Quality Notice No. 46
|
||||
# Emit a quality notice when function, struct, class
|
||||
# or interface blank line percentage is less than the
|
||||
# specified minimum.
|
||||
Quality Notice 46 : No
|
||||
Minimum Function Blank Line Percent : 10.00
|
||||
|
||||
# Quality Notice No. 51
|
||||
# Emit a quality notice when a function
|
||||
# does not have a preceding comment.
|
||||
Quality Notice 51 : Yes
|
||||
|
||||
# Quality Notice No. 52
|
||||
# Emit a quality notice when a class
|
||||
# does not have a preceding comment.
|
||||
Quality Notice 52 : Yes
|
||||
|
||||
# Quality Notice No. 53
|
||||
# Emit a quality notice when a struct
|
||||
# does not have a preceding comment.
|
||||
Quality Notice 53 : Yes
|
||||
|
||||
# Quality Notice No. 54
|
||||
# Emit a quality notice when a interface
|
||||
# does not have a preceding comment.
|
||||
Quality Notice 54 : Yes
|
||||
|
||||
# RSM Quality Notices for File Content #
|
||||
|
||||
# Quality Notice No. 19
|
||||
# Emit a quality notice when file white space
|
||||
# percentage is less than the specified minimum.
|
||||
# Consider setting Notice 30 to No.
|
||||
Quality Notice 19 : Yes
|
||||
Minimum File Whitespace Percent : 10.00
|
||||
A TAB is equivalent to n space : 2
|
||||
|
||||
# Quality Notice No. 20
|
||||
# Emit a quality notice when file comment line
|
||||
# percentage is less than the specified minimum.
|
||||
Quality Notice 20 : Yes
|
||||
Minimum File Comment Line Percent : 10.00
|
||||
|
||||
# Quality Notice No. 47
|
||||
# Emit a quality notice when file blank line
|
||||
# percentage is less than the specified minimum.
|
||||
Quality Notice 47 : No
|
||||
Minimum File Blank Line Percent : 10.00
|
||||
|
||||
# Quality Notice No. 57
|
||||
# Emit a quality notice when RSM skip lines conditions
|
||||
# are met by a matching token.
|
||||
Quality Notice 57 : No
|
||||
|
||||
# Quality Notice No. 58
|
||||
# Emit a quality notice when RSM skip quality notice conditions
|
||||
# are met by a matching token.
|
||||
Quality Notice 58 : No
|
||||
|
||||
# RSM Quality Notices Miscellaneous ####################################
|
||||
|
||||
# Quality Notice No. 25
|
||||
# Deprecated in Version 6.70
|
||||
# See settings under language extensions.
|
||||
|
||||
####################################################################
|
||||
# Code Listing Report Configuration ################################
|
||||
|
||||
# The following parameters setup source code printing.
|
||||
# These values become the default settings.
|
||||
Printed Line Length : 80
|
||||
Printed Page Length : 55
|
||||
Printed Left Margin : 5
|
||||
Printed Top Margin : 1
|
||||
Printed Page Header : RSM Code Listing
|
||||
Page breaks in code print format : No
|
||||
|
||||
####################################################################
|
||||
# HTML Report and Color Configuration ##############################
|
||||
|
||||
# The following parameters setup HTML report output. The hyperlinks
|
||||
# for source code can be either absolute or relative.
|
||||
Relative HTML Links : No
|
||||
|
||||
# The following color parameters modify the HTML report
|
||||
# output. Colors can be specified as Hex or Name.
|
||||
# Blank color parameters will result to the browser default.
|
||||
HTML RSM Color : #0000FF
|
||||
HTML Date Color : #0000FF
|
||||
HTML Text Color : #000000
|
||||
HTML VLink Color : #660099
|
||||
HTML Link Color : #0000EE
|
||||
HTML Background Color : #F8F8F8
|
||||
HTML Error Color : #FF0000
|
||||
HTML Line Color : #003399
|
||||
HTML Old File Differential Color : #CC0033
|
||||
HTML New File Differential Color : #336666
|
||||
HTML File Name Color : #0000FF
|
||||
HTML Function Color : #0000FF
|
||||
HTML Function Parameter Color : #006600
|
||||
HTML Template Color : #006699
|
||||
HTML Macro Color : #33CCFF
|
||||
HTML Class Color : #663300
|
||||
HTML Inheritance Color : #FF3300
|
||||
HTML Struct Color : #990000
|
||||
HTML Notice Color : #CC0000
|
||||
HTML Header Color : #993300
|
||||
HTML New Code Differential Color : #3366CC
|
||||
HTML Removed Code Differential Color : #FF0000
|
||||
HTML Modified Code Differential Color : #993300
|
||||
HTML Equal Code Differential Color : #00CC00
|
||||
HTML Total Color : #993300
|
||||
HTML Inheritance Depth Color : #333300
|
||||
HTML Inheritance Child Color : #CC6600
|
||||
####################################################################
|
||||
# end of rsm.cfg
|
@ -1,13 +1,13 @@
|
||||
/*****************************************************************************
|
||||
* Product: Time Bomb Example with QEP
|
||||
* Last Updated for Version: 4.5.00
|
||||
* Date of the Last Update: May 18, 2012
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 24, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
@ -32,7 +32,7 @@
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
#include "qep_port.h" /* the port of the QEP event processor */
|
||||
#include "qp_port.h" /* the QP port */
|
||||
#include "bsp.h" /* board support package */
|
||||
|
||||
enum BombSignals { /* all signals for the Bomb FSM */
|
||||
|
@ -95,7 +95,7 @@ void QF_onIdle(void) { /* NOTE: entered with interrupts DISABLED */
|
||||
QF_INT_ENABLE(); /* must at least enable interrupts */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
QF_stop();
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ void QF_onIdle(void) { /* NOTE: entered with interrupts DISABLED */
|
||||
QF_INT_ENABLE(); /* must at least enable interrupts */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
QF_stop();
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ void BSP_busyDelay(void) {
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
QF_stop();
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ void QF_onIdle(void) {
|
||||
#endif
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
Video_clearRect ( 0, 24, 80, 25, VIDEO_BGND_RED);
|
||||
Video_printStrAt( 0, 24, VIDEO_FGND_WHITE, "ASSERTION FAILED in file:");
|
||||
Video_printStrAt(26, 24, VIDEO_FGND_YELLOW, file);
|
||||
|
@ -1,13 +1,13 @@
|
||||
/*****************************************************************************
|
||||
* Product: History state pattern example
|
||||
* Last Updated for Version: 4.5.00
|
||||
* Date of the Last Update: May 18, 2012
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 24, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
@ -32,7 +32,7 @@
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
#include "qep_port.h"
|
||||
#include "qp_port.h" /* the QP port */
|
||||
#include "qassert.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -229,7 +229,7 @@ void main() {
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
_exit(-1);
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
/*****************************************************************************
|
||||
* Product: Ultimate Hook state pattern example
|
||||
* Last Updated for Version: 4.5.00
|
||||
* Date of the Last Update: May 18, 2012
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 24, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
@ -32,7 +32,7 @@
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
#include "qep_port.h"
|
||||
#include "qp_port.h" /* the QP port */
|
||||
#include "qassert.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -171,7 +171,7 @@ void main() {
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
_exit(-1);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
QHsmTst example, QEP 5.1.1
|
||||
QHsmTst example, QEP 5.2.0
|
||||
top-INIT;s-ENTRY;s2-ENTRY;s2-INIT;s21-ENTRY;s211-ENTRY;
|
||||
A:s21-A;s211-EXIT;s21-EXIT;s21-ENTRY;s21-INIT;s211-ENTRY;
|
||||
B:s21-B;s211-EXIT;s211-ENTRY;
|
||||
|
@ -1,13 +1,13 @@
|
||||
/*****************************************************************************
|
||||
* Product: QHsmTst Example, DOS, Large model
|
||||
* Last Updated for Version: 4.5.00
|
||||
* Date of the Last Update: May 18, 2012
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 24, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
@ -32,8 +32,7 @@
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
#include "qep_port.h"
|
||||
#include "qassert.h"
|
||||
#include "qp_port.h" /* the QP port */
|
||||
#include "qhsmtst.h"
|
||||
|
||||
#include <conio.h>
|
||||
@ -128,7 +127,7 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ void QF_onIdle(void) { /* NOTE: entered with interrupts DISABLED */
|
||||
QF_INT_ENABLE(); /* must at least enable interrupts */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
||||
QF_stop();
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ void BSP_displyPhilStat(uint8_t n, char const *stat) {
|
||||
QS_END()
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
Video_clearRect ( 0, 24, 80, 25, VIDEO_BGND_RED);
|
||||
Video_printStrAt( 0, 24, VIDEO_FGND_WHITE, "ASSERTION FAILED in file:");
|
||||
Video_printStrAt(26, 24, VIDEO_FGND_YELLOW, file);
|
||||
|
@ -243,7 +243,7 @@ void QK_onIdle(void) {
|
||||
#endif
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
void Q_onAssert(char const Q_ROM * const file, int line) {
|
||||
Video_clearRect ( 0, 24, 80, 25, VIDEO_BGND_RED);
|
||||
Video_printStrAt( 0, 24, VIDEO_FGND_WHITE, "ASSERTION FAILED in file:");
|
||||
Video_printStrAt(26, 24, VIDEO_FGND_YELLOW, file);
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="2.3.2">
|
||||
<item name="license"></item>
|
||||
<group name="locked"/>
|
||||
<group name="settings">
|
||||
<item name="tabs">1</item>
|
||||
<item name="windows">0</item>
|
||||
<item name="grid">3</item>
|
||||
</group>
|
||||
<group name="windows"/>
|
||||
<group name="search">
|
||||
<item name="options">4129280</item>
|
||||
<item name="replace">0</item>
|
||||
</group>
|
||||
<group name="vars"/>
|
||||
<group name="tools">
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
</group>
|
||||
</session>
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: "Dining Philosophers Problem" example, preemptive QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 19, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -64,7 +64,6 @@ Q_ASSERT_COMPILE(MAX_KERNEL_AWARE_CMSIS_PRI <= (0xFF >>(8-__NVIC_PRIO_BITS)));
|
||||
/* ISRs defined in this BSP ------------------------------------------------*/
|
||||
void SysTick_Handler(void);
|
||||
void GPIOPortA_IRQHandler(void);
|
||||
void assert_failed(char const *file, int line);
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static unsigned l_rnd; /* random seed */
|
||||
@ -104,7 +103,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
/* debounce the USER button... */
|
||||
btn = GPIOC->DATA_Bits[PUSH_BUTTON]; /* read the push btn */
|
||||
@ -186,7 +185,6 @@ void BSP_init(void) {
|
||||
if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */
|
||||
Q_ERROR();
|
||||
}
|
||||
QS_RESET();
|
||||
QS_OBJ_DICTIONARY(&l_SysTick_Handler);
|
||||
QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler);
|
||||
}
|
||||
@ -279,17 +277,16 @@ void QK_onIdle(void) {
|
||||
}
|
||||
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char_t const Q_ROM * const Q_ROM_VAR file, int_t line) {
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
for (;;) { /* NOTE: replace the loop with reset for final version */
|
||||
}
|
||||
void Q_onAssert(char const Q_ROM * const file, int_t line) {
|
||||
assert_failed(file, line);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
/* error routine that is called if the CMSIS library encounters an error */
|
||||
void assert_failed(char const *file, int line) {
|
||||
Q_onAssert(file, line);
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
NVIC_SystemReset(); /* perform system reset */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -73,7 +73,7 @@
|
||||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>255</CpuCode>
|
||||
<DllOpt>
|
||||
@ -120,6 +120,15 @@
|
||||
<pMon>BIN\lmidk-agdi.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>UL2CM3</Key>
|
||||
<Name>UL2CM3(-UU0101L5E -O14 -S0 -C0 -N00("ARM Cortex-M3") -D00(1BA00477) -L00(4) -FO7 -FD20000000 -FC800 -FN1 -FF0LM3S_64 -FS00 -FL010000)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
@ -280,7 +289,8 @@
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
<Key>UL2CM3</Key>
|
||||
<Name>UL2CM3(-UU0101L5E -O14 -S0 -C0 -N00("ARM Cortex-M3") -D00(1BA00477) -L00(4) -FO7 -FD20000000 -FC800 -FN1 -FF0LM3S_64 -FS00 -FL010000)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
@ -393,7 +403,7 @@
|
||||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>255</CpuCode>
|
||||
<DllOpt>
|
||||
@ -444,6 +454,11 @@
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>UL2CM3</Key>
|
||||
<Name>UL2CM3(-UU0101L5E -O14 -S0 -C0 -N00("ARM Cortex-M3") -D00(1BA00477) -L00(4) -FO7 -FD20000000 -FC800 -FN1 -FF0LM3S_64 -FS00 -FL010000)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
@ -479,7 +494,7 @@
|
||||
<aSer1>0</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
<aPa>0</aPa>
|
||||
<viewmode>1</viewmode>
|
||||
<viewmode>2</viewmode>
|
||||
<vrSel>0</vrSel>
|
||||
<aSym>0</aSym>
|
||||
<aTbox>0</aTbox>
|
||||
@ -516,8 +531,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>234</TopLine>
|
||||
<CurrentLine>251</CurrentLine>
|
||||
<TopLine>236</TopLine>
|
||||
<CurrentLine>266</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\bsp.c</PathWithFileName>
|
||||
<FilenameWithoutPath>bsp.c</FilenameWithoutPath>
|
||||
@ -676,8 +691,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</CurrentLine>
|
||||
<TopLine>175</TopLine>
|
||||
<CurrentLine>188</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\startup-qk_lm3s.s</PathWithFileName>
|
||||
<FilenameWithoutPath>startup-qk_lm3s.s</FilenameWithoutPath>
|
||||
|
@ -30,6 +30,7 @@
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>SFD\Luminary\LM3S811.SFR</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
@ -97,6 +98,7 @@
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
@ -165,10 +167,14 @@
|
||||
<Capability>1</Capability>
|
||||
<DriverSelection>4097</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>0</bUseTDR>
|
||||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\lmidk-agdi.dll</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
@ -335,7 +341,7 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>0</interw>
|
||||
<Optim>1</Optim>
|
||||
<Optim>2</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
@ -466,6 +472,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -532,6 +539,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -598,6 +606,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -673,6 +682,7 @@
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>SFD\Luminary\LM3S811.SFR</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
@ -740,6 +750,7 @@
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
@ -808,10 +819,14 @@
|
||||
<Capability>1</Capability>
|
||||
<DriverSelection>4097</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>0</bUseTDR>
|
||||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\lmidk-agdi.dll</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
@ -1109,6 +1124,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1175,6 +1191,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1241,6 +1258,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1316,6 +1334,7 @@
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>SFD\Luminary\LM3S811.SFR</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
@ -1383,6 +1402,7 @@
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
@ -1451,10 +1471,14 @@
|
||||
<Capability>1</Capability>
|
||||
<DriverSelection>4097</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>0</bUseTDR>
|
||||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\lmidk-agdi.dll</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
@ -1621,7 +1645,7 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>0</interw>
|
||||
<Optim>1</Optim>
|
||||
<Optim>2</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
@ -1752,6 +1776,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1818,6 +1843,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1884,6 +1910,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -33,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -69,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -102,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -124,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status_ = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -161,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -199,11 +227,11 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -34,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -56,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -67,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -91,7 +113,7 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
@ -100,48 +122,46 @@ static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -161,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -208,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status_ = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status_ = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -257,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -275,11 +300,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="2.3.2">
|
||||
<item name="license"></item>
|
||||
<group name="locked"/>
|
||||
<group name="settings">
|
||||
<item name="tabs">1</item>
|
||||
<item name="windows">0</item>
|
||||
<item name="grid">3</item>
|
||||
</group>
|
||||
<group name="windows"/>
|
||||
<group name="search">
|
||||
<item name="options">4129280</item>
|
||||
<item name="replace">0</item>
|
||||
</group>
|
||||
<group name="vars"/>
|
||||
<group name="tools">
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
</group>
|
||||
</session>
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: "Dining Philosophers Problem" example, preemptive QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 19, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -66,7 +66,6 @@ Q_ASSERT_COMPILE(MAX_KERNEL_AWARE_CMSIS_PRI <= (0xFF >>(8-__NVIC_PRIO_BITS)));
|
||||
/* ISRs defined in this BSP ------------------------------------------------*/
|
||||
void SysTick_Handler(void);
|
||||
void GPIOPortA_IRQHandler(void);
|
||||
void assert_failed(char const *file, int line);
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static unsigned l_rnd; /* random seed */
|
||||
@ -110,7 +109,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
/* debounce the SW1 button... */
|
||||
btn = GPIOF->DATA_Bits[USR_SW1]; /* read the push btn */
|
||||
@ -203,7 +202,6 @@ void BSP_init(void) {
|
||||
if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */
|
||||
Q_ERROR();
|
||||
}
|
||||
QS_RESET();
|
||||
QS_OBJ_DICTIONARY(&l_SysTick_Handler);
|
||||
QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler);
|
||||
}
|
||||
@ -301,17 +299,16 @@ void QK_onIdle(void) {
|
||||
}
|
||||
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
for (;;) { /* NOTE: replace the loop with reset for final version */
|
||||
}
|
||||
void Q_onAssert(char const Q_ROM * const file, int_t line) {
|
||||
assert_failed(file, line);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
/* error routine that is called if the CMSIS library encounters an error */
|
||||
void assert_failed(char const *file, int line) {
|
||||
Q_onAssert(file, line);
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
ROM_SysCtlReset(); /* reset the system */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
16
examples/arm-cm/qk/arm_keil/dpp-qk_ek-tm4c123gxl/dpp-qk.sct
Normal file
16
examples/arm-cm/qk/arm_keil/dpp-qk_ek-tm4c123gxl/dpp-qk.sct
Normal file
@ -0,0 +1,16 @@
|
||||
; *************************************************************
|
||||
; *** Scatter-Loading Description File generated by uVision ***
|
||||
; *************************************************************
|
||||
|
||||
LR_IROM1 0x00000000 0x00040000 { ; load region size_region
|
||||
ER_IROM1 0x00000000 0x00040000 { ; load address = execution address
|
||||
*.o (RESET, +FIRST)
|
||||
*(InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
}
|
||||
RW_IRAM1 0x20000000 0x00008000 { ; RW data
|
||||
*.o (STACK, +FIRST)
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +137,15 @@
|
||||
<pMon>BIN\lmidk-agdi.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>UL2CM3</Key>
|
||||
<Name>UL2CM3(-O207 -S0 -C0 -FO7 -FD20000000 -FC800 -FN1 -FF0TM4C123_256 -FS00 -FL040000)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
@ -574,8 +583,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>262</TopLine>
|
||||
<CurrentLine>279</CurrentLine>
|
||||
<TopLine>273</TopLine>
|
||||
<CurrentLine>278</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\bsp.c</PathWithFileName>
|
||||
<FilenameWithoutPath>bsp.c</FilenameWithoutPath>
|
||||
@ -670,8 +679,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>0</TopLine>
|
||||
<CurrentLine>0</CurrentLine>
|
||||
<TopLine>274</TopLine>
|
||||
<CurrentLine>279</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\startup-qk_tm4c.s</PathWithFileName>
|
||||
<FilenameWithoutPath>startup-qk_tm4c.s</FilenameWithoutPath>
|
||||
|
@ -30,6 +30,7 @@
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>SFD\Luminary\LM4F120H5QR.SFR</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
@ -97,6 +98,7 @@
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
@ -165,10 +167,14 @@
|
||||
<Capability>1</Capability>
|
||||
<DriverSelection>4097</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>0</bUseTDR>
|
||||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\lmidk-agdi.dll</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
@ -371,7 +377,7 @@
|
||||
</VariousControls>
|
||||
</Aads>
|
||||
<LDads>
|
||||
<umfTarg>1</umfTarg>
|
||||
<umfTarg>0</umfTarg>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<noStLib>0</noStLib>
|
||||
@ -379,7 +385,7 @@
|
||||
<useFile>0</useFile>
|
||||
<TextAddressRange>0x00000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<ScatterFile>dpp-qk.sct</ScatterFile>
|
||||
<ScatterFile>.\dpp-qk.sct</ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
<Misc>--entry Reset_Handler</Misc>
|
||||
@ -446,6 +452,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -512,6 +519,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -578,6 +586,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -653,6 +662,7 @@
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>SFD\Luminary\LM4F120H5QR.SFR</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
@ -720,6 +730,7 @@
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
@ -792,6 +803,10 @@
|
||||
<Flash2>BIN\lmidk-agdi.dll</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
@ -1069,6 +1084,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1135,6 +1151,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1201,6 +1218,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1276,6 +1294,7 @@
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>SFD\Luminary\LM4F120H5QR.SFR</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
@ -1343,6 +1362,7 @@
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
@ -1415,6 +1435,10 @@
|
||||
<Flash2>BIN\lmidk-agdi.dll</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
@ -1692,6 +1716,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1758,6 +1783,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
@ -1824,6 +1850,7 @@
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<GroupArmAds>
|
||||
<Cads>
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -33,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -69,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -102,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -124,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status_ = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -161,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -199,11 +227,11 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ Heap EQU 0x00000000
|
||||
; Allocate space for the stack.
|
||||
;
|
||||
;******************************************************************************
|
||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||
AREA STACK, READWRITE, ALIGN=3
|
||||
StackMem
|
||||
SPACE Stack
|
||||
__initial_sp
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -34,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -56,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -67,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -91,7 +113,7 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
@ -100,48 +122,46 @@ static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -161,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -208,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status_ = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status_ = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -257,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -275,11 +300,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="2.3.2">
|
||||
<item name="license"></item>
|
||||
<group name="locked"/>
|
||||
<group name="settings">
|
||||
<item name="tabs">1</item>
|
||||
<item name="windows">0</item>
|
||||
<item name="grid">3</item>
|
||||
</group>
|
||||
<group name="windows"/>
|
||||
<group name="search">
|
||||
<item name="options">4129280</item>
|
||||
<item name="replace">0</item>
|
||||
</group>
|
||||
<group name="vars"/>
|
||||
<group name="tools">
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
</group>
|
||||
</session>
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: "Fly 'n' Shoot" game example, preemptive QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 19, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -110,7 +110,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
QF_PUBLISH(&tickEvt, &l_SysTick_Handler); /* publish to all subscribers */
|
||||
|
||||
QK_ISR_EXIT(); /* infrom QK about exiting an ISR */
|
||||
@ -338,18 +338,16 @@ void QK_onIdle(void) {
|
||||
}
|
||||
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
QS_ASSERTION(file, line);
|
||||
for (;;) { /* NOTE: replace the loop with reset for final version */
|
||||
}
|
||||
void Q_onAssert(char const Q_ROM * const file, int_t line) {
|
||||
assert_failed(file, line);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
/* error routine that is called if the CMSIS library encounters an error */
|
||||
void assert_failed(char const *file, int line) {
|
||||
Q_onAssert(file, line);
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
NVIC_SystemReset(); /* perform system reset */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@ -435,8 +433,6 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
QS_FILTER_OFF(QS_QF_ISR_ENTRY);
|
||||
QS_FILTER_OFF(QS_QF_ISR_EXIT);
|
||||
|
||||
QS_RESET();
|
||||
|
||||
return (uint8_t)1; /* return success */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
|
@ -114,22 +114,22 @@ enum GameBitmapIds {
|
||||
};
|
||||
|
||||
/* active objects' "constructors" */
|
||||
/* @(/2/9) .................................................................*/
|
||||
/* @(/2/8) .................................................................*/
|
||||
void Tunnel_ctor(void);
|
||||
|
||||
/* @(/2/10) ................................................................*/
|
||||
/* @(/2/9) .................................................................*/
|
||||
void Ship_ctor(void);
|
||||
|
||||
/* @(/2/11) ................................................................*/
|
||||
/* @(/2/10) ................................................................*/
|
||||
void Missile_ctor(void);
|
||||
|
||||
|
||||
/* instantiation of the Mines orthogonal components */
|
||||
/* @(/2/12) ................................................................*/
|
||||
QHsm * Mine1_ctor(uint8_t id);
|
||||
/* @(/2/11) ................................................................*/
|
||||
QMsm * Mine1_ctor(uint8_t id);
|
||||
|
||||
/* @(/2/13) ................................................................*/
|
||||
QHsm * Mine2_ctor(uint8_t id);
|
||||
/* @(/2/12) ................................................................*/
|
||||
QMsm * Mine2_ctor(uint8_t id);
|
||||
|
||||
|
||||
/* opaque pointers to active objects in the application */
|
||||
@ -141,7 +141,7 @@ extern QActive * const AO_Missile;
|
||||
|
||||
|
||||
/* helper function for all AOs */
|
||||
/* @(/2/8) .................................................................*/
|
||||
/* @(/2/13) ................................................................*/
|
||||
uint8_t do_bitmaps_overlap(
|
||||
uint8_t bmp_id1,
|
||||
uint8_t x1,
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.2">
|
||||
<documentation>"Fly 'n' Shoot" game model from Chapters 1 & 9 of PSiCC2</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>"Fly 'n' Shoot" game model from Chapters 1 & 9 of PSiCC2
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="ObjectPosEvt" superclass="qpc::QEvt">
|
||||
@ -20,13 +22,13 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Tunnel" superclass="qpc::QActive">
|
||||
<class name="Tunnel" superclass="qpc::QMActive">
|
||||
<documentation>Tunnel Active Object</documentation>
|
||||
<attribute name="blinkTimeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="screenTimeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mines[GAME_MINES_MAX]" type="QHsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine1_pool[GAME_MINES_MAX]" type="QHsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine2_pool[GAME_MINES_MAX]" type="QHsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mines[GAME_MINES_MAX]" type="QMsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine1_pool[GAME_MINES_MAX]" type="QMsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine2_pool[GAME_MINES_MAX]" type="QMsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="blink_ctr" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="last_mine_x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="last_mine_y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -100,7 +102,7 @@ if ((me->last_mine_x + GAME_MINES_DIST_MIN < GAME_SCREEN_WIDTH)
|
||||
{
|
||||
uint8_t n;
|
||||
for (n = 0U; n < Q_DIM(me->mines); ++n) { /*look for disabled mines */
|
||||
if (me->mines[n] == (QHsm *)0) {
|
||||
if (me->mines[n] == (QMsm *)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -127,7 +129,7 @@ if ((me->last_mine_x + GAME_MINES_DIST_MIN < GAME_SCREEN_WIDTH)
|
||||
ope.super.sig = MINE_PLANT_SIG;
|
||||
ope.x = me->last_mine_x;
|
||||
ope.y = me->last_mine_y;
|
||||
QHsm_dispatch(me->mines[n], (QEvt *)&ope); /* direct dispatch */
|
||||
QMSM_DISPATCH(me->mines[n], (QEvt *)&ope); /* direct dispatch */
|
||||
}
|
||||
}
|
||||
</code>
|
||||
@ -163,8 +165,8 @@ for (x = 0U; x < w; ++x) {
|
||||
<code>uint8_t n;
|
||||
|
||||
for (n = 0U; n < GAME_MINES_MAX; ++n) {
|
||||
if (me->mines[n] != (QHsm *)0) { /* is the mine used? */
|
||||
QHsm_dispatch(me->mines[n], e);
|
||||
if (me->mines[n] != (QMsm *)0) { /* is the mine used? */
|
||||
QMSM_DISPATCH(me->mines[n], e);
|
||||
}
|
||||
}</code>
|
||||
</operation>
|
||||
@ -197,8 +199,8 @@ return (uint8_t)0;</code>
|
||||
<initial target="../1/2">
|
||||
<action>uint8_t n;
|
||||
for (n = 0U; n < GAME_MINES_MAX; ++n) {
|
||||
QHsm_init(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
|
||||
QHsm_init(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
|
||||
QMSM_INIT(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
|
||||
QMSM_INIT(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
|
||||
}
|
||||
randomSeed(1234); /* seed the pseudo-random generator */
|
||||
|
||||
@ -241,8 +243,8 @@ QS_SIG_DICTIONARY(SCORE_SIG, &l_tunnel);
|
||||
<state name="active">
|
||||
<tran trig="MINE_DISABLED">
|
||||
<action>Q_ASSERT((Q_EVT_CAST(MineEvt)->id < GAME_MINES_MAX)
|
||||
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QHsm *)0));
|
||||
me->mines[Q_EVT_CAST(MineEvt)->id] = (QHsm *)0;</action>
|
||||
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QMsm *)0));
|
||||
me->mines[Q_EVT_CAST(MineEvt)->id] = (QMsm *)0;</action>
|
||||
<tran_glyph conn="2,9,3,-1,14">
|
||||
<action box="0,-2,14,2"/>
|
||||
</tran_glyph>
|
||||
@ -253,10 +255,9 @@ me->mines[Q_EVT_CAST(MineEvt)->id] = (QHsm *)0;</action>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<state name="show_logo">
|
||||
<entry>QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*5U); /* 5 sec timeout */
|
||||
<entry>QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString(0U, 0U, " Quantum LeAps ");
|
||||
BSP_drawNString(0U, 1U, "state-machine.co");</entry>
|
||||
@ -306,10 +307,9 @@ me->minimal_gap = GAME_SCREEN_HEIGHT - 3U;
|
||||
memset(l_walls, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
|
||||
QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*20U); /* 20s timeout */
|
||||
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*20U, 0U);
|
||||
|
||||
me->blink_ctr = 0U; /* init the blink counter */</entry>
|
||||
<exit>QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
@ -457,10 +457,9 @@ BSP_drawNString((GAME_SCREEN_WIDTH - 6U*10U)/2U + 6U*6U, 1U, str);</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="game_over">
|
||||
<entry>QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*5U); /* 5 sec timeout */
|
||||
<entry>QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString((GAME_SCREEN_WIDTH - 6U*9U)/2U, 0U, "Game Over");</entry>
|
||||
<exit>QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
@ -499,8 +498,7 @@ BSP_drawNString((GAME_SCREEN_WIDTH - 6U*9U)/2, 0U,
|
||||
</tran>
|
||||
<state name="screen_saver_hide">
|
||||
<entry>BSP_displayOff(); /* power down the display */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*3U); /* 3s timeout */</entry>
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*3U, 0U);</entry>
|
||||
<exit>QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
BSP_displayOn(); /* power up the display */</exit>
|
||||
<tran trig="SCREEN_TIMEOUT" target="../../3">
|
||||
@ -523,8 +521,7 @@ Tunnel_addImageAt(me,
|
||||
(uint8_t)(rnd % (GAME_SCREEN_WIDTH - 55U)),
|
||||
(int8_t) (rnd % (GAME_SCREEN_HEIGHT - 8U)));
|
||||
BSP_drawBitmap(l_frame);
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/3U); /* 1/3 sec timeout */</entry>
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC/2U, 0U);</entry>
|
||||
<exit>QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
/* clear the screen frame buffer */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
@ -557,7 +554,7 @@ QF_stop(); /* stop QF and cleanup */</entry>
|
||||
<state_diagram size="68,94"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Ship" superclass="qpc::QActive">
|
||||
<class name="Ship" superclass="qpc::QMActive">
|
||||
<documentation>Ship Active Object</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -701,7 +698,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me);</action>
|
||||
<state_diagram size="41,67"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Missile" superclass="qpc::QActive">
|
||||
<class name="Missile" superclass="qpc::QMActive">
|
||||
<documentation>Missile Active Object</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -811,7 +808,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
|
||||
<state_diagram size="46,55"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Mine1" superclass="qpc::QHsm">
|
||||
<class name="Mine1" superclass="qpc::QMsm">
|
||||
<documentation>The Mine1 orthogonal component</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -975,7 +972,7 @@ QACTIVE_POST(AO_Missile, (QEvt *)&mine1_destroyed, me);</action>
|
||||
<state_diagram size="53,68"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Mine2" superclass="qpc::QHsm">
|
||||
<class name="Mine2" superclass="qpc::QMsm">
|
||||
<documentation>The Mine2 orthogonal component</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -1150,6 +1147,48 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
|
||||
<attribute name="AO_Tunnel" type="QActive * const" visibility="0x00" properties="0x00"/>
|
||||
<attribute name="AO_Ship" type="QActive * const" visibility="0x00" properties="0x00"/>
|
||||
<attribute name="AO_Missile" type="QActive * const" visibility="0x00" properties="0x00"/>
|
||||
<operation name="Tunnel_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>uint8_t n;
|
||||
Tunnel *me = &l_tunnel;
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Tunnel_initial));
|
||||
QTimeEvt_ctorX(&me->blinkTimeEvt, &me->super, BLINK_TIMEOUT_SIG, 0U);
|
||||
QTimeEvt_ctorX(&me->screenTimeEvt, &me->super, SCREEN_TIMEOUT_SIG, 0U);
|
||||
for (n = 0; n < GAME_MINES_MAX; ++n) {
|
||||
me->mine1_pool[n] = Mine1_ctor(n); /* instantiate Mine1 in the pool */
|
||||
me->mine2_pool[n] = Mine2_ctor(n); /* instantiate Mine2 in the pool */
|
||||
me->mines[n] = (QMsm *)0; /* mine 'n' is unused */
|
||||
}
|
||||
me->last_mine_x = 0; /* the last mine at the right edge of the tunnel */
|
||||
me->last_mine_y = 0;</code>
|
||||
</operation>
|
||||
<operation name="Ship_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Ship *me = &l_ship;
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Ship_initial));
|
||||
me->x = GAME_SHIP_X;
|
||||
me->y = GAME_SHIP_Y;</code>
|
||||
</operation>
|
||||
<operation name="Missile_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Missile *me = &l_missile;
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Missile_initial));</code>
|
||||
</operation>
|
||||
<operation name="Mine1_ctor" type="QMsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine1 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine1[id];
|
||||
/* superclass' ctor */
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine1_initial));
|
||||
return (QMsm *)me;</code>
|
||||
</operation>
|
||||
<operation name="Mine2_ctor" type="QMsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine2 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine2[id];
|
||||
/* superclass' ctor */
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial));
|
||||
return (QMsm *)me;</code>
|
||||
</operation>
|
||||
<operation name="do_bitmaps_overlap" type="uint8_t" visibility="0x00" properties="0x00">
|
||||
<parameter name="bmp_id1" type="uint8_t"/>
|
||||
<parameter name="x1" type="uint8_t"/>
|
||||
@ -1158,48 +1197,6 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
|
||||
<parameter name="x2" type="uint8_t"/>
|
||||
<parameter name="y2" type="uint8_t"/>
|
||||
</operation>
|
||||
<operation name="Tunnel_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>uint8_t n;
|
||||
Tunnel *me = &l_tunnel;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Tunnel_initial);
|
||||
QTimeEvt_ctor(&me->blinkTimeEvt, BLINK_TIMEOUT_SIG);
|
||||
QTimeEvt_ctor(&me->screenTimeEvt, SCREEN_TIMEOUT_SIG);
|
||||
for (n = 0; n < GAME_MINES_MAX; ++n) {
|
||||
me->mine1_pool[n] = Mine1_ctor(n); /* instantiate Mine1 in the pool */
|
||||
me->mine2_pool[n] = Mine2_ctor(n); /* instantiate Mine2 in the pool */
|
||||
me->mines[n] = (QHsm *)0; /* mine 'n' is unused */
|
||||
}
|
||||
me->last_mine_x = 0; /* the last mine at the right edge of the tunnel */
|
||||
me->last_mine_y = 0;</code>
|
||||
</operation>
|
||||
<operation name="Ship_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Ship *me = &l_ship;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Ship_initial);
|
||||
me->x = GAME_SHIP_X;
|
||||
me->y = GAME_SHIP_Y;</code>
|
||||
</operation>
|
||||
<operation name="Missile_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Missile *me = &l_missile;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Missile_initial);</code>
|
||||
</operation>
|
||||
<operation name="Mine1_ctor" type="QHsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine1 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine1[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine1_initial);
|
||||
return (QHsm *)me;</code>
|
||||
</operation>
|
||||
<operation name="Mine2_ctor" type="QHsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine2 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine2[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine2_initial);
|
||||
return (QHsm *)me;</code>
|
||||
</operation>
|
||||
</package>
|
||||
<directory name=".">
|
||||
<file name="game.h">
|
||||
@ -1658,17 +1655,17 @@ int main() {
|
||||
QS_SIG_DICTIONARY(GAME_OVER_SIG, (void *)0);
|
||||
|
||||
/* start the active objects... */
|
||||
QActive_start(AO_Missile,
|
||||
QACTIVE_START(AO_Missile,
|
||||
1U, /* priority */
|
||||
l_missileQueueSto, Q_DIM(l_missileQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Ship,
|
||||
QACTIVE_START(AO_Ship,
|
||||
2U, /* priority */
|
||||
l_shipQueueSto, Q_DIM(l_shipQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Tunnel,
|
||||
QACTIVE_START(AO_Tunnel,
|
||||
3U, /* priority */
|
||||
l_tunnelQueueSto, Q_DIM(l_tunnelQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
|
@ -62,17 +62,17 @@ int main() {
|
||||
QS_SIG_DICTIONARY(GAME_OVER_SIG, (void *)0);
|
||||
|
||||
/* start the active objects... */
|
||||
QActive_start(AO_Missile,
|
||||
QACTIVE_START(AO_Missile,
|
||||
1U, /* priority */
|
||||
l_missileQueueSto, Q_DIM(l_missileQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Ship,
|
||||
QACTIVE_START(AO_Ship,
|
||||
2U, /* priority */
|
||||
l_shipQueueSto, Q_DIM(l_shipQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Tunnel,
|
||||
QACTIVE_START(AO_Tunnel,
|
||||
3U, /* priority */
|
||||
l_tunnelQueueSto, Q_DIM(l_tunnelQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/3) .................................................................*/
|
||||
typedef struct Mine1Tag {
|
||||
/* protected: */
|
||||
QHsm super;
|
||||
QMsm super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -37,10 +37,32 @@ typedef struct Mine1Tag {
|
||||
|
||||
/* protected: */
|
||||
static QState Mine1_initial(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_unused(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_used(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_exploding(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_planted(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_unused (Mine1 * const me, QEvt const * const e);
|
||||
static QMState const Mine1_unused_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine1_unused),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine1_used (Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_used_x(Mine1 * const me);
|
||||
static QMState const Mine1_used_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine1_used),
|
||||
Q_ACTION_CAST(&Mine1_used_x)
|
||||
};
|
||||
static QState Mine1_exploding (Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_exploding_e(Mine1 * const me);
|
||||
static QMState const Mine1_exploding_s = {
|
||||
&Mine1_used_s,
|
||||
Q_STATE_CAST(&Mine1_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine1_planted (Mine1 * const me, QEvt const * const e);
|
||||
static QMState const Mine1_planted_s = {
|
||||
&Mine1_used_s,
|
||||
Q_STATE_CAST(&Mine1_planted),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
|
||||
/* local objects -----------------------------------------------------------*/
|
||||
@ -50,14 +72,14 @@ static Mine1 l_mine1[GAME_MINES_MAX]; /* a pool of type-1 mines */
|
||||
#define MINE_ID(me_) ((uint8_t)((me_) - l_mine1))
|
||||
|
||||
/* Mine1 class definition --------------------------------------------------*/
|
||||
/* @(/2/12) ................................................................*/
|
||||
QHsm * Mine1_ctor(uint8_t id) {
|
||||
/* @(/2/11) ................................................................*/
|
||||
QMsm * Mine1_ctor(uint8_t id) {
|
||||
Mine1 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine1[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine1_initial);
|
||||
return (QHsm *)me;
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine1_initial));
|
||||
return (QMsm *)me;
|
||||
}
|
||||
/* @(/2/3) .................................................................*/
|
||||
/* @(/2/3/3) ...............................................................*/
|
||||
@ -88,7 +110,7 @@ static QState Mine1_initial(Mine1 * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(MISSILE_IMG_SIG, me);
|
||||
|
||||
(void)e; /* avoid the "unreferenced parameter" warning */
|
||||
return Q_TRAN(&Mine1_unused);
|
||||
return QM_INITIAL(&Mine1_unused_s, QMsm_emptyAction_);
|
||||
}
|
||||
/* @(/2/3/3/1) .............................................................*/
|
||||
static QState Mine1_unused(Mine1 * const me, QEvt const * const e) {
|
||||
@ -98,51 +120,51 @@ static QState Mine1_unused(Mine1 * const me, QEvt const * const e) {
|
||||
case MINE_PLANT_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_TRAN(&Mine1_planted);
|
||||
status_ = QM_TRAN(&Mine1_planted_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/3/3/2) .............................................................*/
|
||||
static QState Mine1_used_x(Mine1 * const me) {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
return QM_EXIT(&Mine1_used_s);
|
||||
}
|
||||
static QState Mine1_used(Mine1 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/3/3/2) */
|
||||
case Q_EXIT_SIG: {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/3/3/2/0) */
|
||||
case MINE_RECYCLE_SIG: {
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/3/3/2/1) ...........................................................*/
|
||||
static QState Mine1_exploding_e(Mine1 * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Mine1_exploding_s);
|
||||
}
|
||||
static QState Mine1_exploding(Mine1 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/3/3/2/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/3/3/2/1/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/3/3/2/1/0/0) */
|
||||
@ -157,16 +179,20 @@ static QState Mine1_exploding(Mine1 * const me, QEvt const * const e) {
|
||||
oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */
|
||||
oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/3/3/2/1/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine1_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -188,11 +214,15 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
oie->y = me->y;
|
||||
oie->bmp = MINE1_BMP;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/3/3/2/2/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -203,6 +233,10 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/3/3/2/2/1/0) */
|
||||
if (do_bitmaps_overlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static MineEvt const mine1_hit = {
|
||||
{ HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
|
||||
1U /* type of the mine (1 for Mine type-1) */
|
||||
@ -210,10 +244,10 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);
|
||||
/* go straight to 'disabled' and let the Ship do
|
||||
* the exploding */
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -224,20 +258,24 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/3/3/2/2/2/0) */
|
||||
if (do_bitmaps_overlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static ScoreEvt const mine1_destroyed = {
|
||||
{ DESTROYED_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
|
||||
25U /* score for destroying Mine type-1 */
|
||||
};
|
||||
QACTIVE_POST(AO_Missile, (QEvt *)&mine1_destroyed, me);
|
||||
status_ = Q_TRAN(&Mine1_exploding);
|
||||
status_ = QM_TRAN(&Mine1_exploding_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine1_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/4) .................................................................*/
|
||||
typedef struct Mine2Tag {
|
||||
/* protected: */
|
||||
QHsm super;
|
||||
QMsm super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -37,10 +37,32 @@ typedef struct Mine2Tag {
|
||||
|
||||
/* protected: */
|
||||
static QState Mine2_initial(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_unused(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_used(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_planted(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_unused (Mine2 * const me, QEvt const * const e);
|
||||
static QMState const Mine2_unused_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine2_unused),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine2_used (Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_used_x(Mine2 * const me);
|
||||
static QMState const Mine2_used_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine2_used),
|
||||
Q_ACTION_CAST(&Mine2_used_x)
|
||||
};
|
||||
static QState Mine2_planted (Mine2 * const me, QEvt const * const e);
|
||||
static QMState const Mine2_planted_s = {
|
||||
&Mine2_used_s,
|
||||
Q_STATE_CAST(&Mine2_planted),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine2_exploding (Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_exploding_e(Mine2 * const me);
|
||||
static QMState const Mine2_exploding_s = {
|
||||
&Mine2_used_s,
|
||||
Q_STATE_CAST(&Mine2_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
|
||||
/* local objects -----------------------------------------------------------*/
|
||||
@ -50,14 +72,14 @@ static Mine2 l_mine2[GAME_MINES_MAX]; /* a pool of type-2 mines */
|
||||
#define MINE_ID(me_) ((uint8_t)((me_) - l_mine2))
|
||||
|
||||
/* Mine2 class definition --------------------------------------------------*/
|
||||
/* @(/2/13) ................................................................*/
|
||||
QHsm * Mine2_ctor(uint8_t id) {
|
||||
/* @(/2/12) ................................................................*/
|
||||
QMsm * Mine2_ctor(uint8_t id) {
|
||||
Mine2 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine2[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine2_initial);
|
||||
return (QHsm *)me;
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial));
|
||||
return (QMsm *)me;
|
||||
}
|
||||
/* @(/2/4) .................................................................*/
|
||||
/* @(/2/4/3) ...............................................................*/
|
||||
@ -90,7 +112,7 @@ static QState Mine2_initial(Mine2 * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(MISSILE_IMG_SIG, me);
|
||||
|
||||
(void)e; /* avoid the "unreferenced parameter" warning */
|
||||
return Q_TRAN(&Mine2_unused);
|
||||
return QM_INITIAL(&Mine2_unused_s, QMsm_emptyAction_);
|
||||
}
|
||||
/* @(/2/4/3/1) .............................................................*/
|
||||
static QState Mine2_unused(Mine2 * const me, QEvt const * const e) {
|
||||
@ -100,36 +122,38 @@ static QState Mine2_unused(Mine2 * const me, QEvt const * const e) {
|
||||
case MINE_PLANT_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_TRAN(&Mine2_planted);
|
||||
status_ = QM_TRAN(&Mine2_planted_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/4/3/2) .............................................................*/
|
||||
static QState Mine2_used_x(Mine2 * const me) {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
return QM_EXIT(&Mine2_used_s);
|
||||
}
|
||||
static QState Mine2_used(Mine2 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/4/3/2) */
|
||||
case Q_EXIT_SIG: {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/4/3/2/0) */
|
||||
case MINE_RECYCLE_SIG: {
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -151,11 +175,15 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
oie->y = me->y;
|
||||
oie->bmp = MINE2_BMP;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/4/3/2/1/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -166,6 +194,10 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/4/3/2/1/1/0) */
|
||||
if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static MineEvt const mine1_hit = {
|
||||
{ HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
|
||||
2U /* type of the mine (2 for Mine type-2) */
|
||||
@ -173,10 +205,10 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);
|
||||
/* go straight to 'disabled' and let the Ship do
|
||||
* the exploding */
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -187,6 +219,10 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/4/3/2/1/2/0) */
|
||||
if (do_bitmaps_overlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
/* NOTE: Mine type-2 is nastier than Mine type-1.
|
||||
* The type-2 mine can hit the Ship with any of its
|
||||
* "tentacles". However, it can be destroyed by the
|
||||
@ -198,30 +234,28 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
45U /* score for destroying Mine type-2 */
|
||||
};
|
||||
QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me);
|
||||
status_ = Q_TRAN(&Mine2_exploding);
|
||||
status_ = QM_TRAN(&Mine2_exploding_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine2_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/4/3/2/2) ...........................................................*/
|
||||
static QState Mine2_exploding_e(Mine2 * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Mine2_exploding_s);
|
||||
}
|
||||
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/4/3/2/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/4/3/2/2/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/4/3/2/2/0/0) */
|
||||
@ -236,16 +270,20 @@ static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) {
|
||||
oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */
|
||||
oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/4/3/2/2/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine2_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
/* @(/2/2) .................................................................*/
|
||||
typedef struct MissileTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -35,9 +35,25 @@ typedef struct MissileTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Missile_initial(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_armed(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_flying(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_exploding(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_armed (Missile * const me, QEvt const * const e);
|
||||
static QMState const Missile_armed_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Missile_armed),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Missile_flying (Missile * const me, QEvt const * const e);
|
||||
static QMState const Missile_flying_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Missile_flying),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Missile_exploding (Missile * const me, QEvt const * const e);
|
||||
static QState Missile_exploding_e(Missile * const me);
|
||||
static QMState const Missile_exploding_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Missile_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
static Missile l_missile; /* the sole instance of the Missile active object */
|
||||
|
||||
@ -45,10 +61,10 @@ static Missile l_missile; /* the sole instance of the Missile active object */
|
||||
QActive * const AO_Missile = (QActive *)&l_missile; /* opaque pointer */
|
||||
|
||||
/* Active object definition ------------------------------------------------*/
|
||||
/* @(/2/11) ................................................................*/
|
||||
/* @(/2/10) ................................................................*/
|
||||
void Missile_ctor(void) {
|
||||
Missile *me = &l_missile;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Missile_initial);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Missile_initial));
|
||||
}
|
||||
/* @(/2/2) .................................................................*/
|
||||
/* @(/2/2/3) ...............................................................*/
|
||||
@ -67,7 +83,7 @@ static QState Missile_initial(Missile * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(MISSILE_FIRE_SIG, &l_missile); /* local signals */
|
||||
QS_SIG_DICTIONARY(HIT_WALL_SIG, &l_missile);
|
||||
QS_SIG_DICTIONARY(DESTROYED_MINE_SIG, &l_missile);
|
||||
return Q_TRAN(&Missile_armed);
|
||||
return QM_INITIAL(&Missile_armed_s, QMsm_emptyAction_);
|
||||
}
|
||||
/* @(/2/2/3/1) .............................................................*/
|
||||
static QState Missile_armed(Missile * const me, QEvt const * const e) {
|
||||
@ -77,11 +93,11 @@ static QState Missile_armed(Missile * const me, QEvt const * const e) {
|
||||
case MISSILE_FIRE_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_TRAN(&Missile_flying);
|
||||
status_ = QM_TRAN(&Missile_flying_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -103,42 +119,44 @@ static QState Missile_flying(Missile * const me, QEvt const * const e) {
|
||||
oie->y = me->y;
|
||||
oie->bmp = MISSILE_BMP;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/2/3/2/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Missile_armed);
|
||||
status_ = QM_TRAN(&Missile_armed_s, QMsm_emptyAction_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* @(/2/2/3/2/1) */
|
||||
case HIT_WALL_SIG: {
|
||||
status_ = Q_TRAN(&Missile_exploding);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Missile_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Missile_exploding_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/2/3/2/2) */
|
||||
case DESTROYED_MINE_SIG: {
|
||||
QACTIVE_POST(AO_Ship, e, me);
|
||||
status_ = Q_TRAN(&Missile_armed);
|
||||
status_ = QM_TRAN(&Missile_armed_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/2/3/3) .............................................................*/
|
||||
static QState Missile_exploding_e(Missile * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Missile_exploding_s);
|
||||
}
|
||||
static QState Missile_exploding(Missile * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/2/3/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/2/3/3/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/2/3/3/0/0) */
|
||||
@ -154,16 +172,16 @@ static QState Missile_exploding(Missile * const me, QEvt const * const e) {
|
||||
oie->y = (int8_t)((int)me->y - 4U); /* y-pos */
|
||||
oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/2/3/3/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Missile_armed);
|
||||
status_ = QM_TRAN(&Missile_armed_s, QMsm_emptyAction_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct ShipTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -39,10 +39,33 @@ typedef struct ShipTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Ship_initial(Ship * const me, QEvt const * const e);
|
||||
static QState Ship_active(Ship * const me, QEvt const * const e);
|
||||
static QState Ship_parked(Ship * const me, QEvt const * const e);
|
||||
static QState Ship_flying(Ship * const me, QEvt const * const e);
|
||||
static QState Ship_exploding(Ship * const me, QEvt const * const e);
|
||||
static QState Ship_active (Ship * const me, QEvt const * const e);
|
||||
static QState Ship_active_i(Ship * const me);
|
||||
static QMState const Ship_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Ship_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Ship_parked (Ship * const me, QEvt const * const e);
|
||||
static QMState const Ship_parked_s = {
|
||||
&Ship_active_s,
|
||||
Q_STATE_CAST(&Ship_parked),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Ship_flying (Ship * const me, QEvt const * const e);
|
||||
static QState Ship_flying_e(Ship * const me);
|
||||
static QMState const Ship_flying_s = {
|
||||
&Ship_active_s,
|
||||
Q_STATE_CAST(&Ship_flying),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Ship_exploding (Ship * const me, QEvt const * const e);
|
||||
static QState Ship_exploding_e(Ship * const me);
|
||||
static QMState const Ship_exploding_s = {
|
||||
&Ship_active_s,
|
||||
Q_STATE_CAST(&Ship_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
|
||||
/* local objects -----------------------------------------------------------*/
|
||||
@ -52,10 +75,10 @@ static Ship l_ship; /* the sole instance of the Ship active object */
|
||||
QActive * const AO_Ship = (QActive *)&l_ship; /* opaque pointer */
|
||||
|
||||
/* Active object definition ------------------------------------------------*/
|
||||
/* @(/2/10) ................................................................*/
|
||||
/* @(/2/9) .................................................................*/
|
||||
void Ship_ctor(void) {
|
||||
Ship *me = &l_ship;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Ship_initial);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Ship_initial));
|
||||
me->x = GAME_SHIP_X;
|
||||
me->y = GAME_SHIP_Y;
|
||||
}
|
||||
@ -63,6 +86,10 @@ void Ship_ctor(void) {
|
||||
/* @(/2/1/4) ...............................................................*/
|
||||
/* @(/2/1/4/0) */
|
||||
static QState Ship_initial(Ship * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Ship_active_i),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
(void)e; /* avoid the compiler warning 'usused parameter' */
|
||||
QActive_subscribe((QActive *)me, TIME_TICK_SIG);
|
||||
QActive_subscribe((QActive *)me, PLAYER_TRIGGER_SIG);
|
||||
@ -80,26 +107,24 @@ static QState Ship_initial(Ship * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(HIT_WALL_SIG, &l_ship);
|
||||
QS_SIG_DICTIONARY(HIT_MINE_SIG, &l_ship);
|
||||
QS_SIG_DICTIONARY(DESTROYED_MINE_SIG, &l_ship);
|
||||
return Q_TRAN(&Ship_active);
|
||||
return QM_INITIAL(&Ship_active_s, act_);
|
||||
}
|
||||
/* @(/2/1/4/1) .............................................................*/
|
||||
static QState Ship_active_i(Ship * const me) {
|
||||
return QM_INITIAL(&Ship_parked_s, QMsm_emptyAction_);
|
||||
}
|
||||
static QState Ship_active(Ship * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/4/1/0) */
|
||||
case Q_INIT_SIG: {
|
||||
status_ = Q_TRAN(&Ship_parked);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/1) */
|
||||
case PLAYER_SHIP_MOVE_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -111,30 +136,32 @@ static QState Ship_parked(Ship * const me, QEvt const * const e) {
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/4/1/2/0) */
|
||||
case TAKE_OFF_SIG: {
|
||||
status_ = Q_TRAN(&Ship_flying);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Ship_flying_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Ship_flying_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Ship_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/4/1/3) ...........................................................*/
|
||||
static QState Ship_flying_e(Ship * const me) {
|
||||
ScoreEvt *sev;
|
||||
me->score = 0U; /* reset the score */
|
||||
sev = Q_NEW(ScoreEvt, SCORE_SIG);
|
||||
sev->score = me->score;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)sev, me);
|
||||
return QM_ENTRY(&Ship_flying_s);
|
||||
}
|
||||
static QState Ship_flying(Ship * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/4/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
ScoreEvt *sev;
|
||||
me->score = 0U; /* reset the score */
|
||||
sev = Q_NEW(ScoreEvt, SCORE_SIG);
|
||||
sev->score = me->score;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)sev, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/3/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* tell the Tunnel to draw the Ship and test for hits */
|
||||
@ -151,7 +178,7 @@ static QState Ship_flying(Ship * const me, QEvt const * const e) {
|
||||
sev->score = me->score;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)sev, me);
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/3/1) */
|
||||
@ -160,43 +187,49 @@ static QState Ship_flying(Ship * const me, QEvt const * const e) {
|
||||
ope->x = me->x;
|
||||
ope->y = me->y + SHIP_HEIGHT - 1U;
|
||||
QACTIVE_POST(AO_Missile, (QEvt *)ope, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/3/2) */
|
||||
case DESTROYED_MINE_SIG: {
|
||||
me->score += Q_EVT_CAST(ScoreEvt)->score;
|
||||
/* the score will be sent to the Tunnel by the next TIME_TICK */
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/3/3) */
|
||||
case HIT_WALL_SIG: {
|
||||
status_ = Q_TRAN(&Ship_exploding);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Ship_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Ship_exploding_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/3/4) */
|
||||
case HIT_MINE_SIG: {
|
||||
status_ = Q_TRAN(&Ship_exploding);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Ship_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Ship_exploding_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Ship_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/4/1/4) ...........................................................*/
|
||||
static QState Ship_exploding_e(Ship * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Ship_exploding_s);
|
||||
}
|
||||
static QState Ship_exploding(Ship * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/4/1/4) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/4/1/4/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/1/4/1/4/0/0) */
|
||||
@ -209,19 +242,19 @@ static QState Ship_exploding(Ship * const me, QEvt const * const e) {
|
||||
oie->x = me->x; /* x of explosion */
|
||||
oie->y = (int8_t)((int)me->y - 4U + SHIP_HEIGHT);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/4/1/4/0/1) */
|
||||
else {
|
||||
ScoreEvt *gameOver = Q_NEW(ScoreEvt, GAME_OVER_SIG);
|
||||
gameOver->score = me->score;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me);
|
||||
status_ = Q_TRAN(&Ship_parked);
|
||||
status_ = QM_TRAN(&Ship_parked_s, QMsm_emptyAction_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Ship_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -26,14 +26,14 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct TunnelTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt blinkTimeEvt;
|
||||
QTimeEvt screenTimeEvt;
|
||||
QHsm * mines[GAME_MINES_MAX];
|
||||
QHsm * mine1_pool[GAME_MINES_MAX];
|
||||
QHsm * mine2_pool[GAME_MINES_MAX];
|
||||
QMsm * mines[GAME_MINES_MAX];
|
||||
QMsm * mine1_pool[GAME_MINES_MAX];
|
||||
QMsm * mine2_pool[GAME_MINES_MAX];
|
||||
uint8_t blink_ctr;
|
||||
uint8_t last_mine_x;
|
||||
uint8_t last_mine_y;
|
||||
@ -59,15 +59,74 @@ static uint8_t Tunnel_isWallHit(
|
||||
|
||||
/* protected: */
|
||||
static QState Tunnel_initial(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_active(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_show_logo(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_demo(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_playing(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_game_over(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_screen_saver(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_screen_saver_hide(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_screen_saver_show(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_final(Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_active (Tunnel * const me, QEvt const * const e);
|
||||
static QMState const Tunnel_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Tunnel_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Tunnel_show_logo (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_show_logo_e(Tunnel * const me);
|
||||
static QState Tunnel_show_logo_x(Tunnel * const me);
|
||||
static QMState const Tunnel_show_logo_s = {
|
||||
&Tunnel_active_s,
|
||||
Q_STATE_CAST(&Tunnel_show_logo),
|
||||
Q_ACTION_CAST(&Tunnel_show_logo_x)
|
||||
};
|
||||
static QState Tunnel_demo (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_demo_e(Tunnel * const me);
|
||||
static QState Tunnel_demo_x(Tunnel * const me);
|
||||
static QMState const Tunnel_demo_s = {
|
||||
&Tunnel_active_s,
|
||||
Q_STATE_CAST(&Tunnel_demo),
|
||||
Q_ACTION_CAST(&Tunnel_demo_x)
|
||||
};
|
||||
static QState Tunnel_playing (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_playing_e(Tunnel * const me);
|
||||
static QState Tunnel_playing_x(Tunnel * const me);
|
||||
static QMState const Tunnel_playing_s = {
|
||||
&Tunnel_active_s,
|
||||
Q_STATE_CAST(&Tunnel_playing),
|
||||
Q_ACTION_CAST(&Tunnel_playing_x)
|
||||
};
|
||||
static QState Tunnel_game_over (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_game_over_e(Tunnel * const me);
|
||||
static QState Tunnel_game_over_x(Tunnel * const me);
|
||||
static QMState const Tunnel_game_over_s = {
|
||||
&Tunnel_active_s,
|
||||
Q_STATE_CAST(&Tunnel_game_over),
|
||||
Q_ACTION_CAST(&Tunnel_game_over_x)
|
||||
};
|
||||
static QState Tunnel_screen_saver (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_screen_saver_i(Tunnel * const me);
|
||||
static QMState const Tunnel_screen_saver_s = {
|
||||
&Tunnel_active_s,
|
||||
Q_STATE_CAST(&Tunnel_screen_saver),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Tunnel_screen_saver_hide (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_screen_saver_hide_e(Tunnel * const me);
|
||||
static QState Tunnel_screen_saver_hide_x(Tunnel * const me);
|
||||
static QMState const Tunnel_screen_saver_hide_s = {
|
||||
&Tunnel_screen_saver_s,
|
||||
Q_STATE_CAST(&Tunnel_screen_saver_hide),
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_hide_x)
|
||||
};
|
||||
static QState Tunnel_screen_saver_show (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_screen_saver_show_e(Tunnel * const me);
|
||||
static QState Tunnel_screen_saver_show_x(Tunnel * const me);
|
||||
static QMState const Tunnel_screen_saver_show_s = {
|
||||
&Tunnel_screen_saver_s,
|
||||
Q_STATE_CAST(&Tunnel_screen_saver_show),
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_show_x)
|
||||
};
|
||||
static QState Tunnel_final (Tunnel * const me, QEvt const * const e);
|
||||
static QState Tunnel_final_e(Tunnel * const me);
|
||||
static QMState const Tunnel_final_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Tunnel_final),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
static Tunnel l_tunnel; /* the sole instance of the Tunnel active object */
|
||||
|
||||
@ -237,17 +296,17 @@ static Bitmap const l_bitmap[MAX_BMP] = {
|
||||
};
|
||||
|
||||
/* Active object definition ================================================*/
|
||||
/* @(/2/9) .................................................................*/
|
||||
/* @(/2/8) .................................................................*/
|
||||
void Tunnel_ctor(void) {
|
||||
uint8_t n;
|
||||
Tunnel *me = &l_tunnel;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Tunnel_initial);
|
||||
QTimeEvt_ctor(&me->blinkTimeEvt, BLINK_TIMEOUT_SIG);
|
||||
QTimeEvt_ctor(&me->screenTimeEvt, SCREEN_TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Tunnel_initial));
|
||||
QTimeEvt_ctorX(&me->blinkTimeEvt, &me->super, BLINK_TIMEOUT_SIG, 0U);
|
||||
QTimeEvt_ctorX(&me->screenTimeEvt, &me->super, SCREEN_TIMEOUT_SIG, 0U);
|
||||
for (n = 0; n < GAME_MINES_MAX; ++n) {
|
||||
me->mine1_pool[n] = Mine1_ctor(n); /* instantiate Mine1 in the pool */
|
||||
me->mine2_pool[n] = Mine2_ctor(n); /* instantiate Mine2 in the pool */
|
||||
me->mines[n] = (QHsm *)0; /* mine 'n' is unused */
|
||||
me->mines[n] = (QMsm *)0; /* mine 'n' is unused */
|
||||
}
|
||||
me->last_mine_x = 0; /* the last mine at the right edge of the tunnel */
|
||||
me->last_mine_y = 0;
|
||||
@ -322,7 +381,7 @@ static void Tunnel_plantMine(Tunnel * const me) {
|
||||
{
|
||||
uint8_t n;
|
||||
for (n = 0U; n < Q_DIM(me->mines); ++n) { /*look for disabled mines */
|
||||
if (me->mines[n] == (QHsm *)0) {
|
||||
if (me->mines[n] == (QMsm *)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -349,7 +408,7 @@ static void Tunnel_plantMine(Tunnel * const me) {
|
||||
ope.super.sig = MINE_PLANT_SIG;
|
||||
ope.x = me->last_mine_x;
|
||||
ope.y = me->last_mine_y;
|
||||
QHsm_dispatch(me->mines[n], (QEvt *)&ope); /* direct dispatch */
|
||||
QMSM_DISPATCH(me->mines[n], (QEvt *)&ope); /* direct dispatch */
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,8 +447,8 @@ static void Tunnel_dispatchToAllMines(Tunnel * const me, QEvt const * e) {
|
||||
uint8_t n;
|
||||
|
||||
for (n = 0U; n < GAME_MINES_MAX; ++n) {
|
||||
if (me->mines[n] != (QHsm *)0) { /* is the mine used? */
|
||||
QHsm_dispatch(me->mines[n], e);
|
||||
if (me->mines[n] != (QMsm *)0) { /* is the mine used? */
|
||||
QMSM_DISPATCH(me->mines[n], e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -424,10 +483,14 @@ static uint8_t Tunnel_isWallHit(
|
||||
/* @(/2/0/16) ..............................................................*/
|
||||
/* @(/2/0/16/0) */
|
||||
static QState Tunnel_initial(Tunnel * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_show_logo_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
for (n = 0U; n < GAME_MINES_MAX; ++n) {
|
||||
QHsm_init(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
|
||||
QHsm_init(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
|
||||
QMSM_INIT(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
|
||||
QMSM_INIT(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
|
||||
}
|
||||
randomSeed(1234); /* seed the pseudo-random generator */
|
||||
|
||||
@ -463,7 +526,7 @@ static QState Tunnel_initial(Tunnel * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(SCORE_SIG, &l_tunnel);
|
||||
|
||||
(void)e; /* avoid the "unreferenced parameter" warning */
|
||||
return Q_TRAN(&Tunnel_show_logo);
|
||||
return QM_INITIAL(&Tunnel_show_logo_s, act_);
|
||||
}
|
||||
/* @(/2/0/16/1) ............................................................*/
|
||||
static QState Tunnel_active(Tunnel * const me, QEvt const * const e) {
|
||||
@ -472,49 +535,53 @@ static QState Tunnel_active(Tunnel * const me, QEvt const * const e) {
|
||||
/* @(/2/0/16/1/0) */
|
||||
case MINE_DISABLED_SIG: {
|
||||
Q_ASSERT((Q_EVT_CAST(MineEvt)->id < GAME_MINES_MAX)
|
||||
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QHsm *)0));
|
||||
me->mines[Q_EVT_CAST(MineEvt)->id] = (QHsm *)0;
|
||||
status_ = Q_HANDLED();
|
||||
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QMsm *)0));
|
||||
me->mines[Q_EVT_CAST(MineEvt)->id] = (QMsm *)0;
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/1) */
|
||||
case PLAYER_QUIT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_final);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_final_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_final_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/2) ..........................................................*/
|
||||
static QState Tunnel_show_logo_e(Tunnel * const me) {
|
||||
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString(0U, 0U, " Quantum LeAps ");
|
||||
BSP_drawNString(0U, 1U, "state-machine.co");
|
||||
return QM_ENTRY(&Tunnel_show_logo_s);
|
||||
}
|
||||
static QState Tunnel_show_logo_x(Tunnel * const me) {
|
||||
QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
return QM_EXIT(&Tunnel_show_logo_s);
|
||||
}
|
||||
static QState Tunnel_show_logo(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*5U); /* 5 sec timeout */
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString(0U, 0U, " Quantum LeAps ");
|
||||
BSP_drawNString(0U, 1U, "state-machine.co");
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/2) */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/2/0) */
|
||||
case SCREEN_TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_demo);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_show_logo_x),
|
||||
Q_ACTION_CAST(&Tunnel_demo_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_demo_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/2/1) */
|
||||
@ -524,65 +591,65 @@ static QState Tunnel_show_logo(Tunnel * const me, QEvt const * const e) {
|
||||
if (me->blink_ctr == 0U) {
|
||||
BSP_drawNString(6U*9U, 0U, " LeAps");
|
||||
BSP_drawNString(0U, 1U, "state-machine.co");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/0/16/1/2/1/1) */
|
||||
else {
|
||||
BSP_drawNString(6U*9U, 0U, "LeaPs ");
|
||||
BSP_drawNString(0U, 1U, "tate-machine.com");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/3) ..........................................................*/
|
||||
static QState Tunnel_demo_e(Tunnel * const me) {
|
||||
me->last_mine_x = 0U; /* last mine at right edge of the tunnel */
|
||||
me->last_mine_y = 0U;
|
||||
/* set the tunnel properties... */
|
||||
me->wall_thickness_top = 0U;
|
||||
me->wall_thickness_bottom = 0U;
|
||||
me->minimal_gap = GAME_SCREEN_HEIGHT - 3U;
|
||||
|
||||
/* erase the tunnel walls */
|
||||
memset(l_walls, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
|
||||
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*20U, 0U);
|
||||
|
||||
me->blink_ctr = 0U; /* init the blink counter */
|
||||
return QM_ENTRY(&Tunnel_demo_s);
|
||||
}
|
||||
static QState Tunnel_demo_x(Tunnel * const me) {
|
||||
QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
return QM_EXIT(&Tunnel_demo_s);
|
||||
}
|
||||
static QState Tunnel_demo(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->last_mine_x = 0U; /* last mine at right edge of the tunnel */
|
||||
me->last_mine_y = 0U;
|
||||
/* set the tunnel properties... */
|
||||
me->wall_thickness_top = 0U;
|
||||
me->wall_thickness_bottom = 0U;
|
||||
me->minimal_gap = GAME_SCREEN_HEIGHT - 3U;
|
||||
|
||||
/* erase the tunnel walls */
|
||||
memset(l_walls, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
|
||||
QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*20U); /* 20s timeout */
|
||||
|
||||
me->blink_ctr = 0U; /* init the blink counter */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/3/0) */
|
||||
case BLINK_TIMEOUT_SIG: {
|
||||
me->blink_ctr ^= 1U; /* toggle the blink cunter */
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/3/1) */
|
||||
case SCREEN_TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_screen_saver);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_demo_x),
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_i),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_screen_saver_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/3/2) */
|
||||
@ -596,44 +663,45 @@ static QState Tunnel_demo(Tunnel * const me, QEvt const * const e) {
|
||||
(GAME_SCREEN_HEIGHT - 8U)/2U);
|
||||
}
|
||||
BSP_drawBitmap(l_frame);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/3/3) */
|
||||
case PLAYER_TRIGGER_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_playing);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_demo_x),
|
||||
Q_ACTION_CAST(&Tunnel_playing_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_playing_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/4) ..........................................................*/
|
||||
static QState Tunnel_playing_e(Tunnel * const me) {
|
||||
static QEvt const takeoff = { TAKE_OFF_SIG, 0U, 0U };
|
||||
me->minimal_gap = GAME_SCREEN_HEIGHT - 3u;
|
||||
/* erase the walls */
|
||||
memset(l_walls, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
QACTIVE_POST(AO_Ship, &takeoff, me); /* post the TAKEOFF sig */
|
||||
return QM_ENTRY(&Tunnel_playing_s);
|
||||
}
|
||||
static QState Tunnel_playing_x(Tunnel * const me) {
|
||||
QEvt recycle;
|
||||
recycle.sig = MINE_RECYCLE_SIG;
|
||||
Tunnel_dispatchToAllMines(me, &recycle); /* recycle all Mines */
|
||||
return QM_EXIT(&Tunnel_playing_s);
|
||||
}
|
||||
static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/4) */
|
||||
case Q_ENTRY_SIG: {
|
||||
static QEvt const takeoff = { TAKE_OFF_SIG, 0U, 0U };
|
||||
me->minimal_gap = GAME_SCREEN_HEIGHT - 3u;
|
||||
/* erase the walls */
|
||||
memset(l_walls, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
QACTIVE_POST(AO_Ship, &takeoff, me); /* post the TAKEOFF sig */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4) */
|
||||
case Q_EXIT_SIG: {
|
||||
QEvt recycle;
|
||||
recycle.sig = MINE_RECYCLE_SIG;
|
||||
Tunnel_dispatchToAllMines(me, &recycle); /* recycle all Mines */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* render this frame on the display */
|
||||
@ -641,7 +709,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
Tunnel_advance(me);
|
||||
Tunnel_plantMine(me);
|
||||
Tunnel_dispatchToAllMines(me, e);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/1) */
|
||||
@ -657,7 +725,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
}
|
||||
Tunnel_addImageAt(me, bmp, x, y);
|
||||
Tunnel_dispatchToAllMines(me, e); /* let Mines check for hits */
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/2) */
|
||||
@ -673,7 +741,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
}
|
||||
Tunnel_addImageAt(me, bmp, x, y);
|
||||
Tunnel_dispatchToAllMines(me, e); /* let Mines check for hits */
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/3) */
|
||||
@ -682,7 +750,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
Q_EVT_CAST(ObjectImageEvt)->bmp,
|
||||
Q_EVT_CAST(ObjectImageEvt)->x,
|
||||
Q_EVT_CAST(ObjectImageEvt)->y);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/4) */
|
||||
@ -691,7 +759,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
Q_EVT_CAST(ObjectImageEvt)->bmp,
|
||||
Q_EVT_CAST(ObjectImageEvt)->x,
|
||||
Q_EVT_CAST(ObjectImageEvt)->y);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/5) */
|
||||
@ -702,11 +770,16 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
*/
|
||||
me->minimal_gap = (uint8_t)(GAME_SCREEN_HEIGHT - 3U
|
||||
- Q_EVT_CAST(ScoreEvt)->score/2000U);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/4/6) */
|
||||
case GAME_OVER_SIG: {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_playing_x),
|
||||
Q_ACTION_CAST(&Tunnel_game_over_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint16_t score = Q_EVT_CAST(ScoreEvt)->score;
|
||||
char str[5];
|
||||
BSP_updateScore(score);
|
||||
@ -723,39 +796,34 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
|
||||
str[1] = '0' + (score % 10U); score /= 10U;
|
||||
str[0] = '0' + (score % 10U);
|
||||
BSP_drawNString((GAME_SCREEN_WIDTH - 6U*10U)/2U + 6U*6U, 1U, str);
|
||||
status_ = Q_TRAN(&Tunnel_game_over);
|
||||
status_ = QM_TRAN(&Tunnel_game_over_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/5) ..........................................................*/
|
||||
static QState Tunnel_game_over_e(Tunnel * const me) {
|
||||
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString((GAME_SCREEN_WIDTH - 6U*9U)/2U, 0U, "Game Over");
|
||||
return QM_ENTRY(&Tunnel_game_over_s);
|
||||
}
|
||||
static QState Tunnel_game_over_x(Tunnel * const me) {
|
||||
QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
BSP_updateScore(0); /* update the score on the display */
|
||||
return QM_EXIT(&Tunnel_game_over_s);
|
||||
}
|
||||
static QState Tunnel_game_over(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/5) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*5U); /* 5 sec timeout */
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString((GAME_SCREEN_WIDTH - 6U*9U)/2U, 0U, "Game Over");
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/5) */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
BSP_updateScore(0); /* update the score on the display */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/5/0) */
|
||||
case BLINK_TIMEOUT_SIG: {
|
||||
me->blink_ctr ^= 1U; /* toggle the blink couner */
|
||||
@ -763,131 +831,140 @@ static QState Tunnel_game_over(Tunnel * const me, QEvt const * const e) {
|
||||
((me->blink_ctr == 0U)
|
||||
? "Game Over"
|
||||
: " "));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/5/1) */
|
||||
case SCREEN_TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_demo);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_game_over_x),
|
||||
Q_ACTION_CAST(&Tunnel_demo_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_demo_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/6) ..........................................................*/
|
||||
static QState Tunnel_screen_saver_i(Tunnel * const me) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_hide_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
return QM_INITIAL(&Tunnel_screen_saver_hide_s, act_);
|
||||
}
|
||||
static QState Tunnel_screen_saver(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/6/0) */
|
||||
case Q_INIT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_screen_saver_hide);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/6/1) */
|
||||
case PLAYER_TRIGGER_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_demo);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_demo_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_demo_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/6/2) ........................................................*/
|
||||
static QState Tunnel_screen_saver_hide_e(Tunnel * const me) {
|
||||
BSP_displayOff(); /* power down the display */
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*3U, 0U);
|
||||
return QM_ENTRY(&Tunnel_screen_saver_hide_s);
|
||||
}
|
||||
static QState Tunnel_screen_saver_hide_x(Tunnel * const me) {
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
BSP_displayOn(); /* power up the display */
|
||||
return QM_EXIT(&Tunnel_screen_saver_hide_s);
|
||||
}
|
||||
static QState Tunnel_screen_saver_hide(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/6/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayOff(); /* power down the display */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*3U); /* 3s timeout */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/6/2) */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
BSP_displayOn(); /* power up the display */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/6/2/0) */
|
||||
case SCREEN_TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_screen_saver_show);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_hide_x),
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_show_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_screen_saver_show_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_screen_saver);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/1/6/3) ........................................................*/
|
||||
static QState Tunnel_screen_saver_show_e(Tunnel * const me) {
|
||||
uint32_t rnd = random();
|
||||
/* clear the screen frame buffer */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
Tunnel_addImageAt(me,
|
||||
PRESS_BUTTON_BMP,
|
||||
(uint8_t)(rnd % (GAME_SCREEN_WIDTH - 55U)),
|
||||
(int8_t) (rnd % (GAME_SCREEN_HEIGHT - 8U)));
|
||||
BSP_drawBitmap(l_frame);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC/2U, 0U);
|
||||
return QM_ENTRY(&Tunnel_screen_saver_show_s);
|
||||
}
|
||||
static QState Tunnel_screen_saver_show_x(Tunnel * const me) {
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
/* clear the screen frame buffer */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
BSP_drawBitmap(l_frame);
|
||||
return QM_EXIT(&Tunnel_screen_saver_show_s);
|
||||
}
|
||||
static QState Tunnel_screen_saver_show(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/1/6/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint32_t rnd = random();
|
||||
/* clear the screen frame buffer */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
Tunnel_addImageAt(me,
|
||||
PRESS_BUTTON_BMP,
|
||||
(uint8_t)(rnd % (GAME_SCREEN_WIDTH - 55U)),
|
||||
(int8_t) (rnd % (GAME_SCREEN_HEIGHT - 8U)));
|
||||
BSP_drawBitmap(l_frame);
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/3U); /* 1/3 sec timeout */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/6/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
/* clear the screen frame buffer */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
BSP_drawBitmap(l_frame);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/16/1/6/3/0) */
|
||||
case SCREEN_TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Tunnel_screen_saver_hide);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_show_x),
|
||||
Q_ACTION_CAST(&Tunnel_screen_saver_hide_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Tunnel_screen_saver_hide_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Tunnel_screen_saver);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/16/2) ............................................................*/
|
||||
static QState Tunnel_final_e(Tunnel * const me) {
|
||||
/* clear the screen */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8));
|
||||
BSP_drawBitmap(l_frame);
|
||||
QF_stop(); /* stop QF and cleanup */
|
||||
return QM_ENTRY(&Tunnel_final_s);
|
||||
}
|
||||
static QState Tunnel_final(Tunnel * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/16/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
/* clear the screen */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8));
|
||||
BSP_drawBitmap(l_frame);
|
||||
QF_stop(); /* stop QF and cleanup */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="2.3.0">
|
||||
<item name="license"></item>
|
||||
<group name="locked"/>
|
||||
<group name="settings">
|
||||
<item name="tabs">1</item>
|
||||
<item name="windows">0</item>
|
||||
<item name="grid">3</item>
|
||||
</group>
|
||||
<group name="windows"/>
|
||||
<group name="vars"/>
|
||||
<group name="tools">
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
</group>
|
||||
</session>
|
@ -1,7 +1,7 @@
|
||||
##############################################################################
|
||||
# Product: Makefile for DPP EK-LM3811, QK kernel, GNU/Sourcery G++
|
||||
# Last Updated for Version: 5.0.0
|
||||
# Date of the Last Update: Sep 07, 2013
|
||||
# Product: Makefile for EK-LM3811, QK kernel, GNU/Sourcery G++
|
||||
# Last Updated for Version: 5.2.0
|
||||
# Date of the Last Update: Dec 17, 2013
|
||||
#
|
||||
# Q u a n t u m L e a P s
|
||||
# ---------------------------
|
||||
@ -43,8 +43,46 @@
|
||||
# make CONF=rel clean
|
||||
# make CONF=spy clean
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# NOTE: the Makefile expects that the QPC environment variable is defined
|
||||
# and points to the QP/C installation directory
|
||||
#
|
||||
ifndef QPC
|
||||
$(error The QPC environment variable must be defined)
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# directories
|
||||
#
|
||||
|
||||
PROJECT := dpp-qk
|
||||
|
||||
QP_PORT_DIR := $(QPC)/ports/arm-cm/qk/gnu
|
||||
CMSIS_DIR := $(QPC)/ports/arm-cm/cmsis
|
||||
APP_DIR := .
|
||||
|
||||
# source directories
|
||||
VPATH = $(APP_DIR) \
|
||||
$(CMSIS_DIR)
|
||||
|
||||
# Output file basename
|
||||
OUTPUT := $(PROJECT)
|
||||
|
||||
# include directories
|
||||
INCLUDES = -I$(QPC)/include \
|
||||
-I$(QP_PORT_DIR) \
|
||||
-I. \
|
||||
-I$(CMSIS_DIR)
|
||||
|
||||
# defines
|
||||
DEFINES =
|
||||
|
||||
ARM_CORE = cortex-m3
|
||||
ARM_FPU =
|
||||
|
||||
LD_SCRIPT := $(PROJECT).ld
|
||||
LIBS := -lqp_$(ARM_CORE)_cs
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# GNU ARM compiler
|
||||
#
|
||||
@ -64,39 +102,6 @@ RM := rm -rf
|
||||
MKDIR := mkdir
|
||||
RM := rm
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# NOTE: the Makefile expects that the QPC environment variable is defined
|
||||
# and points to the QP/C installation directory
|
||||
#
|
||||
ifndef QPC
|
||||
$(error The QPC environment variable must be defined)
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# directories
|
||||
#
|
||||
QP_PORT_DIR := $(QPC)/ports/arm-cm/qk/gnu
|
||||
CMSIS_DIR := $(QPC)/ports/arm-cm/cmsis
|
||||
APP_DIR := .
|
||||
|
||||
# source directories
|
||||
VPATH = $(APP_DIR) \
|
||||
$(CMSIS_DIR)
|
||||
|
||||
# Output file basename
|
||||
OUTPUT := $(PROJECT)
|
||||
|
||||
# include directories
|
||||
INCLUDES = -I$(QPC)/include \
|
||||
-I$(QP_PORT_DIR) \
|
||||
-I. \
|
||||
-I$(CMSIS_DIR)
|
||||
|
||||
# defines
|
||||
DEFINES =
|
||||
|
||||
ARM_CORE = cortex-m3
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# files
|
||||
#
|
||||
@ -110,15 +115,10 @@ C_SRCS := $(wildcard *.c)
|
||||
# C++ source files
|
||||
CPP_SRCS := $(wildcard *.cpp)
|
||||
|
||||
LD_SCRIPT := lm3s811.ld
|
||||
LIBS := -lqp_$(ARM_CORE)_cs
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# build options for various configurations
|
||||
#
|
||||
|
||||
ARM_CORE = cortex-m3
|
||||
|
||||
ifeq (rel, $(CONF)) # Release configuration ............................
|
||||
|
||||
BIN_DIR := rel
|
||||
@ -217,7 +217,12 @@ $(BIN_DIR)/%.o : %.c
|
||||
$(BIN_DIR)/%.o : %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# include dependency files only if our goal depends on their existence
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(MAKECMDGOALS),show)
|
||||
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
.PHONY : clean
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: "Dining Philosophers Problem" example, preemptive QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 19, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -64,7 +64,6 @@ Q_ASSERT_COMPILE(MAX_KERNEL_AWARE_CMSIS_PRI <= (0xFF >>(8-__NVIC_PRIO_BITS)));
|
||||
/* ISRs defined in this BSP ------------------------------------------------*/
|
||||
void SysTick_Handler(void);
|
||||
void GPIOPortA_IRQHandler(void);
|
||||
void assert_failed(char const *file, int line);
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static unsigned l_rnd; /* random seed */
|
||||
@ -104,7 +103,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
/* debounce the USER button... */
|
||||
btn = GPIOC->DATA_Bits[PUSH_BUTTON]; /* read the push btn */
|
||||
@ -186,7 +185,6 @@ void BSP_init(void) {
|
||||
if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */
|
||||
Q_ERROR();
|
||||
}
|
||||
QS_RESET();
|
||||
QS_OBJ_DICTIONARY(&l_SysTick_Handler);
|
||||
QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler);
|
||||
}
|
||||
@ -279,17 +277,16 @@ void QK_onIdle(void) {
|
||||
}
|
||||
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char_t const Q_ROM * const Q_ROM_VAR file, int_t line) {
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
for (;;) { /* NOTE: replace the loop with reset for final version */
|
||||
}
|
||||
void Q_onAssert(char const Q_ROM * const file, int_t line) {
|
||||
assert_failed(file, line);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
/* error routine that is called if the CMSIS library encounters an error */
|
||||
void assert_failed(char const *file, int line) {
|
||||
Q_onAssert(file, line);
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
NVIC_SystemReset(); /* perform system reset */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -1,42 +1,26 @@
|
||||
/*****************************************************************************
|
||||
* Product: GNU linker script for Stellaris LM3S6965 MCUs
|
||||
* Last Updated for Version: 4.1.03
|
||||
* Date of the Last Update: Mar 11, 2010
|
||||
* Product: Makefile for EK-TM4C123GXL, GNU/Sourcery
|
||||
* Date of the Last Update: Dec 13, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, www.state-machine.com
|
||||
*
|
||||
* Copyright (C) 2002-2010 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This software may be distributed and modified under the terms of the GNU
|
||||
* General Public License version 2 (GPL) as published by the Free Software
|
||||
* Foundation and appearing in the file GPL.TXT included in the packaging of
|
||||
* this file. Please note that GPL Section 2[b] requires that all works based
|
||||
* on this software must also be made publicly available under the terms of
|
||||
* the GPL ("Copyleft").
|
||||
*
|
||||
* Alternatively, this software may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GPL and are specifically designed for licensees interested in
|
||||
* retaining the proprietary status of their code.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web site: http://www.quantum-leaps.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is free software. It comes without any warranty, to the extent
|
||||
* permitted by applicable law. You can redistribute it and/or modify it under
|
||||
* the terms of the WTFPL, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*****************************************************************************/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(Reset_Handler) /* entry Point */
|
||||
|
||||
MEMORY { /* memory map of LM3S6965 */
|
||||
MEMORY { /* memory map of Tiva TM4C123GH6PM */
|
||||
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 256K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
/* The size of the stack used by the application. NOTE: you need to adjust */
|
||||
STACK_SIZE = 1024;
|
||||
STACK_SIZE = 1000;
|
||||
|
||||
/* The size of the heap used by the application. NOTE: you need to adjust */
|
||||
HEAP_SIZE = 0;
|
||||
@ -83,6 +67,13 @@ SECTIONS {
|
||||
|
||||
_etext = .; /* global symbols at end of code */
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = .;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
__stack_end__ = .;
|
||||
} >RAM
|
||||
|
||||
.data : AT (_etext) {
|
||||
__data_load = LOADADDR (.data);
|
||||
__data_start = .;
|
||||
@ -94,7 +85,7 @@ SECTIONS {
|
||||
} >RAM
|
||||
|
||||
.bss : {
|
||||
__bss_start__ = . ;
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
@ -108,18 +99,10 @@ SECTIONS {
|
||||
PROVIDE ( __end__ = _ebss );
|
||||
|
||||
.heap : {
|
||||
__heap_start__ = . ;
|
||||
__heap_start__ = .;
|
||||
. = . + HEAP_SIZE;
|
||||
. = ALIGN(4);
|
||||
__heap_end__ = . ;
|
||||
} >RAM
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = . ;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
__c_stack_top__ = . ;
|
||||
__stack_end__ = . ;
|
||||
__heap_end__ = .;
|
||||
} >RAM
|
||||
|
||||
/* Remove information from the standard libraries */
|
@ -2,10 +2,17 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./dpp.h
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/0) .................................................................*/
|
||||
#ifndef dpp_h
|
||||
@ -43,6 +50,8 @@ void Table_ctor(void);
|
||||
|
||||
|
||||
extern QActive * const AO_Philo[N_PHILO];
|
||||
|
||||
extern QActive * const AO_Table;
|
||||
|
||||
|
||||
#endif /* dpp_h */
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,17 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./philo.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/1) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
@ -18,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -26,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -62,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -95,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -117,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status_ = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -154,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status_ = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -192,11 +227,11 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +1,115 @@
|
||||
/*****************************************************************************
|
||||
* Purpose: CMSIS-compliant startup code for LM3S Cortex-M3 devices, GNU
|
||||
* Last Updated for Version: 4.1.03
|
||||
* Date of the Last Update: Mar 03, 2010
|
||||
* Purpose: CMSIS-compliant startup code for LM3S Cortex-M3 devices, GNU-ARM
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 24, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2010 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This software may be distributed and modified under the terms of the GNU
|
||||
* General Public License version 2 (GPL) as published by the Free Software
|
||||
* Foundation and appearing in the file GPL.TXT included in the packaging of
|
||||
* this file. Please note that GPL Section 2[b] requires that all works based
|
||||
* on this software must also be made publicly available under the terms of
|
||||
* the GPL ("Copyleft").
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alternatively, this software may be distributed and modified under the
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GPL and are specifically designed for licensees interested in
|
||||
* retaining the proprietary status of their code.
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web site: http://www.quantum-leaps.com
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
void __attribute__ ((weak)) Reset_Handler(void);
|
||||
void __attribute__ ((weak)) NMI_Handler(void);
|
||||
void __attribute__ ((weak)) HardFault_Handler(void);
|
||||
void __attribute__ ((weak)) MemManage_Handler(void);
|
||||
void __attribute__ ((weak)) BusFault_Handler(void);
|
||||
void __attribute__ ((weak)) UsageFault_Handler(void);
|
||||
void __attribute__ ((weak)) MemManage_Handler(void);
|
||||
void __attribute__ ((weak)) SVC_Handler(void);
|
||||
void __attribute__ ((weak)) DebugMon_Handler(void);
|
||||
void __attribute__ ((weak)) PendSV_Handler(void);
|
||||
void __attribute__ ((weak)) SysTick_Handler(void);
|
||||
|
||||
/* external interrupts... */
|
||||
void __attribute__ ((weak)) GPIOPortA_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortB_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortC_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortD_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortE_IRQHandler(void);
|
||||
void __attribute__ ((weak)) UART0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) UART1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) SSI0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) I2C0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMFault_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMGen0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMGen1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMGen2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) QEI0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq3_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Watchdog_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer0A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer0B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer1A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer1B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer2A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer2B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Comp0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Comp1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Comp2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) SysCtrl_IRQHandler(void);
|
||||
void __attribute__ ((weak)) FlashCtrl_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortF_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortG_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortH_IRQHandler(void);
|
||||
void __attribute__ ((weak)) UART2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) SSI1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer3A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer3B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) I2C1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) QEI1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) CAN0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) CAN1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) CAN2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Ethernet_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Hibernate_IRQHandler(void);
|
||||
/* Function prototypes -----------------------------------------------------*/
|
||||
void Reset_Handler(void);
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void Spurious_Handler(void);
|
||||
|
||||
void assert_failed(char const *file, int line); /* defined in the BSP */
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* weak aliases for each Exception handler to the Spurious_Handler.
|
||||
* Any function with the same name will override these definitions.
|
||||
*/
|
||||
__attribute__ ((weak)) void SVC_Handler(void);
|
||||
__attribute__ ((weak)) void DebugMon_Handler(void);
|
||||
__attribute__ ((weak)) void PendSV_Handler(void);
|
||||
__attribute__ ((weak)) void SysTick_Handler(void);
|
||||
__attribute__ ((weak)) void Spurious_Handler(void);
|
||||
|
||||
/* external interrupts... */
|
||||
__attribute__ ((weak)) void GPIOPortA_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortB_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortC_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortD_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortE_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SSI0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMFault_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void QEI0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Watchdog_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer0A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer0B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer1A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer1B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer2A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer2B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Comp0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Comp1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Comp2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SysCtrl_IRQHandler(void);
|
||||
__attribute__ ((weak)) void FlashCtrl_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortF_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortG_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortH_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SSI1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer3A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer3B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void QEI1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void CAN0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void CAN1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void CAN2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Ethernet_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Hibernate_IRQHandler(void);
|
||||
|
||||
void __attribute__ ((weak)) Spurious_Handler(void);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* weak aliases for each Exception handler to the Spurious_Handler.
|
||||
* Any function with the same name will override these definitions.
|
||||
*/
|
||||
#pragma weak NMI_Handler = Spurious_Handler
|
||||
#pragma weak MemManage_Handler = Spurious_Handler
|
||||
#pragma weak BusFault_Handler = Spurious_Handler
|
||||
#pragma weak UsageFault_Handler = Spurious_Handler
|
||||
#pragma weak SVC_Handler = Spurious_Handler
|
||||
#pragma weak DebugMon_Handler = Spurious_Handler
|
||||
#pragma weak PendSV_Handler = Spurious_Handler
|
||||
#pragma weak SysTick_Handler = Spurious_Handler
|
||||
|
||||
#pragma weak GPIOPortA_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortB_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortC_IRQHandler = Spurious_Handler
|
||||
@ -143,20 +155,21 @@ void __attribute__ ((weak)) Spurious_Handler(void);
|
||||
#pragma weak Ethernet_IRQHandler = Spurious_Handler
|
||||
#pragma weak Hibernate_IRQHandler = Spurious_Handler
|
||||
|
||||
/* exception and interrupt vector table ------------------------------------*/
|
||||
typedef void (*ExceptionHandler)(void);
|
||||
typedef union {
|
||||
ExceptionHandler handler;
|
||||
void *pointer;
|
||||
} VectorTableEntry;
|
||||
|
||||
/* top of stack defined in the linker script */
|
||||
extern unsigned __c_stack_top__;
|
||||
/* start and end of stack defined in the linker script ---------------------*/
|
||||
extern unsigned __stack_start__;
|
||||
extern unsigned __stack_end__;
|
||||
|
||||
/* exception and interrupt vector table ------------------------------------*/
|
||||
typedef union VectorTableEntryTag {
|
||||
void *pointer; /* used only to initialize the stack top */
|
||||
void (*handler)(void); /* used for all exception and interrupt handlers */
|
||||
} VectorTableEntry;
|
||||
|
||||
/*..........................................................................*/
|
||||
__attribute__ ((section(".isr_vector")))
|
||||
VectorTableEntry const g_pfnVectors[] = {
|
||||
{ .pointer = &__c_stack_top__ }, /* initial stack pointer */
|
||||
{ .pointer = &__stack_end__ }, /* initial stack pointer */
|
||||
{ .handler = &Reset_Handler }, /* Reset Handler */
|
||||
{ .handler = &NMI_Handler }, /* NMI Handler */
|
||||
{ .handler = &HardFault_Handler }, /* Hard Fault Handler */
|
||||
@ -173,57 +186,55 @@ VectorTableEntry const g_pfnVectors[] = {
|
||||
{ .handler = &PendSV_Handler }, /* PendSV Handler */
|
||||
{ .handler = &SysTick_Handler }, /* SysTick Handler */
|
||||
/* external interrupts (IRQs) ... */
|
||||
{ .handler = GPIOPortA_IRQHandler }, /* GPIO Port A */
|
||||
{ .handler = GPIOPortB_IRQHandler }, /* GPIO Port B */
|
||||
{ .handler = GPIOPortC_IRQHandler }, /* GPIO Port C */
|
||||
{ .handler = GPIOPortD_IRQHandler }, /* GPIO Port D */
|
||||
{ .handler = GPIOPortE_IRQHandler }, /* GPIO Port E */
|
||||
{ .handler = UART0_IRQHandler }, /* UART0 Rx and Tx */
|
||||
{ .handler = UART1_IRQHandler }, /* UART1 Rx and Tx */
|
||||
{ .handler = SSI0_IRQHandler }, /* SSI0 Rx and Tx */
|
||||
{ .handler = I2C0_IRQHandler }, /* I2C0 Master and Slave */
|
||||
{ .handler = PWMFault_IRQHandler }, /* PWM Fault */
|
||||
{ .handler = PWMGen0_IRQHandler }, /* PWM Generator 0 */
|
||||
{ .handler = PWMGen1_IRQHandler }, /* PWM Generator 1 */
|
||||
{ .handler = PWMGen2_IRQHandler }, /* PWM Generator 2 */
|
||||
{ .handler = QEI0_IRQHandler }, /* Quadrature Encoder 0 */
|
||||
{ .handler = ADCSeq0_IRQHandler }, /* ADC Sequence 0 */
|
||||
{ .handler = ADCSeq1_IRQHandler }, /* ADC Sequence 1 */
|
||||
{ .handler = ADCSeq2_IRQHandler }, /* ADC Sequence 2 */
|
||||
{ .handler = ADCSeq3_IRQHandler }, /* ADC Sequence 3 */
|
||||
{ .handler = Watchdog_IRQHandler }, /* Watchdog timer */
|
||||
{ .handler = Timer0A_IRQHandler }, /* Timer 0 subtimer A */
|
||||
{ .handler = Timer0B_IRQHandler }, /* Timer 0 subtimer B */
|
||||
{ .handler = Timer1A_IRQHandler }, /* Timer 1 subtimer A */
|
||||
{ .handler = Timer1B_IRQHandler }, /* Timer 1 subtimer B */
|
||||
{ .handler = Timer2A_IRQHandler }, /* Timer 2 subtimer A */
|
||||
{ .handler = Timer2B_IRQHandler }, /* Timer 2 subtimer B */
|
||||
{ .handler = Comp0_IRQHandler }, /* Analog Comparator 0 */
|
||||
{ .handler = Comp1_IRQHandler }, /* Analog Comparator 1 */
|
||||
{ .handler = Comp2_IRQHandler }, /* Analog Comparator 2 */
|
||||
{ .handler = SysCtrl_IRQHandler }, /* System Control (PLL,OSC,BO) */
|
||||
{ .handler = FlashCtrl_IRQHandler }, /* FLASH Control */
|
||||
{ .handler = GPIOPortF_IRQHandler }, /* GPIO Port F */
|
||||
{ .handler = GPIOPortG_IRQHandler }, /* GPIO Port G */
|
||||
{ .handler = GPIOPortH_IRQHandler }, /* GPIO Port H */
|
||||
{ .handler = UART2_IRQHandler }, /* UART2 Rx and Tx */
|
||||
{ .handler = SSI1_IRQHandler }, /* SSI1 Rx and Tx */
|
||||
{ .handler = Timer3A_IRQHandler }, /* Timer 3 subtimer A */
|
||||
{ .handler = Timer3B_IRQHandler }, /* Timer 3 subtimer B */
|
||||
{ .handler = I2C1_IRQHandler }, /* I2C1 Master and Slave */
|
||||
{ .handler = QEI1_IRQHandler }, /* Quadrature Encoder 1 */
|
||||
{ .handler = CAN0_IRQHandler }, /* CAN0 */
|
||||
{ .handler = CAN1_IRQHandler }, /* CAN1 */
|
||||
{ .handler = CAN2_IRQHandler }, /* CAN2 */
|
||||
{ .handler = Ethernet_IRQHandler }, /* Ethernet */
|
||||
{ .handler = Hibernate_IRQHandler }, /* Hibernate */
|
||||
{ .handler = &GPIOPortA_IRQHandler }, /* GPIO Port A */
|
||||
{ .handler = &GPIOPortB_IRQHandler }, /* GPIO Port B */
|
||||
{ .handler = &GPIOPortC_IRQHandler }, /* GPIO Port C */
|
||||
{ .handler = &GPIOPortD_IRQHandler }, /* GPIO Port D */
|
||||
{ .handler = &GPIOPortE_IRQHandler }, /* GPIO Port E */
|
||||
{ .handler = &UART0_IRQHandler }, /* UART0 Rx and Tx */
|
||||
{ .handler = &UART1_IRQHandler }, /* UART1 Rx and Tx */
|
||||
{ .handler = &SSI0_IRQHandler }, /* SSI0 Rx and Tx */
|
||||
{ .handler = &I2C0_IRQHandler }, /* I2C0 Master and Slave */
|
||||
{ .handler = &PWMFault_IRQHandler }, /* PWM Fault */
|
||||
{ .handler = &PWMGen0_IRQHandler }, /* PWM Generator 0 */
|
||||
{ .handler = &PWMGen1_IRQHandler }, /* PWM Generator 1 */
|
||||
{ .handler = &PWMGen2_IRQHandler }, /* PWM Generator 2 */
|
||||
{ .handler = &QEI0_IRQHandler }, /* Quadrature Encoder 0 */
|
||||
{ .handler = &ADCSeq0_IRQHandler }, /* ADC Sequence 0 */
|
||||
{ .handler = &ADCSeq1_IRQHandler }, /* ADC Sequence 1 */
|
||||
{ .handler = &ADCSeq2_IRQHandler }, /* ADC Sequence 2 */
|
||||
{ .handler = &ADCSeq3_IRQHandler }, /* ADC Sequence 3 */
|
||||
{ .handler = &Watchdog_IRQHandler }, /* Watchdog timer */
|
||||
{ .handler = &Timer0A_IRQHandler }, /* Timer 0 subtimer A */
|
||||
{ .handler = &Timer0B_IRQHandler }, /* Timer 0 subtimer B */
|
||||
{ .handler = &Timer1A_IRQHandler }, /* Timer 1 subtimer A */
|
||||
{ .handler = &Timer1B_IRQHandler }, /* Timer 1 subtimer B */
|
||||
{ .handler = &Timer2A_IRQHandler }, /* Timer 2 subtimer A */
|
||||
{ .handler = &Timer2B_IRQHandler }, /* Timer 2 subtimer B */
|
||||
{ .handler = &Comp0_IRQHandler }, /* Analog Comparator 0 */
|
||||
{ .handler = &Comp1_IRQHandler }, /* Analog Comparator 1 */
|
||||
{ .handler = &Comp2_IRQHandler }, /* Analog Comparator 2 */
|
||||
{ .handler = &SysCtrl_IRQHandler }, /* System Control (PLL,OSC,BO) */
|
||||
{ .handler = &FlashCtrl_IRQHandler }, /* FLASH Control */
|
||||
{ .handler = &GPIOPortF_IRQHandler }, /* GPIO Port F */
|
||||
{ .handler = &GPIOPortG_IRQHandler }, /* GPIO Port G */
|
||||
{ .handler = &GPIOPortH_IRQHandler }, /* GPIO Port H */
|
||||
{ .handler = &UART2_IRQHandler }, /* UART2 Rx and Tx */
|
||||
{ .handler = &SSI1_IRQHandler }, /* SSI1 Rx and Tx */
|
||||
{ .handler = &Timer3A_IRQHandler }, /* Timer 3 subtimer A */
|
||||
{ .handler = &Timer3B_IRQHandler }, /* Timer 3 subtimer B */
|
||||
{ .handler = &I2C1_IRQHandler }, /* I2C1 Master and Slave */
|
||||
{ .handler = &QEI1_IRQHandler }, /* Quadrature Encoder 1 */
|
||||
{ .handler = &CAN0_IRQHandler }, /* CAN0 */
|
||||
{ .handler = &CAN1_IRQHandler }, /* CAN1 */
|
||||
{ .handler = &CAN2_IRQHandler }, /* CAN2 */
|
||||
{ .handler = &Ethernet_IRQHandler }, /* Ethernet */
|
||||
{ .handler = &Hibernate_IRQHandler }, /* Hibernate */
|
||||
};
|
||||
|
||||
/* function prototypes -----------------------------------------------------*/
|
||||
void assert_failed(char const *file, int line);
|
||||
|
||||
/*..........................................................................*/
|
||||
void Reset_Handler(void) __attribute__((__interrupt__));
|
||||
/* exception handlers ------------------------------------------------------*/
|
||||
__attribute__((naked)) void Reset_Handler(void);
|
||||
void Reset_Handler(void) {
|
||||
extern int main(void);
|
||||
extern int __libc_init_array(void);
|
||||
@ -240,7 +251,6 @@ void Reset_Handler(void) {
|
||||
for (dst = &__data_start; dst < &__data_end__; ++dst, ++src) {
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/* zero fill the .bss segment... */
|
||||
for (dst = &__bss_start__; dst < &__bss_end__; ++dst) {
|
||||
*dst = 0;
|
||||
@ -248,26 +258,49 @@ void Reset_Handler(void) {
|
||||
/* call all static construcors in C++ (harmless in C programs) */
|
||||
__libc_init_array();
|
||||
|
||||
/* call the application's entry point */
|
||||
main();
|
||||
|
||||
/* in a bare-metal system main() has nothing to return to and it should
|
||||
* never return. Just in case main() returns, the assert_failed() gives
|
||||
* the last opportunity to catch this problem.
|
||||
*/
|
||||
assert_failed("startup_stm32f10x_cl", __LINE__);
|
||||
(void)main(); /* application's entry point, which should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Spurious_Handler(void) __attribute__((__interrupt__));
|
||||
void Spurious_Handler(void) {
|
||||
assert_failed("startup_stm32f10x_cl", __LINE__);
|
||||
/* assert_failed() should not return, but just in case the following
|
||||
* enless loop will tie up the CPU.
|
||||
*/
|
||||
for (;;) {
|
||||
__attribute__((naked)) void NMI_Handler(void);
|
||||
void NMI_Handler(void) {
|
||||
assert_failed("NMI", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void MemManage_Handler(void);
|
||||
void MemManage_Handler(void) {
|
||||
assert_failed("MemManage", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void HardFault_Handler(void);
|
||||
void HardFault_Handler(void) {
|
||||
unsigned old_sp;
|
||||
__asm volatile ("mov %0,sp" : "=r" (old_sp));
|
||||
if (old_sp < (unsigned)&__stack_start__) { /* stack overflow? */
|
||||
unsigned new_sp = (unsigned)&__stack_end__;
|
||||
__asm volatile ("mov sp,%0" :: "r" (new_sp));
|
||||
assert_failed("StackOverflow", old_sp); /* should never return! */
|
||||
}
|
||||
else {
|
||||
assert_failed("HardFault", __LINE__); /* should never return! */
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void BusFault_Handler(void);
|
||||
void BusFault_Handler(void) {
|
||||
assert_failed("BusFault", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void UsageFault_Handler(void);
|
||||
void UsageFault_Handler(void) {
|
||||
assert_failed("UsageFault", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void Spurious_Handler(void);
|
||||
void Spurious_Handler(void) {
|
||||
assert_failed("Spurious", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void _init() {
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,10 +2,17 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./table.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/2) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
@ -18,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -27,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -49,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -60,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -84,7 +113,7 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
@ -93,48 +122,46 @@ static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -154,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -201,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status_ = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status_ = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -250,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -268,11 +300,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
##############################################################################
|
||||
# Product: Makefile for EK-TM4C123XL, QK kernel, GNU/Sourcery
|
||||
# Last Updated for Version: 5.0.0
|
||||
# Date of the Last Update: Sep 07, 2013
|
||||
# Product: Makefile for EK-TM4C123GXL, QK kernel, GNU/Sourcery
|
||||
# Last Updated for Version: 5.2.0
|
||||
# Date of the Last Update: Dec 17, 2013
|
||||
#
|
||||
# Q u a n t u m L e a P s
|
||||
# ---------------------------
|
||||
@ -43,8 +43,46 @@
|
||||
# make CONF=rel clean
|
||||
# make CONF=spy clean
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# NOTE: the Makefile expects that the QPC environment variable is defined
|
||||
# and points to the QP/C installation directory
|
||||
#
|
||||
ifndef QPC
|
||||
$(error The QPC environment variable must be defined)
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# directories
|
||||
#
|
||||
|
||||
PROJECT := dpp-qk
|
||||
|
||||
QP_PORT_DIR := $(QPC)/ports/arm-cm/qk/gnu
|
||||
CMSIS_DIR := $(QPC)/ports/arm-cm/cmsis
|
||||
APP_DIR := .
|
||||
|
||||
# source directories
|
||||
VPATH = $(APP_DIR) \
|
||||
$(CMSIS_DIR)
|
||||
|
||||
# Output file basename
|
||||
OUTPUT := $(PROJECT)
|
||||
|
||||
# include directories
|
||||
INCLUDES = -I$(QPC)/include \
|
||||
-I$(QP_PORT_DIR) \
|
||||
-I. \
|
||||
-I$(CMSIS_DIR)
|
||||
|
||||
# defines
|
||||
DEFINES = -DTARGET_IS_BLIZZARD_RA1 -D__VFP_FP__ -D__FPU_PRESENT
|
||||
|
||||
ARM_CORE = cortex-m4
|
||||
ARM_FPU = vfp
|
||||
|
||||
LD_SCRIPT := $(PROJECT).ld
|
||||
LIBS := -lqp_$(ARM_CORE)f_cs
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# GNU ARM compiler
|
||||
#
|
||||
@ -64,40 +102,6 @@ RM := rm -rf
|
||||
MKDIR := mkdir
|
||||
RM := rm
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# NOTE: the Makefile expects that the QPC environment variable is defined
|
||||
# and points to the QP/C installation directory
|
||||
#
|
||||
ifndef QPC
|
||||
$(error The QPC environment variable must be defined)
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# directories
|
||||
#
|
||||
QP_PORT_DIR := $(QPC)/ports/arm-cm/qk/gnu
|
||||
CMSIS_DIR := $(QPC)/ports/arm-cm/cmsis
|
||||
APP_DIR := .
|
||||
|
||||
# source directories
|
||||
VPATH = $(APP_DIR) \
|
||||
$(CMSIS_DIR)
|
||||
|
||||
# Output file basename
|
||||
OUTPUT := $(PROJECT)
|
||||
|
||||
# include directories
|
||||
INCLUDES = -I$(QPC)/include \
|
||||
-I$(QP_PORT_DIR) \
|
||||
-I. \
|
||||
-I$(CMSIS_DIR)
|
||||
|
||||
# defines
|
||||
DEFINES = -DTARGET_IS_BLIZZARD_RA1 -D__VFP_FP__ -D__FPU_PRESENT
|
||||
|
||||
ARM_CORE = cortex-m4
|
||||
ARM_FPU = vfp
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# files
|
||||
#
|
||||
@ -111,9 +115,6 @@ C_SRCS := $(wildcard *.c)
|
||||
# C++ source files
|
||||
CPP_SRCS := $(wildcard *.cpp)
|
||||
|
||||
LD_SCRIPT := tm4c123gh6pm.ld
|
||||
LIBS := -lqp_$(ARM_CORE)f_cs
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# build options for various configurations
|
||||
#
|
||||
@ -219,7 +220,12 @@ $(BIN_DIR)/%.o : %.c
|
||||
$(BIN_DIR)/%.o : %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# include dependency files only if our goal depends on their existence
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(MAKECMDGOALS),show)
|
||||
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
.PHONY : clean
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: "Dining Philosophers Problem" example, preemptive QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Oct 06, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -109,7 +109,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
/* debounce the SW1 button... */
|
||||
btn = GPIOF->DATA_Bits[USR_SW1]; /* read the push btn */
|
||||
@ -202,7 +202,6 @@ void BSP_init(void) {
|
||||
if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */
|
||||
Q_ERROR();
|
||||
}
|
||||
QS_RESET();
|
||||
QS_OBJ_DICTIONARY(&l_SysTick_Handler);
|
||||
QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler);
|
||||
}
|
||||
@ -300,17 +299,16 @@ void QK_onIdle(void) {
|
||||
}
|
||||
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
for (;;) { /* NOTE: replace the loop with reset for final version */
|
||||
}
|
||||
void Q_onAssert(char const Q_ROM * const file, int_t line) {
|
||||
assert_failed(file, line);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
/* error routine that is called if the CMSIS library encounters an error */
|
||||
void assert_failed(char const *file, int line) {
|
||||
Q_onAssert(file, line);
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
ROM_SysCtlReset(); /* reset the system */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: GNU linker script for Tiva TM4C123GH6PM MCUs
|
||||
* Last Updated for Version: 5.0.0
|
||||
* Date of the Last Update: Aug 26, 2013
|
||||
* Product: Linker script for for EK-TM4C123GXL, GNU-ARM (Sourcery CodeBench)
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 17, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 2 of the License, or
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
@ -32,7 +32,6 @@
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(Reset_Handler) /* entry Point */
|
||||
@ -90,6 +89,13 @@ SECTIONS {
|
||||
|
||||
_etext = .; /* global symbols at end of code */
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = .;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
__stack_end__ = .;
|
||||
} >RAM
|
||||
|
||||
.data : AT (_etext) {
|
||||
__data_load = LOADADDR (.data);
|
||||
__data_start = .;
|
||||
@ -101,7 +107,7 @@ SECTIONS {
|
||||
} >RAM
|
||||
|
||||
.bss : {
|
||||
__bss_start__ = . ;
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
@ -115,18 +121,10 @@ SECTIONS {
|
||||
PROVIDE ( __end__ = _ebss );
|
||||
|
||||
.heap : {
|
||||
__heap_start__ = . ;
|
||||
__heap_start__ = .;
|
||||
. = . + HEAP_SIZE;
|
||||
. = ALIGN(4);
|
||||
__heap_end__ = . ;
|
||||
} >RAM
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = . ;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
__c_stack_top__ = . ;
|
||||
__stack_end__ = . ;
|
||||
__heap_end__ = .;
|
||||
} >RAM
|
||||
|
||||
/* Remove information from the standard libraries */
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./dpp.h
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/0) .................................................................*/
|
||||
#ifndef dpp_h
|
||||
#define dpp_h
|
||||
|
||||
@ -42,6 +50,8 @@ void Table_ctor(void);
|
||||
|
||||
|
||||
extern QActive * const AO_Philo[N_PHILO];
|
||||
|
||||
extern QActive * const AO_Table;
|
||||
|
||||
|
||||
#endif /* dpp_h */
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./philo.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/1) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -25,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -61,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -94,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -116,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -153,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -191,14 +227,14 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Purpose: CMSIS-compliant startup code for Tiva TM4C Cortex-M4F devices, GNU
|
||||
* Last Updated for Version: 5.0.0
|
||||
* Date of the Last Update: Aug 26, 2013
|
||||
* Product: CMSIS-compliant startup code for TM4C Cortex-M4F, GNU-ARM
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 24, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -32,79 +32,158 @@
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
void __attribute__ ((weak)) Reset_Handler(void);
|
||||
void __attribute__ ((weak)) NMI_Handler(void);
|
||||
void __attribute__ ((weak)) HardFault_Handler(void);
|
||||
void __attribute__ ((weak)) MemManage_Handler(void);
|
||||
void __attribute__ ((weak)) BusFault_Handler(void);
|
||||
void __attribute__ ((weak)) UsageFault_Handler(void);
|
||||
void __attribute__ ((weak)) MemManage_Handler(void);
|
||||
void __attribute__ ((weak)) SVC_Handler(void);
|
||||
void __attribute__ ((weak)) DebugMon_Handler(void);
|
||||
void __attribute__ ((weak)) PendSV_Handler(void);
|
||||
void __attribute__ ((weak)) SysTick_Handler(void);
|
||||
#include <stdint.h>
|
||||
#include "sysctl.h"
|
||||
#include "rom.h"
|
||||
|
||||
/* external interrupts... */
|
||||
void __attribute__ ((weak)) GPIOPortA_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortB_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortC_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortD_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortE_IRQHandler(void);
|
||||
void __attribute__ ((weak)) UART0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) UART1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) SSI0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) I2C0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMFault_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMGen0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMGen1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) PWMGen2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) QEI0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) ADCSeq3_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Watchdog_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer0A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer0B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer1A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer1B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer2A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer2B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Comp0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Comp1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Comp2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) SysCtrl_IRQHandler(void);
|
||||
void __attribute__ ((weak)) FlashCtrl_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortF_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortG_IRQHandler(void);
|
||||
void __attribute__ ((weak)) GPIOPortH_IRQHandler(void);
|
||||
void __attribute__ ((weak)) UART2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) SSI1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer3A_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Timer3B_IRQHandler(void);
|
||||
void __attribute__ ((weak)) I2C1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) QEI1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) CAN0_IRQHandler(void);
|
||||
void __attribute__ ((weak)) CAN1_IRQHandler(void);
|
||||
void __attribute__ ((weak)) CAN2_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Ethernet_IRQHandler(void);
|
||||
void __attribute__ ((weak)) Hibernate_IRQHandler(void);
|
||||
/* Function prototypes -----------------------------------------------------*/
|
||||
void Reset_Handler(void);
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void Spurious_Handler(void);
|
||||
|
||||
void assert_failed(char const *file, int line); /* defined in the BSP */
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* weak aliases for each Exception handler to the Spurious_Handler.
|
||||
* Any function with the same name will override these definitions.
|
||||
*/
|
||||
__attribute__ ((weak)) void SVC_Handler(void);
|
||||
__attribute__ ((weak)) void DebugMon_Handler(void);
|
||||
__attribute__ ((weak)) void PendSV_Handler(void);
|
||||
__attribute__ ((weak)) void SysTick_Handler(void);
|
||||
__attribute__ ((weak)) void Spurious_Handler(void);
|
||||
|
||||
/* external interrupts... */
|
||||
__attribute__ ((weak)) void GPIOPortA_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortB_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortC_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortD_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortE_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SSI0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMFault_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void QEI0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADCSeq3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Watchdog_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer0A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer0B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer1A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer1B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer2A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer2B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Comp0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Comp1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Comp2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SysCtrl_IRQHandler(void);
|
||||
__attribute__ ((weak)) void FlashCtrl_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortF_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortG_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortH_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SSI1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer3A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer3B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void QEI1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void CAN0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void CAN1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void CAN2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Ethernet_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Hibernate_IRQHandler(void);
|
||||
|
||||
__attribute__ ((weak)) void USB0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWMGen3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void uDMAST_IRQHandler(void);
|
||||
__attribute__ ((weak)) void uDMAError_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADC1Seq0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADC1Seq1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADC1Seq2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void ADC1Seq3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2S0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void EBI0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortJ_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortK_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortL_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SSI2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void SSI3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART4_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART5_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART6_IRQHandler(void);
|
||||
__attribute__ ((weak)) void UART7_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer4A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer4B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer5A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Timer5B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer0A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer0B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer1A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer1B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer2A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer2B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer3A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer3B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer4A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer4B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer5A_IRQHandler(void);
|
||||
__attribute__ ((weak)) void WideTimer5B_IRQHandler(void);
|
||||
__attribute__ ((weak)) void FPU_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PECI0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void LPC0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C4_IRQHandler(void);
|
||||
__attribute__ ((weak)) void I2C5_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortM_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortN_IRQHandler(void);
|
||||
__attribute__ ((weak)) void QEI2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void Fan0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP4_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP5_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP6_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortP7_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ4_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ5_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ6_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortQ7_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortR_IRQHandler(void);
|
||||
__attribute__ ((weak)) void GPIOPortS_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWM1Gen0_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWM1Gen1_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWM1Gen2_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWM1Gen3_IRQHandler(void);
|
||||
__attribute__ ((weak)) void PWM1Fault_IRQHandler(void);
|
||||
|
||||
void __attribute__ ((weak)) Spurious_Handler(void);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* weak aliases for each Exception handler to the Spurious_Handler.
|
||||
* Any function with the same name will override these definitions.
|
||||
*/
|
||||
#pragma weak NMI_Handler = Spurious_Handler
|
||||
#pragma weak MemManage_Handler = Spurious_Handler
|
||||
#pragma weak BusFault_Handler = Spurious_Handler
|
||||
#pragma weak UsageFault_Handler = Spurious_Handler
|
||||
#pragma weak SVC_Handler = Spurious_Handler
|
||||
#pragma weak DebugMon_Handler = Spurious_Handler
|
||||
#pragma weak PendSV_Handler = Spurious_Handler
|
||||
#pragma weak SysTick_Handler = Spurious_Handler
|
||||
|
||||
#pragma weak GPIOPortA_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortB_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortC_IRQHandler = Spurious_Handler
|
||||
@ -150,20 +229,92 @@ void __attribute__ ((weak)) Spurious_Handler(void);
|
||||
#pragma weak Ethernet_IRQHandler = Spurious_Handler
|
||||
#pragma weak Hibernate_IRQHandler = Spurious_Handler
|
||||
|
||||
/* exception and interrupt vector table ------------------------------------*/
|
||||
typedef void (*ExceptionHandler)(void);
|
||||
typedef union {
|
||||
ExceptionHandler handler;
|
||||
void *pointer;
|
||||
} VectorTableEntry;
|
||||
#pragma weak USB0_IRQHandler = Spurious_Handler
|
||||
#pragma weak PWMGen3_IRQHandler = Spurious_Handler
|
||||
#pragma weak uDMAST_IRQHandler = Spurious_Handler
|
||||
#pragma weak uDMAError_IRQHandler = Spurious_Handler
|
||||
#pragma weak ADC1Seq0_IRQHandler = Spurious_Handler
|
||||
#pragma weak ADC1Seq1_IRQHandler = Spurious_Handler
|
||||
#pragma weak ADC1Seq2_IRQHandler = Spurious_Handler
|
||||
#pragma weak ADC1Seq3_IRQHandler = Spurious_Handler
|
||||
#pragma weak I2S0_IRQHandler = Spurious_Handler
|
||||
#pragma weak EBI0_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortJ_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortK_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortL_IRQHandler = Spurious_Handler
|
||||
#pragma weak SSI2_IRQHandler = Spurious_Handler
|
||||
#pragma weak SSI3_IRQHandler = Spurious_Handler
|
||||
#pragma weak UART3_IRQHandler = Spurious_Handler
|
||||
#pragma weak UART4_IRQHandler = Spurious_Handler
|
||||
#pragma weak UART5_IRQHandler = Spurious_Handler
|
||||
#pragma weak UART6_IRQHandler = Spurious_Handler
|
||||
#pragma weak UART7_IRQHandler = Spurious_Handler
|
||||
#pragma weak I2C2_IRQHandler = Spurious_Handler
|
||||
#pragma weak I2C3_IRQHandler = Spurious_Handler
|
||||
#pragma weak Timer4A_IRQHandler = Spurious_Handler
|
||||
#pragma weak Timer4B_IRQHandler = Spurious_Handler
|
||||
#pragma weak Timer5A_IRQHandler = Spurious_Handler
|
||||
#pragma weak Timer5B_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer0A_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer0B_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer1A_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer1B_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer2A_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer2B_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer3A_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer3B_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer4A_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer4B_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer5A_IRQHandler = Spurious_Handler
|
||||
#pragma weak WideTimer5B_IRQHandler = Spurious_Handler
|
||||
#pragma weak FPU_IRQHandler = Spurious_Handler
|
||||
#pragma weak PECI0_IRQHandler = Spurious_Handler
|
||||
#pragma weak LPC0_IRQHandler = Spurious_Handler
|
||||
#pragma weak I2C4_IRQHandler = Spurious_Handler
|
||||
#pragma weak I2C5_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortM_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortN_IRQHandler = Spurious_Handler
|
||||
#pragma weak QEI2_IRQHandler = Spurious_Handler
|
||||
#pragma weak Fan0_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP0_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP1_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP2_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP3_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP4_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP5_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP6_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortP7_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ0_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ1_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ2_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ3_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ4_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ5_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ6_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortQ7_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortR_IRQHandler = Spurious_Handler
|
||||
#pragma weak GPIOPortS_IRQHandler = Spurious_Handler
|
||||
#pragma weak PWM1Gen0_IRQHandler = Spurious_Handler
|
||||
#pragma weak PWM1Gen1_IRQHandler = Spurious_Handler
|
||||
#pragma weak PWM1Gen2_IRQHandler = Spurious_Handler
|
||||
#pragma weak PWM1Gen3_IRQHandler = Spurious_Handler
|
||||
#pragma weak PWM1Fault_IRQHandler = Spurious_Handler
|
||||
|
||||
/* top of stack defined in the linker script */
|
||||
extern unsigned __c_stack_top__;
|
||||
|
||||
/* start and end of stack defined in the linker script ---------------------*/
|
||||
extern unsigned __stack_start__;
|
||||
extern unsigned __stack_end__;
|
||||
|
||||
/* exception and interrupt vector table ------------------------------------*/
|
||||
typedef union VectorTableEntryTag {
|
||||
void *pointer; /* used only to initialize the stack top */
|
||||
void (*handler)(void); /* used for all exception and interrupt handlers */
|
||||
} VectorTableEntry;
|
||||
|
||||
/*..........................................................................*/
|
||||
__attribute__ ((section(".isr_vector")))
|
||||
VectorTableEntry const g_pfnVectors[] = {
|
||||
{ .pointer = &__c_stack_top__ }, /* initial stack pointer */
|
||||
{ .pointer = &__stack_end__ }, /* initial stack pointer */
|
||||
{ .handler = &Reset_Handler }, /* Reset Handler */
|
||||
{ .handler = &NMI_Handler }, /* NMI Handler */
|
||||
{ .handler = &HardFault_Handler }, /* Hard Fault Handler */
|
||||
@ -180,57 +331,150 @@ VectorTableEntry const g_pfnVectors[] = {
|
||||
{ .handler = &PendSV_Handler }, /* PendSV Handler */
|
||||
{ .handler = &SysTick_Handler }, /* SysTick Handler */
|
||||
/* external interrupts (IRQs) ... */
|
||||
{ .handler = GPIOPortA_IRQHandler }, /* GPIO Port A */
|
||||
{ .handler = GPIOPortB_IRQHandler }, /* GPIO Port B */
|
||||
{ .handler = GPIOPortC_IRQHandler }, /* GPIO Port C */
|
||||
{ .handler = GPIOPortD_IRQHandler }, /* GPIO Port D */
|
||||
{ .handler = GPIOPortE_IRQHandler }, /* GPIO Port E */
|
||||
{ .handler = UART0_IRQHandler }, /* UART0 Rx and Tx */
|
||||
{ .handler = UART1_IRQHandler }, /* UART1 Rx and Tx */
|
||||
{ .handler = SSI0_IRQHandler }, /* SSI0 Rx and Tx */
|
||||
{ .handler = I2C0_IRQHandler }, /* I2C0 Master and Slave */
|
||||
{ .handler = PWMFault_IRQHandler }, /* PWM Fault */
|
||||
{ .handler = PWMGen0_IRQHandler }, /* PWM Generator 0 */
|
||||
{ .handler = PWMGen1_IRQHandler }, /* PWM Generator 1 */
|
||||
{ .handler = PWMGen2_IRQHandler }, /* PWM Generator 2 */
|
||||
{ .handler = QEI0_IRQHandler }, /* Quadrature Encoder 0 */
|
||||
{ .handler = ADCSeq0_IRQHandler }, /* ADC Sequence 0 */
|
||||
{ .handler = ADCSeq1_IRQHandler }, /* ADC Sequence 1 */
|
||||
{ .handler = ADCSeq2_IRQHandler }, /* ADC Sequence 2 */
|
||||
{ .handler = ADCSeq3_IRQHandler }, /* ADC Sequence 3 */
|
||||
{ .handler = Watchdog_IRQHandler }, /* Watchdog timer */
|
||||
{ .handler = Timer0A_IRQHandler }, /* Timer 0 subtimer A */
|
||||
{ .handler = Timer0B_IRQHandler }, /* Timer 0 subtimer B */
|
||||
{ .handler = Timer1A_IRQHandler }, /* Timer 1 subtimer A */
|
||||
{ .handler = Timer1B_IRQHandler }, /* Timer 1 subtimer B */
|
||||
{ .handler = Timer2A_IRQHandler }, /* Timer 2 subtimer A */
|
||||
{ .handler = Timer2B_IRQHandler }, /* Timer 2 subtimer B */
|
||||
{ .handler = Comp0_IRQHandler }, /* Analog Comparator 0 */
|
||||
{ .handler = Comp1_IRQHandler }, /* Analog Comparator 1 */
|
||||
{ .handler = Comp2_IRQHandler }, /* Analog Comparator 2 */
|
||||
{ .handler = SysCtrl_IRQHandler }, /* System Control (PLL,OSC,BO) */
|
||||
{ .handler = FlashCtrl_IRQHandler }, /* FLASH Control */
|
||||
{ .handler = GPIOPortF_IRQHandler }, /* GPIO Port F */
|
||||
{ .handler = GPIOPortG_IRQHandler }, /* GPIO Port G */
|
||||
{ .handler = GPIOPortH_IRQHandler }, /* GPIO Port H */
|
||||
{ .handler = UART2_IRQHandler }, /* UART2 Rx and Tx */
|
||||
{ .handler = SSI1_IRQHandler }, /* SSI1 Rx and Tx */
|
||||
{ .handler = Timer3A_IRQHandler }, /* Timer 3 subtimer A */
|
||||
{ .handler = Timer3B_IRQHandler }, /* Timer 3 subtimer B */
|
||||
{ .handler = I2C1_IRQHandler }, /* I2C1 Master and Slave */
|
||||
{ .handler = QEI1_IRQHandler }, /* Quadrature Encoder 1 */
|
||||
{ .handler = CAN0_IRQHandler }, /* CAN0 */
|
||||
{ .handler = CAN1_IRQHandler }, /* CAN1 */
|
||||
{ .handler = CAN2_IRQHandler }, /* CAN2 */
|
||||
{ .handler = Ethernet_IRQHandler }, /* Ethernet */
|
||||
{ .handler = Hibernate_IRQHandler }, /* Hibernate */
|
||||
{ .handler = &GPIOPortA_IRQHandler }, /* GPIO Port A */
|
||||
{ .handler = &GPIOPortB_IRQHandler }, /* GPIO Port B */
|
||||
{ .handler = &GPIOPortC_IRQHandler }, /* GPIO Port C */
|
||||
{ .handler = &GPIOPortD_IRQHandler }, /* GPIO Port D */
|
||||
{ .handler = &GPIOPortE_IRQHandler }, /* GPIO Port E */
|
||||
{ .handler = &UART0_IRQHandler }, /* UART0 Rx and Tx */
|
||||
{ .handler = &UART1_IRQHandler }, /* UART1 Rx and Tx */
|
||||
{ .handler = &SSI0_IRQHandler }, /* SSI0 Rx and Tx */
|
||||
{ .handler = &I2C0_IRQHandler }, /* I2C0 Master and Slave */
|
||||
{ .handler = &PWMFault_IRQHandler }, /* PWM Fault */
|
||||
{ .handler = &PWMGen0_IRQHandler }, /* PWM Generator 0 */
|
||||
{ .handler = &PWMGen1_IRQHandler }, /* PWM Generator 1 */
|
||||
{ .handler = &PWMGen2_IRQHandler }, /* PWM Generator 2 */
|
||||
{ .handler = &QEI0_IRQHandler }, /* Quadrature Encoder 0 */
|
||||
{ .handler = &ADCSeq0_IRQHandler }, /* ADC Sequence 0 */
|
||||
{ .handler = &ADCSeq1_IRQHandler }, /* ADC Sequence 1 */
|
||||
{ .handler = &ADCSeq2_IRQHandler }, /* ADC Sequence 2 */
|
||||
{ .handler = &ADCSeq3_IRQHandler }, /* ADC Sequence 3 */
|
||||
{ .handler = &Watchdog_IRQHandler }, /* Watchdog timer */
|
||||
{ .handler = &Timer0A_IRQHandler }, /* Timer 0 subtimer A */
|
||||
{ .handler = &Timer0B_IRQHandler }, /* Timer 0 subtimer B */
|
||||
{ .handler = &Timer1A_IRQHandler }, /* Timer 1 subtimer A */
|
||||
{ .handler = &Timer1B_IRQHandler }, /* Timer 1 subtimer B */
|
||||
{ .handler = &Timer2A_IRQHandler }, /* Timer 2 subtimer A */
|
||||
{ .handler = &Timer2B_IRQHandler }, /* Timer 2 subtimer B */
|
||||
{ .handler = &Comp0_IRQHandler }, /* Analog Comparator 0 */
|
||||
{ .handler = &Comp1_IRQHandler }, /* Analog Comparator 1 */
|
||||
{ .handler = &Comp2_IRQHandler }, /* Analog Comparator 2 */
|
||||
{ .handler = &SysCtrl_IRQHandler }, /* System Control (PLL,OSC,BO) */
|
||||
{ .handler = &FlashCtrl_IRQHandler }, /* FLASH Control */
|
||||
{ .handler = &GPIOPortF_IRQHandler }, /* GPIO Port F */
|
||||
{ .handler = &GPIOPortG_IRQHandler }, /* GPIO Port G */
|
||||
{ .handler = &GPIOPortH_IRQHandler }, /* GPIO Port H */
|
||||
{ .handler = &UART2_IRQHandler }, /* UART2 Rx and Tx */
|
||||
{ .handler = &SSI1_IRQHandler }, /* SSI1 Rx and Tx */
|
||||
{ .handler = &Timer3A_IRQHandler }, /* Timer 3 subtimer A */
|
||||
{ .handler = &Timer3B_IRQHandler }, /* Timer 3 subtimer B */
|
||||
{ .handler = &I2C1_IRQHandler }, /* I2C1 Master and Slave */
|
||||
{ .handler = &QEI1_IRQHandler }, /* Quadrature Encoder 1 */
|
||||
{ .handler = &CAN0_IRQHandler }, /* CAN0 */
|
||||
{ .handler = &CAN1_IRQHandler }, /* CAN1 */
|
||||
{ .handler = &CAN2_IRQHandler }, /* CAN2 */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Hibernate_IRQHandler }, /* Hibernate */
|
||||
{ .handler = &USB0_IRQHandler }, /* USB0 */
|
||||
{ .handler = &PWMGen3_IRQHandler }, /* PWM Generator 3 */
|
||||
{ .handler = &uDMAST_IRQHandler }, /* uDMA Software Transfer */
|
||||
{ .handler = &uDMAError_IRQHandler }, /* uDMA Error */
|
||||
{ .handler = &ADC1Seq0_IRQHandler }, /* ADC1 Sequence 0 */
|
||||
{ .handler = &ADC1Seq1_IRQHandler }, /* ADC1 Sequence 1 */
|
||||
{ .handler = &ADC1Seq2_IRQHandler }, /* ADC1 Sequence 2 */
|
||||
{ .handler = &ADC1Seq3_IRQHandler }, /* ADC1 Sequence 3 */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &GPIOPortJ_IRQHandler }, /* GPIO Port J */
|
||||
{ .handler = &GPIOPortK_IRQHandler }, /* GPIO Port K */
|
||||
{ .handler = &GPIOPortL_IRQHandler }, /* GPIO Port L */
|
||||
{ .handler = &SSI2_IRQHandler }, /* SSI2 Rx and Tx */
|
||||
{ .handler = &SSI3_IRQHandler }, /* SSI3 Rx and Tx */
|
||||
{ .handler = &UART3_IRQHandler }, /* UART3 Rx and Tx */
|
||||
{ .handler = &UART4_IRQHandler }, /* UART4 Rx and Tx */
|
||||
{ .handler = &UART5_IRQHandler }, /* UART5 Rx and Tx */
|
||||
{ .handler = &UART6_IRQHandler }, /* UART6 Rx and Tx */
|
||||
{ .handler = &UART7_IRQHandler }, /* UART7 Rx and Tx */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &I2C2_IRQHandler }, /* I2C2 Master and Slave */
|
||||
{ .handler = &I2C3_IRQHandler }, /* I2C3 Master and Slave */
|
||||
{ .handler = &Timer4A_IRQHandler }, /* Timer 4 subtimer A */
|
||||
{ .handler = &Timer4B_IRQHandler }, /* Timer 4 subtimer B */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Timer5A_IRQHandler }, /* Timer 5 subtimer A */
|
||||
{ .handler = &Timer5B_IRQHandler }, /* Timer 5 subtimer B */
|
||||
{ .handler = &WideTimer0A_IRQHandler }, /* Wide Timer 0 subtimer A */
|
||||
{ .handler = &WideTimer0B_IRQHandler }, /* Wide Timer 0 subtimer B */
|
||||
{ .handler = &WideTimer1A_IRQHandler }, /* Wide Timer 1 subtimer A */
|
||||
{ .handler = &WideTimer1B_IRQHandler }, /* Wide Timer 1 subtimer B */
|
||||
{ .handler = &WideTimer2A_IRQHandler }, /* Wide Timer 2 subtimer A */
|
||||
{ .handler = &WideTimer2B_IRQHandler }, /* Wide Timer 2 subtimer B */
|
||||
{ .handler = &WideTimer3A_IRQHandler }, /* Wide Timer 3 subtimer A */
|
||||
{ .handler = &WideTimer3B_IRQHandler }, /* Wide Timer 3 subtimer B */
|
||||
{ .handler = &WideTimer4A_IRQHandler }, /* Wide Timer 4 subtimer A */
|
||||
{ .handler = &WideTimer4B_IRQHandler }, /* Wide Timer 4 subtimer B */
|
||||
{ .handler = &WideTimer5A_IRQHandler }, /* Wide Timer 5 subtimer A */
|
||||
{ .handler = &WideTimer5B_IRQHandler }, /* Wide Timer 5 subtimer B */
|
||||
{ .handler = &FPU_IRQHandler }, /* FPU */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &I2C4_IRQHandler }, /* I2C4 Master and Slave */
|
||||
{ .handler = &I2C5_IRQHandler }, /* I2C5 Master and Slave */
|
||||
{ .handler = &GPIOPortM_IRQHandler }, /* GPIO Port M */
|
||||
{ .handler = &GPIOPortN_IRQHandler }, /* GPIO Port N */
|
||||
{ .handler = &QEI2_IRQHandler }, /* Quadrature Encoder 2 */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &Spurious_Handler }, /* Reserved */
|
||||
{ .handler = &GPIOPortP0_IRQHandler }, /* GPIO Port P (Summary or P0) */
|
||||
{ .handler = &GPIOPortP1_IRQHandler }, /* GPIO Port P1 */
|
||||
{ .handler = &GPIOPortP2_IRQHandler }, /* GPIO Port P2 */
|
||||
{ .handler = &GPIOPortP3_IRQHandler }, /* GPIO Port P3 */
|
||||
{ .handler = &GPIOPortP4_IRQHandler }, /* GPIO Port P4 */
|
||||
{ .handler = &GPIOPortP5_IRQHandler }, /* GPIO Port P5 */
|
||||
{ .handler = &GPIOPortP6_IRQHandler }, /* GPIO Port P6 */
|
||||
{ .handler = &GPIOPortP7_IRQHandler }, /* GPIO Port P7 */
|
||||
{ .handler = &GPIOPortQ0_IRQHandler }, /* GPIO Port Q (Summary or Q0) */
|
||||
{ .handler = &GPIOPortQ1_IRQHandler }, /* GPIO Port Q1 */
|
||||
{ .handler = &GPIOPortQ2_IRQHandler }, /* GPIO Port Q2 */
|
||||
{ .handler = &GPIOPortQ3_IRQHandler }, /* GPIO Port Q3 */
|
||||
{ .handler = &GPIOPortQ4_IRQHandler }, /* GPIO Port Q4 */
|
||||
{ .handler = &GPIOPortQ5_IRQHandler }, /* GPIO Port Q5 */
|
||||
{ .handler = &GPIOPortQ6_IRQHandler }, /* GPIO Port Q6 */
|
||||
{ .handler = &GPIOPortQ7_IRQHandler }, /* GPIO Port Q7 */
|
||||
{ .handler = &GPIOPortR_IRQHandler }, /* GPIO Port R */
|
||||
{ .handler = &GPIOPortS_IRQHandler }, /* GPIO Port S */
|
||||
{ .handler = &PWM1Gen0_IRQHandler }, /* PWM 1 Generator 0 */
|
||||
{ .handler = &PWM1Gen1_IRQHandler }, /* PWM 1 Generator 1 */
|
||||
{ .handler = &PWM1Gen2_IRQHandler }, /* PWM 1 Generator 2 */
|
||||
{ .handler = &PWM1Gen3_IRQHandler }, /* PWM 1 Generator 3 */
|
||||
{ .handler = &PWM1Fault_IRQHandler } /* PWM 1 Fault */
|
||||
};
|
||||
|
||||
/* function prototypes -----------------------------------------------------*/
|
||||
void assert_failed(char const *file, int line);
|
||||
|
||||
/*..........................................................................*/
|
||||
void Reset_Handler(void) __attribute__((__interrupt__));
|
||||
/* exception handlers ------------------------------------------------------*/
|
||||
__attribute__((naked)) void Reset_Handler(void);
|
||||
void Reset_Handler(void) {
|
||||
extern int main(void);
|
||||
extern int __libc_init_array(void);
|
||||
@ -247,34 +491,64 @@ void Reset_Handler(void) {
|
||||
for (dst = &__data_start; dst < &__data_end__; ++dst, ++src) {
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/* zero fill the .bss segment... */
|
||||
for (dst = &__bss_start__; dst < &__bss_end__; ++dst) {
|
||||
*dst = 0;
|
||||
}
|
||||
/* call all static constructors in C++ (harmless in C programs) */
|
||||
//__libc_init_array(); // incompatible ARMv4 ISO C Library in Sourcery
|
||||
/* call all static construcors in C++ (harmless in C programs) */
|
||||
__libc_init_array();
|
||||
|
||||
/* call the application's entry point */
|
||||
main();
|
||||
|
||||
/* in a bare-metal system main() has nothing to return to and it should
|
||||
* never return. Just in case main() returns, the assert_failed() gives
|
||||
* the last opportunity to catch this problem.
|
||||
/* Enable the floating-point unit. This must be done here to handle the
|
||||
* case where main() uses floating-point and the function prologue saves
|
||||
* floating-point registers (which will fault if floating-point is not
|
||||
* enabled). Any configuration of the floating-point unit using DriverLib
|
||||
* APIs must be done here prior to the floating-point unit being enabled.
|
||||
*/
|
||||
assert_failed("startup_lm4f", __LINE__);
|
||||
ROM_FPUEnable();
|
||||
|
||||
(void)main(); /* application's entry point, which should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void Spurious_Handler(void) __attribute__((__interrupt__));
|
||||
void Spurious_Handler(void) {
|
||||
assert_failed("startup_stm32f10x_cl", __LINE__);
|
||||
/* assert_failed() should not return, but just in case the following
|
||||
* enless loop will tie up the CPU.
|
||||
*/
|
||||
for (;;) {
|
||||
__attribute__((naked)) void NMI_Handler(void);
|
||||
void NMI_Handler(void) {
|
||||
assert_failed("NMI", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void MemManage_Handler(void);
|
||||
void MemManage_Handler(void) {
|
||||
assert_failed("MemManage", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void HardFault_Handler(void);
|
||||
void HardFault_Handler(void) {
|
||||
unsigned old_sp;
|
||||
__asm volatile ("mov %0,sp" : "=r" (old_sp));
|
||||
if (old_sp < (unsigned)&__stack_start__) { /* stack overflow? */
|
||||
unsigned new_sp = (unsigned)&__stack_end__;
|
||||
__asm volatile ("mov sp,%0" :: "r" (new_sp));
|
||||
assert_failed("StackOverflow", old_sp); /* should never return! */
|
||||
}
|
||||
else {
|
||||
assert_failed("HardFault", __LINE__); /* should never return! */
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void BusFault_Handler(void);
|
||||
void BusFault_Handler(void) {
|
||||
assert_failed("BusFault", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void UsageFault_Handler(void);
|
||||
void UsageFault_Handler(void) {
|
||||
assert_failed("UsageFault", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
__attribute__((naked)) void Spurious_Handler(void);
|
||||
void Spurious_Handler(void) {
|
||||
assert_failed("Spurious", __LINE__); /* should never return! */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void _init() {
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./table.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/2) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -26,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -48,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -59,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -83,57 +113,55 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -153,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -200,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -249,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -267,14 +300,14 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -219,8 +219,12 @@ $(BIN_DIR)/%.o : %.c
|
||||
$(BIN_DIR)/%.o : %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# include dependency files only if our goal depends on their existence
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(MAKECMDGOALS),show)
|
||||
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY : clean
|
||||
clean:
|
||||
|
@ -98,7 +98,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
QK_ISR_EXIT(); /* inform QK-nano about ISR exit */
|
||||
}
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./dpp.h
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/0) .................................................................*/
|
||||
#ifndef dpp_h
|
||||
#define dpp_h
|
||||
|
||||
@ -42,6 +50,8 @@ void Table_ctor(void);
|
||||
|
||||
|
||||
extern QActive * const AO_Philo[N_PHILO];
|
||||
|
||||
extern QActive * const AO_Table;
|
||||
|
||||
|
||||
#endif /* dpp_h */
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./philo.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/1) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -25,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -61,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -94,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -116,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -153,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -191,14 +227,14 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./table.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/2) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -26,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -48,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -59,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -83,57 +113,55 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -153,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -200,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -249,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -267,14 +300,14 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -219,8 +219,12 @@ $(BIN_DIR)/%.o : %.c
|
||||
$(BIN_DIR)/%.o : %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# include dependency files only if our goal depends on their existence
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(MAKECMDGOALS),show)
|
||||
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY : clean
|
||||
clean:
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example, LPCXpresso-1343 board, QK kernel, GNU/CodeRed
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 21, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -98,7 +98,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
QK_ISR_EXIT(); /* inform QK-nano about ISR exit */
|
||||
}
|
||||
@ -124,7 +124,6 @@ void BSP_init(void) {
|
||||
Q_ERROR();
|
||||
}
|
||||
|
||||
QS_RESET();
|
||||
QS_OBJ_DICTIONARY(&l_SysTick_Handler);
|
||||
QS_OBJ_DICTIONARY(&l_PIOINT0_IRQHandler);
|
||||
}
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./dpp.h
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/0) .................................................................*/
|
||||
#ifndef dpp_h
|
||||
#define dpp_h
|
||||
|
||||
@ -42,6 +50,8 @@ void Table_ctor(void);
|
||||
|
||||
|
||||
extern QActive * const AO_Philo[N_PHILO];
|
||||
|
||||
extern QActive * const AO_Table;
|
||||
|
||||
|
||||
#endif /* dpp_h */
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./philo.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/1) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -25,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -61,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -94,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -116,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -153,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -191,14 +227,14 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,19 @@
|
||||
* Model: dpp.qm
|
||||
* File: ./table.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/2) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -26,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -48,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -59,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -83,57 +113,55 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -153,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -200,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -249,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -267,14 +300,14 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -246,8 +246,12 @@ $(BIN_DIR)/%.o : %.c
|
||||
$(BIN_DIR)/%.o : %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# include dependency files only if our goal depends on their existence
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(MAKECMDGOALS),show)
|
||||
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY : clean
|
||||
clean:
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example, STM3210C-EVAL board, QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 19, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -87,7 +87,7 @@ void SysTick_Handler(void) {
|
||||
QS_tickTime_ += QS_tickPeriod_; /* account for the clock rollover */
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
|
||||
QK_ISR_EXIT(); /* inform QK-nano about ISR exit */
|
||||
}
|
||||
|
@ -1,12 +1,20 @@
|
||||
/*****************************************************************************
|
||||
* Model: dpp.qm
|
||||
* File: ././dpp.h
|
||||
* File: ./dpp.h
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/0) .................................................................*/
|
||||
#ifndef dpp_h
|
||||
#define dpp_h
|
||||
|
||||
@ -34,12 +42,16 @@ typedef struct TableEvtTag {
|
||||
/* number of philosophers */
|
||||
#define N_PHILO ((uint8_t)5)
|
||||
|
||||
/* @(/2/4) .................................................................*/
|
||||
void Philo_ctor(void);
|
||||
|
||||
/* @(/2/5) .................................................................*/
|
||||
void Table_ctor(void);
|
||||
|
||||
|
||||
extern QActive * const AO_Philo[N_PHILO];
|
||||
|
||||
extern QActive * const AO_Table;
|
||||
|
||||
|
||||
#endif /* dpp_h */
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.0">
|
||||
<documentation>Dining Philosopher Problem example</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="TableEvt" superclass="qpc::QEvt">
|
||||
@ -8,7 +10,7 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Philo" superclass="qpc::QActive">
|
||||
<class name="Philo" superclass="qpc::QMActive">
|
||||
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
<initial target="../1">
|
||||
@ -42,7 +44,7 @@ QActive_subscribe(&me->super, EAT_SIG);</action>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<state name="thinking">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);</entry>
|
||||
<tran trig="TIMEOUT" target="../../2">
|
||||
<tran_glyph conn="2,12,3,1,20,13,-3">
|
||||
<action box="0,-2,6,2"/>
|
||||
@ -86,7 +88,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="eating">
|
||||
<entry>QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);</entry>
|
||||
<entry>QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);</entry>
|
||||
<exit>TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);</exit>
|
||||
@ -110,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));</action>
|
||||
<state_diagram size="37,61"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Table" superclass="qpc::QActive">
|
||||
<class name="Table" superclass="qpc::QMActive">
|
||||
<attribute name="fork[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="isHungry[N_PHILO]" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<statechart>
|
||||
@ -316,15 +318,15 @@ me->fork[n] = FREE;</action>
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}</code>
|
||||
</operation>
|
||||
<operation name="Table_ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -424,5 +426,51 @@ QActive * const AO_Table = &l_table.super; /* "opaque" AO pointer
|
||||
$define(AOs::Table_ctor)
|
||||
$define(AOs::Table)</text>
|
||||
</file>
|
||||
<file name="main.c">
|
||||
<text>#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*..........................................................................*/
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
||||
|
@ -1,81 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Product: DPP example
|
||||
* Last Updated for Version: 4.5.02
|
||||
* Date of the Last Update: Jul 04, 2012
|
||||
* Model: dpp.qm
|
||||
* File: ./main.c
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/3) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/* Local-scope objects -----------------------------------------------------*/
|
||||
static QEvt const *l_tableQueueSto[N_PHILO];
|
||||
static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList l_subscrSto[MAX_PUB_SIG];
|
||||
|
||||
/* storage for event pools... */
|
||||
static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(void) {
|
||||
int main() {
|
||||
static QEvt const *tableQueueSto[N_PHILO];
|
||||
static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
|
||||
static QSubscrList subscrSto[MAX_PUB_SIG];
|
||||
static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */
|
||||
uint8_t n;
|
||||
|
||||
Philo_ctor(); /* instantiate all Philosopher active objects */
|
||||
Table_ctor(); /* instantiate the Table active object */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RT kernel */
|
||||
BSP_init(); /* initialize the BSP */
|
||||
BSP_init(); /* initialize the Board Support Package */
|
||||
|
||||
/* object dictionaries... */
|
||||
QS_OBJ_DICTIONARY(l_smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(l_tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
|
||||
QS_OBJ_DICTIONARY(smlPoolSto);
|
||||
QS_OBJ_DICTIONARY(tableQueueSto);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[0]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[1]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[2]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[3]);
|
||||
QS_OBJ_DICTIONARY(philoQueueSto[4]);
|
||||
|
||||
QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
|
||||
QF_psInit(subscrSto, Q_DIM(subscrSto)); /* init publish-subscribe */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
|
||||
|
||||
for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QActive_start(AO_Philo[n], (uint8_t)(n + 1),
|
||||
l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* start the active objects... */
|
||||
QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
|
||||
philoQueueSto[n], Q_DIM(philoQueueSto[n]),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
}
|
||||
QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
l_tableQueueSto, Q_DIM(l_tableQueueSto),
|
||||
QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
|
||||
tableQueueSto, Q_DIM(tableQueueSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,20 @@
|
||||
/*****************************************************************************
|
||||
* Model: dpp.qm
|
||||
* File: ././philo.c
|
||||
* File: ./philo.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/1) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/0) .................................................................*/
|
||||
typedef struct PhiloTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
QTimeEvt timeEvt;
|
||||
@ -25,9 +33,28 @@ typedef struct PhiloTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_thinking_e(Philo * const me);
|
||||
static QMState const Philo_thinking_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_thinking),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_hungry (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_hungry_e(Philo * const me);
|
||||
static QMState const Philo_hungry_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_hungry),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Philo_eating (Philo * const me, QEvt const * const e);
|
||||
static QState Philo_eating_e(Philo * const me);
|
||||
static QState Philo_eating_x(Philo * const me);
|
||||
static QMState const Philo_eating_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Philo_eating),
|
||||
Q_ACTION_CAST(&Philo_eating_x)
|
||||
};
|
||||
|
||||
|
||||
/* Local objects -----------------------------------------------------------*/
|
||||
@ -61,14 +88,18 @@ void Philo_ctor(void) {
|
||||
Philo *me;
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me = &l_philo[n];
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctor(&me->timeEvt, TIMEOUT_SIG);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
|
||||
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
|
||||
}
|
||||
}
|
||||
/* @(/2/0) .................................................................*/
|
||||
/* @(/2/0/1) ...............................................................*/
|
||||
/* @(/2/0/1/0) */
|
||||
static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
if (registered == (uint8_t)0) {
|
||||
@ -94,21 +125,23 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
|
||||
|
||||
QActive_subscribe(&me->super, EAT_SIG);
|
||||
return Q_TRAN(&Philo_thinking);
|
||||
return QM_INITIAL(&Philo_thinking_s, act_);
|
||||
}
|
||||
/* @(/2/0/1/1) .............................................................*/
|
||||
static QState Philo_thinking_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_thinking_s);
|
||||
}
|
||||
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_hungry);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_hungry_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_hungry_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/1/1) */
|
||||
@ -116,36 +149,38 @@ static QState Philo_thinking(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/2) .............................................................*/
|
||||
static QState Philo_hungry_e(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
return QM_ENTRY(&Philo_hungry_s);
|
||||
}
|
||||
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QACTIVE_POST(AO_Table, &pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/2/0) */
|
||||
case EAT_SIG: {
|
||||
/* @(/2/0/1/2/0/0) */
|
||||
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
|
||||
status = Q_TRAN(&Philo_eating);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_eating_s, act_);
|
||||
}
|
||||
else {
|
||||
status = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -153,37 +188,38 @@ static QState Philo_hungry(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/0/1/3) .............................................................*/
|
||||
static QState Philo_eating_e(Philo * const me) {
|
||||
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
|
||||
return QM_ENTRY(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating_x(Philo * const me) {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
return QM_EXIT(&Philo_eating_s);
|
||||
}
|
||||
static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
|
||||
pe->philoNum = PHILO_ID(me);
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/0) */
|
||||
case TIMEOUT_SIG: {
|
||||
status = Q_TRAN(&Philo_thinking);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Philo_eating_x),
|
||||
Q_ACTION_CAST(&Philo_thinking_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Philo_thinking_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/0/1/3/1) */
|
||||
@ -191,14 +227,14 @@ static QState Philo_eating(Philo * const me, QEvt const * const e) {
|
||||
case DONE_SIG: {
|
||||
/* EAT or DONE must be for other Philos than this one */
|
||||
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,20 @@
|
||||
/*****************************************************************************
|
||||
* Model: dpp.qm
|
||||
* File: ././table.c
|
||||
* File: ./table.c
|
||||
*
|
||||
* This file has been generated automatically by QP Modeler (QM).
|
||||
* DO NOT EDIT THIS FILE MANUALLY.
|
||||
* This code has been generated by QM tool (see state-machine.com/qm).
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* Please visit www.state-machine.com/qm for more information.
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*****************************************************************************/
|
||||
/* @(/3/2) .................................................................*/
|
||||
#include "qp_port.h"
|
||||
#include "dpp.h"
|
||||
#include "bsp.h"
|
||||
@ -17,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/1) .................................................................*/
|
||||
typedef struct TableTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t fork[N_PHILO];
|
||||
@ -26,9 +34,27 @@ typedef struct TableTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e);
|
||||
static QState Table_active(Table * const me, QEvt const * const e);
|
||||
static QState Table_serving(Table * const me, QEvt const * const e);
|
||||
static QState Table_paused(Table * const me, QEvt const * const e);
|
||||
static QState Table_active (Table * const me, QEvt const * const e);
|
||||
static QMState const Table_active_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Table_active),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_serving (Table * const me, QEvt const * const e);
|
||||
static QState Table_serving_e(Table * const me);
|
||||
static QMState const Table_serving_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_serving),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Table_paused (Table * const me, QEvt const * const e);
|
||||
static QState Table_paused_e(Table * const me);
|
||||
static QState Table_paused_x(Table * const me);
|
||||
static QMState const Table_paused_s = {
|
||||
&Table_active_s,
|
||||
Q_STATE_CAST(&Table_paused),
|
||||
Q_ACTION_CAST(&Table_paused_x)
|
||||
};
|
||||
|
||||
|
||||
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
|
||||
@ -48,7 +74,7 @@ void Table_ctor(void) {
|
||||
uint8_t n;
|
||||
Table *me = &l_table;
|
||||
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
|
||||
|
||||
for (n = 0U; n < N_PHILO; ++n) {
|
||||
me->fork[n] = FREE;
|
||||
@ -59,6 +85,10 @@ void Table_ctor(void) {
|
||||
/* @(/2/1/2) ...............................................................*/
|
||||
/* @(/2/1/2/0) */
|
||||
static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
uint8_t n;
|
||||
(void)e; /* suppress the compiler warning about unused parameter */
|
||||
|
||||
@ -83,57 +113,55 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "thinking");
|
||||
}
|
||||
return Q_TRAN(&Table_serving);
|
||||
return QM_INITIAL(&Table_serving_s, act_);
|
||||
}
|
||||
/* @(/2/1/2/1) .............................................................*/
|
||||
static QState Table_active(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/0) */
|
||||
case TERMINATE_SIG: {
|
||||
BSP_terminate(0);
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/1) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/2) ...........................................................*/
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
static QState Table_serving_e(Table * const me) {
|
||||
uint8_t n;
|
||||
for (n = 0U; n < N_PHILO; ++n) { /* give permissions to eat... */
|
||||
if ((me->isHungry[n] != 0U)
|
||||
&& (me->fork[LEFT(n)] == FREE)
|
||||
&& (me->fork[n] == FREE))
|
||||
{
|
||||
TableEvt *te;
|
||||
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
me->fork[LEFT(n)] = USED;
|
||||
me->fork[n] = USED;
|
||||
te = Q_NEW(TableEvt, EAT_SIG);
|
||||
te->philoNum = n;
|
||||
QF_PUBLISH(&te->super, me);
|
||||
me->isHungry[n] = 0U;
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
}
|
||||
}
|
||||
return QM_ENTRY(&Table_serving_s);
|
||||
}
|
||||
static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/2/0) */
|
||||
case HUNGRY_SIG: {
|
||||
uint8_t n, m;
|
||||
@ -153,12 +181,12 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
pe->philoNum = n;
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(n, "eating ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/1/2/1/2/0/1) */
|
||||
else {
|
||||
me->isHungry[n] = 1U;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -200,46 +228,51 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
|
||||
QF_PUBLISH(&pe->super, me);
|
||||
BSP_displayPhilStat(m, "eating ");
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/2) */
|
||||
case EAT_SIG: {
|
||||
Q_ERROR();
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/2/3) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_paused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_paused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/1/2/1/3) ...........................................................*/
|
||||
static QState Table_paused_e(Table * const me) {
|
||||
BSP_displayPaused(1U);
|
||||
return QM_ENTRY(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused_x(Table * const me) {
|
||||
BSP_displayPaused(0U);
|
||||
return QM_EXIT(&Table_paused_s);
|
||||
}
|
||||
static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
BSP_displayPaused(1U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3) */
|
||||
case Q_EXIT_SIG: {
|
||||
BSP_displayPaused(0U);
|
||||
status = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/0) */
|
||||
case PAUSE_SIG: {
|
||||
status = Q_TRAN(&Table_serving);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Table_paused_x),
|
||||
Q_ACTION_CAST(&Table_serving_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Table_serving_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/1) */
|
||||
@ -249,7 +282,7 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
Q_ASSERT((n < N_PHILO) && (me->isHungry[n] == 0U));
|
||||
me->isHungry[n] = 1U;
|
||||
BSP_displayPhilStat(n, "hungry ");
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/1/2/1/3/2) */
|
||||
@ -267,14 +300,14 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
|
||||
|
||||
me->fork[m] = FREE;
|
||||
me->fork[n] = FREE;
|
||||
status = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&Table_active);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="2.3.2">
|
||||
<item name="license"></item>
|
||||
<group name="locked"/>
|
||||
<group name="settings">
|
||||
<item name="tabs">1</item>
|
||||
<item name="windows">0</item>
|
||||
<item name="grid">3</item>
|
||||
</group>
|
||||
<group name="windows"/>
|
||||
<group name="search">
|
||||
<item name="options">4129280</item>
|
||||
<item name="replace">0</item>
|
||||
</group>
|
||||
<group name="vars"/>
|
||||
<group name="tools">
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
<group name="tool">
|
||||
<item name="icon">0</item>
|
||||
<item name="title"></item>
|
||||
<item name="command"></item>
|
||||
<item name="args"></item>
|
||||
<item name="initial"></item>
|
||||
<item name="options">0</item>
|
||||
</group>
|
||||
</group>
|
||||
</session>
|
@ -10,11 +10,6 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.codesourcery.arm_none_eabi.cdt.debug.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
|
@ -1,7 +1,7 @@
|
||||
##############################################################################
|
||||
# Product: "Fly 'n' Shoot" game, EK-LM3811, QK kernel, GNU/Sourcery G++
|
||||
# Last Updated for Version: 5.0.0
|
||||
# Date of the Last Update: Aug 25, 2013
|
||||
# Product: Makefile for EK-LM3811, QK kernel, GNU/Sourcery G++
|
||||
# Last Updated for Version: 5.2.0
|
||||
# Date of the Last Update: Dec 17, 2013
|
||||
#
|
||||
# Q u a n t u m L e a P s
|
||||
# ---------------------------
|
||||
@ -51,45 +51,25 @@ ifndef QPC
|
||||
$(error The QPC environment variable must be defined)
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# general utilities
|
||||
#
|
||||
RM = del
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# tools
|
||||
#
|
||||
ifeq ($(GNU_ARM),)
|
||||
GNU_ARM = C:/tools/CodeSourcery
|
||||
endif
|
||||
|
||||
CC := $(GNU_ARM)/bin/arm-none-eabi-gcc
|
||||
CPP := $(GNU_ARM)/bin/arm-none-eabi-g++
|
||||
AS := $(GNU_ARM)/bin/arm-none-eabi-as
|
||||
LINK := $(GNU_ARM)/bin/arm-none-eabi-gcc
|
||||
BIN := $(GNU_ARM)/bin/arm-none-eabi-objcopy
|
||||
RM := rm -rf
|
||||
MKDIR := mkdir
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# directories
|
||||
#
|
||||
|
||||
PROJECT := game-qk
|
||||
|
||||
QP_PORT_DIR := $(QPC)/ports/arm-cm/qk/gnu
|
||||
CMSIS_DIR := $(QPC)/ports/arm-cm/cmsis
|
||||
APP_DIR := .
|
||||
LIB_DIR :=
|
||||
|
||||
# source directories
|
||||
VPATH = $(APP_DIR) \
|
||||
$(CMSIS_DIR) \
|
||||
lwip_port/netif \
|
||||
webserver
|
||||
$(CMSIS_DIR)
|
||||
|
||||
# Output file basename
|
||||
OUTPUT := game-qk
|
||||
OUTPUT := $(PROJECT)
|
||||
|
||||
# include directories
|
||||
INCLUDES = -I$(QPC)/include \
|
||||
INCLUDES = -I$(QPC)/include \
|
||||
-I$(QP_PORT_DIR) \
|
||||
-I. \
|
||||
-I$(CMSIS_DIR)
|
||||
@ -98,6 +78,29 @@ INCLUDES = -I$(QPC)/include \
|
||||
DEFINES =
|
||||
|
||||
ARM_CORE = cortex-m3
|
||||
ARM_FPU =
|
||||
|
||||
LD_SCRIPT := $(PROJECT).ld
|
||||
LIBS := -lqp_$(ARM_CORE)_cs
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# GNU ARM compiler
|
||||
#
|
||||
ifeq ($(GNU_ARM),)
|
||||
GNU_ARM = C:/tools/CodeSourcery
|
||||
endif
|
||||
|
||||
##############################################################################
|
||||
# Typically, you should not need to change anything below this line
|
||||
|
||||
CC := $(GNU_ARM)/bin/arm-none-eabi-gcc
|
||||
CPP := $(GNU_ARM)/bin/arm-none-eabi-g++
|
||||
AS := $(GNU_ARM)/bin/arm-none-eabi-as
|
||||
LINK := $(GNU_ARM)/bin/arm-none-eabi-gcc
|
||||
BIN := $(GNU_ARM)/bin/arm-none-eabi-objcopy
|
||||
RM := rm -rf
|
||||
MKDIR := mkdir
|
||||
RM := rm
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# files
|
||||
@ -112,10 +115,6 @@ C_SRCS := $(wildcard *.c)
|
||||
# C++ source files
|
||||
CPP_SRCS := $(wildcard *.cpp)
|
||||
|
||||
|
||||
LD_SCRIPT := lm3s811.ld
|
||||
LIBS := -lqp_$(ARM_CORE)_cs
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# build options for various configurations
|
||||
#
|
||||
@ -218,7 +217,12 @@ $(BIN_DIR)/%.o : %.c
|
||||
$(BIN_DIR)/%.o : %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# include dependency files only if our goal depends on their existence
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(MAKECMDGOALS),show)
|
||||
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
.PHONY : clean
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*****************************************************************************
|
||||
* Product: "Fly 'n' Shoot" game example, preemptive QK kernel
|
||||
* Last Updated for Version: 5.1.0
|
||||
* Date of the Last Update: Sep 19, 2013
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 25, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
@ -110,7 +110,7 @@ void SysTick_Handler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
QF_TICK(&l_SysTick_Handler); /* process all armed time events */
|
||||
QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */
|
||||
QF_PUBLISH(&tickEvt, &l_SysTick_Handler); /* publish to all subscribers */
|
||||
|
||||
QK_ISR_EXIT(); /* infrom QK about exiting an ISR */
|
||||
@ -338,18 +338,16 @@ void QK_onIdle(void) {
|
||||
}
|
||||
|
||||
/*..........................................................................*/
|
||||
void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
QS_ASSERTION(file, line);
|
||||
for (;;) { /* NOTE: replace the loop with reset for final version */
|
||||
}
|
||||
void Q_onAssert(char const Q_ROM * const file, int_t line) {
|
||||
assert_failed(file, line);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
/* error routine that is called if the CMSIS library encounters an error */
|
||||
void assert_failed(char const *file, int line) {
|
||||
Q_onAssert(file, line);
|
||||
(void)file; /* avoid compiler warning */
|
||||
(void)line; /* avoid compiler warning */
|
||||
QF_INT_DISABLE(); /* make sure that all interrupts are disabled */
|
||||
NVIC_SystemReset(); /* perform system reset */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@ -435,8 +433,6 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
QS_FILTER_OFF(QS_QF_ISR_ENTRY);
|
||||
QS_FILTER_OFF(QS_QF_ISR_EXIT);
|
||||
|
||||
QS_RESET();
|
||||
|
||||
return (uint8_t)1; /* return success */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
|
@ -1,31 +1,44 @@
|
||||
/*****************************************************************************
|
||||
* Product: GNU linker script for Stellaris LM3S811 MCUs
|
||||
* Last Updated for Version: 4.1.03
|
||||
* Date of the Last Update: Mar 03, 2010
|
||||
* Last Updated for Version: 5.2.0
|
||||
* Date of the Last Update: Dec 03, 2013
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ---------------------------
|
||||
* innovating embedded systems
|
||||
*
|
||||
* Copyright (C) 2002-2010 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This software may be distributed and modified under the terms of the GNU
|
||||
* General Public License version 2 (GPL) as published by the Free Software
|
||||
* Foundation and appearing in the file GPL.TXT included in the packaging of
|
||||
* this file. Please note that GPL Section 2[b] requires that all works based
|
||||
* on this software must also be made publicly available under the terms of
|
||||
* the GPL ("Copyleft").
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alternatively, this software may be distributed and modified under the
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GPL and are specifically designed for licensees interested in
|
||||
* retaining the proprietary status of their code.
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* Quantum Leaps Web site: http://www.quantum-leaps.com
|
||||
* Quantum Leaps Web sites: http://www.quantum-leaps.com
|
||||
* http://www.state-machine.com
|
||||
* e-mail: info@quantum-leaps.com
|
||||
*****************************************************************************/
|
||||
|
||||
/* The size of the stack used by the application. NOTE: you need to adjust !*/
|
||||
STACK_SIZE = DEFINED( STACK_SIZE ) ? STACK_SIZE : 600;
|
||||
|
||||
/* The size of the heap used by the application. NOTE: you need to adjust ! */
|
||||
HEAP_SIZE = DEFINED( HEAP_SIZE ) ? HEAP_SIZE : 0;
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(Reset_Handler) /* entry Point */
|
||||
@ -35,12 +48,6 @@ MEMORY { /* memory map of LM3S811 */
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
/* The size of the stack used by the application. NOTE: you need to adjust */
|
||||
STACK_SIZE = 1500;
|
||||
|
||||
/* The size of the heap used by the application. NOTE: you need to adjust */
|
||||
HEAP_SIZE = 0;
|
||||
|
||||
SECTIONS {
|
||||
|
||||
.isr_vector : { /* the vector table goes FIRST into ROM */
|
||||
@ -83,6 +90,14 @@ SECTIONS {
|
||||
|
||||
_etext = .; /* global symbols at end of code */
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = . ;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
__c_stack_top__ = . ;
|
||||
__stack_end__ = . ;
|
||||
} >RAM
|
||||
|
||||
.data : AT (_etext) {
|
||||
__data_load = LOADADDR (.data);
|
||||
__data_start = .;
|
||||
@ -114,14 +129,6 @@ SECTIONS {
|
||||
__heap_end__ = . ;
|
||||
} >RAM
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = . ;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
__c_stack_top__ = . ;
|
||||
__stack_end__ = . ;
|
||||
} >RAM
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ : {
|
||||
libc.a ( * )
|
@ -114,22 +114,22 @@ enum GameBitmapIds {
|
||||
};
|
||||
|
||||
/* active objects' "constructors" */
|
||||
/* @(/2/9) .................................................................*/
|
||||
/* @(/2/8) .................................................................*/
|
||||
void Tunnel_ctor(void);
|
||||
|
||||
/* @(/2/10) ................................................................*/
|
||||
/* @(/2/9) .................................................................*/
|
||||
void Ship_ctor(void);
|
||||
|
||||
/* @(/2/11) ................................................................*/
|
||||
/* @(/2/10) ................................................................*/
|
||||
void Missile_ctor(void);
|
||||
|
||||
|
||||
/* instantiation of the Mines orthogonal components */
|
||||
/* @(/2/12) ................................................................*/
|
||||
QHsm * Mine1_ctor(uint8_t id);
|
||||
/* @(/2/11) ................................................................*/
|
||||
QMsm * Mine1_ctor(uint8_t id);
|
||||
|
||||
/* @(/2/13) ................................................................*/
|
||||
QHsm * Mine2_ctor(uint8_t id);
|
||||
/* @(/2/12) ................................................................*/
|
||||
QMsm * Mine2_ctor(uint8_t id);
|
||||
|
||||
|
||||
/* opaque pointers to active objects in the application */
|
||||
@ -141,7 +141,7 @@ extern QActive * const AO_Missile;
|
||||
|
||||
|
||||
/* helper function for all AOs */
|
||||
/* @(/2/8) .................................................................*/
|
||||
/* @(/2/13) ................................................................*/
|
||||
uint8_t do_bitmaps_overlap(
|
||||
uint8_t bmp_id1,
|
||||
uint8_t x1,
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="2.3.2">
|
||||
<documentation>"Fly 'n' Shoot" game model from Chapters 1 & 9 of PSiCC2</documentation>
|
||||
<model version="3.0.0">
|
||||
<documentation>"Fly 'n' Shoot" game model from Chapters 1 & 9 of PSiCC2
|
||||
|
||||
NOTE: Requries QP 5.</documentation>
|
||||
<framework name="qpc"/>
|
||||
<package name="Events" stereotype="0x01">
|
||||
<class name="ObjectPosEvt" superclass="qpc::QEvt">
|
||||
@ -20,13 +22,13 @@
|
||||
</class>
|
||||
</package>
|
||||
<package name="AOs" stereotype="0x02">
|
||||
<class name="Tunnel" superclass="qpc::QActive">
|
||||
<class name="Tunnel" superclass="qpc::QMActive">
|
||||
<documentation>Tunnel Active Object</documentation>
|
||||
<attribute name="blinkTimeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="screenTimeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mines[GAME_MINES_MAX]" type="QHsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine1_pool[GAME_MINES_MAX]" type="QHsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine2_pool[GAME_MINES_MAX]" type="QHsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mines[GAME_MINES_MAX]" type="QMsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine1_pool[GAME_MINES_MAX]" type="QMsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="mine2_pool[GAME_MINES_MAX]" type="QMsm *" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="blink_ctr" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="last_mine_x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="last_mine_y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -100,7 +102,7 @@ if ((me->last_mine_x + GAME_MINES_DIST_MIN < GAME_SCREEN_WIDTH)
|
||||
{
|
||||
uint8_t n;
|
||||
for (n = 0U; n < Q_DIM(me->mines); ++n) { /*look for disabled mines */
|
||||
if (me->mines[n] == (QHsm *)0) {
|
||||
if (me->mines[n] == (QMsm *)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -127,7 +129,7 @@ if ((me->last_mine_x + GAME_MINES_DIST_MIN < GAME_SCREEN_WIDTH)
|
||||
ope.super.sig = MINE_PLANT_SIG;
|
||||
ope.x = me->last_mine_x;
|
||||
ope.y = me->last_mine_y;
|
||||
QHsm_dispatch(me->mines[n], (QEvt *)&ope); /* direct dispatch */
|
||||
QMSM_DISPATCH(me->mines[n], (QEvt *)&ope); /* direct dispatch */
|
||||
}
|
||||
}
|
||||
</code>
|
||||
@ -163,8 +165,8 @@ for (x = 0U; x < w; ++x) {
|
||||
<code>uint8_t n;
|
||||
|
||||
for (n = 0U; n < GAME_MINES_MAX; ++n) {
|
||||
if (me->mines[n] != (QHsm *)0) { /* is the mine used? */
|
||||
QHsm_dispatch(me->mines[n], e);
|
||||
if (me->mines[n] != (QMsm *)0) { /* is the mine used? */
|
||||
QMSM_DISPATCH(me->mines[n], e);
|
||||
}
|
||||
}</code>
|
||||
</operation>
|
||||
@ -197,8 +199,8 @@ return (uint8_t)0;</code>
|
||||
<initial target="../1/2">
|
||||
<action>uint8_t n;
|
||||
for (n = 0U; n < GAME_MINES_MAX; ++n) {
|
||||
QHsm_init(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
|
||||
QHsm_init(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
|
||||
QMSM_INIT(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
|
||||
QMSM_INIT(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
|
||||
}
|
||||
randomSeed(1234); /* seed the pseudo-random generator */
|
||||
|
||||
@ -241,8 +243,8 @@ QS_SIG_DICTIONARY(SCORE_SIG, &l_tunnel);
|
||||
<state name="active">
|
||||
<tran trig="MINE_DISABLED">
|
||||
<action>Q_ASSERT((Q_EVT_CAST(MineEvt)->id < GAME_MINES_MAX)
|
||||
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QHsm *)0));
|
||||
me->mines[Q_EVT_CAST(MineEvt)->id] = (QHsm *)0;</action>
|
||||
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QMsm *)0));
|
||||
me->mines[Q_EVT_CAST(MineEvt)->id] = (QMsm *)0;</action>
|
||||
<tran_glyph conn="2,9,3,-1,14">
|
||||
<action box="0,-2,14,2"/>
|
||||
</tran_glyph>
|
||||
@ -253,10 +255,9 @@ me->mines[Q_EVT_CAST(MineEvt)->id] = (QHsm *)0;</action>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<state name="show_logo">
|
||||
<entry>QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*5U); /* 5 sec timeout */
|
||||
<entry>QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString(0U, 0U, " Quantum LeAps ");
|
||||
BSP_drawNString(0U, 1U, "state-machine.co");</entry>
|
||||
@ -306,10 +307,9 @@ me->minimal_gap = GAME_SCREEN_HEIGHT - 3U;
|
||||
memset(l_walls, (uint8_t)0,
|
||||
(GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8U));
|
||||
|
||||
QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*20U); /* 20s timeout */
|
||||
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*20U, 0U);
|
||||
|
||||
me->blink_ctr = 0U; /* init the blink counter */</entry>
|
||||
<exit>QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
@ -457,10 +457,9 @@ BSP_drawNString((GAME_SCREEN_WIDTH - 6U*10U)/2U + 6U*6U, 1U, str);</action>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state name="game_over">
|
||||
<entry>QTimeEvt_postEvery(&me->blinkTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/2U); /* 1/2 sec */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*5U); /* 5 sec timeout */
|
||||
<entry>QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
|
||||
BSP_TICKS_PER_SEC/2U);
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
|
||||
me->blink_ctr = 0U;
|
||||
BSP_drawNString((GAME_SCREEN_WIDTH - 6U*9U)/2U, 0U, "Game Over");</entry>
|
||||
<exit>QTimeEvt_disarm(&me->blinkTimeEvt);
|
||||
@ -499,8 +498,7 @@ BSP_drawNString((GAME_SCREEN_WIDTH - 6U*9U)/2, 0U,
|
||||
</tran>
|
||||
<state name="screen_saver_hide">
|
||||
<entry>BSP_displayOff(); /* power down the display */
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC*3U); /* 3s timeout */</entry>
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*3U, 0U);</entry>
|
||||
<exit>QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
BSP_displayOn(); /* power up the display */</exit>
|
||||
<tran trig="SCREEN_TIMEOUT" target="../../3">
|
||||
@ -523,8 +521,7 @@ Tunnel_addImageAt(me,
|
||||
(uint8_t)(rnd % (GAME_SCREEN_WIDTH - 55U)),
|
||||
(int8_t) (rnd % (GAME_SCREEN_HEIGHT - 8U)));
|
||||
BSP_drawBitmap(l_frame);
|
||||
QTimeEvt_postIn(&me->screenTimeEvt, (QActive *)me,
|
||||
BSP_TICKS_PER_SEC/3U); /* 1/3 sec timeout */</entry>
|
||||
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC/2U, 0U);</entry>
|
||||
<exit>QTimeEvt_disarm(&me->screenTimeEvt);
|
||||
/* clear the screen frame buffer */
|
||||
memset(l_frame, (uint8_t)0,
|
||||
@ -557,7 +554,7 @@ QF_stop(); /* stop QF and cleanup */</entry>
|
||||
<state_diagram size="68,94"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Ship" superclass="qpc::QActive">
|
||||
<class name="Ship" superclass="qpc::QMActive">
|
||||
<documentation>Ship Active Object</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -701,7 +698,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me);</action>
|
||||
<state_diagram size="41,67"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Missile" superclass="qpc::QActive">
|
||||
<class name="Missile" superclass="qpc::QMActive">
|
||||
<documentation>Missile Active Object</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -811,7 +808,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
|
||||
<state_diagram size="46,55"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Mine1" superclass="qpc::QHsm">
|
||||
<class name="Mine1" superclass="qpc::QMsm">
|
||||
<documentation>The Mine1 orthogonal component</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -975,7 +972,7 @@ QACTIVE_POST(AO_Missile, (QEvt *)&mine1_destroyed, me);</action>
|
||||
<state_diagram size="53,68"/>
|
||||
</statechart>
|
||||
</class>
|
||||
<class name="Mine2" superclass="qpc::QHsm">
|
||||
<class name="Mine2" superclass="qpc::QMsm">
|
||||
<documentation>The Mine2 orthogonal component</documentation>
|
||||
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
<attribute name="y" type="uint8_t" visibility="0x02" properties="0x00"/>
|
||||
@ -1150,6 +1147,48 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
|
||||
<attribute name="AO_Tunnel" type="QActive * const" visibility="0x00" properties="0x00"/>
|
||||
<attribute name="AO_Ship" type="QActive * const" visibility="0x00" properties="0x00"/>
|
||||
<attribute name="AO_Missile" type="QActive * const" visibility="0x00" properties="0x00"/>
|
||||
<operation name="Tunnel_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>uint8_t n;
|
||||
Tunnel *me = &l_tunnel;
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Tunnel_initial));
|
||||
QTimeEvt_ctorX(&me->blinkTimeEvt, &me->super, BLINK_TIMEOUT_SIG, 0U);
|
||||
QTimeEvt_ctorX(&me->screenTimeEvt, &me->super, SCREEN_TIMEOUT_SIG, 0U);
|
||||
for (n = 0; n < GAME_MINES_MAX; ++n) {
|
||||
me->mine1_pool[n] = Mine1_ctor(n); /* instantiate Mine1 in the pool */
|
||||
me->mine2_pool[n] = Mine2_ctor(n); /* instantiate Mine2 in the pool */
|
||||
me->mines[n] = (QMsm *)0; /* mine 'n' is unused */
|
||||
}
|
||||
me->last_mine_x = 0; /* the last mine at the right edge of the tunnel */
|
||||
me->last_mine_y = 0;</code>
|
||||
</operation>
|
||||
<operation name="Ship_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Ship *me = &l_ship;
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Ship_initial));
|
||||
me->x = GAME_SHIP_X;
|
||||
me->y = GAME_SHIP_Y;</code>
|
||||
</operation>
|
||||
<operation name="Missile_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Missile *me = &l_missile;
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Missile_initial));</code>
|
||||
</operation>
|
||||
<operation name="Mine1_ctor" type="QMsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine1 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine1[id];
|
||||
/* superclass' ctor */
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine1_initial));
|
||||
return (QMsm *)me;</code>
|
||||
</operation>
|
||||
<operation name="Mine2_ctor" type="QMsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine2 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine2[id];
|
||||
/* superclass' ctor */
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial));
|
||||
return (QMsm *)me;</code>
|
||||
</operation>
|
||||
<operation name="do_bitmaps_overlap" type="uint8_t" visibility="0x00" properties="0x00">
|
||||
<parameter name="bmp_id1" type="uint8_t"/>
|
||||
<parameter name="x1" type="uint8_t"/>
|
||||
@ -1158,48 +1197,6 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
|
||||
<parameter name="x2" type="uint8_t"/>
|
||||
<parameter name="y2" type="uint8_t"/>
|
||||
</operation>
|
||||
<operation name="Tunnel_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>uint8_t n;
|
||||
Tunnel *me = &l_tunnel;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Tunnel_initial);
|
||||
QTimeEvt_ctor(&me->blinkTimeEvt, BLINK_TIMEOUT_SIG);
|
||||
QTimeEvt_ctor(&me->screenTimeEvt, SCREEN_TIMEOUT_SIG);
|
||||
for (n = 0; n < GAME_MINES_MAX; ++n) {
|
||||
me->mine1_pool[n] = Mine1_ctor(n); /* instantiate Mine1 in the pool */
|
||||
me->mine2_pool[n] = Mine2_ctor(n); /* instantiate Mine2 in the pool */
|
||||
me->mines[n] = (QHsm *)0; /* mine 'n' is unused */
|
||||
}
|
||||
me->last_mine_x = 0; /* the last mine at the right edge of the tunnel */
|
||||
me->last_mine_y = 0;</code>
|
||||
</operation>
|
||||
<operation name="Ship_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Ship *me = &l_ship;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Ship_initial);
|
||||
me->x = GAME_SHIP_X;
|
||||
me->y = GAME_SHIP_Y;</code>
|
||||
</operation>
|
||||
<operation name="Missile_ctor" type="void" visibility="0x00" properties="0x01">
|
||||
<code>Missile *me = &l_missile;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Missile_initial);</code>
|
||||
</operation>
|
||||
<operation name="Mine1_ctor" type="QHsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine1 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine1[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine1_initial);
|
||||
return (QHsm *)me;</code>
|
||||
</operation>
|
||||
<operation name="Mine2_ctor" type="QHsm *" visibility="0x00" properties="0x01">
|
||||
<parameter name="id" type="uint8_t"/>
|
||||
<code>Mine2 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine2[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine2_initial);
|
||||
return (QHsm *)me;</code>
|
||||
</operation>
|
||||
</package>
|
||||
<directory name=".">
|
||||
<file name="game.h">
|
||||
@ -1658,17 +1655,17 @@ int main() {
|
||||
QS_SIG_DICTIONARY(GAME_OVER_SIG, (void *)0);
|
||||
|
||||
/* start the active objects... */
|
||||
QActive_start(AO_Missile,
|
||||
QACTIVE_START(AO_Missile,
|
||||
1U, /* priority */
|
||||
l_missileQueueSto, Q_DIM(l_missileQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Ship,
|
||||
QACTIVE_START(AO_Ship,
|
||||
2U, /* priority */
|
||||
l_shipQueueSto, Q_DIM(l_shipQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Tunnel,
|
||||
QACTIVE_START(AO_Tunnel,
|
||||
3U, /* priority */
|
||||
l_tunnelQueueSto, Q_DIM(l_tunnelQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
|
@ -62,17 +62,17 @@ int main() {
|
||||
QS_SIG_DICTIONARY(GAME_OVER_SIG, (void *)0);
|
||||
|
||||
/* start the active objects... */
|
||||
QActive_start(AO_Missile,
|
||||
QACTIVE_START(AO_Missile,
|
||||
1U, /* priority */
|
||||
l_missileQueueSto, Q_DIM(l_missileQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Ship,
|
||||
QACTIVE_START(AO_Ship,
|
||||
2U, /* priority */
|
||||
l_shipQueueSto, Q_DIM(l_shipQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
(QEvt *)0); /* no initialization event */
|
||||
QActive_start(AO_Tunnel,
|
||||
QACTIVE_START(AO_Tunnel,
|
||||
3U, /* priority */
|
||||
l_tunnelQueueSto, Q_DIM(l_tunnelQueueSto), /* evt queue */
|
||||
(void *)0, 0U, /* no per-thread stack */
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/3) .................................................................*/
|
||||
typedef struct Mine1Tag {
|
||||
/* protected: */
|
||||
QHsm super;
|
||||
QMsm super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -37,10 +37,32 @@ typedef struct Mine1Tag {
|
||||
|
||||
/* protected: */
|
||||
static QState Mine1_initial(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_unused(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_used(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_exploding(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_planted(Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_unused (Mine1 * const me, QEvt const * const e);
|
||||
static QMState const Mine1_unused_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine1_unused),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine1_used (Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_used_x(Mine1 * const me);
|
||||
static QMState const Mine1_used_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine1_used),
|
||||
Q_ACTION_CAST(&Mine1_used_x)
|
||||
};
|
||||
static QState Mine1_exploding (Mine1 * const me, QEvt const * const e);
|
||||
static QState Mine1_exploding_e(Mine1 * const me);
|
||||
static QMState const Mine1_exploding_s = {
|
||||
&Mine1_used_s,
|
||||
Q_STATE_CAST(&Mine1_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine1_planted (Mine1 * const me, QEvt const * const e);
|
||||
static QMState const Mine1_planted_s = {
|
||||
&Mine1_used_s,
|
||||
Q_STATE_CAST(&Mine1_planted),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
|
||||
/* local objects -----------------------------------------------------------*/
|
||||
@ -50,14 +72,14 @@ static Mine1 l_mine1[GAME_MINES_MAX]; /* a pool of type-1 mines */
|
||||
#define MINE_ID(me_) ((uint8_t)((me_) - l_mine1))
|
||||
|
||||
/* Mine1 class definition --------------------------------------------------*/
|
||||
/* @(/2/12) ................................................................*/
|
||||
QHsm * Mine1_ctor(uint8_t id) {
|
||||
/* @(/2/11) ................................................................*/
|
||||
QMsm * Mine1_ctor(uint8_t id) {
|
||||
Mine1 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine1[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine1_initial);
|
||||
return (QHsm *)me;
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine1_initial));
|
||||
return (QMsm *)me;
|
||||
}
|
||||
/* @(/2/3) .................................................................*/
|
||||
/* @(/2/3/3) ...............................................................*/
|
||||
@ -88,7 +110,7 @@ static QState Mine1_initial(Mine1 * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(MISSILE_IMG_SIG, me);
|
||||
|
||||
(void)e; /* avoid the "unreferenced parameter" warning */
|
||||
return Q_TRAN(&Mine1_unused);
|
||||
return QM_INITIAL(&Mine1_unused_s, QMsm_emptyAction_);
|
||||
}
|
||||
/* @(/2/3/3/1) .............................................................*/
|
||||
static QState Mine1_unused(Mine1 * const me, QEvt const * const e) {
|
||||
@ -98,51 +120,51 @@ static QState Mine1_unused(Mine1 * const me, QEvt const * const e) {
|
||||
case MINE_PLANT_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_TRAN(&Mine1_planted);
|
||||
status_ = QM_TRAN(&Mine1_planted_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/3/3/2) .............................................................*/
|
||||
static QState Mine1_used_x(Mine1 * const me) {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
return QM_EXIT(&Mine1_used_s);
|
||||
}
|
||||
static QState Mine1_used(Mine1 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/3/3/2) */
|
||||
case Q_EXIT_SIG: {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/3/3/2/0) */
|
||||
case MINE_RECYCLE_SIG: {
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/3/3/2/1) ...........................................................*/
|
||||
static QState Mine1_exploding_e(Mine1 * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Mine1_exploding_s);
|
||||
}
|
||||
static QState Mine1_exploding(Mine1 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/3/3/2/1) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/3/3/2/1/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/3/3/2/1/0/0) */
|
||||
@ -157,16 +179,20 @@ static QState Mine1_exploding(Mine1 * const me, QEvt const * const e) {
|
||||
oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */
|
||||
oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/3/3/2/1/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine1_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -188,11 +214,15 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
oie->y = me->y;
|
||||
oie->bmp = MINE1_BMP;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/3/3/2/2/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -203,6 +233,10 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/3/3/2/2/1/0) */
|
||||
if (do_bitmaps_overlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static MineEvt const mine1_hit = {
|
||||
{ HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
|
||||
1U /* type of the mine (1 for Mine type-1) */
|
||||
@ -210,10 +244,10 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);
|
||||
/* go straight to 'disabled' and let the Ship do
|
||||
* the exploding */
|
||||
status_ = Q_TRAN(&Mine1_unused);
|
||||
status_ = QM_TRAN(&Mine1_unused_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -224,20 +258,24 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/3/3/2/2/2/0) */
|
||||
if (do_bitmaps_overlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine1_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static ScoreEvt const mine1_destroyed = {
|
||||
{ DESTROYED_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
|
||||
25U /* score for destroying Mine type-1 */
|
||||
};
|
||||
QACTIVE_POST(AO_Missile, (QEvt *)&mine1_destroyed, me);
|
||||
status_ = Q_TRAN(&Mine1_exploding);
|
||||
status_ = QM_TRAN(&Mine1_exploding_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine1_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ Q_DEFINE_THIS_FILE
|
||||
/* @(/2/4) .................................................................*/
|
||||
typedef struct Mine2Tag {
|
||||
/* protected: */
|
||||
QHsm super;
|
||||
QMsm super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -37,10 +37,32 @@ typedef struct Mine2Tag {
|
||||
|
||||
/* protected: */
|
||||
static QState Mine2_initial(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_unused(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_used(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_planted(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_unused (Mine2 * const me, QEvt const * const e);
|
||||
static QMState const Mine2_unused_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine2_unused),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine2_used (Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_used_x(Mine2 * const me);
|
||||
static QMState const Mine2_used_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Mine2_used),
|
||||
Q_ACTION_CAST(&Mine2_used_x)
|
||||
};
|
||||
static QState Mine2_planted (Mine2 * const me, QEvt const * const e);
|
||||
static QMState const Mine2_planted_s = {
|
||||
&Mine2_used_s,
|
||||
Q_STATE_CAST(&Mine2_planted),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Mine2_exploding (Mine2 * const me, QEvt const * const e);
|
||||
static QState Mine2_exploding_e(Mine2 * const me);
|
||||
static QMState const Mine2_exploding_s = {
|
||||
&Mine2_used_s,
|
||||
Q_STATE_CAST(&Mine2_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
|
||||
/* local objects -----------------------------------------------------------*/
|
||||
@ -50,14 +72,14 @@ static Mine2 l_mine2[GAME_MINES_MAX]; /* a pool of type-2 mines */
|
||||
#define MINE_ID(me_) ((uint8_t)((me_) - l_mine2))
|
||||
|
||||
/* Mine2 class definition --------------------------------------------------*/
|
||||
/* @(/2/13) ................................................................*/
|
||||
QHsm * Mine2_ctor(uint8_t id) {
|
||||
/* @(/2/12) ................................................................*/
|
||||
QMsm * Mine2_ctor(uint8_t id) {
|
||||
Mine2 *me;
|
||||
Q_REQUIRE(id < GAME_MINES_MAX);
|
||||
me = &l_mine2[id];
|
||||
/* superclass' ctor */
|
||||
QHsm_ctor(&me->super, (QStateHandler)&Mine2_initial);
|
||||
return (QHsm *)me;
|
||||
QMsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial));
|
||||
return (QMsm *)me;
|
||||
}
|
||||
/* @(/2/4) .................................................................*/
|
||||
/* @(/2/4/3) ...............................................................*/
|
||||
@ -90,7 +112,7 @@ static QState Mine2_initial(Mine2 * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(MISSILE_IMG_SIG, me);
|
||||
|
||||
(void)e; /* avoid the "unreferenced parameter" warning */
|
||||
return Q_TRAN(&Mine2_unused);
|
||||
return QM_INITIAL(&Mine2_unused_s, QMsm_emptyAction_);
|
||||
}
|
||||
/* @(/2/4/3/1) .............................................................*/
|
||||
static QState Mine2_unused(Mine2 * const me, QEvt const * const e) {
|
||||
@ -100,36 +122,38 @@ static QState Mine2_unused(Mine2 * const me, QEvt const * const e) {
|
||||
case MINE_PLANT_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_TRAN(&Mine2_planted);
|
||||
status_ = QM_TRAN(&Mine2_planted_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/4/3/2) .............................................................*/
|
||||
static QState Mine2_used_x(Mine2 * const me) {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
return QM_EXIT(&Mine2_used_s);
|
||||
}
|
||||
static QState Mine2_used(Mine2 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/4/3/2) */
|
||||
case Q_EXIT_SIG: {
|
||||
/* tell the Tunnel that this mine is becoming disabled */
|
||||
MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG);
|
||||
mev->id = MINE_ID(me);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me);
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/4/3/2/0) */
|
||||
case MINE_RECYCLE_SIG: {
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -151,11 +175,15 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
oie->y = me->y;
|
||||
oie->bmp = MINE2_BMP;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/4/3/2/1/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -166,6 +194,10 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/4/3/2/1/1/0) */
|
||||
if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static MineEvt const mine1_hit = {
|
||||
{ HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
|
||||
2U /* type of the mine (2 for Mine type-2) */
|
||||
@ -173,10 +205,10 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);
|
||||
/* go straight to 'disabled' and let the Ship do
|
||||
* the exploding */
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -187,6 +219,10 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
|
||||
/* @(/2/4/3/2/1/2/0) */
|
||||
if (do_bitmaps_overlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) {
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
/* NOTE: Mine type-2 is nastier than Mine type-1.
|
||||
* The type-2 mine can hit the Ship with any of its
|
||||
* "tentacles". However, it can be destroyed by the
|
||||
@ -198,30 +234,28 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
|
||||
45U /* score for destroying Mine type-2 */
|
||||
};
|
||||
QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me);
|
||||
status_ = Q_TRAN(&Mine2_exploding);
|
||||
status_ = QM_TRAN(&Mine2_exploding_s, act_);
|
||||
}
|
||||
else {
|
||||
status_ = Q_UNHANDLED();
|
||||
status_ = QM_UNHANDLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine2_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/4/3/2/2) ...........................................................*/
|
||||
static QState Mine2_exploding_e(Mine2 * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Mine2_exploding_s);
|
||||
}
|
||||
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/4/3/2/2) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/4/3/2/2/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/4/3/2/2/0/0) */
|
||||
@ -236,16 +270,20 @@ static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) {
|
||||
oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */
|
||||
oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/4/3/2/2/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Mine2_unused);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Mine2_used_x),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Mine2_unused_s, act_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&Mine2_used);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
/* @(/2/2) .................................................................*/
|
||||
typedef struct MissileTag {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
QMActive super;
|
||||
|
||||
/* private: */
|
||||
uint8_t x;
|
||||
@ -35,9 +35,25 @@ typedef struct MissileTag {
|
||||
|
||||
/* protected: */
|
||||
static QState Missile_initial(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_armed(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_flying(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_exploding(Missile * const me, QEvt const * const e);
|
||||
static QState Missile_armed (Missile * const me, QEvt const * const e);
|
||||
static QMState const Missile_armed_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Missile_armed),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Missile_flying (Missile * const me, QEvt const * const e);
|
||||
static QMState const Missile_flying_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Missile_flying),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
static QState Missile_exploding (Missile * const me, QEvt const * const e);
|
||||
static QState Missile_exploding_e(Missile * const me);
|
||||
static QMState const Missile_exploding_s = {
|
||||
(QMState const *)0,
|
||||
Q_STATE_CAST(&Missile_exploding),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
|
||||
static Missile l_missile; /* the sole instance of the Missile active object */
|
||||
|
||||
@ -45,10 +61,10 @@ static Missile l_missile; /* the sole instance of the Missile active object */
|
||||
QActive * const AO_Missile = (QActive *)&l_missile; /* opaque pointer */
|
||||
|
||||
/* Active object definition ------------------------------------------------*/
|
||||
/* @(/2/11) ................................................................*/
|
||||
/* @(/2/10) ................................................................*/
|
||||
void Missile_ctor(void) {
|
||||
Missile *me = &l_missile;
|
||||
QActive_ctor(&me->super, (QStateHandler)&Missile_initial);
|
||||
QMActive_ctor(&me->super, Q_STATE_CAST(&Missile_initial));
|
||||
}
|
||||
/* @(/2/2) .................................................................*/
|
||||
/* @(/2/2/3) ...............................................................*/
|
||||
@ -67,7 +83,7 @@ static QState Missile_initial(Missile * const me, QEvt const * const e) {
|
||||
QS_SIG_DICTIONARY(MISSILE_FIRE_SIG, &l_missile); /* local signals */
|
||||
QS_SIG_DICTIONARY(HIT_WALL_SIG, &l_missile);
|
||||
QS_SIG_DICTIONARY(DESTROYED_MINE_SIG, &l_missile);
|
||||
return Q_TRAN(&Missile_armed);
|
||||
return QM_INITIAL(&Missile_armed_s, QMsm_emptyAction_);
|
||||
}
|
||||
/* @(/2/2/3/1) .............................................................*/
|
||||
static QState Missile_armed(Missile * const me, QEvt const * const e) {
|
||||
@ -77,11 +93,11 @@ static QState Missile_armed(Missile * const me, QEvt const * const e) {
|
||||
case MISSILE_FIRE_SIG: {
|
||||
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
|
||||
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
|
||||
status_ = Q_TRAN(&Missile_flying);
|
||||
status_ = QM_TRAN(&Missile_flying_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -103,42 +119,44 @@ static QState Missile_flying(Missile * const me, QEvt const * const e) {
|
||||
oie->y = me->y;
|
||||
oie->bmp = MISSILE_BMP;
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/2/3/2/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Missile_armed);
|
||||
status_ = QM_TRAN(&Missile_armed_s, QMsm_emptyAction_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* @(/2/2/3/2/1) */
|
||||
case HIT_WALL_SIG: {
|
||||
status_ = Q_TRAN(&Missile_exploding);
|
||||
static QActionHandler const act_[] = {
|
||||
Q_ACTION_CAST(&Missile_exploding_e),
|
||||
Q_ACTION_CAST(0)
|
||||
};
|
||||
status_ = QM_TRAN(&Missile_exploding_s, act_);
|
||||
break;
|
||||
}
|
||||
/* @(/2/2/3/2/2) */
|
||||
case DESTROYED_MINE_SIG: {
|
||||
QACTIVE_POST(AO_Ship, e, me);
|
||||
status_ = Q_TRAN(&Missile_armed);
|
||||
status_ = QM_TRAN(&Missile_armed_s, QMsm_emptyAction_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status_;
|
||||
}
|
||||
/* @(/2/2/3/3) .............................................................*/
|
||||
static QState Missile_exploding_e(Missile * const me) {
|
||||
me->exp_ctr = 0U;
|
||||
return QM_ENTRY(&Missile_exploding_s);
|
||||
}
|
||||
static QState Missile_exploding(Missile * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/* @(/2/2/3/3) */
|
||||
case Q_ENTRY_SIG: {
|
||||
me->exp_ctr = 0U;
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/* @(/2/2/3/3/0) */
|
||||
case TIME_TICK_SIG: {
|
||||
/* @(/2/2/3/3/0/0) */
|
||||
@ -154,16 +172,16 @@ static QState Missile_exploding(Missile * const me, QEvt const * const e) {
|
||||
oie->y = (int8_t)((int)me->y - 4U); /* y-pos */
|
||||
oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2);
|
||||
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
|
||||
status_ = Q_HANDLED();
|
||||
status_ = QM_HANDLED();
|
||||
}
|
||||
/* @(/2/2/3/3/0/1) */
|
||||
else {
|
||||
status_ = Q_TRAN(&Missile_armed);
|
||||
status_ = QM_TRAN(&Missile_armed_s, QMsm_emptyAction_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
status_ = QM_SUPER();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user