Rtos API example

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