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
|
//* PROCESSOR: ARM Cortex-M3
|
segundo |
0:d7810ff946c1
|
8
|
//*
|
segundo |
0:d7810ff946c1
|
9
|
//* TOOLKIT: RVCT (ARM)
|
segundo |
0:d7810ff946c1
|
10
|
//*
|
segundo |
0:d7810ff946c1
|
11
|
//* PURPOSE: Target Dependent Stuff Header. Declarations And Definitions
|
segundo |
0:d7810ff946c1
|
12
|
//*
|
segundo |
0:d7810ff946c1
|
13
|
//* Version: 3.10
|
segundo |
0:d7810ff946c1
|
14
|
//*
|
segundo |
0:d7810ff946c1
|
15
|
//* $Revision: 195 $
|
segundo |
0:d7810ff946c1
|
16
|
//* $Date:: 2008-06-19 #$
|
segundo |
0:d7810ff946c1
|
17
|
//*
|
segundo |
0:d7810ff946c1
|
18
|
//* Copyright (c) 2003-2010, Harry E. Zhurov
|
segundo |
0:d7810ff946c1
|
19
|
//*
|
segundo |
0:d7810ff946c1
|
20
|
//* Permission is hereby granted, free of charge, to any person
|
segundo |
0:d7810ff946c1
|
21
|
//* obtaining a copy of this software and associated documentation
|
segundo |
0:d7810ff946c1
|
22
|
//* files (the "Software"), to deal in the Software without restriction,
|
segundo |
0:d7810ff946c1
|
23
|
//* including without limitation the rights to use, copy, modify, merge,
|
segundo |
0:d7810ff946c1
|
24
|
//* publish, distribute, sublicense, and/or sell copies of the Software,
|
segundo |
0:d7810ff946c1
|
25
|
//* and to permit persons to whom the Software is furnished to do so,
|
segundo |
0:d7810ff946c1
|
26
|
//* subject to the following conditions:
|
segundo |
0:d7810ff946c1
|
27
|
//*
|
segundo |
0:d7810ff946c1
|
28
|
//* The above copyright notice and this permission notice shall be included
|
segundo |
0:d7810ff946c1
|
29
|
//* in all copies or substantial portions of the Software.
|
segundo |
0:d7810ff946c1
|
30
|
//*
|
segundo |
0:d7810ff946c1
|
31
|
//* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
segundo |
0:d7810ff946c1
|
32
|
//* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
segundo |
0:d7810ff946c1
|
33
|
//* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
segundo |
0:d7810ff946c1
|
34
|
//* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
segundo |
0:d7810ff946c1
|
35
|
//* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
segundo |
0:d7810ff946c1
|
36
|
//* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
segundo |
0:d7810ff946c1
|
37
|
//* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
segundo |
0:d7810ff946c1
|
38
|
//*
|
segundo |
0:d7810ff946c1
|
39
|
//* =================================================================
|
segundo |
0:d7810ff946c1
|
40
|
//* See http://scmrtos.sourceforge.net for documentation, latest
|
segundo |
0:d7810ff946c1
|
41
|
//* information, license and contact details.
|
segundo |
0:d7810ff946c1
|
42
|
//* =================================================================
|
segundo |
0:d7810ff946c1
|
43
|
//*
|
segundo |
0:d7810ff946c1
|
44
|
//******************************************************************************
|
segundo |
0:d7810ff946c1
|
45
|
//* Ported by Andrey Chuikin, Copyright (c) 2008-2010
|
segundo |
0:d7810ff946c1
|
46
|
|
segundo |
0:d7810ff946c1
|
47
|
#ifndef scmRTOS_CORTEXM3_H
|
segundo |
0:d7810ff946c1
|
48
|
#define scmRTOS_CORTEXM3_H
|
segundo |
0:d7810ff946c1
|
49
|
|
segundo |
0:d7810ff946c1
|
50
|
#include <commdefs.h>
|
segundo |
0:d7810ff946c1
|
51
|
|
segundo |
0:d7810ff946c1
|
52
|
//------------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
53
|
//
|
segundo |
0:d7810ff946c1
|
54
|
// Compiler and Target checks
|
segundo |
0:d7810ff946c1
|
55
|
//
|
segundo |
0:d7810ff946c1
|
56
|
//
|
segundo |
0:d7810ff946c1
|
57
|
#ifndef __ARMCC_VERSION
|
segundo |
0:d7810ff946c1
|
58
|
#error "This file should only be compiled with ARM RVCT Compiler"
|
segundo |
0:d7810ff946c1
|
59
|
#endif // __ARMCC_VERSION
|
segundo |
0:d7810ff946c1
|
60
|
|
segundo |
0:d7810ff946c1
|
61
|
#if __TARGET_ARCH_ARM != 0 || __TARGET_ARCH_THUMB != 4
|
segundo |
0:d7810ff946c1
|
62
|
#error "This file must be compiled for ARMv7-M (Cortex-M3) processor only."
|
segundo |
0:d7810ff946c1
|
63
|
#endif
|
segundo |
0:d7810ff946c1
|
64
|
|
segundo |
0:d7810ff946c1
|
65
|
//------------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
66
|
//
|
segundo |
0:d7810ff946c1
|
67
|
// Target specific types
|
segundo |
0:d7810ff946c1
|
68
|
//
|
segundo |
0:d7810ff946c1
|
69
|
//
|
segundo |
0:d7810ff946c1
|
70
|
typedef dword TStackItem;
|
segundo |
0:d7810ff946c1
|
71
|
typedef dword TStatusReg;
|
segundo |
0:d7810ff946c1
|
72
|
|
segundo |
0:d7810ff946c1
|
73
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
74
|
//
|
segundo |
0:d7810ff946c1
|
75
|
// Configuration macros
|
segundo |
0:d7810ff946c1
|
76
|
//
|
segundo |
0:d7810ff946c1
|
77
|
//
|
segundo |
0:d7810ff946c1
|
78
|
#define OS_PROCESS __attribute__((__noreturn__))
|
segundo |
0:d7810ff946c1
|
79
|
#define OS_INTERRUPT
|
segundo |
0:d7810ff946c1
|
80
|
#define DUMMY_INSTR() __NOP()
|
segundo |
0:d7810ff946c1
|
81
|
#define INLINE_PROCESS_CTOR INLINE inline
|
segundo |
0:d7810ff946c1
|
82
|
|
segundo |
0:d7810ff946c1
|
83
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
84
|
//
|
segundo |
0:d7810ff946c1
|
85
|
// Uncomment macro value below for SystemTimer() run in critical section
|
segundo |
0:d7810ff946c1
|
86
|
//
|
segundo |
0:d7810ff946c1
|
87
|
// This is useful (and necessary) when target processor has hardware
|
segundo |
0:d7810ff946c1
|
88
|
// enabled nested interrups. Cortex-M3 have such interrupts.
|
segundo |
0:d7810ff946c1
|
89
|
//
|
segundo |
0:d7810ff946c1
|
90
|
#define SYS_TIMER_CRIT_SECT() TCritSect cs
|
segundo |
0:d7810ff946c1
|
91
|
|
segundo |
0:d7810ff946c1
|
92
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
93
|
// Separate return stack not required
|
segundo |
0:d7810ff946c1
|
94
|
#define SEPARATE_RETURN_STACK 0
|
segundo |
0:d7810ff946c1
|
95
|
|
segundo |
0:d7810ff946c1
|
96
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
97
|
// Software interrupt stack switching not supported in Cortex-M3 port
|
segundo |
0:d7810ff946c1
|
98
|
// because processor implements hardware stack switching.
|
segundo |
0:d7810ff946c1
|
99
|
// So, system timer isr wrapper can't be choosen at project level
|
segundo |
0:d7810ff946c1
|
100
|
//
|
segundo |
0:d7810ff946c1
|
101
|
#define scmRTOS_ISRW_TYPE TISRW
|
segundo |
0:d7810ff946c1
|
102
|
|
segundo |
0:d7810ff946c1
|
103
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
104
|
//
|
segundo |
0:d7810ff946c1
|
105
|
// scmRTOS Context Switch Scheme
|
segundo |
0:d7810ff946c1
|
106
|
//
|
segundo |
0:d7810ff946c1
|
107
|
// The macro defines a context switch manner. Value 0 sets direct context
|
segundo |
0:d7810ff946c1
|
108
|
// switch in the scheduler and in the OS ISRs. This is the primary method.
|
segundo |
0:d7810ff946c1
|
109
|
// Value 1 sets the second way to switch context - by using of software
|
segundo |
0:d7810ff946c1
|
110
|
// interrupt. See documentation fo details.
|
segundo |
0:d7810ff946c1
|
111
|
// Cortex-M3 port supports software interrupt switch method only.
|
segundo |
0:d7810ff946c1
|
112
|
//
|
segundo |
0:d7810ff946c1
|
113
|
#define scmRTOS_CONTEXT_SWITCH_SCHEME 1
|
segundo |
0:d7810ff946c1
|
114
|
|
segundo |
0:d7810ff946c1
|
115
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
116
|
//
|
segundo |
0:d7810ff946c1
|
117
|
// Include project-level configurations
|
segundo |
0:d7810ff946c1
|
118
|
// !!! The order of includes is important !!!
|
segundo |
0:d7810ff946c1
|
119
|
//
|
segundo |
0:d7810ff946c1
|
120
|
#include "scmRTOS_config.h"
|
segundo |
0:d7810ff946c1
|
121
|
#include <scmRTOS_TARGET_CFG.h>
|
segundo |
0:d7810ff946c1
|
122
|
#include <scmRTOS_defs.h>
|
segundo |
0:d7810ff946c1
|
123
|
#include <LPC17xx.h>
|
segundo |
0:d7810ff946c1
|
124
|
|
segundo |
0:d7810ff946c1
|
125
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
126
|
//
|
segundo |
0:d7810ff946c1
|
127
|
// The Critital Section Wrapper
|
segundo |
0:d7810ff946c1
|
128
|
//
|
segundo |
0:d7810ff946c1
|
129
|
//
|
segundo |
0:d7810ff946c1
|
130
|
#define __enable_interrupt() __enable_irq()
|
segundo |
0:d7810ff946c1
|
131
|
#define __disable_interrupt() __disable_irq()
|
segundo |
0:d7810ff946c1
|
132
|
|
segundo |
0:d7810ff946c1
|
133
|
#define __set_interrupt_state(status) __set_PRIMASK(status)
|
segundo |
0:d7810ff946c1
|
134
|
#define __get_interrupt_state() __get_PRIMASK()
|
segundo |
0:d7810ff946c1
|
135
|
|
segundo |
0:d7810ff946c1
|
136
|
class TCritSect
|
segundo |
0:d7810ff946c1
|
137
|
{
|
segundo |
0:d7810ff946c1
|
138
|
public:
|
segundo |
0:d7810ff946c1
|
139
|
TCritSect () : StatusReg(__get_interrupt_state()) { __disable_interrupt(); }
|
segundo |
0:d7810ff946c1
|
140
|
~TCritSect() { __set_interrupt_state(StatusReg); }
|
segundo |
0:d7810ff946c1
|
141
|
|
segundo |
0:d7810ff946c1
|
142
|
private:
|
segundo |
0:d7810ff946c1
|
143
|
TStatusReg StatusReg;
|
segundo |
0:d7810ff946c1
|
144
|
};
|
segundo |
0:d7810ff946c1
|
145
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
146
|
|
segundo |
0:d7810ff946c1
|
147
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
148
|
//
|
segundo |
0:d7810ff946c1
|
149
|
// Priority stuff
|
segundo |
0:d7810ff946c1
|
150
|
//
|
segundo |
0:d7810ff946c1
|
151
|
//
|
segundo |
0:d7810ff946c1
|
152
|
namespace OS
|
segundo |
0:d7810ff946c1
|
153
|
{
|
segundo |
0:d7810ff946c1
|
154
|
INLINE inline OS::TProcessMap GetPrioTag(const byte pr) { return static_cast<OS::TProcessMap> (1 << pr); }
|
segundo |
0:d7810ff946c1
|
155
|
|
segundo |
0:d7810ff946c1
|
156
|
#if scmRTOS_PRIORITY_ORDER == 0
|
segundo |
0:d7810ff946c1
|
157
|
INLINE inline byte GetHighPriority(TProcessMap pm)
|
segundo |
0:d7810ff946c1
|
158
|
{
|
segundo |
0:d7810ff946c1
|
159
|
byte pr = 0;
|
segundo |
0:d7810ff946c1
|
160
|
|
segundo |
0:d7810ff946c1
|
161
|
while( !(pm & 0x0001) )
|
segundo |
0:d7810ff946c1
|
162
|
{
|
segundo |
0:d7810ff946c1
|
163
|
pr++;
|
segundo |
0:d7810ff946c1
|
164
|
pm >>= 1;
|
segundo |
0:d7810ff946c1
|
165
|
}
|
segundo |
0:d7810ff946c1
|
166
|
return pr;
|
segundo |
0:d7810ff946c1
|
167
|
}
|
segundo |
0:d7810ff946c1
|
168
|
#else
|
segundo |
0:d7810ff946c1
|
169
|
INLINE inline byte GetHighPriority(TProcessMap pm) { return (31 - __clz(pm)); }
|
segundo |
0:d7810ff946c1
|
170
|
#endif // scmRTOS_PRIORITY_ORDER
|
segundo |
0:d7810ff946c1
|
171
|
}
|
segundo |
0:d7810ff946c1
|
172
|
|
segundo |
0:d7810ff946c1
|
173
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
174
|
//
|
segundo |
0:d7810ff946c1
|
175
|
// Interrupt and Interrupt Service Routines support
|
segundo |
0:d7810ff946c1
|
176
|
//
|
segundo |
0:d7810ff946c1
|
177
|
INLINE inline TStatusReg GetInterruptState( ) { return __get_interrupt_state(); }
|
segundo |
0:d7810ff946c1
|
178
|
INLINE inline void SetInterruptState(TStatusReg sr) { __set_interrupt_state(sr); }
|
segundo |
0:d7810ff946c1
|
179
|
|
segundo |
0:d7810ff946c1
|
180
|
INLINE inline void EnableInterrupts() { __enable_interrupt(); }
|
segundo |
0:d7810ff946c1
|
181
|
INLINE inline void DisableInterrupts() { __disable_interrupt(); }
|
segundo |
0:d7810ff946c1
|
182
|
|
segundo |
0:d7810ff946c1
|
183
|
|
segundo |
0:d7810ff946c1
|
184
|
namespace OS
|
segundo |
0:d7810ff946c1
|
185
|
{
|
segundo |
0:d7810ff946c1
|
186
|
INLINE inline void EnableContextSwitch() { EnableInterrupts(); }
|
segundo |
0:d7810ff946c1
|
187
|
INLINE inline void DisableContextSwitch() { DisableInterrupts(); }
|
segundo |
0:d7810ff946c1
|
188
|
}
|
segundo |
0:d7810ff946c1
|
189
|
|
segundo |
0:d7810ff946c1
|
190
|
#include <OS_Kernel.h>
|
segundo |
0:d7810ff946c1
|
191
|
|
segundo |
0:d7810ff946c1
|
192
|
namespace OS
|
segundo |
0:d7810ff946c1
|
193
|
{
|
segundo |
0:d7810ff946c1
|
194
|
//--------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
195
|
//
|
segundo |
0:d7810ff946c1
|
196
|
// NAME : OS ISR support
|
segundo |
0:d7810ff946c1
|
197
|
//
|
segundo |
0:d7810ff946c1
|
198
|
// PURPOSE : Implements common actions on interrupt enter and exit
|
segundo |
0:d7810ff946c1
|
199
|
// under the OS
|
segundo |
0:d7810ff946c1
|
200
|
//
|
segundo |
0:d7810ff946c1
|
201
|
// DESCRIPTION:
|
segundo |
0:d7810ff946c1
|
202
|
//
|
segundo |
0:d7810ff946c1
|
203
|
//
|
segundo |
0:d7810ff946c1
|
204
|
class TISRW
|
segundo |
0:d7810ff946c1
|
205
|
{
|
segundo |
0:d7810ff946c1
|
206
|
public:
|
segundo |
0:d7810ff946c1
|
207
|
INLINE TISRW() { ISR_Enter(); }
|
segundo |
0:d7810ff946c1
|
208
|
INLINE ~TISRW() { ISR_Exit(); }
|
segundo |
0:d7810ff946c1
|
209
|
|
segundo |
0:d7810ff946c1
|
210
|
private:
|
segundo |
0:d7810ff946c1
|
211
|
//-----------------------------------------------------
|
segundo |
0:d7810ff946c1
|
212
|
INLINE void ISR_Enter()
|
segundo |
0:d7810ff946c1
|
213
|
{
|
segundo |
0:d7810ff946c1
|
214
|
TCritSect cs;
|
segundo |
0:d7810ff946c1
|
215
|
Kernel.ISR_NestCount++;
|
segundo |
0:d7810ff946c1
|
216
|
}
|
segundo |
0:d7810ff946c1
|
217
|
//-----------------------------------------------------
|
segundo |
0:d7810ff946c1
|
218
|
INLINE void ISR_Exit()
|
segundo |
0:d7810ff946c1
|
219
|
{
|
segundo |
0:d7810ff946c1
|
220
|
TCritSect cs;
|
segundo |
0:d7810ff946c1
|
221
|
if(--Kernel.ISR_NestCount) return;
|
segundo |
0:d7810ff946c1
|
222
|
Kernel.SchedISR();
|
segundo |
0:d7810ff946c1
|
223
|
}
|
segundo |
0:d7810ff946c1
|
224
|
//-----------------------------------------------------
|
segundo |
0:d7810ff946c1
|
225
|
};
|
segundo |
0:d7810ff946c1
|
226
|
|
segundo |
0:d7810ff946c1
|
227
|
// No software interrupt stack switching provided,
|
segundo |
0:d7810ff946c1
|
228
|
// TISRW_SS declared to be the same as TISRW for porting compability
|
segundo |
0:d7810ff946c1
|
229
|
#define TISRW_SS TISRW
|
segundo |
0:d7810ff946c1
|
230
|
|
segundo |
0:d7810ff946c1
|
231
|
} // ns OS
|
segundo |
0:d7810ff946c1
|
232
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
233
|
|
segundo |
0:d7810ff946c1
|
234
|
#endif // scmRTOS_CORTEXM3_H
|
segundo |
0:d7810ff946c1
|
235
|
//-----------------------------------------------------------------------------
|
segundo |
0:d7810ff946c1
|
236
|
|