Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_sdk_boot.c Source File

mbed_sdk_boot.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "mbed_toolchain.h"
00019 #include <stdlib.h>
00020 #include <stdint.h>
00021 #include "cmsis.h"
00022 #include "hal/us_ticker_api.h"
00023 
00024 /* This startup is for mbed 2 baremetal. There is no config for RTOS for mbed 2,
00025  * therefore we protect this file with MBED_CONF_RTOS_PRESENT
00026  * Note: The new consolidated started for mbed OS is in rtos/mbed_boot code file.
00027  */
00028 #if !defined(MBED_CONF_RTOS_PRESENT)
00029 
00030 /* mbed_main is a function that is called before main()
00031  * mbed_sdk_init() is also a function that is called before main(), but unlike
00032  * mbed_main(), it is not meant for user code, but for the SDK itself to perform
00033  * initializations before main() is called.
00034  */
00035 MBED_WEAK void mbed_main(void)
00036 {
00037 
00038 }
00039 
00040 /* This function can be implemented by the target to perform higher level target initialization
00041  */
00042 MBED_WEAK void mbed_sdk_init(void)
00043 {
00044 
00045 }
00046 
00047 MBED_WEAK void software_init_hook_rtos()
00048 {
00049     // Nothing by default
00050 }
00051 
00052 void mbed_copy_nvic(void)
00053 {
00054     /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have
00055     VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is
00056     responsible for correctly handling the vectors.
00057     */
00058 #if !defined(__CORTEX_M0) && !defined(__CORTEX_A9)
00059 #ifdef NVIC_RAM_VECTOR_ADDRESS
00060     uint32_t *old_vectors = (uint32_t *)SCB->VTOR;
00061     uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
00062     for (int i = 0; i < NVIC_NUM_VECTORS; i++) {
00063         vectors[i] = old_vectors[i];
00064     }
00065     SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
00066 #endif /* NVIC_RAM_VECTOR_ADDRESS */
00067 #endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */
00068 }
00069 
00070 /* Toolchain specific main code */
00071 
00072 #if defined (__ARMCC_VERSION)
00073 
00074 int $Super$$main(void);
00075 
00076 int $Sub$$main(void)
00077 {
00078     mbed_main();
00079     mbed_error_initialize();
00080     return $Super$$main();
00081 }
00082 
00083 void _platform_post_stackheap_init(void)
00084 {
00085     mbed_copy_nvic();
00086     mbed_sdk_init();
00087 #if DEVICE_USTICKER && MBED_CONF_TARGET_INIT_US_TICKER_AT_BOOT
00088     us_ticker_init();
00089 #endif
00090 }
00091 //Define an empty os_cb_sections to remove a RTX warning when building with no RTOS due
00092 //to the --keep=os_cb_sections linker option
00093 const uint32_t os_cb_sections[] __attribute__((section(".rodata"))) = {};
00094 
00095 #elif defined (__GNUC__)
00096 
00097 extern int __real_main(void);
00098 
00099 void software_init_hook(void)
00100 {
00101     mbed_copy_nvic();
00102     mbed_sdk_init();
00103 #if DEVICE_USTICKER && MBED_CONF_TARGET_INIT_US_TICKER_AT_BOOT
00104     us_ticker_init();
00105 #endif
00106     software_init_hook_rtos();
00107 }
00108 
00109 
00110 int __wrap_main(void)
00111 {
00112     mbed_main();
00113     mbed_error_initialize();
00114     return __real_main();
00115 }
00116 
00117 #elif defined (__ICCARM__)
00118 
00119 int __low_level_init(void)
00120 {
00121     mbed_copy_nvic();
00122 #if DEVICE_USTICKER && MBED_CONF_TARGET_INIT_US_TICKER_AT_BOOT
00123     us_ticker_init();
00124 #endif
00125     return 1;
00126 }
00127 
00128 #endif
00129 
00130 #endif