mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			platform: astyle update
							parent
							
								
									483427a285
								
							
						
					
					
						commit
						ffcb6ecfb5
					
				| 
						 | 
					@ -79,7 +79,7 @@ void ATCmdParser::flush()
 | 
				
			||||||
int ATCmdParser::write(const char *data, int size)
 | 
					int ATCmdParser::write(const char *data, int size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i = 0;
 | 
					    int i = 0;
 | 
				
			||||||
    for ( ; i < size; i++) {
 | 
					    for (; i < size; i++) {
 | 
				
			||||||
        if (putc(data[i]) < 0) {
 | 
					        if (putc(data[i]) < 0) {
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -90,7 +90,7 @@ int ATCmdParser::write(const char *data, int size)
 | 
				
			||||||
int ATCmdParser::read(char *data, int size)
 | 
					int ATCmdParser::read(char *data, int size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i = 0;
 | 
					    int i = 0;
 | 
				
			||||||
    for ( ; i < size; i++) {
 | 
					    for (; i < size; i++) {
 | 
				
			||||||
        int c = getc();
 | 
					        int c = getc();
 | 
				
			||||||
        if (c < 0) {
 | 
					        if (c < 0) {
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
| 
						 | 
					@ -110,7 +110,7 @@ int ATCmdParser::vprintf(const char *format, va_list args)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i = 0;
 | 
					    int i = 0;
 | 
				
			||||||
    for ( ; _buffer[i]; i++) {
 | 
					    for (; _buffer[i]; i++) {
 | 
				
			||||||
        if (putc(_buffer[i]) < 0) {
 | 
					        if (putc(_buffer[i]) < 0) {
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -128,7 +128,7 @@ int ATCmdParser::vscanf(const char *format, va_list args)
 | 
				
			||||||
    int offset = 0;
 | 
					    int offset = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (format[i]) {
 | 
					    while (format[i]) {
 | 
				
			||||||
        if (format[i] == '%' && format[i+1] != '%' && format[i+1] != '*') {
 | 
					        if (format[i] == '%' && format[i + 1] != '%' && format[i + 1] != '*') {
 | 
				
			||||||
            _buffer[offset++] = '%';
 | 
					            _buffer[offset++] = '%';
 | 
				
			||||||
            _buffer[offset++] = '*';
 | 
					            _buffer[offset++] = '*';
 | 
				
			||||||
            i++;
 | 
					            i++;
 | 
				
			||||||
| 
						 | 
					@ -155,7 +155,7 @@ int ATCmdParser::vscanf(const char *format, va_list args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (true) {
 | 
					    while (true) {
 | 
				
			||||||
        // Ran out of space
 | 
					        // Ran out of space
 | 
				
			||||||
        if (j+1 >= _buffer_size - offset) {
 | 
					        if (j + 1 >= _buffer_size - offset) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Receive next character
 | 
					        // Receive next character
 | 
				
			||||||
| 
						 | 
					@ -168,12 +168,12 @@ int ATCmdParser::vscanf(const char *format, va_list args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Check for match
 | 
					        // Check for match
 | 
				
			||||||
        int count = -1;
 | 
					        int count = -1;
 | 
				
			||||||
        sscanf(_buffer+offset, _buffer, &count);
 | 
					        sscanf(_buffer + offset, _buffer, &count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // We only succeed if all characters in the response are matched
 | 
					        // We only succeed if all characters in the response are matched
 | 
				
			||||||
        if (count == j) {
 | 
					        if (count == j) {
 | 
				
			||||||
            // Store the found results
 | 
					            // Store the found results
 | 
				
			||||||
            vsscanf(_buffer+offset, format, args);
 | 
					            vsscanf(_buffer + offset, format, args);
 | 
				
			||||||
            return j;
 | 
					            return j;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -220,14 +220,14 @@ restart:
 | 
				
			||||||
        bool whole_line_wanted = false;
 | 
					        bool whole_line_wanted = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while (response[i]) {
 | 
					        while (response[i]) {
 | 
				
			||||||
            if (response[i] == '%' && response[i+1] != '%' && response[i+1] != '*') {
 | 
					            if (response[i] == '%' && response[i + 1] != '%' && response[i + 1] != '*') {
 | 
				
			||||||
                _buffer[offset++] = '%';
 | 
					                _buffer[offset++] = '%';
 | 
				
			||||||
                _buffer[offset++] = '*';
 | 
					                _buffer[offset++] = '*';
 | 
				
			||||||
                i++;
 | 
					                i++;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                _buffer[offset++] = response[i++];
 | 
					                _buffer[offset++] = response[i++];
 | 
				
			||||||
                // Find linebreaks, taking care not to be fooled if they're in a %[^\n] conversion specification
 | 
					                // Find linebreaks, taking care not to be fooled if they're in a %[^\n] conversion specification
 | 
				
			||||||
                if (response[i - 1] == '\n' && !(i >= 3 && response[i-3] == '[' && response[i-2] == '^')) {
 | 
					                if (response[i - 1] == '\n' && !(i >= 3 && response[i - 3] == '[' && response[i - 2] == '^')) {
 | 
				
			||||||
                    whole_line_wanted = true;
 | 
					                    whole_line_wanted = true;
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -260,7 +260,7 @@ restart:
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // Simplify newlines (borrowed from retarget.cpp)
 | 
					            // Simplify newlines (borrowed from retarget.cpp)
 | 
				
			||||||
            if ((c == CR && _in_prev != LF) ||
 | 
					            if ((c == CR && _in_prev != LF) ||
 | 
				
			||||||
                (c == LF && _in_prev != CR)) {
 | 
					                    (c == LF && _in_prev != CR)) {
 | 
				
			||||||
                _in_prev = c;
 | 
					                _in_prev = c;
 | 
				
			||||||
                c = '\n';
 | 
					                c = '\n';
 | 
				
			||||||
            } else if ((c == CR && _in_prev == LF) ||
 | 
					            } else if ((c == CR && _in_prev == LF) ||
 | 
				
			||||||
| 
						 | 
					@ -277,7 +277,7 @@ restart:
 | 
				
			||||||
            // Check for oob data
 | 
					            // Check for oob data
 | 
				
			||||||
            for (struct oob *oob = _oobs; oob; oob = oob->next) {
 | 
					            for (struct oob *oob = _oobs; oob; oob = oob->next) {
 | 
				
			||||||
                if ((unsigned)j == oob->len && memcmp(
 | 
					                if ((unsigned)j == oob->len && memcmp(
 | 
				
			||||||
                        oob->prefix, _buffer+offset, oob->len) == 0) {
 | 
					                            oob->prefix, _buffer + offset, oob->len) == 0) {
 | 
				
			||||||
                    debug_if(_dbg_on, "AT! %s\n", oob->prefix);
 | 
					                    debug_if(_dbg_on, "AT! %s\n", oob->prefix);
 | 
				
			||||||
                    oob->cb();
 | 
					                    oob->cb();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -298,18 +298,18 @@ restart:
 | 
				
			||||||
                // This allows recv("Foo: %s\n") to work, and not match with just the first character of a string
 | 
					                // This allows recv("Foo: %s\n") to work, and not match with just the first character of a string
 | 
				
			||||||
                // (scanf does not itself match whitespace in its format string, so \n is not significant to it)
 | 
					                // (scanf does not itself match whitespace in its format string, so \n is not significant to it)
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                sscanf(_buffer+offset, _buffer, &count);
 | 
					                sscanf(_buffer + offset, _buffer, &count);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // We only succeed if all characters in the response are matched
 | 
					            // We only succeed if all characters in the response are matched
 | 
				
			||||||
            if (count == j) {
 | 
					            if (count == j) {
 | 
				
			||||||
                debug_if(_dbg_on, "AT= %s\n", _buffer+offset);
 | 
					                debug_if(_dbg_on, "AT= %s\n", _buffer + offset);
 | 
				
			||||||
                // Reuse the front end of the buffer
 | 
					                // Reuse the front end of the buffer
 | 
				
			||||||
                memcpy(_buffer, response, i);
 | 
					                memcpy(_buffer, response, i);
 | 
				
			||||||
                _buffer[i] = 0;
 | 
					                _buffer[i] = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Store the found results
 | 
					                // Store the found results
 | 
				
			||||||
                vsscanf(_buffer+offset, _buffer, args);
 | 
					                vsscanf(_buffer + offset, _buffer, args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Jump to next line and continue parsing
 | 
					                // Jump to next line and continue parsing
 | 
				
			||||||
                response += i;
 | 
					                response += i;
 | 
				
			||||||
| 
						 | 
					@ -318,8 +318,8 @@ restart:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Clear the buffer when we hit a newline or ran out of space
 | 
					            // Clear the buffer when we hit a newline or ran out of space
 | 
				
			||||||
            // running out of space usually means we ran into binary data
 | 
					            // running out of space usually means we ran into binary data
 | 
				
			||||||
            if (c == '\n' || j+1 >= _buffer_size - offset) {
 | 
					            if (c == '\n' || j + 1 >= _buffer_size - offset) {
 | 
				
			||||||
                debug_if(_dbg_on, "AT< %s", _buffer+offset);
 | 
					                debug_if(_dbg_on, "AT< %s", _buffer + offset);
 | 
				
			||||||
                j = 0;
 | 
					                j = 0;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -396,7 +396,7 @@ bool ATCmdParser::process_oob()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Simplify newlines (borrowed from retarget.cpp)
 | 
					        // Simplify newlines (borrowed from retarget.cpp)
 | 
				
			||||||
        if ((c == CR && _in_prev != LF) ||
 | 
					        if ((c == CR && _in_prev != LF) ||
 | 
				
			||||||
            (c == LF && _in_prev != CR)) {
 | 
					                (c == LF && _in_prev != CR)) {
 | 
				
			||||||
            _in_prev = c;
 | 
					            _in_prev = c;
 | 
				
			||||||
            c = '\n';
 | 
					            c = '\n';
 | 
				
			||||||
        } else if ((c == CR && _in_prev == LF) ||
 | 
					        } else if ((c == CR && _in_prev == LF) ||
 | 
				
			||||||
| 
						 | 
					@ -414,7 +414,7 @@ bool ATCmdParser::process_oob()
 | 
				
			||||||
        struct oob *oob = _oobs;
 | 
					        struct oob *oob = _oobs;
 | 
				
			||||||
        while (oob) {
 | 
					        while (oob) {
 | 
				
			||||||
            if (i == (int)oob->len && memcmp(
 | 
					            if (i == (int)oob->len && memcmp(
 | 
				
			||||||
                    oob->prefix, _buffer, oob->len) == 0) {
 | 
					                        oob->prefix, _buffer, oob->len) == 0) {
 | 
				
			||||||
                debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
 | 
					                debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
 | 
				
			||||||
                oob->cb();
 | 
					                oob->cb();
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
| 
						 | 
					@ -424,7 +424,7 @@ bool ATCmdParser::process_oob()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Clear the buffer when we hit a newline or ran out of space
 | 
					        // Clear the buffer when we hit a newline or ran out of space
 | 
				
			||||||
        // running out of space usually means we ran into binary data
 | 
					        // running out of space usually means we ran into binary data
 | 
				
			||||||
        if (((i+1) >= _buffer_size) || (c == '\n')) {
 | 
					        if (((i + 1) >= _buffer_size) || (c == '\n')) {
 | 
				
			||||||
            debug_if(_dbg_on, "AT< %s", _buffer);
 | 
					            debug_if(_dbg_on, "AT< %s", _buffer);
 | 
				
			||||||
            i = 0;
 | 
					            i = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,8 +52,7 @@ namespace mbed {
 | 
				
			||||||
 * @endcode
 | 
					 * @endcode
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ATCmdParser : private NonCopyable<ATCmdParser>
 | 
					class ATCmdParser : private NonCopyable<ATCmdParser> {
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    // File handle
 | 
					    // File handle
 | 
				
			||||||
    // Not owned by ATCmdParser
 | 
					    // Not owned by ATCmdParser
 | 
				
			||||||
| 
						 | 
					@ -90,8 +89,8 @@ public:
 | 
				
			||||||
     * @param debug turns on/off debug output for AT commands
 | 
					     * @param debug turns on/off debug output for AT commands
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ATCmdParser(FileHandle *fh, const char *output_delimiter = "\r",
 | 
					    ATCmdParser(FileHandle *fh, const char *output_delimiter = "\r",
 | 
				
			||||||
             int buffer_size = 256, int timeout = 8000, bool debug = false)
 | 
					                int buffer_size = 256, int timeout = 8000, bool debug = false)
 | 
				
			||||||
            : _fh(fh), _buffer_size(buffer_size), _in_prev(0), _oobs(NULL)
 | 
					        : _fh(fh), _buffer_size(buffer_size), _in_prev(0), _oobs(NULL)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _buffer = new char[buffer_size];
 | 
					        _buffer = new char[buffer_size];
 | 
				
			||||||
        set_timeout(timeout);
 | 
					        set_timeout(timeout);
 | 
				
			||||||
| 
						 | 
					@ -198,7 +197,7 @@ public:
 | 
				
			||||||
     * @param ... all printf-like arguments to insert into command
 | 
					     * @param ... all printf-like arguments to insert into command
 | 
				
			||||||
     * @return true only if command is successfully sent
 | 
					     * @return true only if command is successfully sent
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    bool send(const char *command, ...) MBED_PRINTF_METHOD(1,2);
 | 
					    bool send(const char *command, ...) MBED_PRINTF_METHOD(1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool vsend(const char *command, va_list args);
 | 
					    bool vsend(const char *command, va_list args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -216,7 +215,7 @@ public:
 | 
				
			||||||
     * @param ... all scanf-like arguments to extract from response
 | 
					     * @param ... all scanf-like arguments to extract from response
 | 
				
			||||||
     * @return true only if response is successfully matched
 | 
					     * @return true only if response is successfully matched
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    bool recv(const char *response, ...) MBED_SCANF_METHOD(1,2);
 | 
					    bool recv(const char *response, ...) MBED_SCANF_METHOD(1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool vrecv(const char *response, va_list args);
 | 
					    bool vrecv(const char *response, va_list args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -261,7 +260,7 @@ public:
 | 
				
			||||||
     * @param ... arguments to printf
 | 
					     * @param ... arguments to printf
 | 
				
			||||||
     * @return number of bytes written or -1 on failure
 | 
					     * @return number of bytes written or -1 on failure
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    int printf(const char *format, ...) MBED_PRINTF_METHOD(1,2);
 | 
					    int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int vprintf(const char *format, va_list args);
 | 
					    int vprintf(const char *format, va_list args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -273,7 +272,7 @@ public:
 | 
				
			||||||
     * @param ... arguments to scanf
 | 
					     * @param ... arguments to scanf
 | 
				
			||||||
     * @return number of bytes read or -1 on failure
 | 
					     * @return number of bytes read or -1 on failure
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    int scanf(const char *format, ...) MBED_SCANF_METHOD(1,2);
 | 
					    int scanf(const char *format, ...) MBED_SCANF_METHOD(1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int vscanf(const char *format, va_list args);
 | 
					    int vscanf(const char *format, va_list args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,165 +84,163 @@ typedef void (*CThunkEntry)(void);
 | 
				
			||||||
 * @note Synchronization level: Not protected
 | 
					 * @note Synchronization level: Not protected
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class T>
 | 
					template<class T>
 | 
				
			||||||
class CThunk
 | 
					class CThunk {
 | 
				
			||||||
{
 | 
					public:
 | 
				
			||||||
    public:
 | 
					    typedef void (T::*CCallbackSimple)(void);
 | 
				
			||||||
        typedef void (T::*CCallbackSimple)(void);
 | 
					    typedef void (T::*CCallback)(void *context);
 | 
				
			||||||
        typedef void (T::*CCallback)(void* context);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline CThunk(T *instance)
 | 
					    inline CThunk(T *instance)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            init(instance, NULL, NULL);
 | 
					        init(instance, NULL, NULL);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline CThunk(T *instance, CCallback callback)
 | 
					    inline CThunk(T *instance, CCallback callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            init(instance, callback, NULL);
 | 
					        init(instance, callback, NULL);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ~CThunk() {
 | 
					    ~CThunk()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline CThunk(T *instance, CCallbackSimple callback)
 | 
					    inline CThunk(T *instance, CCallbackSimple callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            init(instance, (CCallback)callback, NULL);
 | 
					        init(instance, (CCallback)callback, NULL);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline CThunk(T &instance, CCallback callback)
 | 
					    inline CThunk(T &instance, CCallback callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            init(instance, callback, NULL);
 | 
					        init(instance, callback, NULL);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline CThunk(T &instance, CCallbackSimple callback)
 | 
					    inline CThunk(T &instance, CCallbackSimple callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            init(instance, (CCallback)callback, NULL);
 | 
					        init(instance, (CCallback)callback, NULL);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline CThunk(T &instance, CCallback callback, void* context)
 | 
					    inline CThunk(T &instance, CCallback callback, void *context)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            init(instance, callback, context);
 | 
					        init(instance, callback, context);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline void callback(CCallback callback)
 | 
					    inline void callback(CCallback callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            m_callback = callback;
 | 
					        m_callback = callback;
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline void callback(CCallbackSimple callback)
 | 
					    inline void callback(CCallbackSimple callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            m_callback = (CCallback)callback;
 | 
					        m_callback = (CCallback)callback;
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline void context(void* context)
 | 
					    inline void context(void *context)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            m_thunk.context = (uint32_t)context;
 | 
					        m_thunk.context = (uint32_t)context;
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline void context(uint32_t context)
 | 
					    inline void context(uint32_t context)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            m_thunk.context = context;
 | 
					        m_thunk.context = context;
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline uint32_t entry(void)
 | 
					    inline uint32_t entry(void)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
 | 
					        return (((uint32_t)&m_thunk) | CTHUNK_ADDRESS);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
					    /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
				
			||||||
        inline operator CThunkEntry(void)
 | 
					    inline operator CThunkEntry(void)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            return (CThunkEntry)entry();
 | 
					        return (CThunkEntry)entry();
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
					    /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
				
			||||||
        inline operator uint32_t(void)
 | 
					    inline operator uint32_t(void)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            return entry();
 | 
					        return entry();
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* simple test function */
 | 
					    /* simple test function */
 | 
				
			||||||
        inline void call(void)
 | 
					    inline void call(void)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            (((CThunkEntry)(entry()))());
 | 
					        (((CThunkEntry)(entry()))());
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private:
 | 
					private:
 | 
				
			||||||
        T* m_instance;
 | 
					    T *m_instance;
 | 
				
			||||||
        volatile CCallback m_callback;
 | 
					    volatile CCallback m_callback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: this needs proper fix, to refactor toolchain header file and all its use
 | 
					// TODO: this needs proper fix, to refactor toolchain header file and all its use
 | 
				
			||||||
// PACKED there is not defined properly for IAR
 | 
					// PACKED there is not defined properly for IAR
 | 
				
			||||||
#if defined (__ICCARM__)
 | 
					#if defined (__ICCARM__)
 | 
				
			||||||
        typedef __packed struct
 | 
					    typedef __packed struct {
 | 
				
			||||||
        {
 | 
					        CTHUNK_VARIABLES;
 | 
				
			||||||
            CTHUNK_VARIABLES;
 | 
					        volatile uint32_t instance;
 | 
				
			||||||
            volatile uint32_t instance;
 | 
					        volatile uint32_t context;
 | 
				
			||||||
            volatile uint32_t context;
 | 
					        volatile uint32_t callback;
 | 
				
			||||||
            volatile uint32_t callback;
 | 
					        volatile uint32_t trampoline;
 | 
				
			||||||
            volatile uint32_t trampoline;
 | 
					    }  CThunkTrampoline;
 | 
				
			||||||
        }  CThunkTrampoline;
 | 
					 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
        typedef struct
 | 
					    typedef struct {
 | 
				
			||||||
        {
 | 
					        CTHUNK_VARIABLES;
 | 
				
			||||||
            CTHUNK_VARIABLES;
 | 
					        volatile uint32_t instance;
 | 
				
			||||||
            volatile uint32_t instance;
 | 
					        volatile uint32_t context;
 | 
				
			||||||
            volatile uint32_t context;
 | 
					        volatile uint32_t callback;
 | 
				
			||||||
            volatile uint32_t callback;
 | 
					        volatile uint32_t trampoline;
 | 
				
			||||||
            volatile uint32_t trampoline;
 | 
					    } __attribute__((__packed__)) CThunkTrampoline;
 | 
				
			||||||
        } __attribute__((__packed__)) CThunkTrampoline;
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static void trampoline(T* instance, void* context, CCallback* callback)
 | 
					    static void trampoline(T *instance, void *context, CCallback *callback)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            if(instance && *callback) {
 | 
					        if (instance && *callback) {
 | 
				
			||||||
                (static_cast<T*>(instance)->**callback)(context);
 | 
					            (static_cast<T *>(instance)->**callback)(context);
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        volatile CThunkTrampoline m_thunk;
 | 
					    volatile CThunkTrampoline m_thunk;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inline void init(T *instance, CCallback callback, void* context)
 | 
					    inline void init(T *instance, CCallback callback, void *context)
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            /* remember callback - need to add this level of redirection
 | 
					        /* remember callback - need to add this level of redirection
 | 
				
			||||||
               as pointer size for member functions differs between platforms */
 | 
					           as pointer size for member functions differs between platforms */
 | 
				
			||||||
            m_callback = callback;
 | 
					        m_callback = callback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* populate thunking trampoline */
 | 
					        /* populate thunking trampoline */
 | 
				
			||||||
            CTHUNK_ASSIGMENT;
 | 
					        CTHUNK_ASSIGMENT;
 | 
				
			||||||
            m_thunk.context = (uint32_t)context;
 | 
					        m_thunk.context = (uint32_t)context;
 | 
				
			||||||
            m_thunk.instance = (uint32_t)instance;
 | 
					        m_thunk.instance = (uint32_t)instance;
 | 
				
			||||||
            m_thunk.callback = (uint32_t)&m_callback;
 | 
					        m_thunk.callback = (uint32_t)&m_callback;
 | 
				
			||||||
            m_thunk.trampoline = (uint32_t)&trampoline;
 | 
					        m_thunk.trampoline = (uint32_t)&trampoline;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__CORTEX_A9)
 | 
					#if defined(__CORTEX_A9)
 | 
				
			||||||
            /* Data cache clean */
 | 
					        /* Data cache clean */
 | 
				
			||||||
            /* Cache control */
 | 
					        /* Cache control */
 | 
				
			||||||
            {
 | 
					        {
 | 
				
			||||||
                uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
 | 
					            uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
 | 
				
			||||||
                uint32_t end_addr   = (uint32_t)&m_thunk + sizeof(m_thunk);
 | 
					            uint32_t end_addr   = (uint32_t)&m_thunk + sizeof(m_thunk);
 | 
				
			||||||
                uint32_t addr;
 | 
					            uint32_t addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                /* Data cache clean and invalid */
 | 
					            /* Data cache clean and invalid */
 | 
				
			||||||
                for (addr = start_addr; addr < end_addr; addr += 0x20) {
 | 
					            for (addr = start_addr; addr < end_addr; addr += 0x20) {
 | 
				
			||||||
                    L1C_CleanInvalidateDCacheMVA((void *)addr);
 | 
					                L1C_CleanInvalidateDCacheMVA((void *)addr);
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                /* Instruction cache invalid */
 | 
					 | 
				
			||||||
                L1C_InvalidateICacheAll();
 | 
					 | 
				
			||||||
                MMU_InvalidateTLB();
 | 
					 | 
				
			||||||
                L1C_InvalidateBTAC();
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            /* Instruction cache invalid */
 | 
				
			||||||
 | 
					            L1C_InvalidateICacheAll();
 | 
				
			||||||
 | 
					            MMU_InvalidateTLB();
 | 
				
			||||||
 | 
					            L1C_InvalidateBTAC();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#if defined(__CORTEX_M7)
 | 
					#if defined(__CORTEX_M7)
 | 
				
			||||||
            /* Data cache clean and invalid */
 | 
					        /* Data cache clean and invalid */
 | 
				
			||||||
            SCB_CleanInvalidateDCache();
 | 
					        SCB_CleanInvalidateDCache();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Instruction cache invalid */
 | 
					        /* Instruction cache invalid */
 | 
				
			||||||
            SCB_InvalidateICache();
 | 
					        SCB_InvalidateICache();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
            __ISB();
 | 
					        __ISB();
 | 
				
			||||||
            __DSB();
 | 
					        __DSB();
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**@}*/
 | 
					/**@}*/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,26 +13,31 @@ namespace mbed {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CallChainLink {
 | 
					class CallChainLink {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    CallChainLink(): cb(), next(NULL) {
 | 
					    CallChainLink(): cb(), next(NULL)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // No work to do
 | 
					        // No work to do
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) {
 | 
					    CallChainLink(Callback<void()> &callback): cb(callback), next(NULL)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // No work to do
 | 
					        // No work to do
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Callback<void()> cb;
 | 
					    Callback<void()> cb;
 | 
				
			||||||
    CallChainLink * next;
 | 
					    CallChainLink *next;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CallChain::CallChain(int size) : _chain(NULL) {
 | 
					CallChain::CallChain(int size) : _chain(NULL)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No work to do
 | 
					    // No work to do
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CallChain::~CallChain() {
 | 
					CallChain::~CallChain()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    clear();
 | 
					    clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pFunctionPointer_t CallChain::add(Callback<void()> func) {
 | 
					pFunctionPointer_t CallChain::add(Callback<void()> func)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *new_link = new CallChainLink(func);
 | 
					    CallChainLink *new_link = new CallChainLink(func);
 | 
				
			||||||
    if (NULL == _chain) {
 | 
					    if (NULL == _chain) {
 | 
				
			||||||
        _chain = new_link;
 | 
					        _chain = new_link;
 | 
				
			||||||
| 
						 | 
					@ -49,14 +54,16 @@ pFunctionPointer_t CallChain::add(Callback<void()> func) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pFunctionPointer_t CallChain::add_front(Callback<void()> func) {
 | 
					pFunctionPointer_t CallChain::add_front(Callback<void()> func)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = new CallChainLink(func);
 | 
					    CallChainLink *link = new CallChainLink(func);
 | 
				
			||||||
    link->next = _chain;
 | 
					    link->next = _chain;
 | 
				
			||||||
    _chain = link;
 | 
					    _chain = link;
 | 
				
			||||||
    return &link->cb;
 | 
					    return &link->cb;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int CallChain::size() const {
 | 
					int CallChain::size() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = _chain;
 | 
					    CallChainLink *link = _chain;
 | 
				
			||||||
    int elements = 0;
 | 
					    int elements = 0;
 | 
				
			||||||
    while (link != NULL) {
 | 
					    while (link != NULL) {
 | 
				
			||||||
| 
						 | 
					@ -66,7 +73,8 @@ int CallChain::size() const {
 | 
				
			||||||
    return elements;
 | 
					    return elements;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pFunctionPointer_t CallChain::get(int idx) const {
 | 
					pFunctionPointer_t CallChain::get(int idx) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = _chain;
 | 
					    CallChainLink *link = _chain;
 | 
				
			||||||
    for (int i = 0; i < idx; i++) {
 | 
					    for (int i = 0; i < idx; i++) {
 | 
				
			||||||
        if (NULL == link) {
 | 
					        if (NULL == link) {
 | 
				
			||||||
| 
						 | 
					@ -77,7 +85,8 @@ pFunctionPointer_t CallChain::get(int idx) const {
 | 
				
			||||||
    return &link->cb;
 | 
					    return &link->cb;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int CallChain::find(pFunctionPointer_t f) const {
 | 
					int CallChain::find(pFunctionPointer_t f) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = _chain;
 | 
					    CallChainLink *link = _chain;
 | 
				
			||||||
    int i = 0;
 | 
					    int i = 0;
 | 
				
			||||||
    while (link != NULL) {
 | 
					    while (link != NULL) {
 | 
				
			||||||
| 
						 | 
					@ -90,7 +99,8 @@ int CallChain::find(pFunctionPointer_t f) const {
 | 
				
			||||||
    return -1;
 | 
					    return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CallChain::clear() {
 | 
					void CallChain::clear()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = _chain;
 | 
					    CallChainLink *link = _chain;
 | 
				
			||||||
    _chain = NULL;
 | 
					    _chain = NULL;
 | 
				
			||||||
    while (link != NULL) {
 | 
					    while (link != NULL) {
 | 
				
			||||||
| 
						 | 
					@ -100,7 +110,8 @@ void CallChain::clear() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool CallChain::remove(pFunctionPointer_t f) {
 | 
					bool CallChain::remove(pFunctionPointer_t f)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = _chain;
 | 
					    CallChainLink *link = _chain;
 | 
				
			||||||
    while (link != NULL) {
 | 
					    while (link != NULL) {
 | 
				
			||||||
        if (f == &link->cb) {
 | 
					        if (f == &link->cb) {
 | 
				
			||||||
| 
						 | 
					@ -112,7 +123,8 @@ bool CallChain::remove(pFunctionPointer_t f) {
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CallChain::call() {
 | 
					void CallChain::call()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CallChainLink *link = _chain;
 | 
					    CallChainLink *link = _chain;
 | 
				
			||||||
    while (link != NULL) {
 | 
					    while (link != NULL) {
 | 
				
			||||||
        link->cb.call();
 | 
					        link->cb.call();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,7 +81,7 @@ public:
 | 
				
			||||||
     *  @param size (optional) Initial size of the chain
 | 
					     *  @param size (optional) Initial size of the chain
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    CallChain(int size = 4);
 | 
					    CallChain(int size = 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Create an empty chain
 | 
					    /** Create an empty chain
 | 
				
			||||||
| 
						 | 
					@ -89,7 +89,7 @@ public:
 | 
				
			||||||
     *  Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
 | 
					     *  Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    virtual ~CallChain();
 | 
					    virtual ~CallChain();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Add a function at the end of the chain
 | 
					    /** Add a function at the end of the chain
 | 
				
			||||||
| 
						 | 
					@ -103,7 +103,7 @@ public:
 | 
				
			||||||
     *  The function object created for 'func'
 | 
					     *  The function object created for 'func'
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    pFunctionPointer_t add(Callback<void()> func);
 | 
					    pFunctionPointer_t add(Callback<void()> func);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Add a function at the end of the chain
 | 
					    /** Add a function at the end of the chain
 | 
				
			||||||
| 
						 | 
					@ -120,9 +120,10 @@ public:
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    template<typename T, typename M>
 | 
					    template<typename T, typename M>
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
				
			||||||
        "The add function does not support cv-qualifiers. Replaced by "
 | 
					                          "The add function does not support cv-qualifiers. Replaced by "
 | 
				
			||||||
        "add(callback(obj, method)).")
 | 
					                          "add(callback(obj, method)).")
 | 
				
			||||||
    pFunctionPointer_t add(T *obj, M method) {
 | 
					    pFunctionPointer_t add(T *obj, M method)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return add(callback(obj, method));
 | 
					        return add(callback(obj, method));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -137,7 +138,7 @@ public:
 | 
				
			||||||
     *  The function object created for 'func'
 | 
					     *  The function object created for 'func'
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    pFunctionPointer_t add_front(Callback<void()> func);
 | 
					    pFunctionPointer_t add_front(Callback<void()> func);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Add a function at the beginning of the chain
 | 
					    /** Add a function at the beginning of the chain
 | 
				
			||||||
| 
						 | 
					@ -154,9 +155,10 @@ public:
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    template<typename T, typename M>
 | 
					    template<typename T, typename M>
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
				
			||||||
        "The add_front function does not support cv-qualifiers. Replaced by "
 | 
					                          "The add_front function does not support cv-qualifiers. Replaced by "
 | 
				
			||||||
        "add_front(callback(obj, method)).")
 | 
					                          "add_front(callback(obj, method)).")
 | 
				
			||||||
    pFunctionPointer_t add_front(T *obj, M method) {
 | 
					    pFunctionPointer_t add_front(T *obj, M method)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return add_front(callback(obj, method));
 | 
					        return add_front(callback(obj, method));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,7 +168,7 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    int size() const;
 | 
					    int size() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Get a function object from the chain
 | 
					    /** Get a function object from the chain
 | 
				
			||||||
| 
						 | 
					@ -179,7 +181,7 @@ public:
 | 
				
			||||||
     *  The function object at position 'i' in the chain
 | 
					     *  The function object at position 'i' in the chain
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    pFunctionPointer_t get(int i) const;
 | 
					    pFunctionPointer_t get(int i) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Look for a function object in the call chain
 | 
					    /** Look for a function object in the call chain
 | 
				
			||||||
| 
						 | 
					@ -192,14 +194,14 @@ public:
 | 
				
			||||||
     *  The index of the function object if found, -1 otherwise.
 | 
					     *  The index of the function object if found, -1 otherwise.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    int find(pFunctionPointer_t f) const;
 | 
					    int find(pFunctionPointer_t f) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Clear the call chain (remove all functions in the chain).
 | 
					    /** Clear the call chain (remove all functions in the chain).
 | 
				
			||||||
     *  @deprecated Do not use this function. This class is not part of the public API of mbed-os and is being removed in the future.
 | 
					     *  @deprecated Do not use this function. This class is not part of the public API of mbed-os and is being removed in the future.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    void clear();
 | 
					    void clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Remove a function object from the chain
 | 
					    /** Remove a function object from the chain
 | 
				
			||||||
| 
						 | 
					@ -212,7 +214,7 @@ public:
 | 
				
			||||||
     *  true if the function object was found and removed, false otherwise.
 | 
					     *  true if the function object was found and removed, false otherwise.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    bool remove(pFunctionPointer_t f);
 | 
					    bool remove(pFunctionPointer_t f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Call all the functions in the chain in sequence
 | 
					    /** Call all the functions in the chain in sequence
 | 
				
			||||||
| 
						 | 
					@ -221,7 +223,7 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    void call();
 | 
					    void call();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					@ -230,8 +232,9 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    void operator ()(void) {
 | 
					    void operator()(void)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        call();
 | 
					        call();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -241,8 +244,9 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
 | 
				
			||||||
        "public API of mbed-os and is being removed in the future.")
 | 
					                          "public API of mbed-os and is being removed in the future.")
 | 
				
			||||||
    pFunctionPointer_t operator [](int i) const {
 | 
					    pFunctionPointer_t operator [](int i) const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return get(i);
 | 
					        return get(i);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1688
									
								
								platform/Callback.h
								
								
								
								
							
							
						
						
									
										1688
									
								
								platform/Callback.h
								
								
								
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
					@ -24,17 +24,29 @@ namespace mbed {
 | 
				
			||||||
namespace internal {
 | 
					namespace internal {
 | 
				
			||||||
/* Detect if CounterType of the Circular buffer is of unsigned type. */
 | 
					/* Detect if CounterType of the Circular buffer is of unsigned type. */
 | 
				
			||||||
template<typename T>
 | 
					template<typename T>
 | 
				
			||||||
struct is_unsigned { static const bool value = false; };
 | 
					struct is_unsigned {
 | 
				
			||||||
 | 
					    static const bool value = false;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
template<>
 | 
					template<>
 | 
				
			||||||
struct is_unsigned<unsigned char> { static const bool value = true; };
 | 
					struct is_unsigned<unsigned char> {
 | 
				
			||||||
 | 
					    static const bool value = true;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
template<>
 | 
					template<>
 | 
				
			||||||
struct is_unsigned<unsigned short> { static const bool value = true; };
 | 
					struct is_unsigned<unsigned short> {
 | 
				
			||||||
 | 
					    static const bool value = true;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
template<>
 | 
					template<>
 | 
				
			||||||
struct is_unsigned<unsigned int> { static const bool value = true; };
 | 
					struct is_unsigned<unsigned int> {
 | 
				
			||||||
 | 
					    static const bool value = true;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
template<>
 | 
					template<>
 | 
				
			||||||
struct is_unsigned<unsigned long> { static const bool value = true; };
 | 
					struct is_unsigned<unsigned long> {
 | 
				
			||||||
 | 
					    static const bool value = true;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
template<>
 | 
					template<>
 | 
				
			||||||
struct is_unsigned<unsigned long long> { static const bool value = true; };
 | 
					struct is_unsigned<unsigned long long> {
 | 
				
			||||||
 | 
					    static const bool value = true;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** \addtogroup platform */
 | 
					/** \addtogroup platform */
 | 
				
			||||||
| 
						 | 
					@ -52,7 +64,8 @@ struct is_unsigned<unsigned long long> { static const bool value = true; };
 | 
				
			||||||
template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
 | 
					template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
 | 
				
			||||||
class CircularBuffer {
 | 
					class CircularBuffer {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    CircularBuffer() : _head(0), _tail(0), _full(false) {
 | 
					    CircularBuffer() : _head(0), _tail(0), _full(false)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        MBED_STATIC_ASSERT(
 | 
					        MBED_STATIC_ASSERT(
 | 
				
			||||||
            internal::is_unsigned<CounterType>::value,
 | 
					            internal::is_unsigned<CounterType>::value,
 | 
				
			||||||
            "CounterType must be unsigned"
 | 
					            "CounterType must be unsigned"
 | 
				
			||||||
| 
						 | 
					@ -65,7 +78,8 @@ public:
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ~CircularBuffer() {
 | 
					    ~CircularBuffer()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Push the transaction to the buffer. This overwrites the buffer if it's
 | 
					    /** Push the transaction to the buffer. This overwrites the buffer if it's
 | 
				
			||||||
| 
						 | 
					@ -73,7 +87,8 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param data Data to be pushed to the buffer
 | 
					     * @param data Data to be pushed to the buffer
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void push(const T& data) {
 | 
					    void push(const T &data)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        if (full()) {
 | 
					        if (full()) {
 | 
				
			||||||
            _tail++;
 | 
					            _tail++;
 | 
				
			||||||
| 
						 | 
					@ -92,7 +107,8 @@ public:
 | 
				
			||||||
     * @param data Data to be popped from the buffer
 | 
					     * @param data Data to be popped from the buffer
 | 
				
			||||||
     * @return True if the buffer is not empty and data contains a transaction, false otherwise
 | 
					     * @return True if the buffer is not empty and data contains a transaction, false otherwise
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    bool pop(T& data) {
 | 
					    bool pop(T &data)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        bool data_popped = false;
 | 
					        bool data_popped = false;
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        if (!empty()) {
 | 
					        if (!empty()) {
 | 
				
			||||||
| 
						 | 
					@ -109,7 +125,8 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return True if the buffer is empty, false if not
 | 
					     * @return True if the buffer is empty, false if not
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    bool empty() const {
 | 
					    bool empty() const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        bool is_empty = (_head == _tail) && !_full;
 | 
					        bool is_empty = (_head == _tail) && !_full;
 | 
				
			||||||
        core_util_critical_section_exit();
 | 
					        core_util_critical_section_exit();
 | 
				
			||||||
| 
						 | 
					@ -120,7 +137,8 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return True if the buffer is full, false if not
 | 
					     * @return True if the buffer is full, false if not
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    bool full() const {
 | 
					    bool full() const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        bool full = _full;
 | 
					        bool full = _full;
 | 
				
			||||||
        core_util_critical_section_exit();
 | 
					        core_util_critical_section_exit();
 | 
				
			||||||
| 
						 | 
					@ -130,7 +148,8 @@ public:
 | 
				
			||||||
    /** Reset the buffer
 | 
					    /** Reset the buffer
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void reset() {
 | 
					    void reset()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        _head = 0;
 | 
					        _head = 0;
 | 
				
			||||||
        _tail = 0;
 | 
					        _tail = 0;
 | 
				
			||||||
| 
						 | 
					@ -139,7 +158,8 @@ public:
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Get the number of elements currently stored in the circular_buffer */
 | 
					    /** Get the number of elements currently stored in the circular_buffer */
 | 
				
			||||||
    CounterType size() const {
 | 
					    CounterType size() const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        CounterType elements;
 | 
					        CounterType elements;
 | 
				
			||||||
        if (!_full) {
 | 
					        if (!_full) {
 | 
				
			||||||
| 
						 | 
					@ -160,7 +180,8 @@ public:
 | 
				
			||||||
     * @param data Data to be peeked from the buffer
 | 
					     * @param data Data to be peeked from the buffer
 | 
				
			||||||
     * @return True if the buffer is not empty and data contains a transaction, false otherwise
 | 
					     * @return True if the buffer is not empty and data contains a transaction, false otherwise
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    bool peek(T& data) const {
 | 
					    bool peek(T &data) const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        bool data_updated = false;
 | 
					        bool data_updated = false;
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
        if (!empty()) {
 | 
					        if (!empty()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,8 +72,8 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.8",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.8",
 | 
				
			||||||
            "This function is inconsistent with RAII and is being removed in the future."
 | 
					                          "This function is inconsistent with RAII and is being removed in the future."
 | 
				
			||||||
            "Replaced by static function CriticalSectionLock::enable.")
 | 
					                          "Replaced by static function CriticalSectionLock::enable.")
 | 
				
			||||||
    void lock()
 | 
					    void lock()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_enter();
 | 
					        core_util_critical_section_enter();
 | 
				
			||||||
| 
						 | 
					@ -84,8 +84,8 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.8",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.8",
 | 
				
			||||||
            "This function is inconsistent with RAII and is being removed in the future."
 | 
					                          "This function is inconsistent with RAII and is being removed in the future."
 | 
				
			||||||
            "Replaced by static function CriticalSectionLock::disable.")
 | 
					                          "Replaced by static function CriticalSectionLock::disable.")
 | 
				
			||||||
    void unlock()
 | 
					    void unlock()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        core_util_critical_section_exit();
 | 
					        core_util_critical_section_exit();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,7 +108,10 @@ public:
 | 
				
			||||||
     *  @deprecated Replaced by `int DirHandle::close()'
 | 
					     *  @deprecated Replaced by `int DirHandle::close()'
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::close")
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::close")
 | 
				
			||||||
    virtual int closedir() { return close(); };
 | 
					    virtual int closedir()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return close();
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Return the directory entry at the current position, and
 | 
					    /** Return the directory entry at the current position, and
 | 
				
			||||||
     *  advances the position to the next entry.
 | 
					     *  advances the position to the next entry.
 | 
				
			||||||
| 
						 | 
					@ -130,7 +133,10 @@ public:
 | 
				
			||||||
     * @deprecated Replaced by `void DirHandle::rewind()'
 | 
					     * @deprecated Replaced by `void DirHandle::rewind()'
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::rewind")
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::rewind")
 | 
				
			||||||
    virtual void rewinddir() { rewind(); }
 | 
					    virtual void rewinddir()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        rewind();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Returns the current position of the DirHandle.
 | 
					    /** Returns the current position of the DirHandle.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					@ -140,7 +146,10 @@ public:
 | 
				
			||||||
     * @deprecated Replaced by `off_t DirHandle::tell()'
 | 
					     * @deprecated Replaced by `off_t DirHandle::tell()'
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::tell")
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::tell")
 | 
				
			||||||
    virtual off_t telldir() { return tell(); }
 | 
					    virtual off_t telldir()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return tell();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Sets the position of the DirHandle.
 | 
					    /** Sets the position of the DirHandle.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					@ -148,7 +157,10 @@ public:
 | 
				
			||||||
     *  @deprecated Replaced by `void DirHandle::seek(off_t offset)'
 | 
					     *  @deprecated Replaced by `void DirHandle::seek(off_t offset)'
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::seek")
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::seek")
 | 
				
			||||||
    virtual void seekdir(off_t location) { seek(location); }
 | 
					    virtual void seekdir(off_t location)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        seek(location);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**@}*/
 | 
					/**@}*/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,8 +23,9 @@ FileBase *FileBase::_head = NULL;
 | 
				
			||||||
SingletonPtr<PlatformMutex> FileBase::_mutex;
 | 
					SingletonPtr<PlatformMutex> FileBase::_mutex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FileBase::FileBase(const char *name, PathType t) : _next(NULL),
 | 
					FileBase::FileBase(const char *name, PathType t) : _next(NULL),
 | 
				
			||||||
                                                   _name(name),
 | 
					    _name(name),
 | 
				
			||||||
                                                   _path_type(t) {
 | 
					    _path_type(t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex->lock();
 | 
					    _mutex->lock();
 | 
				
			||||||
    if (name != NULL) {
 | 
					    if (name != NULL) {
 | 
				
			||||||
        // put this object at head of the list
 | 
					        // put this object at head of the list
 | 
				
			||||||
| 
						 | 
					@ -36,7 +37,8 @@ FileBase::FileBase(const char *name, PathType t) : _next(NULL),
 | 
				
			||||||
    _mutex->unlock();
 | 
					    _mutex->unlock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FileBase::~FileBase() {
 | 
					FileBase::~FileBase()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex->lock();
 | 
					    _mutex->lock();
 | 
				
			||||||
    if (_name != NULL) {
 | 
					    if (_name != NULL) {
 | 
				
			||||||
        // remove this object from the list
 | 
					        // remove this object from the list
 | 
				
			||||||
| 
						 | 
					@ -53,12 +55,13 @@ FileBase::~FileBase() {
 | 
				
			||||||
    _mutex->unlock();
 | 
					    _mutex->unlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (getPathType() == FilePathType) {
 | 
					    if (getPathType() == FilePathType) {
 | 
				
			||||||
        extern void remove_filehandle(FileHandle *file);
 | 
					        extern void remove_filehandle(FileHandle * file);
 | 
				
			||||||
        remove_filehandle(static_cast<FileHandle*>(static_cast<FileLike*>(this)));
 | 
					        remove_filehandle(static_cast<FileHandle *>(static_cast<FileLike *>(this)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FileBase *FileBase::lookup(const char *name, unsigned int len) {
 | 
					FileBase *FileBase::lookup(const char *name, unsigned int len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex->lock();
 | 
					    _mutex->lock();
 | 
				
			||||||
    FileBase *p = _head;
 | 
					    FileBase *p = _head;
 | 
				
			||||||
    while (p != NULL) {
 | 
					    while (p != NULL) {
 | 
				
			||||||
| 
						 | 
					@ -73,7 +76,8 @@ FileBase *FileBase::lookup(const char *name, unsigned int len) {
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FileBase *FileBase::get(int n) {
 | 
					FileBase *FileBase::get(int n)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex->lock();
 | 
					    _mutex->lock();
 | 
				
			||||||
    FileBase *p = _head;
 | 
					    FileBase *p = _head;
 | 
				
			||||||
    int m = 0;
 | 
					    int m = 0;
 | 
				
			||||||
| 
						 | 
					@ -90,12 +94,14 @@ FileBase *FileBase::get(int n) {
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char* FileBase::getName(void) {
 | 
					const char *FileBase::getName(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // Constant read so no lock needed
 | 
					    // Constant read so no lock needed
 | 
				
			||||||
    return _name;
 | 
					    return _name;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PathType FileBase::getPathType(void) {
 | 
					PathType FileBase::getPathType(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // Constant read so no lock needed
 | 
					    // Constant read so no lock needed
 | 
				
			||||||
    return _path_type;
 | 
					    return _path_type;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ public:
 | 
				
			||||||
    FileBase(const char *name, PathType t);
 | 
					    FileBase(const char *name, PathType t);
 | 
				
			||||||
    virtual ~FileBase();
 | 
					    virtual ~FileBase();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char* getName(void);
 | 
					    const char *getName(void);
 | 
				
			||||||
    PathType    getPathType(void);
 | 
					    PathType    getPathType(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static FileBase *lookup(const char *name, unsigned int len);
 | 
					    static FileBase *lookup(const char *name, unsigned int len);
 | 
				
			||||||
| 
						 | 
					@ -61,7 +61,7 @@ private:
 | 
				
			||||||
    static SingletonPtr<PlatformMutex> _mutex;
 | 
					    static SingletonPtr<PlatformMutex> _mutex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FileBase   *_next;
 | 
					    FileBase   *_next;
 | 
				
			||||||
    const char * const _name;
 | 
					    const char *const _name;
 | 
				
			||||||
    const PathType _path_type;
 | 
					    const PathType _path_type;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,11 +17,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace mbed {
 | 
					namespace mbed {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
 | 
					FilePath::FilePath(const char *file_path) : file_name(NULL), fb(NULL)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // skip slashes
 | 
					    // skip slashes
 | 
				
			||||||
    file_path += strspn(file_path, "/");
 | 
					    file_path += strspn(file_path, "/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char* file_system = file_path;
 | 
					    const char *file_system = file_path;
 | 
				
			||||||
    file_name = file_system;
 | 
					    file_name = file_system;
 | 
				
			||||||
    int len = 0;
 | 
					    int len = 0;
 | 
				
			||||||
    while (true) {
 | 
					    while (true) {
 | 
				
			||||||
| 
						 | 
					@ -41,37 +42,45 @@ FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
 | 
				
			||||||
    fb = FileBase::lookup(file_system, len);
 | 
					    fb = FileBase::lookup(file_system, len);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char* FilePath::fileName(void) {
 | 
					const char *FilePath::fileName(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return file_name;
 | 
					    return file_name;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool FilePath::isFileSystem(void) {
 | 
					bool FilePath::isFileSystem(void)
 | 
				
			||||||
    if (NULL == fb)
 | 
					{
 | 
				
			||||||
 | 
					    if (NULL == fb) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return (fb->getPathType() == FileSystemPathType);
 | 
					    return (fb->getPathType() == FileSystemPathType);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FileSystemLike* FilePath::fileSystem(void) {
 | 
					FileSystemLike *FilePath::fileSystem(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (isFileSystem()) {
 | 
					    if (isFileSystem()) {
 | 
				
			||||||
        return static_cast<FileSystemLike*>(fb);
 | 
					        return static_cast<FileSystemLike *>(fb);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool FilePath::isFile(void) {
 | 
					bool FilePath::isFile(void)
 | 
				
			||||||
    if (NULL == fb)
 | 
					{
 | 
				
			||||||
 | 
					    if (NULL == fb) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return (fb->getPathType() == FilePathType);
 | 
					    return (fb->getPathType() == FilePathType);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FileLike* FilePath::file(void) {
 | 
					FileLike *FilePath::file(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (isFile()) {
 | 
					    if (isFile()) {
 | 
				
			||||||
        return (FileLike*)fb;
 | 
					        return (FileLike *)fb;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool FilePath::exists(void) {
 | 
					bool FilePath::exists(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return fb != NULL;
 | 
					    return fb != NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,20 +40,20 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     *  @param file_path     The path of file.
 | 
					     *  @param file_path     The path of file.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    FilePath(const char* file_path);
 | 
					    FilePath(const char *file_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char* fileName(void);
 | 
					    const char *fileName(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool          isFileSystem(void);
 | 
					    bool          isFileSystem(void);
 | 
				
			||||||
    FileSystemLike* fileSystem(void);
 | 
					    FileSystemLike *fileSystem(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool    isFile(void);
 | 
					    bool    isFile(void);
 | 
				
			||||||
    FileLike* file(void);
 | 
					    FileLike *file(void);
 | 
				
			||||||
    bool    exists(void);
 | 
					    bool    exists(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    const char* file_name;
 | 
					    const char *file_name;
 | 
				
			||||||
    FileBase* fb;
 | 
					    FileBase *fb;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**@}*/
 | 
					/**@}*/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,7 +101,7 @@ public:
 | 
				
			||||||
     *  @param buf      The stat buffer to write to
 | 
					     *  @param buf      The stat buffer to write to
 | 
				
			||||||
     *  @return         0 on success, negative error code on failure
 | 
					     *  @return         0 on success, negative error code on failure
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
     virtual int statvfs(const char *path, struct statvfs *buf);
 | 
					    virtual int statvfs(const char *path, struct statvfs *buf);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
/**@}*/
 | 
					/**@}*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,7 +59,7 @@ public:
 | 
				
			||||||
     *  @deprecated Replaced by `int open(FileHandle **, ...)` for propagating error codes
 | 
					     *  @deprecated Replaced by `int open(FileHandle **, ...)` for propagating error codes
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.5",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.5",
 | 
				
			||||||
        "Replaced by `int open(FileHandle **, ...)` for propagating error codes")
 | 
					                          "Replaced by `int open(FileHandle **, ...)` for propagating error codes")
 | 
				
			||||||
    FileHandle *open(const char *path, int flags)
 | 
					    FileHandle *open(const char *path, int flags)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        FileHandle *file;
 | 
					        FileHandle *file;
 | 
				
			||||||
| 
						 | 
					@ -74,7 +74,7 @@ public:
 | 
				
			||||||
     *  @deprecated Replaced by `int open(DirHandle **, ...)` for propagating error codes
 | 
					     *  @deprecated Replaced by `int open(DirHandle **, ...)` for propagating error codes
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.5",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.5",
 | 
				
			||||||
        "Replaced by `int open(DirHandle **, ...)` for propagating error codes")
 | 
					                          "Replaced by `int open(DirHandle **, ...)` for propagating error codes")
 | 
				
			||||||
    DirHandle *opendir(const char *path)
 | 
					    DirHandle *opendir(const char *path)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        DirHandle *dir;
 | 
					        DirHandle *dir;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,21 +35,23 @@ template <typename R, typename A1>
 | 
				
			||||||
class FunctionPointerArg1 : public Callback<R(A1)> {
 | 
					class FunctionPointerArg1 : public Callback<R(A1)> {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
				
			||||||
        "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
					                          "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
				
			||||||
    FunctionPointerArg1(R (*function)(A1) = 0)
 | 
					    FunctionPointerArg1(R(*function)(A1) = 0)
 | 
				
			||||||
        : Callback<R(A1)>(function) {}
 | 
					        : Callback<R(A1)>(function) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    template<typename T>
 | 
					    template<typename T>
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
				
			||||||
        "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
					                          "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
				
			||||||
    FunctionPointerArg1(T *object, R (T::*member)(A1))
 | 
					    FunctionPointerArg1(T *object, R(T::*member)(A1))
 | 
				
			||||||
        : Callback<R(A1)>(object, member) {}
 | 
					        : Callback<R(A1)>(object, member) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    R (*get_function())(A1) {
 | 
					    R(*get_function())(A1)
 | 
				
			||||||
        return *reinterpret_cast<R (**)(A1)>(this);
 | 
					    {
 | 
				
			||||||
 | 
					        return *reinterpret_cast<R(* *)(A1)>(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    R call(A1 a1) const {
 | 
					    R call(A1 a1) const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        if (!Callback<R(A1)>::operator bool()) {
 | 
					        if (!Callback<R(A1)>::operator bool()) {
 | 
				
			||||||
            return (R)0;
 | 
					            return (R)0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -57,7 +59,8 @@ public:
 | 
				
			||||||
        return Callback<R(A1)>::call(a1);
 | 
					        return Callback<R(A1)>::call(a1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    R operator()(A1 a1) const {
 | 
					    R operator()(A1 a1) const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return Callback<R(A1)>::call(a1);
 | 
					        return Callback<R(A1)>::call(a1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -66,21 +69,23 @@ template <typename R>
 | 
				
			||||||
class FunctionPointerArg1<R, void> : public Callback<R()> {
 | 
					class FunctionPointerArg1<R, void> : public Callback<R()> {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
				
			||||||
        "FunctionPointer has been replaced by Callback<void()>")
 | 
					                          "FunctionPointer has been replaced by Callback<void()>")
 | 
				
			||||||
    FunctionPointerArg1(R (*function)() = 0)
 | 
					    FunctionPointerArg1(R(*function)() = 0)
 | 
				
			||||||
        : Callback<R()>(function) {}
 | 
					        : Callback<R()>(function) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    template<typename T>
 | 
					    template<typename T>
 | 
				
			||||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
					    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
				
			||||||
        "FunctionPointer has been replaced by Callback<void()>")
 | 
					                          "FunctionPointer has been replaced by Callback<void()>")
 | 
				
			||||||
    FunctionPointerArg1(T *object, R (T::*member)())
 | 
					    FunctionPointerArg1(T *object, R(T::*member)())
 | 
				
			||||||
        : Callback<R()>(object, member) {}
 | 
					        : Callback<R()>(object, member) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    R (*get_function())() {
 | 
					    R(*get_function())()
 | 
				
			||||||
        return *reinterpret_cast<R (**)()>(this);
 | 
					    {
 | 
				
			||||||
 | 
					        return *reinterpret_cast<R(* *)()>(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    R call() const {
 | 
					    R call() const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        if (!Callback<R()>::operator bool()) {
 | 
					        if (!Callback<R()>::operator bool()) {
 | 
				
			||||||
            return (R)0;
 | 
					            return (R)0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -88,7 +93,8 @@ public:
 | 
				
			||||||
        return Callback<R()>::call();
 | 
					        return Callback<R()>::call();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    R operator()() const {
 | 
					    R operator()() const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return Callback<R()>::call();
 | 
					        return Callback<R()>::call();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,8 @@ typedef struct {         /* File Search info record           */
 | 
				
			||||||
#define RESERVED_FOR_USER_APPLICATIONS (0x100) /* 0x100 - 0x1ff */
 | 
					#define RESERVED_FOR_USER_APPLICATIONS (0x100) /* 0x100 - 0x1ff */
 | 
				
			||||||
#define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
 | 
					#define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int xffind (const char *pattern, XFINFO *info) {
 | 
					static int xffind(const char *pattern, XFINFO *info)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    unsigned param[4];
 | 
					    unsigned param[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    param[0] = (unsigned long)pattern;
 | 
					    param[0] = (unsigned long)pattern;
 | 
				
			||||||
| 
						 | 
					@ -63,7 +64,8 @@ static int xffind (const char *pattern, XFINFO *info) {
 | 
				
			||||||
#define OPEN_A          8
 | 
					#define OPEN_A          8
 | 
				
			||||||
#define OPEN_INVALID   -1
 | 
					#define OPEN_INVALID   -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int posix_to_semihost_open_flags(int flags) {
 | 
					int posix_to_semihost_open_flags(int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    /* POSIX flags -> semihosting open mode */
 | 
					    /* POSIX flags -> semihosting open mode */
 | 
				
			||||||
    int openmode;
 | 
					    int openmode;
 | 
				
			||||||
    if (flags & O_RDWR) {
 | 
					    if (flags & O_RDWR) {
 | 
				
			||||||
| 
						 | 
					@ -94,7 +96,8 @@ int posix_to_semihost_open_flags(int flags) {
 | 
				
			||||||
    return openmode;
 | 
					    return openmode;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FILEHANDLE local_file_open(const char* name, int flags) {
 | 
					FILEHANDLE local_file_open(const char *name, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int openmode = posix_to_semihost_open_flags(flags);
 | 
					    int openmode = posix_to_semihost_open_flags(flags);
 | 
				
			||||||
    if (openmode == OPEN_INVALID) {
 | 
					    if (openmode == OPEN_INVALID) {
 | 
				
			||||||
        return (FILEHANDLE)NULL;
 | 
					        return (FILEHANDLE)NULL;
 | 
				
			||||||
| 
						 | 
					@ -108,42 +111,48 @@ FILEHANDLE local_file_open(const char* name, int flags) {
 | 
				
			||||||
    return fh;
 | 
					    return fh;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LocalFileHandle::LocalFileHandle(FILEHANDLE fh) : _fh(fh), pos(0) {
 | 
					LocalFileHandle::LocalFileHandle(FILEHANDLE fh) : _fh(fh), pos(0)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No lock needed in constructor
 | 
					    // No lock needed in constructor
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LocalFileHandle::close() {
 | 
					int LocalFileHandle::close()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int retval = semihost_close(_fh);
 | 
					    int retval = semihost_close(_fh);
 | 
				
			||||||
    delete this;
 | 
					    delete this;
 | 
				
			||||||
    return retval;
 | 
					    return retval;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t LocalFileHandle::write(const void *buffer, size_t length) {
 | 
					ssize_t LocalFileHandle::write(const void *buffer, size_t length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    ssize_t n = semihost_write(_fh, (const unsigned char*)buffer, length, 0); // number of characters not written
 | 
					    ssize_t n = semihost_write(_fh, (const unsigned char *)buffer, length, 0); // number of characters not written
 | 
				
			||||||
    n = length - n; // number of characters written
 | 
					    n = length - n; // number of characters written
 | 
				
			||||||
    pos += n;
 | 
					    pos += n;
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return n;
 | 
					    return n;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t LocalFileHandle::read(void *buffer, size_t length) {
 | 
					ssize_t LocalFileHandle::read(void *buffer, size_t length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    ssize_t n = semihost_read(_fh, (unsigned char*)buffer, length, 0); // number of characters not read
 | 
					    ssize_t n = semihost_read(_fh, (unsigned char *)buffer, length, 0); // number of characters not read
 | 
				
			||||||
    n = length - n; // number of characters read
 | 
					    n = length - n; // number of characters read
 | 
				
			||||||
    pos += n;
 | 
					    pos += n;
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return n;
 | 
					    return n;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LocalFileHandle::isatty() {
 | 
					int LocalFileHandle::isatty()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    int ret = semihost_istty(_fh);
 | 
					    int ret = semihost_istty(_fh);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
off_t LocalFileHandle::seek(off_t position, int whence) {
 | 
					off_t LocalFileHandle::seek(off_t position, int whence)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    if (whence == SEEK_CUR) {
 | 
					    if (whence == SEEK_CUR) {
 | 
				
			||||||
        position += pos;
 | 
					        position += pos;
 | 
				
			||||||
| 
						 | 
					@ -158,25 +167,29 @@ off_t LocalFileHandle::seek(off_t position, int whence) {
 | 
				
			||||||
    return position;
 | 
					    return position;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LocalFileHandle::sync() {
 | 
					int LocalFileHandle::sync()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    int ret = semihost_ensure(_fh);
 | 
					    int ret = semihost_ensure(_fh);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
off_t LocalFileHandle::size() {
 | 
					off_t LocalFileHandle::size()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    off_t off = semihost_flen(_fh);
 | 
					    off_t off = semihost_flen(_fh);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return off;
 | 
					    return off;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LocalFileHandle::lock() {
 | 
					void LocalFileHandle::lock()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex.lock();
 | 
					    _mutex.lock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LocalFileHandle::unlock() {
 | 
					void LocalFileHandle::unlock()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex.unlock();
 | 
					    _mutex.unlock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,18 +198,21 @@ class LocalDirHandle : public DirHandle {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    XFINFO info;
 | 
					    XFINFO info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LocalDirHandle() : info() {
 | 
					    LocalDirHandle() : info()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual int close() {
 | 
					    virtual int close()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // No lock can be used in destructor
 | 
					        // No lock can be used in destructor
 | 
				
			||||||
        delete this;
 | 
					        delete this;
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual int read(struct dirent *ent) {
 | 
					    virtual int read(struct dirent *ent)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        lock();
 | 
					        lock();
 | 
				
			||||||
        if (xffind("*", &info)!=0) {
 | 
					        if (xffind("*", &info) != 0) {
 | 
				
			||||||
            unlock();
 | 
					            unlock();
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -205,20 +221,23 @@ public:
 | 
				
			||||||
        return 1;
 | 
					        return 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void rewind() {
 | 
					    virtual void rewind()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        lock();
 | 
					        lock();
 | 
				
			||||||
        info.fileID = 0;
 | 
					        info.fileID = 0;
 | 
				
			||||||
        unlock();
 | 
					        unlock();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual off_t tell() {
 | 
					    virtual off_t tell()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        lock();
 | 
					        lock();
 | 
				
			||||||
        int fileId = info.fileID;
 | 
					        int fileId = info.fileID;
 | 
				
			||||||
        unlock();
 | 
					        unlock();
 | 
				
			||||||
        return fileId;
 | 
					        return fileId;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void seek(off_t offset) {
 | 
					    virtual void seek(off_t offset)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        lock();
 | 
					        lock();
 | 
				
			||||||
        info.fileID = offset;
 | 
					        info.fileID = offset;
 | 
				
			||||||
        unlock();
 | 
					        unlock();
 | 
				
			||||||
| 
						 | 
					@ -227,16 +246,19 @@ public:
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
    PlatformMutex _mutex;
 | 
					    PlatformMutex _mutex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void lock() {
 | 
					    virtual void lock()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        _mutex.lock();
 | 
					        _mutex.lock();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void unlock() {
 | 
					    virtual void unlock()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        _mutex.unlock();
 | 
					        _mutex.unlock();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LocalFileSystem::open(FileHandle **file, const char* name, int flags) {
 | 
					int LocalFileSystem::open(FileHandle **file, const char *name, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No global state modified so function is thread safe
 | 
					    // No global state modified so function is thread safe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* reject filenames with / in them */
 | 
					    /* reject filenames with / in them */
 | 
				
			||||||
| 
						 | 
					@ -260,13 +282,15 @@ int LocalFileSystem::open(FileHandle **file, const char* name, int flags) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LocalFileSystem::remove(const char *filename) {
 | 
					int LocalFileSystem::remove(const char *filename)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No global state modified so function is thread safe
 | 
					    // No global state modified so function is thread safe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return semihost_remove(filename);
 | 
					    return semihost_remove(filename);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LocalFileSystem::open(DirHandle **dir, const char *name) {
 | 
					int LocalFileSystem::open(DirHandle **dir, const char *name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No global state modified so function is thread safe
 | 
					    // No global state modified so function is thread safe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *dir = new LocalDirHandle();
 | 
					    *dir = new LocalDirHandle();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ namespace mbed {
 | 
				
			||||||
 * @{
 | 
					 * @{
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FILEHANDLE local_file_open(const char* name, int flags);
 | 
					FILEHANDLE local_file_open(const char *name, int flags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @class LocalFileHandle
 | 
					 * @class LocalFileHandle
 | 
				
			||||||
| 
						 | 
					@ -106,7 +106,8 @@ class LocalFileSystem : public FileSystemLike, private NonCopyable<LocalFileSyst
 | 
				
			||||||
    // No modifiable state
 | 
					    // No modifiable state
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    LocalFileSystem(const char* n) : FileSystemLike(n) {
 | 
					    LocalFileSystem(const char *n) : FileSystemLike(n)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -169,7 +169,7 @@ protected:
 | 
				
			||||||
     * Copy of non copyable resources can lead to resource leak and random error.
 | 
					     * Copy of non copyable resources can lead to resource leak and random error.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED("Invalid copy construction of a NonCopyable resource.")
 | 
					    MBED_DEPRECATED("Invalid copy construction of a NonCopyable resource.")
 | 
				
			||||||
    NonCopyable(const NonCopyable&)
 | 
					    NonCopyable(const NonCopyable &)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        debug("Invalid copy construction of a NonCopyable resource: %s\r\n", MBED_PRETTY_FUNCTION);
 | 
					        debug("Invalid copy construction of a NonCopyable resource: %s\r\n", MBED_PRETTY_FUNCTION);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -184,7 +184,7 @@ protected:
 | 
				
			||||||
     * Copy of non copyable resources can lead to resource leak and random error.
 | 
					     * Copy of non copyable resources can lead to resource leak and random error.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBED_DEPRECATED("Invalid copy assignment of a NonCopyable resource.")
 | 
					    MBED_DEPRECATED("Invalid copy assignment of a NonCopyable resource.")
 | 
				
			||||||
    NonCopyable& operator=(const NonCopyable&)
 | 
					    NonCopyable &operator=(const NonCopyable &)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        debug("Invalid copy assignment of a NonCopyable resource: %s\r\n", MBED_PRETTY_FUNCTION);
 | 
					        debug("Invalid copy assignment of a NonCopyable resource: %s\r\n", MBED_PRETTY_FUNCTION);
 | 
				
			||||||
        return *this;
 | 
					        return *this;
 | 
				
			||||||
| 
						 | 
					@ -196,13 +196,13 @@ private:
 | 
				
			||||||
     * Declare copy constructor as private, any attempt to copy construct
 | 
					     * Declare copy constructor as private, any attempt to copy construct
 | 
				
			||||||
     * a NonCopyable will fail at compile time.
 | 
					     * a NonCopyable will fail at compile time.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    NonCopyable(const NonCopyable&);
 | 
					    NonCopyable(const NonCopyable &);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Declare copy assignment operator as private, any attempt to copy assign
 | 
					     * Declare copy assignment operator as private, any attempt to copy assign
 | 
				
			||||||
     * a NonCopyable will fail at compile time.
 | 
					     * a NonCopyable will fail at compile time.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    NonCopyable& operator=(const NonCopyable&);
 | 
					    NonCopyable &operator=(const NonCopyable &);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,19 +33,23 @@ typedef rtos::Mutex PlatformMutex;
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
class PlatformMutex : private mbed::NonCopyable<PlatformMutex> {
 | 
					class PlatformMutex : private mbed::NonCopyable<PlatformMutex> {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    PlatformMutex() {
 | 
					    PlatformMutex()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Stub
 | 
					        // Stub
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ~PlatformMutex() {
 | 
					    ~PlatformMutex()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Stub
 | 
					        // Stub
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void lock() {
 | 
					    void lock()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Do nothing
 | 
					        // Do nothing
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void unlock() {
 | 
					    void unlock()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Do nothing
 | 
					        // Do nothing
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ public:
 | 
				
			||||||
     * @param lockable reference to the instance of Lockable object
 | 
					     * @param lockable reference to the instance of Lockable object
 | 
				
			||||||
     * @note lockable object should outlive the ScopedLock object
 | 
					     * @note lockable object should outlive the ScopedLock object
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ScopedLock(Lockable& lockable): _lockable(lockable)
 | 
					    ScopedLock(Lockable &lockable): _lockable(lockable)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _lockable.lock();
 | 
					        _lockable.lock();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -75,7 +75,7 @@ public:
 | 
				
			||||||
        _lockable.unlock();
 | 
					        _lockable.unlock();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    Lockable& _lockable;
 | 
					    Lockable &_lockable;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**@}*/
 | 
					/**@}*/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,7 +56,7 @@ inline static void singleton_lock(void)
 | 
				
			||||||
inline static void singleton_unlock(void)
 | 
					inline static void singleton_unlock(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifdef MBED_CONF_RTOS_PRESENT
 | 
					#ifdef MBED_CONF_RTOS_PRESENT
 | 
				
			||||||
    osMutexRelease (singleton_mutex_id);
 | 
					    osMutexRelease(singleton_mutex_id);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,7 +80,8 @@ struct SingletonPtr {
 | 
				
			||||||
     * @returns
 | 
					     * @returns
 | 
				
			||||||
     *   A pointer to the singleton
 | 
					     *   A pointer to the singleton
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    T* get() {
 | 
					    T *get()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        if (NULL == _ptr) {
 | 
					        if (NULL == _ptr) {
 | 
				
			||||||
            singleton_lock();
 | 
					            singleton_lock();
 | 
				
			||||||
            if (NULL == _ptr) {
 | 
					            if (NULL == _ptr) {
 | 
				
			||||||
| 
						 | 
					@ -99,7 +100,8 @@ struct SingletonPtr {
 | 
				
			||||||
     * @returns
 | 
					     * @returns
 | 
				
			||||||
     *   A pointer to the singleton
 | 
					     *   A pointer to the singleton
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    T* operator->() {
 | 
					    T *operator->()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return get();
 | 
					        return get();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace mbed {
 | 
					namespace mbed {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
 | 
					Stream::Stream(const char *name) : FileLike(name), _file(NULL)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No lock needed in constructor
 | 
					    // No lock needed in constructor
 | 
				
			||||||
    /* open ourselves */
 | 
					    /* open ourselves */
 | 
				
			||||||
    _file = fdopen(this, "w+");
 | 
					    _file = fdopen(this, "w+");
 | 
				
			||||||
| 
						 | 
					@ -33,47 +34,54 @@ Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Stream::~Stream() {
 | 
					Stream::~Stream()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // No lock can be used in destructor
 | 
					    // No lock can be used in destructor
 | 
				
			||||||
    fclose(_file);
 | 
					    fclose(_file);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::putc(int c) {
 | 
					int Stream::putc(int c)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    fflush(_file);
 | 
					    fflush(_file);
 | 
				
			||||||
    int ret = std::fputc(c, _file);
 | 
					    int ret = std::fputc(c, _file);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
int Stream::puts(const char *s) {
 | 
					int Stream::puts(const char *s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    fflush(_file);
 | 
					    fflush(_file);
 | 
				
			||||||
    int ret = std::fputs(s, _file);
 | 
					    int ret = std::fputs(s, _file);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
int Stream::getc() {
 | 
					int Stream::getc()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    fflush(_file);
 | 
					    fflush(_file);
 | 
				
			||||||
    int ret = mbed_getc(_file);
 | 
					    int ret = mbed_getc(_file);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
char* Stream::gets(char *s, int size) {
 | 
					char *Stream::gets(char *s, int size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    fflush(_file);
 | 
					    fflush(_file);
 | 
				
			||||||
    char *ret = mbed_gets(s,size,_file);
 | 
					    char *ret = mbed_gets(s, size, _file);
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::close() {
 | 
					int Stream::close()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t Stream::write(const void* buffer, size_t length) {
 | 
					ssize_t Stream::write(const void *buffer, size_t length)
 | 
				
			||||||
    const char* ptr = (const char*)buffer;
 | 
					{
 | 
				
			||||||
    const char* end = ptr + length;
 | 
					    const char *ptr = (const char *)buffer;
 | 
				
			||||||
 | 
					    const char *end = ptr + length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    while (ptr != end) {
 | 
					    while (ptr != end) {
 | 
				
			||||||
| 
						 | 
					@ -83,48 +91,58 @@ ssize_t Stream::write(const void* buffer, size_t length) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ptr - (const char*)buffer;
 | 
					    return ptr - (const char *)buffer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t Stream::read(void* buffer, size_t length) {
 | 
					ssize_t Stream::read(void *buffer, size_t length)
 | 
				
			||||||
    char* ptr = (char*)buffer;
 | 
					{
 | 
				
			||||||
    char* end = ptr + length;
 | 
					    char *ptr = (char *)buffer;
 | 
				
			||||||
 | 
					    char *end = ptr + length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    while (ptr != end) {
 | 
					    while (ptr != end) {
 | 
				
			||||||
        int c = _getc();
 | 
					        int c = _getc();
 | 
				
			||||||
        if (c==EOF) break;
 | 
					        if (c == EOF) {
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        *ptr++ = c;
 | 
					        *ptr++ = c;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    unlock();
 | 
					    unlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ptr - (const char*)buffer;
 | 
					    return ptr - (const char *)buffer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
off_t Stream::seek(off_t offset, int whence) {
 | 
					off_t Stream::seek(off_t offset, int whence)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
off_t Stream::tell() {
 | 
					off_t Stream::tell()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Stream::rewind() {
 | 
					void Stream::rewind()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::isatty() {
 | 
					int Stream::isatty()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::sync() {
 | 
					int Stream::sync()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
off_t Stream::size() {
 | 
					off_t Stream::size()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::printf(const char* format, ...) {
 | 
					int Stream::printf(const char *format, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    std::va_list arg;
 | 
					    std::va_list arg;
 | 
				
			||||||
    va_start(arg, format);
 | 
					    va_start(arg, format);
 | 
				
			||||||
| 
						 | 
					@ -135,7 +153,8 @@ int Stream::printf(const char* format, ...) {
 | 
				
			||||||
    return r;
 | 
					    return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::scanf(const char* format, ...) {
 | 
					int Stream::scanf(const char *format, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    std::va_list arg;
 | 
					    std::va_list arg;
 | 
				
			||||||
    va_start(arg, format);
 | 
					    va_start(arg, format);
 | 
				
			||||||
| 
						 | 
					@ -146,7 +165,8 @@ int Stream::scanf(const char* format, ...) {
 | 
				
			||||||
    return r;
 | 
					    return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::vprintf(const char* format, std::va_list args) {
 | 
					int Stream::vprintf(const char *format, std::va_list args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    fflush(_file);
 | 
					    fflush(_file);
 | 
				
			||||||
    int r = vfprintf(_file, format, args);
 | 
					    int r = vfprintf(_file, format, args);
 | 
				
			||||||
| 
						 | 
					@ -154,7 +174,8 @@ int Stream::vprintf(const char* format, std::va_list args) {
 | 
				
			||||||
    return r;
 | 
					    return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Stream::vscanf(const char* format, std::va_list args) {
 | 
					int Stream::vscanf(const char *format, std::va_list args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    lock();
 | 
					    lock();
 | 
				
			||||||
    fflush(_file);
 | 
					    fflush(_file);
 | 
				
			||||||
    int r = vfscanf(_file, format, args);
 | 
					    int r = vfscanf(_file, format, args);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,7 @@ namespace mbed {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void mbed_set_unbuffered_stream(std::FILE *_file);
 | 
					extern void mbed_set_unbuffered_stream(std::FILE *_file);
 | 
				
			||||||
extern int mbed_getc(std::FILE *_file);
 | 
					extern int mbed_getc(std::FILE *_file);
 | 
				
			||||||
extern char* mbed_gets(char *s, int size, std::FILE *_file);
 | 
					extern char *mbed_gets(char *s, int size, std::FILE *_file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** File stream
 | 
					/** File stream
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -42,24 +42,27 @@ extern char* mbed_gets(char *s, int size, std::FILE *_file);
 | 
				
			||||||
class Stream : public FileLike, private NonCopyable<Stream> {
 | 
					class Stream : public FileLike, private NonCopyable<Stream> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    Stream(const char *name=NULL);
 | 
					    Stream(const char *name = NULL);
 | 
				
			||||||
    virtual ~Stream();
 | 
					    virtual ~Stream();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int putc(int c);
 | 
					    int putc(int c);
 | 
				
			||||||
    int puts(const char *s);
 | 
					    int puts(const char *s);
 | 
				
			||||||
    int getc();
 | 
					    int getc();
 | 
				
			||||||
    char *gets(char *s, int size);
 | 
					    char *gets(char *s, int size);
 | 
				
			||||||
    int printf(const char* format, ...);
 | 
					    int printf(const char *format, ...);
 | 
				
			||||||
    int scanf(const char* format, ...);
 | 
					    int scanf(const char *format, ...);
 | 
				
			||||||
    int vprintf(const char* format, std::va_list args);
 | 
					    int vprintf(const char *format, std::va_list args);
 | 
				
			||||||
    int vscanf(const char* format, std::va_list args);
 | 
					    int vscanf(const char *format, std::va_list args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    operator std::FILE*() {return _file;}
 | 
					    operator std::FILE *()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return _file;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
    virtual int close();
 | 
					    virtual int close();
 | 
				
			||||||
    virtual ssize_t write(const void* buffer, size_t length);
 | 
					    virtual ssize_t write(const void *buffer, size_t length);
 | 
				
			||||||
    virtual ssize_t read(void* buffer, size_t length);
 | 
					    virtual ssize_t read(void *buffer, size_t length);
 | 
				
			||||||
    virtual off_t seek(off_t offset, int whence);
 | 
					    virtual off_t seek(off_t offset, int whence);
 | 
				
			||||||
    virtual off_t tell();
 | 
					    virtual off_t tell();
 | 
				
			||||||
    virtual void rewind();
 | 
					    virtual void rewind();
 | 
				
			||||||
| 
						 | 
					@ -74,13 +77,15 @@ protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Acquire exclusive access to this object.
 | 
					    /** Acquire exclusive access to this object.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    virtual void lock() {
 | 
					    virtual void lock()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Stub
 | 
					        // Stub
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Release exclusive access to this object.
 | 
					    /** Release exclusive access to this object.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    virtual void unlock() {
 | 
					    virtual void unlock()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Stub
 | 
					        // Stub
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,20 +46,24 @@ typedef struct {
 | 
				
			||||||
template<typename Class>
 | 
					template<typename Class>
 | 
				
			||||||
class Transaction {
 | 
					class Transaction {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    Transaction(Class *tpointer, const transaction_t& transaction) : _obj(tpointer), _data(transaction) {
 | 
					    Transaction(Class *tpointer, const transaction_t &transaction) : _obj(tpointer), _data(transaction)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Transaction() : _obj(), _data() {
 | 
					    Transaction() : _obj(), _data()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ~Transaction() {
 | 
					    ~Transaction()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Get object's instance for the transaction
 | 
					    /** Get object's instance for the transaction
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return The object which was stored
 | 
					     * @return The object which was stored
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    Class* get_object() {
 | 
					    Class *get_object()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return _obj;
 | 
					        return _obj;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,12 +71,13 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return The transaction which was stored
 | 
					     * @return The transaction which was stored
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    transaction_t* get_transaction() {
 | 
					    transaction_t *get_transaction()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return &_data;
 | 
					        return &_data;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    Class* _obj;
 | 
					    Class *_obj;
 | 
				
			||||||
    transaction_t _data;
 | 
					    transaction_t _data;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
/**@}*/
 | 
					/**@}*/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,74 @@
 | 
				
			||||||
 | 
					Formatted  .\ATCmdParser.cpp
 | 
				
			||||||
 | 
					Formatted  .\ATCmdParser.h
 | 
				
			||||||
 | 
					Formatted  .\Callback.h
 | 
				
			||||||
 | 
					Formatted  .\CallChain.cpp
 | 
				
			||||||
 | 
					Formatted  .\CallChain.h
 | 
				
			||||||
 | 
					Formatted  .\CircularBuffer.h
 | 
				
			||||||
 | 
					Unchanged  .\critical.h
 | 
				
			||||||
 | 
					Formatted  .\CriticalSectionLock.h
 | 
				
			||||||
 | 
					Formatted  .\CThunk.h
 | 
				
			||||||
 | 
					Unchanged  .\DeepSleepLock.h
 | 
				
			||||||
 | 
					Formatted  .\DirHandle.h
 | 
				
			||||||
 | 
					Formatted  .\FileBase.cpp
 | 
				
			||||||
 | 
					Formatted  .\FileBase.h
 | 
				
			||||||
 | 
					Unchanged  .\FileHandle.cpp
 | 
				
			||||||
 | 
					Formatted  .\FileHandle.h
 | 
				
			||||||
 | 
					Unchanged  .\FileLike.h
 | 
				
			||||||
 | 
					Formatted  .\FilePath.cpp
 | 
				
			||||||
 | 
					Formatted  .\FilePath.h
 | 
				
			||||||
 | 
					Unchanged  .\FileSystemHandle.cpp
 | 
				
			||||||
 | 
					Formatted  .\FileSystemHandle.h
 | 
				
			||||||
 | 
					Formatted  .\FileSystemLike.h
 | 
				
			||||||
 | 
					Formatted  .\FunctionPointer.h
 | 
				
			||||||
 | 
					Formatted  .\LocalFileSystem.cpp
 | 
				
			||||||
 | 
					Formatted  .\LocalFileSystem.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_alloc_wrappers.cpp
 | 
				
			||||||
 | 
					Formatted  .\mbed_application.c
 | 
				
			||||||
 | 
					Unchanged  .\mbed_application.h
 | 
				
			||||||
 | 
					Unchanged  .\mbed_assert.c
 | 
				
			||||||
 | 
					Unchanged  .\mbed_assert.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_board.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_critical.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_critical.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_debug.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_error.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_error.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_error_hist.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_error_hist.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_interface.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_interface.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_mem_trace.cpp
 | 
				
			||||||
 | 
					Formatted  .\mbed_mem_trace.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_mktime.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_mktime.h
 | 
				
			||||||
 | 
					Unchanged  .\mbed_poll.cpp
 | 
				
			||||||
 | 
					Unchanged  .\mbed_poll.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_power_mgmt.h
 | 
				
			||||||
 | 
					Unchanged  .\mbed_preprocessor.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_retarget.cpp
 | 
				
			||||||
 | 
					Formatted  .\mbed_retarget.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_rtc_time.cpp
 | 
				
			||||||
 | 
					Unchanged  .\mbed_rtc_time.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_sdk_boot.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_semihost_api.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_semihost_api.h
 | 
				
			||||||
 | 
					Unchanged  .\mbed_sleep.h
 | 
				
			||||||
 | 
					Unchanged  .\mbed_stats.c
 | 
				
			||||||
 | 
					Unchanged  .\mbed_stats.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_toolchain.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_wait_api.h
 | 
				
			||||||
 | 
					Formatted  .\mbed_wait_api_no_rtos.c
 | 
				
			||||||
 | 
					Formatted  .\mbed_wait_api_rtos.cpp
 | 
				
			||||||
 | 
					Formatted  .\NonCopyable.h
 | 
				
			||||||
 | 
					Unchanged  .\platform.h
 | 
				
			||||||
 | 
					Formatted  .\PlatformMutex.h
 | 
				
			||||||
 | 
					Unchanged  .\rtc_time.h
 | 
				
			||||||
 | 
					Formatted  .\ScopedLock.h
 | 
				
			||||||
 | 
					Unchanged  .\semihost_api.h
 | 
				
			||||||
 | 
					Formatted  .\SingletonPtr.h
 | 
				
			||||||
 | 
					Unchanged  .\sleep.h
 | 
				
			||||||
 | 
					Formatted  .\Stream.cpp
 | 
				
			||||||
 | 
					Formatted  .\Stream.h
 | 
				
			||||||
 | 
					Unchanged  .\toolchain.h
 | 
				
			||||||
 | 
					Formatted  .\Transaction.h
 | 
				
			||||||
 | 
					Unchanged  .\wait_api.h
 | 
				
			||||||
| 
						 | 
					@ -76,33 +76,35 @@ void mbed_stats_heap_get(mbed_stats_heap_t *stats)
 | 
				
			||||||
#endif/* FEATURE_UVISOR */
 | 
					#endif/* FEATURE_UVISOR */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
    void * __real__malloc_r(struct _reent * r, size_t size);
 | 
					    void *__real__malloc_r(struct _reent *r, size_t size);
 | 
				
			||||||
    void * __real__memalign_r(struct _reent * r, size_t alignment, size_t bytes);
 | 
					    void *__real__memalign_r(struct _reent *r, size_t alignment, size_t bytes);
 | 
				
			||||||
    void * __real__realloc_r(struct _reent * r, void * ptr, size_t size);
 | 
					    void *__real__realloc_r(struct _reent *r, void *ptr, size_t size);
 | 
				
			||||||
    void __real__free_r(struct _reent * r, void * ptr);
 | 
					    void __real__free_r(struct _reent *r, void *ptr);
 | 
				
			||||||
    void* __real__calloc_r(struct _reent * r, size_t nmemb, size_t size);
 | 
					    void *__real__calloc_r(struct _reent *r, size_t nmemb, size_t size);
 | 
				
			||||||
    void* malloc_wrapper(struct _reent * r, size_t size, void * caller);
 | 
					    void *malloc_wrapper(struct _reent *r, size_t size, void *caller);
 | 
				
			||||||
    void free_wrapper(struct _reent * r, void * ptr, void* caller);
 | 
					    void free_wrapper(struct _reent *r, void *ptr, void *caller);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: memory tracing doesn't work with uVisor enabled.
 | 
					// TODO: memory tracing doesn't work with uVisor enabled.
 | 
				
			||||||
#if !defined(FEATURE_UVISOR)
 | 
					#if !defined(FEATURE_UVISOR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void * __wrap__malloc_r(struct _reent * r, size_t size) {
 | 
					extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return malloc_wrapper(r, size, MBED_CALLER_ADDR());
 | 
					    return malloc_wrapper(r, size, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void * malloc_wrapper(struct _reent * r, size_t size, void * caller) {
 | 
					extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    void *ptr = NULL;
 | 
					    void *ptr = NULL;
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef MBED_HEAP_STATS_ENABLED
 | 
					#ifdef MBED_HEAP_STATS_ENABLED
 | 
				
			||||||
    malloc_stats_mutex->lock();
 | 
					    malloc_stats_mutex->lock();
 | 
				
			||||||
    alloc_info_t *alloc_info = (alloc_info_t*)__real__malloc_r(r, size + sizeof(alloc_info_t));
 | 
					    alloc_info_t *alloc_info = (alloc_info_t *)__real__malloc_r(r, size + sizeof(alloc_info_t));
 | 
				
			||||||
    if (alloc_info != NULL) {
 | 
					    if (alloc_info != NULL) {
 | 
				
			||||||
        alloc_info->size = size;
 | 
					        alloc_info->size = size;
 | 
				
			||||||
        ptr = (void*)(alloc_info + 1);
 | 
					        ptr = (void *)(alloc_info + 1);
 | 
				
			||||||
        heap_stats.current_size += size;
 | 
					        heap_stats.current_size += size;
 | 
				
			||||||
        heap_stats.total_size += size;
 | 
					        heap_stats.total_size += size;
 | 
				
			||||||
        heap_stats.alloc_cnt += 1;
 | 
					        heap_stats.alloc_cnt += 1;
 | 
				
			||||||
| 
						 | 
					@ -123,7 +125,8 @@ extern "C" void * malloc_wrapper(struct _reent * r, size_t size, void * caller)
 | 
				
			||||||
    return ptr;
 | 
					    return ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size) {
 | 
					extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    void *new_ptr = NULL;
 | 
					    void *new_ptr = NULL;
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
| 
						 | 
					@ -139,7 +142,7 @@ extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size)
 | 
				
			||||||
    // Get old size
 | 
					    // Get old size
 | 
				
			||||||
    uint32_t old_size = 0;
 | 
					    uint32_t old_size = 0;
 | 
				
			||||||
    if (ptr != NULL) {
 | 
					    if (ptr != NULL) {
 | 
				
			||||||
        alloc_info_t *alloc_info = ((alloc_info_t*)ptr) - 1;
 | 
					        alloc_info_t *alloc_info = ((alloc_info_t *)ptr) - 1;
 | 
				
			||||||
        old_size = alloc_info->size;
 | 
					        old_size = alloc_info->size;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -152,7 +155,7 @@ extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size)
 | 
				
			||||||
    // and free the old buffer
 | 
					    // and free the old buffer
 | 
				
			||||||
    if (new_ptr != NULL) {
 | 
					    if (new_ptr != NULL) {
 | 
				
			||||||
        uint32_t copy_size = (old_size < size) ? old_size : size;
 | 
					        uint32_t copy_size = (old_size < size) ? old_size : size;
 | 
				
			||||||
        memcpy(new_ptr, (void*)ptr, copy_size);
 | 
					        memcpy(new_ptr, (void *)ptr, copy_size);
 | 
				
			||||||
        free(ptr);
 | 
					        free(ptr);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
					#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
				
			||||||
| 
						 | 
					@ -165,11 +168,13 @@ extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size)
 | 
				
			||||||
    return new_ptr;
 | 
					    return new_ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void __wrap__free_r(struct _reent * r, void * ptr) {
 | 
					extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    free_wrapper(r, ptr, MBED_CALLER_ADDR());
 | 
					    free_wrapper(r, ptr, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void free_wrapper(struct _reent * r, void * ptr, void * caller) {
 | 
					extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -177,11 +182,11 @@ extern "C" void free_wrapper(struct _reent * r, void * ptr, void * caller) {
 | 
				
			||||||
    malloc_stats_mutex->lock();
 | 
					    malloc_stats_mutex->lock();
 | 
				
			||||||
    alloc_info_t *alloc_info = NULL;
 | 
					    alloc_info_t *alloc_info = NULL;
 | 
				
			||||||
    if (ptr != NULL) {
 | 
					    if (ptr != NULL) {
 | 
				
			||||||
        alloc_info = ((alloc_info_t*)ptr) - 1;
 | 
					        alloc_info = ((alloc_info_t *)ptr) - 1;
 | 
				
			||||||
        heap_stats.current_size -= alloc_info->size;
 | 
					        heap_stats.current_size -= alloc_info->size;
 | 
				
			||||||
        heap_stats.alloc_cnt -= 1;
 | 
					        heap_stats.alloc_cnt -= 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    __real__free_r(r, (void*)alloc_info);
 | 
					    __real__free_r(r, (void *)alloc_info);
 | 
				
			||||||
    malloc_stats_mutex->unlock();
 | 
					    malloc_stats_mutex->unlock();
 | 
				
			||||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
					#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
				
			||||||
    __real__free_r(r, ptr);
 | 
					    __real__free_r(r, ptr);
 | 
				
			||||||
| 
						 | 
					@ -192,7 +197,8 @@ extern "C" void free_wrapper(struct _reent * r, void * ptr, void * caller) {
 | 
				
			||||||
#endif // #ifdef MBED_MEM_TRACING_ENABLED
 | 
					#endif // #ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void * __wrap__calloc_r(struct _reent * r, size_t nmemb, size_t size) {
 | 
					extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    void *ptr = NULL;
 | 
					    void *ptr = NULL;
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
| 
						 | 
					@ -214,7 +220,8 @@ extern "C" void * __wrap__calloc_r(struct _reent * r, size_t nmemb, size_t size)
 | 
				
			||||||
    return ptr;
 | 
					    return ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void * __wrap__memalign_r(struct _reent * r, size_t alignment, size_t bytes) {
 | 
					extern "C" void *__wrap__memalign_r(struct _reent *r, size_t alignment, size_t bytes)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __real__memalign_r(r, alignment, bytes);
 | 
					    return __real__memalign_r(r, alignment, bytes);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -255,26 +262,28 @@ extern "C" {
 | 
				
			||||||
    void *SUPER_REALLOC(void *ptr, size_t size);
 | 
					    void *SUPER_REALLOC(void *ptr, size_t size);
 | 
				
			||||||
    void *SUPER_CALLOC(size_t nmemb, size_t size);
 | 
					    void *SUPER_CALLOC(size_t nmemb, size_t size);
 | 
				
			||||||
    void SUPER_FREE(void *ptr);
 | 
					    void SUPER_FREE(void *ptr);
 | 
				
			||||||
    void *malloc_wrapper(size_t size, void* caller);
 | 
					    void *malloc_wrapper(size_t size, void *caller);
 | 
				
			||||||
    void free_wrapper(void *ptr, void* caller);
 | 
					    void free_wrapper(void *ptr, void *caller);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void* SUB_MALLOC(size_t size) {
 | 
					extern "C" void *SUB_MALLOC(size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return malloc_wrapper(size, MBED_CALLER_ADDR());
 | 
					    return malloc_wrapper(size, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void* malloc_wrapper(size_t size, void* caller) {
 | 
					extern "C" void *malloc_wrapper(size_t size, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    void *ptr = NULL;
 | 
					    void *ptr = NULL;
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef MBED_HEAP_STATS_ENABLED
 | 
					#ifdef MBED_HEAP_STATS_ENABLED
 | 
				
			||||||
    malloc_stats_mutex->lock();
 | 
					    malloc_stats_mutex->lock();
 | 
				
			||||||
    alloc_info_t *alloc_info = (alloc_info_t*)SUPER_MALLOC(size + sizeof(alloc_info_t));
 | 
					    alloc_info_t *alloc_info = (alloc_info_t *)SUPER_MALLOC(size + sizeof(alloc_info_t));
 | 
				
			||||||
    if (alloc_info != NULL) {
 | 
					    if (alloc_info != NULL) {
 | 
				
			||||||
        alloc_info->size = size;
 | 
					        alloc_info->size = size;
 | 
				
			||||||
        ptr = (void*)(alloc_info + 1);
 | 
					        ptr = (void *)(alloc_info + 1);
 | 
				
			||||||
        heap_stats.current_size += size;
 | 
					        heap_stats.current_size += size;
 | 
				
			||||||
        heap_stats.total_size += size;
 | 
					        heap_stats.total_size += size;
 | 
				
			||||||
        heap_stats.alloc_cnt += 1;
 | 
					        heap_stats.alloc_cnt += 1;
 | 
				
			||||||
| 
						 | 
					@ -296,7 +305,8 @@ extern "C" void* malloc_wrapper(size_t size, void* caller) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
					extern "C" void *SUB_REALLOC(void *ptr, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    void *new_ptr = NULL;
 | 
					    void *new_ptr = NULL;
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
| 
						 | 
					@ -307,7 +317,7 @@ extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
				
			||||||
    // Get old size
 | 
					    // Get old size
 | 
				
			||||||
    uint32_t old_size = 0;
 | 
					    uint32_t old_size = 0;
 | 
				
			||||||
    if (ptr != NULL) {
 | 
					    if (ptr != NULL) {
 | 
				
			||||||
        alloc_info_t *alloc_info = ((alloc_info_t*)ptr) - 1;
 | 
					        alloc_info_t *alloc_info = ((alloc_info_t *)ptr) - 1;
 | 
				
			||||||
        old_size = alloc_info->size;
 | 
					        old_size = alloc_info->size;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -320,7 +330,7 @@ extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
				
			||||||
    // and free the old buffer
 | 
					    // and free the old buffer
 | 
				
			||||||
    if (new_ptr != NULL) {
 | 
					    if (new_ptr != NULL) {
 | 
				
			||||||
        uint32_t copy_size = (old_size < size) ? old_size : size;
 | 
					        uint32_t copy_size = (old_size < size) ? old_size : size;
 | 
				
			||||||
        memcpy(new_ptr, (void*)ptr, copy_size);
 | 
					        memcpy(new_ptr, (void *)ptr, copy_size);
 | 
				
			||||||
        free(ptr);
 | 
					        free(ptr);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
					#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
				
			||||||
| 
						 | 
					@ -333,7 +343,8 @@ extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
				
			||||||
    return new_ptr;
 | 
					    return new_ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) {
 | 
					extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    void *ptr = NULL;
 | 
					    void *ptr = NULL;
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
| 
						 | 
					@ -354,11 +365,13 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) {
 | 
				
			||||||
    return ptr;
 | 
					    return ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void SUB_FREE(void *ptr) {
 | 
					extern "C" void SUB_FREE(void *ptr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    free_wrapper(ptr, MBED_CALLER_ADDR());
 | 
					    free_wrapper(ptr, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void free_wrapper(void *ptr, void* caller) {
 | 
					extern "C" void free_wrapper(void *ptr, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
					#ifdef MBED_MEM_TRACING_ENABLED
 | 
				
			||||||
    mbed_mem_trace_lock();
 | 
					    mbed_mem_trace_lock();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -366,11 +379,11 @@ extern "C" void free_wrapper(void *ptr, void* caller) {
 | 
				
			||||||
    malloc_stats_mutex->lock();
 | 
					    malloc_stats_mutex->lock();
 | 
				
			||||||
    alloc_info_t *alloc_info = NULL;
 | 
					    alloc_info_t *alloc_info = NULL;
 | 
				
			||||||
    if (ptr != NULL) {
 | 
					    if (ptr != NULL) {
 | 
				
			||||||
        alloc_info = ((alloc_info_t*)ptr) - 1;
 | 
					        alloc_info = ((alloc_info_t *)ptr) - 1;
 | 
				
			||||||
        heap_stats.current_size -= alloc_info->size;
 | 
					        heap_stats.current_size -= alloc_info->size;
 | 
				
			||||||
        heap_stats.alloc_cnt -= 1;
 | 
					        heap_stats.alloc_cnt -= 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    SUPER_FREE((void*)alloc_info);
 | 
					    SUPER_FREE((void *)alloc_info);
 | 
				
			||||||
    malloc_stats_mutex->unlock();
 | 
					    malloc_stats_mutex->unlock();
 | 
				
			||||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
					#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
				
			||||||
    SUPER_FREE(ptr);
 | 
					    SUPER_FREE(ptr);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,8 +46,8 @@ void mbed_start_application(uintptr_t address)
 | 
				
			||||||
    powerdown_nvic();
 | 
					    powerdown_nvic();
 | 
				
			||||||
    powerdown_scb(address);
 | 
					    powerdown_scb(address);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sp = *((void**)address + 0);
 | 
					    sp = *((void **)address + 0);
 | 
				
			||||||
    pc = *((void**)address + 1);
 | 
					    pc = *((void **)address + 1);
 | 
				
			||||||
    start_new_application(sp, pc);
 | 
					    start_new_application(sp, pc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,16 +133,16 @@ __asm static void start_new_application(void *sp, void *pc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void start_new_application(void *sp, void *pc)
 | 
					void start_new_application(void *sp, void *pc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    __asm volatile (
 | 
					    __asm volatile(
 | 
				
			||||||
        "movw   r2, #0      \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with MOVW.
 | 
					        "movw   r2, #0      \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with MOVW.
 | 
				
			||||||
                                // We needn't "movt r2, #0" immediately following because MOVW
 | 
					        // We needn't "movt r2, #0" immediately following because MOVW
 | 
				
			||||||
                                // will zero-extend the 16-bit immediate.
 | 
					        // will zero-extend the 16-bit immediate.
 | 
				
			||||||
        "msr    control, r2 \n" // Switch to main stack
 | 
					        "msr    control, r2 \n" // Switch to main stack
 | 
				
			||||||
        "mov    sp, %0      \n"
 | 
					        "mov    sp, %0      \n"
 | 
				
			||||||
        "msr    primask, r2 \n" // Enable interrupts
 | 
					        "msr    primask, r2 \n" // Enable interrupts
 | 
				
			||||||
        "bx     %1          \n"
 | 
					        "bx     %1          \n"
 | 
				
			||||||
        :
 | 
					        :
 | 
				
			||||||
        : "l" (sp), "l" (pc)
 | 
					        : "l"(sp), "l"(pc)
 | 
				
			||||||
        : "r2", "cc", "memory"
 | 
					        : "r2", "cc", "memory"
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,11 +26,13 @@ extern int stdio_uart_inited;
 | 
				
			||||||
extern serial_t stdio_uart;
 | 
					extern serial_t stdio_uart;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WEAK void mbed_die(void) {
 | 
					WEAK void mbed_die(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if !defined (NRF51_H) && !defined(TARGET_EFM32)
 | 
					#if !defined (NRF51_H) && !defined(TARGET_EFM32)
 | 
				
			||||||
    core_util_critical_section_enter();
 | 
					    core_util_critical_section_enter();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    gpio_t led_err; gpio_init_out(&led_err, LED1);
 | 
					    gpio_t led_err;
 | 
				
			||||||
 | 
					    gpio_init_out(&led_err, LED1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (1) {
 | 
					    while (1) {
 | 
				
			||||||
        for (int i = 0; i < 4; ++i) {
 | 
					        for (int i = 0; i < 4; ++i) {
 | 
				
			||||||
| 
						 | 
					@ -49,14 +51,16 @@ WEAK void mbed_die(void) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbed_error_printf(const char* format, ...) {
 | 
					void mbed_error_printf(const char *format, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    va_list arg;
 | 
					    va_list arg;
 | 
				
			||||||
    va_start(arg, format);
 | 
					    va_start(arg, format);
 | 
				
			||||||
    mbed_error_vfprintf(format, arg);
 | 
					    mbed_error_vfprintf(format, arg);
 | 
				
			||||||
    va_end(arg);
 | 
					    va_end(arg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbed_error_vfprintf(const char * format, va_list arg) {
 | 
					void mbed_error_vfprintf(const char *format, va_list arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if DEVICE_SERIAL
 | 
					#if DEVICE_SERIAL
 | 
				
			||||||
#define ERROR_BUF_SIZE      (128)
 | 
					#define ERROR_BUF_SIZE      (128)
 | 
				
			||||||
    core_util_critical_section_enter();
 | 
					    core_util_critical_section_enter();
 | 
				
			||||||
| 
						 | 
					@ -70,7 +74,7 @@ void mbed_error_vfprintf(const char * format, va_list arg) {
 | 
				
			||||||
        char stdio_out_prev = '\0';
 | 
					        char stdio_out_prev = '\0';
 | 
				
			||||||
        for (int i = 0; i < size; i++) {
 | 
					        for (int i = 0; i < size; i++) {
 | 
				
			||||||
            if (buffer[i] == '\n' && stdio_out_prev != '\r') {
 | 
					            if (buffer[i] == '\n' && stdio_out_prev != '\r') {
 | 
				
			||||||
                 serial_putc(&stdio_uart, '\r');
 | 
					                serial_putc(&stdio_uart, '\r');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            serial_putc(&stdio_uart, buffer[i]);
 | 
					            serial_putc(&stdio_uart, buffer[i]);
 | 
				
			||||||
            stdio_out_prev = buffer[i];
 | 
					            stdio_out_prev = buffer[i];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@ bool core_util_are_interrupts_enabled(void)
 | 
				
			||||||
bool core_util_is_isr_active(void)
 | 
					bool core_util_is_isr_active(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(__CORTEX_A9)
 | 
					#if defined(__CORTEX_A9)
 | 
				
			||||||
    switch(__get_CPSR() & 0x1FU) {
 | 
					    switch (__get_CPSR() & 0x1FU) {
 | 
				
			||||||
        case CPSR_M_USR:
 | 
					        case CPSR_M_USR:
 | 
				
			||||||
        case CPSR_M_SYS:
 | 
					        case CPSR_M_SYS:
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
| 
						 | 
					@ -79,7 +79,7 @@ void core_util_critical_section_enter(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
// FIXME
 | 
					// FIXME
 | 
				
			||||||
#ifdef FEATURE_UVISOR
 | 
					#ifdef FEATURE_UVISOR
 | 
				
			||||||
    #warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
 | 
					#warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    // If the reentrancy counter overflows something has gone badly wrong.
 | 
					    // If the reentrancy counter overflows something has gone badly wrong.
 | 
				
			||||||
    MBED_ASSERT(critical_section_reentrancy_counter < UINT32_MAX);
 | 
					    MBED_ASSERT(critical_section_reentrancy_counter < UINT32_MAX);
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ void core_util_critical_section_exit(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
// FIXME
 | 
					// FIXME
 | 
				
			||||||
#ifdef FEATURE_UVISOR
 | 
					#ifdef FEATURE_UVISOR
 | 
				
			||||||
    #warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
 | 
					#warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
 | 
				
			||||||
#endif /* FEATURE_UVISOR */
 | 
					#endif /* FEATURE_UVISOR */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // If critical_section_enter has not previously been called, do nothing
 | 
					    // If critical_section_enter has not previously been called, do nothing
 | 
				
			||||||
| 
						 | 
					@ -330,18 +330,21 @@ uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool core_util_atomic_cas_ptr(void * volatile *ptr, void **expectedCurrentValue, void *desiredValue) {
 | 
					bool core_util_atomic_cas_ptr(void *volatile *ptr, void **expectedCurrentValue, void *desiredValue)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return core_util_atomic_cas_u32(
 | 
					    return core_util_atomic_cas_u32(
 | 
				
			||||||
            (volatile uint32_t *)ptr,
 | 
					               (volatile uint32_t *)ptr,
 | 
				
			||||||
            (uint32_t *)expectedCurrentValue,
 | 
					               (uint32_t *)expectedCurrentValue,
 | 
				
			||||||
            (uint32_t)desiredValue);
 | 
					               (uint32_t)desiredValue);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *core_util_atomic_incr_ptr(void * volatile *valuePtr, ptrdiff_t delta) {
 | 
					void *core_util_atomic_incr_ptr(void *volatile *valuePtr, ptrdiff_t delta)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return (void *)core_util_atomic_incr_u32((volatile uint32_t *)valuePtr, (uint32_t)delta);
 | 
					    return (void *)core_util_atomic_incr_u32((volatile uint32_t *)valuePtr, (uint32_t)delta);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *core_util_atomic_decr_ptr(void * volatile *valuePtr, ptrdiff_t delta) {
 | 
					void *core_util_atomic_decr_ptr(void *volatile *valuePtr, ptrdiff_t delta)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return (void *)core_util_atomic_decr_u32((volatile uint32_t *)valuePtr, (uint32_t)delta);
 | 
					    return (void *)core_util_atomic_decr_u32((volatile uint32_t *)valuePtr, (uint32_t)delta);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -315,7 +315,7 @@ bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentV
 | 
				
			||||||
 * always succeeds if the current value is expected, as per the pseudocode
 | 
					 * always succeeds if the current value is expected, as per the pseudocode
 | 
				
			||||||
 * above; it will not spuriously fail as "atomic_compare_exchange_weak" may.
 | 
					 * above; it will not spuriously fail as "atomic_compare_exchange_weak" may.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
bool core_util_atomic_cas_ptr(void * volatile *ptr, void **expectedCurrentValue, void *desiredValue);
 | 
					bool core_util_atomic_cas_ptr(void *volatile *ptr, void **expectedCurrentValue, void *desiredValue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Atomic increment.
 | 
					 * Atomic increment.
 | 
				
			||||||
| 
						 | 
					@ -350,7 +350,7 @@ uint32_t core_util_atomic_incr_u32(volatile uint32_t *valuePtr, uint32_t delta);
 | 
				
			||||||
 * @note The type of the pointer argument is not taken into account
 | 
					 * @note The type of the pointer argument is not taken into account
 | 
				
			||||||
 *       and the pointer is incremented by bytes.
 | 
					 *       and the pointer is incremented by bytes.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void *core_util_atomic_incr_ptr(void * volatile *valuePtr, ptrdiff_t delta);
 | 
					void *core_util_atomic_incr_ptr(void *volatile *valuePtr, ptrdiff_t delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Atomic decrement.
 | 
					 * Atomic decrement.
 | 
				
			||||||
| 
						 | 
					@ -385,7 +385,7 @@ uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta);
 | 
				
			||||||
 * @note The type of the pointer argument is not taken into account
 | 
					 * @note The type of the pointer argument is not taken into account
 | 
				
			||||||
 *       and the pointer is decremented by bytes
 | 
					 *       and the pointer is decremented by bytes
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void *core_util_atomic_decr_ptr(void * volatile *valuePtr, ptrdiff_t delta);
 | 
					void *core_util_atomic_decr_ptr(void *volatile *valuePtr, ptrdiff_t delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
} // extern "C"
 | 
					} // extern "C"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,8 @@ extern "C" {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param format printf-style format string, followed by variables
 | 
					 * @param format printf-style format string, followed by variables
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static inline void debug(const char *format, ...) {
 | 
					static inline void debug(const char *format, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
 | 
					#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
 | 
				
			||||||
    va_list args;
 | 
					    va_list args;
 | 
				
			||||||
    va_start(args, format);
 | 
					    va_start(args, format);
 | 
				
			||||||
| 
						 | 
					@ -55,7 +56,8 @@ static inline void debug(const char *format, ...) {
 | 
				
			||||||
 * @param condition output only if condition is true (!= 0)
 | 
					 * @param condition output only if condition is true (!= 0)
 | 
				
			||||||
 * @param format printf-style format string, followed by variables
 | 
					 * @param format printf-style format string, followed by variables
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static inline void debug_if(int condition, const char *format, ...) {
 | 
					static inline void debug_if(int condition, const char *format, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
 | 
					#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
 | 
				
			||||||
    if (condition) {
 | 
					    if (condition) {
 | 
				
			||||||
        va_list args;
 | 
					        va_list args;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,8 +59,8 @@ static void mbed_halt_system(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    //If not in ISR context exit, otherwise spin on WFI
 | 
					    //If not in ISR context exit, otherwise spin on WFI
 | 
				
			||||||
    if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
 | 
					    if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
 | 
				
			||||||
        for(;;) {
 | 
					        for (;;) {
 | 
				
			||||||
           __WFI();
 | 
					            __WFI();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        //exit eventually calls mbed_die
 | 
					        //exit eventually calls mbed_die
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,8 @@ static void mbed_halt_system(void)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WEAK void error(const char* format, ...) {
 | 
					WEAK void error(const char *format, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Prevent recursion if error is called again
 | 
					    // Prevent recursion if error is called again
 | 
				
			||||||
    if (error_in_progress) {
 | 
					    if (error_in_progress) {
 | 
				
			||||||
| 
						 | 
					@ -194,8 +195,9 @@ mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *e
 | 
				
			||||||
WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
 | 
					WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    //set the error reported and then halt the system
 | 
					    //set the error reported and then halt the system
 | 
				
			||||||
    if ( MBED_SUCCESS != handle_error(error_status, error_value, filename, line_number))
 | 
					    if (MBED_SUCCESS != handle_error(error_status, error_value, filename, line_number)) {
 | 
				
			||||||
        return MBED_ERROR_FAILED_OPERATION;
 | 
					        return MBED_ERROR_FAILED_OPERATION;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //On fatal errors print the error context/report
 | 
					    //On fatal errors print the error context/report
 | 
				
			||||||
    print_error_report(&last_error_ctx, error_msg);
 | 
					    print_error_report(&last_error_ctx, error_msg);
 | 
				
			||||||
| 
						 | 
					@ -208,7 +210,7 @@ WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char
 | 
				
			||||||
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
 | 
					mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    //register the new hook/callback
 | 
					    //register the new hook/callback
 | 
				
			||||||
    if ( error_hook_in != NULL )  {
 | 
					    if (error_hook_in != NULL)  {
 | 
				
			||||||
        error_hook = error_hook_in;
 | 
					        error_hook = error_hook_in;
 | 
				
			||||||
        return MBED_SUCCESS;
 | 
					        return MBED_SUCCESS;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -217,14 +219,14 @@ mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Retrieve the first error context from error log
 | 
					//Retrieve the first error context from error log
 | 
				
			||||||
mbed_error_status_t mbed_get_first_error_info (mbed_error_ctx *error_info) 
 | 
					mbed_error_status_t mbed_get_first_error_info(mbed_error_ctx *error_info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    memcpy(error_info, &first_error_ctx, sizeof(first_error_ctx));
 | 
					    memcpy(error_info, &first_error_ctx, sizeof(first_error_ctx));
 | 
				
			||||||
    return MBED_SUCCESS;
 | 
					    return MBED_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Retrieve the last error context from error log
 | 
					//Retrieve the last error context from error log
 | 
				
			||||||
mbed_error_status_t mbed_get_last_error_info (mbed_error_ctx *error_info) 
 | 
					mbed_error_status_t mbed_get_last_error_info(mbed_error_ctx *error_info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    memcpy(error_info, &last_error_ctx, sizeof(mbed_error_ctx));
 | 
					    memcpy(error_info, &last_error_ctx, sizeof(mbed_error_ctx));
 | 
				
			||||||
    return MBED_SUCCESS;
 | 
					    return MBED_SUCCESS;
 | 
				
			||||||
| 
						 | 
					@ -233,21 +235,23 @@ mbed_error_status_t mbed_get_last_error_info (mbed_error_ctx *error_info)
 | 
				
			||||||
//Makes an mbed_error_status_t value
 | 
					//Makes an mbed_error_status_t value
 | 
				
			||||||
mbed_error_status_t mbed_make_error(mbed_error_type_t error_type, mbed_module_type_t entity, mbed_error_code_t error_code)
 | 
					mbed_error_status_t mbed_make_error(mbed_error_type_t error_type, mbed_module_type_t entity, mbed_error_code_t error_code)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    switch(error_type)
 | 
					    switch (error_type) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        case MBED_ERROR_TYPE_POSIX:
 | 
					        case MBED_ERROR_TYPE_POSIX:
 | 
				
			||||||
            if (error_code >= MBED_POSIX_ERROR_BASE && error_code <= MBED_SYSTEM_ERROR_BASE)
 | 
					            if (error_code >= MBED_POSIX_ERROR_BASE && error_code <= MBED_SYSTEM_ERROR_BASE) {
 | 
				
			||||||
                return -error_code;
 | 
					                return -error_code;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case MBED_ERROR_TYPE_SYSTEM:
 | 
					        case MBED_ERROR_TYPE_SYSTEM:
 | 
				
			||||||
            if (error_code >= MBED_SYSTEM_ERROR_BASE && error_code <= MBED_CUSTOM_ERROR_BASE)
 | 
					            if (error_code >= MBED_SYSTEM_ERROR_BASE && error_code <= MBED_CUSTOM_ERROR_BASE) {
 | 
				
			||||||
                return MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, entity, error_code);
 | 
					                return MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, entity, error_code);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case MBED_ERROR_TYPE_CUSTOM:
 | 
					        case MBED_ERROR_TYPE_CUSTOM:
 | 
				
			||||||
            if (error_code >= MBED_CUSTOM_ERROR_BASE)
 | 
					            if (error_code >= MBED_CUSTOM_ERROR_BASE) {
 | 
				
			||||||
                return MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, entity, error_code);
 | 
					                return MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, entity, error_code);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
| 
						 | 
					@ -292,7 +296,7 @@ static void print_thread(osRtxThread_t *thread)
 | 
				
			||||||
static void print_threads_info(osRtxThread_t *threads)
 | 
					static void print_threads_info(osRtxThread_t *threads)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    while (threads != NULL) {
 | 
					    while (threads != NULL) {
 | 
				
			||||||
        print_thread( threads );
 | 
					        print_thread(threads);
 | 
				
			||||||
        threads = threads->thread_next;
 | 
					        threads = threads->thread_next;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -356,11 +360,11 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
 | 
				
			||||||
    mbed_error_printf("\nError Value: 0x%X", ctx->error_value);
 | 
					    mbed_error_printf("\nError Value: 0x%X", ctx->error_value);
 | 
				
			||||||
#ifdef TARGET_CORTEX_M
 | 
					#ifdef TARGET_CORTEX_M
 | 
				
			||||||
    mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X ",
 | 
					    mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X ",
 | 
				
			||||||
                        ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
 | 
					                      ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    //For Cortex-A targets we dont have support to capture the current SP
 | 
					    //For Cortex-A targets we dont have support to capture the current SP
 | 
				
			||||||
    mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X ",
 | 
					    mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X ",
 | 
				
			||||||
                        ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem);
 | 
					                      ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem);
 | 
				
			||||||
#endif //TARGET_CORTEX_M
 | 
					#endif //TARGET_CORTEX_M
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
 | 
					#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
 | 
				
			||||||
| 
						 | 
					@ -385,7 +389,7 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
 | 
					#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
 | 
				
			||||||
//Retrieve the error context from error log at the specified index
 | 
					//Retrieve the error context from error log at the specified index
 | 
				
			||||||
mbed_error_status_t mbed_get_error_hist_info (int index, mbed_error_ctx *error_info) 
 | 
					mbed_error_status_t mbed_get_error_hist_info(int index, mbed_error_ctx *error_info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return mbed_error_hist_get(index, error_info);
 | 
					    return mbed_error_hist_get(index, error_info);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -404,32 +408,32 @@ mbed_error_status_t mbed_save_error_hist(const char *path)
 | 
				
			||||||
    FILE *error_log_file = NULL;
 | 
					    FILE *error_log_file = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Ensure path is valid
 | 
					    //Ensure path is valid
 | 
				
			||||||
    if (path==NULL) {
 | 
					    if (path == NULL) {
 | 
				
			||||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT);
 | 
					        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT);
 | 
				
			||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Open the file for saving the error log info
 | 
					    //Open the file for saving the error log info
 | 
				
			||||||
    if ((error_log_file = fopen( path, "w" )) == NULL){
 | 
					    if ((error_log_file = fopen(path, "w")) == NULL) {
 | 
				
			||||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_OPEN_FAILED);
 | 
					        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_OPEN_FAILED);
 | 
				
			||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //First store the first and last errors
 | 
					    //First store the first and last errors
 | 
				
			||||||
    if (fprintf(error_log_file, "\nFirst Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
					    if (fprintf(error_log_file, "\nFirst Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
				
			||||||
        (unsigned int)first_error_ctx.error_status, 
 | 
					                (unsigned int)first_error_ctx.error_status,
 | 
				
			||||||
        (unsigned int)first_error_ctx.thread_id, 
 | 
					                (unsigned int)first_error_ctx.thread_id,
 | 
				
			||||||
        (unsigned int)first_error_ctx.error_address, 
 | 
					                (unsigned int)first_error_ctx.error_address,
 | 
				
			||||||
        (unsigned int)first_error_ctx.error_value) <= 0) {
 | 
					                (unsigned int)first_error_ctx.error_value) <= 0) {
 | 
				
			||||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
					        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
				
			||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (fprintf(error_log_file, "\nLast Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
					    if (fprintf(error_log_file, "\nLast Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
				
			||||||
        (unsigned int)last_error_ctx.error_status, 
 | 
					                (unsigned int)last_error_ctx.error_status,
 | 
				
			||||||
        (unsigned int)last_error_ctx.thread_id, 
 | 
					                (unsigned int)last_error_ctx.thread_id,
 | 
				
			||||||
        (unsigned int)last_error_ctx.error_address, 
 | 
					                (unsigned int)last_error_ctx.error_address,
 | 
				
			||||||
        (unsigned int)last_error_ctx.error_value) <= 0) {
 | 
					                (unsigned int)last_error_ctx.error_value) <= 0) {
 | 
				
			||||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
					        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
				
			||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -439,11 +443,11 @@ mbed_error_status_t mbed_save_error_hist(const char *path)
 | 
				
			||||||
        mbed_error_hist_get(log_count, &ctx);
 | 
					        mbed_error_hist_get(log_count, &ctx);
 | 
				
			||||||
        //first line of file will be error log count
 | 
					        //first line of file will be error log count
 | 
				
			||||||
        if (fprintf(error_log_file, "\n%d: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
					        if (fprintf(error_log_file, "\n%d: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
				
			||||||
            log_count, 
 | 
					                    log_count,
 | 
				
			||||||
            (unsigned int)ctx.error_status, 
 | 
					                    (unsigned int)ctx.error_status,
 | 
				
			||||||
            (unsigned int)ctx.thread_id, 
 | 
					                    (unsigned int)ctx.thread_id,
 | 
				
			||||||
            (unsigned int)ctx.error_address, 
 | 
					                    (unsigned int)ctx.error_address,
 | 
				
			||||||
            (unsigned int)ctx.error_value) <= 0) {
 | 
					                    (unsigned int)ctx.error_value) <= 0) {
 | 
				
			||||||
            ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
					            ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
				
			||||||
            goto exit;
 | 
					            goto exit;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -205,8 +205,7 @@ typedef int mbed_error_status_t;
 | 
				
			||||||
 *         MBED_ERROR_TYPE_POSIX  - Used to indicate that the error status is of Posix error type.\n
 | 
					 *         MBED_ERROR_TYPE_POSIX  - Used to indicate that the error status is of Posix error type.\n
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
typedef enum _mbed_error_type_t
 | 
					typedef enum _mbed_error_type_t {
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    MBED_ERROR_TYPE_SYSTEM = 0,
 | 
					    MBED_ERROR_TYPE_SYSTEM = 0,
 | 
				
			||||||
    MBED_ERROR_TYPE_CUSTOM = 1,
 | 
					    MBED_ERROR_TYPE_CUSTOM = 1,
 | 
				
			||||||
    //2 is reserved
 | 
					    //2 is reserved
 | 
				
			||||||
| 
						 | 
					@ -577,206 +576,206 @@ typedef enum _mbed_error_code {
 | 
				
			||||||
    //POSIX ERROR CODE definitions starts at offset 0(MBED_POSIX_ERROR_BASE) to align them with actual Posix Error Code
 | 
					    //POSIX ERROR CODE definitions starts at offset 0(MBED_POSIX_ERROR_BASE) to align them with actual Posix Error Code
 | 
				
			||||||
    //defintions in mbed_retarget.h
 | 
					    //defintions in mbed_retarget.h
 | 
				
			||||||
    //                  Error Name                                    Error Code
 | 
					    //                  Error Name                                    Error Code
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EPERM                 ,EPERM           ),  /* 1       Operation not permitted */
 | 
					    MBED_DEFINE_POSIX_ERROR(EPERM, EPERM),                              /* 1       Operation not permitted */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOENT                ,ENOENT          ),  /* 2       No such file or directory */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOENT, ENOENT),                            /* 2       No such file or directory */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESRCH                 ,ESRCH           ),  /* 3       No such process */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESRCH, ESRCH),                              /* 3       No such process */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EINTR                 ,EINTR           ),  /* 4       Interrupted system call */
 | 
					    MBED_DEFINE_POSIX_ERROR(EINTR, EINTR),                              /* 4       Interrupted system call */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EIO                   ,EIO             ),  /* 5       I/O error */
 | 
					    MBED_DEFINE_POSIX_ERROR(EIO, EIO),                                  /* 5       I/O error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENXIO                 ,ENXIO           ),  /* 6       No such device or address */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENXIO, ENXIO),                              /* 6       No such device or address */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( E2BIG                 ,E2BIG           ),  /* 7       Argument list too long */
 | 
					    MBED_DEFINE_POSIX_ERROR(E2BIG, E2BIG),                              /* 7       Argument list too long */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOEXEC               ,ENOEXEC         ),  /* 8       Exec format error */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOEXEC, ENOEXEC),                          /* 8       Exec format error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADF                 ,EBADF           ),  /* 9       Bad file number */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADF, EBADF),                              /* 9       Bad file number */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECHILD                ,ECHILD          ),  /* 10      No child processes */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECHILD, ECHILD),                            /* 10      No child processes */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EAGAIN                ,EAGAIN          ),  /* 11      Try again */
 | 
					    MBED_DEFINE_POSIX_ERROR(EAGAIN, EAGAIN),                            /* 11      Try again */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOMEM                ,ENOMEM          ),  /* 12      Out of memory */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOMEM, ENOMEM),                            /* 12      Out of memory */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EACCES                ,EACCES          ),  /* 13      Permission denied */
 | 
					    MBED_DEFINE_POSIX_ERROR(EACCES, EACCES),                            /* 13      Permission denied */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EFAULT                ,EFAULT          ),  /* 14      Bad address */
 | 
					    MBED_DEFINE_POSIX_ERROR(EFAULT, EFAULT),                            /* 14      Bad address */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTBLK               ,ENOTBLK         ),  /* 15      Block device required */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTBLK, ENOTBLK),                          /* 15      Block device required */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBUSY                 ,EBUSY           ),  /* 16      Device or resource busy */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBUSY, EBUSY),                              /* 16      Device or resource busy */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EEXIST                ,EEXIST          ),  /* 17      File exists */
 | 
					    MBED_DEFINE_POSIX_ERROR(EEXIST, EEXIST),                            /* 17      File exists */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EXDEV                 ,EXDEV           ),  /* 18      Cross-device link */
 | 
					    MBED_DEFINE_POSIX_ERROR(EXDEV, EXDEV),                              /* 18      Cross-device link */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENODEV                ,ENODEV          ),  /* 19      No such device */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENODEV, ENODEV),                            /* 19      No such device */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTDIR               ,ENOTDIR         ),  /* 20      Not a directory */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTDIR, ENOTDIR),                          /* 20      Not a directory */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EISDIR                ,EISDIR          ),  /* 21      Is a directory */
 | 
					    MBED_DEFINE_POSIX_ERROR(EISDIR, EISDIR),                            /* 21      Is a directory */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EINVAL                ,EINVAL          ),  /* 22      Invalid argument */
 | 
					    MBED_DEFINE_POSIX_ERROR(EINVAL, EINVAL),                            /* 22      Invalid argument */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENFILE                ,ENFILE          ),  /* 23      File table overflow */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENFILE, ENFILE),                            /* 23      File table overflow */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EMFILE                ,EMFILE          ),  /* 24      Too many open files */
 | 
					    MBED_DEFINE_POSIX_ERROR(EMFILE, EMFILE),                            /* 24      Too many open files */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTTY                ,ENOTTY          ),  /* 25      Not a typewriter */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTTY, ENOTTY),                            /* 25      Not a typewriter */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ETXTBSY               ,ETXTBSY         ),  /* 26      Text file busy */
 | 
					    MBED_DEFINE_POSIX_ERROR(ETXTBSY, ETXTBSY),                          /* 26      Text file busy */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EFBIG                 ,EFBIG           ),  /* 27      File too large */
 | 
					    MBED_DEFINE_POSIX_ERROR(EFBIG, EFBIG),                              /* 27      File too large */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOSPC                ,ENOSPC          ),  /* 28      No space left on device */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOSPC, ENOSPC),                            /* 28      No space left on device */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESPIPE                ,ESPIPE          ),  /* 29      Illegal seek */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESPIPE, ESPIPE),                            /* 29      Illegal seek */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EROFS                 ,EROFS           ),  /* 30      Read-only file system */
 | 
					    MBED_DEFINE_POSIX_ERROR(EROFS, EROFS),                              /* 30      Read-only file system */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EMLINK                ,EMLINK          ),  /* 31      Too many links */
 | 
					    MBED_DEFINE_POSIX_ERROR(EMLINK, EMLINK),                            /* 31      Too many links */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EPIPE                 ,EPIPE           ),  /* 32      Broken pipe */
 | 
					    MBED_DEFINE_POSIX_ERROR(EPIPE, EPIPE),                              /* 32      Broken pipe */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EDOM                  ,EDOM            ),  /* 33      Math argument out of domain of func */
 | 
					    MBED_DEFINE_POSIX_ERROR(EDOM, EDOM),                                /* 33      Math argument out of domain of func */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ERANGE                ,ERANGE          ),  /* 34      Math result not representable */
 | 
					    MBED_DEFINE_POSIX_ERROR(ERANGE, ERANGE),                            /* 34      Math result not representable */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EDEADLK               ,EDEADLK         ),  /* 35      Resource deadlock would occur */
 | 
					    MBED_DEFINE_POSIX_ERROR(EDEADLK, EDEADLK),                          /* 35      Resource deadlock would occur */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENAMETOOLONG          ,ENAMETOOLONG    ),  /* 36      File name too long */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENAMETOOLONG, ENAMETOOLONG),                /* 36      File name too long */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOLCK                ,ENOLCK          ),  /* 37      No record locks available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOLCK, ENOLCK),                            /* 37      No record locks available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOSYS                ,ENOSYS          ),  /* 38      Function not implemented */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOSYS, ENOSYS),                            /* 38      Function not implemented */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTEMPTY             ,ENOTEMPTY       ),  /* 39      Directory not empty */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTEMPTY, ENOTEMPTY),                      /* 39      Directory not empty */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELOOP                 ,ELOOP           ),  /* 40      Too many symbolic links encountered */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELOOP, ELOOP),                              /* 40      Too many symbolic links encountered */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EWOULDBLOCK           ,EAGAIN          ),  /* EAGAIN  Operation would block */
 | 
					    MBED_DEFINE_POSIX_ERROR(EWOULDBLOCK, EAGAIN),                       /* EAGAIN  Operation would block */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOMSG                ,ENOMSG          ),  /* 42      No message of desired type */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOMSG, ENOMSG),                            /* 42      No message of desired type */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EIDRM                 ,EIDRM           ),  /* 43      Identifier removed */
 | 
					    MBED_DEFINE_POSIX_ERROR(EIDRM, EIDRM),                              /* 43      Identifier removed */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECHRNG                ,ECHRNG          ),  /* 44      Channel number out of range */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECHRNG, ECHRNG),                            /* 44      Channel number out of range */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EL2NSYNC              ,EL2NSYNC        ),  /* 45      Level 2 not synchronized */
 | 
					    MBED_DEFINE_POSIX_ERROR(EL2NSYNC, EL2NSYNC),                        /* 45      Level 2 not synchronized */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EL3HLT                ,EL3HLT          ),  /* 46      Level 3 halted */
 | 
					    MBED_DEFINE_POSIX_ERROR(EL3HLT, EL3HLT),                            /* 46      Level 3 halted */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EL3RST                ,EL3RST          ),  /* 47      Level 3 reset */
 | 
					    MBED_DEFINE_POSIX_ERROR(EL3RST, EL3RST),                            /* 47      Level 3 reset */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELNRNG                ,ELNRNG          ),  /* 48      Link number out of range */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELNRNG, ELNRNG),                            /* 48      Link number out of range */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EUNATCH               ,EUNATCH         ),  /* 49      Protocol driver not attached */
 | 
					    MBED_DEFINE_POSIX_ERROR(EUNATCH, EUNATCH),                          /* 49      Protocol driver not attached */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOCSI                ,ENOCSI          ),  /* 50      No CSI structure available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOCSI, ENOCSI),                            /* 50      No CSI structure available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EL2HLT                ,EL2HLT          ),  /* 51      Level 2 halted */
 | 
					    MBED_DEFINE_POSIX_ERROR(EL2HLT, EL2HLT),                            /* 51      Level 2 halted */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADE                 ,EBADE           ),  /* 52      Invalid exchange */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADE, EBADE),                              /* 52      Invalid exchange */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADR                 ,EBADR           ),  /* 53      Invalid request descriptor */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADR, EBADR),                              /* 53      Invalid request descriptor */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EXFULL                ,EXFULL          ),  /* 54      Exchange full */
 | 
					    MBED_DEFINE_POSIX_ERROR(EXFULL, EXFULL),                            /* 54      Exchange full */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOANO                ,ENOANO          ),  /* 55      No anode */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOANO, ENOANO),                            /* 55      No anode */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADRQC               ,EBADRQC         ),  /* 56      Invalid request code */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADRQC, EBADRQC),                          /* 56      Invalid request code */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADSLT               ,EBADSLT         ),  /* 57      Invalid slot */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADSLT, EBADSLT),                          /* 57      Invalid slot */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EDEADLOCK             ,EDEADLK         ),  /* EDEADLK Resource deadlock would occur */
 | 
					    MBED_DEFINE_POSIX_ERROR(EDEADLOCK, EDEADLK),                        /* EDEADLK Resource deadlock would occur */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBFONT                ,EBFONT          ),  /* 59      Bad font file format */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBFONT, EBFONT),                            /* 59      Bad font file format */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOSTR                ,ENOSTR          ),  /* 60      Device not a stream */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOSTR, ENOSTR),                            /* 60      Device not a stream */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENODATA               ,ENODATA         ),  /* 61      No data available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENODATA, ENODATA),                          /* 61      No data available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ETIME                 ,ETIME           ),  /* 62      Timer expired */
 | 
					    MBED_DEFINE_POSIX_ERROR(ETIME, ETIME),                              /* 62      Timer expired */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOSR                 ,ENOSR           ),  /* 63      Out of streams resources */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOSR, ENOSR),                              /* 63      Out of streams resources */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENONET                ,ENONET          ),  /* 64      Machine is not on the network */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENONET, ENONET),                            /* 64      Machine is not on the network */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOPKG                ,ENOPKG          ),  /* 65      Package not installed */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOPKG, ENOPKG),                            /* 65      Package not installed */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EREMOTE               ,EREMOTE         ),  /* 66      Object is remote */
 | 
					    MBED_DEFINE_POSIX_ERROR(EREMOTE, EREMOTE),                          /* 66      Object is remote */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOLINK               ,ENOLINK         ),  /* 67      Link has been severed */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOLINK, ENOLINK),                          /* 67      Link has been severed */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EADV                  ,EADV            ),  /* 68      Advertise error */
 | 
					    MBED_DEFINE_POSIX_ERROR(EADV, EADV),                                /* 68      Advertise error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESRMNT                ,ESRMNT          ),  /* 69      Srmount error */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESRMNT, ESRMNT),                            /* 69      Srmount error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECOMM                 ,ECOMM           ),  /* 70      Communication error on send */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECOMM, ECOMM),                              /* 70      Communication error on send */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EPROTO                ,EPROTO          ),  /* 71      Protocol error */
 | 
					    MBED_DEFINE_POSIX_ERROR(EPROTO, EPROTO),                            /* 71      Protocol error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EMULTIHOP             ,EMULTIHOP       ),  /* 72      Multihop attempted */
 | 
					    MBED_DEFINE_POSIX_ERROR(EMULTIHOP, EMULTIHOP),                      /* 72      Multihop attempted */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EDOTDOT               ,EDOTDOT         ),  /* 73      RFS specific error */
 | 
					    MBED_DEFINE_POSIX_ERROR(EDOTDOT, EDOTDOT),                          /* 73      RFS specific error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADMSG               ,EBADMSG         ),  /* 74      Not a data message */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADMSG, EBADMSG),                          /* 74      Not a data message */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EOVERFLOW             ,EOVERFLOW       ),  /* 75      Value too large for defined data type */
 | 
					    MBED_DEFINE_POSIX_ERROR(EOVERFLOW, EOVERFLOW),                      /* 75      Value too large for defined data type */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTUNIQ              ,ENOTUNIQ        ),  /* 76      Name not unique on network */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTUNIQ, ENOTUNIQ),                        /* 76      Name not unique on network */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EBADFD                ,EBADFD          ),  /* 77      File descriptor in bad state */
 | 
					    MBED_DEFINE_POSIX_ERROR(EBADFD, EBADFD),                            /* 77      File descriptor in bad state */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EREMCHG               ,EREMCHG         ),  /* 78      Remote address changed */
 | 
					    MBED_DEFINE_POSIX_ERROR(EREMCHG, EREMCHG),                          /* 78      Remote address changed */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELIBACC               ,ELIBACC         ),  /* 79      Can not access a needed shared library */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELIBACC, ELIBACC),                          /* 79      Can not access a needed shared library */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELIBBAD               ,ELIBBAD         ),  /* 80      Accessing a corrupted shared library */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELIBBAD, ELIBBAD),                          /* 80      Accessing a corrupted shared library */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELIBSCN               ,ELIBSCN         ),  /* 81      .lib section in a.out corrupted */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELIBSCN, ELIBSCN),                          /* 81      .lib section in a.out corrupted */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELIBMAX               ,ELIBMAX         ),  /* 82      Attempting to link in too many shared libraries */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELIBMAX, ELIBMAX),                          /* 82      Attempting to link in too many shared libraries */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ELIBEXEC              ,ELIBEXEC        ),  /* 83      Cannot exec a shared library directly */
 | 
					    MBED_DEFINE_POSIX_ERROR(ELIBEXEC, ELIBEXEC),                        /* 83      Cannot exec a shared library directly */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EILSEQ                ,EILSEQ          ),  /* 84      Illegal byte sequence */
 | 
					    MBED_DEFINE_POSIX_ERROR(EILSEQ, EILSEQ),                            /* 84      Illegal byte sequence */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ERESTART              ,ERESTART        ),  /* 85      Interrupted system call should be restarted */
 | 
					    MBED_DEFINE_POSIX_ERROR(ERESTART, ERESTART),                        /* 85      Interrupted system call should be restarted */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESTRPIPE              ,ESTRPIPE        ),  /* 86      Streams pipe error */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESTRPIPE, ESTRPIPE),                        /* 86      Streams pipe error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EUSERS                ,EUSERS          ),  /* 87      Too many users */
 | 
					    MBED_DEFINE_POSIX_ERROR(EUSERS, EUSERS),                            /* 87      Too many users */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTSOCK              ,ENOTSOCK        ),  /* 88      Socket operation on non-socket */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTSOCK, ENOTSOCK),                        /* 88      Socket operation on non-socket */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EDESTADDRREQ          ,EDESTADDRREQ    ),  /* 89      Destination address required */
 | 
					    MBED_DEFINE_POSIX_ERROR(EDESTADDRREQ, EDESTADDRREQ),                /* 89      Destination address required */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EMSGSIZE              ,EMSGSIZE        ),  /* 90      Message too long */
 | 
					    MBED_DEFINE_POSIX_ERROR(EMSGSIZE, EMSGSIZE),                        /* 90      Message too long */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EPROTOTYPE            ,EPROTOTYPE      ),  /* 91      Protocol wrong type for socket */
 | 
					    MBED_DEFINE_POSIX_ERROR(EPROTOTYPE, EPROTOTYPE),                    /* 91      Protocol wrong type for socket */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOPROTOOPT           ,ENOPROTOOPT     ),  /* 92      Protocol not available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOPROTOOPT, ENOPROTOOPT),                  /* 92      Protocol not available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EPROTONOSUPPORT       ,EPROTONOSUPPORT ),  /* 93      Protocol not supported */
 | 
					    MBED_DEFINE_POSIX_ERROR(EPROTONOSUPPORT, EPROTONOSUPPORT),          /* 93      Protocol not supported */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESOCKTNOSUPPORT       ,ESOCKTNOSUPPORT ),  /* 94      Socket type not supported */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESOCKTNOSUPPORT, ESOCKTNOSUPPORT),          /* 94      Socket type not supported */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EOPNOTSUPP            ,EOPNOTSUPP      ),  /* 95      Operation not supported on transport endpoint */
 | 
					    MBED_DEFINE_POSIX_ERROR(EOPNOTSUPP, EOPNOTSUPP),                    /* 95      Operation not supported on transport endpoint */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EPFNOSUPPORT          ,EPFNOSUPPORT    ),  /* 96      Protocol family not supported */
 | 
					    MBED_DEFINE_POSIX_ERROR(EPFNOSUPPORT, EPFNOSUPPORT),                /* 96      Protocol family not supported */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EAFNOSUPPORT          ,EAFNOSUPPORT    ),  /* 97      Address family not supported by protocol */
 | 
					    MBED_DEFINE_POSIX_ERROR(EAFNOSUPPORT, EAFNOSUPPORT),                /* 97      Address family not supported by protocol */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EADDRINUSE            ,EADDRINUSE      ),  /* 98      Address already in use */
 | 
					    MBED_DEFINE_POSIX_ERROR(EADDRINUSE, EADDRINUSE),                    /* 98      Address already in use */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EADDRNOTAVAIL         ,EADDRNOTAVAIL   ),  /* 99      Cannot assign requested address */
 | 
					    MBED_DEFINE_POSIX_ERROR(EADDRNOTAVAIL, EADDRNOTAVAIL),              /* 99      Cannot assign requested address */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENETDOWN              ,ENETDOWN        ),  /* 100     Network is down */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENETDOWN, ENETDOWN),                        /* 100     Network is down */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENETUNREACH           ,ENETUNREACH     ),  /* 101     Network is unreachable */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENETUNREACH, ENETUNREACH),                  /* 101     Network is unreachable */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENETRESET             ,ENETRESET       ),  /* 102     Network dropped connection because of reset */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENETRESET, ENETRESET),                      /* 102     Network dropped connection because of reset */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECONNABORTED          ,ECONNABORTED    ),  /* 103     Software caused connection abort */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECONNABORTED, ECONNABORTED),                /* 103     Software caused connection abort */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECONNRESET            ,ECONNRESET      ),  /* 104     Connection reset by peer */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECONNRESET, ECONNRESET),                    /* 104     Connection reset by peer */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOBUFS               ,ENOBUFS         ),  /* 105     No buffer space available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOBUFS, ENOBUFS),                          /* 105     No buffer space available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EISCONN               ,EISCONN         ),  /* 106     Transport endpoint is already connected */
 | 
					    MBED_DEFINE_POSIX_ERROR(EISCONN, EISCONN),                          /* 106     Transport endpoint is already connected */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTCONN              ,ENOTCONN        ),  /* 107     Transport endpoint is not connected */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTCONN, ENOTCONN),                        /* 107     Transport endpoint is not connected */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESHUTDOWN             ,ESHUTDOWN       ),  /* 108     Cannot send after transport endpoint shutdown */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESHUTDOWN, ESHUTDOWN),                      /* 108     Cannot send after transport endpoint shutdown */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ETOOMANYREFS          ,ETOOMANYREFS    ),  /* 109     Too many references: cannot splice */
 | 
					    MBED_DEFINE_POSIX_ERROR(ETOOMANYREFS, ETOOMANYREFS),                /* 109     Too many references: cannot splice */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ETIMEDOUT             ,ETIMEDOUT       ),  /* 110     Connection timed out */
 | 
					    MBED_DEFINE_POSIX_ERROR(ETIMEDOUT, ETIMEDOUT),                      /* 110     Connection timed out */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECONNREFUSED          ,ECONNREFUSED    ),  /* 111     Connection refused */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECONNREFUSED, ECONNREFUSED),                /* 111     Connection refused */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EHOSTDOWN             ,EHOSTDOWN       ),  /* 112     Host is down */
 | 
					    MBED_DEFINE_POSIX_ERROR(EHOSTDOWN, EHOSTDOWN),                      /* 112     Host is down */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EHOSTUNREACH          ,EHOSTUNREACH    ),  /* 113     No route to host */
 | 
					    MBED_DEFINE_POSIX_ERROR(EHOSTUNREACH, EHOSTUNREACH),                /* 113     No route to host */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EALREADY              ,EALREADY        ),  /* 114     Operation already in progress */
 | 
					    MBED_DEFINE_POSIX_ERROR(EALREADY, EALREADY),                        /* 114     Operation already in progress */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EINPROGRESS           ,EINPROGRESS     ),  /* 115     Operation now in progress */
 | 
					    MBED_DEFINE_POSIX_ERROR(EINPROGRESS, EINPROGRESS),                  /* 115     Operation now in progress */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ESTALE                ,ESTALE          ),  /* 116     Stale NFS file handle */
 | 
					    MBED_DEFINE_POSIX_ERROR(ESTALE, ESTALE),                            /* 116     Stale NFS file handle */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EUCLEAN               ,EUCLEAN         ),  /* 117     Structure needs cleaning */
 | 
					    MBED_DEFINE_POSIX_ERROR(EUCLEAN, EUCLEAN),                          /* 117     Structure needs cleaning */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTNAM               ,ENOTNAM         ),  /* 118     Not a XENIX named type file */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTNAM, ENOTNAM),                          /* 118     Not a XENIX named type file */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENAVAIL               ,ENAVAIL         ),  /* 119     No XENIX semaphores available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENAVAIL, ENAVAIL),                          /* 119     No XENIX semaphores available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EISNAM                ,EISNAM          ),  /* 120     Is a named type file */
 | 
					    MBED_DEFINE_POSIX_ERROR(EISNAM, EISNAM),                            /* 120     Is a named type file */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EREMOTEIO             ,EREMOTEIO       ),  /* 121     Remote I/O error */
 | 
					    MBED_DEFINE_POSIX_ERROR(EREMOTEIO, EREMOTEIO),                      /* 121     Remote I/O error */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EDQUOT                ,EDQUOT          ),  /* 122     Quota exceeded */
 | 
					    MBED_DEFINE_POSIX_ERROR(EDQUOT, EDQUOT),                            /* 122     Quota exceeded */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOMEDIUM             ,ENOMEDIUM       ),  /* 123     No medium found */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOMEDIUM, ENOMEDIUM),                      /* 123     No medium found */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EMEDIUMTYPE           ,EMEDIUMTYPE     ),  /* 124     Wrong medium type */
 | 
					    MBED_DEFINE_POSIX_ERROR(EMEDIUMTYPE, EMEDIUMTYPE),                  /* 124     Wrong medium type */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ECANCELED             ,ECANCELED       ),  /* 125     Operation Canceled */
 | 
					    MBED_DEFINE_POSIX_ERROR(ECANCELED, ECANCELED),                      /* 125     Operation Canceled */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOKEY                ,ENOKEY          ),  /* 126     Required key not available */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOKEY, ENOKEY),                            /* 126     Required key not available */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EKEYEXPIRED           ,EKEYEXPIRED     ),  /* 127     Key has expired */
 | 
					    MBED_DEFINE_POSIX_ERROR(EKEYEXPIRED, EKEYEXPIRED),                  /* 127     Key has expired */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EKEYREVOKED           ,EKEYREVOKED     ),  /* 128     Key has been revoked */
 | 
					    MBED_DEFINE_POSIX_ERROR(EKEYREVOKED, EKEYREVOKED),                  /* 128     Key has been revoked */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EKEYREJECTED          ,EKEYREJECTED    ),  /* 129     Key was rejected by service */
 | 
					    MBED_DEFINE_POSIX_ERROR(EKEYREJECTED, EKEYREJECTED),                /* 129     Key was rejected by service */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( EOWNERDEAD            ,EOWNERDEAD      ),  /* 130     Owner died */
 | 
					    MBED_DEFINE_POSIX_ERROR(EOWNERDEAD, EOWNERDEAD),                    /* 130     Owner died */
 | 
				
			||||||
    MBED_DEFINE_POSIX_ERROR( ENOTRECOVERABLE       ,ENOTRECOVERABLE ),  /* 131     State not recoverable */
 | 
					    MBED_DEFINE_POSIX_ERROR(ENOTRECOVERABLE, ENOTRECOVERABLE),          /* 131     State not recoverable */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Below are MBED SYSTEM ERROR CODE definitions
 | 
					    //Below are MBED SYSTEM ERROR CODE definitions
 | 
				
			||||||
    //MBED SYSTEM ERROR CODE definitions starts at offset MBED_SYSTEM_ERROR_BASE, see above.
 | 
					    //MBED SYSTEM ERROR CODE definitions starts at offset MBED_SYSTEM_ERROR_BASE, see above.
 | 
				
			||||||
    //                   Error Name                 Error Offset   Error Code
 | 
					    //                   Error Name                 Error Offset   Error Code
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( UNKNOWN                    ,0 ),          /* 256      Unknown error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(UNKNOWN, 0),                               /* 256      Unknown error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT           ,1 ),          /* 257      Invalid Argument */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INVALID_ARGUMENT, 1),                      /* 257      Invalid Argument */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INVALID_DATA_DETECTED      ,2 ),          /* 258      Invalid data detected */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INVALID_DATA_DETECTED, 2),                 /* 258      Invalid data detected */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INVALID_FORMAT             ,3 ),          /* 259      Invalid format */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INVALID_FORMAT, 3),                        /* 259      Invalid format */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INVALID_INDEX              ,4 ),          /* 260      Invalid Index */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INVALID_INDEX, 4),                         /* 260      Invalid Index */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INVALID_SIZE               ,5 ),          /* 261      Inavlid Size */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INVALID_SIZE, 5),                          /* 261      Inavlid Size */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INVALID_OPERATION          ,6 ),          /* 262      Invalid Operation */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INVALID_OPERATION, 6),                     /* 262      Invalid Operation */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( ITEM_NOT_FOUND             ,7 ),          /* 263      Item Not Found */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(ITEM_NOT_FOUND, 7),                        /* 263      Item Not Found */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( ACCESS_DENIED              ,8 ),          /* 264      Access Denied */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(ACCESS_DENIED, 8),                         /* 264      Access Denied */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( UNSUPPORTED                ,9 ),          /* 265      Unsupported */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(UNSUPPORTED, 9),                           /* 265      Unsupported */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( BUFFER_FULL                ,10 ),         /* 266      Buffer Full */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(BUFFER_FULL, 10),                          /* 266      Buffer Full */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( MEDIA_FULL                 ,11 ),         /* 267      Media/Disk Full */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(MEDIA_FULL, 11),                           /* 267      Media/Disk Full */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( ALREADY_IN_USE             ,12 ),         /* 268      Already in use */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(ALREADY_IN_USE, 12),                       /* 268      Already in use */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( TIME_OUT                   ,13 ),         /* 269      Timeout error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(TIME_OUT, 13),                             /* 269      Timeout error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( NOT_READY                  ,14 ),         /* 270      Not Ready */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(NOT_READY, 14),                            /* 270      Not Ready */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( FAILED_OPERATION           ,15 ),         /* 271      Requested Operation failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(FAILED_OPERATION, 15),                     /* 271      Requested Operation failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( OPERATION_PROHIBITED       ,16 ),         /* 272      Operation prohibited */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(OPERATION_PROHIBITED, 16),                 /* 272      Operation prohibited */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( OPERATION_ABORTED          ,17 ),         /* 273      Operation failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(OPERATION_ABORTED, 17),                    /* 273      Operation failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( WRITE_PROTECTED            ,18 ),         /* 274      Attempt to write to write-protected resource */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(WRITE_PROTECTED, 18),                      /* 274      Attempt to write to write-protected resource */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( NO_RESPONSE                ,19 ),         /* 275      No response */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(NO_RESPONSE, 19),                          /* 275      No response */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( SEMAPHORE_LOCK_FAILED      ,20 ),         /* 276      Sempahore lock failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(SEMAPHORE_LOCK_FAILED, 20),                /* 276      Sempahore lock failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( MUTEX_LOCK_FAILED          ,21 ),         /* 277      Mutex lock failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(MUTEX_LOCK_FAILED, 21),                    /* 277      Mutex lock failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( SEMAPHORE_UNLOCK_FAILED    ,22 ),         /* 278      Sempahore unlock failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(SEMAPHORE_UNLOCK_FAILED, 22),              /* 278      Sempahore unlock failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( MUTEX_UNLOCK_FAILED        ,23 ),         /* 279      Mutex unlock failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(MUTEX_UNLOCK_FAILED, 23),                  /* 279      Mutex unlock failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CRC_ERROR                  ,24 ),         /* 280      CRC error or mismatch */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CRC_ERROR, 24),                            /* 280      CRC error or mismatch */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( OPEN_FAILED                ,25 ),         /* 281      Open failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(OPEN_FAILED, 25),                          /* 281      Open failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CLOSE_FAILED               ,26 ),         /* 282      Close failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CLOSE_FAILED, 26),                         /* 282      Close failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( READ_FAILED                ,27 ),         /* 283      Read failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(READ_FAILED, 27),                          /* 283      Read failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( WRITE_FAILED               ,28 ),         /* 284      Write failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(WRITE_FAILED, 28),                         /* 284      Write failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( INITIALIZATION_FAILED      ,29 ),         /* 285      Initialization failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(INITIALIZATION_FAILED, 29),                /* 285      Initialization failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( BOOT_FAILURE               ,30 ),         /* 286      Boot failure */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(BOOT_FAILURE, 30),                         /* 286      Boot failure */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( OUT_OF_MEMORY              ,31 ),         /* 287      Out of memory */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(OUT_OF_MEMORY, 31),                        /* 287      Out of memory */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( OUT_OF_RESOURCES           ,32 ),         /* 288      Out of resources */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(OUT_OF_RESOURCES, 32),                     /* 288      Out of resources */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( ALLOC_FAILED               ,33 ),         /* 289      Alloc failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(ALLOC_FAILED, 33),                         /* 289      Alloc failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( FREE_FAILED                ,34 ),         /* 290      Free failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(FREE_FAILED, 34),                          /* 290      Free failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( OVERFLOW                   ,35 ),         /* 291      Overflow error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(OVERFLOW, 35),                             /* 291      Overflow error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( UNDERFLOW                  ,36 ),         /* 292      Underflow error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(UNDERFLOW, 36),                            /* 292      Underflow error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( STACK_OVERFLOW             ,37 ),         /* 293      Stack overflow error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(STACK_OVERFLOW, 37),                       /* 293      Stack overflow error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( ISR_QUEUE_OVERFLOW         ,38 ),         /* 294      ISR queue overflow */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(ISR_QUEUE_OVERFLOW, 38),                   /* 294      ISR queue overflow */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( TIMER_QUEUE_OVERFLOW       ,39 ),         /* 295      Timer Queue overflow */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(TIMER_QUEUE_OVERFLOW, 39),                 /* 295      Timer Queue overflow */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CLIB_SPACE_UNAVAILABLE     ,40 ),         /* 296      Standard library error - Space unavailable */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CLIB_SPACE_UNAVAILABLE, 40),               /* 296      Standard library error - Space unavailable */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CLIB_EXCEPTION             ,41 ),         /* 297      Standard library error - Exception */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CLIB_EXCEPTION, 41),                       /* 297      Standard library error - Exception */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CLIB_MUTEX_INIT_FAILURE    ,42 ),         /* 298      Standard library error - Mutex Init failure */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CLIB_MUTEX_INIT_FAILURE, 42),              /* 298      Standard library error - Mutex Init failure */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CREATE_FAILED              ,43 ),         /* 299      Create failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CREATE_FAILED, 43),                        /* 299      Create failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( DELETE_FAILED              ,44 ),         /* 300      Delete failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(DELETE_FAILED, 44),                        /* 300      Delete failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( THREAD_CREATE_FAILED       ,45 ),         /* 301      Thread Create failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(THREAD_CREATE_FAILED, 45),                 /* 301      Thread Create failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( THREAD_DELETE_FAILED       ,46 ),         /* 302      Thread Delete failed */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(THREAD_DELETE_FAILED, 46),                 /* 302      Thread Delete failed */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( PROHIBITED_IN_ISR_CONTEXT  ,47 ),         /* 303      Operation Prohibited in ISR context */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(PROHIBITED_IN_ISR_CONTEXT, 47),            /* 303      Operation Prohibited in ISR context */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( PINMAP_INVALID             ,48 ),         /* 304      Pinmap Invalid */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(PINMAP_INVALID, 48),                       /* 304      Pinmap Invalid */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_EVENT                 ,49 ),         /* 305      Unknown Rtos Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_EVENT, 49),                           /* 305      Unknown Rtos Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_THREAD_EVENT          ,50 ),         /* 306      Rtos Thread Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_THREAD_EVENT, 50),                    /* 306      Rtos Thread Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_MUTEX_EVENT           ,51 ),         /* 307      Rtos Mutex Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_MUTEX_EVENT, 51),                     /* 307      Rtos Mutex Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_SEMAPHORE_EVENT       ,52 ),         /* 308      Rtos Semaphore Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_SEMAPHORE_EVENT, 52),                 /* 308      Rtos Semaphore Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_MEMORY_POOL_EVENT     ,53 ),         /* 309      Rtos Memory Pool Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_MEMORY_POOL_EVENT, 53),               /* 309      Rtos Memory Pool Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_TIMER_EVENT           ,54 ),         /* 310      Rtos Timer Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_TIMER_EVENT, 54),                     /* 310      Rtos Timer Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_EVENT_FLAGS_EVENT     ,55 ),         /* 311      Rtos Event flags Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_EVENT_FLAGS_EVENT, 55),               /* 311      Rtos Event flags Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( RTOS_MESSAGE_QUEUE_EVENT   ,56 ),         /* 312      Rtos Message queue Error */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(RTOS_MESSAGE_QUEUE_EVENT, 56),             /* 312      Rtos Message queue Error */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( DEVICE_BUSY                ,57 ),         /* 313      Device Busy */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(DEVICE_BUSY, 57),                          /* 313      Device Busy */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CONFIG_UNSUPPORTED         ,58 ),         /* 314      Configuration not supported */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CONFIG_UNSUPPORTED, 58),                   /* 314      Configuration not supported */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( CONFIG_MISMATCH            ,59 ),         /* 315      Configuration mismatch */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(CONFIG_MISMATCH, 59),                      /* 315      Configuration mismatch */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( ALREADY_INITIALIZED        ,60 ),         /* 316      Already initialzied */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(ALREADY_INITIALIZED, 60),                  /* 316      Already initialzied */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( HARDFAULT_EXCEPTION        ,61 ),         /* 317      HardFault exception */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(HARDFAULT_EXCEPTION, 61),                  /* 317      HardFault exception */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( MEMMANAGE_EXCEPTION        ,62 ),         /* 318      MemManage exception */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(MEMMANAGE_EXCEPTION, 62),                  /* 318      MemManage exception */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( BUSFAULT_EXCEPTION         ,63 ),         /* 319      BusFault exception */
 | 
					    MBED_DEFINE_SYSTEM_ERROR(BUSFAULT_EXCEPTION, 63),                   /* 319      BusFault exception */
 | 
				
			||||||
    MBED_DEFINE_SYSTEM_ERROR( USAGEFAULT_EXCEPTION       ,64 ),         /* 320      UsageFault exception*/
 | 
					    MBED_DEFINE_SYSTEM_ERROR(USAGEFAULT_EXCEPTION, 64),                 /* 320      UsageFault exception*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Everytime you add a new system error code, you must update
 | 
					    //Everytime you add a new system error code, you must update
 | 
				
			||||||
    //Error documentation under Handbook to capture the info on
 | 
					    //Error documentation under Handbook to capture the info on
 | 
				
			||||||
| 
						 | 
					@ -865,7 +864,7 @@ typedef struct _mbed_error_ctx {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void error(const char* format, ...);
 | 
					void error(const char *format, ...);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Call this Macro to generate a mbed_error_status_t value for a System error
 | 
					 * Call this Macro to generate a mbed_error_status_t value for a System error
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,7 +84,7 @@ mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbed_error_hist_get_count()
 | 
					int mbed_error_hist_get_count()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE? MBED_CONF_PLATFORM_ERROR_HIST_SIZE:error_log_count+1);
 | 
					    return (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE ? MBED_CONF_PLATFORM_ERROR_HIST_SIZE : error_log_count + 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mbed_error_status_t mbed_error_hist_reset()
 | 
					mbed_error_status_t mbed_error_hist_reset()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,11 +17,11 @@
 | 
				
			||||||
#define MBED_ERROR_HIST_H
 | 
					#define MBED_ERROR_HIST_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef MBED_CONF_PLATFORM_ERROR_HIST_SIZE
 | 
					#ifndef MBED_CONF_PLATFORM_ERROR_HIST_SIZE
 | 
				
			||||||
    #define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  4
 | 
					#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  4
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    #if MBED_CONF_PLATFORM_ERROR_HIST_SIZE == 0
 | 
					#if MBED_CONF_PLATFORM_ERROR_HIST_SIZE == 0
 | 
				
			||||||
        #define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  1
 | 
					#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  1
 | 
				
			||||||
    #endif    
 | 
					#endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,11 +25,13 @@
 | 
				
			||||||
#if DEVICE_SEMIHOST
 | 
					#if DEVICE_SEMIHOST
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// return true if a debugger is attached, indicating mbed interface is connected
 | 
					// return true if a debugger is attached, indicating mbed interface is connected
 | 
				
			||||||
int mbed_interface_connected(void) {
 | 
					int mbed_interface_connected(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return semihost_connected();
 | 
					    return semihost_connected();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbed_interface_reset(void) {
 | 
					int mbed_interface_reset(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (mbed_interface_connected()) {
 | 
					    if (mbed_interface_connected()) {
 | 
				
			||||||
        semihost_reset();
 | 
					        semihost_reset();
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
| 
						 | 
					@ -38,7 +40,8 @@ int mbed_interface_reset(void) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WEAK int mbed_interface_uid(char *uid) {
 | 
					WEAK int mbed_interface_uid(char *uid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (mbed_interface_connected()) {
 | 
					    if (mbed_interface_connected()) {
 | 
				
			||||||
        return semihost_uid(uid); // Returns 0 if successful, -1 on failure
 | 
					        return semihost_uid(uid); // Returns 0 if successful, -1 on failure
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					@ -47,11 +50,13 @@ WEAK int mbed_interface_uid(char *uid) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbed_interface_disconnect(void) {
 | 
					int mbed_interface_disconnect(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int res;
 | 
					    int res;
 | 
				
			||||||
    if (mbed_interface_connected()) {
 | 
					    if (mbed_interface_connected()) {
 | 
				
			||||||
        if ((res = semihost_disabledebug()) != 0)
 | 
					        if ((res = semihost_disabledebug()) != 0) {
 | 
				
			||||||
            return res;
 | 
					            return res;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        while (mbed_interface_connected());
 | 
					        while (mbed_interface_connected());
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					@ -59,11 +64,13 @@ int mbed_interface_disconnect(void) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbed_interface_powerdown(void) {
 | 
					int mbed_interface_powerdown(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int res;
 | 
					    int res;
 | 
				
			||||||
    if (mbed_interface_connected()) {
 | 
					    if (mbed_interface_connected()) {
 | 
				
			||||||
        if ((res = semihost_powerdown()) != 0)
 | 
					        if ((res = semihost_powerdown()) != 0) {
 | 
				
			||||||
            return res;
 | 
					            return res;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        while (mbed_interface_connected());
 | 
					        while (mbed_interface_connected());
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					@ -72,17 +79,20 @@ int mbed_interface_powerdown(void) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code."
 | 
					MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code."
 | 
				
			||||||
    "For system reset funcionality use system_reset()")
 | 
					                      "For system reset funcionality use system_reset()")
 | 
				
			||||||
void mbed_reset(void) {
 | 
					void mbed_reset(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    mbed_interface_reset();
 | 
					    mbed_interface_reset();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WEAK int mbed_uid(char *uid) {
 | 
					WEAK int mbed_uid(char *uid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return mbed_interface_uid(uid);
 | 
					    return mbed_interface_uid(uid);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WEAK void mbed_mac_address(char *mac) {
 | 
					WEAK void mbed_mac_address(char *mac)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if DEVICE_SEMIHOST
 | 
					#if DEVICE_SEMIHOST
 | 
				
			||||||
    char uid[DEVICE_ID_LENGTH + 1];
 | 
					    char uid[DEVICE_ID_LENGTH + 1];
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
| 
						 | 
					@ -93,7 +103,7 @@ WEAK void mbed_mac_address(char *mac) {
 | 
				
			||||||
#if defined(DEVICE_MAC_OFFSET)
 | 
					#if defined(DEVICE_MAC_OFFSET)
 | 
				
			||||||
        p += DEVICE_MAC_OFFSET;
 | 
					        p += DEVICE_MAC_OFFSET;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
        for (i=0; i<6; i++) {
 | 
					        for (i = 0; i < 6; i++) {
 | 
				
			||||||
            int byte;
 | 
					            int byte;
 | 
				
			||||||
            sscanf(p, "%2x", &byte);
 | 
					            sscanf(p, "%2x", &byte);
 | 
				
			||||||
            mac[i] = byte;
 | 
					            mac[i] = byte;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,7 +135,7 @@ void mbed_die(void);
 | 
				
			||||||
 * @endcode
 | 
					 * @endcode
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void mbed_error_printf(const char* format, ...);
 | 
					void mbed_error_printf(const char *format, ...);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Print out an error message.  Similar to mbed_error_printf
 | 
					/** Print out an error message.  Similar to mbed_error_printf
 | 
				
			||||||
 * but uses a va_list.
 | 
					 * but uses a va_list.
 | 
				
			||||||
| 
						 | 
					@ -146,7 +146,7 @@ void mbed_error_printf(const char* format, ...);
 | 
				
			||||||
 * @param arg       Variable arguments list
 | 
					 * @param arg       Variable arguments list
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void mbed_error_vfprintf(const char * format, va_list arg);
 | 
					void mbed_error_vfprintf(const char *format, va_list arg);
 | 
				
			||||||
/** @}*/
 | 
					/** @}*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,8 @@ static SingletonPtr<PlatformMutex> mem_trace_mutex;
 | 
				
			||||||
 * Public interface
 | 
					 * Public interface
 | 
				
			||||||
 *****************************************************************************/
 | 
					 *****************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb) {
 | 
					void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    mem_trace_cb = cb;
 | 
					    mem_trace_cb = cb;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,7 +58,8 @@ void mbed_mem_trace_unlock()
 | 
				
			||||||
    mem_trace_mutex->unlock();
 | 
					    mem_trace_mutex->unlock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *mbed_mem_trace_malloc(void *res, size_t size, void *caller) {
 | 
					void *mbed_mem_trace_malloc(void *res, size_t size, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (mem_trace_cb) {
 | 
					    if (mem_trace_cb) {
 | 
				
			||||||
        if (TRACE_FIRST_LOCK()) {
 | 
					        if (TRACE_FIRST_LOCK()) {
 | 
				
			||||||
            mem_trace_cb(MBED_MEM_TRACE_MALLOC, res, caller, size);
 | 
					            mem_trace_cb(MBED_MEM_TRACE_MALLOC, res, caller, size);
 | 
				
			||||||
| 
						 | 
					@ -66,7 +68,8 @@ void *mbed_mem_trace_malloc(void *res, size_t size, void *caller) {
 | 
				
			||||||
    return res;
 | 
					    return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller) {
 | 
					void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (mem_trace_cb) {
 | 
					    if (mem_trace_cb) {
 | 
				
			||||||
        if (TRACE_FIRST_LOCK()) {
 | 
					        if (TRACE_FIRST_LOCK()) {
 | 
				
			||||||
            mem_trace_cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size);
 | 
					            mem_trace_cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size);
 | 
				
			||||||
| 
						 | 
					@ -75,7 +78,8 @@ void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller) {
 | 
				
			||||||
    return res;
 | 
					    return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller) {
 | 
					void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (mem_trace_cb) {
 | 
					    if (mem_trace_cb) {
 | 
				
			||||||
        if (TRACE_FIRST_LOCK()) {
 | 
					        if (TRACE_FIRST_LOCK()) {
 | 
				
			||||||
            mem_trace_cb(MBED_MEM_TRACE_CALLOC, res, caller, num, size);
 | 
					            mem_trace_cb(MBED_MEM_TRACE_CALLOC, res, caller, num, size);
 | 
				
			||||||
| 
						 | 
					@ -84,7 +88,8 @@ void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller) {
 | 
				
			||||||
    return res;
 | 
					    return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbed_mem_trace_free(void *ptr, void *caller) {
 | 
					void mbed_mem_trace_free(void *ptr, void *caller)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (mem_trace_cb) {
 | 
					    if (mem_trace_cb) {
 | 
				
			||||||
        if (TRACE_FIRST_LOCK()) {
 | 
					        if (TRACE_FIRST_LOCK()) {
 | 
				
			||||||
            mem_trace_cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr);
 | 
					            mem_trace_cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr);
 | 
				
			||||||
| 
						 | 
					@ -92,20 +97,21 @@ void mbed_mem_trace_free(void *ptr, void *caller) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...) {
 | 
					void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    va_list va;
 | 
					    va_list va;
 | 
				
			||||||
    size_t temp_s1, temp_s2;
 | 
					    size_t temp_s1, temp_s2;
 | 
				
			||||||
    void *temp_ptr;
 | 
					    void *temp_ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    va_start(va, caller);
 | 
					    va_start(va, caller);
 | 
				
			||||||
    switch(op) {
 | 
					    switch (op) {
 | 
				
			||||||
        case MBED_MEM_TRACE_MALLOC:
 | 
					        case MBED_MEM_TRACE_MALLOC:
 | 
				
			||||||
            temp_s1 = va_arg(va, size_t);
 | 
					            temp_s1 = va_arg(va, size_t);
 | 
				
			||||||
            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "m:%p;%p-%u\n", res, caller, temp_s1);
 | 
					            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "m:%p;%p-%u\n", res, caller, temp_s1);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case MBED_MEM_TRACE_REALLOC:
 | 
					        case MBED_MEM_TRACE_REALLOC:
 | 
				
			||||||
            temp_ptr = va_arg(va, void*);
 | 
					            temp_ptr = va_arg(va, void *);
 | 
				
			||||||
            temp_s1 = va_arg(va, size_t);
 | 
					            temp_s1 = va_arg(va, size_t);
 | 
				
			||||||
            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "r:%p;%p-%p;%u\n", res, caller, temp_ptr, temp_s1);
 | 
					            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "r:%p;%p-%p;%u\n", res, caller, temp_ptr, temp_s1);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
| 
						 | 
					@ -117,7 +123,7 @@ void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...) {
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case MBED_MEM_TRACE_FREE:
 | 
					        case MBED_MEM_TRACE_FREE:
 | 
				
			||||||
            temp_ptr = va_arg(va, void*);
 | 
					            temp_ptr = va_arg(va, void *);
 | 
				
			||||||
            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "f:%p;%p-%p\n", res, caller, temp_ptr);
 | 
					            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "f:%p;%p-%p\n", res, caller, temp_ptr);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ enum {
 | 
				
			||||||
 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
 | 
					 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
 | 
				
			||||||
 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr).
 | 
					 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr).
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...);
 | 
					typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void *caller, ...);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Set the callback used by the memory tracer (use NULL for disable tracing).
 | 
					 * Set the callback used by the memory tracer (use NULL for disable tracing).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,34 +39,35 @@ static const uint32_t seconds_before_month[2][12] = {
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        0,
 | 
					        0,
 | 
				
			||||||
        31 * SECONDS_BY_DAY,
 | 
					        31 * SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28) * SECONDS_BY_DAY,
 | 
					        (31 + 28) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31 + 30 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        0,
 | 
					        0,
 | 
				
			||||||
        31 * SECONDS_BY_DAY,
 | 
					        31 * SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29) * SECONDS_BY_DAY,
 | 
					        (31 + 29) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31 + 30 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31 + 30 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) *SECONDS_BY_DAY,
 | 
				
			||||||
        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
 | 
					        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support) {
 | 
					bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * since in practice, the value manipulated by this algorithm lie in the
 | 
					     * since in practice, the value manipulated by this algorithm lie in the
 | 
				
			||||||
     * range: [70 : 206] the algorithm can be reduced to: year % 4 with exception for 200 (year 2100 is not leap year).
 | 
					     * range: [70 : 206] the algorithm can be reduced to: year % 4 with exception for 200 (year 2100 is not leap year).
 | 
				
			||||||
| 
						 | 
					@ -90,7 +91,8 @@ bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support) {
 | 
				
			||||||
    return (year) % 4 ? false : true;
 | 
					    return (year) % 4 ? false : true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_support_t leap_year_support) {
 | 
					bool _rtc_maketime(const struct tm *time, time_t *seconds, rtc_leap_year_support_t leap_year_support)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (seconds == NULL || time == NULL) {
 | 
					    if (seconds == NULL || time == NULL) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -111,8 +113,8 @@ bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_suppor
 | 
				
			||||||
    /* Check if we are within valid range. */
 | 
					    /* Check if we are within valid range. */
 | 
				
			||||||
    if (time->tm_year == LAST_VALID_YEAR) {
 | 
					    if (time->tm_year == LAST_VALID_YEAR) {
 | 
				
			||||||
        if ((leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_FULL_LEAP_YEAR_SUPPORT) ||
 | 
					        if ((leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_FULL_LEAP_YEAR_SUPPORT) ||
 | 
				
			||||||
            (leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT)) {
 | 
					                (leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT)) {
 | 
				
			||||||
        return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,7 +135,8 @@ bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_suppor
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool _rtc_localtime(time_t timestamp, struct tm* time_info, rtc_leap_year_support_t leap_year_support) {
 | 
					bool _rtc_localtime(time_t timestamp, struct tm *time_info, rtc_leap_year_support_t leap_year_support)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (time_info == NULL) {
 | 
					    if (time_info == NULL) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -90,7 +90,7 @@ bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support);
 | 
				
			||||||
 * @note Full and partial leap years support.
 | 
					 * @note Full and partial leap years support.
 | 
				
			||||||
 * @note For use by the HAL only
 | 
					 * @note For use by the HAL only
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_support_t leap_year_support);
 | 
					bool _rtc_maketime(const struct tm *time, time_t *seconds, rtc_leap_year_support_t leap_year_support);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Convert a given time in seconds since epoch into calendar time.
 | 
					/* Convert a given time in seconds since epoch into calendar time.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -118,7 +118,7 @@ bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_suppor
 | 
				
			||||||
 * @note For use by the HAL only.
 | 
					 * @note For use by the HAL only.
 | 
				
			||||||
 * @note Full and partial leap years support.
 | 
					 * @note Full and partial leap years support.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
bool _rtc_localtime(time_t timestamp, struct tm* time_info, rtc_leap_year_support_t leap_year_support);
 | 
					bool _rtc_localtime(time_t timestamp, struct tm *time_info, rtc_leap_year_support_t leap_year_support);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** @}*/
 | 
					/** @}*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,10 +111,11 @@ static SingletonPtr<PlatformMutex> filehandle_mutex;
 | 
				
			||||||
namespace mbed {
 | 
					namespace mbed {
 | 
				
			||||||
void mbed_set_unbuffered_stream(std::FILE *_file);
 | 
					void mbed_set_unbuffered_stream(std::FILE *_file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void remove_filehandle(FileHandle *file) {
 | 
					void remove_filehandle(FileHandle *file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    filehandle_mutex->lock();
 | 
					    filehandle_mutex->lock();
 | 
				
			||||||
    /* Remove all open filehandles for this */
 | 
					    /* Remove all open filehandles for this */
 | 
				
			||||||
    for (unsigned int fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
 | 
					    for (unsigned int fh_i = 0; fh_i < sizeof(filehandles) / sizeof(*filehandles); fh_i++) {
 | 
				
			||||||
        if (filehandles[fh_i] == file) {
 | 
					        if (filehandles[fh_i] == file) {
 | 
				
			||||||
            filehandles[fh_i] = NULL;
 | 
					            filehandles[fh_i] = NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -137,23 +138,30 @@ public:
 | 
				
			||||||
    DirectSerial(PinName tx, PinName rx, int baud);
 | 
					    DirectSerial(PinName tx, PinName rx, int baud);
 | 
				
			||||||
    virtual ssize_t write(const void *buffer, size_t size);
 | 
					    virtual ssize_t write(const void *buffer, size_t size);
 | 
				
			||||||
    virtual ssize_t read(void *buffer, size_t size);
 | 
					    virtual ssize_t read(void *buffer, size_t size);
 | 
				
			||||||
    virtual off_t seek(off_t offset, int whence = SEEK_SET) {
 | 
					    virtual off_t seek(off_t offset, int whence = SEEK_SET)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return -ESPIPE;
 | 
					        return -ESPIPE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    virtual off_t size() {
 | 
					    virtual off_t size()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return -EINVAL;
 | 
					        return -EINVAL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    virtual int isatty() {
 | 
					    virtual int isatty()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    virtual int close() {
 | 
					    virtual int close()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    virtual short poll(short events) const;
 | 
					    virtual short poll(short events) const;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) {
 | 
					DirectSerial::DirectSerial(PinName tx, PinName rx, int baud)
 | 
				
			||||||
    if (stdio_uart_inited) return;
 | 
					{
 | 
				
			||||||
 | 
					    if (stdio_uart_inited) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    serial_init(&stdio_uart, tx, rx);
 | 
					    serial_init(&stdio_uart, tx, rx);
 | 
				
			||||||
    serial_baud(&stdio_uart, baud);
 | 
					    serial_baud(&stdio_uart, baud);
 | 
				
			||||||
#if   CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
 | 
					#if   CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
 | 
				
			||||||
| 
						 | 
					@ -165,7 +173,8 @@ DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t DirectSerial::write(const void *buffer, size_t size) {
 | 
					ssize_t DirectSerial::write(const void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    const unsigned char *buf = static_cast<const unsigned char *>(buffer);
 | 
					    const unsigned char *buf = static_cast<const unsigned char *>(buffer);
 | 
				
			||||||
    for (size_t i = 0; i < size; i++) {
 | 
					    for (size_t i = 0; i < size; i++) {
 | 
				
			||||||
        serial_putc(&stdio_uart, buf[i]);
 | 
					        serial_putc(&stdio_uart, buf[i]);
 | 
				
			||||||
| 
						 | 
					@ -173,7 +182,8 @@ ssize_t DirectSerial::write(const void *buffer, size_t size) {
 | 
				
			||||||
    return size;
 | 
					    return size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t DirectSerial::read(void *buffer, size_t size) {
 | 
					ssize_t DirectSerial::read(void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    unsigned char *buf = static_cast<unsigned char *>(buffer);
 | 
					    unsigned char *buf = static_cast<unsigned char *>(buffer);
 | 
				
			||||||
    if (size == 0) {
 | 
					    if (size == 0) {
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
| 
						 | 
					@ -182,7 +192,8 @@ ssize_t DirectSerial::read(void *buffer, size_t size) {
 | 
				
			||||||
    return 1;
 | 
					    return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
short DirectSerial::poll(short events) const {
 | 
					short DirectSerial::poll(short events) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    short revents = 0;
 | 
					    short revents = 0;
 | 
				
			||||||
    if ((events & POLLIN) && serial_readable(&stdio_uart)) {
 | 
					    if ((events & POLLIN) && serial_readable(&stdio_uart)) {
 | 
				
			||||||
        revents |= POLLIN;
 | 
					        revents |= POLLIN;
 | 
				
			||||||
| 
						 | 
					@ -198,18 +209,32 @@ class Sink : public FileHandle {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    virtual ssize_t write(const void *buffer, size_t size);
 | 
					    virtual ssize_t write(const void *buffer, size_t size);
 | 
				
			||||||
    virtual ssize_t read(void *buffer, size_t size);
 | 
					    virtual ssize_t read(void *buffer, size_t size);
 | 
				
			||||||
    virtual off_t seek(off_t offset, int whence = SEEK_SET) { return ESPIPE; }
 | 
					    virtual off_t seek(off_t offset, int whence = SEEK_SET)
 | 
				
			||||||
    virtual off_t size() { return -EINVAL; }
 | 
					    {
 | 
				
			||||||
    virtual int isatty() { return true; }
 | 
					        return ESPIPE;
 | 
				
			||||||
    virtual int close() { return 0; }
 | 
					    }
 | 
				
			||||||
 | 
					    virtual off_t size()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return -EINVAL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    virtual int isatty()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    virtual int close()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t Sink::write(const void *buffer, size_t size) {
 | 
					ssize_t Sink::write(const void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // Just swallow the data - this is historical non-DEVICE_SERIAL behaviour
 | 
					    // Just swallow the data - this is historical non-DEVICE_SERIAL behaviour
 | 
				
			||||||
    return size;
 | 
					    return size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t Sink::read(void *buffer, size_t size) {
 | 
					ssize_t Sink::read(void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // Produce 1 zero byte - historical behaviour returned 1 without touching
 | 
					    // Produce 1 zero byte - historical behaviour returned 1 without touching
 | 
				
			||||||
    // the buffer
 | 
					    // the buffer
 | 
				
			||||||
    unsigned char *buf = static_cast<unsigned char *>(buffer);
 | 
					    unsigned char *buf = static_cast<unsigned char *>(buffer);
 | 
				
			||||||
| 
						 | 
					@ -218,27 +243,27 @@ ssize_t Sink::read(void *buffer, size_t size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MBED_WEAK FileHandle* mbed::mbed_target_override_console(int fd)
 | 
					MBED_WEAK FileHandle *mbed::mbed_target_override_console(int fd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MBED_WEAK FileHandle* mbed::mbed_override_console(int fd)
 | 
					MBED_WEAK FileHandle *mbed::mbed_override_console(int fd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static FileHandle* default_console()
 | 
					static FileHandle *default_console()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if DEVICE_SERIAL
 | 
					#if DEVICE_SERIAL
 | 
				
			||||||
#  if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL
 | 
					#  if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL
 | 
				
			||||||
    static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 | 
					    static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 | 
				
			||||||
#   if   CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
 | 
					#   if   CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
 | 
				
			||||||
        console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC);
 | 
					    console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC);
 | 
				
			||||||
#   elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS
 | 
					#   elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS
 | 
				
			||||||
        console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS);
 | 
					    console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS);
 | 
				
			||||||
#   elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS
 | 
					#   elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS
 | 
				
			||||||
        console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS);
 | 
					    console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS);
 | 
				
			||||||
#   endif
 | 
					#   endif
 | 
				
			||||||
#  else
 | 
					#  else
 | 
				
			||||||
    static DirectSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 | 
					    static DirectSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 | 
				
			||||||
| 
						 | 
					@ -250,7 +275,8 @@ static FileHandle* default_console()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Locate the default console for stdout, stdin, stderr */
 | 
					/* Locate the default console for stdout, stdin, stderr */
 | 
				
			||||||
static FileHandle* get_console(int fd) {
 | 
					static FileHandle *get_console(int fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FileHandle *fh = mbed_override_console(fd);
 | 
					    FileHandle *fh = mbed_override_console(fd);
 | 
				
			||||||
    if (fh) {
 | 
					    if (fh) {
 | 
				
			||||||
        return fh;
 | 
					        return fh;
 | 
				
			||||||
| 
						 | 
					@ -263,7 +289,8 @@ static FileHandle* get_console(int fd) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Deal with the fact C library may not _open descriptors 0, 1, 2 - auto bind */
 | 
					/* Deal with the fact C library may not _open descriptors 0, 1, 2 - auto bind */
 | 
				
			||||||
static FileHandle* get_fhc(int fd) {
 | 
					static FileHandle *get_fhc(int fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (fd >= OPEN_MAX) {
 | 
					    if (fd >= OPEN_MAX) {
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -281,27 +308,29 @@ static FileHandle* get_fhc(int fd) {
 | 
				
			||||||
 * @param error is a negative error code returned from an mbed function and
 | 
					 * @param error is a negative error code returned from an mbed function and
 | 
				
			||||||
 *              will be negated to store a positive error code in errno
 | 
					 *              will be negated to store a positive error code in errno
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int handle_open_errors(int error, unsigned filehandle_idx) {
 | 
					static int handle_open_errors(int error, unsigned filehandle_idx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    errno = -error;
 | 
					    errno = -error;
 | 
				
			||||||
    // Free file handle
 | 
					    // Free file handle
 | 
				
			||||||
    filehandles[filehandle_idx] = NULL;
 | 
					    filehandles[filehandle_idx] = NULL;
 | 
				
			||||||
    return -1;
 | 
					    return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline int openflags_to_posix(int openflags) {
 | 
					static inline int openflags_to_posix(int openflags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int posix = openflags;
 | 
					    int posix = openflags;
 | 
				
			||||||
#ifdef __ARMCC_VERSION
 | 
					#ifdef __ARMCC_VERSION
 | 
				
			||||||
    if (openflags & OPEN_PLUS) {
 | 
					    if (openflags & OPEN_PLUS) {
 | 
				
			||||||
        posix = O_RDWR;
 | 
					        posix = O_RDWR;
 | 
				
			||||||
    } else if(openflags & OPEN_W) {
 | 
					    } else if (openflags & OPEN_W) {
 | 
				
			||||||
        posix = O_WRONLY;
 | 
					        posix = O_WRONLY;
 | 
				
			||||||
    } else if(openflags & OPEN_A) {
 | 
					    } else if (openflags & OPEN_A) {
 | 
				
			||||||
        posix = O_WRONLY|O_APPEND;
 | 
					        posix = O_WRONLY | O_APPEND;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        posix = O_RDONLY;
 | 
					        posix = O_RDONLY;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* a, w, a+, w+ all create if file does not already exist */
 | 
					    /* a, w, a+, w+ all create if file does not already exist */
 | 
				
			||||||
    if (openflags & (OPEN_A|OPEN_W)) {
 | 
					    if (openflags & (OPEN_A | OPEN_W)) {
 | 
				
			||||||
        posix |= O_CREAT;
 | 
					        posix |= O_CREAT;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* w and w+ truncate */
 | 
					    /* w and w+ truncate */
 | 
				
			||||||
| 
						 | 
					@ -310,26 +339,41 @@ static inline int openflags_to_posix(int openflags) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#elif defined(__ICCARM__)
 | 
					#elif defined(__ICCARM__)
 | 
				
			||||||
    switch (openflags & _LLIO_RDWRMASK) {
 | 
					    switch (openflags & _LLIO_RDWRMASK) {
 | 
				
			||||||
        case _LLIO_RDONLY: posix = O_RDONLY; break;
 | 
					        case _LLIO_RDONLY:
 | 
				
			||||||
        case _LLIO_WRONLY: posix = O_WRONLY; break;
 | 
					            posix = O_RDONLY;
 | 
				
			||||||
        case _LLIO_RDWR  : posix = O_RDWR  ; break;
 | 
					            break;
 | 
				
			||||||
 | 
					        case _LLIO_WRONLY:
 | 
				
			||||||
 | 
					            posix = O_WRONLY;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case _LLIO_RDWR  :
 | 
				
			||||||
 | 
					            posix = O_RDWR  ;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (openflags & _LLIO_CREAT) {
 | 
				
			||||||
 | 
					        posix |= O_CREAT;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (openflags & _LLIO_APPEND) {
 | 
				
			||||||
 | 
					        posix |= O_APPEND;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (openflags & _LLIO_TRUNC) {
 | 
				
			||||||
 | 
					        posix |= O_TRUNC;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (openflags & _LLIO_CREAT ) posix |= O_CREAT;
 | 
					 | 
				
			||||||
    if (openflags & _LLIO_APPEND) posix |= O_APPEND;
 | 
					 | 
				
			||||||
    if (openflags & _LLIO_TRUNC ) posix |= O_TRUNC;
 | 
					 | 
				
			||||||
#elif defined(TOOLCHAIN_GCC)
 | 
					#elif defined(TOOLCHAIN_GCC)
 | 
				
			||||||
    posix &= ~O_BINARY;
 | 
					    posix &= ~O_BINARY;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    return posix;
 | 
					    return posix;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int reserve_filehandle() {
 | 
					static int reserve_filehandle()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // find the first empty slot in filehandles, after the slots reserved for stdin/stdout/stderr
 | 
					    // find the first empty slot in filehandles, after the slots reserved for stdin/stdout/stderr
 | 
				
			||||||
    filehandle_mutex->lock();
 | 
					    filehandle_mutex->lock();
 | 
				
			||||||
    int fh_i;
 | 
					    int fh_i;
 | 
				
			||||||
    for (fh_i = 3; fh_i < OPEN_MAX; fh_i++) {
 | 
					    for (fh_i = 3; fh_i < OPEN_MAX; fh_i++) {
 | 
				
			||||||
        /* Take a next free filehandle slot available. */
 | 
					        /* Take a next free filehandle slot available. */
 | 
				
			||||||
        if (filehandles[fh_i] == NULL) break;
 | 
					        if (filehandles[fh_i] == NULL) {
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (fh_i >= OPEN_MAX) {
 | 
					    if (fh_i >= OPEN_MAX) {
 | 
				
			||||||
        /* Too many file handles have been opened */
 | 
					        /* Too many file handles have been opened */
 | 
				
			||||||
| 
						 | 
					@ -343,7 +387,8 @@ static int reserve_filehandle() {
 | 
				
			||||||
    return fh_i;
 | 
					    return fh_i;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbed::bind_to_fd(FileHandle *fh) {
 | 
					int mbed::bind_to_fd(FileHandle *fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int fildes = reserve_filehandle();
 | 
					    int fildes = reserve_filehandle();
 | 
				
			||||||
    if (fildes < 0) {
 | 
					    if (fildes < 0) {
 | 
				
			||||||
        return fildes;
 | 
					        return fildes;
 | 
				
			||||||
| 
						 | 
					@ -356,7 +401,8 @@ int mbed::bind_to_fd(FileHandle *fh) {
 | 
				
			||||||
    return fildes;
 | 
					    return fildes;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int unbind_from_fd(int fd, FileHandle *fh) {
 | 
					static int unbind_from_fd(int fd, FileHandle *fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (filehandles[fd] == fh) {
 | 
					    if (filehandles[fd] == fh) {
 | 
				
			||||||
        filehandles[fd] = NULL;
 | 
					        filehandles[fd] = NULL;
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
| 
						 | 
					@ -368,7 +414,7 @@ static int unbind_from_fd(int fd, FileHandle *fh) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef __IAR_SYSTEMS_ICC__
 | 
					#ifndef __IAR_SYSTEMS_ICC__
 | 
				
			||||||
/* IAR provides fdopen itself */
 | 
					/* IAR provides fdopen itself */
 | 
				
			||||||
extern "C" std::FILE* fdopen(int fildes, const char *mode)
 | 
					extern "C" std::FILE *fdopen(int fildes, const char *mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // This is to avoid scanf and the bloat it brings.
 | 
					    // This is to avoid scanf and the bloat it brings.
 | 
				
			||||||
    char buf[1 + sizeof fildes]; /* @(integer) */
 | 
					    char buf[1 + sizeof fildes]; /* @(integer) */
 | 
				
			||||||
| 
						 | 
					@ -405,18 +451,19 @@ std::FILE *fdopen(FileHandle *fh, const char *mode)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* @brief 	standard c library fopen() retargeting function.
 | 
					/* @brief   standard c library fopen() retargeting function.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This function is invoked by the standard c library retargeting to handle fopen()
 | 
					 * This function is invoked by the standard c library retargeting to handle fopen()
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return
 | 
					 * @return
 | 
				
			||||||
 *  On success, a valid FILEHANDLE is returned.
 | 
					 *  On success, a valid FILEHANDLE is returned.
 | 
				
			||||||
 *  On failure, -1 is returned and errno is set to an appropriate value e.g.
 | 
					 *  On failure, -1 is returned and errno is set to an appropriate value e.g.
 | 
				
			||||||
 *   ENOENT	    file not found (default errno setting)
 | 
					 *   ENOENT     file not found (default errno setting)
 | 
				
			||||||
 *	 EMFILE		the maximum number of open files was exceeded.
 | 
					 *   EMFILE     the maximum number of open files was exceeded.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * */
 | 
					 * */
 | 
				
			||||||
extern "C" FILEHANDLE PREFIX(_open)(const char *name, int openflags) {
 | 
					extern "C" FILEHANDLE PREFIX(_open)(const char *name, int openflags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if defined(__MICROLIB) && (__ARMCC_VERSION>5030000)
 | 
					#if defined(__MICROLIB) && (__ARMCC_VERSION>5030000)
 | 
				
			||||||
#if !defined(MBED_CONF_RTOS_PRESENT)
 | 
					#if !defined(MBED_CONF_RTOS_PRESENT)
 | 
				
			||||||
    // valid only for mbed 2
 | 
					    // valid only for mbed 2
 | 
				
			||||||
| 
						 | 
					@ -463,7 +510,8 @@ extern "C" FILEHANDLE PREFIX(_open)(const char *name, int openflags) {
 | 
				
			||||||
    return open(name, openflags_to_posix(openflags));
 | 
					    return open(name, openflags_to_posix(openflags));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int open(const char *name, int oflag, ...) {
 | 
					extern "C" int open(const char *name, int oflag, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int fildes = reserve_filehandle();
 | 
					    int fildes = reserve_filehandle();
 | 
				
			||||||
    if (fildes < 0) {
 | 
					    if (fildes < 0) {
 | 
				
			||||||
        return fildes;
 | 
					        return fildes;
 | 
				
			||||||
| 
						 | 
					@ -499,12 +547,14 @@ extern "C" int open(const char *name, int oflag, ...) {
 | 
				
			||||||
    return fildes;
 | 
					    return fildes;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int PREFIX(_close)(FILEHANDLE fh) {
 | 
					extern "C" int PREFIX(_close)(FILEHANDLE fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return close(fh);
 | 
					    return close(fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int close(int fildes) {
 | 
					extern "C" int close(int fildes)
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					{
 | 
				
			||||||
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    filehandles[fildes] = NULL;
 | 
					    filehandles[fildes] = NULL;
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
| 
						 | 
					@ -520,7 +570,8 @@ extern "C" int close(int fildes) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool convert_crlf(int fd) {
 | 
					static bool convert_crlf(int fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES
 | 
					#if MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES
 | 
				
			||||||
    return isatty(fd);
 | 
					    return isatty(fd);
 | 
				
			||||||
#elif MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
 | 
					#elif MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
 | 
				
			||||||
| 
						 | 
					@ -531,9 +582,11 @@ static bool convert_crlf(int fd) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__ICCARM__)
 | 
					#if defined(__ICCARM__)
 | 
				
			||||||
extern "C" size_t    __write (int        fh, const unsigned char *buffer, size_t length) {
 | 
					extern "C" size_t    __write(int        fh, const unsigned char *buffer, size_t length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode) {
 | 
					extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
 | 
					#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
 | 
				
			||||||
| 
						 | 
					@ -610,9 +663,10 @@ finish:
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" ssize_t write(int fildes, const void *buf, size_t length) {
 | 
					extern "C" ssize_t write(int fildes, const void *buf, size_t length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
| 
						 | 
					@ -628,20 +682,24 @@ extern "C" ssize_t write(int fildes, const void *buf, size_t length) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
 | 
					#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
 | 
				
			||||||
extern "C" void PREFIX(_exit)(int return_code) {
 | 
					extern "C" void PREFIX(_exit)(int return_code)
 | 
				
			||||||
    while(1) {}
 | 
					{
 | 
				
			||||||
 | 
					    while (1) {}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void _ttywrch(int ch) {
 | 
					extern "C" void _ttywrch(int ch)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    char c = ch;
 | 
					    char c = ch;
 | 
				
			||||||
    write(STDOUT_FILENO, &c, 1);
 | 
					    write(STDOUT_FILENO, &c, 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__ICCARM__)
 | 
					#if defined(__ICCARM__)
 | 
				
			||||||
extern "C" size_t    __read (int        fh, unsigned char *buffer, size_t       length) {
 | 
					extern "C" size_t    __read(int        fh, unsigned char *buffer, size_t       length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode) {
 | 
					extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
 | 
					#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
 | 
				
			||||||
| 
						 | 
					@ -668,7 +726,7 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
 | 
				
			||||||
                return bytes_read;
 | 
					                return bytes_read;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if ((c == '\r' && stdio_in_prev[fh] != '\n') ||
 | 
					            if ((c == '\r' && stdio_in_prev[fh] != '\n') ||
 | 
				
			||||||
                (c == '\n' && stdio_in_prev[fh] != '\r')) {
 | 
					                    (c == '\n' && stdio_in_prev[fh] != '\r')) {
 | 
				
			||||||
                stdio_in_prev[fh] = c;
 | 
					                stdio_in_prev[fh] = c;
 | 
				
			||||||
                *buffer = '\n';
 | 
					                *buffer = '\n';
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
| 
						 | 
					@ -700,9 +758,10 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" ssize_t read(int fildes, void *buf, size_t length) {
 | 
					extern "C" ssize_t read(int fildes, void *buf, size_t length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
| 
						 | 
					@ -727,8 +786,9 @@ extern "C" int _isatty(FILEHANDLE fh)
 | 
				
			||||||
    return isatty(fh);
 | 
					    return isatty(fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int isatty(int fildes) {
 | 
					extern "C" int isatty(int fildes)
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					{
 | 
				
			||||||
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
| 
						 | 
					@ -765,8 +825,9 @@ int _lseek(FILEHANDLE fh, int offset, int whence)
 | 
				
			||||||
    return off;
 | 
					    return off;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" off_t lseek(int fildes, off_t offset, int whence) {
 | 
					extern "C" off_t lseek(int fildes, off_t offset, int whence)
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					{
 | 
				
			||||||
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
| 
						 | 
					@ -781,13 +842,15 @@ extern "C" off_t lseek(int fildes, off_t offset, int whence) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __ARMCC_VERSION
 | 
					#ifdef __ARMCC_VERSION
 | 
				
			||||||
extern "C" int PREFIX(_ensure)(FILEHANDLE fh) {
 | 
					extern "C" int PREFIX(_ensure)(FILEHANDLE fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return fsync(fh);
 | 
					    return fsync(fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int fsync(int fildes) {
 | 
					extern "C" int fsync(int fildes)
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					{
 | 
				
			||||||
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
| 
						 | 
					@ -803,8 +866,9 @@ extern "C" int fsync(int fildes) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __ARMCC_VERSION
 | 
					#ifdef __ARMCC_VERSION
 | 
				
			||||||
extern "C" long PREFIX(_flen)(FILEHANDLE fh) {
 | 
					extern "C" long PREFIX(_flen)(FILEHANDLE fh)
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fh);
 | 
					{
 | 
				
			||||||
 | 
					    FileHandle *fhc = get_fhc(fh);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
| 
						 | 
					@ -837,7 +901,8 @@ extern "C" MBED_WEAK __value_in_regs struct __initial_stackheap _mbed_user_setup
 | 
				
			||||||
    return r;
 | 
					    return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) {
 | 
					extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return _mbed_user_setup_stackheap(R0, R1, R2, R3);
 | 
					    return _mbed_user_setup_stackheap(R0, R1, R2, R3);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -845,13 +910,15 @@ extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
 | 
					#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
 | 
				
			||||||
extern "C" int _fstat(int fh, struct stat *st) {
 | 
					extern "C" int _fstat(int fh, struct stat *st)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return fstat(fh, st);
 | 
					    return fstat(fh, st);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int fstat(int fildes, struct stat *st) {
 | 
					extern "C" int fstat(int fildes, struct stat *st)
 | 
				
			||||||
    FileHandle* fhc = get_fhc(fildes);
 | 
					{
 | 
				
			||||||
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
| 
						 | 
					@ -862,7 +929,8 @@ extern "C" int fstat(int fildes, struct stat *st) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int fcntl(int fildes, int cmd, ...) {
 | 
					extern "C" int fcntl(int fildes, int cmd, ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FileHandle *fhc = get_fhc(fildes);
 | 
					    FileHandle *fhc = get_fhc(fildes);
 | 
				
			||||||
    if (fhc == NULL) {
 | 
					    if (fhc == NULL) {
 | 
				
			||||||
        errno = EBADF;
 | 
					        errno = EBADF;
 | 
				
			||||||
| 
						 | 
					@ -919,7 +987,8 @@ extern "C" int poll(struct pollfd fds[], nfds_t nfds, int timeout)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace std {
 | 
					namespace std {
 | 
				
			||||||
extern "C" int remove(const char *path) {
 | 
					extern "C" int remove(const char *path)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FilePath fp(path);
 | 
					    FilePath fp(path);
 | 
				
			||||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
					    FileSystemHandle *fs = fp.fileSystem();
 | 
				
			||||||
    if (fs == NULL) {
 | 
					    if (fs == NULL) {
 | 
				
			||||||
| 
						 | 
					@ -936,7 +1005,8 @@ extern "C" int remove(const char *path) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int rename(const char *oldname, const char *newname) {
 | 
					extern "C" int rename(const char *oldname, const char *newname)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FilePath fpOld(oldname);
 | 
					    FilePath fpOld(oldname);
 | 
				
			||||||
    FilePath fpNew(newname);
 | 
					    FilePath fpNew(newname);
 | 
				
			||||||
    FileSystemHandle *fsOld = fpOld.fileSystem();
 | 
					    FileSystemHandle *fsOld = fpOld.fileSystem();
 | 
				
			||||||
| 
						 | 
					@ -962,26 +1032,30 @@ extern "C" int rename(const char *oldname, const char *newname) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" char *tmpnam(char *s) {
 | 
					extern "C" char *tmpnam(char *s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    errno = EBADF;
 | 
					    errno = EBADF;
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" FILE *tmpfile() {
 | 
					extern "C" FILE *tmpfile()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    errno = EBADF;
 | 
					    errno = EBADF;
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
} // namespace std
 | 
					} // namespace std
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __ARMCC_VERSION
 | 
					#ifdef __ARMCC_VERSION
 | 
				
			||||||
extern "C" char *_sys_command_string(char *cmd, int len) {
 | 
					extern "C" char *_sys_command_string(char *cmd, int len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" DIR *opendir(const char *path) {
 | 
					extern "C" DIR *opendir(const char *path)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FilePath fp(path);
 | 
					    FilePath fp(path);
 | 
				
			||||||
    FileSystemHandle* fs = fp.fileSystem();
 | 
					    FileSystemHandle *fs = fp.fileSystem();
 | 
				
			||||||
    if (fs == NULL) {
 | 
					    if (fs == NULL) {
 | 
				
			||||||
        errno = ENODEV;
 | 
					        errno = ENODEV;
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
| 
						 | 
					@ -997,7 +1071,8 @@ extern "C" DIR *opendir(const char *path) {
 | 
				
			||||||
    return dir;
 | 
					    return dir;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" struct dirent *readdir(DIR *dir) {
 | 
					extern "C" struct dirent *readdir(DIR *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    static struct dirent ent;
 | 
					    static struct dirent ent;
 | 
				
			||||||
    int err = dir->read(&ent);
 | 
					    int err = dir->read(&ent);
 | 
				
			||||||
    if (err < 1) {
 | 
					    if (err < 1) {
 | 
				
			||||||
| 
						 | 
					@ -1010,7 +1085,8 @@ extern "C" struct dirent *readdir(DIR *dir) {
 | 
				
			||||||
    return &ent;
 | 
					    return &ent;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int closedir(DIR *dir) {
 | 
					extern "C" int closedir(DIR *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int err = dir->close();
 | 
					    int err = dir->close();
 | 
				
			||||||
    if (err < 0) {
 | 
					    if (err < 0) {
 | 
				
			||||||
        errno = -err;
 | 
					        errno = -err;
 | 
				
			||||||
| 
						 | 
					@ -1020,19 +1096,23 @@ extern "C" int closedir(DIR *dir) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void rewinddir(DIR *dir) {
 | 
					extern "C" void rewinddir(DIR *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    dir->rewind();
 | 
					    dir->rewind();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" off_t telldir(DIR *dir) {
 | 
					extern "C" off_t telldir(DIR *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return dir->tell();
 | 
					    return dir->tell();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void seekdir(DIR *dir, off_t off) {
 | 
					extern "C" void seekdir(DIR *dir, off_t off)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    dir->seek(off);
 | 
					    dir->seek(off);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int mkdir(const char *path, mode_t mode) {
 | 
					extern "C" int mkdir(const char *path, mode_t mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FilePath fp(path);
 | 
					    FilePath fp(path);
 | 
				
			||||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
					    FileSystemHandle *fs = fp.fileSystem();
 | 
				
			||||||
    if (fs == NULL) {
 | 
					    if (fs == NULL) {
 | 
				
			||||||
| 
						 | 
					@ -1049,7 +1129,8 @@ extern "C" int mkdir(const char *path, mode_t mode) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int stat(const char *path, struct stat *st) {
 | 
					extern "C" int stat(const char *path, struct stat *st)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FilePath fp(path);
 | 
					    FilePath fp(path);
 | 
				
			||||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
					    FileSystemHandle *fs = fp.fileSystem();
 | 
				
			||||||
    if (fs == NULL) {
 | 
					    if (fs == NULL) {
 | 
				
			||||||
| 
						 | 
					@ -1066,7 +1147,8 @@ extern "C" int stat(const char *path, struct stat *st) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" int statvfs(const char *path, struct statvfs *buf) {
 | 
					extern "C" int statvfs(const char *path, struct statvfs *buf)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    FilePath fp(path);
 | 
					    FilePath fp(path);
 | 
				
			||||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
					    FileSystemHandle *fs = fp.fileSystem();
 | 
				
			||||||
    if (fs == NULL) {
 | 
					    if (fs == NULL) {
 | 
				
			||||||
| 
						 | 
					@ -1087,12 +1169,14 @@ extern "C" int statvfs(const char *path, struct statvfs *buf) {
 | 
				
			||||||
/* prevents the exception handling name demangling code getting pulled in */
 | 
					/* prevents the exception handling name demangling code getting pulled in */
 | 
				
			||||||
#include "mbed_error.h"
 | 
					#include "mbed_error.h"
 | 
				
			||||||
namespace __gnu_cxx {
 | 
					namespace __gnu_cxx {
 | 
				
			||||||
    void __verbose_terminate_handler() {
 | 
					void __verbose_terminate_handler()
 | 
				
			||||||
        MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_CLIB_EXCEPTION),"Exception", 0);
 | 
					{
 | 
				
			||||||
    }
 | 
					    MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_CLIB_EXCEPTION), "Exception", 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
extern "C" WEAK void __cxa_pure_virtual(void);
 | 
					extern "C" WEAK void __cxa_pure_virtual(void);
 | 
				
			||||||
extern "C" WEAK void __cxa_pure_virtual(void) {
 | 
					extern "C" WEAK void __cxa_pure_virtual(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    exit(1);
 | 
					    exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1120,31 +1204,33 @@ extern "C" int errno;
 | 
				
			||||||
// TARGET_NUMAKER_PFM_M453      targets/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/TOOLCHAIN_GCC_ARM/m451_retarget.c
 | 
					// TARGET_NUMAKER_PFM_M453      targets/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/TOOLCHAIN_GCC_ARM/m451_retarget.c
 | 
				
			||||||
// TARGET_STM32L4               targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L4/l4_retarget.c
 | 
					// TARGET_STM32L4               targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L4/l4_retarget.c
 | 
				
			||||||
extern "C" void *__wrap__sbrk(int incr);
 | 
					extern "C" void *__wrap__sbrk(int incr);
 | 
				
			||||||
extern "C" caddr_t _sbrk(int incr) {
 | 
					extern "C" caddr_t _sbrk(int incr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return (caddr_t) __wrap__sbrk(incr);
 | 
					    return (caddr_t) __wrap__sbrk(incr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
// Linker defined symbol used by _sbrk to indicate where heap should start.
 | 
					// Linker defined symbol used by _sbrk to indicate where heap should start.
 | 
				
			||||||
extern "C" uint32_t __end__;
 | 
					extern "C" uint32_t __end__;
 | 
				
			||||||
// Weak attribute allows user to override, e.g. to use external RAM for dynamic memory.
 | 
					// Weak attribute allows user to override, e.g. to use external RAM for dynamic memory.
 | 
				
			||||||
extern "C" WEAK caddr_t _sbrk(int incr) {
 | 
					extern "C" WEAK caddr_t _sbrk(int incr)
 | 
				
			||||||
    static unsigned char* heap = (unsigned char*)&__end__;
 | 
					{
 | 
				
			||||||
    unsigned char*        prev_heap = heap;
 | 
					    static unsigned char *heap = (unsigned char *)&__end__;
 | 
				
			||||||
    unsigned char*        new_heap = heap + incr;
 | 
					    unsigned char        *prev_heap = heap;
 | 
				
			||||||
 | 
					    unsigned char        *new_heap = heap + incr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TARGET_CORTEX_A)
 | 
					#if defined(TARGET_CORTEX_A)
 | 
				
			||||||
    if (new_heap >= (unsigned char*)&__HeapLimit) {     /* __HeapLimit is end of heap section */
 | 
					    if (new_heap >= (unsigned char *)&__HeapLimit) {    /* __HeapLimit is end of heap section */
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    if (new_heap >= (unsigned char*)__get_MSP()) {
 | 
					    if (new_heap >= (unsigned char *)__get_MSP()) {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
        errno = ENOMEM;
 | 
					        errno = ENOMEM;
 | 
				
			||||||
        return (caddr_t)-1;
 | 
					        return (caddr_t) -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Additional heap checking if set
 | 
					    // Additional heap checking if set
 | 
				
			||||||
    if (mbed_heap_size && (new_heap >= mbed_heap_start + mbed_heap_size)) {
 | 
					    if (mbed_heap_size && (new_heap >= mbed_heap_start + mbed_heap_size)) {
 | 
				
			||||||
        errno = ENOMEM;
 | 
					        errno = ENOMEM;
 | 
				
			||||||
        return (caddr_t)-1;
 | 
					        return (caddr_t) -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    heap = new_heap;
 | 
					    heap = new_heap;
 | 
				
			||||||
| 
						 | 
					@ -1154,10 +1240,12 @@ extern "C" WEAK caddr_t _sbrk(int incr) {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TOOLCHAIN_GCC_ARM) || defined(TOOLCHAIN_GCC_CR)
 | 
					#if defined(TOOLCHAIN_GCC_ARM) || defined(TOOLCHAIN_GCC_CR)
 | 
				
			||||||
extern "C" void _exit(int return_code) {
 | 
					extern "C" void _exit(int return_code)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
namespace std {
 | 
					namespace std {
 | 
				
			||||||
extern "C" void exit(int return_code) {
 | 
					extern "C" void exit(int return_code)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if DEVICE_STDIO_MESSAGES
 | 
					#if DEVICE_STDIO_MESSAGES
 | 
				
			||||||
| 
						 | 
					@ -1191,16 +1279,19 @@ extern "C" void exit(int return_code) {
 | 
				
			||||||
// More informations about this topic for ARMCC here:
 | 
					// More informations about this topic for ARMCC here:
 | 
				
			||||||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/6449.html
 | 
					// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/6449.html
 | 
				
			||||||
extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
int __aeabi_atexit(void *object, void (*dtor)(void* /*this*/), void *handle) {
 | 
					    int __aeabi_atexit(void *object, void (*dtor)(void * /*this*/), void *handle)
 | 
				
			||||||
    return 1;
 | 
					    {
 | 
				
			||||||
}
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int __cxa_atexit(void (*dtor)(void* /*this*/), void *object, void *handle) {
 | 
					    int __cxa_atexit(void (*dtor)(void * /*this*/), void *object, void *handle)
 | 
				
			||||||
    return 1;
 | 
					    {
 | 
				
			||||||
}
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void __cxa_finalize(void *handle) {
 | 
					    void __cxa_finalize(void *handle)
 | 
				
			||||||
}
 | 
					    {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // end of extern "C"
 | 
					} // end of extern "C"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1216,25 +1307,27 @@ void __cxa_finalize(void *handle) {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * To overcome this limitation, exit and atexit are overriden here.
 | 
					 * To overcome this limitation, exit and atexit are overriden here.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
extern "C"{
 | 
					extern "C" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					    /**
 | 
				
			||||||
 * @brief Retarget of exit for GCC.
 | 
					     * @brief Retarget of exit for GCC.
 | 
				
			||||||
 * @details Unlike the standard version, this function doesn't call any function
 | 
					     * @details Unlike the standard version, this function doesn't call any function
 | 
				
			||||||
 * registered with atexit before calling _exit.
 | 
					     * registered with atexit before calling _exit.
 | 
				
			||||||
 */
 | 
					     */
 | 
				
			||||||
void __wrap_exit(int return_code) {
 | 
					    void __wrap_exit(int return_code)
 | 
				
			||||||
    _exit(return_code);
 | 
					    {
 | 
				
			||||||
}
 | 
					        _exit(return_code);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					    /**
 | 
				
			||||||
 * @brief Retarget atexit from GCC.
 | 
					     * @brief Retarget atexit from GCC.
 | 
				
			||||||
 * @details This function will always fail and never register any handler to be
 | 
					     * @details This function will always fail and never register any handler to be
 | 
				
			||||||
 * called at exit.
 | 
					     * called at exit.
 | 
				
			||||||
 */
 | 
					     */
 | 
				
			||||||
int __wrap_atexit(void (*func)()) {
 | 
					    int __wrap_atexit(void (*func)())
 | 
				
			||||||
    return 1;
 | 
					    {
 | 
				
			||||||
}
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1244,20 +1337,22 @@ int __wrap_atexit(void (*func)()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace mbed {
 | 
					namespace mbed {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbed_set_unbuffered_stream(std::FILE *_file) {
 | 
					void mbed_set_unbuffered_stream(std::FILE *_file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if defined (__ICCARM__)
 | 
					#if defined (__ICCARM__)
 | 
				
			||||||
    char buf[2];
 | 
					    char buf[2];
 | 
				
			||||||
    std::setvbuf(_file,buf,_IONBF,NULL);
 | 
					    std::setvbuf(_file, buf, _IONBF, NULL);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    setbuf(_file, NULL);
 | 
					    setbuf(_file, NULL);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbed_getc(std::FILE *_file){
 | 
					int mbed_getc(std::FILE *_file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ < 8000000)
 | 
					#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ < 8000000)
 | 
				
			||||||
    /*This is only valid for unbuffered streams*/
 | 
					    /*This is only valid for unbuffered streams*/
 | 
				
			||||||
    int res = std::fgetc(_file);
 | 
					    int res = std::fgetc(_file);
 | 
				
			||||||
    if (res>=0){
 | 
					    if (res >= 0) {
 | 
				
			||||||
        _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
 | 
					        _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
 | 
				
			||||||
        _file->_Rend = _file->_Wend;
 | 
					        _file->_Rend = _file->_Wend;
 | 
				
			||||||
        _file->_Next = _file->_Wend;
 | 
					        _file->_Next = _file->_Wend;
 | 
				
			||||||
| 
						 | 
					@ -1268,18 +1363,19 @@ int mbed_getc(std::FILE *_file){
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char* mbed_gets(char*s, int size, std::FILE *_file){
 | 
					char *mbed_gets(char *s, int size, std::FILE *_file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ < 8000000)
 | 
					#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ < 8000000)
 | 
				
			||||||
    /*This is only valid for unbuffered streams*/
 | 
					    /*This is only valid for unbuffered streams*/
 | 
				
			||||||
    char *str = fgets(s,size,_file);
 | 
					    char *str = fgets(s, size, _file);
 | 
				
			||||||
    if (str!=NULL){
 | 
					    if (str != NULL) {
 | 
				
			||||||
        _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
 | 
					        _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
 | 
				
			||||||
        _file->_Rend = _file->_Wend;
 | 
					        _file->_Rend = _file->_Wend;
 | 
				
			||||||
        _file->_Next = _file->_Wend;
 | 
					        _file->_Next = _file->_Wend;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return str;
 | 
					    return str;
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    return std::fgets(s,size,_file);
 | 
					    return std::fgets(s, size, _file);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1297,9 +1393,10 @@ extern "C" WEAK void __iar_file_Mtxlock(__iar_Rmtx *mutex) {}
 | 
				
			||||||
extern "C" WEAK void __iar_file_Mtxunlock(__iar_Rmtx *mutex) {}
 | 
					extern "C" WEAK void __iar_file_Mtxunlock(__iar_Rmtx *mutex) {}
 | 
				
			||||||
#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ >= 8000000)
 | 
					#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ >= 8000000)
 | 
				
			||||||
#pragma section="__iar_tls$$DATA"
 | 
					#pragma section="__iar_tls$$DATA"
 | 
				
			||||||
extern "C" WEAK void *__aeabi_read_tp (void) {
 | 
					extern "C" WEAK void *__aeabi_read_tp(void)
 | 
				
			||||||
  // Thread Local storage is not supported, using main thread memory for errno
 | 
					{
 | 
				
			||||||
  return __section_begin("__iar_tls$$DATA");
 | 
					    // Thread Local storage is not supported, using main thread memory for errno
 | 
				
			||||||
 | 
					    return __section_begin("__iar_tls$$DATA");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#elif defined(__CC_ARM)
 | 
					#elif defined(__CC_ARM)
 | 
				
			||||||
| 
						 | 
					@ -1307,27 +1404,27 @@ extern "C" WEAK void *__aeabi_read_tp (void) {
 | 
				
			||||||
#elif defined (__GNUC__)
 | 
					#elif defined (__GNUC__)
 | 
				
			||||||
struct _reent;
 | 
					struct _reent;
 | 
				
			||||||
// Stub out locks when an rtos is not present
 | 
					// Stub out locks when an rtos is not present
 | 
				
			||||||
extern "C" WEAK void __rtos_malloc_lock( struct _reent *_r ) {}
 | 
					extern "C" WEAK void __rtos_malloc_lock(struct _reent *_r) {}
 | 
				
			||||||
extern "C" WEAK void __rtos_malloc_unlock( struct _reent *_r ) {}
 | 
					extern "C" WEAK void __rtos_malloc_unlock(struct _reent *_r) {}
 | 
				
			||||||
extern "C" WEAK void __rtos_env_lock( struct _reent *_r ) {}
 | 
					extern "C" WEAK void __rtos_env_lock(struct _reent *_r) {}
 | 
				
			||||||
extern "C" WEAK void __rtos_env_unlock( struct _reent *_r ) {}
 | 
					extern "C" WEAK void __rtos_env_unlock(struct _reent *_r) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void __malloc_lock( struct _reent *_r )
 | 
					extern "C" void __malloc_lock(struct _reent *_r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    __rtos_malloc_lock(_r);
 | 
					    __rtos_malloc_lock(_r);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void __malloc_unlock( struct _reent *_r )
 | 
					extern "C" void __malloc_unlock(struct _reent *_r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    __rtos_malloc_unlock(_r);
 | 
					    __rtos_malloc_unlock(_r);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void __env_lock( struct _reent *_r )
 | 
					extern "C" void __env_lock(struct _reent *_r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    __rtos_env_lock(_r);
 | 
					    __rtos_env_lock(_r);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void __env_unlock( struct _reent *_r )
 | 
					extern "C" void __env_unlock(struct _reent *_r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    __rtos_env_unlock(_r);
 | 
					    __rtos_env_unlock(_r);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1380,10 +1477,10 @@ extern "C" void __cxa_guard_abort(int *guard_object_p)
 | 
				
			||||||
// provide the implementation for these. Note: this needs to use the wrappers
 | 
					// provide the implementation for these. Note: this needs to use the wrappers
 | 
				
			||||||
// instead of malloc()/free() as the caller address would point to wrappers,
 | 
					// instead of malloc()/free() as the caller address would point to wrappers,
 | 
				
			||||||
// not the caller of "new" or "delete".
 | 
					// not the caller of "new" or "delete".
 | 
				
			||||||
extern "C" void* malloc_wrapper(size_t size, const void* caller);
 | 
					extern "C" void *malloc_wrapper(size_t size, const void *caller);
 | 
				
			||||||
extern "C" void free_wrapper(void *ptr, const void* caller);
 | 
					extern "C" void free_wrapper(void *ptr, const void *caller);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new(std::size_t count)
 | 
					void *operator new (std::size_t count)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    void *buffer = malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
					    void *buffer = malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
				
			||||||
    if (NULL == buffer) {
 | 
					    if (NULL == buffer) {
 | 
				
			||||||
| 
						 | 
					@ -1401,17 +1498,17 @@ void *operator new[](std::size_t count)
 | 
				
			||||||
    return buffer;
 | 
					    return buffer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new(std::size_t count, const std::nothrow_t& tag)
 | 
					void *operator new (std::size_t count, const std::nothrow_t &tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
					    return malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new[](std::size_t count, const std::nothrow_t& tag)
 | 
					void *operator new[](std::size_t count, const std::nothrow_t &tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
					    return malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void operator delete(void *ptr)
 | 
					void operator delete (void *ptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    free_wrapper(ptr, MBED_CALLER_ADDR());
 | 
					    free_wrapper(ptr, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1424,10 +1521,10 @@ void operator delete[](void *ptr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <reent.h>
 | 
					#include <reent.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void* malloc_wrapper(struct _reent * r, size_t size, void * caller);
 | 
					extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller);
 | 
				
			||||||
extern "C" void free_wrapper(struct _reent * r, void * ptr, void * caller);
 | 
					extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new(std::size_t count)
 | 
					void *operator new (std::size_t count)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    void *buffer = malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
 | 
					    void *buffer = malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
 | 
				
			||||||
    if (NULL == buffer) {
 | 
					    if (NULL == buffer) {
 | 
				
			||||||
| 
						 | 
					@ -1445,17 +1542,17 @@ void *operator new[](std::size_t count)
 | 
				
			||||||
    return buffer;
 | 
					    return buffer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new(std::size_t count, const std::nothrow_t& tag)
 | 
					void *operator new (std::size_t count, const std::nothrow_t &tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
 | 
					    return malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new[](std::size_t count, const std::nothrow_t& tag)
 | 
					void *operator new[](std::size_t count, const std::nothrow_t &tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
 | 
					    return malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void operator delete(void *ptr)
 | 
					void operator delete (void *ptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    free_wrapper(_REENT, ptr, MBED_CALLER_ADDR());
 | 
					    free_wrapper(_REENT, ptr, MBED_CALLER_ADDR());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1467,7 +1564,7 @@ void operator delete[](void *ptr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new(std::size_t count)
 | 
					void *operator new (std::size_t count)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    void *buffer = malloc(count);
 | 
					    void *buffer = malloc(count);
 | 
				
			||||||
    if (NULL == buffer) {
 | 
					    if (NULL == buffer) {
 | 
				
			||||||
| 
						 | 
					@ -1485,17 +1582,17 @@ void *operator new[](std::size_t count)
 | 
				
			||||||
    return buffer;
 | 
					    return buffer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new(std::size_t count, const std::nothrow_t& tag)
 | 
					void *operator new (std::size_t count, const std::nothrow_t &tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return malloc(count);
 | 
					    return malloc(count);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *operator new[](std::size_t count, const std::nothrow_t& tag)
 | 
					void *operator new[](std::size_t count, const std::nothrow_t &tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return malloc(count);
 | 
					    return malloc(count);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void operator delete(void *ptr)
 | 
					void operator delete (void *ptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    free(ptr);
 | 
					    free(ptr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1526,7 +1623,7 @@ extern "C" clock_t clock()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// temporary - Default to 1MHz at 32 bits if target does not have us_ticker_get_info
 | 
					// temporary - Default to 1MHz at 32 bits if target does not have us_ticker_get_info
 | 
				
			||||||
MBED_WEAK const ticker_info_t* us_ticker_get_info()
 | 
					MBED_WEAK const ticker_info_t *us_ticker_get_info()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static const ticker_info_t info = {
 | 
					    static const ticker_info_t info = {
 | 
				
			||||||
        1000000,
 | 
					        1000000,
 | 
				
			||||||
| 
						 | 
					@ -1536,7 +1633,7 @@ MBED_WEAK const ticker_info_t* us_ticker_get_info()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// temporary - Default to 1MHz at 32 bits if target does not have lp_ticker_get_info
 | 
					// temporary - Default to 1MHz at 32 bits if target does not have lp_ticker_get_info
 | 
				
			||||||
MBED_WEAK const ticker_info_t* lp_ticker_get_info()
 | 
					MBED_WEAK const ticker_info_t *lp_ticker_get_info()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static const ticker_info_t info = {
 | 
					    static const ticker_info_t info = {
 | 
				
			||||||
        1000000,
 | 
					        1000000,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,7 +108,7 @@ class DirHandle;
 | 
				
			||||||
 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
 | 
					 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
 | 
				
			||||||
 * @return  pointer to FileHandle to override normal stream otherwise NULL
 | 
					 * @return  pointer to FileHandle to override normal stream otherwise NULL
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
FileHandle* mbed_target_override_console(int fd);
 | 
					FileHandle *mbed_target_override_console(int fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Applications may implement this to change stdin, stdout, stderr.
 | 
					/** Applications may implement this to change stdin, stdout, stderr.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ FileHandle* mbed_target_override_console(int fd);
 | 
				
			||||||
 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
 | 
					 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
 | 
				
			||||||
 * @return  pointer to FileHandle to override normal stream otherwise NULL
 | 
					 * @return  pointer to FileHandle to override normal stream otherwise NULL
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
FileHandle* mbed_override_console(int fd);
 | 
					FileHandle *mbed_override_console(int fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -483,7 +483,7 @@ struct statvfs {
 | 
				
			||||||
 * consistency where structure may be different with different toolchains
 | 
					 * consistency where structure may be different with different toolchains
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct dirent {
 | 
					struct dirent {
 | 
				
			||||||
    char d_name[NAME_MAX+1]; ///< Name of file
 | 
					    char d_name[NAME_MAX + 1]; ///< Name of file
 | 
				
			||||||
    uint8_t d_type;          ///< Type of file
 | 
					    uint8_t d_type;          ///< Type of file
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -515,9 +515,9 @@ extern "C" {
 | 
				
			||||||
    int open(const char *path, int oflag, ...);
 | 
					    int open(const char *path, int oflag, ...);
 | 
				
			||||||
#ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
 | 
					#ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
 | 
				
			||||||
#if __cplusplus
 | 
					#if __cplusplus
 | 
				
			||||||
    std::FILE* fdopen(int fildes, const char *mode);
 | 
					    std::FILE *fdopen(int fildes, const char *mode);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    FILE* fdopen(int fildes, const char *mode);
 | 
					    FILE *fdopen(int fildes, const char *mode);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    ssize_t write(int fildes, const void *buf, size_t nbyte);
 | 
					    ssize_t write(int fildes, const void *buf, size_t nbyte);
 | 
				
			||||||
| 
						 | 
					@ -531,12 +531,12 @@ extern "C" {
 | 
				
			||||||
    int close(int fildes);
 | 
					    int close(int fildes);
 | 
				
			||||||
    int stat(const char *path, struct stat *st);
 | 
					    int stat(const char *path, struct stat *st);
 | 
				
			||||||
    int statvfs(const char *path, struct statvfs *buf);
 | 
					    int statvfs(const char *path, struct statvfs *buf);
 | 
				
			||||||
    DIR *opendir(const char*);
 | 
					    DIR *opendir(const char *);
 | 
				
			||||||
    struct dirent *readdir(DIR *);
 | 
					    struct dirent *readdir(DIR *);
 | 
				
			||||||
    int closedir(DIR*);
 | 
					    int closedir(DIR *);
 | 
				
			||||||
    void rewinddir(DIR*);
 | 
					    void rewinddir(DIR *);
 | 
				
			||||||
    long telldir(DIR*);
 | 
					    long telldir(DIR *);
 | 
				
			||||||
    void seekdir(DIR*, long);
 | 
					    void seekdir(DIR *, long);
 | 
				
			||||||
    int mkdir(const char *name, mode_t n);
 | 
					    int mkdir(const char *name, mode_t n);
 | 
				
			||||||
#if __cplusplus
 | 
					#if __cplusplus
 | 
				
			||||||
}; // extern "C"
 | 
					}; // extern "C"
 | 
				
			||||||
| 
						 | 
					@ -556,7 +556,7 @@ namespace mbed {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *  @returns        a pointer to FILE
 | 
					 *  @returns        a pointer to FILE
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
std::FILE* fdopen(mbed::FileHandle *fh, const char *mode);
 | 
					std::FILE *fdopen(mbed::FileHandle *fh, const char *mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Bind an mbed FileHandle to a POSIX file descriptor
 | 
					/** Bind an mbed FileHandle to a POSIX file descriptor
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,7 +88,7 @@ time_t time(time_t *timer)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    time_t t = (time_t)-1;
 | 
					    time_t t = (time_t) -1;
 | 
				
			||||||
    if (_rtc_read != NULL) {
 | 
					    if (_rtc_read != NULL) {
 | 
				
			||||||
        t = _rtc_read();
 | 
					        t = _rtc_read();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -100,7 +100,8 @@ time_t time(time_t *timer)
 | 
				
			||||||
    return t;
 | 
					    return t;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_time(time_t t) {
 | 
					void set_time(time_t t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex->lock();
 | 
					    _mutex->lock();
 | 
				
			||||||
    if (_rtc_init != NULL) {
 | 
					    if (_rtc_init != NULL) {
 | 
				
			||||||
        _rtc_init();
 | 
					        _rtc_init();
 | 
				
			||||||
| 
						 | 
					@ -111,7 +112,8 @@ void set_time(time_t t) {
 | 
				
			||||||
    _mutex->unlock();
 | 
					    _mutex->unlock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
 | 
					void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    _mutex->lock();
 | 
					    _mutex->lock();
 | 
				
			||||||
    _rtc_read = read_rtc;
 | 
					    _rtc_read = read_rtc;
 | 
				
			||||||
    _rtc_write = write_rtc;
 | 
					    _rtc_write = write_rtc;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,7 +56,7 @@ void mbed_copy_nvic(void)
 | 
				
			||||||
#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9)
 | 
					#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9)
 | 
				
			||||||
#ifdef NVIC_RAM_VECTOR_ADDRESS
 | 
					#ifdef NVIC_RAM_VECTOR_ADDRESS
 | 
				
			||||||
    uint32_t *old_vectors = (uint32_t *)SCB->VTOR;
 | 
					    uint32_t *old_vectors = (uint32_t *)SCB->VTOR;
 | 
				
			||||||
    uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
 | 
					    uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
 | 
				
			||||||
    for (int i = 0; i < NVIC_NUM_VECTORS; i++) {
 | 
					    for (int i = 0; i < NVIC_NUM_VECTORS; i++) {
 | 
				
			||||||
        vectors[i] = old_vectors[i];
 | 
					        vectors[i] = old_vectors[i];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -105,8 +105,8 @@ int __wrap_main(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int __low_level_init(void)
 | 
					int __low_level_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  mbed_copy_nvic();
 | 
					    mbed_copy_nvic();
 | 
				
			||||||
  return 1;
 | 
					    return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,8 @@
 | 
				
			||||||
#define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
 | 
					#define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if DEVICE_LOCALFILESYSTEM
 | 
					#if DEVICE_LOCALFILESYSTEM
 | 
				
			||||||
FILEHANDLE semihost_open(const char* name, int openmode) {
 | 
					FILEHANDLE semihost_open(const char *name, int openmode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[3];
 | 
					    uint32_t args[3];
 | 
				
			||||||
    args[0] = (uint32_t)name;
 | 
					    args[0] = (uint32_t)name;
 | 
				
			||||||
    args[1] = (uint32_t)openmode;
 | 
					    args[1] = (uint32_t)openmode;
 | 
				
			||||||
| 
						 | 
					@ -52,12 +53,16 @@ FILEHANDLE semihost_open(const char* name, int openmode) {
 | 
				
			||||||
    return __semihost(SYS_OPEN, args);
 | 
					    return __semihost(SYS_OPEN, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_close(FILEHANDLE fh) {
 | 
					int semihost_close(FILEHANDLE fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __semihost(SYS_CLOSE, &fh);
 | 
					    return __semihost(SYS_CLOSE, &fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) {
 | 
					int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode)
 | 
				
			||||||
    if (length == 0) return 0;
 | 
					{
 | 
				
			||||||
 | 
					    if (length == 0) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint32_t args[3];
 | 
					    uint32_t args[3];
 | 
				
			||||||
    args[0] = (uint32_t)fh;
 | 
					    args[0] = (uint32_t)fh;
 | 
				
			||||||
| 
						 | 
					@ -66,7 +71,8 @@ int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int leng
 | 
				
			||||||
    return __semihost(SYS_WRITE, args);
 | 
					    return __semihost(SYS_WRITE, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode) {
 | 
					int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[3];
 | 
					    uint32_t args[3];
 | 
				
			||||||
    args[0] = (uint32_t)fh;
 | 
					    args[0] = (uint32_t)fh;
 | 
				
			||||||
    args[1] = (uint32_t)buffer;
 | 
					    args[1] = (uint32_t)buffer;
 | 
				
			||||||
| 
						 | 
					@ -74,33 +80,39 @@ int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int
 | 
				
			||||||
    return __semihost(SYS_READ, args);
 | 
					    return __semihost(SYS_READ, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_istty(FILEHANDLE fh) {
 | 
					int semihost_istty(FILEHANDLE fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __semihost(SYS_ISTTY, &fh);
 | 
					    return __semihost(SYS_ISTTY, &fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_seek(FILEHANDLE fh, long position) {
 | 
					int semihost_seek(FILEHANDLE fh, long position)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[2];
 | 
					    uint32_t args[2];
 | 
				
			||||||
    args[0] = (uint32_t)fh;
 | 
					    args[0] = (uint32_t)fh;
 | 
				
			||||||
    args[1] = (uint32_t)position;
 | 
					    args[1] = (uint32_t)position;
 | 
				
			||||||
    return __semihost(SYS_SEEK, args);
 | 
					    return __semihost(SYS_SEEK, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_ensure(FILEHANDLE fh) {
 | 
					int semihost_ensure(FILEHANDLE fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __semihost(SYS_ENSURE, &fh);
 | 
					    return __semihost(SYS_ENSURE, &fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
long semihost_flen(FILEHANDLE fh) {
 | 
					long semihost_flen(FILEHANDLE fh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __semihost(SYS_FLEN, &fh);
 | 
					    return __semihost(SYS_FLEN, &fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_remove(const char *name) {
 | 
					int semihost_remove(const char *name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[2];
 | 
					    uint32_t args[2];
 | 
				
			||||||
    args[0] = (uint32_t)name;
 | 
					    args[0] = (uint32_t)name;
 | 
				
			||||||
    args[1] = (uint32_t)strlen(name);
 | 
					    args[1] = (uint32_t)strlen(name);
 | 
				
			||||||
    return __semihost(SYS_REMOVE, args);
 | 
					    return __semihost(SYS_REMOVE, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_rename(const char *old_name, const char *new_name) {
 | 
					int semihost_rename(const char *old_name, const char *new_name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[4];
 | 
					    uint32_t args[4];
 | 
				
			||||||
    args[0] = (uint32_t)old_name;
 | 
					    args[0] = (uint32_t)old_name;
 | 
				
			||||||
    args[1] = (uint32_t)strlen(old_name);
 | 
					    args[1] = (uint32_t)strlen(old_name);
 | 
				
			||||||
| 
						 | 
					@ -110,35 +122,41 @@ int semihost_rename(const char *old_name, const char *new_name) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_exit(void) {
 | 
					int semihost_exit(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[4];
 | 
					    uint32_t args[4];
 | 
				
			||||||
    return __semihost(SYS_EXIT, args);
 | 
					    return __semihost(SYS_EXIT, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_uid(char *uid) {
 | 
					int semihost_uid(char *uid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[2];
 | 
					    uint32_t args[2];
 | 
				
			||||||
    args[0] = (uint32_t)uid;
 | 
					    args[0] = (uint32_t)uid;
 | 
				
			||||||
    args[1] = DEVICE_ID_LENGTH + 1;
 | 
					    args[1] = DEVICE_ID_LENGTH + 1;
 | 
				
			||||||
    return __semihost(USR_UID, &args);
 | 
					    return __semihost(USR_UID, &args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_reset(void) {
 | 
					int semihost_reset(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // Does not normally return, however if used with older firmware versions
 | 
					    // Does not normally return, however if used with older firmware versions
 | 
				
			||||||
    // that do not support this call it will return -1.
 | 
					    // that do not support this call it will return -1.
 | 
				
			||||||
    return __semihost(USR_RESET, NULL);
 | 
					    return __semihost(USR_RESET, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_vbus(void) {
 | 
					int semihost_vbus(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __semihost(USR_VBUS, NULL);
 | 
					    return __semihost(USR_VBUS, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_powerdown(void) {
 | 
					int semihost_powerdown(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return __semihost(USR_POWERDOWN, NULL);
 | 
					    return __semihost(USR_POWERDOWN, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if DEVICE_DEBUG_AWARENESS
 | 
					#if DEVICE_DEBUG_AWARENESS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_connected(void) {
 | 
					int semihost_connected(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0;
 | 
					    return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,12 +164,14 @@ int semihost_connected(void) {
 | 
				
			||||||
// These processors cannot know if the interface is connect, assume so:
 | 
					// These processors cannot know if the interface is connect, assume so:
 | 
				
			||||||
static int is_debugger_attached = 1;
 | 
					static int is_debugger_attached = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_connected(void) {
 | 
					int semihost_connected(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return is_debugger_attached;
 | 
					    return is_debugger_attached;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_disabledebug(void) {
 | 
					int semihost_disabledebug(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    uint32_t args[1];
 | 
					    uint32_t args[1];
 | 
				
			||||||
#if !(DEVICE_DEBUG_AWARENESS)
 | 
					#if !(DEVICE_DEBUG_AWARENESS)
 | 
				
			||||||
    is_debugger_attached = 0;
 | 
					    is_debugger_attached = 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,8 +29,9 @@ extern "C" {
 | 
				
			||||||
#if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
 | 
					#if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__ICCARM__)
 | 
					#if defined(__ICCARM__)
 | 
				
			||||||
static inline int __semihost(int reason, const void *arg) {
 | 
					static inline int __semihost(int reason, const void *arg)
 | 
				
			||||||
    return __semihosting(reason, (void*)arg);
 | 
					{
 | 
				
			||||||
 | 
					    return __semihosting(reason, (void *)arg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,17 +45,18 @@ static inline int __semihost(int reason, const void *arg) {
 | 
				
			||||||
#   define AngelSWIAsm          swi
 | 
					#   define AngelSWIAsm          swi
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline int __semihost(int reason, const void *arg) {
 | 
					static inline int __semihost(int reason, const void *arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    int value;
 | 
					    int value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    asm volatile (
 | 
					    asm volatile(
 | 
				
			||||||
       "mov r0, %1"          "\n\t"
 | 
					        "mov r0, %1"          "\n\t"
 | 
				
			||||||
       "mov r1, %2"          "\n\t"
 | 
					        "mov r1, %2"          "\n\t"
 | 
				
			||||||
       AngelSWIInsn " %a3"   "\n\t"
 | 
					        AngelSWIInsn " %a3"   "\n\t"
 | 
				
			||||||
       "mov %0, r0"
 | 
					        "mov %0, r0"
 | 
				
			||||||
       : "=r" (value)                                         /* output operands             */
 | 
					        : "=r"(value)                                          /* output operands             */
 | 
				
			||||||
       : "r" (reason), "r" (arg), "i" (AngelSWI)              /* input operands              */
 | 
					        : "r"(reason), "r"(arg), "i"(AngelSWI)                 /* input operands              */
 | 
				
			||||||
       : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"   /* list of clobbered registers */
 | 
					        : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"   /* list of clobbered registers */
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return value;
 | 
					    return value;
 | 
				
			||||||
| 
						 | 
					@ -63,14 +65,14 @@ static inline int __semihost(int reason, const void *arg) {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if DEVICE_LOCALFILESYSTEM
 | 
					#if DEVICE_LOCALFILESYSTEM
 | 
				
			||||||
FILEHANDLE semihost_open(const char* name, int openmode);
 | 
					FILEHANDLE semihost_open(const char *name, int openmode);
 | 
				
			||||||
int semihost_close (FILEHANDLE fh);
 | 
					int semihost_close(FILEHANDLE fh);
 | 
				
			||||||
int semihost_read  (FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode);
 | 
					int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode);
 | 
				
			||||||
int semihost_write (FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode);
 | 
					int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode);
 | 
				
			||||||
int semihost_ensure(FILEHANDLE fh);
 | 
					int semihost_ensure(FILEHANDLE fh);
 | 
				
			||||||
long semihost_flen (FILEHANDLE fh);
 | 
					long semihost_flen(FILEHANDLE fh);
 | 
				
			||||||
int semihost_seek  (FILEHANDLE fh, long position);
 | 
					int semihost_seek(FILEHANDLE fh, long position);
 | 
				
			||||||
int semihost_istty (FILEHANDLE fh);
 | 
					int semihost_istty(FILEHANDLE fh);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int semihost_remove(const char *name);
 | 
					int semihost_remove(const char *name);
 | 
				
			||||||
int semihost_rename(const char *old_name, const char *new_name);
 | 
					int semihost_rename(const char *old_name, const char *new_name);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -396,7 +396,7 @@
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef FILEHANDLE
 | 
					#ifndef FILEHANDLE
 | 
				
			||||||
    typedef int FILEHANDLE;
 | 
					typedef int FILEHANDLE;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Backwards compatibility
 | 
					// Backwards compatibility
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,15 +21,18 @@
 | 
				
			||||||
#include "platform/mbed_wait_api.h"
 | 
					#include "platform/mbed_wait_api.h"
 | 
				
			||||||
#include "hal/us_ticker_api.h"
 | 
					#include "hal/us_ticker_api.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wait(float s) {
 | 
					void wait(float s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    wait_us(s * 1000000.0f);
 | 
					    wait_us(s * 1000000.0f);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wait_ms(int ms) {
 | 
					void wait_ms(int ms)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    wait_us(ms * 1000);
 | 
					    wait_us(ms * 1000);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wait_us(int us) {
 | 
					void wait_us(int us)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    const ticker_data_t *const ticker = get_us_ticker_data();
 | 
					    const ticker_data_t *const ticker = get_us_ticker_data();
 | 
				
			||||||
    uint32_t start = ticker_read(ticker);
 | 
					    uint32_t start = ticker_read(ticker);
 | 
				
			||||||
    while ((ticker_read(ticker) - start) < (uint32_t)us);
 | 
					    while ((ticker_read(ticker) - start) < (uint32_t)us);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,15 +24,18 @@
 | 
				
			||||||
#include "platform/mbed_critical.h"
 | 
					#include "platform/mbed_critical.h"
 | 
				
			||||||
#include "platform/mbed_power_mgmt.h"
 | 
					#include "platform/mbed_power_mgmt.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wait(float s) {
 | 
					void wait(float s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    wait_us(s * 1000000.0f);
 | 
					    wait_us(s * 1000000.0f);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wait_ms(int ms) {
 | 
					void wait_ms(int ms)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    wait_us(ms * 1000);
 | 
					    wait_us(ms * 1000);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wait_us(int us) {
 | 
					void wait_us(int us)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    const ticker_data_t *const ticker = get_us_ticker_data();
 | 
					    const ticker_data_t *const ticker = get_us_ticker_data();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint32_t start = ticker_read(ticker);
 | 
					    uint32_t start = ticker_read(ticker);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue