]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/src/ASF/common/utils/stdio/read.c
Rename DummyTCB_t to StaticTCB_t.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAME70_Xplained_AtmelStudio / src / ASF / common / utils / stdio / read.c
1 /**\r
2  * \file\r
3  *\r
4  * \brief System-specific implementation of the \ref _read 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  * \defgroup group_common_utils_stdio Standard I/O (stdio)\r
52  *\r
53  * Common standard I/O driver that implements the stdio\r
54  * read and write functions on AVR and SAM devices.\r
55  *\r
56  * \{\r
57  */\r
58 \r
59 extern volatile void *volatile stdio_base;\r
60 void (*ptr_get)(void volatile*, char*);\r
61 \r
62 \r
63 // IAR common implementation\r
64 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__) || defined(__ICCARM__) )\r
65 \r
66 #include <yfuns.h>\r
67 \r
68 _STD_BEGIN\r
69 \r
70 #pragma module_name = "?__read"\r
71 \r
72 /*! \brief Reads a number of bytes, at most \a size, into the memory area\r
73  *         pointed to by \a buffer.\r
74  *\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
78  *\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
81  */\r
82 size_t __read(int handle, unsigned char *buffer, size_t size)\r
83 {\r
84         int nChars = 0;\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
88                 return _LLIO_ERROR;\r
89         }\r
90         for (; size > 0; --size) {\r
91                 ptr_get(stdio_base, (char*)buffer);\r
92                 buffer++;\r
93                 nChars++;\r
94         }\r
95         return nChars;\r
96 }\r
97 \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
100  */\r
101 int __close(int handle)\r
102 {\r
103         UNUSED(handle);\r
104         return 0;\r
105 }\r
106 \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
109  */\r
110 int remove(const char* val)\r
111 {\r
112         UNUSED(val);\r
113         return 0;\r
114 }\r
115 \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
118  */\r
119 long __lseek(int handle, long val, int val2)\r
120 {\r
121         UNUSED(handle);\r
122         UNUSED(val2);\r
123         return val;\r
124 }\r
125 \r
126 _STD_END\r
127 \r
128 // GCC AVR32 and SAM implementation\r
129 #elif (defined(__GNUC__) && !XMEGA && !MEGA) \r
130 \r
131 int __attribute__((weak))\r
132 _read (int file, char * ptr, int len); // Remove GCC compiler warning\r
133 \r
134 int __attribute__((weak))\r
135 _read (int file, char * ptr, int len)\r
136 {\r
137         int nChars = 0;\r
138 \r
139         if (file != 0) {\r
140                 return -1;\r
141         }\r
142 \r
143         for (; len > 0; --len) {\r
144                 ptr_get(stdio_base, ptr);\r
145                 ptr++;\r
146                 nChars++;\r
147         }\r
148         return nChars;\r
149 }\r
150 \r
151 // GCC AVR implementation\r
152 #elif (defined(__GNUC__) && (XMEGA || MEGA) )\r
153 \r
154 int _read (int *f); // Remove GCC compiler warning\r
155 \r
156 int _read (int *f)\r
157 {\r
158         char c;\r
159         ptr_get(stdio_base,&c);\r
160         return c;\r
161 }\r
162 #endif\r
163 \r
164 /**\r
165  * \}\r
166  */\r
167 \r