Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/platform/mbed_sdk_boot.c@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2017 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 5 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 6 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 7 | * |
marcozecchini | 0:9fca2b23d0ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 9 | * |
marcozecchini | 0:9fca2b23d0ba | 10 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 13 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 14 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 15 | */ |
marcozecchini | 0:9fca2b23d0ba | 16 | |
marcozecchini | 0:9fca2b23d0ba | 17 | #include "mbed_toolchain.h" |
marcozecchini | 0:9fca2b23d0ba | 18 | #include <stdlib.h> |
marcozecchini | 0:9fca2b23d0ba | 19 | #include <stdint.h> |
marcozecchini | 0:9fca2b23d0ba | 20 | #include "cmsis.h" |
marcozecchini | 0:9fca2b23d0ba | 21 | |
marcozecchini | 0:9fca2b23d0ba | 22 | /* This startup is for mbed 2 baremetal. There is no config for RTOS for mbed 2, |
marcozecchini | 0:9fca2b23d0ba | 23 | * therefore we protect this file with MBED_CONF_RTOS_PRESENT |
marcozecchini | 0:9fca2b23d0ba | 24 | * Note: The new consolidated started for mbed OS is in rtos/mbed_boot code file. |
marcozecchini | 0:9fca2b23d0ba | 25 | */ |
marcozecchini | 0:9fca2b23d0ba | 26 | #if !defined(MBED_CONF_RTOS_PRESENT) |
marcozecchini | 0:9fca2b23d0ba | 27 | |
marcozecchini | 0:9fca2b23d0ba | 28 | /* mbed_main is a function that is called before main() |
marcozecchini | 0:9fca2b23d0ba | 29 | * mbed_sdk_init() is also a function that is called before main(), but unlike |
marcozecchini | 0:9fca2b23d0ba | 30 | * mbed_main(), it is not meant for user code, but for the SDK itself to perform |
marcozecchini | 0:9fca2b23d0ba | 31 | * initializations before main() is called. |
marcozecchini | 0:9fca2b23d0ba | 32 | */ |
marcozecchini | 0:9fca2b23d0ba | 33 | MBED_WEAK void mbed_main(void) |
marcozecchini | 0:9fca2b23d0ba | 34 | { |
marcozecchini | 0:9fca2b23d0ba | 35 | |
marcozecchini | 0:9fca2b23d0ba | 36 | } |
marcozecchini | 0:9fca2b23d0ba | 37 | |
marcozecchini | 0:9fca2b23d0ba | 38 | /* This function can be implemented by the target to perform higher level target initialization |
marcozecchini | 0:9fca2b23d0ba | 39 | */ |
marcozecchini | 0:9fca2b23d0ba | 40 | MBED_WEAK void mbed_sdk_init(void) |
marcozecchini | 0:9fca2b23d0ba | 41 | { |
marcozecchini | 0:9fca2b23d0ba | 42 | |
marcozecchini | 0:9fca2b23d0ba | 43 | } |
marcozecchini | 0:9fca2b23d0ba | 44 | |
marcozecchini | 0:9fca2b23d0ba | 45 | MBED_WEAK void software_init_hook_rtos() |
marcozecchini | 0:9fca2b23d0ba | 46 | { |
marcozecchini | 0:9fca2b23d0ba | 47 | // Nothing by default |
marcozecchini | 0:9fca2b23d0ba | 48 | } |
marcozecchini | 0:9fca2b23d0ba | 49 | |
marcozecchini | 0:9fca2b23d0ba | 50 | void mbed_copy_nvic(void) |
marcozecchini | 0:9fca2b23d0ba | 51 | { |
marcozecchini | 0:9fca2b23d0ba | 52 | /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have |
marcozecchini | 0:9fca2b23d0ba | 53 | VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is |
marcozecchini | 0:9fca2b23d0ba | 54 | responsible for correctly handling the vectors. |
marcozecchini | 0:9fca2b23d0ba | 55 | */ |
marcozecchini | 0:9fca2b23d0ba | 56 | #if !defined(__CORTEX_M0) && !defined(__CORTEX_A9) |
marcozecchini | 0:9fca2b23d0ba | 57 | #ifdef NVIC_RAM_VECTOR_ADDRESS |
marcozecchini | 0:9fca2b23d0ba | 58 | uint32_t *old_vectors = (uint32_t *)SCB->VTOR; |
marcozecchini | 0:9fca2b23d0ba | 59 | uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; |
marcozecchini | 0:9fca2b23d0ba | 60 | for (int i = 0; i < NVIC_NUM_VECTORS; i++) { |
marcozecchini | 0:9fca2b23d0ba | 61 | vectors[i] = old_vectors[i]; |
marcozecchini | 0:9fca2b23d0ba | 62 | } |
marcozecchini | 0:9fca2b23d0ba | 63 | SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; |
marcozecchini | 0:9fca2b23d0ba | 64 | #endif /* NVIC_RAM_VECTOR_ADDRESS */ |
marcozecchini | 0:9fca2b23d0ba | 65 | #endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */ |
marcozecchini | 0:9fca2b23d0ba | 66 | } |
marcozecchini | 0:9fca2b23d0ba | 67 | |
marcozecchini | 0:9fca2b23d0ba | 68 | /* Toolchain specific main code */ |
marcozecchini | 0:9fca2b23d0ba | 69 | |
marcozecchini | 0:9fca2b23d0ba | 70 | #if defined (__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 5010060)) |
marcozecchini | 0:9fca2b23d0ba | 71 | |
marcozecchini | 0:9fca2b23d0ba | 72 | int $Super$$main(void); |
marcozecchini | 0:9fca2b23d0ba | 73 | |
marcozecchini | 0:9fca2b23d0ba | 74 | int $Sub$$main(void) |
marcozecchini | 0:9fca2b23d0ba | 75 | { |
marcozecchini | 0:9fca2b23d0ba | 76 | mbed_main(); |
marcozecchini | 0:9fca2b23d0ba | 77 | return $Super$$main(); |
marcozecchini | 0:9fca2b23d0ba | 78 | } |
marcozecchini | 0:9fca2b23d0ba | 79 | |
marcozecchini | 0:9fca2b23d0ba | 80 | void _platform_post_stackheap_init(void) |
marcozecchini | 0:9fca2b23d0ba | 81 | { |
marcozecchini | 0:9fca2b23d0ba | 82 | mbed_copy_nvic(); |
marcozecchini | 0:9fca2b23d0ba | 83 | mbed_sdk_init(); |
marcozecchini | 0:9fca2b23d0ba | 84 | } |
marcozecchini | 0:9fca2b23d0ba | 85 | |
marcozecchini | 0:9fca2b23d0ba | 86 | #elif defined (__GNUC__) |
marcozecchini | 0:9fca2b23d0ba | 87 | |
marcozecchini | 0:9fca2b23d0ba | 88 | extern int __real_main(void); |
marcozecchini | 0:9fca2b23d0ba | 89 | |
marcozecchini | 0:9fca2b23d0ba | 90 | void software_init_hook(void) |
marcozecchini | 0:9fca2b23d0ba | 91 | { |
marcozecchini | 0:9fca2b23d0ba | 92 | mbed_copy_nvic(); |
marcozecchini | 0:9fca2b23d0ba | 93 | mbed_sdk_init(); |
marcozecchini | 0:9fca2b23d0ba | 94 | software_init_hook_rtos(); |
marcozecchini | 0:9fca2b23d0ba | 95 | } |
marcozecchini | 0:9fca2b23d0ba | 96 | |
marcozecchini | 0:9fca2b23d0ba | 97 | |
marcozecchini | 0:9fca2b23d0ba | 98 | int __wrap_main(void) |
marcozecchini | 0:9fca2b23d0ba | 99 | { |
marcozecchini | 0:9fca2b23d0ba | 100 | mbed_main(); |
marcozecchini | 0:9fca2b23d0ba | 101 | return __real_main(); |
marcozecchini | 0:9fca2b23d0ba | 102 | } |
marcozecchini | 0:9fca2b23d0ba | 103 | |
marcozecchini | 0:9fca2b23d0ba | 104 | #elif defined (__ICCARM__) |
marcozecchini | 0:9fca2b23d0ba | 105 | |
marcozecchini | 0:9fca2b23d0ba | 106 | int __low_level_init(void) |
marcozecchini | 0:9fca2b23d0ba | 107 | { |
marcozecchini | 0:9fca2b23d0ba | 108 | mbed_copy_nvic(); |
marcozecchini | 0:9fca2b23d0ba | 109 | return 1; |
marcozecchini | 0:9fca2b23d0ba | 110 | } |
marcozecchini | 0:9fca2b23d0ba | 111 | |
marcozecchini | 0:9fca2b23d0ba | 112 | #endif |
marcozecchini | 0:9fca2b23d0ba | 113 | |
marcozecchini | 0:9fca2b23d0ba | 114 | #endif |