Helmut Tschemernjak / Mbed 2 deprecated Turtle_RadioShuttle

Dependencies:   mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arch.cpp Source File

arch.cpp

00001 /*
00002  * $Id: $
00003  * This is an unpublished work copyright (c) 2019 HELIOS Software GmbH
00004  * 30827 Garbsen, Germany
00005  */
00006 #include <mbed.h>
00007 #include "arch.h"
00008 
00009 // --------------------------------------------------------------------------------------------------------------------
00010 #ifndef TOOLCHAIN_GCC
00011 
00012 _extern_c size_t strnlen(const char *s, size_t maxlen) {
00013     const char *endp = static_cast<const char *>(memchr(s, 0, maxlen));
00014     if (endp == NULL) {
00015         return maxlen;
00016     } else {
00017         return endp - s;
00018     }
00019 }
00020 
00021 _extern_c char *strdup(const char *s) {
00022     size_t sz = strlen(s) + 1;
00023     char *news = static_cast<char *>(malloc(sz));
00024     if (news) {
00025         memcpy(news, s, sz);
00026     }
00027     return news;
00028 }
00029 
00030 // _extern_c char *stpcpy(char *dest, const char *src) {
00031 //     size_t l = strlen(src);
00032 //     memcpy(dest, src, l+1);
00033 //     return dest + l;
00034 // }
00035 
00036 #endif
00037 
00038 // --------------------------------------------------------------------------------------------------------------------
00039 #ifdef TARGET_STM32L0
00040 #ifdef TOOLCHAIN_GCC
00041 _extern_c unsigned int __atomic_fetch_or_4(volatile void *mem, unsigned int val, int model) {
00042     volatile unsigned int *ptr = static_cast<volatile unsigned int *>(mem);
00043     core_util_critical_section_enter();
00044     unsigned int tmp = *ptr;
00045     *ptr = tmp | val;
00046     core_util_critical_section_exit();
00047     return tmp;
00048 }
00049 
00050 _extern_c unsigned int __atomic_exchange_4(volatile void *mem, unsigned int val, int model) {
00051     volatile unsigned int *ptr = static_cast<volatile unsigned int *>(mem);
00052     core_util_critical_section_enter();
00053     unsigned int tmp = *ptr;
00054     *ptr = val;
00055     core_util_critical_section_exit();
00056     return tmp;
00057 }
00058 
00059 #else
00060 _extern_c bool __user_cmpxchg_1(unsigned char *ptr, unsigned char oldp, unsigned char newp)
00061 {
00062     return !core_util_atomic_cas_u8(ptr, &oldp, newp);
00063 //     core_util_critical_section_enter();
00064 //     bool r = (*ptr == oldp);
00065 //     if (r) {
00066 //         *ptr = newp;
00067 //     }
00068 //     core_util_critical_section_exit();
00069 //     return !r;
00070 }
00071 
00072 _extern_c bool __user_cmpxchg_4(unsigned int *ptr, unsigned int oldp, unsigned int newp)
00073 {
00074     return !core_util_atomic_cas_u32(ptr, &oldp, newp);
00075 //     core_util_critical_section_enter();
00076 //     bool r = (*ptr == oldp);
00077 //     if (r) {
00078 //         *ptr = newp;
00079 //     }
00080 //     core_util_critical_section_exit();
00081 //     return !r;
00082 }
00083 #endif
00084 #endif