]> begriffs open source - freertos/blob - portable/IAR/AVR32_UC3/read.c
[AUTO][RELEASE]: Bump file header version to "10.5.1"
[freertos] / portable / IAR / AVR32_UC3 / read.c
1 /*\r
2  * FreeRTOS Kernel V10.5.1\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT AND BSD-3-Clause\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 /*This file is prepared for Doxygen automatic documentation generation.*/\r
30 /*! \file *********************************************************************\r
31  *\r
32  * \brief System-specific implementation of the \ref __read function used by\r
33           the standard library.\r
34  *\r
35  * - Compiler:           IAR EWAVR32\r
36  * - Supported devices:  All AVR32 devices with a USART module can be used.\r
37  * - AppNote:\r
38  *\r
39  * \author               Atmel Corporation (Now Microchip):\r
40  *                                        https://www.microchip.com \n\r
41  *                       Support and FAQ: https://www.microchip.com/support/\r
42  *\r
43  ******************************************************************************/\r
44 \r
45 /*\r
46  * Copyright (c) 2007, Atmel Corporation All rights reserved.\r
47  *\r
48  * Redistribution and use in source and binary forms, with or without\r
49  * modification, are permitted provided that the following conditions are met:\r
50  *\r
51  * 1. Redistributions of source code must retain the above copyright notice,\r
52  * this list of conditions and the following disclaimer.\r
53  *\r
54  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
55  * this list of conditions and the following disclaimer in the documentation\r
56  * and/or other materials provided with the distribution.\r
57  *\r
58  * 3. The name of ATMEL may not be used to endorse or promote products derived\r
59  * from this software without specific prior written permission.\r
60  *\r
61  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
62  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
63  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND\r
64  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,\r
65  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
66  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
67  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
68  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
69  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
70  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
71  */\r
72 \r
73 \r
74 #include <yfuns.h>\r
75 #include <avr32/io.h>\r
76 #include "usart.h"\r
77 \r
78 \r
79 _STD_BEGIN\r
80 \r
81 \r
82 #pragma module_name = "?__read"\r
83 \r
84 \r
85 extern volatile avr32_usart_t *volatile stdio_usart_base;\r
86 \r
87 \r
88 /*! \brief Reads a number of bytes, at most \a size, into the memory area\r
89  *         pointed to by \a buffer.\r
90  *\r
91  * \param handle File handle to read from.\r
92  * \param buffer Pointer to buffer to write read bytes to.\r
93  * \param size Number of bytes to read.\r
94  *\r
95  * \return The number of bytes read, \c 0 at the end of the file, or\r
96  *         \c _LLIO_ERROR on failure.\r
97  */\r
98 size_t __read(int handle, uint8_t *buffer, size_t size)\r
99 {\r
100   int nChars = 0;\r
101 \r
102   // This implementation only reads from stdin.\r
103   // For all other file handles, it returns failure.\r
104   if (handle != _LLIO_STDIN)\r
105   {\r
106     return _LLIO_ERROR;\r
107   }\r
108 \r
109   for (; size > 0; --size)\r
110   {\r
111     int c = usart_getchar(stdio_usart_base);\r
112     if (c < 0)\r
113       break;\r
114 \r
115     *buffer++ = c;\r
116     ++nChars;\r
117   }\r
118 \r
119   return nChars;\r
120 }\r
121 \r
122 \r
123 _STD_END\r