* src/pic16/device.c (Pics16[]): added devices 18F2550, 18F4331,
[fw/sdcc] / device / include / pic16 / stdio.h
index 22cecd5699913723b75ef5481f248f38252ef56e..35f0be68bee4dd9687b0a0e040cb17c6eb244898 100644 (file)
   typedef unsigned int size_t;
 #endif
 
-//typedef void (*pfn_outputchar)(char c, void* p) _REENTRANT;
 
-//extern int _print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap);
+/* stream descriptor definition */
+typedef char *FILE;
+
+
+/* USART and MSSP module stream descriptors */
+
+/* since FILE is declared as a generic pointer,
+ * the upper byte is used to dereference the pointer
+ * information. For the stream descriptors we
+ * use the 5th bit and the lower nubble bits.
+ * Descriptors are denoted by an 1 in bit 5,
+ * further dereference is made for:
+ * <stream>     <3:0> bits
+ *     USART    0 (0x0)
+ *     MSSP      1 (0x1)
+ *     USER     15 (0xf)
+ *
+ * There is a special value for GPSIM specific (see below)
+ * which is:
+ *     GPSIM    14 (0xe)
+ *
+ *
+ * if further stream descriptors need to be added then more
+ * bits of the upper byte can be used
+ */
+
+
+#define USART_DEREF    0x0
+#define MSSP_DEREF     0x1
+#define USER_DEREF     0xf
+
+#define STREAM_USART   ((FILE *)(0x00200000UL))
+#define STREAM_MSSP    ((FILE *)(0x00210000UL))
+#define STREAM_USER    ((FILE *)(0x002f0000UL))
+
+
+/* this is a custom dereference which points to a custom
+ * port of GPSIM simulator. This port redirects characters
+ * to /tmp/gpsim.debug.1 file (used for debugging purposes)
+ * NOTICE: This feature is not part of the official gpsim
+ * distribution. Contact vrokas AT users.sourceforge.net
+ * for more info */
+#define GPSIM_DEREF    0xe
+#define STREAM_GPSIM   ((FILE *)(0x002e0000UL))
+
+extern FILE * stdin;
+extern FILE * stdout;
 
-/*-----------------------------------------------------------------------*/
+//typedef void (*pfn_outputchar)(char c, void* p) _REENTRANT;
+//extern int _print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap);
 
 /* printf_small() supports float print */
 extern void printf_small(char *, ...);
 
 /* printf_tiny() does not support float print */
-extern void printf_tiny(char *, ...);
+extern void printf_tiny(char *, ...) reentrant;
 
-extern int printf (char *,...);
-extern int vprintf (char *, va_list);
+extern unsigned int printf (char *,...);
+extern unsigned int sprintf (char *, char *, ...);
+extern unsigned int fprintf(FILE *, char *, ...);
 
-extern int sprintf (char *, const char *, ...);
-extern int vsprintf (char *, const char *, va_list);
+extern unsigned int vsprintf (char *, char *, va_list);
+extern unsigned int vprintf (char *, va_list);
+extern unsigned int vfprintf(FILE *, char *, va_list);
 
 extern int puts(char *);
 
-#pragma wparam putchar
-extern void putchar(char);
+extern void __stream_putchar(FILE *, unsigned char);
+
+#define PUTCHAR(arg)   void putchar(unsigned char arg) wparam
+extern PUTCHAR(c);
+
+extern void __stream_usart_putchar(unsigned char c) _naked wparam;
+extern void __stream_mssp_putchar(unsigned char c) _naked wparam;
+extern void __stream_gpsim_putchar(unsigned char c) _naked wparam;
 
 extern char *gets(char *);
 extern char getchar(void);