OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [RX600_RX62N-RDK_Renesas/] [RTOSDemo/] [Renesas-Files/] [lowsrc.c] - Blame information for rev 596

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 585 jeremybenn
/***********************************************************************/
2
/*                                                                     */
3
/*  FILE        :lowsrc.c                                              */
4
/*  DATE        :Wed, Jun 16, 2010                                     */
5
/*  DESCRIPTION :Program of I/O Stream                                 */
6
/*  CPU TYPE    :Other                                                 */
7
/*                                                                     */
8
/*  This file is generated by Renesas Project Generator (Ver.4.50).    */
9
/*  NOTE:THIS IS A TYPICAL EXAMPLE.                                    */
10
/*                                                                     */
11
/***********************************************************************/
12
 
13
 
14
 
15
/*********************************************************************
16
*
17
* Device     : RX
18
*
19
* File Name  : lowsrc.c
20
*
21
* Abstract   : Program of I/O Stream.
22
*
23
* History    : 1.00  (2009-08-07)
24
*
25
* NOTE       : THIS IS A TYPICAL EXAMPLE.
26
*
27
* Copyright(c) 2009 Renesas Technology Corp.
28
*               And Renesas Solutions Corp.,All Rights Reserved.
29
*
30
*********************************************************************/
31
 
32
#include <string.h>
33
#include <stdio.h>
34
#include <stddef.h>
35
#include "lowsrc.h"
36
 
37
/* file number */
38
#define STDIN  0                    /* Standard input (console)        */
39
#define STDOUT 1                    /* Standard output (console)       */
40
#define STDERR 2                    /* Standard error output (console) */
41
 
42
#define FLMIN  0                    /* Minimum file number     */
43
#define _MOPENR 0x1
44
#define _MOPENW 0x2
45
#define _MOPENA 0x4
46
#define _MTRUNC 0x8
47
#define _MCREAT 0x10
48
#define _MBIN   0x20
49
#define _MEXCL  0x40
50
#define _MALBUF 0x40
51
#define _MALFIL 0x80
52
#define _MEOF   0x100
53
#define _MERR   0x200
54
#define _MLBF   0x400
55
#define _MNBF   0x800
56
#define _MREAD  0x1000
57
#define _MWRITE 0x2000
58
#define _MBYTE  0x4000
59
#define _MWIDE  0x8000
60
/* File Flags */
61
#define O_RDONLY 0x0001 /* Read only                                       */
62
#define O_WRONLY 0x0002 /* Write only                                      */
63
#define O_RDWR   0x0004 /* Both read and Write                             */
64
#define O_CREAT  0x0008 /* A file is created if it is not existed          */
65
#define O_TRUNC  0x0010 /* The file size is changed to 0 if it is existed. */
66
#define O_APPEND 0x0020 /* The position is set for next reading/writing    */
67
                        /* 0: Top of the file 1: End of file               */
68
 
69
/* Special character code */
70
#define CR 0x0d                     /* Carriage return */
71
#define LF 0x0a                     /* Line feed       */
72
 
73
#if defined( __RX )
74
const long _nfiles = IOSTREAM; /* The number of files for input/output files */
75
#else
76
const int _nfiles = IOSTREAM;  /* The number of files for input/output files */
77
#endif
78
char flmod[IOSTREAM];          /* The location for the mode of opened file.  */
79
 
80
unsigned char sml_buf[IOSTREAM];
81
 
82
#define FPATH_STDIN     "C:\\stdin"
83
#define FPATH_STDOUT    "C:\\stdout"
84
#define FPATH_STDERR    "C:\\stderr"
85
 
86
/* H8 Normal mode ,SH and RX */
87
#if defined( __2000N__ ) || defined( __2600N__ ) || defined( __300HN__ ) || defined( _SH )
88
/* Output one character to standard output */
89
extern void charput(char);
90
/* Input one character from standard input */
91
extern char charget(void);
92
/* Output one character to the file        */
93
extern char fcharput(char, unsigned char);
94
/* Input one character from the file       */
95
extern char fcharget(char*, unsigned char);
96
/* Open the file */
97
extern char fileopen(char*, unsigned char, unsigned char*);
98
/* Close the file */
99
extern char fileclose(unsigned char);
100
/* Move the file offset */
101
extern char fpseek(unsigned char, long, unsigned char);
102
/* Get the file offset */
103
extern char fptell(unsigned char, long*);
104
 
