RTC auf true
rtos/TARGET_CORTEX/mbed_boot.c@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2016 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | |
kevman | 0:38ceb79fef03 | 17 | /* mbed OS boot sequence |
kevman | 0:38ceb79fef03 | 18 | * |
kevman | 0:38ceb79fef03 | 19 | * Most of mbed supported targets use default ARM Cortex M boot approach, where the core starts executing reset vector |
kevman | 0:38ceb79fef03 | 20 | * after power up. Reset ISR is defined for each target by the vendor (basing on CMSIS template). Reset vector is |
kevman | 0:38ceb79fef03 | 21 | * responsible for low level platform init and then calling in libc (__main). Depending on compiler and version of C |
kevman | 0:38ceb79fef03 | 22 | * library, predefined function will be called which is implemented by mbed OS. |
kevman | 0:38ceb79fef03 | 23 | * |
kevman | 0:38ceb79fef03 | 24 | * There's number of functions, vendor and users can provide to setup the platform and/or inject a code to be executed |
kevman | 0:38ceb79fef03 | 25 | * before main(): |
kevman | 0:38ceb79fef03 | 26 | * * Reset vector and SystemInit: Reset vector should do low level core and board initialization. |
kevman | 0:38ceb79fef03 | 27 | * * mbed_sdk_init: Higher level board init and making sure the board is ready for the mbed OS. |
kevman | 0:38ceb79fef03 | 28 | * * mbed_main: User's code to be executed before main(). |
kevman | 0:38ceb79fef03 | 29 | * * main: Standard application code. |
kevman | 0:38ceb79fef03 | 30 | * |
kevman | 0:38ceb79fef03 | 31 | * Other notes: |
kevman | 0:38ceb79fef03 | 32 | * |
kevman | 0:38ceb79fef03 | 33 | * * In addition to the above, libc will use functions defined in mbed_boot.c: __rtos_malloc_lock/unlock, |
kevman | 0:38ceb79fef03 | 34 | * __rtos_env_lock/unlock. |
kevman | 0:38ceb79fef03 | 35 | * |
kevman | 0:38ceb79fef03 | 36 | * * First step after the execution is passed to mbed, software_init_hook for GCC and __rt_entry for ARMC is to |
kevman | 0:38ceb79fef03 | 37 | * initialize heap. |
kevman | 0:38ceb79fef03 | 38 | * |
kevman | 0:38ceb79fef03 | 39 | * Memory layout notes: |
kevman | 0:38ceb79fef03 | 40 | * ==================== |
kevman | 0:38ceb79fef03 | 41 | * |
kevman | 0:38ceb79fef03 | 42 | * IAR Default Memory layout notes: |
kevman | 0:38ceb79fef03 | 43 | * -Heap defined by "HEAP" region in .icf file |
kevman | 0:38ceb79fef03 | 44 | * -Interrupt stack defined by "CSTACK" region in .icf file |
kevman | 0:38ceb79fef03 | 45 | * -Value INITIAL_SP is ignored |
kevman | 0:38ceb79fef03 | 46 | * |
kevman | 0:38ceb79fef03 | 47 | * IAR Custom Memory layout notes: |
kevman | 0:38ceb79fef03 | 48 | * -There is no custom layout available for IAR - everything must be defined in |
kevman | 0:38ceb79fef03 | 49 | * the .icf file and use the default layout |
kevman | 0:38ceb79fef03 | 50 | * |
kevman | 0:38ceb79fef03 | 51 | * |
kevman | 0:38ceb79fef03 | 52 | * GCC Default Memory layout notes: |
kevman | 0:38ceb79fef03 | 53 | * -Block of memory from symbol __end__ to define INITIAL_SP used to setup interrupt |
kevman | 0:38ceb79fef03 | 54 | * stack and heap in the function set_stack_heap() |
kevman | 0:38ceb79fef03 | 55 | * -ISR_STACK_SIZE can be overridden to be larger or smaller |
kevman | 0:38ceb79fef03 | 56 | * |
kevman | 0:38ceb79fef03 | 57 | * GCC Custom Memory layout notes: |
kevman | 0:38ceb79fef03 | 58 | * -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE |
kevman | 0:38ceb79fef03 | 59 | * -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE |
kevman | 0:38ceb79fef03 | 60 | * |
kevman | 0:38ceb79fef03 | 61 | * |
kevman | 0:38ceb79fef03 | 62 | * ARM Memory layout |
kevman | 0:38ceb79fef03 | 63 | * -Block of memory from end of region "RW_IRAM1" to define INITIAL_SP used to setup interrupt |
kevman | 0:38ceb79fef03 | 64 | * stack and heap in the function set_stack_heap() |
kevman | 0:38ceb79fef03 | 65 | * -ISR_STACK_SIZE can be overridden to be larger or smaller |
kevman | 0:38ceb79fef03 | 66 | * |
kevman | 0:38ceb79fef03 | 67 | * ARM Custom Memory layout notes: |
kevman | 0:38ceb79fef03 | 68 | * -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE |
kevman | 0:38ceb79fef03 | 69 | * -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE |
kevman | 0:38ceb79fef03 | 70 | * |
kevman | 0:38ceb79fef03 | 71 | */ |
kevman | 0:38ceb79fef03 | 72 | |
kevman | 0:38ceb79fef03 | 73 | #include <stdlib.h> |
kevman | 0:38ceb79fef03 | 74 | |
kevman | 0:38ceb79fef03 | 75 | #include "cmsis.h" |
kevman | 0:38ceb79fef03 | 76 | #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 77 | #include "mbed_boot.h" |
kevman | 0:38ceb79fef03 | 78 | |
kevman | 0:38ceb79fef03 | 79 | int main(void); |
kevman | 0:38ceb79fef03 | 80 | static void mbed_cpy_nvic(void); |
kevman | 0:38ceb79fef03 | 81 | |
kevman | 0:38ceb79fef03 | 82 | /* Stack limits */ |
kevman | 0:38ceb79fef03 | 83 | unsigned char *mbed_stack_isr_start = 0; |
kevman | 0:38ceb79fef03 | 84 | uint32_t mbed_stack_isr_size = 0; |
kevman | 0:38ceb79fef03 | 85 | |
kevman | 0:38ceb79fef03 | 86 | void mbed_init(void) |
kevman | 0:38ceb79fef03 | 87 | { |
kevman | 0:38ceb79fef03 | 88 | mbed_cpy_nvic(); |
kevman | 0:38ceb79fef03 | 89 | mbed_sdk_init(); |
kevman | 0:38ceb79fef03 | 90 | mbed_rtos_init(); |
kevman | 0:38ceb79fef03 | 91 | } |
kevman | 0:38ceb79fef03 | 92 | |
kevman | 0:38ceb79fef03 | 93 | void mbed_start(void) |
kevman | 0:38ceb79fef03 | 94 | { |
kevman | 0:38ceb79fef03 | 95 | mbed_toolchain_init(); |
kevman | 0:38ceb79fef03 | 96 | mbed_main(); |
kevman | 0:38ceb79fef03 | 97 | main(); |
kevman | 0:38ceb79fef03 | 98 | } |
kevman | 0:38ceb79fef03 | 99 | |
kevman | 0:38ceb79fef03 | 100 | MBED_WEAK void mbed_sdk_init(void) |
kevman | 0:38ceb79fef03 | 101 | { |
kevman | 0:38ceb79fef03 | 102 | // Nothing by default |
kevman | 0:38ceb79fef03 | 103 | } |
kevman | 0:38ceb79fef03 | 104 | |
kevman | 0:38ceb79fef03 | 105 | MBED_WEAK void software_init_hook_rtos() |
kevman | 0:38ceb79fef03 | 106 | { |
kevman | 0:38ceb79fef03 | 107 | // Nothing by default |
kevman | 0:38ceb79fef03 | 108 | } |
kevman | 0:38ceb79fef03 | 109 | |
kevman | 0:38ceb79fef03 | 110 | MBED_WEAK void mbed_main(void) |
kevman | 0:38ceb79fef03 | 111 | { |
kevman | 0:38ceb79fef03 | 112 | // Nothing by default |
kevman | 0:38ceb79fef03 | 113 | } |
kevman | 0:38ceb79fef03 | 114 | |
kevman | 0:38ceb79fef03 | 115 | static void mbed_cpy_nvic(void) |
kevman | 0:38ceb79fef03 | 116 | { |
kevman | 0:38ceb79fef03 | 117 | /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have |
kevman | 0:38ceb79fef03 | 118 | VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is |
kevman | 0:38ceb79fef03 | 119 | responsible for correctly handling the vectors. |
kevman | 0:38ceb79fef03 | 120 | */ |
kevman | 0:38ceb79fef03 | 121 | #if !defined(__CORTEX_M0) && !defined(__CORTEX_A9) |
kevman | 0:38ceb79fef03 | 122 | #ifdef NVIC_RAM_VECTOR_ADDRESS |
kevman | 0:38ceb79fef03 | 123 | uint32_t *old_vectors = (uint32_t *)SCB->VTOR; |
kevman | 0:38ceb79fef03 | 124 | uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; |
kevman | 0:38ceb79fef03 | 125 | for (int i = 0; i < NVIC_NUM_VECTORS; i++) { |
kevman | 0:38ceb79fef03 | 126 | vectors[i] = old_vectors[i]; |
kevman | 0:38ceb79fef03 | 127 | } |
kevman | 0:38ceb79fef03 | 128 | SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; |
kevman | 0:38ceb79fef03 | 129 | #endif /* NVIC_RAM_VECTOR_ADDRESS */ |
kevman | 0:38ceb79fef03 | 130 | #endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */ |
kevman | 0:38ceb79fef03 | 131 | } |