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