Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
scmRTOS/CortexM3/OS_Target_cpp.cpp@0:906c21fbf97c, 2010-09-27 (annotated)
- Committer:
- kasturir
- Date:
- Mon Sep 27 22:51:19 2010 +0000
- Revision:
- 0:906c21fbf97c
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kasturir | 0:906c21fbf97c | 1 | //****************************************************************************** |
| kasturir | 0:906c21fbf97c | 2 | //* |
| kasturir | 0:906c21fbf97c | 3 | //* FULLNAME: Single-Chip Microcontroller Real-Time Operating System |
| kasturir | 0:906c21fbf97c | 4 | //* |
| kasturir | 0:906c21fbf97c | 5 | //* NICKNAME: scmRTOS |
| kasturir | 0:906c21fbf97c | 6 | //* |
| kasturir | 0:906c21fbf97c | 7 | //* PROCESSOR: ARM Cortex-M3 |
| kasturir | 0:906c21fbf97c | 8 | //* |
| kasturir | 0:906c21fbf97c | 9 | //* TOOLKIT: EWARM (IAR Systems) |
| kasturir | 0:906c21fbf97c | 10 | //* |
| kasturir | 0:906c21fbf97c | 11 | //* PURPOSE: Target Dependent Stuff Source |
| kasturir | 0:906c21fbf97c | 12 | //* |
| kasturir | 0:906c21fbf97c | 13 | //* Version: 3.10 |
| kasturir | 0:906c21fbf97c | 14 | //* |
| kasturir | 0:906c21fbf97c | 15 | //* $Revision: 195 $ |
| kasturir | 0:906c21fbf97c | 16 | //* $Date:: 2008-06-19 #$ |
| kasturir | 0:906c21fbf97c | 17 | //* |
| kasturir | 0:906c21fbf97c | 18 | //* Copyright (c) 2003-2010, Harry E. Zhurov |
| kasturir | 0:906c21fbf97c | 19 | //* |
| kasturir | 0:906c21fbf97c | 20 | //* Permission is hereby granted, free of charge, to any person |
| kasturir | 0:906c21fbf97c | 21 | //* obtaining a copy of this software and associated documentation |
| kasturir | 0:906c21fbf97c | 22 | //* files (the "Software"), to deal in the Software without restriction, |
| kasturir | 0:906c21fbf97c | 23 | //* including without limitation the rights to use, copy, modify, merge, |
| kasturir | 0:906c21fbf97c | 24 | //* publish, distribute, sublicense, and/or sell copies of the Software, |
| kasturir | 0:906c21fbf97c | 25 | //* and to permit persons to whom the Software is furnished to do so, |
| kasturir | 0:906c21fbf97c | 26 | //* subject to the following conditions: |
| kasturir | 0:906c21fbf97c | 27 | //* |
| kasturir | 0:906c21fbf97c | 28 | //* The above copyright notice and this permission notice shall be included |
| kasturir | 0:906c21fbf97c | 29 | //* in all copies or substantial portions of the Software. |
| kasturir | 0:906c21fbf97c | 30 | //* |
| kasturir | 0:906c21fbf97c | 31 | //* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| kasturir | 0:906c21fbf97c | 32 | //* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| kasturir | 0:906c21fbf97c | 33 | //* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| kasturir | 0:906c21fbf97c | 34 | //* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| kasturir | 0:906c21fbf97c | 35 | //* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| kasturir | 0:906c21fbf97c | 36 | //* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH |
| kasturir | 0:906c21fbf97c | 37 | //* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| kasturir | 0:906c21fbf97c | 38 | //* |
| kasturir | 0:906c21fbf97c | 39 | //* ================================================================= |
| kasturir | 0:906c21fbf97c | 40 | //* See http://scmrtos.sourceforge.net for documentation, latest |
| kasturir | 0:906c21fbf97c | 41 | //* information, license and contact details. |
| kasturir | 0:906c21fbf97c | 42 | //* ================================================================= |
| kasturir | 0:906c21fbf97c | 43 | //* |
| kasturir | 0:906c21fbf97c | 44 | //****************************************************************************** |
| kasturir | 0:906c21fbf97c | 45 | //* Ported by Andrey Chuikin, Copyright (c) 2008-2010 |
| kasturir | 0:906c21fbf97c | 46 | |
| kasturir | 0:906c21fbf97c | 47 | |
| kasturir | 0:906c21fbf97c | 48 | #include <scmRTOS.h> |
| kasturir | 0:906c21fbf97c | 49 | |
| kasturir | 0:906c21fbf97c | 50 | using namespace OS; |
| kasturir | 0:906c21fbf97c | 51 | |
| kasturir | 0:906c21fbf97c | 52 | //------------------------------------------------------------------------------ |
| kasturir | 0:906c21fbf97c | 53 | // |
| kasturir | 0:906c21fbf97c | 54 | // OS Process's constructor |
| kasturir | 0:906c21fbf97c | 55 | // |
| kasturir | 0:906c21fbf97c | 56 | // Performs: |
| kasturir | 0:906c21fbf97c | 57 | // * initializing process data; |
| kasturir | 0:906c21fbf97c | 58 | // * registering of the process in kernel; |
| kasturir | 0:906c21fbf97c | 59 | // * preparing stack frame; |
| kasturir | 0:906c21fbf97c | 60 | // |
| kasturir | 0:906c21fbf97c | 61 | // |
| kasturir | 0:906c21fbf97c | 62 | TBaseProcess::TBaseProcess(TStackItem* Stack, TPriority pr, void (*exec)()) |
| kasturir | 0:906c21fbf97c | 63 | : StackPointer(Stack) |
| kasturir | 0:906c21fbf97c | 64 | , Timeout(0) |
| kasturir | 0:906c21fbf97c | 65 | , Priority(pr) |
| kasturir | 0:906c21fbf97c | 66 | { |
| kasturir | 0:906c21fbf97c | 67 | Kernel.RegisterProcess(this); |
| kasturir | 0:906c21fbf97c | 68 | |
| kasturir | 0:906c21fbf97c | 69 | //--------------------------------------------------------------- |
| kasturir | 0:906c21fbf97c | 70 | // |
| kasturir | 0:906c21fbf97c | 71 | // Prepare Process Stack Frame |
| kasturir | 0:906c21fbf97c | 72 | // |
| kasturir | 0:906c21fbf97c | 73 | *(--StackPointer) = 0x01000000L; // xPSR |
| kasturir | 0:906c21fbf97c | 74 | *(--StackPointer) = reinterpret_cast<dword>(exec); // Entry Point |
| kasturir | 0:906c21fbf97c | 75 | StackPointer -= 14; // emulate "push R14,R12,R3,R2,R1,R0,R11-R4" |
| kasturir | 0:906c21fbf97c | 76 | |
| kasturir | 0:906c21fbf97c | 77 | // The code below can be used for debug purpose. In this case comment |
| kasturir | 0:906c21fbf97c | 78 | // line above and uncomment block below. |
| kasturir | 0:906c21fbf97c | 79 | /* |
| kasturir | 0:906c21fbf97c | 80 | *(--StackPointer) = 0xFFFFFFFEL; // R14 (LR) (init value will cause fault if ever used) |
| kasturir | 0:906c21fbf97c | 81 | *(--StackPointer) = 0x12121212L; // R12 |
| kasturir | 0:906c21fbf97c | 82 | *(--StackPointer) = 0x03030303L; // R3 |
| kasturir | 0:906c21fbf97c | 83 | *(--StackPointer) = 0x02020202L; // R2 |
| kasturir | 0:906c21fbf97c | 84 | *(--StackPointer) = 0x01010101L; // R1 |
| kasturir | 0:906c21fbf97c | 85 | *(--StackPointer) = 0x00000000L; // R0 |
| kasturir | 0:906c21fbf97c | 86 | |
| kasturir | 0:906c21fbf97c | 87 | // Remaining registers saved on process stack |
| kasturir | 0:906c21fbf97c | 88 | *(--StackPointer) = 0x11111111L; // R11 |
| kasturir | 0:906c21fbf97c | 89 | *(--StackPointer) = 0x10101010L; // R10 |
| kasturir | 0:906c21fbf97c | 90 | *(--StackPointer) = 0x09090909L; // R9 |
| kasturir | 0:906c21fbf97c | 91 | *(--StackPointer) = 0x08080808L; // R8 |
| kasturir | 0:906c21fbf97c | 92 | *(--StackPointer) = 0x07070707L; // R7 |
| kasturir | 0:906c21fbf97c | 93 | *(--StackPointer) = 0x06060606L; // R6 |
| kasturir | 0:906c21fbf97c | 94 | *(--StackPointer) = 0x05050505L; // R5 |
| kasturir | 0:906c21fbf97c | 95 | *(--StackPointer) = 0x04040404L; // R4 |
| kasturir | 0:906c21fbf97c | 96 | */ |
| kasturir | 0:906c21fbf97c | 97 | } |
| kasturir | 0:906c21fbf97c | 98 | //------------------------------------------------------------------------------ |
| kasturir | 0:906c21fbf97c | 99 | // |
| kasturir | 0:906c21fbf97c | 100 | // Idle Process |
| kasturir | 0:906c21fbf97c | 101 | // |
| kasturir | 0:906c21fbf97c | 102 | typedef process<prIDLE, scmRTOS_IDLE_PROCESS_STACK_SIZE> TIdleProcess; |
| kasturir | 0:906c21fbf97c | 103 | |
| kasturir | 0:906c21fbf97c | 104 | TIdleProcess IdleProcess; |
| kasturir | 0:906c21fbf97c | 105 | |
| kasturir | 0:906c21fbf97c | 106 | template<> OS_PROCESS void TIdleProcess::Exec() |
| kasturir | 0:906c21fbf97c | 107 | { |
| kasturir | 0:906c21fbf97c | 108 | for(;;) |
| kasturir | 0:906c21fbf97c | 109 | { |
| kasturir | 0:906c21fbf97c | 110 | #if scmRTOS_IDLE_HOOK_ENABLE == 1 |
| kasturir | 0:906c21fbf97c | 111 | IdleProcessUserHook(); |
| kasturir | 0:906c21fbf97c | 112 | #endif |
| kasturir | 0:906c21fbf97c | 113 | } |
| kasturir | 0:906c21fbf97c | 114 | } |
| kasturir | 0:906c21fbf97c | 115 | //------------------------------------------------------------------------------ |
| kasturir | 0:906c21fbf97c | 116 | OS_INTERRUPT void OS::SysTick_Handler() |
| kasturir | 0:906c21fbf97c | 117 | { |
| kasturir | 0:906c21fbf97c | 118 | scmRTOS_ISRW_TYPE ISR; |
| kasturir | 0:906c21fbf97c | 119 | |
| kasturir | 0:906c21fbf97c | 120 | Kernel.SystemTimer(); |
| kasturir | 0:906c21fbf97c | 121 | |
| kasturir | 0:906c21fbf97c | 122 | #if scmRTOS_SYSTIMER_NEST_INTS_ENABLE == 0 |
| kasturir | 0:906c21fbf97c | 123 | DISABLE_NESTED_INTERRUPTS(); |
| kasturir | 0:906c21fbf97c | 124 | #endif |
| kasturir | 0:906c21fbf97c | 125 | |
| kasturir | 0:906c21fbf97c | 126 | #if scmRTOS_SYSTIMER_HOOK_ENABLE == 1 |
| kasturir | 0:906c21fbf97c | 127 | SystemTimerUserHook(); |
| kasturir | 0:906c21fbf97c | 128 | #endif |
| kasturir | 0:906c21fbf97c | 129 | } |
| kasturir | 0:906c21fbf97c | 130 | //------------------------------------------------------------------------------ |
| kasturir | 0:906c21fbf97c | 131 |