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 i = 0;
 | 
			
		||||
    for ( ; i < size; i++) {
 | 
			
		||||
    for (; i < size; i++) {
 | 
			
		||||
        if (putc(data[i]) < 0) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +90,7 @@ int ATCmdParser::write(const char *data, int size)
 | 
			
		|||
int ATCmdParser::read(char *data, int size)
 | 
			
		||||
{
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    for ( ; i < size; i++) {
 | 
			
		||||
    for (; i < size; i++) {
 | 
			
		||||
        int c = getc();
 | 
			
		||||
        if (c < 0) {
 | 
			
		||||
            return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +110,7 @@ int ATCmdParser::vprintf(const char *format, va_list args)
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    for ( ; _buffer[i]; i++) {
 | 
			
		||||
    for (; _buffer[i]; i++) {
 | 
			
		||||
        if (putc(_buffer[i]) < 0) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -128,7 +128,7 @@ int ATCmdParser::vscanf(const char *format, va_list args)
 | 
			
		|||
    int offset = 0;
 | 
			
		||||
 | 
			
		||||
    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++] = '*';
 | 
			
		||||
            i++;
 | 
			
		||||
| 
						 | 
				
			
			@ -155,7 +155,7 @@ int ATCmdParser::vscanf(const char *format, va_list args)
 | 
			
		|||
 | 
			
		||||
    while (true) {
 | 
			
		||||
        // Ran out of space
 | 
			
		||||
        if (j+1 >= _buffer_size - offset) {
 | 
			
		||||
        if (j + 1 >= _buffer_size - offset) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        // Receive next character
 | 
			
		||||
| 
						 | 
				
			
			@ -168,12 +168,12 @@ int ATCmdParser::vscanf(const char *format, va_list args)
 | 
			
		|||
 | 
			
		||||
        // Check for match
 | 
			
		||||
        int count = -1;
 | 
			
		||||
        sscanf(_buffer+offset, _buffer, &count);
 | 
			
		||||
        sscanf(_buffer + offset, _buffer, &count);
 | 
			
		||||
 | 
			
		||||
        // We only succeed if all characters in the response are matched
 | 
			
		||||
        if (count == j) {
 | 
			
		||||
            // Store the found results
 | 
			
		||||
            vsscanf(_buffer+offset, format, args);
 | 
			
		||||
            vsscanf(_buffer + offset, format, args);
 | 
			
		||||
            return j;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -220,14 +220,14 @@ restart:
 | 
			
		|||
        bool whole_line_wanted = false;
 | 
			
		||||
 | 
			
		||||
        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++] = '*';
 | 
			
		||||
                i++;
 | 
			
		||||
            } else {
 | 
			
		||||
                _buffer[offset++] = response[i++];
 | 
			
		||||
                // 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;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -260,7 +260,7 @@ restart:
 | 
			
		|||
            }
 | 
			
		||||
            // Simplify newlines (borrowed from retarget.cpp)
 | 
			
		||||
            if ((c == CR && _in_prev != LF) ||
 | 
			
		||||
                (c == LF && _in_prev != CR)) {
 | 
			
		||||
                    (c == LF && _in_prev != CR)) {
 | 
			
		||||
                _in_prev = c;
 | 
			
		||||
                c = '\n';
 | 
			
		||||
            } else if ((c == CR && _in_prev == LF) ||
 | 
			
		||||
| 
						 | 
				
			
			@ -277,7 +277,7 @@ restart:
 | 
			
		|||
            // Check for oob data
 | 
			
		||||
            for (struct oob *oob = _oobs; oob; oob = oob->next) {
 | 
			
		||||
                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);
 | 
			
		||||
                    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
 | 
			
		||||
                // (scanf does not itself match whitespace in its format string, so \n is not significant to it)
 | 
			
		||||
            } else {
 | 
			
		||||
                sscanf(_buffer+offset, _buffer, &count);
 | 
			
		||||
                sscanf(_buffer + offset, _buffer, &count);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // We only succeed if all characters in the response are matched
 | 
			
		||||
            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
 | 
			
		||||
                memcpy(_buffer, response, i);
 | 
			
		||||
                _buffer[i] = 0;
 | 
			
		||||
 | 
			
		||||
                // Store the found results
 | 
			
		||||
                vsscanf(_buffer+offset, _buffer, args);
 | 
			
		||||
                vsscanf(_buffer + offset, _buffer, args);
 | 
			
		||||
 | 
			
		||||
                // Jump to next line and continue parsing
 | 
			
		||||
                response += i;
 | 
			
		||||
| 
						 | 
				
			
			@ -318,8 +318,8 @@ restart:
 | 
			
		|||
 | 
			
		||||
            // Clear the buffer when we hit a newline or ran out of space
 | 
			
		||||
            // running out of space usually means we ran into binary data
 | 
			
		||||
            if (c == '\n' || j+1 >= _buffer_size - offset) {
 | 
			
		||||
                debug_if(_dbg_on, "AT< %s", _buffer+offset);
 | 
			
		||||
            if (c == '\n' || j + 1 >= _buffer_size - offset) {
 | 
			
		||||
                debug_if(_dbg_on, "AT< %s", _buffer + offset);
 | 
			
		||||
                j = 0;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -396,7 +396,7 @@ bool ATCmdParser::process_oob()
 | 
			
		|||
        }
 | 
			
		||||
        // Simplify newlines (borrowed from retarget.cpp)
 | 
			
		||||
        if ((c == CR && _in_prev != LF) ||
 | 
			
		||||
            (c == LF && _in_prev != CR)) {
 | 
			
		||||
                (c == LF && _in_prev != CR)) {
 | 
			
		||||
            _in_prev = c;
 | 
			
		||||
            c = '\n';
 | 
			
		||||
        } else if ((c == CR && _in_prev == LF) ||
 | 
			
		||||
| 
						 | 
				
			
			@ -414,17 +414,17 @@ bool ATCmdParser::process_oob()
 | 
			
		|||
        struct oob *oob = _oobs;
 | 
			
		||||
        while (oob) {
 | 
			
		||||
            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);
 | 
			
		||||
                oob->cb();
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            oob = oob->next;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        // Clear the buffer when we hit a newline or ran out of space
 | 
			
		||||
        // 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);
 | 
			
		||||
            i = 0;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,8 +52,7 @@ namespace mbed {
 | 
			
		|||
 * @endcode
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class ATCmdParser : private NonCopyable<ATCmdParser>
 | 
			
		||||
{
 | 
			
		||||
class ATCmdParser : private NonCopyable<ATCmdParser> {
 | 
			
		||||
private:
 | 
			
		||||
    // File handle
 | 
			
		||||
    // Not owned by ATCmdParser
 | 
			
		||||
| 
						 | 
				
			
			@ -90,8 +89,8 @@ public:
 | 
			
		|||
     * @param debug turns on/off debug output for AT commands
 | 
			
		||||
     */
 | 
			
		||||
    ATCmdParser(FileHandle *fh, const char *output_delimiter = "\r",
 | 
			
		||||
             int buffer_size = 256, int timeout = 8000, bool debug = false)
 | 
			
		||||
            : _fh(fh), _buffer_size(buffer_size), _in_prev(0), _oobs(NULL)
 | 
			
		||||
                int buffer_size = 256, int timeout = 8000, bool debug = false)
 | 
			
		||||
        : _fh(fh), _buffer_size(buffer_size), _in_prev(0), _oobs(NULL)
 | 
			
		||||
    {
 | 
			
		||||
        _buffer = new char[buffer_size];
 | 
			
		||||
        set_timeout(timeout);
 | 
			
		||||
| 
						 | 
				
			
			@ -198,7 +197,7 @@ public:
 | 
			
		|||
     * @param ... all printf-like arguments to insert into command
 | 
			
		||||
     * @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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -216,7 +215,7 @@ public:
 | 
			
		|||
     * @param ... all scanf-like arguments to extract from response
 | 
			
		||||
     * @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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -261,7 +260,7 @@ public:
 | 
			
		|||
     * @param ... arguments to printf
 | 
			
		||||
     * @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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -273,7 +272,7 @@ public:
 | 
			
		|||
     * @param ... arguments to scanf
 | 
			
		||||
     * @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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -298,7 +297,7 @@ public:
 | 
			
		|||
     * recv operation.
 | 
			
		||||
     */
 | 
			
		||||
    void abort();
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Process out-of-band data
 | 
			
		||||
    *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,165 +84,163 @@ typedef void (*CThunkEntry)(void);
 | 
			
		|||
 * @note Synchronization level: Not protected
 | 
			
		||||
 */
 | 
			
		||||
template<class T>
 | 
			
		||||
class CThunk
 | 
			
		||||
{
 | 
			
		||||
    public:
 | 
			
		||||
        typedef void (T::*CCallbackSimple)(void);
 | 
			
		||||
        typedef void (T::*CCallback)(void* context);
 | 
			
		||||
class CThunk {
 | 
			
		||||
public:
 | 
			
		||||
    typedef void (T::*CCallbackSimple)(void);
 | 
			
		||||
    typedef void (T::*CCallback)(void *context);
 | 
			
		||||
 | 
			
		||||
        inline CThunk(T *instance)
 | 
			
		||||
        {
 | 
			
		||||
            init(instance, NULL, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    inline CThunk(T *instance)
 | 
			
		||||
    {
 | 
			
		||||
        init(instance, NULL, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline CThunk(T *instance, CCallback callback)
 | 
			
		||||
        {
 | 
			
		||||
            init(instance, callback, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    inline CThunk(T *instance, CCallback callback)
 | 
			
		||||
    {
 | 
			
		||||
        init(instance, callback, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        ~CThunk() {
 | 
			
		||||
    ~CThunk()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline CThunk(T *instance, CCallbackSimple callback)
 | 
			
		||||
        {
 | 
			
		||||
            init(instance, (CCallback)callback, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    inline CThunk(T *instance, CCallbackSimple callback)
 | 
			
		||||
    {
 | 
			
		||||
        init(instance, (CCallback)callback, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline CThunk(T &instance, CCallback callback)
 | 
			
		||||
        {
 | 
			
		||||
            init(instance, callback, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    inline CThunk(T &instance, CCallback callback)
 | 
			
		||||
    {
 | 
			
		||||
        init(instance, callback, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline CThunk(T &instance, CCallbackSimple callback)
 | 
			
		||||
        {
 | 
			
		||||
            init(instance, (CCallback)callback, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    inline CThunk(T &instance, CCallbackSimple callback)
 | 
			
		||||
    {
 | 
			
		||||
        init(instance, (CCallback)callback, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline CThunk(T &instance, CCallback callback, void* context)
 | 
			
		||||
        {
 | 
			
		||||
            init(instance, callback, context);
 | 
			
		||||
        }
 | 
			
		||||
    inline CThunk(T &instance, CCallback callback, void *context)
 | 
			
		||||
    {
 | 
			
		||||
        init(instance, callback, context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline void callback(CCallback callback)
 | 
			
		||||
        {
 | 
			
		||||
            m_callback = callback;
 | 
			
		||||
        }
 | 
			
		||||
    inline void callback(CCallback callback)
 | 
			
		||||
    {
 | 
			
		||||
        m_callback = callback;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline void callback(CCallbackSimple callback)
 | 
			
		||||
        {
 | 
			
		||||
            m_callback = (CCallback)callback;
 | 
			
		||||
        }
 | 
			
		||||
    inline void callback(CCallbackSimple callback)
 | 
			
		||||
    {
 | 
			
		||||
        m_callback = (CCallback)callback;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline void context(void* context)
 | 
			
		||||
        {
 | 
			
		||||
            m_thunk.context = (uint32_t)context;
 | 
			
		||||
        }
 | 
			
		||||
    inline void context(void *context)
 | 
			
		||||
    {
 | 
			
		||||
        m_thunk.context = (uint32_t)context;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        inline void context(uint32_t context)
 | 
			
		||||
        {
 | 
			
		||||
            m_thunk.context = context;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        inline uint32_t entry(void)
 | 
			
		||||
        {
 | 
			
		||||
            return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
 | 
			
		||||
        }
 | 
			
		||||
    inline void context(uint32_t context)
 | 
			
		||||
    {
 | 
			
		||||
        m_thunk.context = context;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
			
		||||
        inline operator CThunkEntry(void)
 | 
			
		||||
        {
 | 
			
		||||
            return (CThunkEntry)entry();
 | 
			
		||||
        }
 | 
			
		||||
    inline uint32_t entry(void)
 | 
			
		||||
    {
 | 
			
		||||
        return (((uint32_t)&m_thunk) | CTHUNK_ADDRESS);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
			
		||||
        inline operator uint32_t(void)
 | 
			
		||||
        {
 | 
			
		||||
            return entry();
 | 
			
		||||
        }
 | 
			
		||||
    /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
			
		||||
    inline operator CThunkEntry(void)
 | 
			
		||||
    {
 | 
			
		||||
        return (CThunkEntry)entry();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        /* simple test function */
 | 
			
		||||
        inline void call(void)
 | 
			
		||||
        {
 | 
			
		||||
            (((CThunkEntry)(entry()))());
 | 
			
		||||
        }
 | 
			
		||||
    /* get thunk entry point for connecting rhunk to an IRQ table */
 | 
			
		||||
    inline operator uint32_t(void)
 | 
			
		||||
    {
 | 
			
		||||
        return entry();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        T* m_instance;
 | 
			
		||||
        volatile CCallback m_callback;
 | 
			
		||||
    /* simple test function */
 | 
			
		||||
    inline void call(void)
 | 
			
		||||
    {
 | 
			
		||||
        (((CThunkEntry)(entry()))());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    T *m_instance;
 | 
			
		||||
    volatile CCallback m_callback;
 | 
			
		||||
 | 
			
		||||
// TODO: this needs proper fix, to refactor toolchain header file and all its use
 | 
			
		||||
// PACKED there is not defined properly for IAR
 | 
			
		||||
#if defined (__ICCARM__)
 | 
			
		||||
        typedef __packed struct
 | 
			
		||||
        {
 | 
			
		||||
            CTHUNK_VARIABLES;
 | 
			
		||||
            volatile uint32_t instance;
 | 
			
		||||
            volatile uint32_t context;
 | 
			
		||||
            volatile uint32_t callback;
 | 
			
		||||
            volatile uint32_t trampoline;
 | 
			
		||||
        }  CThunkTrampoline;
 | 
			
		||||
    typedef __packed struct {
 | 
			
		||||
        CTHUNK_VARIABLES;
 | 
			
		||||
        volatile uint32_t instance;
 | 
			
		||||
        volatile uint32_t context;
 | 
			
		||||
        volatile uint32_t callback;
 | 
			
		||||
        volatile uint32_t trampoline;
 | 
			
		||||
    }  CThunkTrampoline;
 | 
			
		||||
#else
 | 
			
		||||
        typedef struct
 | 
			
		||||
        {
 | 
			
		||||
            CTHUNK_VARIABLES;
 | 
			
		||||
            volatile uint32_t instance;
 | 
			
		||||
            volatile uint32_t context;
 | 
			
		||||
            volatile uint32_t callback;
 | 
			
		||||
            volatile uint32_t trampoline;
 | 
			
		||||
        } __attribute__((__packed__)) CThunkTrampoline;
 | 
			
		||||
    typedef struct {
 | 
			
		||||
        CTHUNK_VARIABLES;
 | 
			
		||||
        volatile uint32_t instance;
 | 
			
		||||
        volatile uint32_t context;
 | 
			
		||||
        volatile uint32_t callback;
 | 
			
		||||
        volatile uint32_t trampoline;
 | 
			
		||||
    } __attribute__((__packed__)) CThunkTrampoline;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        static void trampoline(T* instance, void* context, CCallback* callback)
 | 
			
		||||
        {
 | 
			
		||||
            if(instance && *callback) {
 | 
			
		||||
                (static_cast<T*>(instance)->**callback)(context);
 | 
			
		||||
            }
 | 
			
		||||
    static void trampoline(T *instance, void *context, CCallback *callback)
 | 
			
		||||
    {
 | 
			
		||||
        if (instance && *callback) {
 | 
			
		||||
            (static_cast<T *>(instance)->**callback)(context);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        volatile CThunkTrampoline m_thunk;
 | 
			
		||||
    volatile CThunkTrampoline m_thunk;
 | 
			
		||||
 | 
			
		||||
        inline void init(T *instance, CCallback callback, void* context)
 | 
			
		||||
        {
 | 
			
		||||
            /* remember callback - need to add this level of redirection
 | 
			
		||||
               as pointer size for member functions differs between platforms */
 | 
			
		||||
            m_callback = callback;
 | 
			
		||||
    inline void init(T *instance, CCallback callback, void *context)
 | 
			
		||||
    {
 | 
			
		||||
        /* remember callback - need to add this level of redirection
 | 
			
		||||
           as pointer size for member functions differs between platforms */
 | 
			
		||||
        m_callback = callback;
 | 
			
		||||
 | 
			
		||||
            /* populate thunking trampoline */
 | 
			
		||||
            CTHUNK_ASSIGMENT;
 | 
			
		||||
            m_thunk.context = (uint32_t)context;
 | 
			
		||||
            m_thunk.instance = (uint32_t)instance;
 | 
			
		||||
            m_thunk.callback = (uint32_t)&m_callback;
 | 
			
		||||
            m_thunk.trampoline = (uint32_t)&trampoline;
 | 
			
		||||
        /* populate thunking trampoline */
 | 
			
		||||
        CTHUNK_ASSIGMENT;
 | 
			
		||||
        m_thunk.context = (uint32_t)context;
 | 
			
		||||
        m_thunk.instance = (uint32_t)instance;
 | 
			
		||||
        m_thunk.callback = (uint32_t)&m_callback;
 | 
			
		||||
        m_thunk.trampoline = (uint32_t)&trampoline;
 | 
			
		||||
 | 
			
		||||
#if defined(__CORTEX_A9)
 | 
			
		||||
            /* Data cache clean */
 | 
			
		||||
            /* Cache control */
 | 
			
		||||
            {
 | 
			
		||||
                uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
 | 
			
		||||
                uint32_t end_addr   = (uint32_t)&m_thunk + sizeof(m_thunk);
 | 
			
		||||
                uint32_t addr;
 | 
			
		||||
        /* Data cache clean */
 | 
			
		||||
        /* Cache control */
 | 
			
		||||
        {
 | 
			
		||||
            uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
 | 
			
		||||
            uint32_t end_addr   = (uint32_t)&m_thunk + sizeof(m_thunk);
 | 
			
		||||
            uint32_t addr;
 | 
			
		||||
 | 
			
		||||
                /* Data cache clean and invalid */
 | 
			
		||||
                for (addr = start_addr; addr < end_addr; addr += 0x20) {
 | 
			
		||||
                    L1C_CleanInvalidateDCacheMVA((void *)addr);
 | 
			
		||||
                }
 | 
			
		||||
                /* Instruction cache invalid */
 | 
			
		||||
                L1C_InvalidateICacheAll();
 | 
			
		||||
                MMU_InvalidateTLB();
 | 
			
		||||
                L1C_InvalidateBTAC();
 | 
			
		||||
            /* Data cache clean and invalid */
 | 
			
		||||
            for (addr = start_addr; addr < end_addr; addr += 0x20) {
 | 
			
		||||
                L1C_CleanInvalidateDCacheMVA((void *)addr);
 | 
			
		||||
            }
 | 
			
		||||
            /* Instruction cache invalid */
 | 
			
		||||
            L1C_InvalidateICacheAll();
 | 
			
		||||
            MMU_InvalidateTLB();
 | 
			
		||||
            L1C_InvalidateBTAC();
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
#if defined(__CORTEX_M7)
 | 
			
		||||
            /* Data cache clean and invalid */
 | 
			
		||||
            SCB_CleanInvalidateDCache();
 | 
			
		||||
        /* Data cache clean and invalid */
 | 
			
		||||
        SCB_CleanInvalidateDCache();
 | 
			
		||||
 | 
			
		||||
            /* Instruction cache invalid */
 | 
			
		||||
            SCB_InvalidateICache();
 | 
			
		||||
        /* Instruction cache invalid */
 | 
			
		||||
        SCB_InvalidateICache();
 | 
			
		||||
#endif
 | 
			
		||||
            __ISB();
 | 
			
		||||
            __DSB();
 | 
			
		||||
        }
 | 
			
		||||
        __ISB();
 | 
			
		||||
        __DSB();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**@}*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,26 +13,31 @@ namespace mbed {
 | 
			
		|||
 | 
			
		||||
class CallChainLink {
 | 
			
		||||
public:
 | 
			
		||||
    CallChainLink(): cb(), next(NULL) {
 | 
			
		||||
    CallChainLink(): cb(), next(NULL)
 | 
			
		||||
    {
 | 
			
		||||
        // No work to do
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) {
 | 
			
		||||
    CallChainLink(Callback<void()> &callback): cb(callback), next(NULL)
 | 
			
		||||
    {
 | 
			
		||||
        // No work to do
 | 
			
		||||
    }
 | 
			
		||||
    Callback<void()> cb;
 | 
			
		||||
    CallChainLink * next;
 | 
			
		||||
    CallChainLink *next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
CallChain::CallChain(int size) : _chain(NULL) {
 | 
			
		||||
CallChain::CallChain(int size) : _chain(NULL)
 | 
			
		||||
{
 | 
			
		||||
    // No work to do
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CallChain::~CallChain() {
 | 
			
		||||
CallChain::~CallChain()
 | 
			
		||||
{
 | 
			
		||||
    clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pFunctionPointer_t CallChain::add(Callback<void()> func) {
 | 
			
		||||
pFunctionPointer_t CallChain::add(Callback<void()> func)
 | 
			
		||||
{
 | 
			
		||||
    CallChainLink *new_link = new CallChainLink(func);
 | 
			
		||||
    if (NULL == _chain) {
 | 
			
		||||
        _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);
 | 
			
		||||
    link->next = _chain;
 | 
			
		||||
    _chain = link;
 | 
			
		||||
    return &link->cb;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CallChain::size() const {
 | 
			
		||||
int CallChain::size() const
 | 
			
		||||
{
 | 
			
		||||
    CallChainLink *link = _chain;
 | 
			
		||||
    int elements = 0;
 | 
			
		||||
    while (link != NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +73,8 @@ int CallChain::size() const {
 | 
			
		|||
    return elements;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pFunctionPointer_t CallChain::get(int idx) const {
 | 
			
		||||
pFunctionPointer_t CallChain::get(int idx) const
 | 
			
		||||
{
 | 
			
		||||
    CallChainLink *link = _chain;
 | 
			
		||||
    for (int i = 0; i < idx; i++) {
 | 
			
		||||
        if (NULL == link) {
 | 
			
		||||
| 
						 | 
				
			
			@ -77,7 +85,8 @@ pFunctionPointer_t CallChain::get(int idx) const {
 | 
			
		|||
    return &link->cb;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CallChain::find(pFunctionPointer_t f) const {
 | 
			
		||||
int CallChain::find(pFunctionPointer_t f) const
 | 
			
		||||
{
 | 
			
		||||
    CallChainLink *link = _chain;
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    while (link != NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +99,8 @@ int CallChain::find(pFunctionPointer_t f) const {
 | 
			
		|||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CallChain::clear() {
 | 
			
		||||
void CallChain::clear()
 | 
			
		||||
{
 | 
			
		||||
    CallChainLink *link = _chain;
 | 
			
		||||
    _chain = 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;
 | 
			
		||||
    while (link != NULL) {
 | 
			
		||||
        if (f == &link->cb) {
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +123,8 @@ bool CallChain::remove(pFunctionPointer_t f) {
 | 
			
		|||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CallChain::call() {
 | 
			
		||||
void CallChain::call()
 | 
			
		||||
{
 | 
			
		||||
    CallChainLink *link = _chain;
 | 
			
		||||
    while (link != NULL) {
 | 
			
		||||
        link->cb.call();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,26 +75,26 @@ class CallChainLink;
 | 
			
		|||
class CallChain : private NonCopyable<CallChain> {
 | 
			
		||||
public:
 | 
			
		||||
    /** Create an empty chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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.
 | 
			
		||||
     *
 | 
			
		||||
     *  @param size (optional) Initial size of the chain
 | 
			
		||||
     */
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
    /** Create an empty chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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 "
 | 
			
		||||
        "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();
 | 
			
		||||
 | 
			
		||||
    /** Add a function at the end of the chain
 | 
			
		||||
     *
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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.
 | 
			
		||||
     *
 | 
			
		||||
     *  @param func A pointer to a void function
 | 
			
		||||
| 
						 | 
				
			
			@ -103,7 +103,7 @@ public:
 | 
			
		|||
     *  The function object created for 'func'
 | 
			
		||||
     */
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
    /** Add a function at the end of the chain
 | 
			
		||||
| 
						 | 
				
			
			@ -120,14 +120,15 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    template<typename T, typename M>
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
			
		||||
        "The add function does not support cv-qualifiers. Replaced by "
 | 
			
		||||
        "add(callback(obj, method)).")
 | 
			
		||||
    pFunctionPointer_t add(T *obj, M method) {
 | 
			
		||||
                          "The add function does not support cv-qualifiers. Replaced by "
 | 
			
		||||
                          "add(callback(obj, method)).")
 | 
			
		||||
    pFunctionPointer_t add(T *obj, M method)
 | 
			
		||||
    {
 | 
			
		||||
        return add(callback(obj, method));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Add a function at the beginning of the chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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.
 | 
			
		||||
     *
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			@ -137,7 +138,7 @@ public:
 | 
			
		|||
     *  The function object created for 'func'
 | 
			
		||||
     */
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
    /** Add a function at the beginning of the chain
 | 
			
		||||
| 
						 | 
				
			
			@ -154,23 +155,24 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    template<typename T, typename M>
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
			
		||||
        "The add_front function does not support cv-qualifiers. Replaced by "
 | 
			
		||||
        "add_front(callback(obj, method)).")
 | 
			
		||||
    pFunctionPointer_t add_front(T *obj, M method) {
 | 
			
		||||
                          "The add_front function does not support cv-qualifiers. Replaced by "
 | 
			
		||||
                          "add_front(callback(obj, method)).")
 | 
			
		||||
    pFunctionPointer_t add_front(T *obj, M method)
 | 
			
		||||
    {
 | 
			
		||||
        return add_front(callback(obj, method));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Get the number of functions in the chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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 "
 | 
			
		||||
        "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;
 | 
			
		||||
 | 
			
		||||
    /** Get a function object from the chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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.
 | 
			
		||||
     *
 | 
			
		||||
     *  @param i function object index
 | 
			
		||||
| 
						 | 
				
			
			@ -179,11 +181,11 @@ public:
 | 
			
		|||
     *  The function object at position 'i' in the chain
 | 
			
		||||
     */
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
    /** Look for a function object in the call chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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.
 | 
			
		||||
     *
 | 
			
		||||
     *  @param f the function object to search
 | 
			
		||||
| 
						 | 
				
			
			@ -192,18 +194,18 @@ public:
 | 
			
		|||
     *  The index of the function object if found, -1 otherwise.
 | 
			
		||||
     */
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
    /** 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.
 | 
			
		||||
     */
 | 
			
		||||
    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();
 | 
			
		||||
 | 
			
		||||
    /** Remove a function object from the chain
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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.
 | 
			
		||||
     *
 | 
			
		||||
     *  @arg f the function object to remove
 | 
			
		||||
| 
						 | 
				
			
			@ -212,37 +214,39 @@ public:
 | 
			
		|||
     *  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 "
 | 
			
		||||
        "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);
 | 
			
		||||
 | 
			
		||||
    /** Call all the functions in the chain in sequence
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
     *  @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 "
 | 
			
		||||
        "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();
 | 
			
		||||
 | 
			
		||||
    /** 
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
    /**
 | 
			
		||||
     *  @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 "
 | 
			
		||||
        "public API of mbed-os and is being removed in the future.")
 | 
			
		||||
    void operator ()(void) {
 | 
			
		||||
                          "public API of mbed-os and is being removed in the future.")
 | 
			
		||||
    void operator()(void)
 | 
			
		||||
    {
 | 
			
		||||
        call();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** 
 | 
			
		||||
     *  @deprecated 
 | 
			
		||||
    /**
 | 
			
		||||
     *  @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 "
 | 
			
		||||
        "public API of mbed-os and is being removed in the future.")
 | 
			
		||||
    pFunctionPointer_t operator [](int i) const {
 | 
			
		||||
                          "public API of mbed-os and is being removed in the future.")
 | 
			
		||||
    pFunctionPointer_t operator [](int i) const
 | 
			
		||||
    {
 | 
			
		||||
        return get(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1748
									
								
								platform/Callback.h
								
								
								
								
							
							
						
						
									
										1748
									
								
								platform/Callback.h
								
								
								
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -24,17 +24,29 @@ namespace mbed {
 | 
			
		|||
namespace internal {
 | 
			
		||||
/* Detect if CounterType of the Circular buffer is of unsigned type. */
 | 
			
		||||
template<typename T>
 | 
			
		||||
struct is_unsigned { static const bool value = false; };
 | 
			
		||||
struct is_unsigned {
 | 
			
		||||
    static const bool value = false;
 | 
			
		||||
};
 | 
			
		||||
template<>
 | 
			
		||||
struct is_unsigned<unsigned char> { static const bool value = true; };
 | 
			
		||||
struct is_unsigned<unsigned char> {
 | 
			
		||||
    static const bool value = true;
 | 
			
		||||
};
 | 
			
		||||
template<>
 | 
			
		||||
struct is_unsigned<unsigned short> { static const bool value = true; };
 | 
			
		||||
struct is_unsigned<unsigned short> {
 | 
			
		||||
    static const bool value = true;
 | 
			
		||||
};
 | 
			
		||||
template<>
 | 
			
		||||
struct is_unsigned<unsigned int> { static const bool value = true; };
 | 
			
		||||
struct is_unsigned<unsigned int> {
 | 
			
		||||
    static const bool value = true;
 | 
			
		||||
};
 | 
			
		||||
template<>
 | 
			
		||||
struct is_unsigned<unsigned long> { static const bool value = true; };
 | 
			
		||||
struct is_unsigned<unsigned long> {
 | 
			
		||||
    static const bool value = true;
 | 
			
		||||
};
 | 
			
		||||
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 */
 | 
			
		||||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
class CircularBuffer {
 | 
			
		||||
public:
 | 
			
		||||
    CircularBuffer() : _head(0), _tail(0), _full(false) {
 | 
			
		||||
    CircularBuffer() : _head(0), _tail(0), _full(false)
 | 
			
		||||
    {
 | 
			
		||||
        MBED_STATIC_ASSERT(
 | 
			
		||||
            internal::is_unsigned<CounterType>::value,
 | 
			
		||||
            "CounterType must be unsigned"
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +78,8 @@ public:
 | 
			
		|||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ~CircularBuffer() {
 | 
			
		||||
    ~CircularBuffer()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** 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
 | 
			
		||||
     */
 | 
			
		||||
    void push(const T& data) {
 | 
			
		||||
    void push(const T &data)
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        if (full()) {
 | 
			
		||||
            _tail++;
 | 
			
		||||
| 
						 | 
				
			
			@ -92,7 +107,8 @@ public:
 | 
			
		|||
     * @param data Data to be popped from the buffer
 | 
			
		||||
     * @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;
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        if (!empty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -109,7 +125,8 @@ public:
 | 
			
		|||
     *
 | 
			
		||||
     * @return True if the buffer is empty, false if not
 | 
			
		||||
     */
 | 
			
		||||
    bool empty() const {
 | 
			
		||||
    bool empty() const
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        bool is_empty = (_head == _tail) && !_full;
 | 
			
		||||
        core_util_critical_section_exit();
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +137,8 @@ public:
 | 
			
		|||
     *
 | 
			
		||||
     * @return True if the buffer is full, false if not
 | 
			
		||||
     */
 | 
			
		||||
    bool full() const {
 | 
			
		||||
    bool full() const
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        bool full = _full;
 | 
			
		||||
        core_util_critical_section_exit();
 | 
			
		||||
| 
						 | 
				
			
			@ -130,7 +148,8 @@ public:
 | 
			
		|||
    /** Reset the buffer
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    void reset() {
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        _head = 0;
 | 
			
		||||
        _tail = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +158,8 @@ public:
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /** Get the number of elements currently stored in the circular_buffer */
 | 
			
		||||
    CounterType size() const {
 | 
			
		||||
    CounterType size() const
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        CounterType elements;
 | 
			
		||||
        if (!_full) {
 | 
			
		||||
| 
						 | 
				
			
			@ -160,7 +180,8 @@ public:
 | 
			
		|||
     * @param data Data to be peeked from the buffer
 | 
			
		||||
     * @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;
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
        if (!empty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -170,7 +191,7 @@ public:
 | 
			
		|||
        core_util_critical_section_exit();
 | 
			
		||||
        return data_updated;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    T _pool[BufferSize];
 | 
			
		||||
    volatile CounterType _head;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,12 +57,12 @@ namespace mbed {
 | 
			
		|||
  */
 | 
			
		||||
class CriticalSectionLock {
 | 
			
		||||
public:
 | 
			
		||||
    CriticalSectionLock() 
 | 
			
		||||
    CriticalSectionLock()
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ~CriticalSectionLock() 
 | 
			
		||||
    ~CriticalSectionLock()
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_exit();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -72,8 +72,8 @@ public:
 | 
			
		|||
     *
 | 
			
		||||
     */
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.8",
 | 
			
		||||
            "This function is inconsistent with RAII and is being removed in the future."
 | 
			
		||||
            "Replaced by static function CriticalSectionLock::enable.")
 | 
			
		||||
                          "This function is inconsistent with RAII and is being removed in the future."
 | 
			
		||||
                          "Replaced by static function CriticalSectionLock::enable.")
 | 
			
		||||
    void lock()
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_enter();
 | 
			
		||||
| 
						 | 
				
			
			@ -84,8 +84,8 @@ public:
 | 
			
		|||
     *
 | 
			
		||||
     */
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.8",
 | 
			
		||||
            "This function is inconsistent with RAII and is being removed in the future."
 | 
			
		||||
            "Replaced by static function CriticalSectionLock::disable.")
 | 
			
		||||
                          "This function is inconsistent with RAII and is being removed in the future."
 | 
			
		||||
                          "Replaced by static function CriticalSectionLock::disable.")
 | 
			
		||||
    void unlock()
 | 
			
		||||
    {
 | 
			
		||||
        core_util_critical_section_exit();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,7 +80,7 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    virtual void rewind() = 0;
 | 
			
		||||
 | 
			
		||||
    /** Get the sizeof the directory 
 | 
			
		||||
    /** Get the sizeof the directory
 | 
			
		||||
     *
 | 
			
		||||
     *  @return         Number of files in the directory
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +108,10 @@ public:
 | 
			
		|||
     *  @deprecated Replaced by `int 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
 | 
			
		||||
     *  advances the position to the next entry.
 | 
			
		||||
| 
						 | 
				
			
			@ -130,7 +133,10 @@ public:
 | 
			
		|||
     * @deprecated Replaced by `void 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.
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			@ -140,7 +146,10 @@ public:
 | 
			
		|||
     * @deprecated Replaced by `off_t 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.
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +157,10 @@ public:
 | 
			
		|||
     *  @deprecated Replaced by `void DirHandle::seek(off_t offset)'
 | 
			
		||||
     */
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
FileBase::FileBase(const char *name, PathType t) : _next(NULL),
 | 
			
		||||
                                                   _name(name),
 | 
			
		||||
                                                   _path_type(t) {
 | 
			
		||||
    _name(name),
 | 
			
		||||
    _path_type(t)
 | 
			
		||||
{
 | 
			
		||||
    _mutex->lock();
 | 
			
		||||
    if (name != NULL) {
 | 
			
		||||
        // put this object at head of the list
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +37,8 @@ FileBase::FileBase(const char *name, PathType t) : _next(NULL),
 | 
			
		|||
    _mutex->unlock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FileBase::~FileBase() {
 | 
			
		||||
FileBase::~FileBase()
 | 
			
		||||
{
 | 
			
		||||
    _mutex->lock();
 | 
			
		||||
    if (_name != NULL) {
 | 
			
		||||
        // remove this object from the list
 | 
			
		||||
| 
						 | 
				
			
			@ -53,12 +55,13 @@ FileBase::~FileBase() {
 | 
			
		|||
    _mutex->unlock();
 | 
			
		||||
 | 
			
		||||
    if (getPathType() == FilePathType) {
 | 
			
		||||
        extern void remove_filehandle(FileHandle *file);
 | 
			
		||||
        remove_filehandle(static_cast<FileHandle*>(static_cast<FileLike*>(this)));
 | 
			
		||||
        extern void remove_filehandle(FileHandle * file);
 | 
			
		||||
        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();
 | 
			
		||||
    FileBase *p = _head;
 | 
			
		||||
    while (p != NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +76,8 @@ FileBase *FileBase::lookup(const char *name, unsigned int len) {
 | 
			
		|||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FileBase *FileBase::get(int n) {
 | 
			
		||||
FileBase *FileBase::get(int n)
 | 
			
		||||
{
 | 
			
		||||
    _mutex->lock();
 | 
			
		||||
    FileBase *p = _head;
 | 
			
		||||
    int m = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -90,12 +94,14 @@ FileBase *FileBase::get(int n) {
 | 
			
		|||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* FileBase::getName(void) {
 | 
			
		||||
const char *FileBase::getName(void)
 | 
			
		||||
{
 | 
			
		||||
    // Constant read so no lock needed
 | 
			
		||||
    return _name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PathType FileBase::getPathType(void) {
 | 
			
		||||
PathType FileBase::getPathType(void)
 | 
			
		||||
{
 | 
			
		||||
    // Constant read so no lock needed
 | 
			
		||||
    return _path_type;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ typedef int FILEHANDLE;
 | 
			
		|||
#include "platform/NonCopyable.h"
 | 
			
		||||
 | 
			
		||||
namespace mbed {
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    FilePathType,
 | 
			
		||||
    FileSystemPathType
 | 
			
		||||
| 
						 | 
				
			
			@ -42,13 +42,13 @@ typedef enum {
 | 
			
		|||
/** Class FileBase
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
class FileBase : private NonCopyable<FileBase> {
 | 
			
		||||
public:
 | 
			
		||||
    FileBase(const char *name, PathType t);
 | 
			
		||||
    virtual ~FileBase();
 | 
			
		||||
 | 
			
		||||
    const char* getName(void);
 | 
			
		||||
    const char *getName(void);
 | 
			
		||||
    PathType    getPathType(void);
 | 
			
		||||
 | 
			
		||||
    static FileBase *lookup(const char *name, unsigned int len);
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ private:
 | 
			
		|||
    static SingletonPtr<PlatformMutex> _mutex;
 | 
			
		||||
 | 
			
		||||
    FileBase   *_next;
 | 
			
		||||
    const char * const _name;
 | 
			
		||||
    const char *const _name;
 | 
			
		||||
    const PathType _path_type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -69,7 +69,7 @@ public:
 | 
			
		|||
     * * if some data can be written, and non-blocking set, write partial
 | 
			
		||||
     *
 | 
			
		||||
     *  @param buffer   The buffer to write from
 | 
			
		||||
     *  @param size     The number of bytes to write 
 | 
			
		||||
     *  @param size     The number of bytes to write
 | 
			
		||||
     *  @return         The number of bytes written, negative error on failure
 | 
			
		||||
     */
 | 
			
		||||
    virtual ssize_t write(const void *buffer, size_t size) = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,11 +17,12 @@
 | 
			
		|||
 | 
			
		||||
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
 | 
			
		||||
    file_path += strspn(file_path, "/");
 | 
			
		||||
 | 
			
		||||
    const char* file_system = file_path;
 | 
			
		||||
    const char *file_system = file_path;
 | 
			
		||||
    file_name = file_system;
 | 
			
		||||
    int len = 0;
 | 
			
		||||
    while (true) {
 | 
			
		||||
| 
						 | 
				
			
			@ -41,37 +42,45 @@ FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
 | 
			
		|||
    fb = FileBase::lookup(file_system, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* FilePath::fileName(void) {
 | 
			
		||||
const char *FilePath::fileName(void)
 | 
			
		||||
{
 | 
			
		||||
    return file_name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool FilePath::isFileSystem(void) {
 | 
			
		||||
    if (NULL == fb)
 | 
			
		||||
bool FilePath::isFileSystem(void)
 | 
			
		||||
{
 | 
			
		||||
    if (NULL == fb) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    return (fb->getPathType() == FileSystemPathType);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FileSystemLike* FilePath::fileSystem(void) {
 | 
			
		||||
FileSystemLike *FilePath::fileSystem(void)
 | 
			
		||||
{
 | 
			
		||||
    if (isFileSystem()) {
 | 
			
		||||
        return static_cast<FileSystemLike*>(fb);
 | 
			
		||||
        return static_cast<FileSystemLike *>(fb);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool FilePath::isFile(void) {
 | 
			
		||||
    if (NULL == fb)
 | 
			
		||||
bool FilePath::isFile(void)
 | 
			
		||||
{
 | 
			
		||||
    if (NULL == fb) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    return (fb->getPathType() == FilePathType);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FileLike* FilePath::file(void) {
 | 
			
		||||
FileLike *FilePath::file(void)
 | 
			
		||||
{
 | 
			
		||||
    if (isFile()) {
 | 
			
		||||
        return (FileLike*)fb;
 | 
			
		||||
        return (FileLike *)fb;
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool FilePath::exists(void) {
 | 
			
		||||
bool FilePath::exists(void)
 | 
			
		||||
{
 | 
			
		||||
    return fb != NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,27 +33,27 @@ class FileSystem;
 | 
			
		|||
/** Class FilePath
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
class FilePath {
 | 
			
		||||
public:
 | 
			
		||||
    /** Constructor FilePath
 | 
			
		||||
     *
 | 
			
		||||
     *  @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);
 | 
			
		||||
    FileSystemLike* fileSystem(void);
 | 
			
		||||
    FileSystemLike *fileSystem(void);
 | 
			
		||||
 | 
			
		||||
    bool    isFile(void);
 | 
			
		||||
    FileLike* file(void);
 | 
			
		||||
    FileLike *file(void);
 | 
			
		||||
    bool    exists(void);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    const char* file_name;
 | 
			
		||||
    FileBase* fb;
 | 
			
		||||
    const char *file_name;
 | 
			
		||||
    FileBase *fb;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**@}*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -101,7 +101,7 @@ public:
 | 
			
		|||
     *  @param buf      The stat buffer to write to
 | 
			
		||||
     *  @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
 | 
			
		||||
     */
 | 
			
		||||
    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 *file;
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +74,7 @@ public:
 | 
			
		|||
     *  @deprecated Replaced by `int open(DirHandle **, ...)` for propagating error codes
 | 
			
		||||
     */
 | 
			
		||||
    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 *dir;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,21 +35,23 @@ template <typename R, typename A1>
 | 
			
		|||
class FunctionPointerArg1 : public Callback<R(A1)> {
 | 
			
		||||
public:
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
			
		||||
        "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
			
		||||
    FunctionPointerArg1(R (*function)(A1) = 0)
 | 
			
		||||
                          "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
			
		||||
    FunctionPointerArg1(R(*function)(A1) = 0)
 | 
			
		||||
        : Callback<R(A1)>(function) {}
 | 
			
		||||
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
			
		||||
        "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
			
		||||
    FunctionPointerArg1(T *object, R (T::*member)(A1))
 | 
			
		||||
                          "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
 | 
			
		||||
    FunctionPointerArg1(T *object, R(T::*member)(A1))
 | 
			
		||||
        : Callback<R(A1)>(object, member) {}
 | 
			
		||||
 | 
			
		||||
    R (*get_function())(A1) {
 | 
			
		||||
        return *reinterpret_cast<R (**)(A1)>(this);
 | 
			
		||||
    R(*get_function())(A1)
 | 
			
		||||
    {
 | 
			
		||||
        return *reinterpret_cast<R(* *)(A1)>(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    R call(A1 a1) const {
 | 
			
		||||
    R call(A1 a1) const
 | 
			
		||||
    {
 | 
			
		||||
        if (!Callback<R(A1)>::operator bool()) {
 | 
			
		||||
            return (R)0;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -57,7 +59,8 @@ public:
 | 
			
		|||
        return Callback<R(A1)>::call(a1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    R operator()(A1 a1) const {
 | 
			
		||||
    R operator()(A1 a1) const
 | 
			
		||||
    {
 | 
			
		||||
        return Callback<R(A1)>::call(a1);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -66,21 +69,23 @@ template <typename R>
 | 
			
		|||
class FunctionPointerArg1<R, void> : public Callback<R()> {
 | 
			
		||||
public:
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
			
		||||
        "FunctionPointer has been replaced by Callback<void()>")
 | 
			
		||||
    FunctionPointerArg1(R (*function)() = 0)
 | 
			
		||||
                          "FunctionPointer has been replaced by Callback<void()>")
 | 
			
		||||
    FunctionPointerArg1(R(*function)() = 0)
 | 
			
		||||
        : Callback<R()>(function) {}
 | 
			
		||||
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    MBED_DEPRECATED_SINCE("mbed-os-5.1",
 | 
			
		||||
        "FunctionPointer has been replaced by Callback<void()>")
 | 
			
		||||
    FunctionPointerArg1(T *object, R (T::*member)())
 | 
			
		||||
                          "FunctionPointer has been replaced by Callback<void()>")
 | 
			
		||||
    FunctionPointerArg1(T *object, R(T::*member)())
 | 
			
		||||
        : Callback<R()>(object, member) {}
 | 
			
		||||
 | 
			
		||||
    R (*get_function())() {
 | 
			
		||||
        return *reinterpret_cast<R (**)()>(this);
 | 
			
		||||
    R(*get_function())()
 | 
			
		||||
    {
 | 
			
		||||
        return *reinterpret_cast<R(* *)()>(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    R call() const {
 | 
			
		||||
    R call() const
 | 
			
		||||
    {
 | 
			
		||||
        if (!Callback<R()>::operator bool()) {
 | 
			
		||||
            return (R)0;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -88,7 +93,8 @@ public:
 | 
			
		|||
        return Callback<R()>::call();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    R operator()() const {
 | 
			
		||||
    R operator()() const
 | 
			
		||||
    {
 | 
			
		||||
        return Callback<R()>::call();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,8 @@ typedef struct {         /* File Search info record           */
 | 
			
		|||
#define RESERVED_FOR_USER_APPLICATIONS (0x100) /* 0x100 - 0x1ff */
 | 
			
		||||
#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];
 | 
			
		||||
 | 
			
		||||
    param[0] = (unsigned long)pattern;
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +64,8 @@ static int xffind (const char *pattern, XFINFO *info) {
 | 
			
		|||
#define OPEN_A          8
 | 
			
		||||
#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 */
 | 
			
		||||
    int openmode;
 | 
			
		||||
    if (flags & O_RDWR) {
 | 
			
		||||
| 
						 | 
				
			
			@ -94,7 +96,8 @@ int posix_to_semihost_open_flags(int flags) {
 | 
			
		|||
    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);
 | 
			
		||||
    if (openmode == OPEN_INVALID) {
 | 
			
		||||
        return (FILEHANDLE)NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -108,42 +111,48 @@ FILEHANDLE local_file_open(const char* name, int flags) {
 | 
			
		|||
    return fh;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LocalFileHandle::LocalFileHandle(FILEHANDLE fh) : _fh(fh), pos(0) {
 | 
			
		||||
LocalFileHandle::LocalFileHandle(FILEHANDLE fh) : _fh(fh), pos(0)
 | 
			
		||||
{
 | 
			
		||||
    // No lock needed in constructor
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LocalFileHandle::close() {
 | 
			
		||||
int LocalFileHandle::close()
 | 
			
		||||
{
 | 
			
		||||
    int retval = semihost_close(_fh);
 | 
			
		||||
    delete this;
 | 
			
		||||
    return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t LocalFileHandle::write(const void *buffer, size_t length) {
 | 
			
		||||
ssize_t LocalFileHandle::write(const void *buffer, size_t length)
 | 
			
		||||
{
 | 
			
		||||
    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
 | 
			
		||||
    pos += n;
 | 
			
		||||
    unlock();
 | 
			
		||||
    return n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t LocalFileHandle::read(void *buffer, size_t length) {
 | 
			
		||||
ssize_t LocalFileHandle::read(void *buffer, size_t length)
 | 
			
		||||
{
 | 
			
		||||
    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
 | 
			
		||||
    pos += n;
 | 
			
		||||
    unlock();
 | 
			
		||||
    return n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LocalFileHandle::isatty() {
 | 
			
		||||
int LocalFileHandle::isatty()
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    int ret = semihost_istty(_fh);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
off_t LocalFileHandle::seek(off_t position, int whence) {
 | 
			
		||||
off_t LocalFileHandle::seek(off_t position, int whence)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    if (whence == SEEK_CUR) {
 | 
			
		||||
        position += pos;
 | 
			
		||||
| 
						 | 
				
			
			@ -158,25 +167,29 @@ off_t LocalFileHandle::seek(off_t position, int whence) {
 | 
			
		|||
    return position;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LocalFileHandle::sync() {
 | 
			
		||||
int LocalFileHandle::sync()
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    int ret = semihost_ensure(_fh);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
off_t LocalFileHandle::size() {
 | 
			
		||||
off_t LocalFileHandle::size()
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    off_t off = semihost_flen(_fh);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return off;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LocalFileHandle::lock() {
 | 
			
		||||
void LocalFileHandle::lock()
 | 
			
		||||
{
 | 
			
		||||
    _mutex.lock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LocalFileHandle::unlock() {
 | 
			
		||||
void LocalFileHandle::unlock()
 | 
			
		||||
{
 | 
			
		||||
    _mutex.unlock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -185,18 +198,21 @@ class LocalDirHandle : public DirHandle {
 | 
			
		|||
public:
 | 
			
		||||
    XFINFO info;
 | 
			
		||||
 | 
			
		||||
    LocalDirHandle() : info() {
 | 
			
		||||
    LocalDirHandle() : info()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual int close() {
 | 
			
		||||
    virtual int close()
 | 
			
		||||
    {
 | 
			
		||||
        // No lock can be used in destructor
 | 
			
		||||
        delete this;
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual int read(struct dirent *ent) {
 | 
			
		||||
    virtual int read(struct dirent *ent)
 | 
			
		||||
    {
 | 
			
		||||
        lock();
 | 
			
		||||
        if (xffind("*", &info)!=0) {
 | 
			
		||||
        if (xffind("*", &info) != 0) {
 | 
			
		||||
            unlock();
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -205,20 +221,23 @@ public:
 | 
			
		|||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void rewind() {
 | 
			
		||||
    virtual void rewind()
 | 
			
		||||
    {
 | 
			
		||||
        lock();
 | 
			
		||||
        info.fileID = 0;
 | 
			
		||||
        unlock();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual off_t tell() {
 | 
			
		||||
    virtual off_t tell()
 | 
			
		||||
    {
 | 
			
		||||
        lock();
 | 
			
		||||
        int fileId = info.fileID;
 | 
			
		||||
        unlock();
 | 
			
		||||
        return fileId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void seek(off_t offset) {
 | 
			
		||||
    virtual void seek(off_t offset)
 | 
			
		||||
    {
 | 
			
		||||
        lock();
 | 
			
		||||
        info.fileID = offset;
 | 
			
		||||
        unlock();
 | 
			
		||||
| 
						 | 
				
			
			@ -227,16 +246,19 @@ public:
 | 
			
		|||
protected:
 | 
			
		||||
    PlatformMutex _mutex;
 | 
			
		||||
 | 
			
		||||
    virtual void lock() {
 | 
			
		||||
    virtual void lock()
 | 
			
		||||
    {
 | 
			
		||||
        _mutex.lock();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void unlock() {
 | 
			
		||||
    virtual void 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
 | 
			
		||||
 | 
			
		||||
    /* reject filenames with / in them */
 | 
			
		||||
| 
						 | 
				
			
			@ -260,13 +282,15 @@ int LocalFileSystem::open(FileHandle **file, const char* name, int flags) {
 | 
			
		|||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LocalFileSystem::remove(const char *filename) {
 | 
			
		||||
int LocalFileSystem::remove(const char *filename)
 | 
			
		||||
{
 | 
			
		||||
    // No global state modified so function is thread safe
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
    *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
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +106,8 @@ class LocalFileSystem : public FileSystemLike, private NonCopyable<LocalFileSyst
 | 
			
		|||
    // No modifiable state
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
     */
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -184,7 +184,7 @@ protected:
 | 
			
		|||
     * Copy of non copyable resources can lead to resource leak and random error.
 | 
			
		||||
     */
 | 
			
		||||
    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);
 | 
			
		||||
        return *this;
 | 
			
		||||
| 
						 | 
				
			
			@ -196,13 +196,13 @@ private:
 | 
			
		|||
     * Declare copy constructor as private, any attempt to copy construct
 | 
			
		||||
     * a NonCopyable will fail at compile time.
 | 
			
		||||
     */
 | 
			
		||||
    NonCopyable(const NonCopyable&);
 | 
			
		||||
    NonCopyable(const NonCopyable &);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Declare copy assignment operator as private, any attempt to copy assign
 | 
			
		||||
     * a NonCopyable will fail at compile time.
 | 
			
		||||
     */
 | 
			
		||||
    NonCopyable& operator=(const NonCopyable&);
 | 
			
		||||
    NonCopyable &operator=(const NonCopyable &);
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,19 +33,23 @@ typedef rtos::Mutex PlatformMutex;
 | 
			
		|||
*/
 | 
			
		||||
class PlatformMutex : private mbed::NonCopyable<PlatformMutex> {
 | 
			
		||||
public:
 | 
			
		||||
    PlatformMutex() {
 | 
			
		||||
    PlatformMutex()
 | 
			
		||||
    {
 | 
			
		||||
        // Stub
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    ~PlatformMutex() {
 | 
			
		||||
    ~PlatformMutex()
 | 
			
		||||
    {
 | 
			
		||||
        // Stub
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void lock() {
 | 
			
		||||
    void lock()
 | 
			
		||||
    {
 | 
			
		||||
        // Do nothing
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void unlock() {
 | 
			
		||||
    void unlock()
 | 
			
		||||
    {
 | 
			
		||||
        // Do nothing
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -65,7 +65,7 @@ public:
 | 
			
		|||
     * @param lockable reference to the instance of Lockable object
 | 
			
		||||
     * @note lockable object should outlive the ScopedLock object
 | 
			
		||||
     */
 | 
			
		||||
    ScopedLock(Lockable& lockable): _lockable(lockable)
 | 
			
		||||
    ScopedLock(Lockable &lockable): _lockable(lockable)
 | 
			
		||||
    {
 | 
			
		||||
        _lockable.lock();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +75,7 @@ public:
 | 
			
		|||
        _lockable.unlock();
 | 
			
		||||
    }
 | 
			
		||||
private:
 | 
			
		||||
    Lockable& _lockable;
 | 
			
		||||
    Lockable &_lockable;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**@}*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ inline static void singleton_lock(void)
 | 
			
		|||
inline static void singleton_unlock(void)
 | 
			
		||||
{
 | 
			
		||||
#ifdef MBED_CONF_RTOS_PRESENT
 | 
			
		||||
    osMutexRelease (singleton_mutex_id);
 | 
			
		||||
    osMutexRelease(singleton_mutex_id);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +80,8 @@ struct SingletonPtr {
 | 
			
		|||
     * @returns
 | 
			
		||||
     *   A pointer to the singleton
 | 
			
		||||
     */
 | 
			
		||||
    T* get() {
 | 
			
		||||
    T *get()
 | 
			
		||||
    {
 | 
			
		||||
        if (NULL == _ptr) {
 | 
			
		||||
            singleton_lock();
 | 
			
		||||
            if (NULL == _ptr) {
 | 
			
		||||
| 
						 | 
				
			
			@ -99,7 +100,8 @@ struct SingletonPtr {
 | 
			
		|||
     * @returns
 | 
			
		||||
     *   A pointer to the singleton
 | 
			
		||||
     */
 | 
			
		||||
    T* operator->() {
 | 
			
		||||
    T *operator->()
 | 
			
		||||
    {
 | 
			
		||||
        return get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,13 +19,14 @@
 | 
			
		|||
 | 
			
		||||
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
 | 
			
		||||
    /* open ourselves */
 | 
			
		||||
    _file = fdopen(this, "w+");
 | 
			
		||||
    // fdopen() will make us buffered because Stream::isatty()
 | 
			
		||||
    // wrongly returns zero which is not being changed for
 | 
			
		||||
    // backward compatibility 
 | 
			
		||||
    // backward compatibility
 | 
			
		||||
    if (_file) {
 | 
			
		||||
        mbed_set_unbuffered_stream(_file);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -33,47 +34,54 @@ Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Stream::~Stream() {
 | 
			
		||||
Stream::~Stream()
 | 
			
		||||
{
 | 
			
		||||
    // No lock can be used in destructor
 | 
			
		||||
    fclose(_file);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::putc(int c) {
 | 
			
		||||
int Stream::putc(int c)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    fflush(_file);
 | 
			
		||||
    int ret = std::fputc(c, _file);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
int Stream::puts(const char *s) {
 | 
			
		||||
int Stream::puts(const char *s)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    fflush(_file);
 | 
			
		||||
    int ret = std::fputs(s, _file);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
int Stream::getc() {
 | 
			
		||||
int Stream::getc()
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    fflush(_file);
 | 
			
		||||
    int ret = mbed_getc(_file);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
char* Stream::gets(char *s, int size) {
 | 
			
		||||
char *Stream::gets(char *s, int size)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    fflush(_file);
 | 
			
		||||
    char *ret = mbed_gets(s,size,_file);
 | 
			
		||||
    char *ret = mbed_gets(s, size, _file);
 | 
			
		||||
    unlock();
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::close() {
 | 
			
		||||
int Stream::close()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t Stream::write(const void* buffer, size_t length) {
 | 
			
		||||
    const char* ptr = (const char*)buffer;
 | 
			
		||||
    const char* end = ptr + length;
 | 
			
		||||
ssize_t Stream::write(const void *buffer, size_t length)
 | 
			
		||||
{
 | 
			
		||||
    const char *ptr = (const char *)buffer;
 | 
			
		||||
    const char *end = ptr + length;
 | 
			
		||||
 | 
			
		||||
    lock();
 | 
			
		||||
    while (ptr != end) {
 | 
			
		||||
| 
						 | 
				
			
			@ -83,48 +91,58 @@ ssize_t Stream::write(const void* buffer, size_t length) {
 | 
			
		|||
    }
 | 
			
		||||
    unlock();
 | 
			
		||||
 | 
			
		||||
    return ptr - (const char*)buffer;
 | 
			
		||||
    return ptr - (const char *)buffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t Stream::read(void* buffer, size_t length) {
 | 
			
		||||
    char* ptr = (char*)buffer;
 | 
			
		||||
    char* end = ptr + length;
 | 
			
		||||
ssize_t Stream::read(void *buffer, size_t length)
 | 
			
		||||
{
 | 
			
		||||
    char *ptr = (char *)buffer;
 | 
			
		||||
    char *end = ptr + length;
 | 
			
		||||
 | 
			
		||||
    lock();
 | 
			
		||||
    while (ptr != end) {
 | 
			
		||||
        int c = _getc();
 | 
			
		||||
        if (c==EOF) break;
 | 
			
		||||
        if (c == EOF) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        *ptr++ = c;
 | 
			
		||||
    }
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
off_t Stream::tell() {
 | 
			
		||||
off_t Stream::tell()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Stream::rewind() {
 | 
			
		||||
void Stream::rewind()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::isatty() {
 | 
			
		||||
int Stream::isatty()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::sync() {
 | 
			
		||||
int Stream::sync()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
off_t Stream::size() {
 | 
			
		||||
off_t Stream::size()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::printf(const char* format, ...) {
 | 
			
		||||
int Stream::printf(const char *format, ...)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    std::va_list arg;
 | 
			
		||||
    va_start(arg, format);
 | 
			
		||||
| 
						 | 
				
			
			@ -135,7 +153,8 @@ int Stream::printf(const char* format, ...) {
 | 
			
		|||
    return r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::scanf(const char* format, ...) {
 | 
			
		||||
int Stream::scanf(const char *format, ...)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    std::va_list arg;
 | 
			
		||||
    va_start(arg, format);
 | 
			
		||||
| 
						 | 
				
			
			@ -146,7 +165,8 @@ int Stream::scanf(const char* format, ...) {
 | 
			
		|||
    return r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::vprintf(const char* format, std::va_list args) {
 | 
			
		||||
int Stream::vprintf(const char *format, std::va_list args)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    fflush(_file);
 | 
			
		||||
    int r = vfprintf(_file, format, args);
 | 
			
		||||
| 
						 | 
				
			
			@ -154,7 +174,8 @@ int Stream::vprintf(const char* format, std::va_list args) {
 | 
			
		|||
    return r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::vscanf(const char* format, std::va_list args) {
 | 
			
		||||
int Stream::vscanf(const char *format, std::va_list args)
 | 
			
		||||
{
 | 
			
		||||
    lock();
 | 
			
		||||
    fflush(_file);
 | 
			
		||||
    int r = vfscanf(_file, format, args);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ namespace mbed {
 | 
			
		|||
 | 
			
		||||
extern void mbed_set_unbuffered_stream(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
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -42,24 +42,27 @@ extern char* mbed_gets(char *s, int size, std::FILE *_file);
 | 
			
		|||
class Stream : public FileLike, private NonCopyable<Stream> {
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    Stream(const char *name=NULL);
 | 
			
		||||
    Stream(const char *name = NULL);
 | 
			
		||||
    virtual ~Stream();
 | 
			
		||||
 | 
			
		||||
    int putc(int c);
 | 
			
		||||
    int puts(const char *s);
 | 
			
		||||
    int getc();
 | 
			
		||||
    char *gets(char *s, int size);
 | 
			
		||||
    int printf(const char* format, ...);
 | 
			
		||||
    int scanf(const char* format, ...);
 | 
			
		||||
    int vprintf(const char* format, std::va_list args);
 | 
			
		||||
    int vscanf(const char* format, std::va_list args);
 | 
			
		||||
    int printf(const char *format, ...);
 | 
			
		||||
    int scanf(const char *format, ...);
 | 
			
		||||
    int vprintf(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:
 | 
			
		||||
    virtual int close();
 | 
			
		||||
    virtual ssize_t write(const void* buffer, size_t length);
 | 
			
		||||
    virtual ssize_t read(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 off_t seek(off_t offset, int whence);
 | 
			
		||||
    virtual off_t tell();
 | 
			
		||||
    virtual void rewind();
 | 
			
		||||
| 
						 | 
				
			
			@ -74,13 +77,15 @@ protected:
 | 
			
		|||
 | 
			
		||||
    /** Acquire exclusive access to this object.
 | 
			
		||||
     */
 | 
			
		||||
    virtual void lock() {
 | 
			
		||||
    virtual void lock()
 | 
			
		||||
    {
 | 
			
		||||
        // Stub
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Release exclusive access to this object.
 | 
			
		||||
     */
 | 
			
		||||
    virtual void unlock() {
 | 
			
		||||
    virtual void unlock()
 | 
			
		||||
    {
 | 
			
		||||
        // Stub
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,20 +46,24 @@ typedef struct {
 | 
			
		|||
template<typename Class>
 | 
			
		||||
class Transaction {
 | 
			
		||||
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
 | 
			
		||||
     *
 | 
			
		||||
     * @return The object which was stored
 | 
			
		||||
     */
 | 
			
		||||
    Class* get_object() {
 | 
			
		||||
    Class *get_object()
 | 
			
		||||
    {
 | 
			
		||||
        return _obj;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -67,12 +71,13 @@ public:
 | 
			
		|||
     *
 | 
			
		||||
     * @return The transaction which was stored
 | 
			
		||||
     */
 | 
			
		||||
    transaction_t* get_transaction() {
 | 
			
		||||
    transaction_t *get_transaction()
 | 
			
		||||
    {
 | 
			
		||||
        return &_data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Class* _obj;
 | 
			
		||||
    Class *_obj;
 | 
			
		||||
    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 */
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
    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__realloc_r(struct _reent * r, void * ptr, size_t size);
 | 
			
		||||
    void __real__free_r(struct _reent * r, void * ptr);
 | 
			
		||||
    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 free_wrapper(struct _reent * r, void * ptr, void* caller);
 | 
			
		||||
    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__realloc_r(struct _reent *r, void *ptr, size_t size);
 | 
			
		||||
    void __real__free_r(struct _reent *r, void *ptr);
 | 
			
		||||
    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 free_wrapper(struct _reent *r, void *ptr, void *caller);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: memory tracing doesn't work with uVisor enabled.
 | 
			
		||||
#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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
			
		||||
    mbed_mem_trace_lock();
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef MBED_HEAP_STATS_ENABLED
 | 
			
		||||
    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) {
 | 
			
		||||
        alloc_info->size = size;
 | 
			
		||||
        ptr = (void*)(alloc_info + 1);
 | 
			
		||||
        ptr = (void *)(alloc_info + 1);
 | 
			
		||||
        heap_stats.current_size += size;
 | 
			
		||||
        heap_stats.total_size += size;
 | 
			
		||||
        heap_stats.alloc_cnt += 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -123,7 +125,8 @@ extern "C" void * malloc_wrapper(struct _reent * r, size_t size, void * caller)
 | 
			
		|||
    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;
 | 
			
		||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
			
		||||
    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
 | 
			
		||||
    uint32_t old_size = 0;
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -152,7 +155,7 @@ extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size)
 | 
			
		|||
    // and free the old buffer
 | 
			
		||||
    if (new_ptr != NULL) {
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
#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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
    mbed_mem_trace_lock();
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -177,11 +182,11 @@ extern "C" void free_wrapper(struct _reent * r, void * ptr, void * caller) {
 | 
			
		|||
    malloc_stats_mutex->lock();
 | 
			
		||||
    alloc_info_t *alloc_info = 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.alloc_cnt -= 1;
 | 
			
		||||
    }
 | 
			
		||||
    __real__free_r(r, (void*)alloc_info);
 | 
			
		||||
    __real__free_r(r, (void *)alloc_info);
 | 
			
		||||
    malloc_stats_mutex->unlock();
 | 
			
		||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
			
		||||
    __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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -255,26 +262,28 @@ extern "C" {
 | 
			
		|||
    void *SUPER_REALLOC(void *ptr, size_t size);
 | 
			
		||||
    void *SUPER_CALLOC(size_t nmemb, size_t size);
 | 
			
		||||
    void SUPER_FREE(void *ptr);
 | 
			
		||||
    void *malloc_wrapper(size_t size, void* caller);
 | 
			
		||||
    void free_wrapper(void *ptr, void* caller);
 | 
			
		||||
    void *malloc_wrapper(size_t size, 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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void* malloc_wrapper(size_t size, void* caller) {
 | 
			
		||||
extern "C" void *malloc_wrapper(size_t size, void *caller)
 | 
			
		||||
{
 | 
			
		||||
    void *ptr = NULL;
 | 
			
		||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
			
		||||
    mbed_mem_trace_lock();
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef MBED_HEAP_STATS_ENABLED
 | 
			
		||||
    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) {
 | 
			
		||||
        alloc_info->size = size;
 | 
			
		||||
        ptr = (void*)(alloc_info + 1);
 | 
			
		||||
        ptr = (void *)(alloc_info + 1);
 | 
			
		||||
        heap_stats.current_size += size;
 | 
			
		||||
        heap_stats.total_size += size;
 | 
			
		||||
        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;
 | 
			
		||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
			
		||||
    mbed_mem_trace_lock();
 | 
			
		||||
| 
						 | 
				
			
			@ -307,7 +317,7 @@ extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
			
		|||
    // Get old size
 | 
			
		||||
    uint32_t old_size = 0;
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -320,7 +330,7 @@ extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
			
		|||
    // and free the old buffer
 | 
			
		||||
    if (new_ptr != NULL) {
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
			
		||||
| 
						 | 
				
			
			@ -333,7 +343,8 @@ extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
 | 
			
		|||
    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;
 | 
			
		||||
#ifdef MBED_MEM_TRACING_ENABLED
 | 
			
		||||
    mbed_mem_trace_lock();
 | 
			
		||||
| 
						 | 
				
			
			@ -354,11 +365,13 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) {
 | 
			
		|||
    return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void SUB_FREE(void *ptr) {
 | 
			
		||||
extern "C" void SUB_FREE(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    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
 | 
			
		||||
    mbed_mem_trace_lock();
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -366,11 +379,11 @@ extern "C" void free_wrapper(void *ptr, void* caller) {
 | 
			
		|||
    malloc_stats_mutex->lock();
 | 
			
		||||
    alloc_info_t *alloc_info = 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.alloc_cnt -= 1;
 | 
			
		||||
    }
 | 
			
		||||
    SUPER_FREE((void*)alloc_info);
 | 
			
		||||
    SUPER_FREE((void *)alloc_info);
 | 
			
		||||
    malloc_stats_mutex->unlock();
 | 
			
		||||
#else // #ifdef MBED_HEAP_STATS_ENABLED
 | 
			
		||||
    SUPER_FREE(ptr);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,8 +46,8 @@ void mbed_start_application(uintptr_t address)
 | 
			
		|||
    powerdown_nvic();
 | 
			
		||||
    powerdown_scb(address);
 | 
			
		||||
 | 
			
		||||
    sp = *((void**)address + 0);
 | 
			
		||||
    pc = *((void**)address + 1);
 | 
			
		||||
    sp = *((void **)address + 0);
 | 
			
		||||
    pc = *((void **)address + 1);
 | 
			
		||||
    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)
 | 
			
		||||
{
 | 
			
		||||
    __asm volatile (
 | 
			
		||||
    __asm volatile(
 | 
			
		||||
        "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
 | 
			
		||||
                                // will zero-extend the 16-bit immediate.
 | 
			
		||||
        // We needn't "movt r2, #0" immediately following because MOVW
 | 
			
		||||
        // will zero-extend the 16-bit immediate.
 | 
			
		||||
        "msr    control, r2 \n" // Switch to main stack
 | 
			
		||||
        "mov    sp, %0      \n"
 | 
			
		||||
        "msr    primask, r2 \n" // Enable interrupts
 | 
			
		||||
        "bx     %1          \n"
 | 
			
		||||
        :
 | 
			
		||||
        : "l" (sp), "l" (pc)
 | 
			
		||||
        : "l"(sp), "l"(pc)
 | 
			
		||||
        : "r2", "cc", "memory"
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,11 +26,13 @@ extern int stdio_uart_inited;
 | 
			
		|||
extern serial_t stdio_uart;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
WEAK void mbed_die(void) {
 | 
			
		||||
WEAK void mbed_die(void)
 | 
			
		||||
{
 | 
			
		||||
#if !defined (NRF51_H) && !defined(TARGET_EFM32)
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
#endif
 | 
			
		||||
    gpio_t led_err; gpio_init_out(&led_err, LED1);
 | 
			
		||||
    gpio_t led_err;
 | 
			
		||||
    gpio_init_out(&led_err, LED1);
 | 
			
		||||
 | 
			
		||||
    while (1) {
 | 
			
		||||
        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_start(arg, format);
 | 
			
		||||
    mbed_error_vfprintf(format, 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
 | 
			
		||||
#define ERROR_BUF_SIZE      (128)
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +74,7 @@ void mbed_error_vfprintf(const char * format, va_list arg) {
 | 
			
		|||
        char stdio_out_prev = '\0';
 | 
			
		||||
        for (int i = 0; i < size; i++) {
 | 
			
		||||
            if (buffer[i] == '\n' && stdio_out_prev != '\r') {
 | 
			
		||||
                 serial_putc(&stdio_uart, '\r');
 | 
			
		||||
                serial_putc(&stdio_uart, '\r');
 | 
			
		||||
            }
 | 
			
		||||
            serial_putc(&stdio_uart, buffer[i]);
 | 
			
		||||
            stdio_out_prev = buffer[i];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,7 +38,7 @@
 | 
			
		|||
#else
 | 
			
		||||
#error "Unknown architecture for exclusive access"
 | 
			
		||||
#endif
 | 
			
		||||
#else 
 | 
			
		||||
#else
 | 
			
		||||
#define MBED_EXCLUSIVE_ACCESS __EXCLUSIVE_ACCESS
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -57,7 +57,7 @@ bool core_util_are_interrupts_enabled(void)
 | 
			
		|||
bool core_util_is_isr_active(void)
 | 
			
		||||
{
 | 
			
		||||
#if defined(__CORTEX_A9)
 | 
			
		||||
    switch(__get_CPSR() & 0x1FU) {
 | 
			
		||||
    switch (__get_CPSR() & 0x1FU) {
 | 
			
		||||
        case CPSR_M_USR:
 | 
			
		||||
        case CPSR_M_SYS:
 | 
			
		||||
            return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ void core_util_critical_section_enter(void)
 | 
			
		|||
{
 | 
			
		||||
// FIXME
 | 
			
		||||
#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
 | 
			
		||||
    // If the reentrancy counter overflows something has gone badly wrong.
 | 
			
		||||
    MBED_ASSERT(critical_section_reentrancy_counter < UINT32_MAX);
 | 
			
		||||
| 
						 | 
				
			
			@ -94,7 +94,7 @@ void core_util_critical_section_exit(void)
 | 
			
		|||
{
 | 
			
		||||
// FIXME
 | 
			
		||||
#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 */
 | 
			
		||||
 | 
			
		||||
    // If critical_section_enter has not previously been called, do nothing
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +112,7 @@ void core_util_critical_section_exit(void)
 | 
			
		|||
#if MBED_EXCLUSIVE_ACCESS
 | 
			
		||||
 | 
			
		||||
/* Supress __ldrex and __strex deprecated warnings - "#3731-D: intrinsic is deprecated" */
 | 
			
		||||
#if defined (__CC_ARM) 
 | 
			
		||||
#if defined (__CC_ARM)
 | 
			
		||||
#pragma diag_suppress 3731
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -330,18 +330,21 @@ uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta)
 | 
			
		|||
#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(
 | 
			
		||||
            (volatile uint32_t *)ptr,
 | 
			
		||||
            (uint32_t *)expectedCurrentValue,
 | 
			
		||||
            (uint32_t)desiredValue);
 | 
			
		||||
               (volatile uint32_t *)ptr,
 | 
			
		||||
               (uint32_t *)expectedCurrentValue,
 | 
			
		||||
               (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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 * 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 *       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.
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 *       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
 | 
			
		||||
} // extern "C"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
 * \defgroup platform_debug Debug functions
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
/* mbed Microcontroller Library
 | 
			
		||||
 * Copyright (c) 2006-2013 ARM Limited
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +37,8 @@ extern "C" {
 | 
			
		|||
 *
 | 
			
		||||
 * @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)
 | 
			
		||||
    va_list args;
 | 
			
		||||
    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 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 (condition) {
 | 
			
		||||
        va_list args;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,7 @@
 | 
			
		|||
#include "platform/mbed_error.h"
 | 
			
		||||
#include "platform/mbed_error_hist.h"
 | 
			
		||||
#include "platform/mbed_interface.h"
 | 
			
		||||
#ifdef MBED_CONF_RTOS_PRESENT  
 | 
			
		||||
#ifdef MBED_CONF_RTOS_PRESENT
 | 
			
		||||
#include "rtx_os.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +43,7 @@
 | 
			
		|||
                                    sp = __get_PSP();/*Read PSP*/                   \
 | 
			
		||||
                                }                                                   \
 | 
			
		||||
                            }                                                       \
 | 
			
		||||
                        }    
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static uint8_t error_in_progress = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -59,8 +59,8 @@ static void mbed_halt_system(void)
 | 
			
		|||
{
 | 
			
		||||
    //If not in ISR context exit, otherwise spin on WFI
 | 
			
		||||
    if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
 | 
			
		||||
        for(;;) {
 | 
			
		||||
           __WFI();
 | 
			
		||||
        for (;;) {
 | 
			
		||||
            __WFI();
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        //exit eventually calls mbed_die
 | 
			
		||||
| 
						 | 
				
			
			@ -68,13 +68,14 @@ 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
 | 
			
		||||
    if (error_in_progress) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Call handle_error/print_error_report permanently setting error_in_progress flag
 | 
			
		||||
    handle_error(MBED_ERROR_UNKNOWN, 0, NULL, 0);
 | 
			
		||||
    print_error_report(&last_error_ctx, "Fatal Run-time error");
 | 
			
		||||
| 
						 | 
				
			
			@ -90,46 +91,46 @@ WEAK void error(const char* format, ...) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
//Set an error status with the error handling system
 | 
			
		||||
static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsigned int error_value, const char *filename, int line_number) 
 | 
			
		||||
static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsigned int error_value, const char *filename, int line_number)
 | 
			
		||||
{
 | 
			
		||||
    mbed_error_ctx current_error_ctx;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Error status should always be < 0
 | 
			
		||||
    if (error_status >= 0) {
 | 
			
		||||
        //This is a weird situation, someone called mbed_error with invalid error code.
 | 
			
		||||
        //We will still handle the situation but change the error code to ERROR_INVALID_ARGUMENT, atleast the context will have info on who called it
 | 
			
		||||
        error_status = MBED_ERROR_INVALID_ARGUMENT;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Prevent corruption by holding out other callers
 | 
			
		||||
    //and we also need this until we remove the "error" call completely
 | 
			
		||||
    while (error_in_progress == 1);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Use critsect here, as we don't want inadvertant modification of this global variable
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
    error_in_progress = 1;
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Increment error count
 | 
			
		||||
    error_count++;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Clear the context capturing buffer
 | 
			
		||||
    memset(¤t_error_ctx, sizeof(mbed_error_ctx), 0);
 | 
			
		||||
    //Capture error information
 | 
			
		||||
    current_error_ctx.error_status = error_status;
 | 
			
		||||
    current_error_ctx.error_address = (uint32_t)MBED_CALLER_ADDR();
 | 
			
		||||
    current_error_ctx.error_value = error_value;
 | 
			
		||||
#ifdef MBED_CONF_RTOS_PRESENT         
 | 
			
		||||
#ifdef MBED_CONF_RTOS_PRESENT
 | 
			
		||||
    //Capture thread info
 | 
			
		||||
    osRtxThread_t *current_thread = osRtxInfo.thread.run.curr;
 | 
			
		||||
    current_error_ctx.thread_id = (uint32_t)current_thread;
 | 
			
		||||
    current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr;
 | 
			
		||||
    current_error_ctx.thread_stack_size = current_thread->stack_size;
 | 
			
		||||
    current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem;
 | 
			
		||||
#ifdef TARGET_CORTEX_M        
 | 
			
		||||
#ifdef TARGET_CORTEX_M
 | 
			
		||||
    GET_CURRENT_SP(current_error_ctx.thread_current_sp);
 | 
			
		||||
#endif //TARGET_CORTEX_M
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
#endif //MBED_CONF_RTOS_PRESENT
 | 
			
		||||
 | 
			
		||||
#ifdef MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
 | 
			
		||||
| 
						 | 
				
			
			@ -139,121 +140,124 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
 | 
			
		|||
    strncpy(current_error_ctx.error_filename, filename, MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN);
 | 
			
		||||
    current_error_ctx.error_line_number = line_number;
 | 
			
		||||
#endif
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Capture the fist system error and store it
 | 
			
		||||
    if (error_count == 1) { //first error
 | 
			
		||||
        memcpy(&first_error_ctx, ¤t_error_ctx, sizeof(mbed_error_ctx));
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //copy this error to last error
 | 
			
		||||
    memcpy(&last_error_ctx, ¤t_error_ctx, sizeof(mbed_error_ctx));
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
 | 
			
		||||
    //Log the error with error log
 | 
			
		||||
    mbed_error_hist_put(¤t_error_ctx);
 | 
			
		||||
#endif    
 | 
			
		||||
    
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    //Call the error hook if available
 | 
			
		||||
    if (error_hook != NULL) {
 | 
			
		||||
        error_hook(&last_error_ctx);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    error_in_progress = 0;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Return the first error
 | 
			
		||||
mbed_error_status_t mbed_get_first_error(void) 
 | 
			
		||||
mbed_error_status_t mbed_get_first_error(void)
 | 
			
		||||
{
 | 
			
		||||
    //return the first error recorded
 | 
			
		||||
    return first_error_ctx.error_status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Return the last error
 | 
			
		||||
mbed_error_status_t mbed_get_last_error(void) 
 | 
			
		||||
mbed_error_status_t mbed_get_last_error(void)
 | 
			
		||||
{
 | 
			
		||||
    //return the last error recorded
 | 
			
		||||
    return last_error_ctx.error_status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Gets the current error count
 | 
			
		||||
int mbed_get_error_count(void) 
 | 
			
		||||
int mbed_get_error_count(void)
 | 
			
		||||
{
 | 
			
		||||
    //return the current error count
 | 
			
		||||
    return error_count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Sets a fatal error 
 | 
			
		||||
mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number) 
 | 
			
		||||
//Sets a fatal error
 | 
			
		||||
mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
 | 
			
		||||
{
 | 
			
		||||
    return handle_error(error_status, error_value, filename, line_number);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Sets a fatal error, this function is marked WEAK to be able to override this for some tests 
 | 
			
		||||
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) 
 | 
			
		||||
//Sets a fatal error, this function is marked WEAK to be able to override this for some tests
 | 
			
		||||
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
 | 
			
		||||
    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;
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //On fatal errors print the error context/report
 | 
			
		||||
    print_error_report(&last_error_ctx, error_msg);
 | 
			
		||||
    mbed_halt_system();
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    return MBED_ERROR_FAILED_OPERATION;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Register an application defined callback with error handling
 | 
			
		||||
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
 | 
			
		||||
    if ( error_hook_in != NULL )  {
 | 
			
		||||
    if (error_hook_in != NULL)  {
 | 
			
		||||
        error_hook = error_hook_in;
 | 
			
		||||
        return MBED_SUCCESS;
 | 
			
		||||
    } 
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return MBED_ERROR_INVALID_ARGUMENT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Retrieve the first error context from error log 
 | 
			
		||||
mbed_error_status_t mbed_get_first_error_info (mbed_error_ctx *error_info) 
 | 
			
		||||
//Retrieve the first error context from error log
 | 
			
		||||
mbed_error_status_t mbed_get_first_error_info(mbed_error_ctx *error_info)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(error_info, &first_error_ctx, sizeof(first_error_ctx));
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Retrieve the last error context from error log 
 | 
			
		||||
mbed_error_status_t mbed_get_last_error_info (mbed_error_ctx *error_info) 
 | 
			
		||||
//Retrieve the last error context from error log
 | 
			
		||||
mbed_error_status_t mbed_get_last_error_info(mbed_error_ctx *error_info)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(error_info, &last_error_ctx, sizeof(mbed_error_ctx));
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//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:
 | 
			
		||||
            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;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //If we are passed incorrect values return a generic system error
 | 
			
		||||
    return MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, MBED_ERROR_CODE_UNKNOWN);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -263,21 +267,21 @@ mbed_error_status_t mbed_make_error(mbed_error_type_t error_type, mbed_module_ty
 | 
			
		|||
 * @return                      0 or MBED_SUCCESS on success.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
mbed_error_status_t mbed_clear_all_errors(void) 
 | 
			
		||||
mbed_error_status_t mbed_clear_all_errors(void)
 | 
			
		||||
{
 | 
			
		||||
    mbed_error_status_t status = MBED_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Make sure we dont multiple clients resetting
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
    //Clear the error and context capturing buffer
 | 
			
		||||
    memset(&last_error_ctx, sizeof(mbed_error_ctx), 0);
 | 
			
		||||
    //reset error count to 0
 | 
			
		||||
    error_count = 0;
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED    
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
 | 
			
		||||
    status = mbed_error_hist_reset();
 | 
			
		||||
#endif
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -292,7 +296,7 @@ static void print_thread(osRtxThread_t *thread)
 | 
			
		|||
static void print_threads_info(osRtxThread_t *threads)
 | 
			
		||||
{
 | 
			
		||||
    while (threads != NULL) {
 | 
			
		||||
        print_thread( threads );
 | 
			
		||||
        print_thread(threads);
 | 
			
		||||
        threads = threads->thread_next;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -302,96 +306,96 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
 | 
			
		|||
{
 | 
			
		||||
    uint32_t error_code = MBED_GET_ERROR_CODE(ctx->error_status);
 | 
			
		||||
    uint32_t error_module = MBED_GET_ERROR_MODULE(ctx->error_status);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    mbed_error_printf("\n\n++ MbedOS Error Info ++\nError Status: 0x%X Code: %d Module: %d\nError Message: ", ctx->error_status, error_code, error_module);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    switch (error_code) {
 | 
			
		||||
        //These are errors reported by kernel handled from mbed_rtx_handlers
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_EVENT:
 | 
			
		||||
            mbed_error_printf("Kernel Error: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_THREAD_EVENT:
 | 
			
		||||
            mbed_error_printf("Thread: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_MUTEX_EVENT:
 | 
			
		||||
            mbed_error_printf("Mutex: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT:
 | 
			
		||||
            mbed_error_printf("Semaphore: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT:
 | 
			
		||||
            mbed_error_printf("MemoryPool: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT:
 | 
			
		||||
            mbed_error_printf("EventFlags: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_TIMER_EVENT:
 | 
			
		||||
            mbed_error_printf("Timer: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT:    
 | 
			
		||||
 | 
			
		||||
        case MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT:
 | 
			
		||||
            mbed_error_printf("MessageQueue: 0x%X, ", ctx->error_value);
 | 
			
		||||
            break;
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            //Nothing to do here, just print the error info down
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    mbed_error_printf(error_msg);
 | 
			
		||||
    mbed_error_printf("\nLocation: 0x%X", ctx->error_address);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED && !defined(NDEBUG)
 | 
			
		||||
    if ((NULL != ctx->error_filename[0]) && (ctx->error_line_number != 0)) {
 | 
			
		||||
        //for string, we must pass address of a ptr which has the address of the string 
 | 
			
		||||
        //for string, we must pass address of a ptr which has the address of the string
 | 
			
		||||
        mbed_error_printf("\nFile:%s+%d", ctx->error_filename, ctx->error_line_number);
 | 
			
		||||
    }
 | 
			
		||||
#endif 
 | 
			
		||||
    
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    mbed_error_printf("\nError Value: 0x%X", ctx->error_value);
 | 
			
		||||
#ifdef TARGET_CORTEX_M
 | 
			
		||||
    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);
 | 
			
		||||
    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);
 | 
			
		||||
#else
 | 
			
		||||
    //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 ", 
 | 
			
		||||
                        ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem);
 | 
			
		||||
    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);
 | 
			
		||||
#endif //TARGET_CORTEX_M
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
 | 
			
		||||
    mbed_error_printf("\nNext:");
 | 
			
		||||
    print_thread(osRtxInfo.thread.run.next);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    mbed_error_printf("\nWait:");
 | 
			
		||||
    osRtxThread_t *threads = (osRtxThread_t *)&osRtxInfo.thread.wait_list;
 | 
			
		||||
    print_threads_info(threads);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    mbed_error_printf("\nDelay:");
 | 
			
		||||
    threads = (osRtxThread_t *)&osRtxInfo.thread.delay_list;
 | 
			
		||||
    print_threads_info(threads);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    mbed_error_printf("\nIdle:");
 | 
			
		||||
    threads = (osRtxThread_t *)&osRtxInfo.thread.idle;
 | 
			
		||||
    print_threads_info(threads);
 | 
			
		||||
#endif
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    mbed_error_printf("\n-- MbedOS Error Info --\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
 | 
			
		||||
//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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Retrieve the error log count
 | 
			
		||||
int mbed_get_error_hist_count(void) 
 | 
			
		||||
int mbed_get_error_hist_count(void)
 | 
			
		||||
{
 | 
			
		||||
    return mbed_error_hist_get_count();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -402,56 +406,56 @@ mbed_error_status_t mbed_save_error_hist(const char *path)
 | 
			
		|||
    mbed_error_ctx ctx = {0};
 | 
			
		||||
    int log_count = mbed_error_hist_get_count();
 | 
			
		||||
    FILE *error_log_file = NULL;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Ensure path is valid
 | 
			
		||||
    if (path==NULL) {
 | 
			
		||||
    if (path == NULL) {
 | 
			
		||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT);
 | 
			
		||||
        goto exit;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //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);
 | 
			
		||||
        goto exit;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //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", 
 | 
			
		||||
        (unsigned int)first_error_ctx.error_status, 
 | 
			
		||||
        (unsigned int)first_error_ctx.thread_id, 
 | 
			
		||||
        (unsigned int)first_error_ctx.error_address, 
 | 
			
		||||
        (unsigned int)first_error_ctx.error_value) <= 0) {
 | 
			
		||||
    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.thread_id,
 | 
			
		||||
                (unsigned int)first_error_ctx.error_address,
 | 
			
		||||
                (unsigned int)first_error_ctx.error_value) <= 0) {
 | 
			
		||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
			
		||||
        goto exit;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    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.thread_id, 
 | 
			
		||||
        (unsigned int)last_error_ctx.error_address, 
 | 
			
		||||
        (unsigned int)last_error_ctx.error_value) <= 0) {
 | 
			
		||||
 | 
			
		||||
    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.thread_id,
 | 
			
		||||
                (unsigned int)last_error_ctx.error_address,
 | 
			
		||||
                (unsigned int)last_error_ctx.error_value) <= 0) {
 | 
			
		||||
        ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
			
		||||
        goto exit;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //Update with error log info
 | 
			
		||||
    while (--log_count >= 0) {
 | 
			
		||||
        mbed_error_hist_get(log_count, &ctx);
 | 
			
		||||
        //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", 
 | 
			
		||||
            log_count, 
 | 
			
		||||
            (unsigned int)ctx.error_status, 
 | 
			
		||||
            (unsigned int)ctx.thread_id, 
 | 
			
		||||
            (unsigned int)ctx.error_address, 
 | 
			
		||||
            (unsigned int)ctx.error_value) <= 0) {
 | 
			
		||||
        if (fprintf(error_log_file, "\n%d: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
 | 
			
		||||
                    log_count,
 | 
			
		||||
                    (unsigned int)ctx.error_status,
 | 
			
		||||
                    (unsigned int)ctx.thread_id,
 | 
			
		||||
                    (unsigned int)ctx.error_address,
 | 
			
		||||
                    (unsigned int)ctx.error_value) <= 0) {
 | 
			
		||||
            ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
 | 
			
		||||
            goto exit;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
exit:
 | 
			
		||||
    fclose(error_log_file);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -33,12 +33,12 @@ mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx)
 | 
			
		|||
    if (NULL == error_ctx) {
 | 
			
		||||
        return MBED_ERROR_INVALID_ARGUMENT;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
    error_log_count++;
 | 
			
		||||
    memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx));
 | 
			
		||||
    core_util_critical_section_exit(); 
 | 
			
		||||
    
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -48,15 +48,15 @@ mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx)
 | 
			
		|||
    if (index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
 | 
			
		||||
        return MBED_ERROR_INVALID_ARGUMENT;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
    //calculate the index where we want to pick the ctx
 | 
			
		||||
    if (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
 | 
			
		||||
        index = (error_log_count + index + 1) % MBED_CONF_PLATFORM_ERROR_HIST_SIZE;
 | 
			
		||||
    }
 | 
			
		||||
    core_util_critical_section_exit(); 
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
    memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx));
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,8 +65,8 @@ mbed_error_ctx *mbed_error_hist_get_entry(void)
 | 
			
		|||
    core_util_critical_section_enter();
 | 
			
		||||
    error_log_count++;
 | 
			
		||||
    mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE];
 | 
			
		||||
    core_util_critical_section_exit(); 
 | 
			
		||||
    
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
 | 
			
		||||
    return ctx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -77,22 +77,22 @@ mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx)
 | 
			
		|||
    }
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
    memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx));
 | 
			
		||||
    core_util_critical_section_exit(); 
 | 
			
		||||
    
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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()
 | 
			
		||||
{
 | 
			
		||||
    core_util_critical_section_enter();
 | 
			
		||||
    error_log_count = -1;
 | 
			
		||||
    core_util_critical_section_exit(); 
 | 
			
		||||
    
 | 
			
		||||
    core_util_critical_section_exit();
 | 
			
		||||
 | 
			
		||||
    return MBED_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,11 +17,11 @@
 | 
			
		|||
#define MBED_ERROR_HIST_H
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CONF_PLATFORM_ERROR_HIST_SIZE
 | 
			
		||||
    #define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  4
 | 
			
		||||
#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  4
 | 
			
		||||
#else
 | 
			
		||||
    #if MBED_CONF_PLATFORM_ERROR_HIST_SIZE == 0
 | 
			
		||||
        #define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  1
 | 
			
		||||
    #endif    
 | 
			
		||||
#if MBED_CONF_PLATFORM_ERROR_HIST_SIZE == 0
 | 
			
		||||
#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE  1
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
| 
						 | 
				
			
			@ -29,24 +29,24 @@ extern "C" {
 | 
			
		|||
#endif
 | 
			
		||||
/*
 | 
			
		||||
 * Puts/Adds an error entry into the error history list
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @param  error_ctx            pointer to the mbed_error_ctx struct with the error context
 | 
			
		||||
 * @return                      0 or MBED_SUCCESS on success.
 | 
			
		||||
 *                              MBED_ERROR_WRITE_FAILED if writing to file failed
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid 
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Reads the error entry from the error list with the specified index
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @param  index                Index of the error context to be retrieved. It starts from 0 and 0 is the oldest.
 | 
			
		||||
 * @param  error_ctx            pointer to the mbed_error_ctx struct where the error context will be filled, this should be allocated by the caller
 | 
			
		||||
 * @return                      0 or MBED_SUCCESS on success.
 | 
			
		||||
 *                              MBED_ERROR_WRITE_FAILED if writing to file failed
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid 
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -55,8 +55,8 @@ mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx);
 | 
			
		|||
/*
 | 
			
		||||
 * Gets a reference to the next error entry in the error log where in the error ctx can be filled in.
 | 
			
		||||
 * Its like reserving the next error entry to fill in the error info
 | 
			
		||||
 * 
 | 
			
		||||
 * @return                      Returns the pointer to the next error ctx entry     
 | 
			
		||||
 *
 | 
			
		||||
 * @return                      Returns the pointer to the next error ctx entry
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -64,11 +64,11 @@ mbed_error_ctx *mbed_error_hist_get_entry(void);
 | 
			
		|||
 | 
			
		||||
/*
 | 
			
		||||
 * Reads the last(latest) error entry from the error history
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @param  error_ctx            pointer to the mbed_error_ctx struct where the error context will be filled, this should be allocated by the caller
 | 
			
		||||
 * @return                      0 or MBED_SUCCESS on success.
 | 
			
		||||
 *                              MBED_ERROR_WRITE_FAILED if writing to file failed
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid 
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -76,8 +76,8 @@ mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx);
 | 
			
		|||
 | 
			
		||||
/*
 | 
			
		||||
 * Returns the number of error entries in the error history list
 | 
			
		||||
 * 
 | 
			
		||||
 * @return                      Number of entries in the history list 
 | 
			
		||||
 *
 | 
			
		||||
 * @return                      Number of entries in the history list
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -85,10 +85,10 @@ int mbed_error_hist_get_count(void);
 | 
			
		|||
 | 
			
		||||
/*
 | 
			
		||||
 * Resets the error log by resetting the number of errors to 0 and clears all previous errors in the history list
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @return                      0 or MBED_SUCCESS on success.
 | 
			
		||||
 *                              MBED_ERROR_WRITE_FAILED if writing to file failed
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid 
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -96,17 +96,17 @@ mbed_error_status_t mbed_error_hist_reset(void);
 | 
			
		|||
 | 
			
		||||
/*
 | 
			
		||||
 * Saves the error log information to a file
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @param  path                 path to the file in the filesystem
 | 
			
		||||
 * @return                      0 or MBED_SUCCESS on success.
 | 
			
		||||
 *                              MBED_ERROR_WRITE_FAILED if writing to file failed
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid 
 | 
			
		||||
 *                              MBED_ERROR_INVALID_ARGUMENT if path is not valid
 | 
			
		||||
 *
 | 
			
		||||
 * @note                        Filesystem support is required in order for this function to work.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
mbed_error_status_t mbed_save_error_hist(const char *path);    
 | 
			
		||||
    
 | 
			
		||||
mbed_error_status_t mbed_save_error_hist(const char *path);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,11 +25,13 @@
 | 
			
		|||
#if DEVICE_SEMIHOST
 | 
			
		||||
 | 
			
		||||
// 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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int mbed_interface_reset(void) {
 | 
			
		||||
int mbed_interface_reset(void)
 | 
			
		||||
{
 | 
			
		||||
    if (mbed_interface_connected()) {
 | 
			
		||||
        semihost_reset();
 | 
			
		||||
        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()) {
 | 
			
		||||
        return semihost_uid(uid); // Returns 0 if successful, -1 on failure
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -47,11 +50,13 @@ WEAK int mbed_interface_uid(char *uid) {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int mbed_interface_disconnect(void) {
 | 
			
		||||
int mbed_interface_disconnect(void)
 | 
			
		||||
{
 | 
			
		||||
    int res;
 | 
			
		||||
    if (mbed_interface_connected()) {
 | 
			
		||||
        if ((res = semihost_disabledebug()) != 0)
 | 
			
		||||
        if ((res = semihost_disabledebug()) != 0) {
 | 
			
		||||
            return res;
 | 
			
		||||
        }
 | 
			
		||||
        while (mbed_interface_connected());
 | 
			
		||||
        return 0;
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -59,11 +64,13 @@ int mbed_interface_disconnect(void) {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int mbed_interface_powerdown(void) {
 | 
			
		||||
int mbed_interface_powerdown(void)
 | 
			
		||||
{
 | 
			
		||||
    int res;
 | 
			
		||||
    if (mbed_interface_connected()) {
 | 
			
		||||
        if ((res = semihost_powerdown()) != 0)
 | 
			
		||||
        if ((res = semihost_powerdown()) != 0) {
 | 
			
		||||
            return res;
 | 
			
		||||
        }
 | 
			
		||||
        while (mbed_interface_connected());
 | 
			
		||||
        return 0;
 | 
			
		||||
    } 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."
 | 
			
		||||
    "For system reset funcionality use system_reset()")
 | 
			
		||||
void mbed_reset(void) {
 | 
			
		||||
                      "For system reset funcionality use system_reset()")
 | 
			
		||||
void mbed_reset(void)
 | 
			
		||||
{
 | 
			
		||||
    mbed_interface_reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
WEAK int mbed_uid(char *uid) {
 | 
			
		||||
WEAK int mbed_uid(char *uid)
 | 
			
		||||
{
 | 
			
		||||
    return mbed_interface_uid(uid);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
WEAK void mbed_mac_address(char *mac) {
 | 
			
		||||
WEAK void mbed_mac_address(char *mac)
 | 
			
		||||
{
 | 
			
		||||
#if DEVICE_SEMIHOST
 | 
			
		||||
    char uid[DEVICE_ID_LENGTH + 1];
 | 
			
		||||
    int i;
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +103,7 @@ WEAK void mbed_mac_address(char *mac) {
 | 
			
		|||
#if defined(DEVICE_MAC_OFFSET)
 | 
			
		||||
        p += DEVICE_MAC_OFFSET;
 | 
			
		||||
#endif
 | 
			
		||||
        for (i=0; i<6; i++) {
 | 
			
		||||
        for (i = 0; i < 6; i++) {
 | 
			
		||||
            int byte;
 | 
			
		||||
            sscanf(p, "%2x", &byte);
 | 
			
		||||
            mac[i] = byte;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -135,7 +135,7 @@ void mbed_die(void);
 | 
			
		|||
 * @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
 | 
			
		||||
 * but uses a va_list.
 | 
			
		||||
| 
						 | 
				
			
			@ -146,7 +146,7 @@ void mbed_error_printf(const char* format, ...);
 | 
			
		|||
 * @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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,7 +41,8 @@ static SingletonPtr<PlatformMutex> mem_trace_mutex;
 | 
			
		|||
 * 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -57,7 +58,8 @@ void mbed_mem_trace_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 (TRACE_FIRST_LOCK()) {
 | 
			
		||||
            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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 (TRACE_FIRST_LOCK()) {
 | 
			
		||||
            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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 (TRACE_FIRST_LOCK()) {
 | 
			
		||||
            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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mbed_mem_trace_free(void *ptr, void *caller) {
 | 
			
		||||
void mbed_mem_trace_free(void *ptr, void *caller)
 | 
			
		||||
{
 | 
			
		||||
    if (mem_trace_cb) {
 | 
			
		||||
        if (TRACE_FIRST_LOCK()) {
 | 
			
		||||
            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;
 | 
			
		||||
    size_t temp_s1, temp_s2;
 | 
			
		||||
    void *temp_ptr;
 | 
			
		||||
 | 
			
		||||
    va_start(va, caller);
 | 
			
		||||
    switch(op) {
 | 
			
		||||
    switch (op) {
 | 
			
		||||
        case MBED_MEM_TRACE_MALLOC:
 | 
			
		||||
            temp_s1 = va_arg(va, size_t);
 | 
			
		||||
            printf(MBED_MEM_DEFAULT_TRACER_PREFIX "m:%p;%p-%u\n", res, caller, temp_s1);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case MBED_MEM_TRACE_REALLOC:
 | 
			
		||||
            temp_ptr = va_arg(va, void*);
 | 
			
		||||
            temp_ptr = va_arg(va, void *);
 | 
			
		||||
            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);
 | 
			
		||||
            break;
 | 
			
		||||
| 
						 | 
				
			
			@ -117,7 +123,7 @@ void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...) {
 | 
			
		|||
            break;
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,7 +63,7 @@ enum {
 | 
			
		|||
 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
 | 
			
		||||
 * - 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).
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@
 | 
			
		|||
#define SECONDS_BY_MINUTES 60
 | 
			
		||||
#define MINUTES_BY_HOUR 60
 | 
			
		||||
#define SECONDS_BY_HOUR (SECONDS_BY_MINUTES * MINUTES_BY_HOUR)
 | 
			
		||||
#define HOURS_BY_DAY 24 
 | 
			
		||||
#define HOURS_BY_DAY 24
 | 
			
		||||
#define SECONDS_BY_DAY (SECONDS_BY_HOUR * HOURS_BY_DAY)
 | 
			
		||||
#define LAST_VALID_YEAR 206
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -29,48 +29,49 @@
 | 
			
		|||
#define EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT 3133695  // 6th of February 1970 at 06:28:15
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 2 dimensional array containing the number of seconds elapsed before a given 
 | 
			
		||||
 * 2 dimensional array containing the number of seconds elapsed before a given
 | 
			
		||||
 * month.
 | 
			
		||||
 * The second index map to the month while the first map to the type of year:
 | 
			
		||||
 *   - 0: non leap year 
 | 
			
		||||
 *   - 0: non leap year
 | 
			
		||||
 *   - 1: leap year
 | 
			
		||||
 */
 | 
			
		||||
static const uint32_t seconds_before_month[2][12] = {
 | 
			
		||||
    {
 | 
			
		||||
        0,
 | 
			
		||||
        31 * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28 + 31) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28 + 31 + 30) * 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 + 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 + 31) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28) *SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28 + 31) *SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28 + 31 + 30) *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 + 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 + 31) *SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        0,
 | 
			
		||||
        31 * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29 + 31) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29 + 31 + 30) * 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 + 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 + 31) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29) *SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29 + 31) *SECONDS_BY_DAY,
 | 
			
		||||
        (31 + 29 + 31 + 30) *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 + 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 + 31) *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) {
 | 
			
		||||
    /* 
 | 
			
		||||
     * since in practice, the value manipulated by this algorithm lie in the 
 | 
			
		||||
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
 | 
			
		||||
     * range: [70 : 206] the algorithm can be reduced to: year % 4 with exception for 200 (year 2100 is not leap year).
 | 
			
		||||
     * The algorithm valid over the full range of value is: 
 | 
			
		||||
     * The algorithm valid over the full range of value is:
 | 
			
		||||
 | 
			
		||||
        year = 1900 + year;
 | 
			
		||||
        if (year % 4) {
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +83,7 @@ bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support) {
 | 
			
		|||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
 | 
			
		||||
     */ 
 | 
			
		||||
     */
 | 
			
		||||
    if (leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT && year == 200) {
 | 
			
		||||
        return false; // 2100 is not a 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -111,12 +113,12 @@ bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_suppor
 | 
			
		|||
    /* Check if we are within valid range. */
 | 
			
		||||
    if (time->tm_year == LAST_VALID_YEAR) {
 | 
			
		||||
        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)) {
 | 
			
		||||
        return false;
 | 
			
		||||
                (leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (time->tm_year > 70) { 
 | 
			
		||||
    if (time->tm_year > 70) {
 | 
			
		||||
        /* Valid in the range [70:206]. */
 | 
			
		||||
        uint32_t count_of_leap_days = ((time->tm_year - 1) / 4) - (70 / 4);
 | 
			
		||||
        if (leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT) {
 | 
			
		||||
| 
						 | 
				
			
			@ -133,7 +135,8 @@ bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_suppor
 | 
			
		|||
    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) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -154,7 +157,7 @@ bool _rtc_localtime(time_t timestamp, struct tm* time_info, rtc_leap_year_suppor
 | 
			
		|||
 | 
			
		||||
    /* Years start at 70. */
 | 
			
		||||
    time_info->tm_year = 70;
 | 
			
		||||
    while (true) { 
 | 
			
		||||
    while (true) {
 | 
			
		||||
        if (_rtc_is_leap_year(time_info->tm_year, leap_year_support) && seconds >= 366) {
 | 
			
		||||
            ++time_info->tm_year;
 | 
			
		||||
            seconds -= 366;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 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.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -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 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);
 | 
			
		||||
 | 
			
		||||
/** @}*/
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -170,7 +170,7 @@ static inline void sleep(void)
 | 
			
		|||
/** Send the microcontroller to deep sleep
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated
 | 
			
		||||
 * Do not use this function. Applications should use sleep() API which puts the system in deepsleep mode if supported. 
 | 
			
		||||
 * Do not use this function. Applications should use sleep() API which puts the system in deepsleep mode if supported.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function can be a noop if not implemented by the platform.
 | 
			
		||||
 * @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined)
 | 
			
		||||
| 
						 | 
				
			
			@ -206,7 +206,7 @@ static inline void system_reset(void)
 | 
			
		|||
{
 | 
			
		||||
    NVIC_SystemReset();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
/** Provides the time spent in sleep mode since boot.
 | 
			
		||||
 *
 | 
			
		||||
 *  @return  Time spent in sleep
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -111,10 +111,11 @@ static SingletonPtr<PlatformMutex> filehandle_mutex;
 | 
			
		|||
namespace mbed {
 | 
			
		||||
void mbed_set_unbuffered_stream(std::FILE *_file);
 | 
			
		||||
 | 
			
		||||
void remove_filehandle(FileHandle *file) {
 | 
			
		||||
void remove_filehandle(FileHandle *file)
 | 
			
		||||
{
 | 
			
		||||
    filehandle_mutex->lock();
 | 
			
		||||
    /* 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) {
 | 
			
		||||
            filehandles[fh_i] = NULL;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -137,23 +138,30 @@ public:
 | 
			
		|||
    DirectSerial(PinName tx, PinName rx, int baud);
 | 
			
		||||
    virtual ssize_t write(const 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;
 | 
			
		||||
    }
 | 
			
		||||
    virtual off_t size() {
 | 
			
		||||
    virtual off_t size()
 | 
			
		||||
    {
 | 
			
		||||
        return -EINVAL;
 | 
			
		||||
    }
 | 
			
		||||
    virtual int isatty() {
 | 
			
		||||
    virtual int isatty()
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    virtual int close() {
 | 
			
		||||
    virtual int close()
 | 
			
		||||
    {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    virtual short poll(short events) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) {
 | 
			
		||||
    if (stdio_uart_inited) return;
 | 
			
		||||
DirectSerial::DirectSerial(PinName tx, PinName rx, int baud)
 | 
			
		||||
{
 | 
			
		||||
    if (stdio_uart_inited) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    serial_init(&stdio_uart, tx, rx);
 | 
			
		||||
    serial_baud(&stdio_uart, baud);
 | 
			
		||||
#if   CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
 | 
			
		||||
| 
						 | 
				
			
			@ -165,7 +173,8 @@ DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) {
 | 
			
		|||
#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);
 | 
			
		||||
    for (size_t i = 0; i < size; i++) {
 | 
			
		||||
        serial_putc(&stdio_uart, buf[i]);
 | 
			
		||||
| 
						 | 
				
			
			@ -173,7 +182,8 @@ ssize_t DirectSerial::write(const void *buffer, size_t 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);
 | 
			
		||||
    if (size == 0) {
 | 
			
		||||
        return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -182,7 +192,8 @@ ssize_t DirectSerial::read(void *buffer, size_t size) {
 | 
			
		|||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
short DirectSerial::poll(short events) const {
 | 
			
		||||
short DirectSerial::poll(short events) const
 | 
			
		||||
{
 | 
			
		||||
    short revents = 0;
 | 
			
		||||
    if ((events & POLLIN) && serial_readable(&stdio_uart)) {
 | 
			
		||||
        revents |= POLLIN;
 | 
			
		||||
| 
						 | 
				
			
			@ -198,18 +209,32 @@ class Sink : public FileHandle {
 | 
			
		|||
public:
 | 
			
		||||
    virtual ssize_t write(const 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 size() { return -EINVAL; }
 | 
			
		||||
    virtual int isatty() { return true; }
 | 
			
		||||
    virtual int close() { return 0; }
 | 
			
		||||
    virtual off_t seek(off_t offset, int whence = SEEK_SET)
 | 
			
		||||
    {
 | 
			
		||||
        return ESPIPE;
 | 
			
		||||
    }
 | 
			
		||||
    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
 | 
			
		||||
    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
 | 
			
		||||
    // the 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MBED_WEAK FileHandle* mbed::mbed_override_console(int fd)
 | 
			
		||||
MBED_WEAK FileHandle *mbed::mbed_override_console(int fd)
 | 
			
		||||
{
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static FileHandle* default_console()
 | 
			
		||||
static FileHandle *default_console()
 | 
			
		||||
{
 | 
			
		||||
#if DEVICE_SERIAL
 | 
			
		||||
#  if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL
 | 
			
		||||
    static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 | 
			
		||||
#   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
 | 
			
		||||
        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
 | 
			
		||||
        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
 | 
			
		||||
#  else
 | 
			
		||||
    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 */
 | 
			
		||||
static FileHandle* get_console(int fd) {
 | 
			
		||||
static FileHandle *get_console(int fd)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fh = mbed_override_console(fd);
 | 
			
		||||
    if (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 */
 | 
			
		||||
static FileHandle* get_fhc(int fd) {
 | 
			
		||||
static FileHandle *get_fhc(int fd)
 | 
			
		||||
{
 | 
			
		||||
    if (fd >= OPEN_MAX) {
 | 
			
		||||
        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
 | 
			
		||||
 *              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;
 | 
			
		||||
    // Free file handle
 | 
			
		||||
    filehandles[filehandle_idx] = NULL;
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int openflags_to_posix(int openflags) {
 | 
			
		||||
static inline int openflags_to_posix(int openflags)
 | 
			
		||||
{
 | 
			
		||||
    int posix = openflags;
 | 
			
		||||
#ifdef __ARMCC_VERSION
 | 
			
		||||
    if (openflags & OPEN_PLUS) {
 | 
			
		||||
        posix = O_RDWR;
 | 
			
		||||
    } else if(openflags & OPEN_W) {
 | 
			
		||||
    } else if (openflags & OPEN_W) {
 | 
			
		||||
        posix = O_WRONLY;
 | 
			
		||||
    } else if(openflags & OPEN_A) {
 | 
			
		||||
        posix = O_WRONLY|O_APPEND;
 | 
			
		||||
    } else if (openflags & OPEN_A) {
 | 
			
		||||
        posix = O_WRONLY | O_APPEND;
 | 
			
		||||
    } else {
 | 
			
		||||
        posix = O_RDONLY;
 | 
			
		||||
    }
 | 
			
		||||
    /* 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;
 | 
			
		||||
    }
 | 
			
		||||
    /* w and w+ truncate */
 | 
			
		||||
| 
						 | 
				
			
			@ -310,26 +339,41 @@ static inline int openflags_to_posix(int openflags) {
 | 
			
		|||
    }
 | 
			
		||||
#elif defined(__ICCARM__)
 | 
			
		||||
    switch (openflags & _LLIO_RDWRMASK) {
 | 
			
		||||
        case _LLIO_RDONLY: posix = O_RDONLY; break;
 | 
			
		||||
        case _LLIO_WRONLY: posix = O_WRONLY; break;
 | 
			
		||||
        case _LLIO_RDWR  : posix = O_RDWR  ; break;
 | 
			
		||||
        case _LLIO_RDONLY:
 | 
			
		||||
            posix = O_RDONLY;
 | 
			
		||||
            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)
 | 
			
		||||
    posix &= ~O_BINARY;
 | 
			
		||||
#endif
 | 
			
		||||
    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
 | 
			
		||||
    filehandle_mutex->lock();
 | 
			
		||||
    int fh_i;
 | 
			
		||||
    for (fh_i = 3; fh_i < OPEN_MAX; fh_i++) {
 | 
			
		||||
        /* Take a next free filehandle slot available. */
 | 
			
		||||
        if (filehandles[fh_i] == NULL) break;
 | 
			
		||||
        if (filehandles[fh_i] == NULL) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (fh_i >= OPEN_MAX) {
 | 
			
		||||
        /* Too many file handles have been opened */
 | 
			
		||||
| 
						 | 
				
			
			@ -343,7 +387,8 @@ static int reserve_filehandle() {
 | 
			
		|||
    return fh_i;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int mbed::bind_to_fd(FileHandle *fh) {
 | 
			
		||||
int mbed::bind_to_fd(FileHandle *fh)
 | 
			
		||||
{
 | 
			
		||||
    int fildes = reserve_filehandle();
 | 
			
		||||
    if (fildes < 0) {
 | 
			
		||||
        return fildes;
 | 
			
		||||
| 
						 | 
				
			
			@ -356,7 +401,8 @@ int mbed::bind_to_fd(FileHandle *fh) {
 | 
			
		|||
    return fildes;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int unbind_from_fd(int fd, FileHandle *fh) {
 | 
			
		||||
static int unbind_from_fd(int fd, FileHandle *fh)
 | 
			
		||||
{
 | 
			
		||||
    if (filehandles[fd] == fh) {
 | 
			
		||||
        filehandles[fd] = NULL;
 | 
			
		||||
        return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -368,7 +414,7 @@ static int unbind_from_fd(int fd, FileHandle *fh) {
 | 
			
		|||
 | 
			
		||||
#ifndef __IAR_SYSTEMS_ICC__
 | 
			
		||||
/* 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.
 | 
			
		||||
    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()
 | 
			
		||||
 *
 | 
			
		||||
 * @return
 | 
			
		||||
 *  On success, a valid FILEHANDLE is returned.
 | 
			
		||||
 *  On failure, -1 is returned and errno is set to an appropriate value e.g.
 | 
			
		||||
 *   ENOENT	    file not found (default errno setting)
 | 
			
		||||
 *	 EMFILE		the maximum number of open files was exceeded.
 | 
			
		||||
 *   ENOENT     file not found (default errno setting)
 | 
			
		||||
 *   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(MBED_CONF_RTOS_PRESENT)
 | 
			
		||||
    // 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));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int open(const char *name, int oflag, ...) {
 | 
			
		||||
extern "C" int open(const char *name, int oflag, ...)
 | 
			
		||||
{
 | 
			
		||||
    int fildes = reserve_filehandle();
 | 
			
		||||
    if (fildes < 0) {
 | 
			
		||||
        return fildes;
 | 
			
		||||
| 
						 | 
				
			
			@ -499,12 +547,14 @@ extern "C" int open(const char *name, int oflag, ...) {
 | 
			
		|||
    return fildes;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int PREFIX(_close)(FILEHANDLE fh) {
 | 
			
		||||
extern "C" int PREFIX(_close)(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    return close(fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int close(int fildes) {
 | 
			
		||||
    FileHandle* fhc = get_fhc(fildes);
 | 
			
		||||
extern "C" int close(int fildes)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    filehandles[fildes] = NULL;
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        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
 | 
			
		||||
    return isatty(fd);
 | 
			
		||||
#elif MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
 | 
			
		||||
| 
						 | 
				
			
			@ -531,9 +582,11 @@ static bool convert_crlf(int fd) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
 | 
			
		||||
| 
						 | 
				
			
			@ -610,9 +663,10 @@ finish:
 | 
			
		|||
#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) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        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)
 | 
			
		||||
extern "C" void PREFIX(_exit)(int return_code) {
 | 
			
		||||
    while(1) {}
 | 
			
		||||
extern "C" void PREFIX(_exit)(int return_code)
 | 
			
		||||
{
 | 
			
		||||
    while (1) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void _ttywrch(int ch) {
 | 
			
		||||
extern "C" void _ttywrch(int ch)
 | 
			
		||||
{
 | 
			
		||||
    char c = ch;
 | 
			
		||||
    write(STDOUT_FILENO, &c, 1);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
#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;
 | 
			
		||||
            }
 | 
			
		||||
            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;
 | 
			
		||||
                *buffer = '\n';
 | 
			
		||||
                break;
 | 
			
		||||
| 
						 | 
				
			
			@ -700,9 +758,10 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
 | 
			
		|||
#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) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -727,8 +786,9 @@ extern "C" int _isatty(FILEHANDLE fh)
 | 
			
		|||
    return isatty(fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int isatty(int fildes) {
 | 
			
		||||
    FileHandle* fhc = get_fhc(fildes);
 | 
			
		||||
extern "C" int isatty(int fildes)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -765,8 +825,9 @@ int _lseek(FILEHANDLE fh, int offset, int whence)
 | 
			
		|||
    return off;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" off_t lseek(int fildes, off_t offset, int whence) {
 | 
			
		||||
    FileHandle* fhc = get_fhc(fildes);
 | 
			
		||||
extern "C" off_t lseek(int fildes, off_t offset, int whence)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -781,13 +842,15 @@ extern "C" off_t lseek(int fildes, off_t offset, int whence) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
#ifdef __ARMCC_VERSION
 | 
			
		||||
extern "C" int PREFIX(_ensure)(FILEHANDLE fh) {
 | 
			
		||||
extern "C" int PREFIX(_ensure)(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    return fsync(fh);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
extern "C" int fsync(int fildes) {
 | 
			
		||||
    FileHandle* fhc = get_fhc(fildes);
 | 
			
		||||
extern "C" int fsync(int fildes)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -803,8 +866,9 @@ extern "C" int fsync(int fildes) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
#ifdef __ARMCC_VERSION
 | 
			
		||||
extern "C" long PREFIX(_flen)(FILEHANDLE fh) {
 | 
			
		||||
    FileHandle* fhc = get_fhc(fh);
 | 
			
		||||
extern "C" long PREFIX(_flen)(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fh);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -837,7 +901,8 @@ extern "C" MBED_WEAK __value_in_regs struct __initial_stackheap _mbed_user_setup
 | 
			
		|||
    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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -845,13 +910,15 @@ extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uin
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
#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);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
extern "C" int fstat(int fildes, struct stat *st) {
 | 
			
		||||
    FileHandle* fhc = get_fhc(fildes);
 | 
			
		||||
extern "C" int fstat(int fildes, struct stat *st)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
        return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -862,7 +929,8 @@ extern "C" int fstat(int fildes, struct stat *st) {
 | 
			
		|||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int fcntl(int fildes, int cmd, ...) {
 | 
			
		||||
extern "C" int fcntl(int fildes, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
| 
						 | 
				
			
			@ -919,7 +987,8 @@ extern "C" int poll(struct pollfd fds[], nfds_t nfds, int timeout)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
namespace std {
 | 
			
		||||
extern "C" int remove(const char *path) {
 | 
			
		||||
extern "C" int remove(const char *path)
 | 
			
		||||
{
 | 
			
		||||
    FilePath fp(path);
 | 
			
		||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
			
		||||
    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 fpNew(newname);
 | 
			
		||||
    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;
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" FILE *tmpfile() {
 | 
			
		||||
extern "C" FILE *tmpfile()
 | 
			
		||||
{
 | 
			
		||||
    errno = EBADF;
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
} // namespace std
 | 
			
		||||
 | 
			
		||||
#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;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
extern "C" DIR *opendir(const char *path) {
 | 
			
		||||
extern "C" DIR *opendir(const char *path)
 | 
			
		||||
{
 | 
			
		||||
    FilePath fp(path);
 | 
			
		||||
    FileSystemHandle* fs = fp.fileSystem();
 | 
			
		||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
			
		||||
    if (fs == NULL) {
 | 
			
		||||
        errno = ENODEV;
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -997,7 +1071,8 @@ extern "C" DIR *opendir(const char *path) {
 | 
			
		|||
    return dir;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" struct dirent *readdir(DIR *dir) {
 | 
			
		||||
extern "C" struct dirent *readdir(DIR *dir)
 | 
			
		||||
{
 | 
			
		||||
    static struct dirent ent;
 | 
			
		||||
    int err = dir->read(&ent);
 | 
			
		||||
    if (err < 1) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1010,7 +1085,8 @@ extern "C" struct dirent *readdir(DIR *dir) {
 | 
			
		|||
    return &ent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int closedir(DIR *dir) {
 | 
			
		||||
extern "C" int closedir(DIR *dir)
 | 
			
		||||
{
 | 
			
		||||
    int err = dir->close();
 | 
			
		||||
    if (err < 0) {
 | 
			
		||||
        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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" off_t telldir(DIR *dir) {
 | 
			
		||||
extern "C" off_t telldir(DIR *dir)
 | 
			
		||||
{
 | 
			
		||||
    return dir->tell();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void seekdir(DIR *dir, off_t off) {
 | 
			
		||||
extern "C" void seekdir(DIR *dir, off_t 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);
 | 
			
		||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
			
		||||
    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);
 | 
			
		||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
			
		||||
    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);
 | 
			
		||||
    FileSystemHandle *fs = fp.fileSystem();
 | 
			
		||||
    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 */
 | 
			
		||||
#include "mbed_error.h"
 | 
			
		||||
namespace __gnu_cxx {
 | 
			
		||||
    void __verbose_terminate_handler() {
 | 
			
		||||
        MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_CLIB_EXCEPTION),"Exception", 0);
 | 
			
		||||
    }
 | 
			
		||||
void __verbose_terminate_handler()
 | 
			
		||||
{
 | 
			
		||||
    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)
 | 
			
		||||
{
 | 
			
		||||
    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_STM32L4               targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L4/l4_retarget.c
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
// Linker defined symbol used by _sbrk to indicate where heap should start.
 | 
			
		||||
extern "C" uint32_t __end__;
 | 
			
		||||
// Weak attribute allows user to override, e.g. to use external RAM for dynamic memory.
 | 
			
		||||
extern "C" WEAK caddr_t _sbrk(int incr) {
 | 
			
		||||
    static unsigned char* heap = (unsigned char*)&__end__;
 | 
			
		||||
    unsigned char*        prev_heap = heap;
 | 
			
		||||
    unsigned char*        new_heap = heap + incr;
 | 
			
		||||
extern "C" WEAK caddr_t _sbrk(int incr)
 | 
			
		||||
{
 | 
			
		||||
    static unsigned char *heap = (unsigned char *)&__end__;
 | 
			
		||||
    unsigned char        *prev_heap = heap;
 | 
			
		||||
    unsigned char        *new_heap = heap + incr;
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
    if (new_heap >= (unsigned char*)__get_MSP()) {
 | 
			
		||||
    if (new_heap >= (unsigned char *)__get_MSP()) {
 | 
			
		||||
#endif
 | 
			
		||||
        errno = ENOMEM;
 | 
			
		||||
        return (caddr_t)-1;
 | 
			
		||||
        return (caddr_t) -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Additional heap checking if set
 | 
			
		||||
    if (mbed_heap_size && (new_heap >= mbed_heap_start + mbed_heap_size)) {
 | 
			
		||||
        errno = ENOMEM;
 | 
			
		||||
        return (caddr_t)-1;
 | 
			
		||||
        return (caddr_t) -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    heap = new_heap;
 | 
			
		||||
| 
						 | 
				
			
			@ -1154,10 +1240,12 @@ extern "C" WEAK caddr_t _sbrk(int incr) {
 | 
			
		|||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(TOOLCHAIN_GCC_ARM) || defined(TOOLCHAIN_GCC_CR)
 | 
			
		||||
extern "C" void _exit(int return_code) {
 | 
			
		||||
extern "C" void _exit(int return_code)
 | 
			
		||||
{
 | 
			
		||||
#else
 | 
			
		||||
namespace std {
 | 
			
		||||
extern "C" void exit(int return_code) {
 | 
			
		||||
extern "C" void exit(int return_code)
 | 
			
		||||
{
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if DEVICE_STDIO_MESSAGES
 | 
			
		||||
| 
						 | 
				
			
			@ -1191,16 +1279,19 @@ extern "C" void exit(int return_code) {
 | 
			
		|||
// More informations about this topic for ARMCC here:
 | 
			
		||||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/6449.html
 | 
			
		||||
extern "C" {
 | 
			
		||||
int __aeabi_atexit(void *object, void (*dtor)(void* /*this*/), void *handle) {
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
    int __aeabi_atexit(void *object, void (*dtor)(void * /*this*/), void *handle)
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
int __cxa_atexit(void (*dtor)(void* /*this*/), void *object, void *handle) {
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
    int __cxa_atexit(void (*dtor)(void * /*this*/), void *object, void *handle)
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
void __cxa_finalize(void *handle) {
 | 
			
		||||
}
 | 
			
		||||
    void __cxa_finalize(void *handle)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
} // end of extern "C"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1216,25 +1307,27 @@ void __cxa_finalize(void *handle) {
 | 
			
		|||
 *
 | 
			
		||||
 * To overcome this limitation, exit and atexit are overriden here.
 | 
			
		||||
 */
 | 
			
		||||
extern "C"{
 | 
			
		||||
extern "C" {
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Retarget of exit for GCC.
 | 
			
		||||
 * @details Unlike the standard version, this function doesn't call any function
 | 
			
		||||
 * registered with atexit before calling _exit.
 | 
			
		||||
 */
 | 
			
		||||
void __wrap_exit(int return_code) {
 | 
			
		||||
    _exit(return_code);
 | 
			
		||||
}
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief Retarget of exit for GCC.
 | 
			
		||||
     * @details Unlike the standard version, this function doesn't call any function
 | 
			
		||||
     * registered with atexit before calling _exit.
 | 
			
		||||
     */
 | 
			
		||||
    void __wrap_exit(int return_code)
 | 
			
		||||
    {
 | 
			
		||||
        _exit(return_code);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Retarget atexit from GCC.
 | 
			
		||||
 * @details This function will always fail and never register any handler to be
 | 
			
		||||
 * called at exit.
 | 
			
		||||
 */
 | 
			
		||||
int __wrap_atexit(void (*func)()) {
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief Retarget atexit from GCC.
 | 
			
		||||
     * @details This function will always fail and never register any handler to be
 | 
			
		||||
     * called at exit.
 | 
			
		||||
     */
 | 
			
		||||
    int __wrap_atexit(void (*func)())
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1244,20 +1337,22 @@ int __wrap_atexit(void (*func)()) {
 | 
			
		|||
 | 
			
		||||
namespace mbed {
 | 
			
		||||
 | 
			
		||||
void mbed_set_unbuffered_stream(std::FILE *_file) {
 | 
			
		||||
void mbed_set_unbuffered_stream(std::FILE *_file)
 | 
			
		||||
{
 | 
			
		||||
#if defined (__ICCARM__)
 | 
			
		||||
    char buf[2];
 | 
			
		||||
    std::setvbuf(_file,buf,_IONBF,NULL);
 | 
			
		||||
    std::setvbuf(_file, buf, _IONBF, NULL);
 | 
			
		||||
#else
 | 
			
		||||
    setbuf(_file, NULL);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int mbed_getc(std::FILE *_file){
 | 
			
		||||
int mbed_getc(std::FILE *_file)
 | 
			
		||||
{
 | 
			
		||||
#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ < 8000000)
 | 
			
		||||
    /*This is only valid for unbuffered streams*/
 | 
			
		||||
    int res = std::fgetc(_file);
 | 
			
		||||
    if (res>=0){
 | 
			
		||||
    if (res >= 0) {
 | 
			
		||||
        _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
 | 
			
		||||
        _file->_Rend = _file->_Wend;
 | 
			
		||||
        _file->_Next = _file->_Wend;
 | 
			
		||||
| 
						 | 
				
			
			@ -1268,18 +1363,19 @@ int mbed_getc(std::FILE *_file){
 | 
			
		|||
#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)
 | 
			
		||||
    /*This is only valid for unbuffered streams*/
 | 
			
		||||
    char *str = fgets(s,size,_file);
 | 
			
		||||
    if (str!=NULL){
 | 
			
		||||
    char *str = fgets(s, size, _file);
 | 
			
		||||
    if (str != NULL) {
 | 
			
		||||
        _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
 | 
			
		||||
        _file->_Rend = _file->_Wend;
 | 
			
		||||
        _file->_Next = _file->_Wend;
 | 
			
		||||
    }
 | 
			
		||||
    return str;
 | 
			
		||||
#else
 | 
			
		||||
    return std::fgets(s,size,_file);
 | 
			
		||||
    return std::fgets(s, size, _file);
 | 
			
		||||
#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) {}
 | 
			
		||||
#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ >= 8000000)
 | 
			
		||||
#pragma section="__iar_tls$$DATA"
 | 
			
		||||
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");
 | 
			
		||||
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");
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#elif defined(__CC_ARM)
 | 
			
		||||
| 
						 | 
				
			
			@ -1307,27 +1404,27 @@ extern "C" WEAK void *__aeabi_read_tp (void) {
 | 
			
		|||
#elif defined (__GNUC__)
 | 
			
		||||
struct _reent;
 | 
			
		||||
// 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_unlock( 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_malloc_lock(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_unlock(struct _reent *_r) {}
 | 
			
		||||
 | 
			
		||||
extern "C" void __malloc_lock( struct _reent *_r )
 | 
			
		||||
extern "C" void __malloc_lock(struct _reent *_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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void __env_lock( struct _reent *_r )
 | 
			
		||||
extern "C" void __env_lock(struct _reent *_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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
// instead of malloc()/free() as the caller address would point to wrappers,
 | 
			
		||||
// not the caller of "new" or "delete".
 | 
			
		||||
extern "C" void* malloc_wrapper(size_t size, const void* caller);
 | 
			
		||||
extern "C" void free_wrapper(void *ptr, const void* caller);
 | 
			
		||||
    
 | 
			
		||||
void *operator new(std::size_t count)
 | 
			
		||||
extern "C" void *malloc_wrapper(size_t size, const void *caller);
 | 
			
		||||
extern "C" void free_wrapper(void *ptr, const void *caller);
 | 
			
		||||
 | 
			
		||||
void *operator new (std::size_t count)
 | 
			
		||||
{
 | 
			
		||||
    void *buffer = malloc_wrapper(count, MBED_CALLER_ADDR());
 | 
			
		||||
    if (NULL == buffer) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1401,17 +1498,17 @@ void *operator new[](std::size_t count)
 | 
			
		|||
    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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void operator delete(void *ptr)
 | 
			
		||||
void operator delete (void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    free_wrapper(ptr, MBED_CALLER_ADDR());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1424,10 +1521,10 @@ void operator delete[](void *ptr)
 | 
			
		|||
 | 
			
		||||
#include <reent.h>
 | 
			
		||||
 | 
			
		||||
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 *malloc_wrapper(struct _reent *r, size_t size, 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());
 | 
			
		||||
    if (NULL == buffer) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1445,17 +1542,17 @@ void *operator new[](std::size_t count)
 | 
			
		|||
    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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void operator delete(void *ptr)
 | 
			
		||||
void operator delete (void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    free_wrapper(_REENT, ptr, MBED_CALLER_ADDR());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1467,7 +1564,7 @@ void operator delete[](void *ptr)
 | 
			
		|||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
void *operator new(std::size_t count)
 | 
			
		||||
void *operator new (std::size_t count)
 | 
			
		||||
{
 | 
			
		||||
    void *buffer = malloc(count);
 | 
			
		||||
    if (NULL == buffer) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1485,17 +1582,17 @@ void *operator new[](std::size_t count)
 | 
			
		|||
    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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void operator delete(void *ptr)
 | 
			
		||||
void operator delete (void *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
 | 
			
		||||
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 = {
 | 
			
		||||
        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
 | 
			
		||||
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 = {
 | 
			
		||||
        1000000,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,7 +108,7 @@ class DirHandle;
 | 
			
		|||
 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
 | 
			
		||||
 * @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.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -130,7 +130,7 @@ FileHandle* mbed_target_override_console(int fd);
 | 
			
		|||
 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
 | 
			
		||||
 * @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
 | 
			
		||||
 */
 | 
			
		||||
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
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -515,9 +515,9 @@ extern "C" {
 | 
			
		|||
    int open(const char *path, int oflag, ...);
 | 
			
		||||
#ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
 | 
			
		||||
#if __cplusplus
 | 
			
		||||
    std::FILE* fdopen(int fildes, const char *mode);
 | 
			
		||||
    std::FILE *fdopen(int fildes, const char *mode);
 | 
			
		||||
#else
 | 
			
		||||
    FILE* fdopen(int fildes, const char *mode);
 | 
			
		||||
    FILE *fdopen(int fildes, const char *mode);
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
    ssize_t write(int fildes, const void *buf, size_t nbyte);
 | 
			
		||||
| 
						 | 
				
			
			@ -531,12 +531,12 @@ extern "C" {
 | 
			
		|||
    int close(int fildes);
 | 
			
		||||
    int stat(const char *path, struct stat *st);
 | 
			
		||||
    int statvfs(const char *path, struct statvfs *buf);
 | 
			
		||||
    DIR *opendir(const char*);
 | 
			
		||||
    DIR *opendir(const char *);
 | 
			
		||||
    struct dirent *readdir(DIR *);
 | 
			
		||||
    int closedir(DIR*);
 | 
			
		||||
    void rewinddir(DIR*);
 | 
			
		||||
    long telldir(DIR*);
 | 
			
		||||
    void seekdir(DIR*, long);
 | 
			
		||||
    int closedir(DIR *);
 | 
			
		||||
    void rewinddir(DIR *);
 | 
			
		||||
    long telldir(DIR *);
 | 
			
		||||
    void seekdir(DIR *, long);
 | 
			
		||||
    int mkdir(const char *name, mode_t n);
 | 
			
		||||
#if __cplusplus
 | 
			
		||||
}; // extern "C"
 | 
			
		||||
| 
						 | 
				
			
			@ -556,7 +556,7 @@ namespace mbed {
 | 
			
		|||
 *
 | 
			
		||||
 *  @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
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,8 +87,8 @@ time_t time(time_t *timer)
 | 
			
		|||
            set_time(0);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    time_t t = (time_t)-1;
 | 
			
		||||
 | 
			
		||||
    time_t t = (time_t) -1;
 | 
			
		||||
    if (_rtc_read != NULL) {
 | 
			
		||||
        t = _rtc_read();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -100,7 +100,8 @@ time_t time(time_t *timer)
 | 
			
		|||
    return t;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void set_time(time_t t) {
 | 
			
		||||
void set_time(time_t t)
 | 
			
		||||
{
 | 
			
		||||
    _mutex->lock();
 | 
			
		||||
    if (_rtc_init != NULL) {
 | 
			
		||||
        _rtc_init();
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +112,8 @@ void set_time(time_t t) {
 | 
			
		|||
    _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();
 | 
			
		||||
    _rtc_read = read_rtc;
 | 
			
		||||
    _rtc_write = write_rtc;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,14 +30,14 @@
 | 
			
		|||
 * mbed_main(), it is not meant for user code, but for the SDK itself to perform
 | 
			
		||||
 * initializations before main() is called.
 | 
			
		||||
 */
 | 
			
		||||
MBED_WEAK void mbed_main(void) 
 | 
			
		||||
MBED_WEAK void mbed_main(void)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* This function can be implemented by the target to perform higher level target initialization
 | 
			
		||||
 */
 | 
			
		||||
MBED_WEAK void mbed_sdk_init(void) 
 | 
			
		||||
MBED_WEAK void mbed_sdk_init(void)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ void mbed_copy_nvic(void)
 | 
			
		|||
#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9)
 | 
			
		||||
#ifdef NVIC_RAM_VECTOR_ADDRESS
 | 
			
		||||
    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++) {
 | 
			
		||||
        vectors[i] = old_vectors[i];
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -71,19 +71,19 @@ void mbed_copy_nvic(void)
 | 
			
		|||
 | 
			
		||||
int $Super$$main(void);
 | 
			
		||||
 | 
			
		||||
int $Sub$$main(void) 
 | 
			
		||||
int $Sub$$main(void)
 | 
			
		||||
{
 | 
			
		||||
    mbed_main();
 | 
			
		||||
    return $Super$$main();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void _platform_post_stackheap_init(void) 
 | 
			
		||||
void _platform_post_stackheap_init(void)
 | 
			
		||||
{
 | 
			
		||||
    mbed_copy_nvic();
 | 
			
		||||
    mbed_sdk_init();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined (__GNUC__) 
 | 
			
		||||
#elif defined (__GNUC__)
 | 
			
		||||
 | 
			
		||||
extern int __real_main(void);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -95,7 +95,7 @@ void software_init_hook(void)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int __wrap_main(void) 
 | 
			
		||||
int __wrap_main(void)
 | 
			
		||||
{
 | 
			
		||||
    mbed_main();
 | 
			
		||||
    return __real_main();
 | 
			
		||||
| 
						 | 
				
			
			@ -105,8 +105,8 @@ int __wrap_main(void)
 | 
			
		|||
 | 
			
		||||
int __low_level_init(void)
 | 
			
		||||
{
 | 
			
		||||
  mbed_copy_nvic();
 | 
			
		||||
  return 1;
 | 
			
		||||
    mbed_copy_nvic();
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,8 @@
 | 
			
		|||
#define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
 | 
			
		||||
 | 
			
		||||
#if DEVICE_LOCALFILESYSTEM
 | 
			
		||||
FILEHANDLE semihost_open(const char* name, int openmode) {
 | 
			
		||||
FILEHANDLE semihost_open(const char *name, int openmode)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t args[3];
 | 
			
		||||
    args[0] = (uint32_t)name;
 | 
			
		||||
    args[1] = (uint32_t)openmode;
 | 
			
		||||
| 
						 | 
				
			
			@ -52,12 +53,16 @@ FILEHANDLE semihost_open(const char* name, int openmode) {
 | 
			
		|||
    return __semihost(SYS_OPEN, args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_close(FILEHANDLE fh) {
 | 
			
		||||
int semihost_close(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    return __semihost(SYS_CLOSE, &fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) {
 | 
			
		||||
    if (length == 0) return 0;
 | 
			
		||||
int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode)
 | 
			
		||||
{
 | 
			
		||||
    if (length == 0) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint32_t args[3];
 | 
			
		||||
    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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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];
 | 
			
		||||
    args[0] = (uint32_t)fh;
 | 
			
		||||
    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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_istty(FILEHANDLE fh) {
 | 
			
		||||
int semihost_istty(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    return __semihost(SYS_ISTTY, &fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_seek(FILEHANDLE fh, long position) {
 | 
			
		||||
int semihost_seek(FILEHANDLE fh, long position)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t args[2];
 | 
			
		||||
    args[0] = (uint32_t)fh;
 | 
			
		||||
    args[1] = (uint32_t)position;
 | 
			
		||||
    return __semihost(SYS_SEEK, args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_ensure(FILEHANDLE fh) {
 | 
			
		||||
int semihost_ensure(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    return __semihost(SYS_ENSURE, &fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
long semihost_flen(FILEHANDLE fh) {
 | 
			
		||||
long semihost_flen(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    return __semihost(SYS_FLEN, &fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_remove(const char *name) {
 | 
			
		||||
int semihost_remove(const char *name)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t args[2];
 | 
			
		||||
    args[0] = (uint32_t)name;
 | 
			
		||||
    args[1] = (uint32_t)strlen(name);
 | 
			
		||||
    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];
 | 
			
		||||
    args[0] = (uint32_t)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
 | 
			
		||||
 | 
			
		||||
int semihost_exit(void) {
 | 
			
		||||
int semihost_exit(void)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t args[4];
 | 
			
		||||
    return __semihost(SYS_EXIT, args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_uid(char *uid) {
 | 
			
		||||
int semihost_uid(char *uid)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t args[2];
 | 
			
		||||
    args[0] = (uint32_t)uid;
 | 
			
		||||
    args[1] = DEVICE_ID_LENGTH + 1;
 | 
			
		||||
    return __semihost(USR_UID, &args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_reset(void) {
 | 
			
		||||
int semihost_reset(void)
 | 
			
		||||
{
 | 
			
		||||
    // Does not normally return, however if used with older firmware versions
 | 
			
		||||
    // that do not support this call it will return -1.
 | 
			
		||||
    return __semihost(USR_RESET, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_vbus(void) {
 | 
			
		||||
int semihost_vbus(void)
 | 
			
		||||
{
 | 
			
		||||
    return __semihost(USR_VBUS, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int semihost_powerdown(void) {
 | 
			
		||||
int semihost_powerdown(void)
 | 
			
		||||
{
 | 
			
		||||
    return __semihost(USR_POWERDOWN, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if DEVICE_DEBUG_AWARENESS
 | 
			
		||||
 | 
			
		||||
int semihost_connected(void) {
 | 
			
		||||
int semihost_connected(void)
 | 
			
		||||
{
 | 
			
		||||
    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:
 | 
			
		||||
static int is_debugger_attached = 1;
 | 
			
		||||
 | 
			
		||||
int semihost_connected(void) {
 | 
			
		||||
int semihost_connected(void)
 | 
			
		||||
{
 | 
			
		||||
    return is_debugger_attached;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int semihost_disabledebug(void) {
 | 
			
		||||
int semihost_disabledebug(void)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t args[1];
 | 
			
		||||
#if !(DEVICE_DEBUG_AWARENESS)
 | 
			
		||||
    is_debugger_attached = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,8 +29,9 @@ extern "C" {
 | 
			
		|||
#if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
 | 
			
		||||
 | 
			
		||||
#if defined(__ICCARM__)
 | 
			
		||||
static inline int __semihost(int reason, const void *arg) {
 | 
			
		||||
    return __semihosting(reason, (void*)arg);
 | 
			
		||||
static inline int __semihost(int reason, const void *arg)
 | 
			
		||||
{
 | 
			
		||||
    return __semihosting(reason, (void *)arg);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -44,17 +45,18 @@ static inline int __semihost(int reason, const void *arg) {
 | 
			
		|||
#   define AngelSWIAsm          swi
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static inline int __semihost(int reason, const void *arg) {
 | 
			
		||||
static inline int __semihost(int reason, const void *arg)
 | 
			
		||||
{
 | 
			
		||||
    int value;
 | 
			
		||||
 | 
			
		||||
    asm volatile (
 | 
			
		||||
       "mov r0, %1"          "\n\t"
 | 
			
		||||
       "mov r1, %2"          "\n\t"
 | 
			
		||||
       AngelSWIInsn " %a3"   "\n\t"
 | 
			
		||||
       "mov %0, r0"
 | 
			
		||||
       : "=r" (value)                                         /* output operands             */
 | 
			
		||||
       : "r" (reason), "r" (arg), "i" (AngelSWI)              /* input operands              */
 | 
			
		||||
       : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"   /* list of clobbered registers */
 | 
			
		||||
    asm volatile(
 | 
			
		||||
        "mov r0, %1"          "\n\t"
 | 
			
		||||
        "mov r1, %2"          "\n\t"
 | 
			
		||||
        AngelSWIInsn " %a3"   "\n\t"
 | 
			
		||||
        "mov %0, r0"
 | 
			
		||||
        : "=r"(value)                                          /* output operands             */
 | 
			
		||||
        : "r"(reason), "r"(arg), "i"(AngelSWI)                 /* input operands              */
 | 
			
		||||
        : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"   /* list of clobbered registers */
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return value;
 | 
			
		||||
| 
						 | 
				
			
			@ -63,14 +65,14 @@ static inline int __semihost(int reason, const void *arg) {
 | 
			
		|||
#endif
 | 
			
		||||
 | 
			
		||||
#if DEVICE_LOCALFILESYSTEM
 | 
			
		||||
FILEHANDLE semihost_open(const char* name, int openmode);
 | 
			
		||||
int semihost_close (FILEHANDLE fh);
 | 
			
		||||
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);
 | 
			
		||||
FILEHANDLE semihost_open(const char *name, int openmode);
 | 
			
		||||
int semihost_close(FILEHANDLE fh);
 | 
			
		||||
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_ensure(FILEHANDLE fh);
 | 
			
		||||
long semihost_flen (FILEHANDLE fh);
 | 
			
		||||
int semihost_seek  (FILEHANDLE fh, long position);
 | 
			
		||||
int semihost_istty (FILEHANDLE fh);
 | 
			
		||||
long semihost_flen(FILEHANDLE fh);
 | 
			
		||||
int semihost_seek(FILEHANDLE fh, long position);
 | 
			
		||||
int semihost_istty(FILEHANDLE fh);
 | 
			
		||||
 | 
			
		||||
int semihost_remove(const char *name);
 | 
			
		||||
int semihost_rename(const char *old_name, const char *new_name);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -396,7 +396,7 @@
 | 
			
		|||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef FILEHANDLE
 | 
			
		||||
    typedef int FILEHANDLE;
 | 
			
		||||
typedef int FILEHANDLE;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Backwards compatibility
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
 * \defgroup platform_wait_api wait_api functions
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
/* mbed Microcontroller Library
 | 
			
		||||
 * Copyright (c) 2006-2013 ARM Limited
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -53,10 +53,10 @@ extern "C" {
 | 
			
		|||
 *  the accuracy of single precision floating point).
 | 
			
		||||
 *
 | 
			
		||||
 *  @param s number of seconds to wait
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *  @note
 | 
			
		||||
 *    If the RTOS is present, this function always spins to get the exact number of microseconds, 
 | 
			
		||||
 *    which potentially affects power (such as preventing deep sleep) and multithread performance. 
 | 
			
		||||
 *    If the RTOS is present, this function always spins to get the exact number of microseconds,
 | 
			
		||||
 *    which potentially affects power (such as preventing deep sleep) and multithread performance.
 | 
			
		||||
 *    You can avoid it by using Thread::wait().
 | 
			
		||||
 */
 | 
			
		||||
void wait(float s);
 | 
			
		||||
| 
						 | 
				
			
			@ -64,10 +64,10 @@ void wait(float s);
 | 
			
		|||
/** Waits a number of milliseconds.
 | 
			
		||||
 *
 | 
			
		||||
 *  @param ms the whole number of milliseconds to wait
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *  @note
 | 
			
		||||
 *    If the RTOS is present, this function always spins to get the exact number of microseconds, 
 | 
			
		||||
 *    which potentially affects power (such as preventing deep sleep) and multithread performance. 
 | 
			
		||||
 *    If the RTOS is present, this function always spins to get the exact number of microseconds,
 | 
			
		||||
 *    which potentially affects power (such as preventing deep sleep) and multithread performance.
 | 
			
		||||
 *    You can avoid it by using Thread::wait().
 | 
			
		||||
 */
 | 
			
		||||
void wait_ms(int ms);
 | 
			
		||||
| 
						 | 
				
			
			@ -75,9 +75,9 @@ void wait_ms(int ms);
 | 
			
		|||
/** Waits a number of microseconds.
 | 
			
		||||
 *
 | 
			
		||||
 *  @param us the whole number of microseconds to wait
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *  @note
 | 
			
		||||
 *    If the RTOS is present, this function always spins to get the exact number of microseconds, 
 | 
			
		||||
 *    If the RTOS is present, this function always spins to get the exact number of microseconds,
 | 
			
		||||
 *    which potentially affects power (such as preventing deep sleep) and multithread performance.
 | 
			
		||||
 */
 | 
			
		||||
void wait_us(int us);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,15 +21,18 @@
 | 
			
		|||
#include "platform/mbed_wait_api.h"
 | 
			
		||||
#include "hal/us_ticker_api.h"
 | 
			
		||||
 | 
			
		||||
void wait(float s) {
 | 
			
		||||
void wait(float s)
 | 
			
		||||
{
 | 
			
		||||
    wait_us(s * 1000000.0f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wait_ms(int ms) {
 | 
			
		||||
void wait_ms(int ms)
 | 
			
		||||
{
 | 
			
		||||
    wait_us(ms * 1000);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wait_us(int us) {
 | 
			
		||||
void wait_us(int us)
 | 
			
		||||
{
 | 
			
		||||
    const ticker_data_t *const ticker = get_us_ticker_data();
 | 
			
		||||
    uint32_t start = ticker_read(ticker);
 | 
			
		||||
    while ((ticker_read(ticker) - start) < (uint32_t)us);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,15 +24,18 @@
 | 
			
		|||
#include "platform/mbed_critical.h"
 | 
			
		||||
#include "platform/mbed_power_mgmt.h"
 | 
			
		||||
 | 
			
		||||
void wait(float s) {
 | 
			
		||||
void wait(float s)
 | 
			
		||||
{
 | 
			
		||||
    wait_us(s * 1000000.0f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wait_ms(int ms) {
 | 
			
		||||
void wait_ms(int ms)
 | 
			
		||||
{
 | 
			
		||||
    wait_us(ms * 1000);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wait_us(int us) {
 | 
			
		||||
void wait_us(int us)
 | 
			
		||||
{
 | 
			
		||||
    const ticker_data_t *const ticker = get_us_ticker_data();
 | 
			
		||||
 | 
			
		||||
    uint32_t start = ticker_read(ticker);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue