Program to control an accelerometer, motors and a rangefinder using the ScmRTOS ported to mbed. (Work in progress and buggy)

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OS_Target_cpp.cpp Source File

OS_Target_cpp.cpp

00001 //******************************************************************************
00002 //*
00003 //*     FULLNAME:  Single-Chip Microcontroller Real-Time Operating System
00004 //*
00005 //*     NICKNAME:  scmRTOS
00006 //*
00007 //*     PROCESSOR: ARM Cortex-M3 
00008 //*
00009 //*     TOOLKIT:   EWARM (IAR Systems)
00010 //*               
00011 //*     PURPOSE:   Target Dependent Stuff Source
00012 //*               
00013 //*     Version: 3.10
00014 //*
00015 //*     $Revision: 195 $
00016 //*     $Date:: 2008-06-19 #$
00017 //*
00018 //*     Copyright (c) 2003-2010, Harry E. Zhurov
00019 //*
00020 //*     Permission is hereby granted, free of charge, to any person 
00021 //*     obtaining  a copy of this software and associated documentation 
00022 //*     files (the "Software"), to deal in the Software without restriction, 
00023 //*     including without limitation the rights to use, copy, modify, merge, 
00024 //*     publish, distribute, sublicense, and/or sell copies of the Software, 
00025 //*     and to permit persons to whom the Software is furnished to do so, 
00026 //*     subject to the following conditions:
00027 //*
00028 //*     The above copyright notice and this permission notice shall be included 
00029 //*     in all copies or substantial portions of the Software.
00030 //*
00031 //*     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00032 //*     EXPRESS  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
00033 //*     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00034 //*     IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
00035 //*     CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
00036 //*     TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 
00037 //*     THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00038 //*
00039 //*     =================================================================
00040 //*     See http://scmrtos.sourceforge.net for documentation, latest
00041 //*     information, license and contact details.
00042 //*     =================================================================
00043 //*
00044 //******************************************************************************
00045 //*     Ported by Andrey Chuikin, Copyright (c) 2008-2010
00046 
00047 
00048 #include <scmRTOS.h>
00049 
00050 using namespace OS;
00051 
00052 //------------------------------------------------------------------------------
00053 //
00054 //       OS Process's constructor
00055 //
00056 //       Performs:  
00057 //           * initializing process data;
00058 //           * registering of the process in kernel;
00059 //           * preparing stack frame;
00060 //                  
00061 //
00062 TBaseProcess::TBaseProcess(TStackItem* Stack, TPriority pr, void (*exec)())
00063     : StackPointer(Stack)
00064     , Timeout(0)
00065     , Priority(pr)
00066 {
00067     Kernel.RegisterProcess(this);
00068 
00069     //---------------------------------------------------------------
00070     //
00071     //  Prepare Process Stack Frame
00072     //
00073     *(--StackPointer)  = 0x01000000L;             // xPSR
00074     *(--StackPointer)  = reinterpret_cast<dword>(exec); // Entry Point
00075     StackPointer -= 14;                           // emulate "push R14,R12,R3,R2,R1,R0,R11-R4"
00076     
00077     // The code below can be used for debug purpose. In this case comment
00078     // line above and uncomment block below.
00079 /*
00080     *(--StackPointer)  = 0xFFFFFFFEL;             // R14 (LR) (init value will cause fault if ever used)
00081     *(--StackPointer)  = 0x12121212L;             // R12
00082     *(--StackPointer)  = 0x03030303L;             // R3
00083     *(--StackPointer)  = 0x02020202L;             // R2
00084     *(--StackPointer)  = 0x01010101L;             // R1
00085     *(--StackPointer)  = 0x00000000L;             // R0
00086 
00087                                                   // Remaining registers saved on process stack
00088     *(--StackPointer)  = 0x11111111L;             // R11
00089     *(--StackPointer)  = 0x10101010L;             // R10
00090     *(--StackPointer)  = 0x09090909L;             // R9
00091     *(--StackPointer)  = 0x08080808L;             // R8
00092     *(--StackPointer)  = 0x07070707L;             // R7
00093     *(--StackPointer)  = 0x06060606L;             // R6
00094     *(--StackPointer)  = 0x05050505L;             // R5
00095     *(--StackPointer)  = 0x04040404L;             // R4
00096 */
00097 }
00098 //------------------------------------------------------------------------------
00099 //
00100 //   Idle Process
00101 //
00102 typedef process<prIDLE, scmRTOS_IDLE_PROCESS_STACK_SIZE> TIdleProcess;
00103 
00104 TIdleProcess IdleProcess;
00105 
00106 template<> OS_PROCESS void TIdleProcess::Exec()
00107 {
00108     for(;;)
00109     {
00110         #if scmRTOS_IDLE_HOOK_ENABLE == 1
00111         IdleProcessUserHook();
00112         #endif
00113     }
00114 }
00115 //------------------------------------------------------------------------------
00116 OS_INTERRUPT void OS::SysTick_Handler()
00117 {
00118     scmRTOS_ISRW_TYPE ISR;
00119 
00120     Kernel.SystemTimer();
00121     
00122 #if scmRTOS_SYSTIMER_NEST_INTS_ENABLE == 0
00123     DISABLE_NESTED_INTERRUPTS();
00124 #endif
00125     
00126 #if scmRTOS_SYSTIMER_HOOK_ENABLE == 1
00127     SystemTimerUserHook();
00128 #endif
00129 }
00130 //------------------------------------------------------------------------------
00131