inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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