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