ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 /* 00027 * **** This file incorporates work covered by the following copyright and **** 00028 * **** permission notice: **** 00029 * 00030 * Copyright (c) 2009 by Michael Fischer. All rights reserved. 00031 * 00032 * Redistribution and use in source and binary forms, with or without 00033 * modification, are permitted provided that the following conditions 00034 * are met: 00035 * 00036 * 1. Redistributions of source code must retain the above copyright 00037 * notice, this list of conditions and the following disclaimer. 00038 * 2. Redistributions in binary form must reproduce the above copyright 00039 * notice, this list of conditions and the following disclaimer in the 00040 * documentation and/or other materials provided with the distribution. 00041 * 3. Neither the name of the author nor the names of its contributors may 00042 * be used to endorse or promote products derived from this software 00043 * without specific prior written permission. 00044 * 00045 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00046 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00047 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00048 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00049 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00050 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00051 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00052 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00053 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00054 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00055 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00056 * SUCH DAMAGE. 00057 * 00058 **************************************************************************** 00059 * History: 00060 * 00061 * 28.03.09 mifi First Version, based on the original syscall.c from 00062 * newlib version 1.17.0 00063 * 17.08.09 gdisirio Modified the file for use under ChibiOS/RT 00064 * 15.11.09 gdisirio Added read and write handling 00065 ****************************************************************************/ 00066 00067 #include <stdlib.h> 00068 #include <errno.h> 00069 #include <string.h> 00070 #include <sys/stat.h> 00071 #include <sys/types.h> 00072 00073 #include "ch.h" 00074 #if defined(STDOUT_SD) || defined(STDIN_SD) 00075 #include "hal.h" 00076 #endif 00077 00078 /***************************************************************************/ 00079 00080 int _read_r(struct _reent *r, int file, char * ptr, int len) 00081 { 00082 (void)r; 00083 #if defined(STDIN_SD) 00084 if (!len || (file != 0)) { 00085 __errno_r(r) = EINVAL; 00086 return -1; 00087 } 00088 len = sdRead(&STDIN_SD, (uint8_t *)ptr, (size_t)len); 00089 return len; 00090 #else 00091 (void)file; 00092 (void)ptr; 00093 (void)len; 00094 __errno_r(r) = EINVAL; 00095 return -1; 00096 #endif 00097 } 00098 00099 /***************************************************************************/ 00100 00101 int _lseek_r(struct _reent *r, int file, int ptr, int dir) 00102 { 00103 (void)r; 00104 (void)file; 00105 (void)ptr; 00106 (void)dir; 00107 00108 return 0; 00109 } 00110 00111 /***************************************************************************/ 00112 00113 int _write_r(struct _reent *r, int file, char * ptr, int len) 00114 { 00115 (void)r; 00116 (void)file; 00117 (void)ptr; 00118 #if defined(STDOUT_SD) 00119 if (file != 1) { 00120 __errno_r(r) = EINVAL; 00121 return -1; 00122 } 00123 sdWrite(&STDOUT_SD, (uint8_t *)ptr, (size_t)len); 00124 #endif 00125 return len; 00126 } 00127 00128 /***************************************************************************/ 00129 00130 int _close_r(struct _reent *r, int file) 00131 { 00132 (void)r; 00133 (void)file; 00134 00135 return 0; 00136 } 00137 00138 /***************************************************************************/ 00139 00140 caddr_t _sbrk_r(struct _reent *r, int incr) 00141 { 00142 void *p; 00143 00144 chDbgCheck(incr > 0, "_sbrk_r"); 00145 00146 (void)r; 00147 p = chCoreAlloc((size_t)incr); 00148 if (p == NULL) { 00149 __errno_r(r) = ENOMEM; 00150 return (caddr_t)-1; 00151 } 00152 return (caddr_t)p; 00153 } 00154 00155 /***************************************************************************/ 00156 00157 int _fstat_r(struct _reent *r, int file, struct stat * st) 00158 { 00159 (void)r; 00160 (void)file; 00161 00162 memset(st, 0, sizeof(*st)); 00163 st->st_mode = S_IFCHR; 00164 return 0; 00165 } 00166 00167 /***************************************************************************/ 00168 00169 int _isatty_r(struct _reent *r, int fd) 00170 { 00171 (void)r; 00172 (void)fd; 00173 00174 return 1; 00175 } 00176 00177 /*** EOF ***/