Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

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