4 * \brief System-specific implementation of the \ref _write 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 * \addtogroup group_common_utils_stdio
\r
56 volatile void *volatile stdio_base;
\r
57 int (*ptr_put)(void volatile*, char);
\r
60 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__) || defined(__ICCARM__))
\r
66 #pragma module_name = "?__write"
\r
68 /*! \brief Writes a number of bytes, at most \a size, from the memory area
\r
69 * pointed to by \a buffer.
\r
71 * If \a buffer is zero then \ref __write performs flushing of internal buffers,
\r
72 * if any. In this case, \a handle can be \c -1 to indicate that all handles
\r
73 * should be flushed.
\r
75 * \param handle File handle to write to.
\r
76 * \param buffer Pointer to buffer to read bytes to write from.
\r
77 * \param size Number of bytes to write.
\r
79 * \return The number of bytes written, or \c _LLIO_ERROR on failure.
\r
81 size_t __write(int handle, const unsigned char *buffer, size_t size)
\r
86 // This means that we should flush internal buffers.
\r
90 // This implementation only writes to stdout and stderr.
\r
91 // For all other file handles, it returns failure.
\r
92 if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
\r
96 for (; size != 0; --size) {
\r
97 if (ptr_put(stdio_base, *buffer++) < 0) {
\r
108 #elif (defined(__GNUC__) && !XMEGA && !MEGA)
\r
110 int __attribute__((weak))
\r
111 _write (int file, const char *ptr, int len);
\r
113 int __attribute__((weak))
\r
114 _write (int file, const char *ptr, int len)
\r
118 if ((file != 1) && (file != 2) && (file!=3)) {
\r
122 for (; len != 0; --len) {
\r
123 if (ptr_put(stdio_base, *ptr++) < 0) {
\r
131 #elif (defined(__GNUC__) && (XMEGA || MEGA))
\r
133 int _write (char c, int *f);
\r
135 int _write (char c, int *f)
\r
137 if (ptr_put(stdio_base, c) < 0) {
\r