ソースの整理中ですが、利用はできます。
Dependencies: EthernetInterface HttpServer TextLCD mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip
mbed-rtos/rtx/HAL_CM.c@2:14b689a85306, 2014-03-12 (annotated)
- Committer:
- yueee_yt
- Date:
- Wed Mar 12 04:39:15 2014 +0000
- Revision:
- 2:14b689a85306
- Parent:
- 0:7766f6712673
bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:7766f6712673 | 1 | /*---------------------------------------------------------------------------- |
yueee_yt | 0:7766f6712673 | 2 | * RL-ARM - RTX |
yueee_yt | 0:7766f6712673 | 3 | *---------------------------------------------------------------------------- |
yueee_yt | 0:7766f6712673 | 4 | * Name: HAL_CM.C |
yueee_yt | 0:7766f6712673 | 5 | * Purpose: Hardware Abstraction Layer for Cortex-M |
yueee_yt | 0:7766f6712673 | 6 | * Rev.: V4.60 |
yueee_yt | 0:7766f6712673 | 7 | *---------------------------------------------------------------------------- |
yueee_yt | 0:7766f6712673 | 8 | * |
yueee_yt | 0:7766f6712673 | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH |
yueee_yt | 0:7766f6712673 | 10 | * All rights reserved. |
yueee_yt | 0:7766f6712673 | 11 | * Redistribution and use in source and binary forms, with or without |
yueee_yt | 0:7766f6712673 | 12 | * modification, are permitted provided that the following conditions are met: |
yueee_yt | 0:7766f6712673 | 13 | * - Redistributions of source code must retain the above copyright |
yueee_yt | 0:7766f6712673 | 14 | * notice, this list of conditions and the following disclaimer. |
yueee_yt | 0:7766f6712673 | 15 | * - Redistributions in binary form must reproduce the above copyright |
yueee_yt | 0:7766f6712673 | 16 | * notice, this list of conditions and the following disclaimer in the |
yueee_yt | 0:7766f6712673 | 17 | * documentation and/or other materials provided with the distribution. |
yueee_yt | 0:7766f6712673 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
yueee_yt | 0:7766f6712673 | 19 | * to endorse or promote products derived from this software without |
yueee_yt | 0:7766f6712673 | 20 | * specific prior written permission. |
yueee_yt | 0:7766f6712673 | 21 | * |
yueee_yt | 0:7766f6712673 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
yueee_yt | 0:7766f6712673 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
yueee_yt | 0:7766f6712673 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
yueee_yt | 0:7766f6712673 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
yueee_yt | 0:7766f6712673 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
yueee_yt | 0:7766f6712673 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
yueee_yt | 0:7766f6712673 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
yueee_yt | 0:7766f6712673 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
yueee_yt | 0:7766f6712673 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
yueee_yt | 0:7766f6712673 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
yueee_yt | 0:7766f6712673 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
yueee_yt | 0:7766f6712673 | 33 | *---------------------------------------------------------------------------*/ |
yueee_yt | 0:7766f6712673 | 34 | |
yueee_yt | 0:7766f6712673 | 35 | #include "rt_TypeDef.h" |
yueee_yt | 0:7766f6712673 | 36 | #include "RTX_Conf.h" |
yueee_yt | 0:7766f6712673 | 37 | #include "rt_HAL_CM.h" |
yueee_yt | 0:7766f6712673 | 38 | |
yueee_yt | 0:7766f6712673 | 39 | |
yueee_yt | 0:7766f6712673 | 40 | /*---------------------------------------------------------------------------- |
yueee_yt | 0:7766f6712673 | 41 | * Global Variables |
yueee_yt | 0:7766f6712673 | 42 | *---------------------------------------------------------------------------*/ |
yueee_yt | 0:7766f6712673 | 43 | |
yueee_yt | 0:7766f6712673 | 44 | #ifdef DBG_MSG |
yueee_yt | 0:7766f6712673 | 45 | BIT dbg_msg; |
yueee_yt | 0:7766f6712673 | 46 | #endif |
yueee_yt | 0:7766f6712673 | 47 | |
yueee_yt | 0:7766f6712673 | 48 | /*---------------------------------------------------------------------------- |
yueee_yt | 0:7766f6712673 | 49 | * Functions |
yueee_yt | 0:7766f6712673 | 50 | *---------------------------------------------------------------------------*/ |
yueee_yt | 0:7766f6712673 | 51 | |
yueee_yt | 0:7766f6712673 | 52 | |
yueee_yt | 0:7766f6712673 | 53 | /*--------------------------- rt_init_stack ---------------------------------*/ |
yueee_yt | 0:7766f6712673 | 54 | |
yueee_yt | 0:7766f6712673 | 55 | void rt_init_stack (P_TCB p_TCB, FUNCP task_body) { |
yueee_yt | 0:7766f6712673 | 56 | /* Prepare TCB and saved context for a first time start of a task. */ |
yueee_yt | 0:7766f6712673 | 57 | U32 *stk,i,size; |
yueee_yt | 0:7766f6712673 | 58 | |
yueee_yt | 0:7766f6712673 | 59 | /* Prepare a complete interrupt frame for first task start */ |
yueee_yt | 0:7766f6712673 | 60 | size = p_TCB->priv_stack >> 2; |
yueee_yt | 0:7766f6712673 | 61 | |
yueee_yt | 0:7766f6712673 | 62 | /* Write to the top of stack. */ |
yueee_yt | 0:7766f6712673 | 63 | stk = &p_TCB->stack[size]; |
yueee_yt | 0:7766f6712673 | 64 | |
yueee_yt | 0:7766f6712673 | 65 | /* Auto correct to 8-byte ARM stack alignment. */ |
yueee_yt | 0:7766f6712673 | 66 | if ((U32)stk & 0x04) { |
yueee_yt | 0:7766f6712673 | 67 | stk--; |
yueee_yt | 0:7766f6712673 | 68 | } |
yueee_yt | 0:7766f6712673 | 69 | |
yueee_yt | 0:7766f6712673 | 70 | stk -= 16; |
yueee_yt | 0:7766f6712673 | 71 | |
yueee_yt | 0:7766f6712673 | 72 | /* Default xPSR and initial PC */ |
yueee_yt | 0:7766f6712673 | 73 | stk[15] = INITIAL_xPSR; |
yueee_yt | 0:7766f6712673 | 74 | stk[14] = (U32)task_body; |
yueee_yt | 0:7766f6712673 | 75 | |
yueee_yt | 0:7766f6712673 | 76 | /* Clear R4-R11,R0-R3,R12,LR registers. */ |
yueee_yt | 0:7766f6712673 | 77 | for (i = 0; i < 14; i++) { |
yueee_yt | 0:7766f6712673 | 78 | stk[i] = 0; |
yueee_yt | 0:7766f6712673 | 79 | } |
yueee_yt | 0:7766f6712673 | 80 | |
yueee_yt | 0:7766f6712673 | 81 | /* Assign a void pointer to R0. */ |
yueee_yt | 0:7766f6712673 | 82 | stk[8] = (U32)p_TCB->msg; |
yueee_yt | 0:7766f6712673 | 83 | |
yueee_yt | 0:7766f6712673 | 84 | /* Initial Task stack pointer. */ |
yueee_yt | 0:7766f6712673 | 85 | p_TCB->tsk_stack = (U32)stk; |
yueee_yt | 0:7766f6712673 | 86 | |
yueee_yt | 0:7766f6712673 | 87 | /* Task entry point. */ |
yueee_yt | 0:7766f6712673 | 88 | p_TCB->ptask = task_body; |
yueee_yt | 0:7766f6712673 | 89 | |
yueee_yt | 0:7766f6712673 | 90 | /* Set a magic word for checking of stack overflow. |
yueee_yt | 0:7766f6712673 | 91 | For the main thread (ID: 0x01) the stack is in a memory area shared with the |
yueee_yt | 0:7766f6712673 | 92 | heap, therefore the last word of the stack is a moving target. |
yueee_yt | 0:7766f6712673 | 93 | We want to do stack/heap collision detection instead. |
yueee_yt | 0:7766f6712673 | 94 | */ |
yueee_yt | 0:7766f6712673 | 95 | if (p_TCB->task_id != 0x01) |
yueee_yt | 0:7766f6712673 | 96 | p_TCB->stack[0] = MAGIC_WORD; |
yueee_yt | 0:7766f6712673 | 97 | } |
yueee_yt | 0:7766f6712673 | 98 | |
yueee_yt | 0:7766f6712673 | 99 | |
yueee_yt | 0:7766f6712673 | 100 | /*--------------------------- rt_ret_val ----------------------------------*/ |
yueee_yt | 0:7766f6712673 | 101 | |
yueee_yt | 0:7766f6712673 | 102 | static __inline U32 *rt_ret_regs (P_TCB p_TCB) { |
yueee_yt | 0:7766f6712673 | 103 | /* Get pointer to task return value registers (R0..R3) in Stack */ |
yueee_yt | 0:7766f6712673 | 104 | #if (__TARGET_FPU_VFP) |
yueee_yt | 0:7766f6712673 | 105 | if (p_TCB->stack_frame) { |
yueee_yt | 0:7766f6712673 | 106 | /* Extended Stack Frame: R4-R11,S16-S31,R0-R3,R12,LR,PC,xPSR,S0-S15,FPSCR */ |
yueee_yt | 0:7766f6712673 | 107 | return (U32 *)(p_TCB->tsk_stack + 8*4 + 16*4); |
yueee_yt | 0:7766f6712673 | 108 | } else { |
yueee_yt | 0:7766f6712673 | 109 | /* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */ |
yueee_yt | 0:7766f6712673 | 110 | return (U32 *)(p_TCB->tsk_stack + 8*4); |
yueee_yt | 0:7766f6712673 | 111 | } |
yueee_yt | 0:7766f6712673 | 112 | #else |
yueee_yt | 0:7766f6712673 | 113 | /* Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */ |
yueee_yt | 0:7766f6712673 | 114 | return (U32 *)(p_TCB->tsk_stack + 8*4); |
yueee_yt | 0:7766f6712673 | 115 | #endif |
yueee_yt | 0:7766f6712673 | 116 | } |
yueee_yt | 0:7766f6712673 | 117 | |
yueee_yt | 0:7766f6712673 | 118 | void rt_ret_val (P_TCB p_TCB, U32 v0) { |
yueee_yt | 0:7766f6712673 | 119 | U32 *ret; |
yueee_yt | 0:7766f6712673 | 120 | |
yueee_yt | 0:7766f6712673 | 121 | ret = rt_ret_regs(p_TCB); |
yueee_yt | 0:7766f6712673 | 122 | ret[0] = v0; |
yueee_yt | 0:7766f6712673 | 123 | } |
yueee_yt | 0:7766f6712673 | 124 | |
yueee_yt | 0:7766f6712673 | 125 | void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) { |
yueee_yt | 0:7766f6712673 | 126 | U32 *ret; |
yueee_yt | 0:7766f6712673 | 127 | |
yueee_yt | 0:7766f6712673 | 128 | ret = rt_ret_regs(p_TCB); |
yueee_yt | 0:7766f6712673 | 129 | ret[0] = v0; |
yueee_yt | 0:7766f6712673 | 130 | ret[1] = v1; |
yueee_yt | 0:7766f6712673 | 131 | } |
yueee_yt | 0:7766f6712673 | 132 | |
yueee_yt | 0:7766f6712673 | 133 | |
yueee_yt | 0:7766f6712673 | 134 | /*--------------------------- dbg_init --------------------------------------*/ |
yueee_yt | 0:7766f6712673 | 135 | |
yueee_yt | 0:7766f6712673 | 136 | #ifdef DBG_MSG |
yueee_yt | 0:7766f6712673 | 137 | void dbg_init (void) { |
yueee_yt | 0:7766f6712673 | 138 | if ((DEMCR & DEMCR_TRCENA) && |
yueee_yt | 0:7766f6712673 | 139 | (ITM_CONTROL & ITM_ITMENA) && |
yueee_yt | 0:7766f6712673 | 140 | (ITM_ENABLE & (1UL << 31))) { |
yueee_yt | 0:7766f6712673 | 141 | dbg_msg = __TRUE; |
yueee_yt | 0:7766f6712673 | 142 | } |
yueee_yt | 0:7766f6712673 | 143 | } |
yueee_yt | 0:7766f6712673 | 144 | #endif |
yueee_yt | 0:7766f6712673 | 145 | |
yueee_yt | 0:7766f6712673 | 146 | /*--------------------------- dbg_task_notify -------------------------------*/ |
yueee_yt | 0:7766f6712673 | 147 | |
yueee_yt | 0:7766f6712673 | 148 | #ifdef DBG_MSG |
yueee_yt | 0:7766f6712673 | 149 | void dbg_task_notify (P_TCB p_tcb, BOOL create) { |
yueee_yt | 0:7766f6712673 | 150 | while (ITM_PORT31_U32 == 0); |
yueee_yt | 0:7766f6712673 | 151 | ITM_PORT31_U32 = (U32)p_tcb->ptask; |
yueee_yt | 0:7766f6712673 | 152 | while (ITM_PORT31_U32 == 0); |
yueee_yt | 0:7766f6712673 | 153 | ITM_PORT31_U16 = (create << 8) | p_tcb->task_id; |
yueee_yt | 0:7766f6712673 | 154 | } |
yueee_yt | 0:7766f6712673 | 155 | #endif |
yueee_yt | 0:7766f6712673 | 156 | |
yueee_yt | 0:7766f6712673 | 157 | /*--------------------------- dbg_task_switch -------------------------------*/ |
yueee_yt | 0:7766f6712673 | 158 | |
yueee_yt | 0:7766f6712673 | 159 | #ifdef DBG_MSG |
yueee_yt | 0:7766f6712673 | 160 | void dbg_task_switch (U32 task_id) { |
yueee_yt | 0:7766f6712673 | 161 | while (ITM_PORT31_U32 == 0); |
yueee_yt | 0:7766f6712673 | 162 | ITM_PORT31_U8 = task_id; |
yueee_yt | 0:7766f6712673 | 163 | } |
yueee_yt | 0:7766f6712673 | 164 | #endif |
yueee_yt | 0:7766f6712673 | 165 | |
yueee_yt | 0:7766f6712673 | 166 | |
yueee_yt | 0:7766f6712673 | 167 | /*---------------------------------------------------------------------------- |
yueee_yt | 0:7766f6712673 | 168 | * end of file |
yueee_yt | 0:7766f6712673 | 169 | *---------------------------------------------------------------------------*/ |
yueee_yt | 0:7766f6712673 | 170 |