4 * \brief System-specific implementation of the \ref _read function used by
\r
5 * the standard library.
\r
7 * Copyright (c) 2009-2015 Atmel Corporation. All rights reserved.
\r
13 * Redistribution and use in source and binary forms, with or without
\r
14 * modification, are permitted provided that the following conditions are met:
\r
16 * 1. Redistributions of source code must retain the above copyright notice,
\r
17 * this list of conditions and the following disclaimer.
\r
19 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
20 * this list of conditions and the following disclaimer in the documentation
\r
21 * and/or other materials provided with the distribution.
\r
23 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
24 * from this software without specific prior written permission.
\r
26 * 4. This software may only be redistributed and used in connection with an
\r
27 * Atmel microcontroller product.
\r
29 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
32 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
33 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
39 * POSSIBILITY OF SUCH DAMAGE.
\r
45 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
\r
48 #include "compiler.h"
\r
51 * \defgroup group_common_utils_stdio Standard I/O (stdio)
\r
53 * Common standard I/O driver that implements the stdio
\r
54 * read and write functions on AVR and SAM devices.
\r
59 extern volatile void *volatile stdio_base;
\r
60 void (*ptr_get)(void volatile*, char*);
\r
63 // IAR common implementation
\r
64 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__) || defined(__ICCARM__) )
\r
70 #pragma module_name = "?__read"
\r
72 /*! \brief Reads a number of bytes, at most \a size, into the memory area
\r
73 * pointed to by \a buffer.
\r
75 * \param handle File handle to read from.
\r
76 * \param buffer Pointer to buffer to write read bytes to.
\r
77 * \param size Number of bytes to read.
\r
79 * \return The number of bytes read, \c 0 at the end of the file, or
\r
80 * \c _LLIO_ERROR on failure.
\r
82 size_t __read(int handle, unsigned char *buffer, size_t size)
\r
85 // This implementation only reads from stdin.
\r
86 // For all other file handles, it returns failure.
\r
87 if (handle != _LLIO_STDIN) {
\r
90 for (; size > 0; --size) {
\r
91 ptr_get(stdio_base, (char*)buffer);
\r
98 /*! \brief This routine is required by IAR DLIB library since EWAVR V6.10
\r
99 * the implementation is empty to be compatible with old IAR version.
\r
101 int __close(int handle)
\r
107 /*! \brief This routine is required by IAR DLIB library since EWAVR V6.10
\r
108 * the implementation is empty to be compatible with old IAR version.
\r
110 int remove(const char* val)
\r
116 /*! \brief This routine is required by IAR DLIB library since EWAVR V6.10
\r
117 * the implementation is empty to be compatible with old IAR version.
\r
119 long __lseek(int handle, long val, int val2)
\r
128 // GCC AVR32 and SAM implementation
\r
129 #elif (defined(__GNUC__) && !XMEGA && !MEGA)
\r
131 int __attribute__((weak))
\r
132 _read (int file, char * ptr, int len); // Remove GCC compiler warning
\r
134 int __attribute__((weak))
\r
135 _read (int file, char * ptr, int len)
\r
143 for (; len > 0; --len) {
\r
144 ptr_get(stdio_base, ptr);
\r
151 // GCC AVR implementation
\r
152 #elif (defined(__GNUC__) && (XMEGA || MEGA) )
\r
154 int _read (int *f); // Remove GCC compiler warning
\r
159 ptr_get(stdio_base,&c);
\r