This commit is contained in:
Quantum Leaps 2016-11-30 18:14:20 -05:00
parent 3f1930993f
commit 33d17c2dbd
188 changed files with 30759 additions and 30236 deletions

1
.gitignore vendored
View File

@ -32,6 +32,7 @@
lint*.txt
*.Miro
*.bak
*.qlc
JLink*.*
eclipse/

View File

@ -1,136 +0,0 @@
/* ----------------------------------------------------------------------
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
*
* $Date: 19. October 2015
* $Revision: V.1.4.5 a
*
* Project: CMSIS DSP Library
* Title: arm_common_tables.h
*
* Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
*
* Target Processor: Cortex-M4/Cortex-M3
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of ARM LIMITED nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------- */
#ifndef _ARM_COMMON_TABLES_H
#define _ARM_COMMON_TABLES_H
#include "arm_math.h"
extern const uint16_t armBitRevTable[1024];
extern const q15_t armRecipTableQ15[64];
extern const q31_t armRecipTableQ31[64];
/* extern const q31_t realCoefAQ31[1024]; */
/* extern const q31_t realCoefBQ31[1024]; */
extern const float32_t twiddleCoef_16[32];
extern const float32_t twiddleCoef_32[64];
extern const float32_t twiddleCoef_64[128];
extern const float32_t twiddleCoef_128[256];
extern const float32_t twiddleCoef_256[512];
extern const float32_t twiddleCoef_512[1024];
extern const float32_t twiddleCoef_1024[2048];
extern const float32_t twiddleCoef_2048[4096];
extern const float32_t twiddleCoef_4096[8192];
#define twiddleCoef twiddleCoef_4096
extern const q31_t twiddleCoef_16_q31[24];
extern const q31_t twiddleCoef_32_q31[48];
extern const q31_t twiddleCoef_64_q31[96];
extern const q31_t twiddleCoef_128_q31[192];
extern const q31_t twiddleCoef_256_q31[384];
extern const q31_t twiddleCoef_512_q31[768];
extern const q31_t twiddleCoef_1024_q31[1536];
extern const q31_t twiddleCoef_2048_q31[3072];
extern const q31_t twiddleCoef_4096_q31[6144];
extern const q15_t twiddleCoef_16_q15[24];
extern const q15_t twiddleCoef_32_q15[48];
extern const q15_t twiddleCoef_64_q15[96];
extern const q15_t twiddleCoef_128_q15[192];
extern const q15_t twiddleCoef_256_q15[384];
extern const q15_t twiddleCoef_512_q15[768];
extern const q15_t twiddleCoef_1024_q15[1536];
extern const q15_t twiddleCoef_2048_q15[3072];
extern const q15_t twiddleCoef_4096_q15[6144];
extern const float32_t twiddleCoef_rfft_32[32];
extern const float32_t twiddleCoef_rfft_64[64];
extern const float32_t twiddleCoef_rfft_128[128];
extern const float32_t twiddleCoef_rfft_256[256];
extern const float32_t twiddleCoef_rfft_512[512];
extern const float32_t twiddleCoef_rfft_1024[1024];
extern const float32_t twiddleCoef_rfft_2048[2048];
extern const float32_t twiddleCoef_rfft_4096[4096];
/* floating-point bit reversal tables */
#define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
#define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
#define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
#define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
#define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
#define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
#define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
#define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
#define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH];
/* fixed-point bit reversal tables */
#define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
#define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
#define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
#define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
#define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
#define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
#define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
#define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
#define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
/* Tables for Fast Math Sine and Cosine */
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
#endif /* ARM_COMMON_TABLES_H */

View File

@ -1,79 +0,0 @@
/* ----------------------------------------------------------------------
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
*
* $Date: 19. March 2015
* $Revision: V.1.4.5
*
* Project: CMSIS DSP Library
* Title: arm_const_structs.h
*
* Description: This file has constant structs that are initialized for
* user convenience. For example, some can be given as
* arguments to the arm_cfft_f32() function.
*
* Target Processor: Cortex-M4/Cortex-M3
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of ARM LIMITED nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------- */
#ifndef _ARM_CONST_STRUCTS_H
#define _ARM_CONST_STRUCTS_H
#include "arm_math.h"
#include "arm_common_tables.h"
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048;
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048;
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096;
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,199 +0,0 @@
//*****************************************************************************
//
// Copyright (C) 2012 - 2014 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// MSP432 Family CMSIS Definitions
//
//****************************************************************************
#ifndef CMSIS_CCS_H_
#define CMSIS_CCS_H_
// Data Synchronization Barrier
__attribute__( ( always_inline ) ) static inline void __DSB(void)
{
__asm(" dsb");
}
#if (0)
// Get Main Stack Pointer
static inline uint32_t __get_MSP(void)
{
register uint32_t result;
//__asm (" mrs result, msp");
return(result);
}
// Set Main Stack Pointer
static inline void __set_MSP(uint32_t topOfMainStack)
{
asm(" .global topOfMainStack");
__asm (" msr msp, topOfMainStack");
}
// Get Priority Mask
static inline uint32_t __get_PRIMASK(void)
{
uint32_t result;
__asm (" mrs result, primask");
return(result);
}
// Set Priority Mask
static inline void __set_PRIMASK(uint32_t priMask)
{
__asm (" msr primask, priMask");
}
#endif
//
// v5e, v6, Cortex-M3, Cortex-M4, Cortex-R4, and Cortex-A8 compiler intrinsics
//
#define __CLZ _norm
#define __SXTB _sxtb
#define __SXTH _sxth
#define __UXTB _uxtb
#define __UXTH _uxth
#define __NOP __nop
#define __WFI __wfi
// CCS supports intrinsics to take advantage of the shift operand left/right
// before saturation extension of SSAT, but CMSIS does not take advantage
// of those, so tell the compiler to use a sat & shift left with a shift
// value of 0 whenever it encounters an SSAT
#define __SSAT(VAL, BITPOS) \
_ssatl(VAL , 0, BITPOS)
//
// Only define M4 based intrinsics if we're not using an M4
//
#if defined (__TI_TMS470_V7M4__)
//
// V5E, V6, Cortex-M4, Cortex-R4, and Cortex-A8 compiler intrinsics
//
#define __QADD _sadd
#define __QDADD _sdadd
#define __QDSUB _sdsub
#define __SMLABB _smlabb
#define __SMLABT _smlabt
#define __SMLALBB _smlalbb
#define __SMLALBT _smlalbt
#define __SMLALTB _smlaltb
#define __SMLALTT _smlaltt
#define __SMLATB _smlatb
#define __SMLATT _smlatt
#define __SMLAWB _smlawb
#define __SMLAWT _smlawt
#define __SMULBB _smulbb
#define __SMULBT _smulbt
#define __SMULTB _smultb
#define __SMULTT _smultt
#define __SMULWB _smulwb
#define __SMULWT _smulwt
#define __QSUB _ssub
#define __SUBC _subc
//
// v6, Cortex-M4, Cortex-R4, and Cortex-A8 compiler intrinsics
//
#define __SHASX _shaddsubx
#define __SHSAX _shsubaddx
#define __PKHBT _pkhbt
#define __PKHTB _pkhtb
#define __QADD16 _qadd16
#define __QADD8 _qadd8
#define __QSUB16 _qsub16
#define __QSUB8 _qsub8
#define __QASX _saddsubx
#define __QSAX _qsubaddx
#define __SADD16 _sadd16
#define __SADD8 _sadd8
#define __SASX _saddsubx
#define __SEL _sel
#define __SHADD16 _shadd16
#define __SHADD8 _shadd8
#define __SHSUB16 _shsub16
#define __SHSUB8 _shsub8
#define __SMLAD _smlad
#define __SMLADX _smladx
#define __SMLALD _smlald
#define __SMLALDX _smlaldx
#define __SMLSD _smlsd
#define __SMLSDX _smlsdx
#define __SMLSLD _smlsld
#define __SMLSLDX _smlsldx
#define __SMMLA _smmla
#define __SMMLAR _smmlar
#define __SMMLS _smmls
#define __SMMLSR _smmlsr
#define __SMMUL _smmul
#define __SMMULR _smmulr
#define __SMUAD _smuad
#define __SMUADX _smuadx
#define __SMUSD _smusd
#define __SMUSDX _smusd
#define __SSAT16 _ssat16
#define __SSUB16 _ssub16
#define __SSUB8 _ssub8
#define __SSAX _ssubaddx
#define __SXTAB _sxtab
#define __SXTAB16 _sxtab16
#define __SXTAH _sxtah
#define __UMAAL _umaal
#define __UADD16 _uadd16
#define __UADD8 _uadd8
#define __UHADD16 _uhadd16
#define __UHADD8 _uhadd8
#define __UASX _uaddsubx
#define __UHSUB16 _uhsub16
#define __UHSUB8 _uhsub8
#define __UQADD16 _uqadd16
#define __UQADD8 _uqadd8
#define __UQASX _uqaddsubx
#define __UQSUB16 _uqsub16
#define __UQSUB8 _uqsub8
#define __UQSAX _uqsubaddx
#define __USAD8 _usad8
#define __USAT16 _usat16
#define __USUB16 _usub16
#define __USUB8 _usub8
#define __USAX _usubaddx
#define __UXTAB _uxtab
#define __UXTAB16 _uxtab16
#define __UXTAH _uxtah
#define __UXTB16 _uxtb16
#endif /*__TI_TMS470_V7M4__*/
#endif /*CMSIS_CCS_H_*/

211
3rd_party/CMSIS/Include/cmsis_compiler.h vendored Normal file
View File

@ -0,0 +1,211 @@
/**************************************************************************//**
* @file cmsis_compiler.h
* @brief CMSIS compiler specific macros, functions, instructions
* @version V5.00
* @date 09. November 2016
******************************************************************************/
/*
* Copyright (c) 2009-2016 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_COMPILER_H
#define __CMSIS_COMPILER_H
#include <stdint.h>
/*
* ARM Compiler 4/5
*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*
* ARM Compiler 6 (armclang)
*/
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armclang.h"
/*
* GNU Compiler
*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*
* IAR Compiler
*/
#elif defined ( __ICCARM__ )
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#include <cmsis_iar.h>
#ifndef __NO_RETURN
#define __NO_RETURN __noreturn
#endif
#ifndef __USED
#define __USED __root
#endif
#ifndef __WEAK
#define __WEAK __weak
#endif
#ifndef __UNALIGNED_UINT32
__packed struct T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __ALIGNED
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
#define __ALIGNED(x)
#endif
#ifndef __PACKED
#define __PACKED __packed
#endif
/*
* TI ARM Compiler
*/
#elif defined ( __TI_ARM__ )
#include <cmsis_ccs.h>
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __UNALIGNED_UINT32
struct __attribute__((packed)) T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed))
#endif
/*
* TASKING Compiler
*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __UNALIGNED_UINT32
struct __packed__ T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __align(x)
#endif
#ifndef __PACKED
#define __PACKED __packed__
#endif
/*
* COSMIC Compiler
*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#ifndef __ASM
#define __ASM _asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __NO_RETURN
// NO RETURN is automatically detected hence no warning here
#define __NO_RETURN
#endif
#ifndef __USED
#warning No compiler specific solution for __USED. __USED is ignored.
#define __USED
#endif
#ifndef __WEAK
#define __WEAK __weak
#endif
#ifndef __UNALIGNED_UINT32
@packed struct T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __ALIGNED
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
#define __ALIGNED(x)
#endif
#ifndef __PACKED
#define __PACKED @packed
#endif
#else
#error Unknown compiler.
#endif
#endif /* __CMSIS_COMPILER_H */

File diff suppressed because it is too large Load Diff

1865
3rd_party/CMSIS/Include/core_armv8mbl.h vendored Normal file

File diff suppressed because it is too large Load Diff

2879
3rd_party/CMSIS/Include/core_armv8mml.h vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1865
3rd_party/CMSIS/Include/core_cm23.h vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2879
3rd_party/CMSIS/Include/core_cm33.h vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +0,0 @@
/**************************************************************************//**
* @file core_cmFunc.h
* @brief CMSIS Cortex-M Core Function Access Header File
* @version V4.30
* @date 20. October 2015
******************************************************************************/
/* Copyright (c) 2009 - 2015 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CMFUNC_H
#define __CORE_CMFUNC_H
/* ########################### Core Function Access ########################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
@{
*/
/*------------------ RealView Compiler -----------------*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*------------------ ARM Compiler V6 -------------------*/
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armcc_V6.h"
/*------------------ GNU Compiler ----------------------*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*------------------ ICC Compiler ----------------------*/
#elif defined ( __ICCARM__ )
#include <cmsis_iar.h>
/*------------------ TI CCS Compiler -------------------*/
#elif defined ( __TMS470__ )
#include <cmsis_ccs.h>
/*------------------ TASKING Compiler ------------------*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
/*------------------ COSMIC Compiler -------------------*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#endif
/*@} end of CMSIS_Core_RegAccFunctions */
#endif /* __CORE_CMFUNC_H */

View File

@ -1,87 +0,0 @@
/**************************************************************************//**
* @file core_cmInstr.h
* @brief CMSIS Cortex-M Core Instruction Access Header File
* @version V4.30
* @date 20. October 2015
******************************************************************************/
/* Copyright (c) 2009 - 2015 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CMINSTR_H
#define __CORE_CMINSTR_H
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
/*------------------ RealView Compiler -----------------*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*------------------ ARM Compiler V6 -------------------*/
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armcc_V6.h"
/*------------------ GNU Compiler ----------------------*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*------------------ ICC Compiler ----------------------*/
#elif defined ( __ICCARM__ )
#include <cmsis_iar.h>
/*------------------ TI CCS Compiler -------------------*/
#elif defined ( __TMS470__ )
#include <cmsis_ccs.h>
/*------------------ TASKING Compiler ------------------*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
/*------------------ COSMIC Compiler -------------------*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#endif
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
#endif /* __CORE_CMINSTR_H */

View File

@ -1,96 +0,0 @@
/**************************************************************************//**
* @file core_cmSimd.h
* @brief CMSIS Cortex-M SIMD Header File
* @version V4.30
* @date 20. October 2015
******************************************************************************/
/* Copyright (c) 2009 - 2015 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CMSIMD_H
#define __CORE_CMSIMD_H
#ifdef __cplusplus
extern "C" {
#endif
/* ################### Compiler specific Intrinsics ########################### */
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
Access to dedicated SIMD instructions
@{
*/
/*------------------ RealView Compiler -----------------*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*------------------ ARM Compiler V6 -------------------*/
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armcc_V6.h"
/*------------------ GNU Compiler ----------------------*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*------------------ ICC Compiler ----------------------*/
#elif defined ( __ICCARM__ )
#include <cmsis_iar.h>
/*------------------ TI CCS Compiler -------------------*/
#elif defined ( __TMS470__ )
#include <cmsis_ccs.h>
/*------------------ TASKING Compiler ------------------*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
/*------------------ COSMIC Compiler -------------------*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#endif
/*@} end of group CMSIS_SIMD_intrinsics */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CMSIMD_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

69
3rd_party/CMSIS/Include/tz_context.h vendored Normal file
View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ----------------------------------------------------------------------------
*
* $Date: 21. September 2016
* $Revision: V1.0
*
* Project: TrustZone for ARMv8-M
* Title: Context Management for ARMv8-M TrustZone
*
* Version 1.0
* Initial Release
*---------------------------------------------------------------------------*/
#ifndef TZ_CONTEXT_H
#define TZ_CONTEXT_H
#include <stdint.h>
#ifndef TZ_MODULEID_T
#define TZ_MODULEID_T
/// \details Data type that identifies secure software modules called by a process.
typedef uint32_t TZ_ModuleId_t;
#endif
/// \details TZ Memory ID identifies an allocated memory slot.
typedef uint32_t TZ_MemoryId_t;
/// Initialize secure context memory system
/// \return execution status (1: success, 0: error)
uint32_t TZ_InitContextSystem_S (void);
/// Allocate context memory for calling secure software modules in TrustZone
/// \param[in] module identifies software modules called from non-secure mode
/// \return value != 0 id TrustZone memory slot identifier
/// \return value 0 no memory available or internal error
TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module);
/// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
/// \param[in] id TrustZone memory slot identifier
/// \return execution status (1: success, 0: error)
uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id);
/// Load secure context (called on RTOS thread context switch)
/// \param[in] id TrustZone memory slot identifier
/// \return execution status (1: success, 0: error)
uint32_t TZ_LoadContext_S (TZ_MemoryId_t id);
/// Store secure context (called on RTOS thread context switch)
/// \param[in] id TrustZone memory slot identifier
/// \return execution status (1: success, 0: error)
uint32_t TZ_StoreContext_S (TZ_MemoryId_t id);
#endif // TZ_CONTEXT_H

