]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/AVR32_UC3/write.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Source / portable / IAR / AVR32_UC3 / write.c
1 /*This file is prepared for Doxygen automatic documentation generation.*/\r
2 /*! \file *********************************************************************\r
3  *\r
4  * \brief System-specific implementation of the \ref __write function used by\r
5           the standard library.\r
6  *\r
7  * - Compiler:           IAR EWAVR32\r
8  * - Supported devices:  All AVR32 devices with a USART module can be used.\r
9  * - AppNote:\r
10  *\r
11  * \author               Atmel Corporation: http://www.atmel.com \n\r
12  *                       Support and FAQ: http://support.atmel.no/\r
13  *\r
14  ******************************************************************************/\r
15 \r
16 /* Copyright (c) 2007, Atmel Corporation All rights reserved.\r
17  *\r
18  * Redistribution and use in source and binary forms, with or without\r
19  * modification, are permitted provided that the following conditions are met:\r
20  *\r
21  * 1. Redistributions of source code must retain the above copyright notice,\r
22  * this list of conditions and the following disclaimer.\r
23  *\r
24  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
25  * this list of conditions and the following disclaimer in the documentation\r
26  * and/or other materials provided with the distribution.\r
27  *\r
28  * 3. The name of ATMEL may not be used to endorse or promote products derived\r
29  * from this software without specific prior written permission.\r
30  *\r
31  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND\r
34  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,\r
35  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
37  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
38  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
40  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
41  */\r
42 \r
43 \r
44 #include <yfuns.h>\r
45 #include <avr32/io.h>\r
46 #include "usart.h"\r
47 \r
48 \r
49 _STD_BEGIN\r
50 \r
51 \r
52 #pragma module_name = "?__write"\r
53 \r
54 \r
55 //! Pointer to the base of the USART module instance to use for stdio.\r
56 __no_init volatile avr32_usart_t *volatile stdio_usart_base;\r
57 \r
58 \r
59 /*! \brief Writes a number of bytes, at most \a size, from the memory area\r
60  *         pointed to by \a buffer.\r
61  *\r
62  * If \a buffer is zero then \ref __write performs flushing of internal buffers,\r
63  * if any. In this case, \a handle can be \c -1 to indicate that all handles\r
64  * should be flushed.\r
65  *\r
66  * \param handle File handle to write to.\r
67  * \param buffer Pointer to buffer to read bytes to write from.\r
68  * \param size Number of bytes to write.\r
69  *\r
70  * \return The number of bytes written, or \c _LLIO_ERROR on failure.\r
71  */\r
72 size_t __write(int handle, const unsigned char *buffer, size_t size)\r
73 {\r
74   size_t nChars = 0;\r
75 \r
76   if (buffer == 0)\r
77   {\r
78     // This means that we should flush internal buffers.\r
79     return 0;\r
80   }\r
81 \r
82   // This implementation only writes to stdout and stderr.\r
83   // For all other file handles, it returns failure.\r
84   if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR)\r
85   {\r
86     return _LLIO_ERROR;\r
87   }\r
88 \r
89   for (; size != 0; --size)\r
90   {\r
91     if (usart_putchar(stdio_usart_base, *buffer++) < 0)\r
92     {\r
93       return _LLIO_ERROR;\r
94     }\r
95 \r
96     ++nChars;\r
97   }\r
98 \r
99   return nChars;\r
100 }\r
101 \r
102 \r
103 _STD_END\r