]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/src/ASF/common/utils/stdio/write.c
Rename DummyTCB_t to StaticTCB_t.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAME70_Xplained_AtmelStudio / src / ASF / common / utils / stdio / write.c
1 /**\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  * Copyright (c) 2009-2015 Atmel Corporation. All rights reserved.\r
8  *\r
9  * \asf_license_start\r
10  *\r
11  * \page License\r
12  *\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
15  *\r
16  * 1. Redistributions of source code must retain the above copyright notice,\r
17  *    this list of conditions and the following disclaimer.\r
18  *\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
22  *\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
25  *\r
26  * 4. This software may only be redistributed and used in connection with an\r
27  *    Atmel microcontroller product.\r
28  *\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
40  *\r
41  * \asf_license_stop\r
42  *\r
43  */\r
44 /*\r
45  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>\r
46  */\r
47 \r
48 #include "compiler.h"\r
49 \r
50 /**\r
51  * \addtogroup group_common_utils_stdio\r
52  *\r
53  * \{\r
54  */\r
55 \r
56 volatile void *volatile stdio_base;\r
57 int (*ptr_put)(void volatile*, char);\r
58 \r
59 \r
60 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__) || defined(__ICCARM__))\r
61 \r
62 #include <yfuns.h>\r
63 \r
64 _STD_BEGIN\r
65 \r
66 #pragma module_name = "?__write"\r
67 \r
68 /*! \brief Writes a number of bytes, at most \a size, from the memory area\r
69  *         pointed to by \a buffer.\r
70  *\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
74  *\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
78  *\r
79  * \return The number of bytes written, or \c _LLIO_ERROR on failure.\r
80  */\r
81 size_t __write(int handle, const unsigned char *buffer, size_t size)\r
82 {\r
83         size_t nChars = 0;\r
84 \r
85         if (buffer == 0) {\r
86                 // This means that we should flush internal buffers.\r
87                 return 0;\r
88         }\r
89 \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
93                 return _LLIO_ERROR;\r
94         }\r
95 \r
96         for (; size != 0; --size) {\r
97                 if (ptr_put(stdio_base, *buffer++) < 0) {\r
98                         return _LLIO_ERROR;\r
99                 }\r
100                 ++nChars;\r
101         }\r
102         return nChars;\r
103 }\r
104 \r
105 _STD_END\r
106 \r
107 \r
108 #elif (defined(__GNUC__) && !XMEGA && !MEGA)\r
109 \r
110 int __attribute__((weak))\r
111 _write (int file, const char *ptr, int len);\r
112 \r
113 int __attribute__((weak))\r
114 _write (int file, const char *ptr, int len)\r
115 {\r
116         int nChars = 0;\r
117 \r
118         if ((file != 1) && (file != 2) && (file!=3)) {\r
119                 return -1;\r
120         }\r
121 \r
122         for (; len != 0; --len) {\r
123                 if (ptr_put(stdio_base, *ptr++) < 0) {\r
124                         return -1;\r
125                 }\r
126                 ++nChars;\r
127         }\r
128         return nChars;\r
129 }\r
130 \r
131 #elif (defined(__GNUC__) && (XMEGA || MEGA))\r
132 \r
133 int _write (char c, int *f);\r
134 \r
135 int _write (char c, int *f)\r
136 {\r
137         if (ptr_put(stdio_base, c) < 0) {\r
138                 return -1;\r
139         }\r
140         return 1;\r
141 }\r
142 #endif\r
143 \r
144 /**\r
145  * \}\r
146  */\r
147 \r