Dependencies:   mbed

Committer:
mbed714
Date:
Tue Sep 21 19:48:05 2010 +0000
Revision:
0:331db0b44b67

        

Who changed what in which revision?

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