Committer:
segundo
Date:
Thu Nov 11 10:30:39 2010 +0000
Revision:
7:6fab7e5aa489
Parent:
0:d7810ff946c1

        

Who changed what in which revision?

UserRevisionLine numberNew 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: EWARM (IAR Systems)
segundo 0:d7810ff946c1 10 //*
segundo 0:d7810ff946c1 11 //* PURPOSE: Target Dependent Stuff Source
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
segundo 0:d7810ff946c1 48 #include <scmRTOS.h>
segundo 0:d7810ff946c1 49
segundo 0:d7810ff946c1 50 using namespace OS;
segundo 0:d7810ff946c1 51
segundo 0:d7810ff946c1 52 //------------------------------------------------------------------------------
segundo 0:d7810ff946c1 53 //
segundo 0:d7810ff946c1 54 // OS Process's constructor
segundo 0:d7810ff946c1 55 //
segundo 0:d7810ff946c1 56 // Performs:
segundo 0:d7810ff946c1 57 // * initializing process data;
segundo 0:d7810ff946c1 58 // * registering of the process in kernel;
segundo 0:d7810ff946c1 59 // * preparing stack frame;
segundo 0:d7810ff946c1 60 //
segundo 0:d7810ff946c1 61 //
segundo 0:d7810ff946c1 62 TBaseProcess::TBaseProcess(TStackItem* Stack, word stackSize, TPriority pr, void (*exec)())
segundo 0:d7810ff946c1 63 : StackPointer(Stack)
segundo 0:d7810ff946c1 64 , StackSize(stackSize)
segundo 0:d7810ff946c1 65 , Timeout(0)
segundo 0:d7810ff946c1 66 , Priority(pr)
segundo 0:d7810ff946c1 67 {
segundo 0:d7810ff946c1 68 Kernel.RegisterProcess(this);
segundo 0:d7810ff946c1 69 #ifdef DEBUG_STACK
segundo 0:d7810ff946c1 70 // Fill stack area with some value to be able later to define stack usage
segundo 0:d7810ff946c1 71 for (StackPointer-=(StackSize/sizeof(TStackItem)); StackPointer < Stack; *(StackPointer++) = STACK_FILL_CONST);
segundo 0:d7810ff946c1 72 #endif //DEBUG_STACK
segundo 0:d7810ff946c1 73
segundo 0:d7810ff946c1 74 //---------------------------------------------------------------
segundo 0:d7810ff946c1 75 //
segundo 0:d7810ff946c1 76 // Prepare Process Stack Frame
segundo 0:d7810ff946c1 77 //
segundo 0:d7810ff946c1 78 *(--StackPointer) = 0x01000000L; // xPSR
segundo 0:d7810ff946c1 79 *(--StackPointer) = reinterpret_cast<dword>(exec); // Entry Point
segundo 0:d7810ff946c1 80 StackPointer -= 14; // emulate "push R14,R12,R3,R2,R1,R0,R11-R4"
segundo 0:d7810ff946c1 81
segundo 0:d7810ff946c1 82 // The code below can be used for debug purpose. In this case comment
segundo 0:d7810ff946c1 83 // line above and uncomment block below.
segundo 0:d7810ff946c1 84 /*
segundo 0:d7810ff946c1 85 *(--StackPointer) = 0xFFFFFFFEL; // R14 (LR) (init value will cause fault if ever used)
segundo 0:d7810ff946c1 86 *(--StackPointer) = 0x12121212L; // R12
segundo 0:d7810ff946c1 87 *(--StackPointer) = 0x03030303L; // R3
segundo 0:d7810ff946c1 88 *(--StackPointer) = 0x02020202L; // R2
segundo 0:d7810ff946c1 89 *(--StackPointer) = 0x01010101L; // R1
segundo 0:d7810ff946c1 90 *(--StackPointer) = 0x00000000L; // R0
segundo 0:d7810ff946c1 91
segundo 0:d7810ff946c1 92 // Remaining registers saved on process stack
segundo 0:d7810ff946c1 93 *(--StackPointer) = 0x11111111L; // R11
segundo 0:d7810ff946c1 94 *(--StackPointer) = 0x10101010L; // R10
segundo 0:d7810ff946c1 95 *(--StackPointer) = 0x09090909L; // R9
segundo 0:d7810ff946c1 96 *(--StackPointer) = 0x08080808L; // R8
segundo 0:d7810ff946c1 97 *(--StackPointer) = 0x07070707L; // R7
segundo 0:d7810ff946c1 98 *(--StackPointer) = 0x06060606L; // R6
segundo 0:d7810ff946c1 99 *(--StackPointer) = 0x05050505L; // R5
segundo 0:d7810ff946c1 100 *(--StackPointer) = 0x04040404L; // R4
segundo 0:d7810ff946c1 101 */
segundo 0:d7810ff946c1 102 }
segundo 0:d7810ff946c1 103 //------------------------------------------------------------------------------
segundo 0:d7810ff946c1 104 //
segundo 0:d7810ff946c1 105 // Idle Process
segundo 0:d7810ff946c1 106 //
segundo 0:d7810ff946c1 107 typedef process<prIDLE, scmRTOS_IDLE_PROCESS_STACK_SIZE> TIdleProcess;
segundo 0:d7810ff946c1 108
segundo 0:d7810ff946c1 109 TIdleProcess IdleProcess;
segundo 0:d7810ff946c1 110
segundo 0:d7810ff946c1 111 template<> OS_PROCESS void TIdleProcess::Exec()
segundo 0:d7810ff946c1 112 {
segundo 0:d7810ff946c1 113 for(;;)
segundo 0:d7810ff946c1 114 {
segundo 0:d7810ff946c1 115 #if scmRTOS_IDLE_HOOK_ENABLE == 1
segundo 0:d7810ff946c1 116 IdleProcessUserHook();
segundo 0:d7810ff946c1 117 #endif
segundo 0:d7810ff946c1 118 }
segundo 0:d7810ff946c1 119 }
segundo 0:d7810ff946c1 120 //------------------------------------------------------------------------------
segundo 0:d7810ff946c1 121 OS_INTERRUPT void OS::SysTick_Handler()
segundo 0:d7810ff946c1 122 {
segundo 0:d7810ff946c1 123 scmRTOS_ISRW_TYPE ISR;
segundo 0:d7810ff946c1 124
segundo 0:d7810ff946c1 125 Kernel.SystemTimer();
segundo 0:d7810ff946c1 126
segundo 0:d7810ff946c1 127 #if scmRTOS_SYSTIMER_NEST_INTS_ENABLE == 0
segundo 0:d7810ff946c1 128 DISABLE_NESTED_INTERRUPTS();
segundo 0:d7810ff946c1 129 #endif
segundo 0:d7810ff946c1 130
segundo 0:d7810ff946c1 131 #if scmRTOS_SYSTIMER_HOOK_ENABLE == 1
segundo 0:d7810ff946c1 132 SystemTimerUserHook();
segundo 0:d7810ff946c1 133 #endif
segundo 0:d7810ff946c1 134 }
segundo 0:d7810ff946c1 135 //------------------------------------------------------------------------------
segundo 0:d7810ff946c1 136