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