00001 /***************************************************************************** 00002 * Product: QK/C 00003 * Last Updated for Version: 4.1.00 00004 * Date of the Last Update: Oct 09, 2009 00005 * 00006 * Q u a n t u m L e a P s 00007 * --------------------------- 00008 * innovating embedded systems 00009 * 00010 * Copyright (C) 2002-2009 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 00027 *****************************************************************************/ 00028 #include "qk_pkg.h" 00029 #include "qassert.h" 00030 00031 Q_DEFINE_THIS_MODULE(qk_ext) 00032 00033 00039 /*..........................................................................*/ 00040 /* NOTE: the QK scheduler is entered and exited with interrupts LOCKED */ 00041 #ifndef QF_INT_KEY_TYPE 00042 void QK_scheduleExt_(void) { 00043 #else 00044 void QK_scheduleExt_(QF_INT_KEY_TYPE intLockKey_) { 00045 #endif 00046 uint8_t p; 00047 /* the QK scheduler must be called at task level only */ 00048 Q_REQUIRE(QK_intNest_ == (uint8_t)0); 00049 00050 #if (QF_MAX_ACTIVE <= 8) 00051 /* determine the priority of the highest-priority task ready to run */ 00052 QPSet8_findMax(&QK_readySet_, p); 00053 #else 00054 /* determine the priority of the highest-priority task ready to run */ 00055 QPSet64_findMax(&QK_readySet_, p); 00056 #endif 00057 00058 #ifdef QK_NO_MUTEX 00059 if (p > QK_currPrio_) { /* do we have a preemption? */ 00060 #else /* QK priority-ceiling mutexes allowed */ 00061 if ((p > QK_currPrio_) && (p > QK_ceilingPrio_)) { 00062 #endif 00063 uint8_t pin = QK_currPrio_; /* save the initial priority */ 00064 QActive *a; 00065 #ifdef QK_TLS /* thread-local storage used? */ 00066 uint8_t pprev = pin; 00067 #endif 00068 #ifdef QK_EXT_SAVE /* extended context-switch used? */ 00069 if (pin != (uint8_t)0) { /* no extended context for the idle loop */ 00070 a = QF_active_[pin]; /* the pointer to the preempted AO */ 00071 QK_EXT_SAVE(a); /* save the extended context */ 00072 } 00073 #endif 00074 do { 00075 QEvent const *e; 00076 a = QF_active_[p]; /* obtain the pointer to the AO */ 00077 00078 QK_currPrio_ = p; /* this becomes the current task priority */ 00079 00080 #ifdef QK_TLS /* thread-local storage used? */ 00081 if (p != pprev) { /* are we changing threads? */ 00082 QK_TLS(a); /* switch new thread-local storage */ 00083 pprev = p; 00084 } 00085 #endif 00086 QS_BEGIN_NOLOCK_(QS_QK_SCHEDULE, QS_aoObj_, a) 00087 QS_TIME_(); /* timestamp */ 00088 QS_U8_(p); /* the priority of the AO */ 00089 QS_U8_(pin); /* the preempted priority */ 00090 QS_END_NOLOCK_() 00091 00092 QK_INT_UNLOCK_(); /* unlock the interrupts */ 00093 00094 e = QActive_get_(a); /* get the next event for this AO */ 00095 QF_ACTIVE_DISPATCH_(&a->super, e); /* dispatch to the AO */ 00096 QF_gc(e); /* garbage collect the event, if necessary */ 00097 00098 QK_INT_LOCK_(); 00099 /* determine the highest-priority AO ready to run */ 00100 #if (QF_MAX_ACTIVE <= 8) 00101 QPSet8_findMax(&QK_readySet_, p); 00102 #else 00103 QPSet64_findMax(&QK_readySet_, p); 00104 #endif 00105 #ifdef QK_NO_MUTEX 00106 } while (p > pin); /* is the new priority higher than initial? */ 00107 #else /* QK priority-ceiling mutexes allowed */ 00108 } while ((p > pin) && (p > QK_ceilingPrio_)); 00109 #endif 00110 00111 QK_currPrio_ = pin; /* restore the initial priority */ 00112 00113 #if defined(QK_TLS) || defined(QK_EXT_RESTORE) 00114 if (pin != (uint8_t)0) { /* no extended context for the idle loop */ 00115 a = QF_active_[pin]; /* the pointer to the preempted AO */ 00116 #ifdef QK_TLS /* thread-local storage used? */ 00117 QK_TLS(a); /* restore the original TLS */ 00118 #endif 00119 #ifdef QK_EXT_RESTORE /* extended context-switch used? */ 00120 QK_EXT_RESTORE(a); /* restore the extended context */ 00121 #endif 00122 } 00123 #endif 00124 } 00125 }
1.6.3