QP is an event-driven, RTOS-like, active object framework for microcontrollers, such as mbed. The QP framework provides thread-safe execution of active objects (concurrent state machines) and support both manual and automatic coding of UML statecharts in readable, production-quality C or C++. Automatic code generation of QP code is supported by the free QM modeling tool.

Dependents:   qp_hangman qp_dpp qp_blinky

QP/C++ (Quantum Platform in C++) is a lightweight, open source active object (actor) framework for building responsive and modular real-time embedded applications as systems of asynchronous event-driven active objects (actors). The QP/C++ framework is a member of a larger family consisting of QP/C++, QP/C, and QP-nano frameworks, which are all strictly quality controlled, thoroughly documented, and available under GPLv3 with a special Exception for mbed (see http://www.state-machine.com/licensing/QP-mbed_GPL_Exception.txt).

The behavior of active objects is specified in QP/C++ by means of hierarchical state machines (UML statecharts). The framework supports manual coding of UML state machines in C++ as well as automatic code generation by means of the free QM modeling tool (http://www.state-machine.com/qm).

Please see the "QP/C++ Reference Manual" (http://www.state-machine.com/qpcpp) for more information.

Revision:
0:064c79e7311a
Child:
5:949864ba515c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qk_port.s	Wed Feb 09 14:46:03 2011 +0000
@@ -0,0 +1,126 @@
+;*****************************************************************************
+; Product: QK port to ARM Cortex-M0/M3, mbed ARM assembler, CMSIS-compliant
+; Last Updated for Version: 4.1.06
+; Date of the Last Update:  Feb 07, 2011
+;
+;                    Q u a n t u m     L e a P s
+;                    ---------------------------
+;                    innovating embedded systems
+;
+; Copyright (C) 2002-2011 Quantum Leaps, LLC. All rights reserved.
+;
+; This software may be distributed and modified under the terms of the GNU
+; General Public License version 2 (GPL) as published by the Free Software
+; Foundation and appearing in the file GPL.TXT included in the packaging of
+; this file. Please note that GPL Section 2[b] requires that all works based
+; on this software must also be made publicly available under the terms of
+; the GPL ("Copyleft").
+;
+; Alternatively, this software may be distributed and modified under the
+; terms of Quantum Leaps commercial licenses, which expressly supersede
+; the GPL and are specifically designed for licensees interested in
+; retaining the proprietary status of their code.
+;
+; Contact information:
+; Quantum Leaps Web site:  http://www.quantum-leaps.com
+; e-mail:                  info@quantum-leaps.com
+;*****************************************************************************
+    AREA QK, CODE, READONLY
+
+    EXPORT  QK_init
+    EXPORT  PendSV_Handler    ; CMSIS-compliant PendSV exception name
+    EXPORT  SVC_Handler       ; CMSIS-compliant SVC exception name
+
+    EXTERN  QK_schedule_      ; external references
+    EXTERN  QK_readySet_      ; external references
+
+
+;*****************************************************************************
+;
+; The QK_init function sets the priorities of SVCall and PendSV exceptions
+; to the lowest level possible (0xFF). The function internally disables
+; interrupts, but restores the original interrupt lock before exit.
+;
+;*****************************************************************************
+QK_init
+    MRS     r0,PRIMASK        ; store the state of the PRIMASK in r0
+    CPSID   i                 ; disable interrupts (set PRIMASK)
+
+    LDR     r1,=0xE000ED18    ; System Handler Priority Register
+    LDR     r2,[r1,#8]        ; load the System 12-15 Priority Register
+    MOVS    r3,#0xFF
+    LSLS    r3,r3,#16
+    ORRS    r2,r3             ; set PRI_14 (PendSV) to 0xFF
+    STR     r2,[r1,#8]        ; write the System 12-15 Priority Register
+    LDR     r2,[r1,#4]        ; load the System 8-11 Priority Register
+    LSLS    r3,r3,#8
+    ORRS    r2,r3             ; set PRI_11 (SVCall) to 0xFF
+    STR     r2,[r1,#4]        ; write the System 8-11 Priority Register
+
+    MSR     PRIMASK,r0        ; restore the original PRIMASK
+    BX      lr                ; return to the caller
+
+
+;*****************************************************************************
+;
+; The PendSV_Handler exception hanlder is used for handling asynchronous
+; preemptions in QK. The use of the PendSV exception is the recommended
+; and most efficient method for performing context switches with ARM Cortex.
+;
+; The PendSV exception should have the lowest priority in the whole system
+; (0xFF, see QK_init). All other exeptions and interrupts should have higher
+; priority. For example, for NVIC with 2 priority bits all interrupts and
+; exceptions must have numerical value of priority lower than 0xC0. In this
+; case the interrupt priority levels available to your applications are (in
+; the order from the lowest urgency to the highest urgency): 0x80, 0x40, 0x00.
+;
+; Also, *all* ISRs in the QK application must trigger the PendSV exception
+; by calling the QK_ISR_EXIT() macro.
+;
+; Due to tail-chaining and its lowest priority, the PendSV exception will be
+; entered immediately after the exit from the *last* nested interrupt (or
+; exception). In QK, this is exactly the time when the QK scheduler needs to
+; check for the asynchronous preemptions.
+;
+;*****************************************************************************
+PendSV_Handler
+    CPSID   i                 ; disable interrupts at processor level
+    LDR     r0,=QK_readySet_  ; load the address of QK_readySet_
+    LDRB    r0,[r0]           ; load the first byte of QK_readySet_
+    CMP     r0,#0             ; is QK_readySet_ == 0 ?
+    BEQ.N   iret              ; if QK_readySet_ == 0, branch to iret
+
+    MOVS    r1,#0x01
+    LSLS    r1,r1,#24         ; make up a task xPSR with only the T bit set
+    LDR     r0,=schedule      ; load the address of sched wrapper (new PC)
+    PUSH    {r0-r1}           ; push xPSR,PC
+    SUB     sp,sp,#(6*4)      ; don't care for lr,r12,r3,r2,r1,r0
+    BX      lr                ; interrupt return to the scheduler
+
+iret
+    CPSIE   i                 ; enable interrupts at processor level
+    BX      lr                ; interrupt return to the task
+
+schedule
+    BL      QK_schedule_      ; call the QK scheduler
+    CPSIE   i                 ; enable interrupts to allow SVCall exception
+    SVC     0                 ; SV exception returns to the preempted task
+
+
+;*****************************************************************************
+;
+; The SVC_Handler exception handler is used for returning back to the
+; interrupted context (task or interrupt). The SVC exception should have
+; the lowest priority in the whole system (see QK_init). The SVCall
+; exception simply removes its own interrupt stack frame from the stack and
+; returns to the preempted task using the interrupt stack frame that must be
+; at the top of the stack.
+;
+;*****************************************************************************
+SVC_Handler
+    ADD     sp,sp,#(8*4)      ; remove one interrupt frame from the stack
+    BX      lr                ; return to the preempted task
+
+    ALIGN                     ; make sure proper alignment
+    END
+    
\ No newline at end of file