mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
<>
Date:
Fri Sep 30 16:49:46 2016 +0100
Revision:
127:25aea2a3f4e3
Parent:
122:f9eeca106725
Release 127 of the mbed library

Ports for Upcoming Targets

2669: Added u-blox C029 target https://github.com/ARMmbed/mbed-os/pull/2669
2707: [EFM32] Add IAR support for remaining Silicon Labs targets https://github.com/ARMmbed/mbed-os/pull/2707
2819: MultiTech xDot platform support - 09.26.2016 https://github.com/ARMmbed/mbed-os/pull/2819
2827: include MultiTech xDot in mbed 5 releases https://github.com/ARMmbed/mbed-os/pull/2827

Fixes and Changes

2522: Add CThunk for CM7 https://github.com/ARMmbed/mbed-os/pull/2522
2518: Enable uvisor on Beetle https://github.com/ARMmbed/mbed-os/pull/2518
2571: STM32F7 - Add asynchronous serial https://github.com/ARMmbed/mbed-os/pull/2571
2616: STM32F3xx - Add Serial Flow Control pins + enable it https://github.com/ARMmbed/mbed-os/pull/2616
2619: NUCLEO_L152RE - Add Serial Flow Control https://github.com/ARMmbed/mbed-os/pull/2619
2620: NUCLEO_F429ZI - Add SERIAL_FC macro https://github.com/ARMmbed/mbed-os/pull/2620
2666: [EFM32] Microsecond ticker optimization https://github.com/ARMmbed/mbed-os/pull/2666
2681: STM32F0xx - Add support of ADC internal channels https://github.com/ARMmbed/mbed-os/pull/2681
2687: [NRF5] Add fs_data symbol in data secton for gcc https://github.com/ARMmbed/mbed-os/pull/2687
2696: Add device_has to all nrf51 devices https://github.com/ARMmbed/mbed-os/pull/2696
2703: TARGET_NRF5: Changed 'serial_baud' implementation to support special baud rates. https://github.com/ARMmbed/mbed-os/pull/2703
2704: DISCO_L476VG: add SPI nicknames https://github.com/ARMmbed/mbed-os/pull/2704
2723: KSDK serial_api.c: Fix assertion error for ParityEven https://github.com/ARMmbed/mbed-os/pull/2723
2463: [STM32L0] Add asynchronous serial https://github.com/ARMmbed/mbed-os/pull/2463
2572: Fix STM32F407VG target name and LPC11U6X linker errors https://github.com/ARMmbed/mbed-os/pull/2572
2698: DELTA_DFBM_NQ620 target https://github.com/ARMmbed/mbed-os/pull/2698
2542: Dev spi asynch stm32f4 https://github.com/ARMmbed/mbed-os/pull/2542
2650: STM32F3 - Add low power timer https://github.com/ARMmbed/mbed-os/pull/2650
2415: [STM32F0] Add asynchronous serial https://github.com/ARMmbed/mbed-os/pull/2415
2585: Added support for ADC only pins in LPC43xx https://github.com/ARMmbed/mbed-os/pull/2585
2622: [STM32F4] Add asynchronous I2C https://github.com/ARMmbed/mbed-os/pull/2622
2719: Updated ARM linker scripts for Kinetis platforms that use SDK 2.0 https://github.com/ARMmbed/mbed-os/pull/2719
2728: Added ethernet and enabled IPV4 feature for the EVK-ODIN-W2/C029 target https://github.com/ARMmbed/mbed-os/pull/2728
2747: [LPC11U68] Fix pin interrupt select offset https://github.com/ARMmbed/mbed-os/pull/2747
2751: STM32L0xx - Add Serial Flow Control https://github.com/ARMmbed/mbed-os/pull/2751
2753: [NUCLEO_F767ZI] Add CAN capability https://github.com/ARMmbed/mbed-os/pull/2753
2759: STM32F0 - Add low power timer https://github.com/ARMmbed/mbed-os/pull/2759
2763: STM32L1 - Add low power timer https://github.com/ARMmbed/mbed-os/pull/2763
2764: STM32L4 - Add low power timer https://github.com/ARMmbed/mbed-os/pull/2764
2771: STM32L4 - Update deepsleep implementation https://github.com/ARMmbed/mbed-os/pull/2771
2775: Update KSDK SDHC driver for K64F & K66F https://github.com/ARMmbed/mbed-os/pull/2775
2792: [NUCLEO_F303ZE] MBED-OS5 capability https://github.com/ARMmbed/mbed-os/pull/2792
2762: STM32L0 - Add low power timer https://github.com/ARMmbed/mbed-os/pull/2762
2761: STM32F7 - Add low power timer https://github.com/ARMmbed/mbed-os/pull/2761

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 98:8ab26030e058 1 /* General C++ Object Thunking class
Kojto 98:8ab26030e058 2 *
Kojto 98:8ab26030e058 3 * - allows direct callbacks to non-static C++ class functions
Kojto 98:8ab26030e058 4 * - keeps track for the corresponding class instance
Kojto 98:8ab26030e058 5 * - supports an optional context parameter for the called function
Kojto 98:8ab26030e058 6 * - ideally suited for class object receiving interrupts (NVIC_SetVector)
Kojto 98:8ab26030e058 7 *
Kojto 98:8ab26030e058 8 * Copyright (c) 2014-2015 ARM Limited
Kojto 98:8ab26030e058 9 *
Kojto 98:8ab26030e058 10 * Licensed under the Apache License, Version 2.0 (the "License");
Kojto 98:8ab26030e058 11 * you may not use this file except in compliance with the License.
Kojto 98:8ab26030e058 12 * You may obtain a copy of the License at
Kojto 98:8ab26030e058 13 *
Kojto 98:8ab26030e058 14 * http://www.apache.org/licenses/LICENSE-2.0
Kojto 98:8ab26030e058 15 *
Kojto 98:8ab26030e058 16 * Unless required by applicable law or agreed to in writing, software
Kojto 98:8ab26030e058 17 * distributed under the License is distributed on an "AS IS" BASIS,
Kojto 98:8ab26030e058 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Kojto 98:8ab26030e058 19 * See the License for the specific language governing permissions and
Kojto 98:8ab26030e058 20 * limitations under the License.
Kojto 98:8ab26030e058 21 */
Kojto 122:f9eeca106725 22
Kojto 122:f9eeca106725 23 /* General C++ Object Thunking class
Kojto 122:f9eeca106725 24 *
Kojto 122:f9eeca106725 25 * - allows direct callbacks to non-static C++ class functions
Kojto 122:f9eeca106725 26 * - keeps track for the corresponding class instance
Kojto 122:f9eeca106725 27 * - supports an optional context parameter for the called function
Kojto 122:f9eeca106725 28 * - ideally suited for class object receiving interrupts (NVIC_SetVector)
Kojto 122:f9eeca106725 29 */
Kojto 122:f9eeca106725 30
Kojto 98:8ab26030e058 31 #ifndef __CTHUNK_H__
Kojto 98:8ab26030e058 32 #define __CTHUNK_H__
Kojto 98:8ab26030e058 33
Kojto 98:8ab26030e058 34 #define CTHUNK_ADDRESS 1
<> 127:25aea2a3f4e3 35 #define CTHUNK_VARIABLES volatile uint32_t code[2]
Kojto 98:8ab26030e058 36
<> 127:25aea2a3f4e3 37 #if (defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_M7) || defined(__CORTEX_A9))
Kojto 98:8ab26030e058 38 /**
<> 127:25aea2a3f4e3 39 * CTHUNK disassembly for Cortex-M3/M4/M7/A9 (thumb2):
<> 127:25aea2a3f4e3 40 * * adr r0, #4
<> 127:25aea2a3f4e3 41 * * ldm r0, {r0, r1, r2, pc}
Kojto 98:8ab26030e058 42 *
Kojto 98:8ab26030e058 43 * This instruction loads the arguments for the static thunking function to r0-r2, and
Kojto 98:8ab26030e058 44 * branches to that function by loading its address into PC.
Kojto 98:8ab26030e058 45 *
Kojto 98:8ab26030e058 46 * This is safe for both regular calling and interrupt calling, since it only touches scratch registers
Kojto 98:8ab26030e058 47 * which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
Kojto 98:8ab26030e058 48 */
<> 127:25aea2a3f4e3 49 #define CTHUNK_ASSIGMENT do { \
<> 127:25aea2a3f4e3 50 m_thunk.code[0] = 0xE890A001; \
<> 127:25aea2a3f4e3 51 m_thunk.code[1] = 0x00008007; \
<> 127:25aea2a3f4e3 52 } while (0)
Kojto 98:8ab26030e058 53
<> 127:25aea2a3f4e3 54 #elif (defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0))
Kojto 98:8ab26030e058 55 /*
<> 127:25aea2a3f4e3 56 * CTHUNK disassembly for Cortex M0/M0+ (thumb):
<> 127:25aea2a3f4e3 57 * * adr r0, #4
<> 127:25aea2a3f4e3 58 * * ldm r0, {r0, r1, r2, r3}
<> 127:25aea2a3f4e3 59 * * bx r3
Kojto 98:8ab26030e058 60 */
Kojto 98:8ab26030e058 61 #define CTHUNK_ASSIGMENT do { \
<> 127:25aea2a3f4e3 62 m_thunk.code[0] = 0xC80FA001; \
<> 127:25aea2a3f4e3 63 m_thunk.code[1] = 0x00004718; \
Kojto 98:8ab26030e058 64 } while (0)
Kojto 98:8ab26030e058 65
Kojto 98:8ab26030e058 66 #else
Kojto 98:8ab26030e058 67 #error "Target is not currently suported."
Kojto 98:8ab26030e058 68 #endif
Kojto 98:8ab26030e058 69
Kojto 98:8ab26030e058 70 /* IRQ/Exception compatible thunk entry function */
Kojto 98:8ab26030e058 71 typedef void (*CThunkEntry)(void);
Kojto 98:8ab26030e058 72
Kojto 122:f9eeca106725 73 /**
Kojto 122:f9eeca106725 74 * Class for created a pointer with data bound to it
Kojto 122:f9eeca106725 75 *
Kojto 122:f9eeca106725 76 * @Note Synchronization level: Not protected
Kojto 122:f9eeca106725 77 */
Kojto 98:8ab26030e058 78 template<class T>
Kojto 98:8ab26030e058 79 class CThunk
Kojto 98:8ab26030e058 80 {
Kojto 98:8ab26030e058 81 public:
Kojto 98:8ab26030e058 82 typedef void (T::*CCallbackSimple)(void);
Kojto 98:8ab26030e058 83 typedef void (T::*CCallback)(void* context);
Kojto 98:8ab26030e058 84
Kojto 98:8ab26030e058 85 inline CThunk(T *instance)
Kojto 98:8ab26030e058 86 {
Kojto 98:8ab26030e058 87 init(instance, NULL, NULL);
Kojto 98:8ab26030e058 88 }
Kojto 98:8ab26030e058 89
Kojto 98:8ab26030e058 90 inline CThunk(T *instance, CCallback callback)
Kojto 98:8ab26030e058 91 {
Kojto 98:8ab26030e058 92 init(instance, callback, NULL);
Kojto 98:8ab26030e058 93 }
Kojto 98:8ab26030e058 94
Kojto 98:8ab26030e058 95 ~CThunk() {
Kojto 98:8ab26030e058 96
Kojto 98:8ab26030e058 97 }
Kojto 98:8ab26030e058 98
Kojto 98:8ab26030e058 99 inline CThunk(T *instance, CCallbackSimple callback)
Kojto 98:8ab26030e058 100 {
Kojto 98:8ab26030e058 101 init(instance, (CCallback)callback, NULL);
Kojto 98:8ab26030e058 102 }
Kojto 98:8ab26030e058 103
Kojto 98:8ab26030e058 104 inline CThunk(T &instance, CCallback callback)
Kojto 98:8ab26030e058 105 {
Kojto 98:8ab26030e058 106 init(instance, callback, NULL);
Kojto 98:8ab26030e058 107 }
Kojto 98:8ab26030e058 108
Kojto 98:8ab26030e058 109 inline CThunk(T &instance, CCallbackSimple callback)
Kojto 98:8ab26030e058 110 {
Kojto 98:8ab26030e058 111 init(instance, (CCallback)callback, NULL);
Kojto 98:8ab26030e058 112 }
Kojto 98:8ab26030e058 113
Kojto 98:8ab26030e058 114 inline CThunk(T &instance, CCallback callback, void* context)
Kojto 98:8ab26030e058 115 {
Kojto 98:8ab26030e058 116 init(instance, callback, context);
Kojto 98:8ab26030e058 117 }
Kojto 98:8ab26030e058 118
Kojto 98:8ab26030e058 119 inline void callback(CCallback callback)
Kojto 98:8ab26030e058 120 {
Kojto 98:8ab26030e058 121 m_callback = callback;
Kojto 98:8ab26030e058 122 }
Kojto 98:8ab26030e058 123
Kojto 98:8ab26030e058 124 inline void callback(CCallbackSimple callback)
Kojto 98:8ab26030e058 125 {
Kojto 98:8ab26030e058 126 m_callback = (CCallback)callback;
Kojto 98:8ab26030e058 127 }
Kojto 98:8ab26030e058 128
Kojto 98:8ab26030e058 129 inline void context(void* context)
Kojto 98:8ab26030e058 130 {
Kojto 98:8ab26030e058 131 m_thunk.context = (uint32_t)context;
Kojto 98:8ab26030e058 132 }
Kojto 98:8ab26030e058 133
Kojto 98:8ab26030e058 134 inline void context(uint32_t context)
Kojto 98:8ab26030e058 135 {
Kojto 98:8ab26030e058 136 m_thunk.context = context;
Kojto 98:8ab26030e058 137 }
Kojto 98:8ab26030e058 138
Kojto 98:8ab26030e058 139 inline uint32_t entry(void)
Kojto 98:8ab26030e058 140 {
Kojto 98:8ab26030e058 141 return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
Kojto 98:8ab26030e058 142 }
Kojto 98:8ab26030e058 143
Kojto 98:8ab26030e058 144 /* get thunk entry point for connecting rhunk to an IRQ table */
Kojto 98:8ab26030e058 145 inline operator CThunkEntry(void)
Kojto 98:8ab26030e058 146 {
Kojto 98:8ab26030e058 147 return (CThunkEntry)entry();
Kojto 98:8ab26030e058 148 }
Kojto 98:8ab26030e058 149
Kojto 98:8ab26030e058 150 /* get thunk entry point for connecting rhunk to an IRQ table */
Kojto 98:8ab26030e058 151 inline operator uint32_t(void)
Kojto 98:8ab26030e058 152 {
Kojto 98:8ab26030e058 153 return entry();
Kojto 98:8ab26030e058 154 }
Kojto 98:8ab26030e058 155
Kojto 98:8ab26030e058 156 /* simple test function */
Kojto 98:8ab26030e058 157 inline void call(void)
Kojto 98:8ab26030e058 158 {
Kojto 98:8ab26030e058 159 (((CThunkEntry)(entry()))());
Kojto 98:8ab26030e058 160 }
Kojto 98:8ab26030e058 161
Kojto 98:8ab26030e058 162 private:
Kojto 98:8ab26030e058 163 T* m_instance;
Kojto 98:8ab26030e058 164 volatile CCallback m_callback;
Kojto 98:8ab26030e058 165
Kojto 98:8ab26030e058 166 // TODO: this needs proper fix, to refactor toolchain header file and all its use
Kojto 98:8ab26030e058 167 // PACKED there is not defined properly for IAR
Kojto 98:8ab26030e058 168 #if defined (__ICCARM__)
Kojto 98:8ab26030e058 169 typedef __packed struct
Kojto 98:8ab26030e058 170 {
Kojto 98:8ab26030e058 171 CTHUNK_VARIABLES;
Kojto 98:8ab26030e058 172 volatile uint32_t instance;
Kojto 98:8ab26030e058 173 volatile uint32_t context;
Kojto 98:8ab26030e058 174 volatile uint32_t callback;
Kojto 98:8ab26030e058 175 volatile uint32_t trampoline;
Kojto 98:8ab26030e058 176 } CThunkTrampoline;
Kojto 98:8ab26030e058 177 #else
Kojto 98:8ab26030e058 178 typedef struct
Kojto 98:8ab26030e058 179 {
Kojto 98:8ab26030e058 180 CTHUNK_VARIABLES;
Kojto 98:8ab26030e058 181 volatile uint32_t instance;
Kojto 98:8ab26030e058 182 volatile uint32_t context;
Kojto 98:8ab26030e058 183 volatile uint32_t callback;
Kojto 98:8ab26030e058 184 volatile uint32_t trampoline;
Kojto 98:8ab26030e058 185 } __attribute__((__packed__)) CThunkTrampoline;
Kojto 98:8ab26030e058 186 #endif
Kojto 98:8ab26030e058 187
Kojto 98:8ab26030e058 188 static void trampoline(T* instance, void* context, CCallback* callback)
Kojto 98:8ab26030e058 189 {
Kojto 98:8ab26030e058 190 if(instance && *callback) {
Kojto 98:8ab26030e058 191 (static_cast<T*>(instance)->**callback)(context);
Kojto 98:8ab26030e058 192 }
Kojto 98:8ab26030e058 193 }
Kojto 98:8ab26030e058 194
Kojto 98:8ab26030e058 195 volatile CThunkTrampoline m_thunk;
Kojto 98:8ab26030e058 196
Kojto 98:8ab26030e058 197 inline void init(T *instance, CCallback callback, void* context)
Kojto 98:8ab26030e058 198 {
Kojto 98:8ab26030e058 199 /* remember callback - need to add this level of redirection
Kojto 98:8ab26030e058 200 as pointer size for member functions differs between platforms */
Kojto 98:8ab26030e058 201 m_callback = callback;
Kojto 98:8ab26030e058 202
Kojto 98:8ab26030e058 203 /* populate thunking trampoline */
Kojto 98:8ab26030e058 204 CTHUNK_ASSIGMENT;
Kojto 98:8ab26030e058 205 m_thunk.context = (uint32_t)context;
Kojto 98:8ab26030e058 206 m_thunk.instance = (uint32_t)instance;
Kojto 98:8ab26030e058 207 m_thunk.callback = (uint32_t)&m_callback;
Kojto 98:8ab26030e058 208 m_thunk.trampoline = (uint32_t)&trampoline;
Kojto 98:8ab26030e058 209
Kojto 120:7c328cabac7e 210 #if defined(__CORTEX_A9)
Kojto 120:7c328cabac7e 211 /* Data cache clean */
Kojto 120:7c328cabac7e 212 /* Cache control */
Kojto 120:7c328cabac7e 213 {
Kojto 120:7c328cabac7e 214 uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
Kojto 120:7c328cabac7e 215 uint32_t end_addr = (uint32_t)&m_thunk + sizeof(m_thunk);
Kojto 120:7c328cabac7e 216 uint32_t addr;
Kojto 120:7c328cabac7e 217
Kojto 120:7c328cabac7e 218 /* Data cache clean and invalid */
Kojto 120:7c328cabac7e 219 for (addr = start_addr; addr < end_addr; addr += 0x20) {
Kojto 120:7c328cabac7e 220 __v7_clean_inv_dcache_mva((void *)addr);
Kojto 120:7c328cabac7e 221 }
Kojto 120:7c328cabac7e 222 /* Instruction cache invalid */
Kojto 120:7c328cabac7e 223 __v7_inv_icache_all();
Kojto 120:7c328cabac7e 224 __ca9u_inv_tlb_all();
Kojto 120:7c328cabac7e 225 __v7_inv_btac();
Kojto 120:7c328cabac7e 226 }
Kojto 120:7c328cabac7e 227 #endif
<> 127:25aea2a3f4e3 228 #if defined(__CORTEX_M7)
<> 127:25aea2a3f4e3 229 /* Data cache clean and invalid */
<> 127:25aea2a3f4e3 230 SCB_CleanInvalidateDCache();
<> 127:25aea2a3f4e3 231
<> 127:25aea2a3f4e3 232 /* Instruction cache invalid */
<> 127:25aea2a3f4e3 233 SCB_InvalidateICache();
<> 127:25aea2a3f4e3 234 #endif
Kojto 98:8ab26030e058 235 __ISB();
Kojto 98:8ab26030e058 236 __DSB();
Kojto 98:8ab26030e058 237 }
Kojto 98:8ab26030e058 238 };
Kojto 98:8ab26030e058 239
Kojto 98:8ab26030e058 240 #endif/*__CTHUNK_H__*/