ld scripts moved to arch subdirectory.
[LPC2xxx_and_RobotSpejbl.git] / app / arm / armtest_clk / sys_dev.c
blobe168508e0a6d4190f107d63a76b8558556ad80ca
1 /**************************** sys_dev.c *********************************/
2 /* Copyright 2003/12/27 Aeolus Development */
3 /* All rights reserved. */
4 /* */
5 /* Redistribution and use in source and binary forms, with or without */
6 /* modification, are permitted provided that the following conditions */
7 /* are met: */
8 /* 1. Redistributions of source code must retain the above copyright */
9 /* notice, this list of conditions and the following disclaimer. */
10 /* 2. Redistributions in binary form must reproduce the above copyright */
11 /* notice, this list of conditions and the following disclaimer in the*/
12 /* documentation and/or other materials provided with the */
13 /* distribution. */
14 /* 3. The name of the Aeolus Development or its contributors may not be */
15 /* used to endorse or promote products derived from this software */
16 /* without specific prior written permission. */
17 /* */
18 /* THIS SOFTWARE IS PROVIDED BY THE AEOULUS DEVELOPMENT "AS IS" AND ANY */
19 /* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */
20 /* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
21 /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AEOLUS DEVELOPMENT BE */
22 /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */
23 /* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */
24 /* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
25 /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,*/
26 /* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */
27 /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
28 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /* System device. Right now mostly a place holder. */
31 /* Provides hooks needed to work as a device driver. */
32 /* Note: All the actual routines are private to this module. The only */
33 /* element publically visible is the device table entry structure. */
34 /************************************************************************/
36 * TLIB revision history:
37 * 1 sys_dev.c 30-Dec-2003,10:34:12,`RADSETT' First archival version.
38 * TLIB revision history ends.
40 #include <errno.h>
41 #include <limits.h>
42 //#include "lpc210x.h"
43 #include "dev_cntrl.h"
44 #include <stdio.h>
46 /**** Local Prototypes ****/
47 static _ssize_t sys_read ( struct _reent *r, int file, void *ptr, size_t len);
48 static _ssize_t sys_write ( struct _reent *r, int file, const void *ptr, size_t len);
49 static int sys_open( struct _reent *r, const char *name, int o_flags, int o_mode);
50 static int sys_close( struct _reent *r, int file);
52 /************************** sys_read ************************************/
53 /* Reads from 'sys'. */
54 /* struct _reent *r -- re-entrancy structure, used by newlib to */
55 /* support multiple threads of operation. */
56 /* int file -- number referring to the open file. Generally */
57 /* obtained from a corresponding call to open. */
58 /* Only one file number (0) is supported. */
59 /* void *ptr -- memory area to place read bytes into. */
60 /* size_t len -- maximum number of bytes to read. */
61 /* Note: will only return a single byte on every call. That byte is */
62 /* just a dummy. */
63 /* Returns number of bytes read. (_ssize_t)-1 on error. */
64 /*lint -e{715} multiple arguments not referenced since this is */
65 /* basically a placeholder. */
66 static _ssize_t sys_read (
67 struct _reent *r, /* Re-entrancy structure, used to make */
68 /* thread safe. */
69 int file, /* File handle. Used to distinguish */
70 /* multiple instances. */
71 void *ptr, /* Where to place data. */
72 size_t len) /* Max data to read. */
74 unsigned char *p;
76 if( file != 0) { /* Only one device. */
77 r->_errno = EBADF; /* Bad file number. */
78 return (_ssize_t)-1;
81 p = ptr;
82 *p = (unsigned char)'a'; /* Dummy operation for now. */
83 return (_ssize_t)1;
86 /************************** sys_write ***********************************/
87 /* Writes to 'sys'. */
88 /* struct _reent *r -- re-entrancy structure, used by newlib to */
89 /* support multiple threads of operation. */
90 /* int file -- number referring to the open file. Generally */
91 /* obtained from a corresponding call to open. */
92 /* Only one file number (0) is supported. */
93 /* const void *ptr -- memory area to place read bytes from. */
94 /* size_t len -- maximum number of bytes to write. */
95 /* Returns number of bytes written. (_ssize_t)-1 on error. */
96 /* Note: simply returns indicating it wrote everything requested. IE */
97 /*lint -e{715} multiple arguments not referenced since this is */
98 /* basically a placeholder. */
99 static _ssize_t sys_write (
100 struct _reent *r, /* Re-entrancy structure, used to make */
101 /* thread safe. */
102 int file, /* File handle. Used to distinguish */
103 /* multiple instances. */
104 const void *ptr, /* Pointer to data to write. */
105 size_t len) /* Amount of data to write. */
108 if( file != 0) { /* Only one device. */
109 r->_errno = EBADF; /* Bad file number. */
110 return (_ssize_t)-1;
113 return (_ssize_t)len;
116 /************************** sys_open ************************************/
117 /* Opens 'sys' */
118 /* struct _reent *r -- re-entrancy structure, used by newlib to */
119 /* support multiple threads of operation. */
120 /* const char *name -- name of file/device to open. Since sys */
121 /* supports no sub devices this should be an empty */
122 /* string. */
123 /* int flags -- Flags to control open. Not used at the */
124 /* moment. */
125 /* int mode -- Mode to open in. Not used at the moment. */
126 /* Returns file number >= 0 if successful. Otherwise the error code */
127 /* may be found in errno. */
128 /*lint -e{715} multiple arguments not referenced since this is */
129 /* basically a placeholder. */
130 static int sys_open(
131 struct _reent *r, /* Re-entrancy structure, used to make */
132 /* thread safe. */
133 const char *name, /* Name to open. */
134 int o_flags, /* Flags to control open. */
135 /* Read, write binary etc... */
136 /* See flags.c for values generated by */
137 /* newlib. */
138 int o_mode) /* Mode to open in. This is a */
139 /* security or permissions value. */
140 /* Newlib uses the classic 0666 for all */
141 /* fopens. See fopen.c */
144 /* Check against null pointer. Also no sub-devices available */
145 /* so make sure we aren't asked to open one. */
146 if( (name == 0) || (*name != '\0')) {
147 r->_errno = ENOENT; /* No such file or directory. */
148 return( -1);
150 return( 0); /* Always sub-handle 0. Note we never */
151 /* fail on this open. */
154 /************************** sys_close ***********************************/
155 /* Close sys. */
156 /* struct _reent *r -- re-entrancy structure, used by newlib to */
157 /* support multiple threads of operation. */
158 /* int file -- number referring to the open file. Generally */
159 /* obtained from a corresponding call to open. */
160 /* Only one file number (0) is supported. */
161 /* Returns 0 if successful. Otherwise the error code may be found in */
162 /* errno. */
163 static int sys_close(
164 struct _reent *r, /* Re-entrancy structure, used to make */
165 /* thread safe. */
166 int file) /* File/device sub handle. */
169 if( file != 0) { /* Only one device. */
170 r->_errno = EBADF; /* Bad file number. */
171 return -1;
173 return( 0); /* Always succeeds. */
176 /************************** sys *****************************************/
177 /* Device table entry used to add this device. */
178 const struct device_table_entry sys = {
179 "sys", /* Device name. */
180 sys_open, /* Open method. */
181 sys_close, /* Close method. */
182 sys_read, /* Read method. */
183 sys_write, /* Write method. */
184 0 }; /* ioctl not supported. */