105
/* RX */
106
#elif defined( __RX )
107
/* Output one character to standard output */
108
extern void charput(unsigned char);
109
/* Input one character from standard input */
110
extern unsigned char charget(void);
111
 
112
/* H8 Advanced mode */
113
#elif defined( __2000A__ ) || defined( __2600A__ ) || defined( __300HA__ ) || defined( __H8SXN__ ) || defined( __H8SXA__ ) || defined( __H8SXM__ ) || defined( __H8SXX__ )
114
/* Output one character to standard output */
115
extern void charput(char);
116
/* Input one character from standard input */
117
extern char charget(void);
118
/* Output one character to the file        */
119
extern char fcharput(char, unsigned char);
120
/* Input one character from the file       */
121
extern char fcharget(char*, unsigned char);
122
/* Open the file */
123
/* Specified as the number of register which stored paramter is 3 */
124
extern char __regparam3 fileopen(char*, unsigned char, unsigned char*);
125
/* Close the file */
126
extern char fileclose(unsigned char);
127
/* Move the file offset */
128
extern char fpseek(unsigned char, long, unsigned char);
129
/* Get the file offset */
130
extern char fptell(unsigned char, long*);
131
 
132
/* H8300 and H8300L */
133
#elif defined( __300__ ) || defined( __300L__ )
134
/* Output one character to standard output */
135
extern void charput(char);
136
/* Input one character from standard input */
137
extern char charget(void);
138
/* Output one character to the file        */
139
extern char fcharput(char, unsigned char);
140
/* Input one character from the file       */
141
extern char fcharget(char*, unsigned char);
142
/* Open the file */
143
/* Specified as the number of register which stored paramter is 3 */
144
extern char __regparam3 fileopen(char*, unsigned char, unsigned char*);
145
/* Close the file */
146
extern char fileclose(unsigned char);
147
/* Move the file offset */
148
/* Move the file offset */
149
extern char __regparam3 fpseek(unsigned char, long, unsigned char);
150
/* Get the file offset */
151
extern char fptell(unsigned char, long*);
152
#endif
153
 
154
#include <stdio.h>
155
FILE *_Files[IOSTREAM]; // structure for FILE
156
char *env_list[] = {            // Array for environment variables(**environ)
157
    "ENV1=temp01",
158
    "ENV2=temp02",
159
    "ENV9=end",
160
    '\0'                        // Terminal for environment variables
161
};
162
 
163
char **environ = env_list;
164
 
165
/****************************************************************************/
166
/* _INIT_IOLIB                                                              */
167
/*  Initialize C library Functions, if necessary.                           */
168
/*  Define USES_SIMIO on Assembler Option.                                  */
169
/****************************************************************************/
170
void _INIT_IOLIB( void )
171
{
172
    /* A file for standard input/output is opened or created. Each FILE     */
173
    /* structure members are initialized by the library. Each _Buf member   */
174
    /* in it is re-set the end of buffer pointer.                           */
175
 
176
    /* Standard Input File                                                  */
177
    if( freopen( FPATH_STDIN, "r", stdin ) == NULL )
178
        stdin->_Mode = 0xffff;  /* Not allow the access if it fails to open */
179
    stdin->_Mode  = _MOPENR;            /* Read only attribute              */
180
    stdin->_Mode |= _MNBF;              /* Non-buffering for data           */
181
    stdin->_Bend = stdin->_Buf + 1;  /* Re-set pointer to the end of buffer */
182
 
183
    /* Standard Output File                                                 */
184
    if( freopen( FPATH_STDOUT, "w", stdout ) == NULL )
185
        stdout->_Mode = 0xffff; /* Not allow the access if it fails to open */
186
    stdout->_Mode |= _MNBF;             /* Non-buffering for data           */
187
    stdout->_Bend = stdout->_Buf + 1;/* Re-set pointer to the end of buffer */
188
 
189
    /* Standard Error File                                                  */
190
    if( freopen( FPATH_STDERR, "w", stderr ) == NULL )
191
        stderr->_Mode = 0xffff; /* Not allow the access if it fails to open */
192
    stderr->_Mode |= _MNBF;             /* Non-buffering for data           */
193
    stderr->_Bend = stderr->_Buf + 1;/* Re-set pointer to the end of buffer */
194
}
195
 
