00

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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