Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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