201
3rd_party/CMSIS/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,22 +1,21 @@
About CMSIS
===========
This folder contains the Cortex Microcontroller Software Interface Standard
(CMSIS) V4.4.0, which provides a single standard across all Cortex-Mx
(CMSIS) V5.0.15, which provides a single standard across all Cortex-Mx
processor series vendors. It enables code re-use and code sharing across
software projects and reduces time-to-market for new embedded applications.
Licensing
=========
CMSIS is released under the terms of the end user license agreement
("CMSIS_END_USER_LICENCE_AGREEMENT.pdf"). Any user of the software package
is bound to the terms and conditions of the end user license agreement.
CMSIS-5 is released under the terms of the Apache License Version 2.0
included in the file LICENSE.txt.
Documentation
=============
To reduce the size of the distribution, the Documentation sub-folder from
the original distribution has been removed. However, the CMSIS-RTOS RTX
documentation is available online at:
Complete Downloads
==================
To reduce the size of the distribution, this CMSIS folder contains only the
Include sub-directory. The complete CMSIS-5 is available at:
https://github.com/ARM-software/CMSIS_5
http://www.keil.com/pack/doc/CMSIS/General/html

View File

@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "QP/C"
PROJECT_NUMBER = "5.7.4"
PROJECT_NUMBER = "5.8.0"
PROJECT_BRIEF =
PROJECT_LOGO = images/header_logo_ql.png
OUTPUT_DIRECTORY =

View File

@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "QP/C"
PROJECT_NUMBER = "5.7.4"
PROJECT_NUMBER = "5.8.0"
PROJECT_BRIEF =
PROJECT_LOGO = images/header_logo_ql.png
OUTPUT_DIRECTORY =

View File

@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "QP/C"
PROJECT_NUMBER = "5.7.4"
PROJECT_NUMBER = "5.8.0"
PROJECT_BRIEF =
PROJECT_LOGO = images/header_logo_ql.png
OUTPUT_DIRECTORY =

View File

