chokchai Hantanong
/
RtosTest
LED Fork
Fork of RtosTest by
scmRTOS/Common/OS_Kernel.cpp@0:331db0b44b67, 2010-09-21 (annotated)
- Committer:
- mbed714
- Date:
- Tue Sep 21 19:48:05 2010 +0000
- Revision:
- 0:331db0b44b67
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed714 | 0:331db0b44b67 | 1 | //****************************************************************************** |
mbed714 | 0:331db0b44b67 | 2 | //* |
mbed714 | 0:331db0b44b67 | 3 | //* FULLNAME: Single-Chip Microcontroller Real-Time Operating System |
mbed714 | 0:331db0b44b67 | 4 | //* |
mbed714 | 0:331db0b44b67 | 5 | //* NICKNAME: scmRTOS |
mbed714 | 0:331db0b44b67 | 6 | //* |
mbed714 | 0:331db0b44b67 | 7 | //* PURPOSE: OS Kernel Source |
mbed714 | 0:331db0b44b67 | 8 | //* |
mbed714 | 0:331db0b44b67 | 9 | //* Version: 3.10 |
mbed714 | 0:331db0b44b67 | 10 | //* |
mbed714 | 0:331db0b44b67 | 11 | //* $Revision: 256 $ |
mbed714 | 0:331db0b44b67 | 12 | //* $Date:: 2010-01-22 #$ |
mbed714 | 0:331db0b44b67 | 13 | //* |
mbed714 | 0:331db0b44b67 | 14 | //* Copyright (c) 2003-2010, Harry E. Zhurov |
mbed714 | 0:331db0b44b67 | 15 | //* |
mbed714 | 0:331db0b44b67 | 16 | //* Permission is hereby granted, free of charge, to any person |
mbed714 | 0:331db0b44b67 | 17 | //* obtaining a copy of this software and associated documentation |
mbed714 | 0:331db0b44b67 | 18 | //* files (the "Software"), to deal in the Software without restriction, |
mbed714 | 0:331db0b44b67 | 19 | //* including without limitation the rights to use, copy, modify, merge, |
mbed714 | 0:331db0b44b67 | 20 | //* publish, distribute, sublicense, and/or sell copies of the Software, |
mbed714 | 0:331db0b44b67 | 21 | //* and to permit persons to whom the Software is furnished to do so, |
mbed714 | 0:331db0b44b67 | 22 | //* subject to the following conditions: |
mbed714 | 0:331db0b44b67 | 23 | //* |
mbed714 | 0:331db0b44b67 | 24 | //* The above copyright notice and this permission notice shall be included |
mbed714 | 0:331db0b44b67 | 25 | //* in all copies or substantial portions of the Software. |
mbed714 | 0:331db0b44b67 | 26 | //* |
mbed714 | 0:331db0b44b67 | 27 | //* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
mbed714 | 0:331db0b44b67 | 28 | //* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
mbed714 | 0:331db0b44b67 | 29 | //* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
mbed714 | 0:331db0b44b67 | 30 | //* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
mbed714 | 0:331db0b44b67 | 31 | //* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
mbed714 | 0:331db0b44b67 | 32 | //* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH |
mbed714 | 0:331db0b44b67 | 33 | //* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mbed714 | 0:331db0b44b67 | 34 | //* |
mbed714 | 0:331db0b44b67 | 35 | //* ================================================================= |
mbed714 | 0:331db0b44b67 | 36 | //* See http://scmrtos.sourceforge.net for documentation, latest |
mbed714 | 0:331db0b44b67 | 37 | //* information, license and contact details. |
mbed714 | 0:331db0b44b67 | 38 | //* ================================================================= |
mbed714 | 0:331db0b44b67 | 39 | //* |
mbed714 | 0:331db0b44b67 | 40 | //****************************************************************************** |
mbed714 | 0:331db0b44b67 | 41 | |
mbed714 | 0:331db0b44b67 | 42 | #include "scmRTOS.h" |
mbed714 | 0:331db0b44b67 | 43 | |
mbed714 | 0:331db0b44b67 | 44 | using namespace OS; |
mbed714 | 0:331db0b44b67 | 45 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 46 | OS::TKernel OS::Kernel; |
mbed714 | 0:331db0b44b67 | 47 | |
mbed714 | 0:331db0b44b67 | 48 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 49 | #if scmRTOS_CONTEXT_SWITCH_SCHEME == 0 |
mbed714 | 0:331db0b44b67 | 50 | void TKernel::Sched() |
mbed714 | 0:331db0b44b67 | 51 | { |
mbed714 | 0:331db0b44b67 | 52 | byte NextPrty = GetHighPriority(ReadyProcessMap); |
mbed714 | 0:331db0b44b67 | 53 | if(NextPrty != CurProcPriority) |
mbed714 | 0:331db0b44b67 | 54 | { |
mbed714 | 0:331db0b44b67 | 55 | TStackItem* Next_SP = ProcessTable[NextPrty]->StackPointer; |
mbed714 | 0:331db0b44b67 | 56 | TStackItem** Curr_SP_addr = &(ProcessTable[CurProcPriority]->StackPointer); |
mbed714 | 0:331db0b44b67 | 57 | CurProcPriority = NextPrty; |
mbed714 | 0:331db0b44b67 | 58 | OS_ContextSwitcher(Curr_SP_addr, Next_SP); |
mbed714 | 0:331db0b44b67 | 59 | } |
mbed714 | 0:331db0b44b67 | 60 | } |
mbed714 | 0:331db0b44b67 | 61 | #else |
mbed714 | 0:331db0b44b67 | 62 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 63 | void TKernel::Sched() |
mbed714 | 0:331db0b44b67 | 64 | { |
mbed714 | 0:331db0b44b67 | 65 | byte NextPrty = GetHighPriority(ReadyProcessMap); |
mbed714 | 0:331db0b44b67 | 66 | if(NextPrty != CurProcPriority) |
mbed714 | 0:331db0b44b67 | 67 | { |
mbed714 | 0:331db0b44b67 | 68 | SchedProcPriority = NextPrty; |
mbed714 | 0:331db0b44b67 | 69 | |
mbed714 | 0:331db0b44b67 | 70 | RaiseContextSwitch(); |
mbed714 | 0:331db0b44b67 | 71 | do |
mbed714 | 0:331db0b44b67 | 72 | { |
mbed714 | 0:331db0b44b67 | 73 | EnableContextSwitch(); |
mbed714 | 0:331db0b44b67 | 74 | DUMMY_INSTR(); |
mbed714 | 0:331db0b44b67 | 75 | DisableContextSwitch(); |
mbed714 | 0:331db0b44b67 | 76 | } |
mbed714 | 0:331db0b44b67 | 77 | while(!IsContextSwitchDone()); |
mbed714 | 0:331db0b44b67 | 78 | } |
mbed714 | 0:331db0b44b67 | 79 | } |
mbed714 | 0:331db0b44b67 | 80 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 81 | TStackItem* OS_ContextSwitchHook(TStackItem* sp) { return OS::Kernel.ContextSwitchHook(sp); } |
mbed714 | 0:331db0b44b67 | 82 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 83 | #endif // scmRTOS_CONTEXT_SWITCH_SCHEME |
mbed714 | 0:331db0b44b67 | 84 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 85 | void TBaseProcess::Sleep(TTimeout timeout) |
mbed714 | 0:331db0b44b67 | 86 | { |
mbed714 | 0:331db0b44b67 | 87 | TCritSect cs; |
mbed714 | 0:331db0b44b67 | 88 | |
mbed714 | 0:331db0b44b67 | 89 | Kernel.ProcessTable[Kernel.CurProcPriority]->Timeout = timeout; |
mbed714 | 0:331db0b44b67 | 90 | Kernel.SetProcessUnready(Kernel.CurProcPriority); |
mbed714 | 0:331db0b44b67 | 91 | Kernel.Scheduler(); |
mbed714 | 0:331db0b44b67 | 92 | } |
mbed714 | 0:331db0b44b67 | 93 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 94 | void OS::WakeUpProcess(TBaseProcess& p) |
mbed714 | 0:331db0b44b67 | 95 | { |
mbed714 | 0:331db0b44b67 | 96 | TCritSect cs; |
mbed714 | 0:331db0b44b67 | 97 | |
mbed714 | 0:331db0b44b67 | 98 | if(p.Timeout) |
mbed714 | 0:331db0b44b67 | 99 | { |
mbed714 | 0:331db0b44b67 | 100 | p.Timeout = 0; |
mbed714 | 0:331db0b44b67 | 101 | Kernel.SetProcessReady(p.Priority); |
mbed714 | 0:331db0b44b67 | 102 | Kernel.Scheduler(); |
mbed714 | 0:331db0b44b67 | 103 | } |
mbed714 | 0:331db0b44b67 | 104 | } |
mbed714 | 0:331db0b44b67 | 105 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 106 | void OS::ForceWakeUpProcess(TBaseProcess& p) |
mbed714 | 0:331db0b44b67 | 107 | { |
mbed714 | 0:331db0b44b67 | 108 | TCritSect cs; |
mbed714 | 0:331db0b44b67 | 109 | |
mbed714 | 0:331db0b44b67 | 110 | p.Timeout = 0; |
mbed714 | 0:331db0b44b67 | 111 | Kernel.SetProcessReady(p.Priority); |
mbed714 | 0:331db0b44b67 | 112 | Kernel.Scheduler(); |
mbed714 | 0:331db0b44b67 | 113 | } |
mbed714 | 0:331db0b44b67 | 114 | //------------------------------------------------------------------------------ |
mbed714 | 0:331db0b44b67 | 115 |