QP/C++
qk_port.h
Go to the documentation of this file.
00001 
00002 // Product: QK/C++ port to Lint, Generic C++ compiler
00003 // Last Updated for Version: 4.0.03
00004 // Date of the Last Update:  Dec 27, 2008
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2008 Quantum Leaps, LLC. All rights reserved.
00011 //
00012 // This software may be distributed and modified under the terms of the GNU
00013 // General Public License version 2 (GPL) as published by the Free Software
00014 // Foundation and appearing in the file GPL.TXT included in the packaging of
00015 // this file. Please note that GPL Section 2[b] requires that all works based
00016 // on this software must also be made publicly available under the terms of
00017 // the GPL ("Copyleft").
00018 //
00019 // Alternatively, this software may be distributed and modified under the
00020 // terms of Quantum Leaps commercial licenses, which expressly supersede
00021 // the GPL and are specifically designed for licensees interested in
00022 // retaining the proprietary status of their code.
00023 //
00024 // Contact information:
00025 // Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 // e-mail:                  info@quantum-leaps.com
00028 #ifndef qk_port_h
00029 #define qk_port_h
00030 
00037 
00038 #ifdef Q_USE_NAMESPACE
00039 namespace QP {
00040 #endif
00041 
00043 // QK extended context (FPU) save/restore
00044 
00052 #define QK_EXT_SAVE(act_)      FPU_save((FPU_context *)(act_)->m_thread)
00053 
00061 #define QK_EXT_RESTORE(act_)   FPU_restore((FPU_context *)(act_)->m_thread)
00062 
00063 struct FPU_context {
00064     uint32_t align;
00065     uint8_t  fpu[108];                  // the x87 FPU context takes 108-bytes
00066 };
00067 extern "C" void FPU_save(FPU_context *ctx);             // defined in assembly
00068 extern "C" void FPU_restore(FPU_context *ctx);          // defined in assembly
00069 
00071 // Thread-Local-Storage switching
00072 
00081 #define QK_TLS(act_)        \
00082     _impure_ptr = (struct _reent *)(act_)->m_thread
00083 
00084 // fake struct _reent and _impure_ptr elements of Newlib...
00085 struct _reent {
00086     int foo[32];
00087 };
00088 extern struct _reent *_impure_ptr;
00089 
00091 // QK interrupt entry and exit
00092 
00100 #define QK_ISR_ENTRY() do { \
00101     ++QK_intNest_; \
00102     QF_QS_ISR_ENTRY(QK_intNest_, QK_currPrio_); \
00103 } while (0)
00104 
00105 
00113 #define QK_ISR_EXIT() do { \
00114     send End-Of-Interrupt instruction to the Interrupt Controller; \
00115     QF_QS_ISR_EXIT(QK_intNest_, QK_currPrio_); \
00116     --QK_intNest_; \
00117     if (QK_intNest_ == (uint8_t)0) { \
00118         QK_scheduleExt_(); \
00119     } \
00120 } while (0)
00121 
00122 #ifdef Q_USE_NAMESPACE
00123 }                                                              // namespace QP
00124 #endif
00125 
00126 #include "qk.h"                    // QK platform-independent public interface
00127 
00128 #endif                                                            // qk_port_h