@ -1,6 +1,54 @@
/**
@page history Revision History
@section qpc_5_8_0 Version 5.8.0, 2016-11-30
The main purpose of this milestone QP/C release is to finally provide
the baseline framework fully compatible with the upcoming QM 4.0.0.
This release changes the class hierarchy so that QHsm becomes the base
class of ::QMsm and ::QActive. Also, ::QActive becomes the base class of
::QMActive, which reverses the changes introduced in version 4.1.
The modified @ref classes "class hierarchy" better reflects the fact that ::QHsm state
machine implementation strategy is simpler and supports less functionality
than the more advanced ::QMsm strategy. For example, only the ::QMsm class
fully supports sub-machines and sub-machine states that are the main
feature of QM 4.x. This clean progression of supported functionality from
subclasses to superclasses allows QM to easier check and enforce that
advanced features are not generated for subclasses that don't have the
required capabilities. (With previous class hierarchy with ::QMsm as the
base class all subclasses, including QHsm, would technically inherit the
advanced functionality, which is not the case).
@note
ALl changes in QP/C 5.8.0 remain transparent for the existing QP/C applications,
because of the provided backwards compatiblity layer in qpc.h.
Also, this release changes the implementation of the QV, QK, and QXK kernels
in that the ready-set representing active threads is cleared only *after*
completion of the RTC-step, not when the last event is removed from the
corresponding event queue. In case of the QXK kernel this change fixes the
high-priority <a href="https://sourceforge.net/p/qpc/bugs/147/">bug#147</a>.
But even in case of the QV and QK kernels, where this behavior didn't lead
to any bugs, the policy better reflects the semantics of the ready-set.
This release also updates the CMSIS interface included in the 3rd_party/CMSIS
folder to the latest CMSIS-5.
All examples and QM models have been updated to the new upcoming QM 4.0.0.
All these models require QM 4.x.
Finally, the complete list of bugs fixed in this release is as follows:
- <a href="https://sourceforge.net/p/qpc/bugs/147/">bug#147</a> "QXK: PendSV_error is triggered on special conditions"
- <a href="https://sourceforge.net/p/qpc/bugs/146/">bug#146</a> "Misra-C 2004 warning for rule 8.3 in qxk.c"
- <a href="https://sourceforge.net/p/qpc/bugs/144/">bug#144</a> "Obsolete Win32 API in qwin_gui.c"
- <a href="https://sourceforge.net/p/qpc/bugs/143/">bug#143</a> "QACTIVE_POST_LIFO() on initial transition asserts on QXK"
- <a href="https://sourceforge.net/p/qpc/bugs/124/">bug#124</a> "Windows port now cause memory leakage"
------------------------------------------------------------------------------
@section qpc_5_7_4 Version 5.7.4, 2016-11-04
This release fixes the following bugs:
- bug#145 QF_PUBLISH() leaks events that have no subscribers

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -1,8 +1,8 @@
@echo off
:: ==========================================================================
:: Product: QP/C script for generating Doxygen documentation
:: Last Updated for Version: 5.7.4
:: Date of the Last Update: 2016-11-01
:: Last Updated for Version: 5.8.0
:: Date of the Last Update: 2016-11-19
::
:: Q u a n t u m L e a P s
:: ---------------------------
@ -38,7 +38,7 @@ echo usage:
echo make
echo make -CHM
set VERSION=5.7.4
set VERSION=5.8.0
:: Generate Resource Standard Metrics for QP/C ...............................
set DOXHOME="C:\tools\doxygen\bin"

View File

@ -1,7 +1,7 @@
/** @page metrics Code Metrics
@code
Standard Code Metrics for QP/C 5.7.4
Standard Code Metrics for QP/C 5.8.0
Resource Standard Metrics (TM) for C, C++, C# and Java
Version 7.75 - mSquaredTechnologies.com
@ -9,7 +9,7 @@
License Type: Windows Single User License
Licensed To : Quantum Leaps, LLC
License No. : WS2975 License Date: Dec 15, 2013
Build Date : Sep 2 2009 Run Date: Nov 02, 2016
Build Date : Sep 2 2009 Run Date: Nov 30, 2016
(C)1996-2009 M Squared Technologies LLC
________________________________________________________________________
@ -31,7 +31,7 @@
~~ Total File Summary ~~
LOC 148 eLOC 144 lLOC 54 Comment 381 Lines 578
LOC 157 eLOC 153 lLOC 57 Comment 405 Lines 617
________________________________________________________________________
End of File: ..\include\qep.h
@ -51,7 +51,7 @@
~~ Total File Summary ~~
LOC 188 eLOC 188 lLOC 73 Comment 519 Lines 808
LOC 188 eLOC 188 lLOC 73 Comment 511 Lines 800
________________________________________________________________________
End of File: ..\include\qf.h
@ -61,7 +61,7 @@
~~ Total File Summary ~~
LOC 67 eLOC 67 lLOC 25 Comment 110 Lines 187
LOC 66 eLOC 66 lLOC 25 Comment 110 Lines 186
________________________________________________________________________
End of File: ..\include\qk.h
@ -91,7 +91,7 @@
~~ Total File Summary ~~
LOC 62 eLOC 61 lLOC 8 Comment 120 Lines 213
LOC 66 eLOC 65 lLOC 8 Comment 125 Lines 223
________________________________________________________________________
End of File: ..\include\qpc.h
@ -168,7 +168,7 @@
~~ Total File Summary ~~
LOC 27 eLOC 27 lLOC 2 Comment 80 Lines 114
LOC 26 eLOC 26 lLOC 2 Comment 80 Lines 113
________________________________________________________________________
End of File: ..\include\qv.h
@ -178,7 +178,7 @@
~~ Total File Summary ~~
LOC 70 eLOC 70 lLOC 27 Comment 117 Lines 196
LOC 69 eLOC 69 lLOC 27 Comment 117 Lines 195
________________________________________________________________________
End of File: ..\include\qxk.h
@ -203,16 +203,6 @@
End of File: ..\source\qf_pkg.h
File: ..\source\qk_pkg.h
________________________________________________________________________
~~ Total File Summary ~~
LOC 4 eLOC 4 lLOC 0 Comment 41 Lines 46
________________________________________________________________________
End of File: ..\source\qk_pkg.h
File: ..\source\qs_pkg.h
________________________________________________________________________
@ -239,7 +229,7 @@
Function: QHsm_ctor
Parameters: (QHsm * const me, QStateHandler initial)
Complexity Param 2 Return 1 Cyclo Vg 1 Total 4
LOC 9 eLOC 7 lLOC 4 Comment 30 Lines 10
LOC 9 eLOC 7 lLOC 4 Comment 21 Lines 9
Function: QHsm_init_
Parameters: (QHsm * const me, QEvt const * const e)
@ -285,20 +275,20 @@
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 16 eLOC 13 lLOC 9 Comment 21 Lines 21
Function: QHsm_childState
Function: QHsm_childState_
Parameters: (QHsm * const me, QStateHandler const parent)
Cyclomatic Complexity Vg Detail
Function Base : 1
Loops while / do : 1
Conditional if / else if: 1
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 19 eLOC 15 lLOC 12 Comment 28 Lines 25
LOC 19 eLOC 15 lLOC 12 Comment 30 Lines 25
------------------------------------------------------------------------
~~ Total File Summary ~~
LOC 344 eLOC 297 lLOC 176 Comment 321 Lines 632
LOC 344 eLOC 297 lLOC 176 Comment 314 Lines 625
------------------------------------------------------------------------
~~ File Functional Summary ~~
@ -329,7 +319,7 @@
Function: QMsm_ctor
Parameters: (QMsm * const me, QStateHandler initial)
Complexity Param 2 Return 1 Cyclo Vg 1 Total 4
LOC 9 eLOC 7 lLOC 4 Comment 19 Lines 9
LOC 9 eLOC 7 lLOC 4 Comment 28 Lines 10
Function: QMsm_init_
Parameters: (QMsm * const me, QEvt const * const e)
@ -365,7 +355,7 @@
Loops while / do : 1
Conditional if / else if: 2
Complexity Param 3 Return 1 Cyclo Vg 4 Total 8
LOC 19 eLOC 13 lLOC 6 Comment 20 Lines 26
LOC 17 eLOC 12 lLOC 6 Comment 20 Lines 23
Function: QMsm_enterHistory_
Parameters: (QMsm * const me, QMState const * const hist)
@ -385,33 +375,33 @@
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 11 eLOC 8 lLOC 6 Comment 16 Lines 12
Function: QMsm_childStateObj
Function: QMsm_childStateObj_
Parameters: (QMsm const * const me, QMState const * const parent)
Cyclomatic Complexity Vg Detail
Function Base : 1
Loops for / foreach : 1
Conditional if / else if: 1
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 19 eLOC 13 lLOC 9 Comment 18 Lines 23
LOC 19 eLOC 13 lLOC 9 Comment 20 Lines 23
------------------------------------------------------------------------
~~ Total File Summary ~~
LOC 315 eLOC 261 lLOC 144 Comment 287 Lines 573
LOC 313 eLOC 260 lLOC 144 Comment 298 Lines 581
------------------------------------------------------------------------
~~ File Functional Summary ~~
File Function Count....: 8
Total Function LOC.....: 288 Total Function Pts LOC : 2.5
Total Function eLOC....: 236 Total Function Pts eLOC: 2.0
Total Function LOC.....: 286 Total Function Pts LOC : 2.4
Total Function eLOC....: 235 Total Function Pts eLOC: 2.0
Total Function lLOC....: 139 Total Function Pts lLOC: 1.1
Total Function Params .: 17 Total Function Return .: 8
Total Cyclo Complexity : 45 Total Function Complex.: 70
------ ----- ----- ------ ------ -----
Max Function LOC ......: 114 Average Function LOC ..: 36.00
Max Function eLOC .....: 97 Average Function eLOC .: 29.50
Max Function LOC ......: 114 Average Function LOC ..: 35.75
Max Function eLOC .....: 97 Average Function eLOC .: 29.38
Max Function lLOC .....: 59 Average Function lLOC .: 17.38
------ ----- ----- ------ ------ -----
Max Function Parameters: 3 Avg Function Parameters: 2.13
@ -427,7 +417,7 @@
________________________________________________________________________
Function: QF_add_
Parameters: (QMActive * const a)
Parameters: (QActive * const a)
Cyclomatic Complexity Vg Detail
Function Base : 1
Logical and ( && ) : 2
@ -435,7 +425,7 @@
LOC 15 eLOC 14 lLOC 8 Comment 23 Lines 25
Function: QF_remove_
Parameters: (QMActive * const a)
Parameters: (QActive * const a)
Cyclomatic Complexity Vg Detail
Function Base : 1
Logical and ( && ) : 2
@ -491,8 +481,8 @@
________________________________________________________________________
Function: QActive_post_
Parameters: (QMActive * const me, QEvt const * const e, uint_fast16_t co
nst margin)
Parameters: (QActive * const me, QEvt const * const e, uint_fast16_t con
st margin)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 5
@ -500,7 +490,7 @@
LOC 56 eLOC 47 lLOC 35 Comment 79 Lines 77
Function: QActive_postLIFO_
Parameters: (QMActive * const me, QEvt const * const e)
Parameters: (QActive * const me, QEvt const * const e)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 4
@ -508,7 +498,7 @@
LOC 37 eLOC 31 lLOC 22 Comment 36 Lines 50
Function: QActive_get_
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 2
@ -556,13 +546,13 @@
________________________________________________________________________
Function: QActive_defer
Parameters: (QMActive const * const me, QEQueue * const eq, QEvt const *
const e)
Parameters: (QActive const * const me, QEQueue * const eq, QEvt const *
const e)
Complexity Param 3 Return 1 Cyclo Vg 1 Total 5
LOC 4 eLOC 2 lLOC 2 Comment 24 Lines 5
Function: QActive_recall
Parameters: (QMActive * const me, QEQueue * const eq)
Parameters: (QActive * const me, QEQueue * const eq)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 2
@ -570,7 +560,7 @@
LOC 19 eLOC 15 lLOC 10 Comment 33 Lines 36
Function: QActive_flushDeferred
Parameters: (QMActive const * const me, QEQueue * const eq)
Parameters: (QActive const * const me, QEQueue * const eq)
Cyclomatic Complexity Vg Detail
Function Base : 1
Loops for / foreach : 1
@ -979,8 +969,8 @@
LOC 14 eLOC 10 lLOC 6 Comment 13 Lines 17
Function: QTimeEvt_ctorX
Parameters: (QTimeEvt * const me, QMActive * const act, enum_t const sig
, uint_fast8_t tickRate)
Parameters: (QTimeEvt * const me, QActive * const act, enum_t const sig,
uint_fast8_t tickRate)
Cyclomatic Complexity Vg Detail
Function Base : 1
Logical and ( && ) : 1
@ -1055,7 +1045,7 @@
Function: QF_init
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 1 Total 2
LOC 11 eLOC 10 lLOC 9 Comment 18 Lines 18
LOC 12 eLOC 11 lLOC 10 Comment 18 Lines 19
Function: QF_stop
Parameters: (void)
@ -1079,9 +1069,9 @@
LOC 12 eLOC 10 lLOC 7 Comment 12 Lines 15
Function: QActive_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 1
@ -1090,7 +1080,7 @@
LOC 19 eLOC 16 lLOC 11 Comment 29 Lines 24
Function: QActive_stop
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 1
@ -1110,35 +1100,35 @@
Cyclomatic Complexity Vg Detail
Function Base : 1
Loops while / do : 1
Conditional if / else if: 4
Complexity Param 0 Return 1 Cyclo Vg 6 Total 7
LOC 57 eLOC 50 lLOC 28 Comment 47 Lines 82
Conditional if / else if: 5
Complexity Param 0 Return 1 Cyclo Vg 7 Total 8
LOC 60 eLOC 52 lLOC 29 Comment 48 Lines 86
------------------------------------------------------------------------
~~ Total File Summary ~~
LOC 153 eLOC 131 lLOC 73 Comment 211 Lines 349
LOC 157 eLOC 134 lLOC 75 Comment 212 Lines 354
------------------------------------------------------------------------
~~ File Functional Summary ~~
File Function Count....: 8
Total Function LOC.....: 134 Total Function Pts LOC : 1.2
Total Function eLOC....: 112 Total Function Pts eLOC: 1.0
Total Function lLOC....: 71 Total Function Pts lLOC: 0.6
Total Function LOC.....: 138 Total Function Pts LOC : 1.2
Total Function eLOC....: 115 Total Function Pts eLOC: 1.0
Total Function lLOC....: 73 Total Function Pts lLOC: 0.6
Total Function Params .: 8 Total Function Return .: 8
Total Cyclo Complexity : 22 Total Function Complex.: 38
Total Cyclo Complexity : 23 Total Function Complex.: 39
------ ----- ----- ------ ------ -----
Max Function LOC ......: 57 Average Function LOC ..: 16.75
Max Function eLOC .....: 50 Average Function eLOC .: 14.00
Max Function lLOC .....: 28 Average Function lLOC .: 8.88
Max Function LOC ......: 60 Average Function LOC ..: 17.25
Max Function eLOC .....: 52 Average Function eLOC .: 14.38
Max Function lLOC .....: 29 Average Function lLOC .: 9.13
------ ----- ----- ------ ------ -----
Max Function Parameters: 7 Avg Function Parameters: 1.00
Max Function Returns ..: 1 Avg Function Returns ..: 1.00
Max Interface Complex. : 8 Avg Interface Complex. : 2.00
Max Cyclomatic Complex.: 6 Avg Cyclomatic Complex.: 2.75
Max Total Complexity ..: 13 Avg Total Complexity ..: 4.75
Max Cyclomatic Complex.: 7 Avg Cyclomatic Complex.: 2.88
Max Total Complexity ..: 13 Avg Total Complexity ..: 4.88
________________________________________________________________________
End of File: ..\source\qk.c
@ -1589,7 +1579,7 @@
Function: QF_init
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 1 Total 2
LOC 8 eLOC 7 lLOC 6 Comment 15 Lines 13
LOC 9 eLOC 8 lLOC 7 Comment 15 Lines 14
Function: QF_stop
Parameters: (void)
@ -1601,14 +1591,14 @@
Cyclomatic Complexity Vg Detail
Function Base : 1
Loops for / foreach : 1
Conditional if / else if: 2
Complexity Param 0 Return 1 Cyclo Vg 4 Total 5
LOC 43 eLOC 38 lLOC 21 Comment 44 Lines 68
Conditional if / else if: 3
Complexity Param 0 Return 1 Cyclo Vg 5 Total 6
LOC 48 eLOC 42 lLOC 24 Comment 45 Lines 75
Function: QActive_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Cyclomatic Complexity Vg Detail
Function Base : 1
Logical and ( && ) : 2
@ -1616,7 +1606,7 @@
LOC 11 eLOC 9 lLOC 7 Comment 31 Lines 17
Function: QActive_stop
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Complexity Param 1 Return 1 Cyclo Vg 1 Total 3
LOC 3 eLOC 2 lLOC 1 Comment 13 Lines 3
@ -1624,27 +1614,27 @@
~~ Total File Summary ~~
LOC 85 eLOC 75 lLOC 37 Comment 168 Lines 246
LOC 92 eLOC 81 lLOC 41 Comment 170 Lines 255
------------------------------------------------------------------------
~~ File Functional Summary ~~
File Function Count....: 5
Total Function LOC.....: 68 Total Function Pts LOC : 0.7
Total Function eLOC....: 58 Total Function Pts eLOC: 0.6
Total Function lLOC....: 36 Total Function Pts lLOC: 0.3
Total Function LOC.....: 74 Total Function Pts LOC : 0.7
Total Function eLOC....: 63 Total Function Pts eLOC: 0.6
Total Function lLOC....: 40 Total Function Pts lLOC: 0.3
Total Function Params .: 8 Total Function Return .: 5
Total Cyclo Complexity : 10 Total Function Complex.: 23
Total Cyclo Complexity : 11 Total Function Complex.: 24
------ ----- ----- ------ ------ -----
Max Function LOC ......: 43 Average Function LOC ..: 13.60
Max Function eLOC .....: 38 Average Function eLOC .: 11.60
Max Function lLOC .....: 21 Average Function lLOC .: 7.20
Max Function LOC ......: 48 Average Function LOC ..: 14.80
Max Function eLOC .....: 42 Average Function eLOC .: 12.60
Max Function lLOC .....: 24 Average Function lLOC .: 8.00
------ ----- ----- ------ ------ -----
Max Function Parameters: 7 Avg Function Parameters: 1.60
Max Function Returns ..: 1 Avg Function Returns ..: 1.00
Max Interface Complex. : 8 Avg Interface Complex. : 2.60
Max Cyclomatic Complex.: 4 Avg Cyclomatic Complex.: 2.00
Max Total Complexity ..: 11 Avg Total Complexity ..: 4.60
Max Cyclomatic Complex.: 5 Avg Cyclomatic Complex.: 2.20
Max Total Complexity ..: 11 Avg Total Complexity ..: 4.80
________________________________________________________________________
End of File: ..\source\qv.c
@ -1655,7 +1645,7 @@
Function: QF_init
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 1 Total 2
LOC 13 eLOC 12 lLOC 11 Comment 20 Lines 23
LOC 14 eLOC 13 lLOC 12 Comment 16 Lines 20
Function: QF_stop
Parameters: (void)
@ -1679,9 +1669,9 @@
LOC 12 eLOC 10 lLOC 7 Comment 13 Lines 15
Function: QActive_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 1
@ -1690,7 +1680,7 @@
LOC 23 eLOC 20 lLOC 12 Comment 32 Lines 28
Function: QActive_stop
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 1
@ -1710,35 +1700,35 @@
Cyclomatic Complexity Vg Detail
Function Base : 1
Loops while / do : 1
Conditional if / else if: 5
Complexity Param 0 Return 1 Cyclo Vg 7 Total 8
LOC 72 eLOC 63 lLOC 35 Comment 53 Lines 100
Conditional if / else if: 6
Complexity Param 0 Return 1 Cyclo Vg 8 Total 9
LOC 75 eLOC 65 lLOC 36 Comment 54 Lines 104
------------------------------------------------------------------------
~~ Total File Summary ~~
LOC 210 eLOC 180 lLOC 99 Comment 236 Lines 427
LOC 214 eLOC 183 lLOC 101 Comment 233 Lines 428
------------------------------------------------------------------------
~~ File Functional Summary ~~
File Function Count....: 8
Total Function LOC.....: 190 Total Function Pts LOC : 1.6
Total Function eLOC....: 160 Total Function Pts eLOC: 1.4
Total Function lLOC....: 96 Total Function Pts lLOC: 0.8
Total Function LOC.....: 194 Total Function Pts LOC : 1.7
Total Function eLOC....: 163 Total Function Pts eLOC: 1.4
Total Function lLOC....: 98 Total Function Pts lLOC: 0.8
Total Function Params .: 8 Total Function Return .: 8
Total Cyclo Complexity : 29 Total Function Complex.: 45
Total Cyclo Complexity : 30 Total Function Complex.: 46
------ ----- ----- ------ ------ -----
Max Function LOC ......: 72 Average Function LOC ..: 23.75
Max Function eLOC .....: 63 Average Function eLOC .: 20.00
Max Function lLOC .....: 35 Average Function lLOC .: 12.00
Max Function LOC ......: 75 Average Function LOC ..: 24.25
Max Function eLOC .....: 65 Average Function eLOC .: 20.38
Max Function lLOC .....: 36 Average Function lLOC .: 12.25
------ ----- ----- ------ ------ -----
Max Function Parameters: 7 Avg Function Parameters: 1.00
Max Function Returns ..: 1 Avg Function Returns ..: 1.00
Max Interface Complex. : 8 Avg Interface Complex. : 2.00
Max Cyclomatic Complex.: 8 Avg Cyclomatic Complex.: 3.63
Max Total Complexity ..: 16 Avg Total Complexity ..: 5.63
Max Cyclomatic Complex.: 8 Avg Cyclomatic Complex.: 3.75
Max Total Complexity ..: 16 Avg Total Complexity ..: 5.75
________________________________________________________________________
End of File: ..\source\qxk.c
@ -1875,9 +1865,9 @@
LOC 5 eLOC 4 lLOC 3 Comment 1 Lines 5
Function: QXThread_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 1
@ -1886,8 +1876,8 @@
LOC 20 eLOC 17 lLOC 11 Comment 35 Lines 36
Function: QXThread_post_
Parameters: (QMActive * const me, QEvt const * const e, uint_fast16_t co
nst margin)
Parameters: (QActive * const me, QEvt const * const e, uint_fast16_t con
st margin)
Cyclomatic Complexity Vg Detail
Function Base : 1
Conditional if / else if: 9
@ -1895,7 +1885,7 @@
LOC 77 eLOC 63 lLOC 45 Comment 76 Lines 110
Function: QXThread_postLIFO_
Parameters: (QMActive * const me, QEvt const * const e)
Parameters: (QActive * const me, QEvt const * const e)
Complexity Param 2 Return 1 Cyclo Vg 1 Total 4
LOC 5 eLOC 4 lLOC 3 Comment 10 Lines 5
@ -1988,15 +1978,15 @@
------------------------------------------------------------------------
~~ Project Analysis For 41 Files ~~
~~ Project Analysis For 40 Files ~~
------------------------------------------------------------------------
~~ Total Project Summary ~~
LOC 5252 eLOC 4691 lLOC 2278 Comment 7350 Lines 12746
Average per File, metric/41 files
LOC 128 eLOC 114 lLOC 55 Comment 179 Lines 310
LOC 5271 eLOC 4708 lLOC 2289 Comment 7334 Lines 12754
Average per File, metric/40 files
LOC 131 eLOC 117 lLOC 57 Comment 183 Lines 318
------------------------------------------------------------------------
@ -2010,7 +2000,7 @@
Function: QHsm_ctor
Parameters: (QHsm * const me, QStateHandler initial)
Complexity Param 2 Return 1 Cyclo Vg 1 Total 4
LOC 9 eLOC 7 lLOC 4 Comment 30 Lines 10
LOC 9 eLOC 7 lLOC 4 Comment 21 Lines 9
Function: QHsm_init_
Parameters: (QHsm * const me, QEvt const * const e)
@ -2037,15 +2027,15 @@
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 16 eLOC 13 lLOC 9 Comment 21 Lines 21
Function: QHsm_childState
Function: QHsm_childState_
Parameters: (QHsm * const me, QStateHandler const parent)
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 19 eLOC 15 lLOC 12 Comment 28 Lines 25
LOC 19 eLOC 15 lLOC 12 Comment 30 Lines 25
Function: QMsm_ctor
Parameters: (QMsm * const me, QStateHandler initial)
Complexity Param 2 Return 1 Cyclo Vg 1 Total 4
LOC 9 eLOC 7 lLOC 4 Comment 19 Lines 9
LOC 9 eLOC 7 lLOC 4 Comment 28 Lines 10
Function: QMsm_init_
Parameters: (QMsm * const me, QEvt const * const e)
@ -2065,7 +2055,7 @@
Function: QMsm_exitToTranSource_
Parameters: (QMsm * const me, QMState const *s, QMState const *ts)
Complexity Param 3 Return 1 Cyclo Vg 4 Total 8
LOC 19 eLOC 13 lLOC 6 Comment 20 Lines 26
LOC 17 eLOC 12 lLOC 6 Comment 20 Lines 23
Function: QMsm_enterHistory_
Parameters: (QMsm * const me, QMState const * const hist)
@ -2077,18 +2067,18 @@
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 11 eLOC 8 lLOC 6 Comment 16 Lines 12
Function: QMsm_childStateObj
Function: QMsm_childStateObj_
Parameters: (QMsm const * const me, QMState const * const parent)
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 19 eLOC 13 lLOC 9 Comment 18 Lines 23
LOC 19 eLOC 13 lLOC 9 Comment 20 Lines 23
Function: QF_add_
Parameters: (QMActive * const a)
Parameters: (QActive * const a)
Complexity Param 1 Return 1 Cyclo Vg 3 Total 5
LOC 15 eLOC 14 lLOC 8 Comment 23 Lines 25
Function: QF_remove_
Parameters: (QMActive * const a)
Parameters: (QActive * const a)
Complexity Param 1 Return 1 Cyclo Vg 3 Total 5
LOC 16 eLOC 15 lLOC 9 Comment 23 Lines 25
@ -2103,18 +2093,18 @@
LOC 25 eLOC 18 lLOC 11 Comment 1 Lines 26
Function: QActive_post_
Parameters: (QMActive * const me, QEvt const * const e, uint_fast16_t co
nst margin)
Parameters: (QActive * const me, QEvt const * const e, uint_fast16_t con
st margin)
Complexity Param 3 Return 1 Cyclo Vg 6 Total 10
LOC 56 eLOC 47 lLOC 35 Comment 79 Lines 77
Function: QActive_postLIFO_
Parameters: (QMActive * const me, QEvt const * const e)
Parameters: (QActive * const me, QEvt const * const e)
Complexity Param 2 Return 1 Cyclo Vg 5 Total 8
LOC 37 eLOC 31 lLOC 22 Comment 36 Lines 50
Function: QActive_get_
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Complexity Param 1 Return 1 Cyclo Vg 3 Total 5
LOC 37 eLOC 33 lLOC 24 Comment 32 Lines 48
@ -2124,18 +2114,18 @@
LOC 10 eLOC 9 lLOC 6 Comment 18 Lines 13
Function: QActive_defer
Parameters: (QMActive const * const me, QEQueue * const eq, QEvt const *
const e)
Parameters: (QActive const * const me, QEQueue * const eq, QEvt const *
const e)
Complexity Param 3 Return 1 Cyclo Vg 1 Total 5
LOC 4 eLOC 2 lLOC 2 Comment 24 Lines 5
Function: QActive_recall
Parameters: (QMActive * const me, QEQueue * const eq)
Parameters: (QActive * const me, QEQueue * const eq)
Complexity Param 2 Return 1 Cyclo Vg 3 Total 6
LOC 19 eLOC 15 lLOC 10 Comment 33 Lines 36
Function: QActive_flushDeferred
Parameters: (QMActive const * const me, QEQueue * const eq)
Parameters: (QActive const * const me, QEQueue * const eq)
Complexity Param 2 Return 1 Cyclo Vg 2 Total 5
LOC 10 eLOC 7 lLOC 7 Comment 17 Lines 12
@ -2260,8 +2250,8 @@
LOC 14 eLOC 10 lLOC 6 Comment 13 Lines 17
Function: QTimeEvt_ctorX
Parameters: (QTimeEvt * const me, QMActive * const act, enum_t const sig
, uint_fast8_t tickRate)
Parameters: (QTimeEvt * const me, QActive * const act, enum_t const sig,
uint_fast8_t tickRate)
Complexity Param 4 Return 1 Cyclo Vg 2 Total 7
LOC 11 eLOC 9 lLOC 8 Comment 32 Lines 31
@ -2289,7 +2279,7 @@
Function: QF_init
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 1 Total 2
LOC 11 eLOC 10 lLOC 9 Comment 18 Lines 18
LOC 12 eLOC 11 lLOC 10 Comment 18 Lines 19
Function: QF_stop
Parameters: (void)
@ -2307,14 +2297,14 @@
LOC 12 eLOC 10 lLOC 7 Comment 12 Lines 15
Function: QActive_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Complexity Param 7 Return 1 Cyclo Vg 5 Total 13
LOC 19 eLOC 16 lLOC 11 Comment 29 Lines 24
Function: QActive_stop
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Complexity Param 1 Return 1 Cyclo Vg 2 Total 4
LOC 11 eLOC 9 lLOC 6 Comment 13 Lines 15
@ -2325,8 +2315,8 @@
Function: QK_activate_
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 6 Total 7
LOC 57 eLOC 50 lLOC 28 Comment 47 Lines 82
Complexity Param 0 Return 1 Cyclo Vg 7 Total 8
LOC 60 eLOC 52 lLOC 29 Comment 48 Lines 86
Function: QMutex_init
Parameters: (QMutex * const me, uint_fast8_t prio)
@ -2522,7 +2512,7 @@
Function: QF_init
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 1 Total 2
LOC 8 eLOC 7 lLOC 6 Comment 15 Lines 13
LOC 9 eLOC 8 lLOC 7 Comment 15 Lines 14
Function: QF_stop
Parameters: (void)
@ -2531,25 +2521,25 @@
Function: QF_run
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 4 Total 5
LOC 43 eLOC 38 lLOC 21 Comment 44 Lines 68
Complexity Param 0 Return 1 Cyclo Vg 5 Total 6
LOC 48 eLOC 42 lLOC 24 Comment 45 Lines 75
Function: QActive_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Complexity Param 7 Return 1 Cyclo Vg 3 Total 11
LOC 11 eLOC 9 lLOC 7 Comment 31 Lines 17
Function: QActive_stop
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Complexity Param 1 Return 1 Cyclo Vg 1 Total 3
LOC 3 eLOC 2 lLOC 1 Comment 13 Lines 3
Function: QF_init
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 1 Total 2
LOC 13 eLOC 12 lLOC 11 Comment 20 Lines 23
LOC 14 eLOC 13 lLOC 12 Comment 16 Lines 20
Function: QF_stop
Parameters: (void)
@ -2567,14 +2557,14 @@
LOC 12 eLOC 10 lLOC 7 Comment 13 Lines 15
Function: QActive_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Complexity Param 7 Return 1 Cyclo Vg 8 Total 16
LOC 23 eLOC 20 lLOC 12 Comment 32 Lines 28
Function: QActive_stop
Parameters: (QMActive * const me)
Parameters: (QActive * const me)
Complexity Param 1 Return 1 Cyclo Vg 2 Total 4
LOC 11 eLOC 9 lLOC 6 Comment 13 Lines 15
@ -2585,8 +2575,8 @@
Function: QXK_activate_
Parameters: (void)
Complexity Param 0 Return 1 Cyclo Vg 7 Total 8
LOC 72 eLOC 63 lLOC 35 Comment 53 Lines 100
Complexity Param 0 Return 1 Cyclo Vg 8 Total 9
LOC 75 eLOC 65 lLOC 36 Comment 54 Lines 104
Function: QXMutex_init
Parameters: (QXMutex * const me, uint_fast8_t prio)
@ -2636,20 +2626,20 @@
LOC 5 eLOC 4 lLOC 3 Comment 1 Lines 5
Function: QXThread_start_
Parameters: (QMActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QE
vt const *ie)
Parameters: (QActive * const me, uint_fast8_t prio, QEvt const *qSto[],
uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize, QEv
t const *ie)
Complexity Param 7 Return 1 Cyclo Vg 6 Total 14
LOC 20 eLOC 17 lLOC 11 Comment 35 Lines 36
Function: QXThread_post_
Parameters: (QMActive * const me, QEvt const * const e, uint_fast16_t co
nst margin)
Parameters: (QActive * const me, QEvt const * const e, uint_fast16_t con
st margin)
Complexity Param 3 Return 1 Cyclo Vg 10 Total 14
LOC 77 eLOC 63 lLOC 45 Comment 76 Lines 110
Function: QXThread_postLIFO_
Parameters: (QMActive * const me, QEvt const * const e)
Parameters: (QActive * const me, QEvt const * const e)
Complexity Param 2 Return 1 Cyclo Vg 1 Total 4
LOC 5 eLOC 4 lLOC 3 Comment 10 Lines 5
@ -2695,26 +2685,26 @@
LOC 10 eLOC 9 lLOC 7 Comment 12 Lines 12
Total: Functions
LOC 3289 eLOC 2750 lLOC 1803 InCmp 354 CycloCmp 512
Function Points FP(LOC) 25.5 FP(eLOC) 21.3 FP(lLOC) 14.0
LOC 3301 eLOC 2760 lLOC 1811 InCmp 354 CycloCmp 515
Function Points FP(LOC) 25.6 FP(eLOC) 21.4 FP(lLOC) 14.1
------------------------------------------------------------------------
~~ Project Functional Analysis ~~
Total Functions .......: 134 Total Physical Lines ..: 4328
Total LOC .............: 3289 Total Function Pts LOC : 25.5
Total eLOC ............: 2750 Total Function Pts eLOC: 21.3
Total lLOC.............: 1803 Total Function Pts lLOC: 14.0
Total Cyclomatic Comp. : 512 Total Interface Comp. .: 354
Total Functions .......: 134 Total Physical Lines ..: 4339
Total LOC .............: 3301 Total Function Pts LOC : 25.6
Total eLOC ............: 2760 Total Function Pts eLOC: 21.4
Total lLOC.............: 1811 Total Function Pts lLOC: 14.1
Total Cyclomatic Comp. : 515 Total Interface Comp. .: 354
Total Parameters ......: 220 Total Return Points ...: 134
Total Comment Lines ...: 3083 Total Blank Lines .....: 559
Total Comment Lines ...: 3086 Total Blank Lines .....: 564
------ ----- ----- ------ ------ -----
Avg Physical Lines ....: 32.30
Avg LOC ...............: 24.54 Avg eLOC ..............: 20.52
Avg lLOC ..............: 13.46 Avg Cyclomatic Comp. ..: 3.82
Avg Physical Lines ....: 32.38
Avg LOC ...............: 24.63 Avg eLOC ..............: 20.60
Avg lLOC ..............: 13.51 Avg Cyclomatic Comp. ..: 3.84
Avg Interface Comp. ...: 2.64 Avg Parameters ........: 1.64
Avg Return Points .....: 1.00 Avg Comment Lines .....: 23.01
Avg Return Points .....: 1.00 Avg Comment Lines .....: 23.03
------ ----- ----- ------ ------ -----
Max LOC ...............: 254
Max eLOC ..............: 197 Max lLOC ..............: 125
@ -2732,10 +2722,10 @@
~~ File Summary ~~
C Source Files *.c ....: 23 C/C++ Include Files *.h: 18
C Source Files *.c ....: 23 C/C++ Include Files *.h: 17
C++ Source Files *.c* .: 0 C++ Include Files *.h* : 0
C# Source Files *.cs ..: 0 Java Source File *.jav*: 0
Other File Count ......: 0 Total File Count ......: 41
Other File Count ......: 0 Total File Count ......: 40
________________________________________________________________________
@endcode

View File

@ -48,16 +48,17 @@ The figure below shows the main classes comprising the QP/C framework and their
<li><span class="tag">0</span> The ::QEvt class represents events without parameters and serves as the base class for derivation of time events and any events with parameters. For example, application-level events `ObjectPosEvt` and `ObjectImageEvt` inherit ::QEvt and add to it some parameters (see [8]).
</li>
<li><span class="tag">1</span> The abstract ::QMsm class represents the most fundamental State Machine in QP/C. This class implements the fastest and the most efficient strategy for coding hierarchical state machines, but this strategy is not human-maintainable and requires the use of the <a class="extern" target="_blank" href="http://www.state-machine.com/qm">QM modeling tool</a>. The class is abstract, meaning that it is not designed to be instantiated directly, but rather only for inheritance. The @ref game application provides an example of application-level classes deriving directly from ::QMsm (see [7]).
<li><span class="tag">1</span> The abstract ::QHsm class represents a Hierarchical State Machine (HSM) with full support for hierarchical nesting of states, entry/exit actions, initial transitions, and transitions to history in any composite state. This class is designed for ease of manual coding of HSMs in C, but it is also supported by the <a class="extern" target="_blank" href="http://www.state-machine.com/qm">QM modeling tool</a>.
::QHsm is also the base class for the ::QMsm state machine, which provides a superior efficiency, but requires the use of the <a class="extern" target="_blank" href="http://www.state-machine.com/qm">QM modeling tool</a> to generate code.
</li>
<li><span class="tag">2</span> The abstract ::QHsm class derives from ::QMsm and implements the state machine coding strategy suitable for manual coding and maintaining the code. The ::QHsm strategy is also supported by the <a class="extern" target="_blank" href="http://www.state-machine.com/qm">QM modeling tool</a>, but is not as fast or efficient as the ::QMsm strategy.
<li><span class="tag">2</span> The abstract ::QActive class represents an active object that uses the ::QHsm style implementation strategy for state machines. This strategy is tailored to manual coding, but it is also supported by the <a class="extern" target="_blank" href="http://www.state-machine.com/qm">QM modeling tool</a>. The resulting code is slower than in the ::QMsm-style implementation strategy.
</li>
<li><span class="tag">3</span> The abstract ::QMActive class represents an active object that uses the ::QMsm style state machine implementation strategy. This strategy requires the use of the QM modeling tool to generate state machine code automatically, but the code is faster than in the ::QHsm style implementation strategy and needs less run-time support (smaller event-processor).
<li><span class="tag">3</span> The abstract ::QMsm class (QM State Machine) derives from ::QHsm and implements the fastest and the most efficient strategy for coding hierarchical state machines, but this strategy is not human-maintainable and requires the use of the <a class="extern" target="_blank" href="http://www.state-machine.com/qm">QM modeling tool</a>. The class is abstract, meaning that it is not designed to be instantiated directly, but rather only for inheritance. The @ref game application provides an example of application-level classes deriving directly from ::QMsm (see [7]).
</li>
<li><span class="tag">4</span> The abstract ::QActive class represents an active object that uses the ::QHsm style implementation strategy for state machines. This strategy is tailored to manual coding, but it is also supported by the QM modeling tool. The resulting code is slower than in the ::QMsm-style implementation strategy.
<li><span class="tag">4</span> The abstract ::QMActive class represents an active object that uses the ::QMsm state machine implementation strategy. This strategy requires the use of the QM modeling tool to generate state machine code automatically, but the code is faster than in the ::QHsm style implementation strategy and needs less run-time support (smaller event-processor).
</li>
<li><span class="tag">5</span> The ::QTimeEvt class represents time events in QP. **Time events** are special QP events equipped with the notion of time passage. The basic usage model of the time events is as follows. An active object allocates one or more ::QTimeEvt objects (provides the storage for them). When the active object needs to arrange for a timeout, it arms one of its time events to fire either just once (one-shot) or periodically. Each time event times out independently from the others, so a QP application can make multiple parallel timeout requests (from the same or different active objects). When QP detects that the appropriate moment has arrived, it inserts the time event directly into the recipient's event queue. The recipient then processes the time event just like any other event.

View File

@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -53,7 +58,7 @@ extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QMActive * const AO_Table;
extern QActive * const AO_Table;
#ifdef qxk_h

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -120,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -323,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -337,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,35 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QState Philo_thinking_x(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(&Philo_thinking_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -91,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -135,37 +104,27 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
QActive_subscribe(&me->super, EAT_SIG);
QActive_subscribe(&me->super, TEST_SIG);
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_x(Philo * const me) {
QTimeEvt_disarm(&me->timeEvt);
return QM_EXIT(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_x), /* exit */
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -173,52 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -226,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -274,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -129,58 +100,56 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -200,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -247,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -318,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -336,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -53,7 +58,7 @@ extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QMActive * const AO_Table;
extern QActive * const AO_Table;
#ifdef qxk_h

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -120,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -323,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -337,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,35 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QState Philo_thinking_x(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(&Philo_thinking_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -91,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -135,37 +104,27 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
QActive_subscribe(&me->super, EAT_SIG);
QActive_subscribe(&me->super, TEST_SIG);
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_x(Philo * const me) {
QTimeEvt_disarm(&me->timeEvt);
return QM_EXIT(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_x), /* exit */
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -173,52 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -226,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -274,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -84,16 +84,36 @@
</folderInfo>
<fileInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1412738644.QP/qxk_pkg.h" name="qxk_pkg.h" rcbsApplicability="disable" resourcePath="QP/qxk_pkg.h" toolsToInvoke=""/>
<fileInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1412738644.QP/qxk_xthr.c" name="qxk_xthr.c" rcbsApplicability="disable" resourcePath="QP/qxk_xthr.c" toolsToInvoke="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.788962651">
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.788962651" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495"/>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.788962651" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495">
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS.1147932138" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS.1340492158" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS.629076420" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS.344979043" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS"/>
</tool>
</fileInfo>
<fileInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1412738644.QP/qxk_sema.c" name="qxk_sema.c" rcbsApplicability="disable" resourcePath="QP/qxk_sema.c" toolsToInvoke="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.1087782132">
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.1087782132" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495"/>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.1087782132" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495">
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS.1653242093" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS.1232478648" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS.209952187" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS.556090452" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS"/>
</tool>
</fileInfo>
<fileInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1412738644.QP/qxk.c" name="qxk.c" rcbsApplicability="disable" resourcePath="QP/qxk.c" toolsToInvoke="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.804391732">
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.804391732" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495"/>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.804391732" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495">
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS.1640329765" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS.1081692032" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS.1520992376" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS.302079022" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS"/>
</tool>
</fileInfo>
<fileInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1412738644.QP/qxk_mutex.c" name="qxk_mutex.c" rcbsApplicability="disable" resourcePath="QP/qxk_mutex.c" toolsToInvoke="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.476190529">
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.476190529" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495"/>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495.476190529" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.exe.compilerDebug.1196596495">
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS.533299580" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__C_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS.780863423" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__CPP_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS.429193584" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS.503933257" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_15.12.compiler.inputType__ASM2_SRCS"/>
</tool>
</fileInfo>
<sourceEntries>
<entry excluding="QP/qxk.c|QP/qxk_pkg.h|QP/qxk_sema.c|QP/qxk_xthr.c|QP/qxk_mutex.c|ek-tm4c123gxl/iar/startup_TM4C123GH6PM.s|ek-tm4c123gxl/gnu/startup_TM4C123GH6PM.c|ek-tm4c123gxl/arm/startup_TM4C123GH6PM.s|QP/qv.c|QP/qs.c|QP/qs_rx.c|QP/qs_fp.c|QP/qs_64bit.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -129,58 +100,56 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -200,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -247,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -318,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -336,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -362,11 +368,18 @@ $declare(Events::TableEvt)
#define N_PHILO ((uint8_t)5)
$declare(AOs::Philo_ctor)
$declare(AOs::Table_ctor)
$declare(AOs::AO_Philo[N_PHILO])
$declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>
</file>
<file name="philo.c">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -53,7 +58,7 @@ extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QMActive * const AO_Table;
extern QActive * const AO_Table;
#ifdef qxk_h

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -120,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -323,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -337,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,35 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QState Philo_thinking_x(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(&Philo_thinking_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -91,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -135,37 +104,27 @@ static QState Philo_initial(Philo * const me, QEvt const * const e) {
QActive_subscribe(&me->super, EAT_SIG);
QActive_subscribe(&me->super, TEST_SIG);
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_x(Philo * const me) {
QTimeEvt_disarm(&me->timeEvt);
return QM_EXIT(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_x), /* exit */
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -173,52 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -226,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -274,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -129,58 +100,56 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -200,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -247,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -318,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -336,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -362,11 +368,18 @@ $declare(Events::TableEvt)
#define N_PHILO ((uint8_t)5)
$declare(AOs::Philo_ctor)
$declare(AOs::Table_ctor)
$declare(AOs::AO_Philo[N_PHILO])
$declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>
</file>
<file name="philo.c">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -50,6 +50,11 @@ enum GameSignals { /* signals used in the game */
MAX_SIG /* the last signal (keep always last) */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::ObjectPosEvt} ..................................................*/
typedef struct {
/* protected: */
@ -127,18 +132,18 @@ void Missile_ctor(void);
/* instantiation of the Mines orthogonal components */
/*${AOs::Mine1_ctor} .......................................................*/
QMsm * Mine1_ctor(uint8_t id);
QHsm * Mine1_ctor(uint8_t id);
/*${AOs::Mine2_ctor} .......................................................*/
QMsm * Mine2_ctor(uint8_t id);
QHsm * Mine2_ctor(uint8_t id);
/* opaque pointers to active objects in the application */
extern QMActive * const AO_Tunnel;
extern QActive * const AO_Tunnel;
extern QMActive * const AO_Ship;
extern QActive * const AO_Ship;
extern QMActive * const AO_Missile;
extern QActive * const AO_Missile;
#endif /* game_h */

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>&quot;Fly 'n' Shoot&quot; game model from Chapters 1 &amp; 9 of PSiCC2
NOTE: Requries QP5.</documentation>
@ -22,7 +22,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Tunnel" superclass="qpc::QMActive">
<class name="Tunnel" superclass="qpc::QActive">
<documentation>Tunnel Active Object</documentation>
<attribute name="blinkTimeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<attribute name="screenTimeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
@ -114,7 +114,7 @@ if ((me-&gt;last_mine_x + GAME_MINES_DIST_MIN &lt; GAME_TUNNEL_WIDTH)
ope.super.sig = MINE_PLANT_SIG;
ope.x = me-&gt;last_mine_x;
ope.y = me-&gt;last_mine_y;
QMSM_DISPATCH(me-&gt;mines[n], (QEvt *)&amp;ope); /* direct dispatch */
QHSM_DISPATCH(me-&gt;mines[n], (QEvt *)&amp;ope); /* direct dispatch */
}
}</code>
</operation>
@ -124,7 +124,7 @@ if ((me-&gt;last_mine_x + GAME_MINES_DIST_MIN &lt; GAME_TUNNEL_WIDTH)
for (n = 0U; n &lt; GAME_MINES_MAX; ++n) {
if (me-&gt;mines[n] != (QMsm *)0) { /* is the mine used? */
QMSM_DISPATCH(me-&gt;mines[n], e);
QHSM_DISPATCH(me-&gt;mines[n], e);
}
}</code>
</operation>
@ -132,8 +132,8 @@ for (n = 0U; n &lt; GAME_MINES_MAX; ++n) {
<initial target="../1/2">
<action>uint8_t n;
for (n = 0U; n &lt; GAME_MINES_MAX; ++n) {
QMSM_INIT(me-&gt;mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
QMSM_INIT(me-&gt;mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
QHSM_INIT(me-&gt;mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
QHSM_INIT(me-&gt;mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
}
BSP_randomSeed(1234); /* seed the pseudo-random generator */
@ -475,7 +475,7 @@ QF_stop(); /* stop QF and cleanup */</entry>
<state_diagram size="68,94"/>
</statechart>
</class>
<class name="Ship" superclass="qpc::QMActive">
<class name="Ship" superclass="qpc::QActive">
<documentation>Ship Active Object</documentation>
<attribute name="x" type="uint8_t" visibility="0x02" properties="0x00"/>
<attribute name="y" type="uint16_t" visibility="0x02" properties="0x00">
@ -630,7 +630,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me);</action>
<state_diagram size="40,62"/>
</statechart>
</class>
<class name="Missile" superclass="qpc::QMActive">
<class name="Missile" superclass="qpc::QActive">
<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"/>
@ -740,7 +740,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
<state_diagram size="46,55"/>
</statechart>
</class>
<class name="Mine1" superclass="qpc::QMsm">
<class name="Mine1" superclass="qpc::QHsm">
<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"/>
@ -904,7 +904,7 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
<state_diagram size="53,68"/>
</statechart>
</class>
<class name="Mine2" superclass="qpc::QMsm">
<class name="Mine2" superclass="qpc::QHsm">
<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"/>
@ -1076,13 +1076,13 @@ QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);</action>
<state_diagram size="53,68"/>
</statechart>
</class>
<attribute name="AO_Tunnel" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Ship" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Missile" type="QMActive * const" visibility="0x00" properties="0x00"/>
<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 = &amp;l_tunnel;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Tunnel_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Tunnel_initial));
QTimeEvt_ctorX(&amp;me-&gt;blinkTimeEvt, &amp;me-&gt;super, BLINK_TIMEOUT_SIG, 0U);
QTimeEvt_ctorX(&amp;me-&gt;screenTimeEvt, &amp;me-&gt;super, SCREEN_TIMEOUT_SIG, 0U);
for (n = 0; n &lt; GAME_MINES_MAX; ++n) {
@ -1095,31 +1095,31 @@ me-&gt;last_mine_y = 0;</code>
</operation>
<operation name="Ship_ctor" type="void" visibility="0x00" properties="0x01">
<code>Ship *me = &amp;l_ship;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Ship_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Ship_initial));
me-&gt;x = GAME_SHIP_X;
me-&gt;y = (GAME_SHIP_Y &lt;&lt; 2);</code>
</operation>
<operation name="Missile_ctor" type="void" visibility="0x00" properties="0x01">
<code>Missile *me = &amp;l_missile;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Missile_initial));</code>
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Missile_initial));</code>
</operation>
<operation name="Mine1_ctor" type="QMsm *" visibility="0x00" properties="0x01">
<operation name="Mine1_ctor" type="QHsm *" visibility="0x00" properties="0x01">
<parameter name="id" type="uint8_t"/>
<code>Mine1 *me;
Q_REQUIRE(id &lt; GAME_MINES_MAX);
me = &amp;l_mine1[id];
/* superclass' ctor */
QMsm_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Mine1_initial));
return (QMsm *)me;</code>
QHsm_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Mine1_initial));
return (QHsm *)me;</code>
</operation>
<operation name="Mine2_ctor" type="QMsm *" visibility="0x00" properties="0x01">
<operation name="Mine2_ctor" type="QHsm *" visibility="0x00" properties="0x01">
<parameter name="id" type="uint8_t"/>
<code>Mine2 *me;
Q_REQUIRE(id &lt; GAME_MINES_MAX);
me = &amp;l_mine2[id];
/* superclass' ctor */
QMsm_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Mine2_initial));
return (QMsm *)me;</code>
QHsm_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Mine2_initial));
return (QHsm *)me;</code>
</operation>
</package>
<directory name=".">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* encapsulated delcaration of the Mine1 HSM -------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Mine1} ............................................................*/
typedef struct {
/* protected: */
QMsm super;
QHsm super;
/* private: */
uint8_t x;
@ -37,40 +42,10 @@ typedef struct {
/* protected: */
static QState Mine1_initial(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, /* superstate (top) */
Q_STATE_CAST(&Mine1_unused),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Mine1_used),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(&Mine1_used_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
static QState Mine1_planted (Mine1 * const me, QEvt const * const e);
static QMState const Mine1_planted_s = {
&Mine1_used_s, /* superstate */
Q_STATE_CAST(&Mine1_planted),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Mine1_exploding),
Q_ACTION_CAST(&Mine1_exploding_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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_planted(Mine1 * const me, QEvt const * const e);
static QState Mine1_exploding(Mine1 * const me, QEvt const * const e);
/* local objects -----------------------------------------------------------*/
@ -81,23 +56,17 @@ static Mine1 l_mine1[GAME_MINES_MAX]; /* a pool of type-1 mines */
/* Mine1 class definition --------------------------------------------------*/
/*${AOs::Mine1_ctor} .......................................................*/
QMsm * Mine1_ctor(uint8_t id) {
QHsm * Mine1_ctor(uint8_t id) {
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;
QHsm_ctor(&me->super, Q_STATE_CAST(&Mine1_initial));
return (QHsm *)me;
}
/*${AOs::Mine1} ............................................................*/
/*${AOs::Mine1::SM} ........................................................*/
static QState Mine1_initial(Mine1 * const me, QEvt const * const e) {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Mine1_unused_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Mine1::SM::initial} */
static uint8_t dict_sent;
@ -124,70 +93,52 @@ 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 QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Mine1_unused);
}
/*${AOs::Mine1::SM::unused} ................................................*/
/* ${AOs::Mine1::SM::unused} */
static QState Mine1_unused(Mine1 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Mine1::SM::unused::MINE_PLANT} */
case MINE_PLANT_SIG: {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Mine1_planted_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine1_planted);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Mine1::SM::used} ..................................................*/
/* ${AOs::Mine1::SM::used} */
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);
}
/* ${AOs::Mine1::SM::used} */
static QState Mine1_used(Mine1 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Mine1::SM::used} */
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;
}
/* ${AOs::Mine1::SM::used::MINE_RECYCLE} */
case MINE_RECYCLE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine1_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine1_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine1_unused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Mine1::SM::used::planted} .........................................*/
/* ${AOs::Mine1::SM::used::planted} */
static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
@ -203,21 +154,11 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Mine1::SM::used::planted::TIME_TICK::[else]} */
else {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine1_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine1_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine1_unused);
}
break;
}
@ -228,16 +169,6 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
/* ${AOs::Mine1::SM::used::planted::SHIP_IMG::[collisionwithMINE1_BMP?]} */
if (BSP_doBitmapsOverlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine1_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine1_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
static MineEvt const mine1_hit = {
{ HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
1U /* type of the mine (1 for Mine type-1) */
@ -245,10 +176,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_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine1_unused);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -259,45 +190,35 @@ static QState Mine1_planted(Mine1 * const me, QEvt const * const e) {
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
/* ${AOs::Mine1::SM::used::planted::MISSILE_IMG::[collisionwithMINE1_BMP?]} */
if (BSP_doBitmapsOverlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine1_exploding_s, /* target state */
{
Q_ACTION_CAST(&Mine1_exploding_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
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_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine1_exploding);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Mine1_used);
break;
}
}
return status_;
}
/*${AOs::Mine1::SM::used::exploding} .......................................*/
/* ${AOs::Mine1::SM::used::exploding} */
static QState Mine1_exploding_e(Mine1 * const me) {
me->exp_ctr = 0U;
return QM_ENTRY(&Mine1_exploding_s);
}
/* ${AOs::Mine1::SM::used::exploding} */
static QState Mine1_exploding(Mine1 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Mine1::SM::used::exploding} */
case Q_ENTRY_SIG: {
me->exp_ctr = 0U;
status_ = Q_HANDLED();
break;
}
/* ${AOs::Mine1::SM::used::exploding::TIME_TICK} */
case TIME_TICK_SIG: {
/* ${AOs::Mine1::SM::used::exploding::TIME_TICK::[stillonscreen?]} */
@ -312,26 +233,16 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Mine1::SM::used::exploding::TIME_TICK::[else]} */
else {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine1_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine1_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine1_unused);
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Mine1_used);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* encapsulated delcaration of the Mine2 HSM -------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Mine2} ............................................................*/
typedef struct {
/* protected: */
QMsm super;
QHsm super;
/* private: */
uint8_t x;
@ -37,40 +42,10 @@ typedef struct {
/* protected: */
static QState Mine2_initial(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, /* superstate (top) */
Q_STATE_CAST(&Mine2_unused),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Mine2_used),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(&Mine2_used_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
static QState Mine2_planted (Mine2 * const me, QEvt const * const e);
static QMState const Mine2_planted_s = {
&Mine2_used_s, /* superstate */
Q_STATE_CAST(&Mine2_planted),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Mine2_exploding),
Q_ACTION_CAST(&Mine2_exploding_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* local objects -----------------------------------------------------------*/
@ -81,23 +56,17 @@ static Mine2 l_mine2[GAME_MINES_MAX]; /* a pool of type-2 mines */
/* Mine2 class definition --------------------------------------------------*/
/*${AOs::Mine2_ctor} .......................................................*/
QMsm * Mine2_ctor(uint8_t id) {
QHsm * Mine2_ctor(uint8_t id) {
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;
QHsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial));
return (QHsm *)me;
}
/*${AOs::Mine2} ............................................................*/
/*${AOs::Mine2::SM} ........................................................*/
static QState Mine2_initial(Mine2 * const me, QEvt const * const e) {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Mine2_unused_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Mine2::SM::initial} */
static uint8_t dict_sent;
@ -126,70 +95,52 @@ 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 QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Mine2_unused);
}
/*${AOs::Mine2::SM::unused} ................................................*/
/* ${AOs::Mine2::SM::unused} */
static QState Mine2_unused(Mine2 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Mine2::SM::unused::MINE_PLANT} */
case MINE_PLANT_SIG: {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Mine2_planted_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine2_planted);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Mine2::SM::used} ..................................................*/
/* ${AOs::Mine2::SM::used} */
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);
}
/* ${AOs::Mine2::SM::used} */
static QState Mine2_used(Mine2 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Mine2::SM::used} */
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;
}
/* ${AOs::Mine2::SM::used::MINE_RECYCLE} */
case MINE_RECYCLE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine2_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine2_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine2_unused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Mine2::SM::used::planted} .........................................*/
/* ${AOs::Mine2::SM::used::planted} */
static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
@ -205,21 +156,11 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Mine2::SM::used::planted::TIME_TICK::[else]} */
else {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine2_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine2_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine2_unused);
}
break;
}
@ -230,16 +171,6 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
/* ${AOs::Mine2::SM::used::planted::SHIP_IMG::[collisionwithMINE2_BMP?]} */
if (BSP_doBitmapsOverlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine2_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine2_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
static MineEvt const mine1_hit = {
{ HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
2U /* type of the mine (2 for Mine type-2) */
@ -247,10 +178,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_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine2_unused);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -261,16 +192,6 @@ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
/* ${AOs::Mine2::SM::used::planted::MISSILE_IMG::[collisionwithMINE2_MISSILE_BMP?~} */
if (BSP_doBitmapsOverlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine2_exploding_s, /* target state */
{
Q_ACTION_CAST(&Mine2_exploding_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* 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
@ -282,30 +203,30 @@ 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_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine2_exploding);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Mine2_used);
break;
}
}
return status_;
}
/*${AOs::Mine2::SM::used::exploding} .......................................*/
/* ${AOs::Mine2::SM::used::exploding} */
static QState Mine2_exploding_e(Mine2 * const me) {
me->exp_ctr = 0U;
return QM_ENTRY(&Mine2_exploding_s);
}
/* ${AOs::Mine2::SM::used::exploding} */
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Mine2::SM::used::exploding} */
case Q_ENTRY_SIG: {
me->exp_ctr = 0U;
status_ = Q_HANDLED();
break;
}
/* ${AOs::Mine2::SM::used::exploding::TIME_TICK} */
case TIME_TICK_SIG: {
/* ${AOs::Mine2::SM::used::exploding::TIME_TICK::[stillonscreen?]} */
@ -320,26 +241,16 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Mine2::SM::used::exploding::TIME_TICK::[else]} */
else {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Mine2_unused_s, /* target state */
{
Q_ACTION_CAST(&Mine2_used_x), /* exit */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Mine2_unused);
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Mine2_used);
break;
}
}

