mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			platform: astyle update
							parent
							
								
									483427a285
								
							
						
					
					
						commit
						ffcb6ecfb5
					
				| 
						 | 
				
			
			@ -52,8 +52,7 @@ namespace mbed {
 | 
			
		|||
 * @endcode
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class ATCmdParser : private NonCopyable<ATCmdParser>
 | 
			
		||||
{
 | 
			
		||||
class ATCmdParser : private NonCopyable<ATCmdParser> {
 | 
			
		||||
private:
 | 
			
		||||
    // File handle
 | 
			
		||||
    // Not owned by ATCmdParser
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,8 +84,7 @@ typedef void (*CThunkEntry)(void);
 | 
			
		|||
 * @note Synchronization level: Not protected
 | 
			
		||||
 */
 | 
			
		||||
template<class T>
 | 
			
		||||
class CThunk
 | 
			
		||||
{
 | 
			
		||||
class CThunk {
 | 
			
		||||
public:
 | 
			
		||||
    typedef void (T::*CCallbackSimple)(void);
 | 
			
		||||
    typedef void (T::*CCallback)(void *context);
 | 
			
		||||
| 
						 | 
				
			
			@ -100,7 +99,8 @@ class CThunk
 | 
			
		|||
        init(instance, callback, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        ~CThunk() {
 | 
			
		||||
    ~CThunk()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -174,8 +174,7 @@ class CThunk
 | 
			
		|||
// 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
 | 
			
		||||
        {
 | 
			
		||||
    typedef __packed struct {
 | 
			
		||||
        CTHUNK_VARIABLES;
 | 
			
		||||
        volatile uint32_t instance;
 | 
			
		||||
        volatile uint32_t context;
 | 
			
		||||
| 
						 | 
				
			
			@ -183,8 +182,7 @@ class CThunk
 | 
			
		|||
        volatile uint32_t trampoline;
 | 
			
		||||
    }  CThunkTrampoline;
 | 
			
		||||
#else
 | 
			
		||||
        typedef struct
 | 
			
		||||
        {
 | 
			
		||||
    typedef struct {
 | 
			
		||||
        CTHUNK_VARIABLES;
 | 
			
		||||
        volatile uint32_t instance;
 | 
			
		||||
        volatile uint32_t context;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -122,7 +122,8 @@ public:
 | 
			
		|||
    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) {
 | 
			
		||||
    pFunctionPointer_t add(T *obj, M method)
 | 
			
		||||
    {
 | 
			
		||||
        return add(callback(obj, method));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -156,7 +157,8 @@ public:
 | 
			
		|||
    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) {
 | 
			
		||||
    pFunctionPointer_t add_front(T *obj, M method)
 | 
			
		||||
    {
 | 
			
		||||
        return add_front(callback(obj, method));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -231,7 +233,8 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    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) {
 | 
			
		||||
    void operator()(void)
 | 
			
		||||
    {
 | 
			
		||||
        call();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -242,7 +245,8 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    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 {
 | 
			
		||||
    pFunctionPointer_t operator [](int i) const
 | 
			
		||||
    {
 | 
			
		||||
        return get(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1156
									
								
								platform/Callback.h
								
								
								
								
							
							
						
						
									
										1156
									
								
								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()) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**@}*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,8 @@ SingletonPtr<PlatformMutex> FileBase::_mutex;
 | 
			
		|||
 | 
			
		||||
FileBase::FileBase(const char *name, PathType t) : _next(NULL),
 | 
			
		||||
    _name(name),
 | 
			
		||||
                                                   _path_type(t) {
 | 
			
		||||
    _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
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +60,8 @@ FileBase::~FileBase() {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,8 @@
 | 
			
		|||
 | 
			
		||||
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, "/");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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 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 NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool FilePath::exists(void) {
 | 
			
		||||
bool FilePath::exists(void)
 | 
			
		||||
{
 | 
			
		||||
    return fb != NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,11 +45,13 @@ public:
 | 
			
		|||
    FunctionPointerArg1(T *object, R(T::*member)(A1))
 | 
			
		||||
        : Callback<R(A1)>(object, member) {}
 | 
			
		||||
 | 
			
		||||
    R (*get_function())(A1) {
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -76,11 +79,13 @@ public:
 | 
			
		|||
    FunctionPointerArg1(T *object, R(T::*member)())
 | 
			
		||||
        : Callback<R()>(object, member) {}
 | 
			
		||||
 | 
			
		||||
    R (*get_function())() {
 | 
			
		||||
    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,17 +111,20 @@ 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
 | 
			
		||||
    n = length - n; // number of characters written
 | 
			
		||||
| 
						 | 
				
			
			@ -127,7 +133,8 @@ ssize_t LocalFileHandle::write(const void *buffer, size_t length) {
 | 
			
		|||
    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
 | 
			
		||||
    n = length - n; // number of characters read
 | 
			
		||||
| 
						 | 
				
			
			@ -136,14 +143,16 @@ ssize_t LocalFileHandle::read(void *buffer, size_t length) {
 | 
			
		|||
    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,16 +198,19 @@ 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) {
 | 
			
		||||
            unlock();
 | 
			
		||||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,7 +19,8 @@
 | 
			
		|||
 | 
			
		||||
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+");
 | 
			
		||||
| 
						 | 
				
			
			@ -33,33 +34,38 @@ 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);
 | 
			
		||||
| 
						 | 
				
			
			@ -67,11 +73,13 @@ char* Stream::gets(char *s, int size) {
 | 
			
		|||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Stream::close() {
 | 
			
		||||
int Stream::close()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t Stream::write(const void* buffer, size_t length) {
 | 
			
		||||
ssize_t Stream::write(const void *buffer, size_t length)
 | 
			
		||||
{
 | 
			
		||||
    const char *ptr = (const char *)buffer;
 | 
			
		||||
    const char *end = ptr + length;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -86,14 +94,17 @@ ssize_t Stream::write(const void* buffer, size_t length) {
 | 
			
		|||
    return ptr - (const char *)buffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t Stream::read(void* buffer, size_t length) {
 | 
			
		||||
ssize_t Stream::read(void *buffer, size_t length)
 | 
			
		||||
{
 | 
			
		||||
    char *ptr = (char *)buffer;
 | 
			
		||||
    char *end = ptr + length;
 | 
			
		||||
 | 
			
		||||
    lock();
 | 
			
		||||
    while (ptr != end) {
 | 
			
		||||
        int c = _getc();
 | 
			
		||||
        if (c==EOF) break;
 | 
			
		||||
        if (c == EOF) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        *ptr++ = c;
 | 
			
		||||
    }
 | 
			
		||||
    unlock();
 | 
			
		||||
| 
						 | 
				
			
			@ -101,30 +112,37 @@ ssize_t Stream::read(void* buffer, size_t length) {
 | 
			
		|||
    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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,7 +54,10 @@ public:
 | 
			
		|||
    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();
 | 
			
		||||
| 
						 | 
				
			
			@ -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,7 +71,8 @@ public:
 | 
			
		|||
     *
 | 
			
		||||
     * @return The transaction which was stored
 | 
			
		||||
     */
 | 
			
		||||
    transaction_t* get_transaction() {
 | 
			
		||||
    transaction_t *get_transaction()
 | 
			
		||||
    {
 | 
			
		||||
        return &_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
 | 
			
		||||
| 
						 | 
				
			
			@ -88,11 +88,13 @@ extern "C" {
 | 
			
		|||
// 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();
 | 
			
		||||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -260,11 +267,13 @@ extern "C" {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,7 +68,8 @@ static void mbed_halt_system(void)
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
WEAK void error(const char* format, ...) {
 | 
			
		||||
WEAK void error(const char *format, ...)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    // Prevent recursion if error is called again
 | 
			
		||||
    if (error_in_progress) {
 | 
			
		||||
| 
						 | 
				
			
			@ -194,8 +195,9 @@ mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *e
 | 
			
		|||
WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
 | 
			
		||||
{
 | 
			
		||||
    //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);
 | 
			
		||||
| 
						 | 
				
			
			@ -233,21 +235,23 @@ mbed_error_status_t mbed_get_last_error_info (mbed_error_ctx *error_info)
 | 
			
		|||
//Makes an mbed_error_status_t value
 | 
			
		||||
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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -205,8 +205,7 @@ typedef int mbed_error_status_t;
 | 
			
		|||
 *         MBED_ERROR_TYPE_POSIX  - Used to indicate that the error status is of Posix error type.\n
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
typedef enum _mbed_error_type_t
 | 
			
		||||
{
 | 
			
		||||
typedef enum _mbed_error_type_t {
 | 
			
		||||
    MBED_ERROR_TYPE_SYSTEM = 0,
 | 
			
		||||
    MBED_ERROR_TYPE_CUSTOM = 1,
 | 
			
		||||
    //2 is reserved
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -73,16 +80,19 @@ 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) {
 | 
			
		||||
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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,7 +97,8 @@ 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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,8 @@ static const uint32_t seconds_before_month[2][12] = {
 | 
			
		|||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support) {
 | 
			
		||||
bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support)
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
     * since in practice, the value manipulated by this algorithm lie in the
 | 
			
		||||
     * range: [70 : 206] the algorithm can be reduced to: year % 4 with exception for 200 (year 2100 is not leap year).
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +91,8 @@ bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support) {
 | 
			
		|||
    return (year) % 4 ? false : true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -111,7 +111,8 @@ 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++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			@ -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,14 +308,16 @@ 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) {
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -416,7 +462,8 @@ std::FILE *fdopen(FileHandle *fh, const char *mode)
 | 
			
		|||
 *   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,11 +547,13 @@ 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) {
 | 
			
		||||
extern "C" int close(int fildes)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    filehandles[fildes] = NULL;
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -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,7 +663,8 @@ 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);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
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)
 | 
			
		||||
| 
						 | 
				
			
			@ -700,7 +758,8 @@ 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);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -727,7 +786,8 @@ extern "C" int _isatty(FILEHANDLE fh)
 | 
			
		|||
    return isatty(fh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int isatty(int fildes) {
 | 
			
		||||
extern "C" int isatty(int fildes)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
| 
						 | 
				
			
			@ -765,7 +825,8 @@ int _lseek(FILEHANDLE fh, int offset, int whence)
 | 
			
		|||
    return off;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" off_t lseek(int fildes, off_t offset, int whence) {
 | 
			
		||||
extern "C" off_t lseek(int fildes, off_t offset, int whence)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
| 
						 | 
				
			
			@ -781,12 +842,14 @@ 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) {
 | 
			
		||||
extern "C" int fsync(int fildes)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
| 
						 | 
				
			
			@ -803,7 +866,8 @@ extern "C" int fsync(int fildes) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
#ifdef __ARMCC_VERSION
 | 
			
		||||
extern "C" long PREFIX(_flen)(FILEHANDLE fh) {
 | 
			
		||||
extern "C" long PREFIX(_flen)(FILEHANDLE fh)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fh);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
| 
						 | 
				
			
			@ -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,12 +910,14 @@ 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) {
 | 
			
		||||
extern "C" int fstat(int fildes, struct stat *st)
 | 
			
		||||
{
 | 
			
		||||
    FileHandle *fhc = get_fhc(fildes);
 | 
			
		||||
    if (fhc == NULL) {
 | 
			
		||||
        errno = EBADF;
 | 
			
		||||
| 
						 | 
				
			
			@ -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,24 +1032,28 @@ 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();
 | 
			
		||||
    if (fs == 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() {
 | 
			
		||||
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,14 +1204,16 @@ 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) {
 | 
			
		||||
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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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,15 +1279,18 @@ 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) {
 | 
			
		||||
    int __aeabi_atexit(void *object, void (*dtor)(void * /*this*/), void *handle)
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
int __cxa_atexit(void (*dtor)(void* /*this*/), void *object, void *handle) {
 | 
			
		||||
    int __cxa_atexit(void (*dtor)(void * /*this*/), void *object, void *handle)
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
void __cxa_finalize(void *handle) {
 | 
			
		||||
    void __cxa_finalize(void *handle)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
} // end of extern "C"
 | 
			
		||||
| 
						 | 
				
			
			@ -1223,7 +1314,8 @@ extern "C"{
 | 
			
		|||
     * @details Unlike the standard version, this function doesn't call any function
 | 
			
		||||
     * registered with atexit before calling _exit.
 | 
			
		||||
     */
 | 
			
		||||
void __wrap_exit(int return_code) {
 | 
			
		||||
    void __wrap_exit(int return_code)
 | 
			
		||||
    {
 | 
			
		||||
        _exit(return_code);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1232,7 +1324,8 @@ void __wrap_exit(int return_code) {
 | 
			
		|||
     * @details This function will always fail and never register any handler to be
 | 
			
		||||
     * called at exit.
 | 
			
		||||
     */
 | 
			
		||||
int __wrap_atexit(void (*func)()) {
 | 
			
		||||
    int __wrap_atexit(void (*func)())
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1244,7 +1337,8 @@ 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);
 | 
			
		||||
| 
						 | 
				
			
			@ -1253,7 +1347,8 @@ void mbed_set_unbuffered_stream(std::FILE *_file) {
 | 
			
		|||
#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);
 | 
			
		||||
| 
						 | 
				
			
			@ -1268,7 +1363,8 @@ 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);
 | 
			
		||||
| 
						 | 
				
			
			@ -1297,7 +1393,8 @@ 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) {
 | 
			
		||||
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");
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,7 +29,8 @@ extern "C" {
 | 
			
		|||
#if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
 | 
			
		||||
 | 
			
		||||
#if defined(__ICCARM__)
 | 
			
		||||
static inline int __semihost(int reason, const void *arg) {
 | 
			
		||||
static inline int __semihost(int reason, const void *arg)
 | 
			
		||||
{
 | 
			
		||||
    return __semihosting(reason, (void *)arg);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			@ -44,7 +45,8 @@ 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(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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