196
/****************************************************************************/
197
/* _CLOSEALL                                                                */
198
/****************************************************************************/
199
void _CLOSEALL( void )
200
{
201
    long i;
202
 
203
    for( i=0; i < _nfiles; i++ )
204
    {
205
        /* Checks if the file is opened or not                               */
206
        if( _Files[i]->_Mode & (_MOPENR | _MOPENW | _MOPENA ) )
207
        fclose( _Files[i] );    /* Closes the file                           */
208
    }
209
}
210
 
211
/**************************************************************************/
212
/*       open:file open                                                   */
213
/*          Return value:File number (Pass)                               */
214
/*                       -1          (Failure)                            */
215
/**************************************************************************/
216
#if defined( __RX )
217
long open(const char *name,                  /* File name                 */
218
     long  mode,                             /* Open mode                 */
219
     long  flg)                              /* Open flag                 */
220
#else
221
int open(char *name,                         /* File name                 */
222
     int  mode,                              /* Open mode                 */
223
     int  flg)                               /* Open flag                 */
224
#endif
225
{
226
 
227
 
228
    if( strcmp( name, FPATH_STDIN ) == 0 )      /* Standard Input file?   */
229
    {
230
        if( ( mode & O_RDONLY ) == 0 ) return -1;
231
        flmod[STDIN] = mode;
232
        return STDIN;
233
    }
234
    else if( strcmp( name, FPATH_STDOUT ) == 0 )/* Standard Output file?  */
235
    {
236
        if( ( mode & O_WRONLY ) == 0 ) return -1;
237
        flmod[STDOUT] = mode;
238
        return STDOUT;
239
    }
240
    else if(strcmp(name, FPATH_STDERR ) == 0 )  /* Standard Error file?   */
241
    {
242
        if( ( mode & O_WRONLY ) == 0 ) return -1;
243
        flmod[STDERR] = mode;
244
        return STDERR;
245
    }
246
    else return -1;                             /*Others                  */
247
}
248
 
249
#if defined( __RX )
250
long close( long fileno )
251
#else
252
int close( int fileno )
253
#endif
254
{
255
    return 1;
256
}
257
 
258
/**************************************************************************/
259
/* write:Data write                                                       */
260
/*  Return value:Number of write characters (Pass)                        */
261
/*               -1                         (Failure)                     */
262
/**************************************************************************/
263
#if defined( __RX )
264
long write(long  fileno,             /* File number                       */
265
      const unsigned char *buf,       /* The address of destination buffer */
266
      long  count)                   /* The number of chacter to write    */
267
#else
268
int write(int  fileno,               /* File number                       */
269
      char *buf,                     /* The address of destination buffer */
270
      int  count)                    /* The number of chacter to write    */
271
#endif
272
{
273
    long    i;                          /* A variable for counter         */
274
    unsigned char    c;                 /* An output character            */
275
 
276
    /* Checking the mode of file , output each character                  */
277
    /* Checking the attribute for Write-Only, Read-Only or Read-Write     */
278
    if(flmod[fileno]&O_WRONLY || flmod[fileno]&O_RDWR)
279
    {
280
        if( fileno == STDIN ) return -1;            /* Standard Input     */
281
        else if( (fileno == STDOUT) || (fileno == STDERR) )
282
                                                            /* Standard Error/output   */
283
        {
284
            for( i = count; i > 0; --i )
285
            {
286
                c = *buf++;
287
                charput(c);
288
            }
289
            return count;        /*Return the number of written characters */
290
        }
291
        else return -1;                  /* Incorrect file number          */
292
    }
293
    else return -1;                      /* An error                       */
294
}
295
 
296
#if defined( __RX )
297
long read( long fileno, unsigned char *buf, long count )
298
#else
299
int read( int fileno, char *buf, unsigned int count )
300
#endif
301
{
302
           long i;
303
 
304
       /* Checking the file mode with the file number, each character is input and stored the buffer */
305
 
306
       if((flmod[fileno]&_MOPENR) || (flmod[fileno]&O_RDWR)){
307
             for(i = count; i > 0; i--){
308
                   *buf = charget();
309
                   if(*buf==CR){              /* Replace the new line character */
310
                         *buf = LF;
311
                   }
312
                   buf++;
313
             }
314
             return count;
315
       }
316
       else {
317
             return -1;
318
       }
319
}
320
 
321
#if defined( __RX )
322
long lseek( long fileno, long offset, long base )
323
#else
324
long lseek( int fileno, long offset, int base )
325
#endif
326
{
327
    return -1L;
328
}
329
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.