View File

@ -22,10 +22,15 @@
/* Q_DEFINE_THIS_FILE */
/* local objects -----------------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Missile} ..........................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t x;
@ -35,31 +40,9 @@ typedef struct {
/* protected: */
static QState Missile_initial(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, /* superstate (top) */
Q_STATE_CAST(&Missile_armed),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
static QState Missile_flying (Missile * const me, QEvt const * const e);
static QMState const Missile_flying_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Missile_flying),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Missile_exploding),
Q_ACTION_CAST(&Missile_exploding_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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 Missile l_missile; /* the sole instance of the Missile active object */
@ -70,17 +53,11 @@ QMActive * const AO_Missile = &l_missile.super; /* opaque AO pointer */
/*${AOs::Missile_ctor} .....................................................*/
void Missile_ctor(void) {
Missile *me = &l_missile;
QMActive_ctor(&me->super, Q_STATE_CAST(&Missile_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Missile_initial));
}
/*${AOs::Missile} ..........................................................*/
/*${AOs::Missile::SM} ......................................................*/
static QState Missile_initial(Missile * const me, QEvt const * const e) {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Missile_armed_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Missile::SM::initial} */
(void)e;
QActive_subscribe((QActive *)me, TIME_TICK_SIG);
@ -95,35 +72,27 @@ 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 QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Missile_armed);
}
/*${AOs::Missile::SM::armed} ...............................................*/
/* ${AOs::Missile::SM::armed} */
static QState Missile_armed(Missile * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Missile::SM::armed::MISSILE_FIRE} */
case MISSILE_FIRE_SIG: {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Missile_flying_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
me->x = Q_EVT_CAST(ObjectPosEvt)->x;
me->y = Q_EVT_CAST(ObjectPosEvt)->y;
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Missile_flying);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Missile::SM::flying} ..............................................*/
/* ${AOs::Missile::SM::flying} */
static QState Missile_flying(Missile * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
@ -139,64 +108,42 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Missile::SM::flying::TIME_TICK::[else]} */
else {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Missile_armed_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Missile_armed);
}
break;
}
/* ${AOs::Missile::SM::flying::HIT_WALL} */
case HIT_WALL_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Missile_exploding_s, /* target state */
{
Q_ACTION_CAST(&Missile_exploding_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Missile_exploding);
break;
}
/* ${AOs::Missile::SM::flying::DESTROYED_MINE} */
case DESTROYED_MINE_SIG: {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Missile_armed_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
QACTIVE_POST(AO_Ship, e, me);
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Missile_armed);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Missile::SM::exploding} ...........................................*/
/* ${AOs::Missile::SM::exploding} */
static QState Missile_exploding_e(Missile * const me) {
me->exp_ctr = 0U;
return QM_ENTRY(&Missile_exploding_s);
}
/* ${AOs::Missile::SM::exploding} */
static QState Missile_exploding(Missile * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Missile::SM::exploding} */
case Q_ENTRY_SIG: {
me->exp_ctr = 0U;
status_ = Q_HANDLED();
break;
}
/* ${AOs::Missile::SM::exploding::TIME_TICK} */
case TIME_TICK_SIG: {
/* ${AOs::Missile::SM::exploding::TIME_TICK::[(me->x>=GAME_SPEED_X)&&(me->exp~} */
@ -212,22 +159,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Missile::SM::exploding::TIME_TICK::[else]} */
else {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Missile_armed_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Missile_armed);
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -25,10 +25,15 @@
#define SHIP_HEIGHT 3
/* encapsulated delcaration of the Ship active object ----------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Ship} .............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t x;
@ -39,41 +44,10 @@ typedef struct {
/* 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_active_i(Ship * const me);
static QMState const Ship_active_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Ship_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(&Ship_active_i)
};
static QState Ship_parked (Ship * const me, QEvt const * const e);
static QMState const Ship_parked_s = {
&Ship_active_s, /* superstate */
Q_STATE_CAST(&Ship_parked),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Ship_flying),
Q_ACTION_CAST(&Ship_flying_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Ship_exploding),
Q_ACTION_CAST(&Ship_exploding_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* local objects -----------------------------------------------------------*/
@ -86,23 +60,13 @@ QMActive * const AO_Ship = &l_ship.super; /* opaque AO pointer */
/*${AOs::Ship_ctor} ........................................................*/
void Ship_ctor(void) {
Ship *me = &l_ship;
QMActive_ctor(&me->super, Q_STATE_CAST(&Ship_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Ship_initial));
me->x = GAME_SHIP_X;
me->y = (GAME_SHIP_Y << 2);
}
/*${AOs::Ship} .............................................................*/
/*${AOs::Ship::SM} .........................................................*/
static QState Ship_initial(Ship * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Ship_active_s, /* target state */
{
Q_ACTION_CAST(&Ship_active_i), /* init.tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Ship::SM::initial} */
(void)e; /* avoid the compiler warning 'usused parameter' */
QActive_subscribe((QActive *)me, TIME_TICK_SIG);
@ -121,76 +85,57 @@ 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 QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Ship_active);
}
/*${AOs::Ship::SM::active} .................................................*/
/* ${AOs::Ship::SM::active::initial} */
static QState Ship_active_i(Ship * const me) {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Ship_parked_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Ship::SM::active::initial} */
return QM_TRAN_INIT(&tatbl_);
}
/* ${AOs::Ship::SM::active} */
static QState Ship_active(Ship * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Ship::SM::active::initial} */
case Q_INIT_SIG: {
status_ = Q_TRAN(&Ship_parked);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Ship::SM::active::parked} .........................................*/
/* ${AOs::Ship::SM::active::parked} */
static QState Ship_parked(Ship * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Ship::SM::active::parked::TAKE_OFF} */
case TAKE_OFF_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Ship_flying_s, /* target state */
{
Q_ACTION_CAST(&Ship_flying_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Ship_flying);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Ship_active);
break;
}
}
return status_;
}
/*${AOs::Ship::SM::active::flying} .........................................*/
/* ${AOs::Ship::SM::active::flying} */
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);
/* lauch the ship from the initial hight */
me->y = (GAME_SHIP_Y << 2);
return QM_ENTRY(&Ship_flying_s);
}
/* ${AOs::Ship::SM::active::flying} */
static QState Ship_flying(Ship * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Ship::SM::active::flying} */
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);
/* lauch the ship from the initial hight */
me->y = (GAME_SHIP_Y << 2);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Ship::SM::active::flying::TIME_TICK} */
case TIME_TICK_SIG: {
ObjectImageEvt *oie;
@ -220,7 +165,7 @@ static QState Ship_flying(Ship * const me, QEvt const * const e) {
sev->score = me->score;
QACTIVE_POST(AO_Tunnel, (QEvt *)sev, me);
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Ship::SM::active::flying::PLAYER_TRIGGER} */
@ -229,63 +174,43 @@ static QState Ship_flying(Ship * const me, QEvt const * const e) {
ope->x = me->x;
ope->y = (me->y >> 2) + SHIP_HEIGHT - 1U;
QACTIVE_POST(AO_Missile, (QEvt *)ope, me);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Ship::SM::active::flying::DESTROYED_MINE} */
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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Ship::SM::active::flying::HIT_WALL} */
case HIT_WALL_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Ship_exploding_s, /* target state */
{
Q_ACTION_CAST(&Ship_exploding_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Ship_exploding);
break;
}
/* ${AOs::Ship::SM::active::flying::HIT_MINE} */
case HIT_MINE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Ship_exploding_s, /* target state */
{
Q_ACTION_CAST(&Ship_exploding_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Ship_exploding);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Ship_active);
break;
}
}
return status_;
}
/*${AOs::Ship::SM::active::exploding} ......................................*/
/* ${AOs::Ship::SM::active::exploding} */
static QState Ship_exploding_e(Ship * const me) {
me->exp_ctr = 0U;
return QM_ENTRY(&Ship_exploding_s);
}
/* ${AOs::Ship::SM::active::exploding} */
static QState Ship_exploding(Ship * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Ship::SM::active::exploding} */
case Q_ENTRY_SIG: {
me->exp_ctr = 0U;
status_ = Q_HANDLED();
break;
}
/* ${AOs::Ship::SM::active::exploding::TIME_TICK} */
case TIME_TICK_SIG: {
/* ${AOs::Ship::SM::active::exploding::TIME_TICK::[me->exp_ctr<15U]} */
@ -298,25 +223,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 >> 2) - 4U + SHIP_HEIGHT);
QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Ship::SM::active::exploding::TIME_TICK::[else]} */
else {
static QMTranActTable const tatbl_ = { /* transition-action table */
&Ship_parked_s,
{
Q_ACTION_CAST(0) /* zero terminator */
}
};
ScoreEvt *gameOver = Q_NEW(ScoreEvt, GAME_OVER_SIG);
gameOver->score = me->score;
QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me);
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Ship_parked);
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Ship_active);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* local objects -----------------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Tunnel} ...........................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt blinkTimeEvt;
@ -48,92 +53,15 @@ static void Tunnel_dispatchToAllMines(Tunnel * const me, QEvt const * e);
/* protected: */
static QState Tunnel_initial(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, /* superstate (top) */
Q_STATE_CAST(&Tunnel_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_show_logo),
Q_ACTION_CAST(&Tunnel_show_logo_e),
Q_ACTION_CAST(&Tunnel_show_logo_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_demo),
Q_ACTION_CAST(&Tunnel_demo_e),
Q_ACTION_CAST(&Tunnel_demo_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_playing),
Q_ACTION_CAST(&Tunnel_playing_e),
Q_ACTION_CAST(&Tunnel_playing_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_game_over),
Q_ACTION_CAST(&Tunnel_game_over_e),
Q_ACTION_CAST(&Tunnel_game_over_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_screen_saver),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(&Tunnel_screen_saver_i)
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_screen_saver_hide),
Q_ACTION_CAST(&Tunnel_screen_saver_hide_e),
Q_ACTION_CAST(&Tunnel_screen_saver_hide_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Tunnel_screen_saver_show),
Q_ACTION_CAST(&Tunnel_screen_saver_show_e),
Q_ACTION_CAST(&Tunnel_screen_saver_show_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Tunnel_final),
Q_ACTION_CAST(&Tunnel_final_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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 Tunnel l_tunnel; /* the sole instance of the Tunnel active object */
@ -145,7 +73,7 @@ QMActive * const AO_Tunnel = &l_tunnel.super; /* opaque AO pointer */
void Tunnel_ctor(void) {
uint8_t n;
Tunnel *me = &l_tunnel;
QMActive_ctor(&me->super, Q_STATE_CAST(&Tunnel_initial));
QActive_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) {
@ -238,7 +166,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;
QMSM_DISPATCH(me->mines[n], (QEvt *)&ope); /* direct dispatch */
QHSM_DISPATCH(me->mines[n], (QEvt *)&ope); /* direct dispatch */
}
}
}
@ -248,27 +176,17 @@ static void Tunnel_dispatchToAllMines(Tunnel * const me, QEvt const * e) {
for (n = 0U; n < GAME_MINES_MAX; ++n) {
if (me->mines[n] != (QMsm *)0) { /* is the mine used? */
QMSM_DISPATCH(me->mines[n], e);
QHSM_DISPATCH(me->mines[n], e);
}
}
}
/*${AOs::Tunnel::SM} .......................................................*/
static QState Tunnel_initial(Tunnel * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Tunnel_show_logo_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_show_logo_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Tunnel::SM::initial} */
uint8_t n;
for (n = 0U; n < GAME_MINES_MAX; ++n) {
QMSM_INIT(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
QMSM_INIT(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
QHSM_INIT(me->mine1_pool[n], (QEvt *)0);/*initial tran. for Mine1 */
QHSM_INIT(me->mine2_pool[n], (QEvt *)0);/*initial tran. for Mine2 */
}
BSP_randomSeed(1234); /* seed the pseudo-random generator */
@ -304,10 +222,9 @@ static QState Tunnel_initial(Tunnel * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(SCORE_SIG, &l_tunnel);
(void)e; /* unused parameter */
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Tunnel_show_logo);
}
/*${AOs::Tunnel::SM::active} ...............................................*/
/* ${AOs::Tunnel::SM::active} */
static QState Tunnel_active(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
@ -316,71 +233,51 @@ static QState Tunnel_active(Tunnel * const me, QEvt const * const e) {
Q_ASSERT((Q_EVT_CAST(MineEvt)->id < GAME_MINES_MAX)
&& (me->mines[Q_EVT_CAST(MineEvt)->id] != (QMsm *)0));
me->mines[Q_EVT_CAST(MineEvt)->id] = (QMsm *)0;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::PLAYER_QUIT} */
case PLAYER_QUIT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Tunnel_final_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_final_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_final);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::active::show_logo} ....................................*/
/* ${AOs::Tunnel::SM::active::show_logo} */
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_paintString(24U, (GAME_TUNNEL_HEIGHT / 2U) - 8U, "Quantum LeAps");
BSP_paintString(16U, (GAME_TUNNEL_HEIGHT / 2U) + 0U, "state-machine.com");
BSP_paintString(1U, GAME_TUNNEL_HEIGHT - 18U, "Fire missile: BTN0");
BSP_paintString(1U, GAME_TUNNEL_HEIGHT - 10U, "Fly ship up: BTN1");
BSP_updateScreen();
return QM_ENTRY(&Tunnel_show_logo_s);
}
/* ${AOs::Tunnel::SM::active::show_logo} */
static QState Tunnel_show_logo_x(Tunnel * const me) {
QTimeEvt_disarm(&me->blinkTimeEvt);
QTimeEvt_disarm(&me->screenTimeEvt);
return QM_EXIT(&Tunnel_show_logo_s);
}
/* ${AOs::Tunnel::SM::active::show_logo} */
static QState Tunnel_show_logo(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::show_logo} */
case Q_ENTRY_SIG: {
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_paintString(24U, (GAME_TUNNEL_HEIGHT / 2U) - 8U, "Quantum LeAps");
BSP_paintString(16U, (GAME_TUNNEL_HEIGHT / 2U) + 0U, "state-machine.com");
BSP_paintString(1U, GAME_TUNNEL_HEIGHT - 18U, "Fire missile: BTN0");
BSP_paintString(1U, GAME_TUNNEL_HEIGHT - 10U, "Fly ship up: BTN1");
BSP_updateScreen();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::show_logo} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->blinkTimeEvt);
QTimeEvt_disarm(&me->screenTimeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::show_logo::SCREEN_TIMEOUT} */
case SCREEN_TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_demo_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_show_logo_x), /* exit */
Q_ACTION_CAST(&Tunnel_demo_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_demo);
break;
}
/* ${AOs::Tunnel::SM::active::show_logo::BLINK_TIMEOUT} */
@ -390,74 +287,63 @@ static QState Tunnel_show_logo(Tunnel * const me, QEvt const * const e) {
if (me->blink_ctr == 0U) {
BSP_paintString(24U + 8U*6U, (GAME_TUNNEL_HEIGHT / 2U) - 8U, "LeAps");
BSP_updateScreen();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Tunnel::SM::active::show_logo::BLINK_TIMEOUT::[else]} */
else {
BSP_paintString(24U + 8U*6U, (GAME_TUNNEL_HEIGHT / 2U) - 8U, "LeaPs");
BSP_updateScreen();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_active);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Tunnel::SM::active::demo} .........................................*/
/* ${AOs::Tunnel::SM::active::demo} */
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->wall_gap = GAME_WALLS_GAP_Y;
/* clear the tunnel walls */
BSP_clearWalls();
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*20U, 0U);
me->blink_ctr = 0U; /* init the blink counter */
return QM_ENTRY(&Tunnel_demo_s);
}
/* ${AOs::Tunnel::SM::active::demo} */
static QState Tunnel_demo_x(Tunnel * const me) {
QTimeEvt_disarm(&me->blinkTimeEvt);
QTimeEvt_disarm(&me->screenTimeEvt);
return QM_EXIT(&Tunnel_demo_s);
}
/* ${AOs::Tunnel::SM::active::demo} */
static QState Tunnel_demo(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::demo} */
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->wall_gap = GAME_WALLS_GAP_Y;
/* clear the tunnel walls */
BSP_clearWalls();
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*20U, 0U);
me->blink_ctr = 0U; /* init the blink counter */
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::demo} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->blinkTimeEvt);
QTimeEvt_disarm(&me->screenTimeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::demo::BLINK_TIMEOUT} */
case BLINK_TIMEOUT_SIG: {
me->blink_ctr ^= 1U; /* toggle the blink cunter */
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::demo::SCREEN_TIMEOUT} */
case SCREEN_TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_screen_saver_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_demo_x), /* exit */
Q_ACTION_CAST(&Tunnel_screen_saver_i), /* init.tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_screen_saver);
break;
}
/* ${AOs::Tunnel::SM::active::demo::TIME_TICK} */
@ -470,51 +356,41 @@ static QState Tunnel_demo(Tunnel * const me, QEvt const * const e) {
"Press BTN0");
}
BSP_updateScreen();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::demo::PLAYER_TRIGGER} */
case PLAYER_TRIGGER_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_playing_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_demo_x), /* exit */
Q_ACTION_CAST(&Tunnel_playing_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_playing);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_active);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::active::playing} ......................................*/
/* ${AOs::Tunnel::SM::active::playing} */
static QState Tunnel_playing_e(Tunnel * const me) {
static QEvt const takeoff = { TAKE_OFF_SIG, 0U, 0U };
me->wall_gap = GAME_WALLS_GAP_Y;
QACTIVE_POST(AO_Ship, &takeoff, me); /* post the TAKEOFF sig */
return QM_ENTRY(&Tunnel_playing_s);
}
/* ${AOs::Tunnel::SM::active::playing} */
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);
}
/* ${AOs::Tunnel::SM::active::playing} */
static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::playing} */
case Q_ENTRY_SIG: {
static QEvt const takeoff = { TAKE_OFF_SIG, 0U, 0U };
me->wall_gap = GAME_WALLS_GAP_Y;
QACTIVE_POST(AO_Ship, &takeoff, me); /* post the TAKEOFF sig */
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing} */
case Q_EXIT_SIG: {
QEvt recycle;
recycle.sig = MINE_RECYCLE_SIG;
Tunnel_dispatchToAllMines(me, &recycle); /* recycle all Mines */
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::TIME_TICK} */
case TIME_TICK_SIG: {
/* render this frame on the display */
@ -522,7 +398,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
Tunnel_advance(me);
Tunnel_plantMine(me);
Tunnel_dispatchToAllMines(me, e);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::SHIP_IMG} */
@ -538,7 +414,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
}
BSP_paintBitmap(x, y, bmp);
Tunnel_dispatchToAllMines(me, e); /* let Mines check for hits */
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::MISSILE_IMG} */
@ -554,7 +430,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
}
BSP_paintBitmap(x, y, bmp);
Tunnel_dispatchToAllMines(me, e); /* let Mines check for hits */
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::MINE_IMG} */
@ -562,7 +438,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
BSP_paintBitmap(Q_EVT_CAST(ObjectImageEvt)->x,
Q_EVT_CAST(ObjectImageEvt)->y,
Q_EVT_CAST(ObjectImageEvt)->bmp);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::EXPLOSION} */
@ -570,7 +446,7 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
BSP_paintBitmap(Q_EVT_CAST(ObjectImageEvt)->x,
Q_EVT_CAST(ObjectImageEvt)->y,
Q_EVT_CAST(ObjectImageEvt)->bmp);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::SCORE} */
@ -584,59 +460,49 @@ static QState Tunnel_playing(Tunnel * const me, QEvt const * const e) {
if (me->wall_gap < GAME_WALLS_MIN_GAP_Y) {
me->wall_gap = GAME_WALLS_MIN_GAP_Y;
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::playing::GAME_OVER} */
case GAME_OVER_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_game_over_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_playing_x), /* exit */
Q_ACTION_CAST(&Tunnel_game_over_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
BSP_clearWalls();
BSP_updateScore(Q_EVT_CAST(ScoreEvt)->score);
BSP_updateScreen();
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_game_over);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_active);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::active::game_over} ....................................*/
/* ${AOs::Tunnel::SM::active::game_over} */
static QState Tunnel_game_over_e(Tunnel * const me) {
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
me->blink_ctr = 0U;
BSP_paintString((GAME_TUNNEL_WIDTH - 6U * 9U) / 2U,
(GAME_TUNNEL_HEIGHT / 2U) - 4U,
"Game Over");
BSP_updateScreen();
return QM_ENTRY(&Tunnel_game_over_s);
}
/* ${AOs::Tunnel::SM::active::game_over} */
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);
}
/* ${AOs::Tunnel::SM::active::game_over} */
static QState Tunnel_game_over(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::game_over} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->blinkTimeEvt, BSP_TICKS_PER_SEC/2U,
BSP_TICKS_PER_SEC/2U); /* every 1/2 sec */
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*5U, 0U);
me->blink_ctr = 0U;
BSP_paintString((GAME_TUNNEL_WIDTH - 6U * 9U) / 2U,
(GAME_TUNNEL_HEIGHT / 2U) - 4U,
"Game Over");
BSP_updateScreen();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::game_over} */
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;
}
/* ${AOs::Tunnel::SM::active::game_over::BLINK_TIMEOUT} */
case BLINK_TIMEOUT_SIG: {
me->blink_ctr ^= 1U; /* toggle the blink counter */
@ -646,181 +512,127 @@ static QState Tunnel_game_over(Tunnel * const me, QEvt const * const e) {
? "Game Over"
: " "));
BSP_updateScreen();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::game_over::SCREEN_TIMEOUT} */
case SCREEN_TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_demo_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_game_over_x), /* exit */
Q_ACTION_CAST(&Tunnel_demo_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_demo);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_active);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::active::screen_saver} .................................*/
/* ${AOs::Tunnel::SM::active::screen_saver::initial} */
static QState Tunnel_screen_saver_i(Tunnel * const me) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Tunnel_screen_saver_hide_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_screen_saver_hide_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Tunnel::SM::active::screen_saver::initial} */
return QM_TRAN_INIT(&tatbl_);
}
/* ${AOs::Tunnel::SM::active::screen_saver} */
static QState Tunnel_screen_saver(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::screen_saver::initial} */
case Q_INIT_SIG: {
status_ = Q_TRAN(&Tunnel_screen_saver_hide);
break;
}
/* ${AOs::Tunnel::SM::active::screen_saver::PLAYER_TRIGGER} */
case PLAYER_TRIGGER_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Tunnel_demo_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_demo_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_demo);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_active);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::active::screen_saver::screen_saver_hide} ..............*/
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_hide} */
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);
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_hide} */
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);
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_hide} */
static QState Tunnel_screen_saver_hide(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_hide} */
case Q_ENTRY_SIG: {
BSP_displayOff(); /* power down the display */
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC*3U, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_hide} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->screenTimeEvt);
BSP_displayOn(); /* power up the display */
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_hid~::SCREEN_TIMEOUT} */
case SCREEN_TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_screen_saver_show_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_screen_saver_hide_x), /* exit */
Q_ACTION_CAST(&Tunnel_screen_saver_show_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_screen_saver_show);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_screen_saver);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::active::screen_saver::screen_saver_show} ..............*/
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_show} */
static QState Tunnel_screen_saver_show_e(Tunnel * const me) {
uint32_t rnd = BSP_random();
/* clear the screen frame buffer */
BSP_clearFB();
BSP_paintString((uint8_t)(rnd % (GAME_TUNNEL_WIDTH - 10U*6U)),
(uint8_t) (rnd % (GAME_TUNNEL_HEIGHT - 8U)),
"Press BTN0");
BSP_updateScreen();
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC/2U, 0U);
return QM_ENTRY(&Tunnel_screen_saver_show_s);
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_show} */
static QState Tunnel_screen_saver_show_x(Tunnel * const me) {
QTimeEvt_disarm(&me->screenTimeEvt);
BSP_clearFB();
BSP_updateScreen();
return QM_EXIT(&Tunnel_screen_saver_show_s);
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_show} */
static QState Tunnel_screen_saver_show(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_show} */
case Q_ENTRY_SIG: {
uint32_t rnd = BSP_random();
/* clear the screen frame buffer */
BSP_clearFB();
BSP_paintString((uint8_t)(rnd % (GAME_TUNNEL_WIDTH - 10U*6U)),
(uint8_t) (rnd % (GAME_TUNNEL_HEIGHT - 8U)),
"Press BTN0");
BSP_updateScreen();
QTimeEvt_armX(&me->screenTimeEvt, BSP_TICKS_PER_SEC/2U, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_show} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->screenTimeEvt);
BSP_clearFB();
BSP_updateScreen();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Tunnel::SM::active::screen_saver::screen_saver_sho~::SCREEN_TIMEOUT} */
case SCREEN_TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Tunnel_screen_saver_hide_s, /* target state */
{
Q_ACTION_CAST(&Tunnel_screen_saver_show_x), /* exit */
Q_ACTION_CAST(&Tunnel_screen_saver_hide_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Tunnel_screen_saver_hide);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Tunnel_screen_saver);
break;
}
}
return status_;
}
/*${AOs::Tunnel::SM::final} ................................................*/
/* ${AOs::Tunnel::SM::final} */
static QState Tunnel_final_e(Tunnel * const me) {
/* clear the screen */
BSP_clearFB();
BSP_updateScreen();
QF_stop(); /* stop QF and cleanup */
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Tunnel_final_s);
}
/* ${AOs::Tunnel::SM::final} */
static QState Tunnel_final(Tunnel * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Tunnel::SM::final} */
case Q_ENTRY_SIG: {
/* clear the screen */
BSP_clearFB();
BSP_updateScreen();
QF_stop(); /* stop QF and cleanup */
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -53,12 +58,14 @@ extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QMActive * const AO_Table;
extern QActive * const AO_Table;
#ifdef qxk_h
void Test_ctor(void);
extern QXThread * const XT_Test;
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -368,8 +374,10 @@ $declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test_ctor(void);
extern QXThread * const XT_Test;
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -362,11 +368,18 @@ $declare(Events::TableEvt)
#define N_PHILO ((uint8_t)5)
$declare(AOs::Philo_ctor)
$declare(AOs::Table_ctor)
$declare(AOs::AO_Philo[N_PHILO])
$declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>
</file>
<file name="philo.c">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -362,11 +368,18 @@ $declare(Events::TableEvt)
#define N_PHILO ((uint8_t)5)
$declare(AOs::Philo_ctor)
$declare(AOs::Table_ctor)
$declare(AOs::AO_Philo[N_PHILO])
$declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>
</file>
<file name="philo.c">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
@ -10,7 +10,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -112,7 +112,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -322,7 +322,7 @@ me-&gt;fork[n] = FREE;</action>
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +330,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,21 @@ 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 QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +125,36 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +162,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +200,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -129,59 +100,57 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +170,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +217,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +266,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +284,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -362,11 +368,18 @@ $declare(Events::TableEvt)
#define N_PHILO ((uint8_t)5)
$declare(AOs::Philo_ctor)
$declare(AOs::Table_ctor)
$declare(AOs::AO_Philo[N_PHILO])
$declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>
</file>
<file name="philo.c">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -1,7 +1,7 @@
/*****************************************************************************
* Product: QHsmTst Example, Linux
* Last updated for version 5.6.0
* Last updated on 2015-12-18
* Last updated for version 5.8.0
* Last updated on 2016-11-29
*
* Q u a n t u m L e a P s
* ---------------------------
@ -49,63 +49,63 @@ static void dispatch(QSignal sig);
/*..........................................................................*/
int main(int argc, char *argv[]) {
QHsmTst_ctor(); /* instantiate the QHsmTst object */
QHsmTst_ctor(); /* instantiate the QHsmTst object */
if (argc > 1) { /* file name provided? */
if (argc > 1) { /* file name provided? */
l_outFile = fopen(argv[1], "w");
}
if (l_outFile == (FILE *)0) { /* interactive version? */
if (l_outFile == (FILE *)0) { /* interactive version? */
struct termios newt;
tcgetattr(STDIN_FILENO, &l_oldt); /* save the terminal state */
tcgetattr(STDIN_FILENO, &l_oldt); /* save the terminal state */
newt = l_oldt;
newt.c_lflag &= ~ICANON;
tcsetattr(STDIN_FILENO, TCSANOW, &newt); /* set non-canonical mode */
tcsetattr(STDIN_FILENO, TCSANOW, &newt); /* set non-canonical mode */
l_outFile = stdout; /* use the stdout as the output file */
l_outFile = stdout; /* use the stdout as the output file */
printf("QHsmTst example, built on %s at %s,\n"
"QEP: %s.\nPress ESC to quit...\n",
__DATE__, __TIME__, QEP_getVersion());
"QP: %s.\nPress ESC to quit...\n",
__DATE__, __TIME__, QP_VERSION_STR);
QMSM_INIT(the_hsm, (QEvt *)0); /* the top-most initial tran. */
QHSM_INIT(the_hsm, (QEvt *)0); /* the top-most initial tran. */
for (;;) { /* event loop */
for (;;) { /* event loop */
QEvt e;
int c;
printf("\n>");
c = getchar(); /* get a character from stdin */
c = getchar(); /* get a character from stdin */
printf(": ");
if ('a' <= c && c <= 'i') { /* in range? */
if ('a' <= c && c <= 'i') { /* in range? */
e.sig = (QSignal)(c - 'a' + A_SIG);
}
else if ('A' <= c && c <= 'I') { /* in range? */
else if ('A' <= c && c <= 'I') { /* in range? */
e.sig = (QSignal)(c - 'A' + A_SIG);
}
else if (c == '\33') { /* the ESC key? */
e.sig = TERMINATE_SIG; /* terminate the interactive test */
else if (c == '\33') { /* the ESC key? */
e.sig = TERMINATE_SIG; /* terminate the interactive test */
}
else {
e.sig = IGNORE_SIG;
}
QMSM_DISPATCH(the_hsm, &e); /* dispatch the event */
QHSM_DISPATCH(the_hsm, &e); /* dispatch the event */
}
}
else { /* batch version */
printf("QHsmTst example, built on %s at %s, QEP %s\n"
else { /* batch version */
printf("QHsmTst example, built on %s at %s, QP %s\n"
"output saved to %s\n",
__DATE__, __TIME__, QEP_getVersion(),
__DATE__, __TIME__, QP_VERSION_STR,
argv[1]);
fprintf(l_outFile, "QHsmTst example, QEP %s\n",
QEP_getVersion());
QP_VERSION_STR);
QMSM_INIT(the_hsm, (QEvt *)0); /* the top-most initial tran. */
QHSM_INIT(the_hsm, (QEvt *)0); /* the top-most initial tran. */
/* testing of dynamic transitions... */
/* testing of dynamic transitions... */
dispatch(A_SIG);
dispatch(B_SIG);
dispatch(D_SIG);
@ -155,7 +155,7 @@ static void dispatch(QSignal sig) {
Q_REQUIRE((A_SIG <= sig) && (sig <= I_SIG));
e.sig = sig;
fprintf(l_outFile, "\n%c:", 'A' + sig - A_SIG);
QMSM_DISPATCH(the_hsm, &e); /* dispatch the event */
QHSM_DISPATCH(the_hsm, &e); /* dispatch the event */
}
/*--------------------------------------------------------------------------*/
@ -180,5 +180,3 @@ QSTimeCtr QS_onGetTime(void) {
}
#endif

View File

@ -18,6 +18,11 @@
#include "qpc.h"
#include "qhsmtst.h"
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${HSMs::QHsmTst} .........................................................*/
typedef struct {
/* protected: */

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>QHsmTst is a contrived state machine from Chapter 2 of the PSiCC2 book for testing all possible transition topologies with up to 4-levels of state nesting.</documentation>
<framework name="qpc"/>
<package name="HSMs" stereotype="0x02">

View File

@ -1,23 +0,0 @@
QMsmTst example, QEP 5.5.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;
D:s211-D;s211-EXIT;s21-INIT;s211-ENTRY;
E:s-E;s211-EXIT;s21-EXIT;s2-EXIT;s1-ENTRY;s11-ENTRY;
I:s1-I;
F:s1-F;s11-EXIT;s1-EXIT;s2-ENTRY;s21-ENTRY;s211-ENTRY;
I:s2-I;
I:s-I;
F:s2-F;s211-EXIT;s21-EXIT;s2-EXIT;s1-ENTRY;s11-ENTRY;
A:s1-A;s11-EXIT;s1-EXIT;s1-ENTRY;s1-INIT;s11-ENTRY;
B:s1-B;s11-EXIT;s11-ENTRY;
D:s1-D;s11-EXIT;s1-EXIT;s-INIT;s1-ENTRY;s11-ENTRY;
D:s11-D;s11-EXIT;s1-INIT;s11-ENTRY;
E:s-E;s11-EXIT;s1-EXIT;s1-ENTRY;s11-ENTRY;
G:s11-G;s11-EXIT;s1-EXIT;s2-ENTRY;s21-ENTRY;s211-ENTRY;
H:s211-H;s211-EXIT;s21-EXIT;s2-EXIT;s-INIT;s1-ENTRY;s11-ENTRY;
H:s11-H;s11-EXIT;s1-EXIT;s-INIT;s1-ENTRY;s11-ENTRY;
C:s1-C;s11-EXIT;s1-EXIT;s2-ENTRY;s2-INIT;s21-ENTRY;s211-ENTRY;
G:s21-G;s211-EXIT;s21-EXIT;s2-EXIT;s1-ENTRY;s1-INIT;s11-ENTRY;
C:s1-C;s11-EXIT;s1-EXIT;s2-ENTRY;s2-INIT;s21-ENTRY;s211-ENTRY;
C:s2-C;s211-EXIT;s21-EXIT;s2-EXIT;s1-ENTRY;s1-INIT;s11-ENTRY;

View File

@ -1,7 +1,7 @@
/*****************************************************************************
* Product: QMsmTst Example, Linux
* Last updated for version 5.6.0
* Last updated on 2015-12-18
* Last updated for version 5.8.0
* Last updated on 2016-11-29
*
* Q u a n t u m L e a P s
* ---------------------------
@ -49,63 +49,63 @@ static void dispatch(QSignal sig);
/*..........................................................................*/
int main(int argc, char *argv[]) {
QMsmTst_ctor(); /* instantiate the QMsmTst object */
QMsmTst_ctor(); /* instantiate the QMsmTst object */
if (argc > 1) { /* file name provided? */
if (argc > 1) { /* file name provided? */
l_outFile = fopen(argv[1], "w");
}
if (l_outFile == (FILE *)0) { /* interactive version? */
if (l_outFile == (FILE *)0) { /* interactive version? */
struct termios newt;
tcgetattr(STDIN_FILENO, &l_oldt); /* save the terminal state */
tcgetattr(STDIN_FILENO, &l_oldt); /* save the terminal state */
newt = l_oldt;
newt.c_lflag &= ~ICANON;
tcsetattr(STDIN_FILENO, TCSANOW, &newt); /* set non-canonical mode */
tcsetattr(STDIN_FILENO, TCSANOW, &newt); /* set non-canonical mode */
l_outFile = stdout; /* use the stdout as the output file */
l_outFile = stdout; /* use the stdout as the output file */
printf("QMsmTst example, built on %s at %s,\n"
"QEP: %s.\nPress ESC to quit...\n",
__DATE__, __TIME__, QEP_getVersion());
"QP: %s.\nPress ESC to quit...\n",
__DATE__, __TIME__, QP_VERSION_STR);
QMSM_INIT(the_msm, (QEvt *)0); /* the top-most initial tran. */
QHSM_INIT(the_msm, (QEvt *)0); /* the top-most initial tran. */
for (;;) { /* event loop */
for (;;) { /* event loop */
QEvt e;
int c;
printf("\n>");
c = getchar(); /* get a character from stdin */
c = getchar(); /* get a character from stdin */
printf(": ");
if ('a' <= c && c <= 'i') { /* in range? */
if ('a' <= c && c <= 'i') { /* in range? */
e.sig = (QSignal)(c - 'a' + A_SIG);
}
else if ('A' <= c && c <= 'I') { /* in range? */
else if ('A' <= c && c <= 'I') { /* in range? */
e.sig = (QSignal)(c - 'A' + A_SIG);
}
else if (c == '\33') { /* the ESC key? */
e.sig = TERMINATE_SIG; /* terminate the interactive test */
else if (c == '\33') { /* the ESC key? */
e.sig = TERMINATE_SIG; /* terminate the interactive test */
}
else {
e.sig = IGNORE_SIG;
}
QMSM_DISPATCH(the_msm, &e); /* dispatch the event */
QHSM_DISPATCH(the_msm, &e); /* dispatch the event */
}
}
else { /* batch version */
printf("QMsmTst example, built on %s at %s, QEP %s\n"
else { /* batch version */
printf("QMsmTst example, built on %s at %s, QP %s\n"
"output saved to %s\n",
__DATE__, __TIME__, QEP_getVersion(),
__DATE__, __TIME__, QP_VERSION_STR,
argv[1]);
fprintf(l_outFile, "QMsmTst example, QEP %s\n",
QEP_getVersion());
QP_VERSION_STR);
QMSM_INIT(the_msm, (QEvt *)0); /* the top-most initial tran. */
QHSM_INIT(the_msm, (QEvt *)0); /* the top-most initial tran. */
/* testing of dynamic transitions... */
/* testing of dynamic transitions... */
dispatch(A_SIG);
dispatch(B_SIG);
dispatch(D_SIG);
@ -155,7 +155,7 @@ static void dispatch(QSignal sig) {
Q_REQUIRE((A_SIG <= sig) && (sig <= I_SIG));
e.sig = sig;
fprintf(l_outFile, "\n%c:", 'A' + sig - A_SIG);
QMSM_DISPATCH(the_msm, &e); /* dispatch the event */
QHSM_DISPATCH(the_msm, &e); /* dispatch the event */
}
/*--------------------------------------------------------------------------*/

View File

@ -5,19 +5,26 @@
* 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.
*
* 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.
* This code is covered by the following commercial QP license:
* License # : QPC-EVAL-161130
* Issued to : Company/individual evaluating the QP/C framework
* Framework(s): qpc
* Support ends: 2017-01-31
* Product(s) :
* This license is available only for evaluation purposes and
* the generated code is still licensed under the terms of GPL.
* Please submit request for extension of the evaluaion period at:
* http://www.state-machine.com/licensing/index.html#RequestForm
*****************************************************************************/
/*${.::qmsmtst.c} ..........................................................*/
#include "qpc.h"
#include "qmsmtst.h"
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${SMs::QMsmTst} ..........................................................*/
typedef struct {
/* protected: */
@ -116,7 +123,7 @@ static QState QMsmTst_initial(QMsmTst * const me, QEvt const * const e) {
{
Q_ACTION_CAST(&QMsmTst_s_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s2_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s2_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s2_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -254,7 +261,7 @@ static QState QMsmTst_s1(QMsmTst * const me, QEvt const * const e) {
&QMsmTst_s_s, /* target state */
{
Q_ACTION_CAST(&QMsmTst_s1_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -277,7 +284,7 @@ static QState QMsmTst_s1(QMsmTst * const me, QEvt const * const e) {
{
Q_ACTION_CAST(&QMsmTst_s1_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s1_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s1_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s1_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -330,7 +337,7 @@ static QState QMsmTst_s1(QMsmTst * const me, QEvt const * const e) {
{
Q_ACTION_CAST(&QMsmTst_s1_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s2_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s2_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s2_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -372,7 +379,7 @@ static QState QMsmTst_s11(QMsmTst * const me, QEvt const * const e) {
{
Q_ACTION_CAST(&QMsmTst_s11_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s1_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -391,7 +398,7 @@ static QState QMsmTst_s11(QMsmTst * const me, QEvt const * const e) {
&QMsmTst_s1_s, /* target state */
{
Q_ACTION_CAST(&QMsmTst_s11_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s1_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s1_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -506,7 +513,7 @@ static QState QMsmTst_s2(QMsmTst * const me, QEvt const * const e) {
{
Q_ACTION_CAST(&QMsmTst_s2_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s1_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s1_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s1_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -565,7 +572,7 @@ static QState QMsmTst_s21(QMsmTst * const me, QEvt const * const e) {
Q_ACTION_CAST(&QMsmTst_s21_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s2_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s1_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s1_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s1_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -583,7 +590,7 @@ static QState QMsmTst_s21(QMsmTst * const me, QEvt const * const e) {
{
Q_ACTION_CAST(&QMsmTst_s21_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s21_e), /* entry */
Q_ACTION_CAST(&QMsmTst_s21_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s21_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -642,7 +649,7 @@ static QState QMsmTst_s211(QMsmTst * const me, QEvt const * const e) {
Q_ACTION_CAST(&QMsmTst_s211_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s21_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s2_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
@ -659,7 +666,7 @@ static QState QMsmTst_s211(QMsmTst * const me, QEvt const * const e) {
&QMsmTst_s21_s, /* target state */
{
Q_ACTION_CAST(&QMsmTst_s211_x), /* exit */
Q_ACTION_CAST(&QMsmTst_s21_i), /* init.tran. */
Q_ACTION_CAST(&QMsmTst_s21_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};

View File

@ -5,14 +5,16 @@
* 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.
*
* 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.
* This code is covered by the following commercial QP license:
* License # : QPC-EVAL-161130
* Issued to : Company/individual evaluating the QP/C framework
* Framework(s): qpc
* Support ends: 2017-01-31
* Product(s) :
* This license is available only for evaluation purposes and
* the generated code is still licensed under the terms of GPL.
* Please submit request for extension of the evaluaion period at:
* http://www.state-machine.com/licensing/index.html#RequestForm
*****************************************************************************/
/*${.::qmsmtst.h} ..........................................................*/
#ifndef qmsmtst_h

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>QMsmTst is a QMsm state machine test based on the contrived state machine from Chapter 2 of the PSiCC2 book for testing all possible transition topologies with up to 4-levels of state nesting.</documentation>
<framework name="qpc"/>
<framework name="qpc" license="../../../QPC-EVAL-161130.qlc"/>
<package name="SMs" stereotype="0x02">
<class name="QMsmTst" superclass="qpc::QMsm">
<documentation>Test active object</documentation>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<session version="4.0.0">
<item name="license">GPL</item>
<group name="locked"/>
<group name="settings">
<item name="tabs">1</item>
<item name="windows">0</item>
<item name="grid">3</item>
<item name="backups">0</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="dir"></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="dir"></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="dir"></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="dir"></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="dir"></item>
<item name="options">0</item>
</group>
</group>
</session>

View File

@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
NOTE: Reduced number of Philosophers, because off the limitations of the ThreadX evaluation library.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
<class name="TableEvt" superclass="qpc::QEvt">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -112,7 +111,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -322,7 +321,7 @@ me-&gt;fork[n] = FREE;</action>
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +329,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,21 @@ 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 QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +125,36 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +162,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +200,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -129,59 +100,57 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +170,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +217,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +266,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +284,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<model version="3.3.0">
<model version="4.0.0" links="0">
<documentation>Dining Philosopher Problem example
NOTE: Requries QP5.</documentation>
<framework name="qpc"/>
<package name="Events" stereotype="0x01">
@ -10,7 +9,7 @@ NOTE: Requries QP5.</documentation>
</class>
</package>
<package name="AOs" stereotype="0x02">
<class name="Philo" superclass="qpc::QMActive">
<class name="Philo" superclass="qpc::QActive">
<attribute name="timeEvt" type="QTimeEvt" visibility="0x02" properties="0x00"/>
<statechart>
<initial target="../1">
@ -38,15 +37,17 @@ if (registered == (uint8_t)0) {
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal for each Philos */
QS_SIG_DICTIONARY(TIMEOUT_SIG, me); /* signal for each Philos */
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);</action>
QActive_subscribe(&amp;me-&gt;super, EAT_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);</action>
<initial_glyph conn="2,3,5,1,20,5,-3">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<state name="thinking">
<entry>QTimeEvt_armX(&amp;me-&gt;timeEvt, THINK_TIME, 0U);</entry>
<exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
<tran trig="TIMEOUT" target="../../2">
<tran_glyph conn="2,12,3,1,20,13,-3">
<tran_glyph conn="2,13,3,1,20,12,-3">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
@ -57,8 +58,14 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<tran trig="TEST">
<tran_glyph conn="2,20,3,-1,13">
<action box="0,-2,11,4"/>
</tran_glyph>
</tran>
<state_glyph node="2,5,17,16">
<entry box="1,2,5,2"/>
<exit box="1,4,6,2"/>
</state_glyph>
</state>
<state name="hungry">
@ -112,7 +119,7 @@ Q_ASSERT(Q_EVT_CAST(TableEvt)-&gt;philoNum != PHILO_ID(me));</action>
<state_diagram size="37,61"/>
</statechart>
</class>
<class name="Table" superclass="qpc::QMActive">
<class name="Table" superclass="qpc::QActive">
<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>
@ -131,14 +138,14 @@ QS_SIG_DICTIONARY(DONE_SIG, (void *)0); /* global signals */
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&amp;me-&gt;super, DONE_SIG);
QActive_subscribe(&amp;me-&gt;super, PAUSE_SIG);
QActive_subscribe(&amp;me-&gt;super, SERVE_SIG);
QActive_subscribe(&amp;me-&gt;super, TERMINATE_SIG);
QActive_subscribe(&amp;me-&gt;super, TEST_SIG);
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -150,8 +157,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
</initial_glyph>
</initial>
<state name="active">
<tran trig="TERMINATE">
<action>BSP_terminate(0);</action>
<tran trig="TEST">
<tran_glyph conn="2,11,3,-1,14">
<action box="0,-2,11,4"/>
</tran_glyph>
@ -316,13 +322,13 @@ me-&gt;fork[n] = FREE;</action>
</statechart>
</class>
<attribute name="AO_Philo[N_PHILO]" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QMActive * const" visibility="0x00" properties="0x00"/>
<attribute name="AO_Table" type="QActive * const" visibility="0x00" properties="0x00"/>
<operation name="Philo_ctor" type="void" visibility="0x00" properties="0x00">
<code>uint8_t n;
Philo *me;
for (n = 0U; n &lt; N_PHILO; ++n) {
me = &amp;l_philo[n];
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Philo_initial));
QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TIMEOUT_SIG, 0U);
}</code>
</operation>
@ -330,7 +336,7 @@ for (n = 0U; n &lt; N_PHILO; ++n) {
<code>uint8_t n;
Table *me = &amp;l_table;
QMActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Table_initial));
for (n = 0U; n &lt; N_PHILO; ++n) {
me-&gt;fork[n] = FREE;
@ -348,7 +354,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -362,11 +368,18 @@ $declare(Events::TableEvt)
#define N_PHILO ((uint8_t)5)
$declare(AOs::Philo_ctor)
$declare(AOs::Table_ctor)
$declare(AOs::AO_Philo[N_PHILO])
$declare(AOs::Table_ctor)
$declare(AOs::AO_Table)
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */</text>
</file>
<file name="philo.c">

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Philo} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
QTimeEvt timeEvt;
@ -33,34 +38,9 @@ typedef struct {
/* 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_thinking_e(Philo * const me);
static QMState const Philo_thinking_s = {
(QMState const *)0, /* superstate (top) */
Q_STATE_CAST(&Philo_thinking),
Q_ACTION_CAST(&Philo_thinking_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_hungry),
Q_ACTION_CAST(&Philo_hungry_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate (top) */
Q_STATE_CAST(&Philo_eating),
Q_ACTION_CAST(&Philo_eating_e),
Q_ACTION_CAST(&Philo_eating_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
/* Local objects -----------------------------------------------------------*/
@ -90,23 +70,13 @@ void Philo_ctor(void) {
Philo *me;
for (n = 0U; n < N_PHILO; ++n) {
me = &l_philo[n];
QMActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Philo_initial));
QTimeEvt_ctorX(&me->timeEvt, &me->super, TIMEOUT_SIG, 0U);
}
}
/*${AOs::Philo} ............................................................*/
/*${AOs::Philo::SM} ........................................................*/
static QState Philo_initial(Philo * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Philo::SM::initial} */
static uint8_t registered = (uint8_t)0; /* starts off with 0, per C-standard */
(void)e; /* suppress the compiler warning about unused parameter */
@ -133,31 +103,28 @@ 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 QM_TRAN_INIT(&tatbl_);
QActive_subscribe(&me->super, TEST_SIG);
return Q_TRAN(&Philo_thinking);
}
/*${AOs::Philo::SM::thinking} ..............................................*/
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
return QM_ENTRY(&Philo_thinking_s);
}
/* ${AOs::Philo::SM::thinking} */
static QState Philo_thinking(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::thinking} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, THINK_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking} */
case Q_EXIT_SIG: {
QTimeEvt_disarm(&me->timeEvt);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_hungry_s, /* target state */
{
Q_ACTION_CAST(&Philo_hungry_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_hungry);
break;
}
/* ${AOs::Philo::SM::thinking::EAT, DONE} */
@ -165,46 +132,41 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::thinking::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::hungry} ................................................*/
/* ${AOs::Philo::SM::hungry} */
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);
}
/* ${AOs::Philo::SM::hungry} */
static QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::hungry} */
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;
}
/* ${AOs::Philo::SM::hungry::EAT} */
case EAT_SIG: {
/* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} */
if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Philo_eating_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_eating);
}
else {
status_ = QM_UNHANDLED();
status_ = Q_UNHANDLED();
}
break;
}
@ -212,47 +174,37 @@ 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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*${AOs::Philo::SM::eating} ................................................*/
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating_e(Philo * const me) {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
return QM_ENTRY(&Philo_eating_s);
}
/* ${AOs::Philo::SM::eating} */
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);
}
/* ${AOs::Philo::SM::eating} */
static QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Philo::SM::eating} */
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Philo::SM::eating} */
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;
}
/* ${AOs::Philo::SM::eating::TIMEOUT} */
case TIMEOUT_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Philo_thinking_s, /* target state */
{
Q_ACTION_CAST(&Philo_eating_x), /* exit */
Q_ACTION_CAST(&Philo_thinking_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Philo_thinking);
break;
}
/* ${AOs::Philo::SM::eating::EAT, DONE} */
@ -260,11 +212,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}

View File

@ -22,10 +22,15 @@
Q_DEFINE_THIS_FILE
/* Active object class -----------------------------------------------------*/
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${AOs::Table} ............................................................*/
typedef struct {
/* protected: */
QMActive super;
QActive super;
/* private: */
uint8_t fork[N_PHILO];
@ -34,33 +39,9 @@ typedef struct {
/* protected: */
static QState Table_initial(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, /* superstate (top) */
Q_STATE_CAST(&Table_active),
Q_ACTION_CAST(0), /* no entry action */
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_serving),
Q_ACTION_CAST(&Table_serving_e),
Q_ACTION_CAST(0), /* no exit action */
Q_ACTION_CAST(0) /* no intitial tran. */
};
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, /* superstate */
Q_STATE_CAST(&Table_paused),
Q_ACTION_CAST(&Table_paused_e),
Q_ACTION_CAST(&Table_paused_x),
Q_ACTION_CAST(0) /* no intitial tran. */
};
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);
#define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1U)) % N_PHILO))
@ -80,7 +61,7 @@ void Table_ctor(void) {
uint8_t n;
Table *me = &l_table;
QMActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
QActive_ctor(&me->super, Q_STATE_CAST(&Table_initial));
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
@ -90,16 +71,6 @@ void Table_ctor(void) {
/*${AOs::Table} ............................................................*/
/*${AOs::Table::SM} ........................................................*/
static QState Table_initial(Table * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/* ${AOs::Table::SM::initial} */
uint8_t n;
(void)e; /* suppress the compiler warning about unused parameter */
@ -115,73 +86,70 @@ static QState Table_initial(Table * const me, QEvt const * const e) {
QS_SIG_DICTIONARY(EAT_SIG, (void *)0);
QS_SIG_DICTIONARY(PAUSE_SIG, (void *)0);
QS_SIG_DICTIONARY(SERVE_SIG, (void *)0);
QS_SIG_DICTIONARY(TERMINATE_SIG, (void *)0);
QS_SIG_DICTIONARY(TEST_SIG, (void *)0);
QS_SIG_DICTIONARY(HUNGRY_SIG, me); /* signal just for Table */
QActive_subscribe(&me->super, DONE_SIG);
QActive_subscribe(&me->super, PAUSE_SIG);
QActive_subscribe(&me->super, SERVE_SIG);
QActive_subscribe(&me->super, TERMINATE_SIG);
QActive_subscribe(&me->super, TEST_SIG);
for (n = 0U; n < N_PHILO; ++n) {
me->fork[n] = FREE;
me->isHungry[n] = 0U;
BSP_displayPhilStat(n, "thinking");
}
return QM_TRAN_INIT(&tatbl_);
return Q_TRAN(&Table_serving);
}
/*${AOs::Table::SM::active} ................................................*/
/* ${AOs::Table::SM::active} */
static QState Table_active(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::TERMINATE} */
case TERMINATE_SIG: {
BSP_terminate(0);
status_ = QM_HANDLED();
/* ${AOs::Table::SM::active::TEST} */
case TEST_SIG: {
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&QHsm_top);
break;
}
}
(void)me; /* avoid compiler warning in case 'me' is not used */
return status_;
}
/*${AOs::Table::SM::active::serving} .......................................*/
/* ${AOs::Table::SM::active::serving} */
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);
}
/* ${AOs::Table::SM::active::serving} */
static QState Table_serving(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::serving} */
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;
}
/* ${AOs::Table::SM::active::serving::HUNGRY} */
case HUNGRY_SIG: {
uint8_t n, m;
@ -201,12 +169,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_ = QM_HANDLED();
status_ = Q_HANDLED();
}
/* ${AOs::Table::SM::active::serving::HUNGRY::[else]} */
else {
me->isHungry[n] = 1U;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
}
break;
}
@ -248,68 +216,46 @@ static QState Table_serving(Table * const me, QEvt const * const e) {
QF_PUBLISH(&pe->super, me);
BSP_displayPhilStat(m, "eating ");
}
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::EAT} */
case EAT_SIG: {
Q_ERROR();
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::serving::PAUSE} */
case PAUSE_SIG: {
static struct {
QMState const *target;
QActionHandler act[2];
} const tatbl_ = { /* transition-action table */
&Table_paused_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_paused);
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}
return status_;
}
/*${AOs::Table::SM::active::paused} ........................................*/
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_e(Table * const me) {
BSP_displayPaused(1U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_ENTRY(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused_x(Table * const me) {
BSP_displayPaused(0U);
(void)me; /* avoid compiler warning in case 'me' is not used */
return QM_EXIT(&Table_paused_s);
}
/* ${AOs::Table::SM::active::paused} */
static QState Table_paused(Table * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
/* ${AOs::Table::SM::active::paused} */
case Q_ENTRY_SIG: {
BSP_displayPaused(1U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused} */
case Q_EXIT_SIG: {
BSP_displayPaused(0U);
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::SERVE} */
case SERVE_SIG: {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* transition-action table */
&Table_serving_s, /* target state */
{
Q_ACTION_CAST(&Table_paused_x), /* exit */
Q_ACTION_CAST(&Table_serving_e), /* entry */
Q_ACTION_CAST(0) /* zero terminator */
}
};
status_ = QM_TRAN(&tatbl_);
status_ = Q_TRAN(&Table_serving);
break;
}
/* ${AOs::Table::SM::active::paused::HUNGRY} */
@ -319,7 +265,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_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
/* ${AOs::Table::SM::active::paused::DONE} */
@ -337,11 +283,11 @@ static QState Table_paused(Table * const me, QEvt const * const e) {
me->fork[m] = FREE;
me->fork[n] = FREE;
status_ = QM_HANDLED();
status_ = Q_HANDLED();
break;
}
default: {
status_ = QM_SUPER();
status_ = Q_SUPER(&Table_active);
break;
}
}

View File

@ -23,7 +23,7 @@ enum DPPSignals {
DONE_SIG, /* published by Philosopher when done eating */
PAUSE_SIG, /* published by BSP to pause serving forks */
SERVE_SIG, /* published by BSP to serve re-start serving forks */
TERMINATE_SIG, /* published by BSP to terminate the application */
TEST_SIG, /* published by BSP to test the application */
MAX_PUB_SIG, /* the last published signal */
HUNGRY_SIG, /* posted direclty to Table from hungry Philo */
@ -31,6 +31,11 @@ enum DPPSignals {
MAX_SIG /* the last signal */
};
#if ((QP_VERSION < 580) || (QP_VERSION != ((QP_RELEASE^4294967295) % 0x3E8)))
#error qpc version 5.8.0 or higher required
#endif
/*${Events::TableEvt} ......................................................*/
typedef struct {
/* protected: */
@ -47,13 +52,20 @@ typedef struct {
/*${AOs::Philo_ctor} .......................................................*/
void Philo_ctor(void);
extern QMActive * const AO_Philo[N_PHILO];
/*${AOs::Table_ctor} .......................................................*/
void Table_ctor(void);
extern QActive * const AO_Table;
extern QMActive * const AO_Philo[N_PHILO];
extern QMActive * const AO_Table;
#ifdef qxk_h
void Test1_ctor(void);
extern QXThread * const XT_Test1;
void Test2_ctor(void);
extern QXThread * const XT_Test2;
#endif /* qxk_h */
#endif /* dpp_h */

Some files were not shown because too many files have changed in this diff Show More