123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- #include "r_bsp_config.h"
- #if (BSP_CFG_STARTUP_DISABLE == 0)
- #if (BSP_CFG_IO_LIB_ENABLE == 1)
- #if defined(__CCRX__)
- #include <string.h>
- #include "platform.h"
- #define IOSTREAM 20
- #define STDIN 0
- #define STDOUT 1
- #define STDERR 2
- #define FLMIN 0
- #define _MOPENR 0x1
- #define _MOPENW 0x2
- #define _MOPENA 0x4
- #define _MTRUNC 0x8
- #define _MCREAT 0x10
- #define _MBIN 0x20
- #define _MEXCL 0x40
- #define _MALBUF 0x40
- #define _MALFIL 0x80
- #define _MEOF 0x100
- #define _MERR 0x200
- #define _MLBF 0x400
- #define _MNBF 0x800
- #define _MREAD 0x1000
- #define _MWRITE 0x2000
- #define _MBYTE 0x4000
- #define _MWIDE 0x8000
- #define O_RDONLY 0x0001
- #define O_WRONLY 0x0002
- #define O_RDWR 0x0004
- #define O_CREAT 0x0008
- #define O_TRUNC 0x0010
- #define O_APPEND 0x0020
-
- #define CR 0x0d
- #define LF 0x0a
- #if defined( __RX )
- const long _nfiles = IOSTREAM;
- #else
- const int _nfiles = IOSTREAM;
- #endif
- char flmod[IOSTREAM];
- unsigned char sml_buf[IOSTREAM];
- #define FPATH_STDIN "C:\\stdin"
- #define FPATH_STDOUT "C:\\stdout"
- #define FPATH_STDERR "C:\\stderr"
- #if defined( __2000N__ ) || defined( __2600N__ ) || defined( __300HN__ ) || defined( _SH )
- extern void charput(char);
- extern char charget(void);
- extern char fcharput(char, unsigned char);
- extern char fcharget(char*, unsigned char);
- extern char fileopen(char*, unsigned char, unsigned char*);
- extern char fileclose(unsigned char);
- extern char fpseek(unsigned char, long, unsigned char);
- extern char fptell(unsigned char, long*);
- #elif defined( __RX )
- extern void charput(uint32_t);
- extern uint32_t charget(void);
- #elif defined( __2000A__ ) || defined( __2600A__ ) || defined( __300HA__ ) || defined( __H8SXN__ ) || defined( __H8SXA__ ) || defined( __H8SXM__ ) || defined( __H8SXX__ )
- extern void charput(char);
- extern char charget(void);
- extern char fcharput(char, unsigned char);
- extern char fcharget(char*, unsigned char);
- extern char __regparam3 fileopen(char*, unsigned char, unsigned char*);
- extern char fileclose(unsigned char);
- extern char fpseek(unsigned char, long, unsigned char);
- extern char fptell(unsigned char, long*);
- #elif defined( __300__ ) || defined( __300L__ )
- extern void charput(char);
- extern char charget(void);
- extern char fcharput(char, unsigned char);
- extern char fcharget(char*, unsigned char);
- extern char __regparam3 fileopen(char*, unsigned char, unsigned char*);
- extern char fileclose(unsigned char);
- extern char __regparam3 fpseek(unsigned char, long, unsigned char);
- extern char fptell(unsigned char, long*);
- #endif
- #include <stdio.h>
- FILE *_Files[IOSTREAM];
- char *env_list[] = {
- "ENV1=temp01",
- "ENV2=temp02",
- "ENV9=end",
- '\0'
- };
- char **environ = env_list;
- #define INTERNAL_NOT_USED(p) ((void)(p))
- void _INIT_IOLIB( void )
- {
-
-
-
-
- if( freopen( FPATH_STDIN, "r", stdin ) == NULL )
- {
- stdin->_Mode = 0xffff;
- }
- stdin->_Mode = _MOPENR;
- stdin->_Mode |= _MNBF;
- stdin->_Bend = stdin->_Buf + 1;
-
- if( freopen( FPATH_STDOUT, "w", stdout ) == NULL )
- {
- stdout->_Mode = 0xffff;
- }
- stdout->_Mode |= _MNBF;
- stdout->_Bend = stdout->_Buf + 1;
-
-
- if( freopen( FPATH_STDERR, "w", stderr ) == NULL )
- {
- stderr->_Mode = 0xffff;
- }
- stderr->_Mode |= _MNBF;
- stderr->_Bend = stderr->_Buf + 1;
- }
- void _CLOSEALL( void )
- {
- long i;
- for( i=0; i < _nfiles; i++ )
- {
-
- if( _Files[i]->_Mode & (_MOPENR | _MOPENW | _MOPENA ) )
- {
- fclose( _Files[i] );
- }
- }
- }
- #if defined( __RX )
- long open(const char *name,
- long mode,
- long flg)
- #else
- int open(char *name,
- int mode,
- int flg)
- #endif
- {
-
- INTERNAL_NOT_USED(flg);
- if( strcmp( name, FPATH_STDIN ) == 0 )
- {
- if( ( mode & O_RDONLY ) == 0 )
- {
- return -1;
- }
- flmod[STDIN] = (char)mode;
- return STDIN;
- }
- else if( strcmp( name, FPATH_STDOUT ) == 0 )
- {
- if( ( mode & O_WRONLY ) == 0 )
- {
- return -1;
- }
- flmod[STDOUT] = (char)mode;
- return STDOUT;
- }
- else if(strcmp(name, FPATH_STDERR ) == 0 )
- {
- if( ( mode & O_WRONLY ) == 0 )
- {
- return -1;
- }
- flmod[STDERR] = (char)mode;
- return STDERR;
- }
- else
- {
- return -1;
- }
- }
- #if defined( __RX )
- long close( long fileno )
- #else
- int close( int fileno )
- #endif
- {
-
- INTERNAL_NOT_USED(fileno);
- return 1;
- }
- #if defined( __RX )
- long write(long fileno,
- const unsigned char *buf,
- long count)
- #else
- int write(int fileno,
- char *buf,
- int count)
- #endif
- {
- long i;
- unsigned char c;
-
-
- if((flmod[fileno]&O_WRONLY) || (flmod[fileno]&O_RDWR))
- {
- if( fileno == STDIN )
- {
- return -1;
- }
- else if( (fileno == STDOUT) || (fileno == STDERR) )
-
- {
- for( i = count; i > 0; --i )
- {
- c = *buf++;
- charput(c);
- }
- return count;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- #if defined( __RX )
- long read( long fileno, unsigned char *buf, long count )
- #else
- int read( int fileno, char *buf, unsigned int count )
- #endif
- {
- long i;
-
- if((flmod[fileno]&_MOPENR) || (flmod[fileno]&O_RDWR))
- {
- for(i = count; i > 0; i--)
- {
- *buf = charget();
- if(*buf==CR)
- {
- *buf = LF;
- }
- buf++;
- }
- return count;
- }
- else
- {
- return -1;
- }
- }
- #if defined( __RX )
- long lseek( long fileno, long offset, long base )
- #else
- long lseek( int fileno, long offset, int base )
- #endif
- {
-
- INTERNAL_NOT_USED(fileno);
- INTERNAL_NOT_USED(offset);
- INTERNAL_NOT_USED(base);
- return -1L;
- }
- #endif
- #endif
- #endif
|