1 /**************************** sys_dev.c *********************************/
2 /* Copyright 2003/12/27 Aeolus Development */
3 /* All rights reserved. */
5 /* Redistribution and use in source and binary forms, with or without */
6 /* modification, are permitted provided that the following conditions */
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 */
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. */
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. */
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.
42 //#include "lpc210x.h"
43 #include "dev_cntrl.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 */
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 */
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. */
76 if( file
!= 0) { /* Only one device. */
77 r
->_errno
= EBADF
; /* Bad file number. */
82 *p
= (unsigned char)'a'; /* Dummy operation for now. */
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 */
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. */
113 return (_ssize_t
)len
;
116 /************************** sys_open ************************************/
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 */
123 /* int flags -- Flags to control open. Not used at the */
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. */
131 struct _reent
*r
, /* Re-entrancy structure, used to make */
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 */
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. */
150 return( 0); /* Always sub-handle 0. Note we never */
151 /* fail on this open. */
154 /************************** sys_close ***********************************/
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 */
163 static int sys_close(
164 struct _reent
*r
, /* Re-entrancy structure, used to make */
166 int file
) /* File/device sub handle. */
169 if( file
!= 0) { /* Only one device. */
170 r
->_errno
= EBADF
; /* Bad file number. */
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. */