Xmega Application Note | |||||
00001 /*This file is prepared for Doxygen automatic documentation generation.*/ 00016 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00017 * 00018 * Redistribution and use in source and binary forms, with or without 00019 * modification, are permitted provided that the following conditions are met: 00020 * 00021 * 1. Redistributions of source code must retain the above copyright notice, this 00022 * list of conditions and the following disclaimer. 00023 * 00024 * 2. Redistributions in binary form must reproduce the above copyright notice, 00025 * this list of conditions and the following disclaimer in the documentation 00026 * and/or other materials provided with the distribution. 00027 * 00028 * 3. The name of Atmel may not be used to endorse or promote products derived 00029 * from this software without specific prior written permission. 00030 * 00031 * 4. This software may only be redistributed and used in connection with an Atmel 00032 * AVR product. 00033 * 00034 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00035 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00036 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00037 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00038 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00039 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00040 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00041 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00042 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00043 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00044 * 00045 */ 00046 00047 #include "compiler.h" 00048 00049 // IAR common implmentation 00050 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__)) 00051 00052 #include <yfuns.h> 00053 00054 _STD_BEGIN 00055 00056 #pragma module_name = "?__read" 00057 extern volatile void *volatile stdio_base; 00058 void (*ptr_get)(void volatile*,int*); 00059 00070 size_t __read(int handle, unsigned char *buffer, size_t size) 00071 { 00072 int nChars = 0; 00073 // This implementation only reads from stdin. 00074 // For all other file handles, it returns failure. 00075 if (handle != _LLIO_STDIN) { 00076 return _LLIO_ERROR; 00077 } 00078 for (; size > 0; --size) { 00079 int c; 00080 ptr_get(stdio_base,&c); 00081 if (c < 0) 00082 break; 00083 *buffer++ = c; 00084 ++nChars; 00085 } 00086 return nChars; 00087 } 00088 _STD_END 00089 00090 // GCC AVR32 implementation 00091 #elif (defined(__GNUC__) && !defined(XMEGA)) 00092 00093 extern volatile void *volatile stdio_base; 00094 extern void (*ptr_get)(void volatile*,int*); 00095 00096 00097 int __attribute__((weak)) 00098 _read (int file, char * ptr, int len) 00099 { 00100 int nChars = 0; 00101 00102 if (file != 0) 00103 return -1; 00104 00105 for (; len > 0; --len) { 00106 int c; 00107 ptr_get(stdio_base,&c); 00108 if (c < 0) 00109 break; 00110 *ptr++ = c; 00111 ++nChars; 00112 } 00113 return nChars; 00114 } 00115 00116 // GCC AVR implementation 00117 #elif (defined(__GNUC__) && defined(XMEGA)) 00118 00119 extern volatile void *volatile stdio_base; 00120 extern void (*ptr_get)(void volatile*,int*); 00121 int _read (int *f) 00122 { 00123 int c; 00124 ptr_get(stdio_base,&c); 00125 return c; 00126 } 00127 00128 #endif
Generated on Fri Oct 22 12:15:25 2010 for AVR1300 Using the Xmega ADC by ![]() |