Nummer 0.1 Werkt nog niet volledig
Fork of mbed-rtos by
rtx/TARGET_CORTEX_A/HAL_CA.c@109:f37e70028583, 2016-05-13 (annotated)
- Committer:
- Reynier
- Date:
- Fri May 13 21:42:20 2016 +0000
- Revision:
- 109:f37e70028583
- Parent:
- 92:bc9729798a19
Alles zonder werkende NRF
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 48:e9a2c7cb57a4 | 1 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 2 | * RL-ARM - RTX |
mbed_official | 48:e9a2c7cb57a4 | 3 | *---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 4 | * Name: HAL_CA.C |
mbed_official | 48:e9a2c7cb57a4 | 5 | * Purpose: Hardware Abstraction Layer for Cortex-A |
mbed_official | 48:e9a2c7cb57a4 | 6 | * Rev.: |
mbed_official | 48:e9a2c7cb57a4 | 7 | *---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 8 | * |
mbed_official | 48:e9a2c7cb57a4 | 9 | * Copyright (c) 2012 ARM Limited |
mbed_official | 48:e9a2c7cb57a4 | 10 | * All rights reserved. |
mbed_official | 48:e9a2c7cb57a4 | 11 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 48:e9a2c7cb57a4 | 12 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 48:e9a2c7cb57a4 | 13 | * - Redistributions of source code must retain the above copyright |
mbed_official | 48:e9a2c7cb57a4 | 14 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 48:e9a2c7cb57a4 | 15 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 48:e9a2c7cb57a4 | 16 | * notice, this list of conditions and the following disclaimer in the |
mbed_official | 48:e9a2c7cb57a4 | 17 | * documentation and/or other materials provided with the distribution. |
mbed_official | 68:d3d0e710b443 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
mbed_official | 68:d3d0e710b443 | 19 | * to endorse or promote products derived from this software without |
mbed_official | 48:e9a2c7cb57a4 | 20 | * specific prior written permission. |
mbed_official | 48:e9a2c7cb57a4 | 21 | * |
mbed_official | 68:d3d0e710b443 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 68:d3d0e710b443 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 48:e9a2c7cb57a4 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
mbed_official | 48:e9a2c7cb57a4 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
mbed_official | 48:e9a2c7cb57a4 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
mbed_official | 68:d3d0e710b443 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
mbed_official | 68:d3d0e710b443 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
mbed_official | 68:d3d0e710b443 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
mbed_official | 68:d3d0e710b443 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
mbed_official | 48:e9a2c7cb57a4 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 48:e9a2c7cb57a4 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 48:e9a2c7cb57a4 | 33 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 34 | |
mbed_official | 48:e9a2c7cb57a4 | 35 | #include "rt_TypeDef.h" |
mbed_official | 48:e9a2c7cb57a4 | 36 | #include "RTX_Config.h" |
mbed_official | 48:e9a2c7cb57a4 | 37 | #include "rt_HAL_CA.h" |
mbed_official | 48:e9a2c7cb57a4 | 38 | |
mbed_official | 48:e9a2c7cb57a4 | 39 | /*--------------------------- os_init_context -------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 40 | |
mbed_official | 48:e9a2c7cb57a4 | 41 | void rt_init_stack (P_TCB p_TCB, FUNCP task_body) { |
mbed_official | 48:e9a2c7cb57a4 | 42 | /* Prepare TCB and saved context for a first time start of a task. */ |
mbed_official | 48:e9a2c7cb57a4 | 43 | U32 *stk,i,size; |
mbed_official | 48:e9a2c7cb57a4 | 44 | |
mbed_official | 48:e9a2c7cb57a4 | 45 | /* Prepare a complete interrupt frame for first task start */ |
mbed_official | 48:e9a2c7cb57a4 | 46 | size = p_TCB->priv_stack >> 2; |
mbed_official | 48:e9a2c7cb57a4 | 47 | if (size == 0) { |
mbed_official | 48:e9a2c7cb57a4 | 48 | size = (U16)os_stackinfo >> 2; |
mbed_official | 48:e9a2c7cb57a4 | 49 | } |
mbed_official | 48:e9a2c7cb57a4 | 50 | /* Write to the top of stack. */ |
mbed_official | 48:e9a2c7cb57a4 | 51 | stk = &p_TCB->stack[size]; |
mbed_official | 48:e9a2c7cb57a4 | 52 | |
mbed_official | 48:e9a2c7cb57a4 | 53 | /* Auto correct to 8-byte ARM stack alignment. */ |
mbed_official | 48:e9a2c7cb57a4 | 54 | if ((U32)stk & 0x04) { |
mbed_official | 48:e9a2c7cb57a4 | 55 | stk--; |
mbed_official | 48:e9a2c7cb57a4 | 56 | } |
mbed_official | 48:e9a2c7cb57a4 | 57 | |
mbed_official | 48:e9a2c7cb57a4 | 58 | stk -= 16; |
mbed_official | 48:e9a2c7cb57a4 | 59 | |
mbed_official | 48:e9a2c7cb57a4 | 60 | /* Initial PC and default CPSR */ |
mbed_official | 48:e9a2c7cb57a4 | 61 | stk[14] = (U32)task_body; |
mbed_official | 48:e9a2c7cb57a4 | 62 | /* Task run mode is inherited from the startup file. */ |
mbed_official | 48:e9a2c7cb57a4 | 63 | /* (non-privileged USER or privileged SYSTEM mode) */ |
mbed_official | 48:e9a2c7cb57a4 | 64 | stk[15] = (os_flags & 1) ? INIT_CPSR_SYS : INIT_CPSR_USER; |
mbed_official | 48:e9a2c7cb57a4 | 65 | /* Set T-bit if task function in Thumb mode. */ |
mbed_official | 48:e9a2c7cb57a4 | 66 | if ((U32)task_body & 1) { |
mbed_official | 48:e9a2c7cb57a4 | 67 | stk[15] |= CPSR_T_BIT; |
mbed_official | 48:e9a2c7cb57a4 | 68 | } |
mbed_official | 48:e9a2c7cb57a4 | 69 | /* Assign a void pointer to R0. */ |
mbed_official | 48:e9a2c7cb57a4 | 70 | stk[8] = (U32)p_TCB->msg; |
mbed_official | 48:e9a2c7cb57a4 | 71 | /* Clear R1-R12,LR registers. */ |
mbed_official | 48:e9a2c7cb57a4 | 72 | for (i = 0; i < 8; i++) { |
mbed_official | 48:e9a2c7cb57a4 | 73 | stk[i] = 0; |
mbed_official | 48:e9a2c7cb57a4 | 74 | } |
mbed_official | 48:e9a2c7cb57a4 | 75 | for (i = 9; i < 14; i++) { |
mbed_official | 48:e9a2c7cb57a4 | 76 | stk[i] = 0; |
mbed_official | 48:e9a2c7cb57a4 | 77 | } |
mbed_official | 48:e9a2c7cb57a4 | 78 | |
mbed_official | 48:e9a2c7cb57a4 | 79 | /* Initial Task stack pointer. */ |
mbed_official | 48:e9a2c7cb57a4 | 80 | p_TCB->tsk_stack = (U32)stk; |
mbed_official | 48:e9a2c7cb57a4 | 81 | |
mbed_official | 48:e9a2c7cb57a4 | 82 | /* Task entry point. */ |
mbed_official | 48:e9a2c7cb57a4 | 83 | p_TCB->ptask = task_body; |
mbed_official | 48:e9a2c7cb57a4 | 84 | |
mbed_official | 48:e9a2c7cb57a4 | 85 | /* Set a magic word for checking of stack overflow. */ |
mbed_official | 48:e9a2c7cb57a4 | 86 | p_TCB->stack[0] = MAGIC_WORD; |
mbed_official | 48:e9a2c7cb57a4 | 87 | } |
mbed_official | 48:e9a2c7cb57a4 | 88 | |
mbed_official | 48:e9a2c7cb57a4 | 89 | |
mbed_official | 48:e9a2c7cb57a4 | 90 | /*--------------------------- rt_ret_val ----------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 91 | |
mbed_official | 48:e9a2c7cb57a4 | 92 | static __inline U32 *rt_ret_regs (P_TCB p_TCB) { |
mbed_official | 48:e9a2c7cb57a4 | 93 | /* Get pointer to task return value registers (R0..R3) in Stack */ |
mbed_official | 92:bc9729798a19 | 94 | if (p_TCB->stack_frame & 0x4) { |
mbed_official | 92:bc9729798a19 | 95 | /* NEON/D32 Stack Frame: D0-31,FPSCR,Reserved,R4-R11,R0-R3,R12,LR,PC,xPSR */ |
mbed_official | 92:bc9729798a19 | 96 | return (U32 *)(p_TCB->tsk_stack + 8*4 + 2*4 + 32*8); |
mbed_official | 92:bc9729798a19 | 97 | } else if (p_TCB->stack_frame & 0x2) { |
mbed_official | 92:bc9729798a19 | 98 | /* VFP/D16 Stack Frame: D0-D15/S0-31,FPSCR,Reserved,R4-R11,R0-R3,R12,LR,PC,xPSR */ |
mbed_official | 92:bc9729798a19 | 99 | return (U32 *)(p_TCB->tsk_stack + 8*4 + 2*4 + 32*4); |
mbed_official | 48:e9a2c7cb57a4 | 100 | } else { |
mbed_official | 48:e9a2c7cb57a4 | 101 | /* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */ |
mbed_official | 48:e9a2c7cb57a4 | 102 | return (U32 *)(p_TCB->tsk_stack + 8*4); |
mbed_official | 48:e9a2c7cb57a4 | 103 | } |
mbed_official | 48:e9a2c7cb57a4 | 104 | } |
mbed_official | 48:e9a2c7cb57a4 | 105 | |
mbed_official | 48:e9a2c7cb57a4 | 106 | void rt_ret_val (P_TCB p_TCB, U32 v0) { |
mbed_official | 48:e9a2c7cb57a4 | 107 | U32 *ret; |
mbed_official | 48:e9a2c7cb57a4 | 108 | |
mbed_official | 48:e9a2c7cb57a4 | 109 | ret = rt_ret_regs(p_TCB); |
mbed_official | 48:e9a2c7cb57a4 | 110 | ret[0] = v0; |
mbed_official | 48:e9a2c7cb57a4 | 111 | } |
mbed_official | 48:e9a2c7cb57a4 | 112 | |
mbed_official | 48:e9a2c7cb57a4 | 113 | void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) { |
mbed_official | 48:e9a2c7cb57a4 | 114 | U32 *ret; |
mbed_official | 48:e9a2c7cb57a4 | 115 | |
mbed_official | 48:e9a2c7cb57a4 | 116 | ret = rt_ret_regs(p_TCB); |
mbed_official | 48:e9a2c7cb57a4 | 117 | ret[0] = v0; |
mbed_official | 48:e9a2c7cb57a4 | 118 | ret[1] = v1; |
mbed_official | 48:e9a2c7cb57a4 | 119 | } |
mbed_official | 48:e9a2c7cb57a4 | 120 | |
mbed_official | 48:e9a2c7cb57a4 | 121 | |
mbed_official | 48:e9a2c7cb57a4 | 122 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 123 | * end of file |
mbed_official | 48:e9a2c7cb57a4 | 124 | *---------------------------------------------------------------------------*/ |