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