The Dining Philosophers Problem (DPP) example is described in the Application Note: Dining Philosophers Problem (DPP) Example↑.
The DPP example is an intermediate-level application with multiple active objects. It illustrates the following QP features:
The DPP example is provided in many versions for various execution targets, including host computers and embedded boards. All of these DPP versions contain essentially the same state machine code and differ only in the Board Support Package (BSP).
<qp> // QP/C or QP/C++ installation directory | +---examples // QP examples | | | +---posix-win32 // examples for the host (POSIX, Windows) | | +---dpp // DPP for Windows, Linux, macOS <== TRY FIRST | | +---dpp-comp // DPP-component for Windows, Linux, macOS | | | +---arm-cm // examples for ARM Cortex-M embedded boards | | +---dpp_ek-tm4c123gxl // DPP for EK-TM4C123GXL (Cortex-M4) | | +---dpp_mbed-lpc1768 // DPP for mbed LPC1768 (Cortex-M4) | | +---dpp_ek-tm4c123gxl // DPP for EK-TM4C123GXL (Cortex-M4) | | +---dpp_nucleo-c031c6 // DPP for STM32 NUCLEO-C031C6 (Cortex-M0+) | | +---dpp_nucleo-f401re // DPP for STM32 NUCLEO-F401RE (Cortex-M4) | | +---dpp_nucleo-h743zi // DPP for STM32 NUCLEO-H743ZI (Cortex-M7) | | +---dpp_nucleo-l053r8 // DPP for STM32 NUCLEO-L053R8 (Cortex-M0+) | | +---dpp_nucleo-l152re // DPP for STM32 NUCLEO-L152RE (Cortex-M3) | | +---dpp_nucleo-l552ze // DPP for STM32 NUCLEO-L55ZE (Cortex-M33) | | +---dpp_nucleo-u545re // DPP for STM32 NUCLEO-U545RE (Cortex-M33) | | +---dpp_stm32f4-discovery // DPP for STM32F4-DISCO (Cortex-M4) | | | +---stm32cube // examples for STM32Cube IDE | | +---dpp_nucleo-u545re // DPP for STM32 NUCLEO-U545RE (Cortex-M33) | | | +---arm-cr // examples for ARM Cortex-R embedded boards | | +---dpp_launchxl2-tms57012 // DPP for LAUNCHXL2-TMS57012 (Cortex-R4) | | | +---msp430 // examples for MSP430 embedded boards | | +---dpp_msp-exp430f5529lp // DPP for MSP-EXP430f5529LP (MSP430 extended) | | | +---embos // examples for embOS RTOS (SEGGER) | | +---dpp_nucleo-h743zi // DPP for NUCLEO-H743ZI (Cortex-M7) | | | +---esp-idf // examples for ESP IDF modified FreeRTOS (Espressif) | | +---dpp_nucleo-h743zi // DPP for NUCLEO-H743ZI (Cortex-M7) | | | +---freertos // examples for FreeRTOS (Amazon Web Services) | | +---dpp_ek-tm4c123gxl // EK-TM4C123GXL (Cortex-M4) | | +---dpp_nucleo-c031c6 // DPP for STM32 NUCLEO-C031C6 (Cortex-M0+) | | +---dpp_ek-tm4c123gxl // DPP for EK-TM4C123GXL (Cortex-M4) | | +---dpp_nucleo-f401re // DPP for STM32 NUCLEO-F401RE (Cortex-M4) | | +---dpp_nucleo-h743zi // DPP for STM32 NUCLEO-H743ZI (Cortex-M7) | | +---dpp_nucleo-u545re // DPP for STM32 NUCLEO-U545RE (Cortex-M33) | | +---dpp_stm32f4-discovery // DPP for STM32F4-DISCO (Cortex-M4) | | | +---zephyr // examples for Zephyr RTOS (Linux Foundation) | | +---dpp // DPP for all Zephyr-supported boards
The DPP example demonstrate multiple build configurations:
The DPP example demonstrates the general structure of QP/C++ applications. Most of the code is identical for any deployment target. The only target-dependent part is the Board Support Package (BSP) implementation (the file bsp.cpp ). Here are the annotated files comprising the DPP example:
dpp // DPP example | app.hpp // Application interface (e.g., signals, events) | bsp.hpp // Board Support Package interface | bsp.cpp // Board Support Package implementation | main.cpp // main function | philo.cpp // Philosopher active object implementation | table.cpp // Table active object implementation | qp_config.hpp // QP/C++ configuration
The file main.cpp shows the general steps to initialize and run the QP/C++ application.
The Philo Active Object has a simple state machine depicted in the state diagram below. On the right, you can see the generated code for the state machine, with a very clear mapping of state machine elements to code.
Deafault Debug build configuration:
cd \qp\qpcp\examples\posix-win32\dpp make
This assumes that the qpcpp framework exists in the directory \qp\qpcpp. Please check your installation and adjust the location as necessary.
Release build configuration:
cd \qp\qpcp\examples\posix-win32\dpp make CONF=rel
Spy build configuration (with QP/Spy software tracing enabled):
cd \qp\qpcp\examples\posix-win32\dpp make CONF=spy
Deafault Debug build configuration:
cd ~/qp/qpcpp/examples/posix-win32/dpp make
This assumes that the qpcpp framework exists in the directory ~/qp/qpcpp. Please check your installation and adjust the location as necessary.
Release build configuration:
cd ~/qp/qpcpp/examples/posix-win32/dpp make CONF=rel
Spy build configuration (with QP/Spy software tracing enabled):
cd ~/qp/qpcpp/examples/posix-win32/dpp make CONF=spy
The DPP examples for various embedded boards are located in the @qpx/examples (see DPP Versions). For embedded targets, you have many more choices than on the host. The choices include: