![](/media/cache/profiles/ce7206100d5cf8e7bb691376c7d73526.jpg.50x50_q85.jpg)
An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
Utils/arch.cpp@62:86aaaf9fa55d, 2019-06-06 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Thu Jun 06 09:31:08 2019 +0200
- Revision:
- 62:86aaaf9fa55d
- Parent:
- 43:ec1b7aa823a6
Updated OLED lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut Tschemernjak | 11:e20b3c6c4a5c | 1 | /* |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 2 | * $Id: $ |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 3 | * This is an unpublished work copyright (c) 2019 HELIOS Software GmbH |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 4 | * 30827 Garbsen, Germany |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 5 | */ |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 6 | #include <mbed.h> |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 7 | #include "arch.h" |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 8 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 9 | // -------------------------------------------------------------------------------------------------------------------- |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 10 | #ifndef TOOLCHAIN_GCC |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 11 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 12 | _extern_c size_t strnlen(const char *s, size_t maxlen) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 13 | const char *endp = static_cast<const char *>(memchr(s, 0, maxlen)); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 14 | if (endp == NULL) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 15 | return maxlen; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 16 | } else { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 17 | return endp - s; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 18 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 19 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 20 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 21 | _extern_c char *strdup(const char *s) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 22 | size_t sz = strlen(s) + 1; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 23 | char *news = static_cast<char *>(malloc(sz)); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 24 | if (news) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 25 | memcpy(news, s, sz); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 26 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 27 | return news; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 28 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 29 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 30 | // _extern_c char *stpcpy(char *dest, const char *src) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 31 | // size_t l = strlen(src); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 32 | // memcpy(dest, src, l+1); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 33 | // return dest + l; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 34 | // } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 35 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 36 | #endif |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 37 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 38 | // -------------------------------------------------------------------------------------------------------------------- |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 39 | #ifdef TARGET_STM32L0 |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 40 | #ifdef TOOLCHAIN_GCC |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 41 | _extern_c unsigned int __atomic_fetch_or_4(volatile void *mem, unsigned int val, int model) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 42 | volatile unsigned int *ptr = static_cast<volatile unsigned int *>(mem); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 43 | core_util_critical_section_enter(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 44 | unsigned int tmp = *ptr; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 45 | *ptr = tmp | val; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 46 | core_util_critical_section_exit(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 47 | return tmp; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 48 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 49 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 50 | _extern_c unsigned int __atomic_exchange_4(volatile void *mem, unsigned int val, int model) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 51 | volatile unsigned int *ptr = static_cast<volatile unsigned int *>(mem); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 52 | core_util_critical_section_enter(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 53 | unsigned int tmp = *ptr; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 54 | *ptr = val; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 55 | core_util_critical_section_exit(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 56 | return tmp; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 57 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 58 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 59 | #else |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 60 | _extern_c bool __user_cmpxchg_1(unsigned char *ptr, unsigned char oldp, unsigned char newp) |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 61 | { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 62 | return !core_util_atomic_cas_u8(ptr, &oldp, newp); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 63 | // core_util_critical_section_enter(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 64 | // bool r = (*ptr == oldp); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 65 | // if (r) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 66 | // *ptr = newp; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 67 | // } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 68 | // core_util_critical_section_exit(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 69 | // return !r; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 70 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 71 | |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 72 | _extern_c bool __user_cmpxchg_4(unsigned int *ptr, unsigned int oldp, unsigned int newp) |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 73 | { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 74 | return !core_util_atomic_cas_u32(ptr, &oldp, newp); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 75 | // core_util_critical_section_enter(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 76 | // bool r = (*ptr == oldp); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 77 | // if (r) { |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 78 | // *ptr = newp; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 79 | // } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 80 | // core_util_critical_section_exit(); |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 81 | // return !r; |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 82 | } |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 83 | #endif |
Helmut Tschemernjak | 11:e20b3c6c4a5c | 84 | #endif |