mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
20:4263a77256ae
Parent:
13:0645d8841f51
Child:
23:8d50de55f208
--- a/common/retarget.cpp	Mon Aug 19 18:17:02 2013 +0300
+++ b/common/retarget.cpp	Tue Sep 10 15:14:19 2013 +0300
@@ -163,7 +163,9 @@
     } else {
         FilePath path(name);
 
-        if (path.isFile()) {
+        if (!path.exists())
+            return -1;
+        else if (path.isFile()) {
             res = path.file();
         } else {
             FileSystemLike *fs = path.fileSystem();
@@ -425,3 +427,30 @@
     mbed_main();
 }
 #endif
+
+// Provide implementation of _sbrk (low-level dynamic memory allocation
+// routine) for GCC_ARM which compares new heap pointer with MSP instead of
+// SP.  This make it compatible with RTX RTOS thread stacks.
+#if defined(TOOLCHAIN_GCC_ARM)
+// Linker defined symbol used by _sbrk to indicate where heap should start.
+extern "C" int __end__;
+
+// Turn off the errno macro and use actual global variable instead.
+#undef errno
+extern "C" int errno;
+
+// Dynamic memory allocation related syscall.
+extern "C" caddr_t _sbrk(int incr) {
+    static unsigned char* heap = (unsigned char*)&__end__;
+    unsigned char*        prev_heap = heap;
+    unsigned char*        new_heap = heap + incr;
+
+    if (new_heap >= (unsigned char*)__get_MSP()) {
+        errno = ENOMEM;
+        return (caddr_t)-1;
+    }
+    
+    heap = new_heap;
+    return (caddr_t) prev_heap;
+}
+#endif