f4b4e4f5d0f98c8d9a353aa3e02b70b92e685b5c
[fw/sdcc] / device / include / pic16 / stdio.h
1 /*-------------------------------------------------------------------------
2   stdio.h - ANSI functions forward declarations
3
4    Ported to PIC16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
5    
6              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
7
8    This program is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published by the
10    Free Software Foundation; either version 2, or (at your option) any
11    later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22    In other words, you are welcome to use, share and improve this program.
23    You are forbidden to forbid anyone else to use, share and improve
24    what you give them.   Help stamp out software-hoarding!
25 -------------------------------------------------------------------------*/
26
27 /*
28 ** $Id$
29 */
30
31 #ifndef __STDIO_H
32 #define __STDIO_H 1
33
34 /* link the C library */
35 #pragma library c
36
37 #include <stdarg.h>
38
39 #include <sdcc-lib.h>
40
41 #ifndef NULL
42   #define NULL (void *)0
43 #endif
44
45 #ifndef _SIZE_T_DEFINED
46 #define _SIZE_T_DEFINED
47   typedef unsigned int size_t;
48 #endif
49
50
51 /* stream descriptor definition */
52 typedef char *FILE;
53
54
55 /* USART and MSSP module stream descriptors */
56
57 /* since FILE is declared as a generic pointer,
58  * the upper byte is used to dereference the pointer
59  * information. For the stream descriptors we
60  * use the 5th bit and the lower nubble bits.
61  * Descriptors are denoted by an 1 in bit 5,
62  * further dereference is made for:
63  * <stream>     <3:0> bits
64  *     USART     0 (0x0)
65  *     MSSP      1 (0x1)
66  *     USER     15 (0xf)
67  *
68  * There is a special value for GPSIM specific (see below)
69  * which is:
70  *     GPSIM    14 (0xe)
71  *
72  *
73  * if further stream descriptors need to be added then more
74  * bits of the upper byte can be used
75  */
76
77
78 #define USART_DEREF     0x0
79 #define MSSP_DEREF      0x1
80 #define USER_DEREF      0xf
81
82 #define STREAM_USART    ((FILE *)(0x00200000UL))
83 #define STREAM_MSSP     ((FILE *)(0x00210000UL))
84 #define STREAM_USER     ((FILE *)(0x002f0000UL))
85
86
87 /* this is a custom dereference which points to a custom
88  * port of GPSIM simulator. This port redirects characters
89  * to /tmp/gpsim.debug.1 file (used for debugging purposes)
90  * NOTICE: This feature is not part of the official gpsim
91  * distribution. Contact vrokas AT users.sourceforge.net
92  * for more info */
93 #define GPSIM_DEREF     0xe
94 #define STREAM_GPSIM    ((FILE *)(0x002e0000UL))
95
96 extern FILE * stdin;
97 extern FILE * stdout;
98
99 //typedef void (*pfn_outputchar)(char c, void* p) _REENTRANT;
100 //extern int _print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap);
101
102 /* printf_small() supports float print */
103 void printf_small(char *, ...);
104
105 /* printf_tiny() does not support float print */
106 void printf_tiny(char *, ...);  // __reentrant;
107
108 extern unsigned int printf (char *,...);
109 extern unsigned int sprintf (char *, char *, ...);
110 extern unsigned int fprintf(FILE *, char *, ...);
111
112 extern unsigned int vsprintf (char *, char *, va_list);
113 extern unsigned int vprintf (char *, va_list);
114 extern unsigned int vfprintf(FILE *, char *, va_list);
115
116 extern int puts(char *);
117
118 extern void __stream_putchar(FILE *, unsigned char);
119
120 #define PUTCHAR(arg)    void putchar(unsigned char arg) __wparam
121 extern PUTCHAR(c);
122
123 extern void __stream_usart_putchar(unsigned char c) __wparam __naked;
124 extern void __stream_mssp_putchar(unsigned char c) __wparam __naked;
125 extern void __stream_gpsim_putchar(unsigned char c) __wparam __naked;
126
127 extern char *gets(char *);
128 extern char getchar(void);
129
130 #endif /* __STDIO_H */