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