RTC auf true
rtos/TARGET_CORTEX/TOOLCHAIN_IAR/mbed_boot_iar.c@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2018-2018 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | |
kevman | 0:38ceb79fef03 | 17 | #include "cmsis.h" |
kevman | 0:38ceb79fef03 | 18 | #include "mbed_error.h" |
kevman | 0:38ceb79fef03 | 19 | #include "mbed_boot.h" |
kevman | 0:38ceb79fef03 | 20 | #if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ >= 8000000) |
kevman | 0:38ceb79fef03 | 21 | #include <DLib_Threads.h> |
kevman | 0:38ceb79fef03 | 22 | #endif |
kevman | 0:38ceb79fef03 | 23 | #include "mbed_rtos_storage.h" |
kevman | 0:38ceb79fef03 | 24 | #include "cmsis_os2.h" |
kevman | 0:38ceb79fef03 | 25 | |
kevman | 0:38ceb79fef03 | 26 | /* Defined by linker script */ |
kevman | 0:38ceb79fef03 | 27 | #pragma section="CSTACK" |
kevman | 0:38ceb79fef03 | 28 | #pragma section="HEAP" |
kevman | 0:38ceb79fef03 | 29 | |
kevman | 0:38ceb79fef03 | 30 | extern void* __vector_table; |
kevman | 0:38ceb79fef03 | 31 | extern int __low_level_init(void); |
kevman | 0:38ceb79fef03 | 32 | extern void __iar_data_init3(void); |
kevman | 0:38ceb79fef03 | 33 | extern __weak void __iar_init_core(void); |
kevman | 0:38ceb79fef03 | 34 | extern __weak void __iar_init_vfp(void); |
kevman | 0:38ceb79fef03 | 35 | extern void __iar_dynamic_initialization(void); |
kevman | 0:38ceb79fef03 | 36 | |
kevman | 0:38ceb79fef03 | 37 | /* |
kevman | 0:38ceb79fef03 | 38 | * mbed entry point for the IAR toolchain |
kevman | 0:38ceb79fef03 | 39 | * |
kevman | 0:38ceb79fef03 | 40 | * Override __iar_program_start to run code before main. |
kevman | 0:38ceb79fef03 | 41 | * This is the first function called after the low level |
kevman | 0:38ceb79fef03 | 42 | * target initialization, so RAM has not been setup yet. |
kevman | 0:38ceb79fef03 | 43 | * |
kevman | 0:38ceb79fef03 | 44 | * Details on what this function are supposed to do can |
kevman | 0:38ceb79fef03 | 45 | * be found by looking at the IAR source for this file. |
kevman | 0:38ceb79fef03 | 46 | * |
kevman | 0:38ceb79fef03 | 47 | * IAR source files for ARM instruction set: |
kevman | 0:38ceb79fef03 | 48 | * <IAR>\arm\src\lib\arm\cstartup.s |
kevman | 0:38ceb79fef03 | 49 | * <IAR>\arm\src\lib\arm\cmain.s |
kevman | 0:38ceb79fef03 | 50 | * |
kevman | 0:38ceb79fef03 | 51 | * IAR source files for THUMB instruction set: |
kevman | 0:38ceb79fef03 | 52 | * <IAR>\arm\src\lib\thumb\cmain.s |
kevman | 0:38ceb79fef03 | 53 | * <IAR>\arm\src\lib\thumb\cstartup_M.s |
kevman | 0:38ceb79fef03 | 54 | */ |
kevman | 0:38ceb79fef03 | 55 | #pragma required=__vector_table |
kevman | 0:38ceb79fef03 | 56 | void __iar_program_start( void ) |
kevman | 0:38ceb79fef03 | 57 | { |
kevman | 0:38ceb79fef03 | 58 | /* the calls below are normally made in IAR cstartup */ |
kevman | 0:38ceb79fef03 | 59 | __iar_init_core(); |
kevman | 0:38ceb79fef03 | 60 | __iar_init_vfp(); |
kevman | 0:38ceb79fef03 | 61 | |
kevman | 0:38ceb79fef03 | 62 | /* the calls below are normally made in IAR cmain |
kevman | 0:38ceb79fef03 | 63 | * |
kevman | 0:38ceb79fef03 | 64 | * The function "__low_level_init" is a user overrideable hook |
kevman | 0:38ceb79fef03 | 65 | * that does nothing by default. Returning zero means that |
kevman | 0:38ceb79fef03 | 66 | * ram initialization should be skipped. Skipping ram initialization |
kevman | 0:38ceb79fef03 | 67 | * is not allowed by mbed. |
kevman | 0:38ceb79fef03 | 68 | * |
kevman | 0:38ceb79fef03 | 69 | * The function "__iar_data_init3" is an IAR function which |
kevman | 0:38ceb79fef03 | 70 | * initializes ram. |
kevman | 0:38ceb79fef03 | 71 | * |
kevman | 0:38ceb79fef03 | 72 | */ |
kevman | 0:38ceb79fef03 | 73 | __low_level_init(); |
kevman | 0:38ceb79fef03 | 74 | __iar_data_init3(); |
kevman | 0:38ceb79fef03 | 75 | |
kevman | 0:38ceb79fef03 | 76 | /* mbed specific code */ |
kevman | 0:38ceb79fef03 | 77 | mbed_heap_start = (unsigned char*)__section_begin("HEAP"); |
kevman | 0:38ceb79fef03 | 78 | mbed_heap_size = (uint32_t)__section_size("HEAP"); |
kevman | 0:38ceb79fef03 | 79 | |
kevman | 0:38ceb79fef03 | 80 | mbed_stack_isr_start = (unsigned char*)__section_begin("CSTACK"); |
kevman | 0:38ceb79fef03 | 81 | mbed_stack_isr_size = (uint32_t)__section_size("CSTACK"); |
kevman | 0:38ceb79fef03 | 82 | |
kevman | 0:38ceb79fef03 | 83 | mbed_init(); |
kevman | 0:38ceb79fef03 | 84 | mbed_rtos_start(); |
kevman | 0:38ceb79fef03 | 85 | } |
kevman | 0:38ceb79fef03 | 86 | |
kevman | 0:38ceb79fef03 | 87 | void mbed_toolchain_init(void) |
kevman | 0:38ceb79fef03 | 88 | { |
kevman | 0:38ceb79fef03 | 89 | #if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ >= 8000000) |
kevman | 0:38ceb79fef03 | 90 | __iar_Initlocks(); |
kevman | 0:38ceb79fef03 | 91 | #endif |
kevman | 0:38ceb79fef03 | 92 | |
kevman | 0:38ceb79fef03 | 93 | /* Run the C++ global object constructors */ |
kevman | 0:38ceb79fef03 | 94 | __iar_dynamic_initialization(); |
kevman | 0:38ceb79fef03 | 95 | } |
kevman | 0:38ceb79fef03 | 96 | |
kevman | 0:38ceb79fef03 | 97 | /* Thread safety */ |
kevman | 0:38ceb79fef03 | 98 | static osMutexId_t std_mutex_id_sys[_MAX_LOCK] = {0}; |
kevman | 0:38ceb79fef03 | 99 | static mbed_rtos_storage_mutex_t std_mutex_sys[_MAX_LOCK] = {0}; |
kevman | 0:38ceb79fef03 | 100 | #define _FOPEN_MAX 10 |
kevman | 0:38ceb79fef03 | 101 | static osMutexId_t std_mutex_id_file[_FOPEN_MAX] = {0}; |
kevman | 0:38ceb79fef03 | 102 | static mbed_rtos_storage_mutex_t std_mutex_file[_FOPEN_MAX] = {0}; |
kevman | 0:38ceb79fef03 | 103 | |
kevman | 0:38ceb79fef03 | 104 | void __iar_system_Mtxinit(__iar_Rmtx *mutex) /* Initialize a system lock */ |
kevman | 0:38ceb79fef03 | 105 | { |
kevman | 0:38ceb79fef03 | 106 | osMutexAttr_t attr; |
kevman | 0:38ceb79fef03 | 107 | uint32_t index; |
kevman | 0:38ceb79fef03 | 108 | for (index = 0; index < _MAX_LOCK; index++) { |
kevman | 0:38ceb79fef03 | 109 | if (0 == std_mutex_id_sys[index]) { |
kevman | 0:38ceb79fef03 | 110 | attr.name = "system_mutex"; |
kevman | 0:38ceb79fef03 | 111 | attr.cb_mem = &std_mutex_sys[index]; |
kevman | 0:38ceb79fef03 | 112 | attr.cb_size = sizeof(std_mutex_sys[index]); |
kevman | 0:38ceb79fef03 | 113 | attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; |
kevman | 0:38ceb79fef03 | 114 | std_mutex_id_sys[index] = osMutexNew(&attr); |
kevman | 0:38ceb79fef03 | 115 | *mutex = (__iar_Rmtx*)&std_mutex_id_sys[index]; |
kevman | 0:38ceb79fef03 | 116 | return; |
kevman | 0:38ceb79fef03 | 117 | } |
kevman | 0:38ceb79fef03 | 118 | } |
kevman | 0:38ceb79fef03 | 119 | |
kevman | 0:38ceb79fef03 | 120 | /* This should never happen */ |
kevman | 0:38ceb79fef03 | 121 | error("Not enough mutexes\n"); |
kevman | 0:38ceb79fef03 | 122 | } |
kevman | 0:38ceb79fef03 | 123 | |
kevman | 0:38ceb79fef03 | 124 | void __iar_system_Mtxdst(__iar_Rmtx *mutex) /* Destroy a system lock */ |
kevman | 0:38ceb79fef03 | 125 | { |
kevman | 0:38ceb79fef03 | 126 | osMutexDelete(*(osMutexId_t*)*mutex); |
kevman | 0:38ceb79fef03 | 127 | *mutex = 0; |
kevman | 0:38ceb79fef03 | 128 | } |
kevman | 0:38ceb79fef03 | 129 | |
kevman | 0:38ceb79fef03 | 130 | void __iar_system_Mtxlock(__iar_Rmtx *mutex) /* Lock a system lock */ |
kevman | 0:38ceb79fef03 | 131 | { |
kevman | 0:38ceb79fef03 | 132 | osMutexAcquire(*(osMutexId_t*)*mutex, osWaitForever); |
kevman | 0:38ceb79fef03 | 133 | } |
kevman | 0:38ceb79fef03 | 134 | |
kevman | 0:38ceb79fef03 | 135 | void __iar_system_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a system lock */ |
kevman | 0:38ceb79fef03 | 136 | { |
kevman | 0:38ceb79fef03 | 137 | osMutexRelease(*(osMutexId_t*)*mutex); |
kevman | 0:38ceb79fef03 | 138 | } |
kevman | 0:38ceb79fef03 | 139 | |
kevman | 0:38ceb79fef03 | 140 | void __iar_file_Mtxinit(__iar_Rmtx *mutex) /* Initialize a file lock */ |
kevman | 0:38ceb79fef03 | 141 | { |
kevman | 0:38ceb79fef03 | 142 | osMutexAttr_t attr; |
kevman | 0:38ceb79fef03 | 143 | uint32_t index; |
kevman | 0:38ceb79fef03 | 144 | for (index = 0; index < _FOPEN_MAX; index++) { |
kevman | 0:38ceb79fef03 | 145 | if (0 == std_mutex_id_file[index]) { |
kevman | 0:38ceb79fef03 | 146 | attr.name = "file_mutex"; |
kevman | 0:38ceb79fef03 | 147 | attr.cb_mem = &std_mutex_file[index]; |
kevman | 0:38ceb79fef03 | 148 | attr.cb_size = sizeof(std_mutex_file[index]); |
kevman | 0:38ceb79fef03 | 149 | attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; |
kevman | 0:38ceb79fef03 | 150 | std_mutex_id_file[index] = osMutexNew(&attr); |
kevman | 0:38ceb79fef03 | 151 | *mutex = (__iar_Rmtx*)&std_mutex_id_file[index]; |
kevman | 0:38ceb79fef03 | 152 | return; |
kevman | 0:38ceb79fef03 | 153 | } |
kevman | 0:38ceb79fef03 | 154 | } |
kevman | 0:38ceb79fef03 | 155 | /* The variable _FOPEN_MAX needs to be increased */ |
kevman | 0:38ceb79fef03 | 156 | error("Not enough mutexes\n"); |
kevman | 0:38ceb79fef03 | 157 | } |
kevman | 0:38ceb79fef03 | 158 | |
kevman | 0:38ceb79fef03 | 159 | void __iar_file_Mtxdst(__iar_Rmtx *mutex) /* Destroy a file lock */ |
kevman | 0:38ceb79fef03 | 160 | { |
kevman | 0:38ceb79fef03 | 161 | osMutexDelete(*(osMutexId_t*)*mutex); |
kevman | 0:38ceb79fef03 | 162 | *mutex = 0; |
kevman | 0:38ceb79fef03 | 163 | } |
kevman | 0:38ceb79fef03 | 164 | |
kevman | 0:38ceb79fef03 | 165 | void __iar_file_Mtxlock(__iar_Rmtx *mutex) /* Lock a file lock */ |
kevman | 0:38ceb79fef03 | 166 | { |
kevman | 0:38ceb79fef03 | 167 | osMutexAcquire(*(osMutexId_t*)*mutex, osWaitForever); |
kevman | 0:38ceb79fef03 | 168 | } |
kevman | 0:38ceb79fef03 | 169 | |
kevman | 0:38ceb79fef03 | 170 | void __iar_file_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a file lock */ |
kevman | 0:38ceb79fef03 | 171 | { |
kevman | 0:38ceb79fef03 | 172 | osMutexRelease(*(osMutexId_t*)*mutex); |
kevman | 0:38ceb79fef03 | 173 | } |