* .version: bumped version number to 2.4.8
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 22 Jan 2005 18:02:16 +0000 (18:02 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 22 Jan 2005 18:02:16 +0000 (18:02 +0000)
* device/lib/pic16/pics.all: list of PIC18F devices supported by
pic16 port,
* device/lib/pic16/libio/i2c/: I2C module support library,
* device/include/pic16/i2c.h: I2C support library header,
* device/lib/pic16/libc/stdio/: standard IO support sources,
* (printf_small.c): printf_small() source, supports float print,
* (printf_tiny.c): printf_tiny() source, does not support floats,
* device/lib/pic16/Makefile.common.in: added OPT_FLAGS macro to
enable global optimizations for entire library source, other
Makefiles in the source tree are also modified to reflect this,
* device/lib/pic16/libc/stdlib/putchar.c (putchar): dummy putchar()
function,
* doc/sdccman.lyx: updated to reflect new changes,
* src/pic16/gen.c (aopForSym): don't handle sym->iaccess in
sym->onStack if-case,
* src/pic16/main.c (_pic16_keywords): commented out keywords bit,
sbit, idata, _idata, xdata, _xdata,
* added pragma library, to link an external library, (see doc),
* removed command line options, --pomit-config-words, --pomit-ivt,
--pleave-reset-vector,
* (pic16_finaliseOptions): when define macro SDCC_MODEL_{SMALL/LARGE}
when calling assembler to reflect memory model used, also define
macro STACK_MODEL_{SMALL/LARGE} when compiling and assembling to
reflect stack model used,
* src/pic16/ralloc.c (pic16_allocDirReg): when operand is allocated
on stack return NULL,

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3648 4a8a32a2-be11-0410-ad9d-d568d2c75423

49 files changed:
.version
ChangeLog
device/include/pic16/adc.h
device/include/pic16/ctype.h
device/include/pic16/gstack.h
device/include/pic16/i2c.h [new file with mode: 0644]
device/include/pic16/malloc.h
device/include/pic16/math.h
device/include/pic16/stdio.h
device/include/pic16/stdlib.h
device/lib/pic16/Makefile
device/lib/pic16/Makefile.common.in
device/lib/pic16/configure
device/lib/pic16/configure.in
device/lib/pic16/debug/Makefile.rules
device/lib/pic16/libc/Makefile
device/lib/pic16/libc/Makefile.rules
device/lib/pic16/libc/stdio/Makefile [new file with mode: 0644]
device/lib/pic16/libc/stdio/printf_small.c [new file with mode: 0644]
device/lib/pic16/libc/stdlib/Makefile
device/lib/pic16/libc/stdlib/ltoa.c
device/lib/pic16/libc/stdlib/putchar.c [new file with mode: 0644]
device/lib/pic16/libdev/Makefile
device/lib/pic16/libio/Makefile
device/lib/pic16/libio/Makefile.rules
device/lib/pic16/libio/i2c/Makefile [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cack.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cclose.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cdrdy.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cidle.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cnack.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2copen.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2creadc.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2creads.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2crestart.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cstart.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cstop.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cwritec.c [new file with mode: 0644]
device/lib/pic16/libio/i2c/i2cwrites.c [new file with mode: 0644]
device/lib/pic16/libsdcc/Makefile
device/lib/pic16/libsdcc/Makefile.rules
device/lib/pic16/libsdcc/float/Makefile
device/lib/pic16/pics.all [new file with mode: 0644]
device/lib/pic16/startup/crt0i.c
doc/sdccman.lyx
src/clean.mk
src/pic16/gen.c
src/pic16/main.c
src/pic16/ralloc.c

index e30309f735e40c4eb0347dc467f7dc970cf574c3..f041bc6dba218c58ccee9b909685a8c1db543b0f 100644 (file)
--- a/.version
+++ b/.version
@@ -1 +1 @@
-2.4.7
+2.4.8
index 2d4c75d4f148ed34ff80313b5e19615e2d361fce..5fe897c46a95a6a645802e2901baa817bdf08457 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2005-01-22 Vangelis Rokas <vrokas AT otenet.gr>
+
+       * .version: bumped version number to 2.4.8
+       * device/lib/pic16/pics.all: list of PIC18F devices supported by
+       pic16 port,
+       * device/lib/pic16/libio/i2c/: I2C module support library,
+       * device/include/pic16/i2c.h: I2C support library header,
+       * device/lib/pic16/libc/stdio/: standard IO support sources,
+       * (printf_small.c): printf_small() source, supports float print,
+       * (printf_tiny.c): printf_tiny() source, does not support floats,
+       * device/lib/pic16/Makefile.common.in: added OPT_FLAGS macro to
+       enable global optimizations for entire library source, other
+       Makefiles in the source tree are also modified to reflect this,
+       * device/lib/pic16/libc/stdlib/putchar.c (putchar): dummy putchar()
+       function,
+       * doc/sdccman.lyx: updated to reflect new changes,
+       * src/pic16/gen.c (aopForSym): don't handle sym->iaccess in
+       sym->onStack if-case,
+       * src/pic16/main.c (_pic16_keywords): commented out keywords bit,
+       sbit, idata, _idata, xdata, _xdata,
+       * added pragma library, to link an external library, (see doc),
+       * removed command line options, --pomit-config-words, --pomit-ivt,
+       --pleave-reset-vector,
+       * (pic16_finaliseOptions): when define macro SDCC_MODEL_{SMALL/LARGE}
+       when calling assembler to reflect memory model used, also define
+       macro STACK_MODEL_{SMALL/LARGE} when compiling and assembling to
+       reflect stack model used,
+       * src/pic16/ralloc.c (pic16_allocDirReg): when operand is allocated
+       on stack return NULL,
+
 2005-01-22 Daniel Winkler <post AT danielwinkler.de>
 
        * src/SDCCopt.c (killDeadCode): do not throw iCodes away if one
index 68f3f09571af8e9bc5c61b47f4762b92aeddeb34..b6815732b5a5afe8215b82244879baed8a5ef645 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef __ADC_H__
 #define __ADC_H__
 
+/* link I/O libarary */
+#pragma library io
 
 /* interrupt on/off flag */
 #define ADC_INT_OFF    0x00
index 3f8cab29ca1b785d7e914eccf26fdfc34437fa8d..3769e287db9b5f958f688a60c2765558d60d16ac 100644 (file)
@@ -39,6 +39,9 @@
 #ifndef __CTYPE_H
 #define __CTYPE_H 1
 
+/* link the C libarary */
+#pragma library c
+
 #include <sdcc-lib.h>
 
 extern char  iscntrl   (unsigned char )  ;
index f5ab76dd351be73e81170b05e7a7fcf7ebc4baf8..c309a7d811c609cbdb1aadfaff878cf9f098f550 100644 (file)
@@ -29,6 +29,9 @@
 #ifndef __PIC16_GSTACK_H__
 #define __PIC16_GSTACK_H__
 
+/* link the debug library */
+#pragma library debug
+
 extern void (* _gstack_overflow_handler)(void);
 
 #endif /* __PIC16_GSTACK_H__ */
diff --git a/device/include/pic16/i2c.h b/device/include/pic16/i2c.h
new file mode 100644 (file)
index 0000000..eef8b75
--- /dev/null
@@ -0,0 +1,121 @@
+
+/*
+ * I2C communications module library header
+ *
+ * written by Vangelis Rokas, 2005 <vrokas AT otenet.gr>
+ *
+ * Devices implemented:
+ *     PIC18F[24][45][28]
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/*
+** $Id$
+*/
+
+
+#ifndef __I2C_H__
+#define __I2C_H__
+
+/* link the I/O library */
+#pragma library io
+
+#include <pic18fregs.h>
+
+
+#define _I2CPARAM_SPEC data
+
+
+/* I2C modes of operation */
+#define I2C_SLAVE10B_INT       0x0f
+#define I2C_SLAVE7B_INT                0x0e
+#define I2C_SLAVE_IDLE         0x0b
+#define I2C_MASTER             0x08
+#define I2C_SLAVE10B           0x07
+#define I2C_SLAVE7B            0x06
+
+
+/* slew rate control */
+#define I2C_SLEW_OFF   0xc0
+#define I2C_SLEW_ON    0x00
+
+/* macros to generate hardware conditions on I2C module */
+
+/* generate stop condition */
+#define I2C_STOP()     SSPCON2bits.PEN=1
+
+/* generate start condition */
+#define I2C_START()    SSPCON2bits.SEN=1
+
+/* generate restart condition */
+#define I2C_RESTART()  SSPCON2bits.RSEN=1
+
+/* generate not acknoledge condition */
+#define I2C_NACK()     SSPCON2bits.ACKDT=1; SSPCON2bits.ACKEN=1
+
+/* generate acknoledge condition */
+#define I2C_ACK()      SSPCON2bits.ACKDT=0; SSPCON2bits.ACKEN=1
+
+/* wait until I2C is idle */
+#define I2C_IDLE()     while((SSPCON2 & 0x1f) | (SSPSTATbits.R_W));
+
+/* is data ready from I2C module ?? */
+#define I2C_DRDY()     (SSPSTATbits.BF)
+
+
+/* function equivalent to macros for generating hardware conditions */
+
+/* stop */
+void i2c_stop(void);
+
+/* start */
+void i2c_start(void);
+
+/* restart */
+void i2c_restart(void);
+
+/* not acknoledge */
+void i2c_nack(void);
+
+/* acknoledge */
+void i2c_ack(void);
+
+/* wait until I2C goes idle */
+void i2c_idle(void);
+
+/* is character ready in I2C buffer ?? */
+unsigned char i2c_drdy(void);
+
+/* read a character from I2C module */
+unsigned char i2c_readchar(void);
+
+/* read a string from I2C module */
+char i2c_readstr(_I2CPARAM_SPEC unsigned char *ptr, unsigned char len);
+
+/* write a character to I2C module */
+char i2c_writechar(unsigned char dat);
+
+/* write a string to I2C module */
+char i2c_writestr(unsigned char *ptr);
+
+/* configure I2C port for operation */
+void i2c_open(unsigned char mode, unsigned char slew, unsigned char addr_brd);
+
+void i2c_close(void);
+
+
+#endif /* __I2C_H__ */
index cc5f2462e9505e627ae35746eccbb8ae0989af73..4f9d24e7a0199b5b2fb751b2e77cbda7f8313ee7 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __MALLOC_H__
 #define __MALLOC_H__
 
-#include <../asm/pic16/features.h>
+#pragma library c
 
 #define EMULATION      0
 
index 3ea9245a7b34492376eb496b7cf67957fd022e62..c8b58ce0157a629b830870f71282b7c486fe7e9c 100644 (file)
@@ -28,6 +28,8 @@
 #ifndef __PIC16_MATH_H
 #define __PIC16_MATH_H 1
 
+#pragma library math
+
 #include <sdcc-lib.h>
 
 #define PI          3.1415926536
index e0d52d14e105f6dec9c8df6536cabd1cd14a01ed..daf5d204b1617c559243cbe38161ba394d7b359c 100644 (file)
@@ -31,6 +31,9 @@
 #ifndef __PIC16_STDIO_H
 #define __PIC16_STDIO_H 1
 
+/* link the C library */
+#pragma library c
+
 #include <stdarg.h>
 
 #include <sdcc-lib.h>
   typedef unsigned int size_t;
 #endif
 
-typedef void (*pfn_outputchar)(char c, void* p) _REENTRANT;
+//typedef void (*pfn_outputchar)(char c, void* p) _REENTRANT;
 
-extern int _print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap);
+//extern int _print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap);
 
 /*-----------------------------------------------------------------------*/
 
-extern void printfl(char *, ...);
+extern void printf_small(char *, ...);
+
+extern int printf (char *,...);
+extern int vprintf (char *, va_list);
 
-//extern void printf_small (char *,...) _REENTRANT;
-extern int printf (const char *,...);
-extern int vprintf (const char *, va_list);
 extern int sprintf (char *, const char *, ...);
 extern int vsprintf (char *, const char *, va_list);
-extern int puts(const char *);
-extern char *gets(char *);
-extern char getchar(void);
+
+extern int puts(char *);
 
 #pragma wparam putchar
 extern void putchar(char);
 
+extern char *gets(char *);
+extern char getchar(void);
 
 #endif /* __PIC16_STDIO_H */
index 8e522a2c017486336ea73b5a60046850b0811c00..77ec060b209e3f0c053483fb97f98847598bf567 100644 (file)
@@ -31,6 +31,8 @@
 #ifndef __PIC16_STDLIB_H
 #define __PIC16_STDLIB_H 1
 
+#pragma library c
+
 #ifndef NULL
 # define NULL (void *)0
 #endif
@@ -41,11 +43,11 @@ extern float atof (char *);
 extern int atoi (char *);
 extern long atol (char *);
 
-extern void uitoa(unsigned int, char*, unsigned char);
-extern void itoa(unsigned int, char*, unsigned char);
+extern void uitoa(unsigned int, data char *, unsigned char);
+extern void itoa(unsigned int, data char*, unsigned char);
 
-extern void ultoa(unsigned long, char*, unsigned char);
-extern void ltoa(unsigned long, char*, unsigned char);
+extern void ultoa(unsigned long, data char *, unsigned char);
+extern void ltoa(unsigned long, data char*, unsigned char);
 
 extern char x_ftoa(float, data char *, unsigned char, unsigned char);
 
index fee486adceab2db2e296eb20d245e94d5dcd8b3c..ba6de15e2540df18d9c373851d6c3c2a8d02d181 100644 (file)
 include ./Makefile.common
 
 
-DIRS   =       libdev  \
+DIRS   =       startup \
+               libdev  \
                libsdcc \
-               libc    \
-               startup \
+               libc \
+               libm \
                debug
+               
+#              libio 
 
 
 all: build-all-libraries
@@ -30,6 +33,9 @@ build-all-libraries:
        done
 
 
+lib-io:
+       $(MAKE) -C libio MODELFLAGS=$(MODELFLAGS)
+
 clean: all-clean
        $(RM) -f bin/*.*
 
index 13e1e2eccd8afe9029fa57c3ef8e0ab8bbc35062..a7d77c5d56c25cceff245151ad7b5401a2791988 100644 (file)
@@ -29,3 +29,8 @@ SED   = @SED@
 MM = -MM
 
 MODELFLAGS      = -mpic16
+
+OPT_FLAGS      += --denable-peeps
+OPT_FLAGS      += --obanksel=9
+OPT_FLAGS      += --optimize-goto
+OPT_FLAGS      += --i-code-in-asm
index 5ea2db5ec9e08283f55f488f98528c5240afbc5c..fcef71c7e2c420a1464c142479155352d9f99dce 100755 (executable)
@@ -1484,7 +1484,10 @@ fi
 
 # Checks for library functions.
 
+cp pics.all pics.build
+
           ac_config_files="$ac_config_files Makefile.common"
+
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
 # tests run on this system so they can be shared between configure
index d6daa2d17150337c86c7d2760b8df5d6047d264d..160347650f9917be2930910beb87c337cec0186f 100644 (file)
@@ -37,5 +37,7 @@ AC_CHECK_PROG(SED,    sed,    sed, :)
 
 # Checks for library functions.
 
+cp pics.all pics.build
+
 AC_CONFIG_FILES([Makefile.common])
 AC_OUTPUT
index 82548825587a612919b19cd30605f3a9c32be73e..c76ece10e37e00248f368acd2d1a161d59e86498 100644 (file)
@@ -19,7 +19,8 @@ PRJDIR        = ../../../../..
 
 LIBC_INC_DIR   = $(PRJDIR)/device/include/pic16
 
-COMPILE_FLAGS  += $(MODELFLAGS) --pomit-config-words --pomit-ivt --denable-peeps --optimize-goto --obanksel=2 --i-code-in-asm
+COMPILE_FLAGS  += $(MODELFLAGS) $(OPT_FLAGS)
+
 CFLAGS = --nostdinc -I$(LIBC_INC_DIR)
 
 CFILES = $(patsubst %,%.c,$(SRCS))
index c73980f296edef915fbee040395d4edc1b9503d5..71b119182a4ddb83d8a6b869a654174c430e619b 100644 (file)
 
 DIRS   =       ctype \
                stdlib \
+               stdio \
                string \
                utils
 
-LIB    = libp18c.lib
+LOBJS  = $(patsubst %,%/*.o,$(DIRS))
+
+LIB    = libc18f.lib
 
 all: build-libraries
 
@@ -27,7 +30,7 @@ build-libraries:
        for dir in $(DIRS) ; do  \
                $(MAKE) -C $$dir ; \
        done;
-       gplib -c $(LIB) string/*.o
+       gplib -c $(LIB) $(LOBJS)
        mv -v $(LIB) ../bin
        
 
index b54bc5798464c8a3e25e84eab1d1c129c53f9506..582d5bd958ca57a532447222427c7c41f72031c2 100644 (file)
@@ -18,7 +18,11 @@ PRJDIR       = ../../../../..
 
 LIBC_INC_DIR   = $(PRJDIR)/device/include/pic16
 
-COMPILE_FLAGS  += $(MODELFLAGS) --pomit-config-words --pomit-ivt --denable-peeps --optimize-goto --obanksel=2 --i-code-in-asm
+#OPT_FLAGS     += --pstack-model=large
+
+COMPILE_FLAGS  += $(MODELFLAGS) $(OPT_FLAGS)
+
+
 CFLAGS = -I$(LIBC_INC_DIR)
 
 CFILES = $(patsubst %,%.c,$(SRCS))
@@ -28,11 +32,14 @@ OFILES      = $(patsubst %.c,%.o,$(CFILES))
        $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
 
 
-all: build-library
+all: build-library clean-intermediate-no-asm
 
 clean-intermediate:
        $(RM) -f *.lst *.asm *.dump* *.p *.d *.adb
 
+clean-intermediate-no-asm:
+       $(RM) -f *.lst *.dump* *.p *.d *.adb
+
 
 clean: clean-intermediate
        $(RM) -f $(LIB) *.o
diff --git a/device/lib/pic16/libc/stdio/Makefile b/device/lib/pic16/libc/stdio/Makefile
new file mode 100644 (file)
index 0000000..3797e4e
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# Makefile - Makefile to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+#      Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+include ../Makefile.rules
+
+SRCS   =       printf_tiny \
+               printf_small
+
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+
+DEBUG=
+#COMPILE_FLAGS   += --pomit-config-words --pomit-ivt --no-peep
+COMPILE_FLAGS  += $(DEBUG)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+       $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+build-library: $(OFILES)
+
diff --git a/device/lib/pic16/libc/stdio/printf_small.c b/device/lib/pic16/libc/stdio/printf_small.c
new file mode 100644 (file)
index 0000000..31ef420
--- /dev/null
@@ -0,0 +1,134 @@
+/*-----------------------------------------------------------------
+    printf_small.c - source file for reduced version of printf
+
+    Modified for pic16 port, by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+    
+    Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by the
+    Free Software Foundation; either version 2, or (at your option) any
+    later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+    In other words, you are welcome to use, share and improve this program.
+    You are forbidden to forbid anyone else to use, share and improve
+    what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* This function uses function putchar() to dump a character
+ * to standard output. putchar() is defined in libc18f.lib
+ * as dummy function, which will be linked if no putchar()
+ * function is provided by the user.
+ * The user can write his own putchar() function and link it
+ * with the source *BEFORE* the libc18f.lib library. This way
+ * the linker will link the first function (i.e. the user's function) */
+
+/* following formats are supported :-
+   format     output type       argument-type
+     %d        decimal             int
+     %ld       decimal             long
+     %hd       decimal             char
+     %x        hexadecimal         int
+     %lx       hexadecimal         long
+     %hx       hexadecimal         char
+     %o        octal               int
+     %lo       octal               long
+     %ho       octal               char
+     %c        character           char
+     %s        character           generic pointer
+     %f        float               float
+*/
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void printf_small(char *fmt, ...) 
+{
+  char *ch;
+  char radix;
+  char flong;
+  char fstr;
+  char fchar;
+  char ffloat;
+  float flt;
+  char *str;
+  data char *str1;
+  long val;
+  static char buffer[16];
+  va_list ap ;
+
+    ch = fmt;
+    va_start(ap,fmt);
+
+    while( *ch ) {                     //for (; *fmt ; fmt++ )
+        if (*ch == '%') {
+            flong = fstr = fchar = ffloat = 0;
+            radix = 0;
+            ch++;
+
+            if(*ch == 'l') {
+              flong = 1;
+              ch++;
+            } else
+            if(*ch == 'h') {
+              fchar = 1;
+              ch++;
+            }
+            
+            if(*ch == 's')fstr = 1;
+            else if(*ch == 'f')ffloat = 1;
+            else if(*ch == 'd')radix = 10;
+            else if(*ch == 'x')radix = 16;
+            else if(*ch == 'c')radix = 0;
+            else if(*ch == 'o')radix = 8;
+            
+            if(fstr) {
+                str = va_arg(ap, char *);
+                while (*str) putchar(*str++);
+            } else
+            if(ffloat) {
+                flt = va_arg(ap, float);
+                x_ftoa(flt, buffer, 32, 6);
+                str1 = buffer;
+                while( *str1 )str1++; str1--;
+                while( *str1 == '0' )str1--; str1++;
+                *str1 = 0; str1 = buffer;
+                while( *str1 )putchar(*str1++);
+            } else {
+              if(flong)val = va_arg(ap, long);
+              else
+              if(fchar)val = va_arg(ap, char);
+              else {
+                  val = va_arg(ap, int);
+              }
+            
+              if(radix) {
+                ltoa (val, buffer, radix);
+
+                str1 = buffer;
+                while ( *str1 ) {
+                  putchar ( *str1++ );
+                }
+              }        else
+                putchar((char)val);
+            }
+          } else
+            putchar(*ch);
+
+        ch++;
+    }
+}
index cb2da82d01deeffcf8f970ebfd16a80915846bb4..b166c4695fb52e2e1af18665674eff1185d6ab9b 100644 (file)
@@ -21,7 +21,8 @@ SRCS  =       atof \
                ltoa \
                malloc \
                realloc \
-               x_ftoa
+               x_ftoa \
+               putchar
 
 
 CFILES = $(patsubst %,%.c,$(SRCS))
index 30d7772cc31c8752e4f143fc4238088f9b4fcba7..84203e8bb6d6ed4954573c05a78e4ca27a353874 100644 (file)
@@ -39,10 +39,9 @@ void ltoa(long value, data char* string, unsigned char radix)
 {
   if (value < 0 && radix == 10) {
     *string++ = '-';
-    ultoa(-value, string, radix);
-  }
-  else {
-    ultoa(value, string, radix);
+    value = -value;
   }
+
+  ultoa(value, string, radix);
 }
 
diff --git a/device/lib/pic16/libc/stdlib/putchar.c b/device/lib/pic16/libc/stdlib/putchar.c
new file mode 100644 (file)
index 0000000..f526c28
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * putchar.c - putchar dummy function
+ *
+ * written by Vangelis Rokas, 2005 (vrokas@otenet.gr)
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/*
+** $Id$
+ */
+
+#include <stdio.h>
+
+/* this is a dummy function so that sources compile,
+ * even when user doesn't give a putchar() function.
+ * NOTE that putchar() is declared in stdio.h to
+ * have the argument in WCHAR (via the wparam pragma) */
+
+void putchar(char c)
+{
+  c;
+  _asm
+    return
+  _endasm;
+}
index 3d504a637b496c0cfd6cb5afdbf5658c4f77836b..0cb604e041b343c4b75d9cb59964fd575a24c732 100644 (file)
@@ -20,25 +20,30 @@ PRJDIR      = ../../../..
 INCDIR = $(PRJDIR)/device/include
 
 
+# MCUs to build
+MCUS   = $(shell cat ../pics.build)
+
 # Supported devices
-DEVS   =       18f242 \
-               18f248 \
-               18f252 \
-               18f258 \
-               18f442 \
-               18f448 \
-               18f452 \
-               18f458 \
-               18f1220 \
-               18f2220 \
-               18f6520 \
-               18f6620 \
-               18f6680 \
-               18f6720 \
-               18f8520 \
-               18f8620 \
-               18f8680 \
-               18f8720
+DEVS   = $(patsubst    %,18f%,$(MCUS))
+
+#DEVS  =       18f242 \
+#              18f248 \
+#              18f252 \
+#              18f258 \
+#              18f442 \
+#              18f448 \
+#              18f452 \
+#              18f458 \
+#              18f1220 \
+#              18f2220 \
+#              18f6520 \
+#              18f6620 \
+#              18f6680 \
+#              18f6720 \
+#              18f8520 \
+#              18f8620 \
+#              18f8680 \
+#              18f8720
 
 
 # pic16 port specific headers
@@ -66,7 +71,7 @@ LFILE = $(patsubst %.c,%.lib,$<)
        
 all: make-lib
 
-make-lib: $(LFILES)
+make-lib: $(LFILES) clean-intermediate-no-asm
        @$(MV) -v $(LFILES) ../bin
        
 $(LFILES): $(OFILES)
@@ -76,6 +81,9 @@ $(OFILES): $(CFILES)
 
 clean-intermediate:
        $(RM) -f *.lst *.asm *.dump*
+
+clean-intermediate-no-asm:
+       $(RM) -f *.lst *.dump*
        
 clean: clean-intermediate
        $(RM) -f *.o
index 45242dd02468a9049ebf3ee6a24c4a08085a40ad..abbf31d4dc6ef37502366eee533209b379a52018 100644 (file)
 #
 #
 
+MCUS   = $(shell cat ../pics.build)
 
-DIRS   =       adc
+PROCESSORS     = $(MCUS)
 
 
-LIB    = libio.lib
+DIRS   = adc i2c
+
+LOBJS  = $(patsubst %,%/*.o,$(DIRS))
+
+# library name example libio18f8720.lib
+LIB    = libio18f$(MMCU).lib
 
 all: build-libraries
 
 make-target: build-libraries
 
 build-libraries:
+       for proc in $(PROCESSORS) ; do \
+               echo "Building libraries for processor pic18f $$proc" ; \
+               $(MAKE) -C . build-processor-library MMCU=$$proc ;  \
+       done ;
+
+# Should have externally specified PROC
+build-processor-library:
        for dir in $(DIRS) ; do  \
-               $(MAKE) -C $$dir ; \
+               $(MAKE) -C $$dir clean ; \
+               $(MAKE) -C $$dir build-mcu-library MCU=18f$(MMCU); \
        done;
-       gplib -c $(LIB) adc/*.o
+       gplib -c $(LIB) $(LOBJS)
        mv -v $(LIB) ../bin
        
 
index 4a8e9fbe0c11c5f99c2ea083b04bb7c83d3e8849..a7a64aeecee22dedbd9fb4eea5bc32c3ef2f89d2 100644 (file)
@@ -18,7 +18,11 @@ PRJDIR       = ../../../../..
 
 LIBC_INC_DIR   = $(PRJDIR)/device/include/pic16
 
-COMPILE_FLAGS  += $(MODELFLAGS) --pomit-config-words --pomit-ivt --denable-peeps --optimize-goto --obanksel=2 --i-code-in-asm
+COMPILE_FLAGS  += $(MODELFLAGS)
+COMPILE_FLAGS  += -p$(MCU)
+#COMPILE_FLAGS += --pomit-config-words --pomit-ivt
+COMPILE_FLAGS  += --no-peep
+COMPILE_FLAGS  += --i-code-in-asm
 CFLAGS = -I$(LIBC_INC_DIR)
 
 CFILES = $(patsubst %,%.c,$(SRCS))
@@ -27,12 +31,19 @@ OFILES      = $(patsubst %.c,%.o,$(CFILES))
 %.o: %.c
        $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
 
+all:
+       @echo "Please make target build-mcu-library setting"
+       @echo "MCU= to the target device (i.e. MCU=18f452)"
 
-all: build-library
+
+build-mcu-library: build-library clean-intermediate-no-asm
 
 clean-intermediate:
        $(RM) -f *.lst *.asm *.dump* *.p *.d *.adb
 
+clean-intermediate-no-asm:
+       $(RM) -f *.lst *.dump* *.p *.d *.adb
+
 
 clean: clean-intermediate
        $(RM) -f $(LIB) *.o
diff --git a/device/lib/pic16/libio/i2c/Makefile b/device/lib/pic16/libio/i2c/Makefile
new file mode 100644 (file)
index 0000000..7ad6f94
--- /dev/null
@@ -0,0 +1,46 @@
+#
+# Makefile - Makefile to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+#      Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+include ../Makefile.rules
+
+SRCS   =       i2cack \
+               i2cclose \
+               i2cdrdy \
+               i2cidle \
+               i2cnack \
+               i2copen \
+               i2creadc \
+               i2creads \
+               i2crestart \
+               i2cstart \
+               i2cstop \
+               i2cwritec \
+               i2cwrites
+
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+
+DEBUG=
+#COMPILE_FLAGS   += --pomit-config-words --pomit-ivt --no-peep
+COMPILE_FLAGS  += $(DEBUG)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+       $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+build-library: $(OFILES)
+
diff --git a/device/lib/pic16/libio/i2c/i2cack.c b/device/lib/pic16/libio/i2c/i2cack.c
new file mode 100644 (file)
index 0000000..e5ad735
--- /dev/null
@@ -0,0 +1,11 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+void i2c_ack(void)
+{
+  SSPCON2bits.ACKDT = 0;
+  SSPCON2bits.ACKEN = 1;
+}
diff --git a/device/lib/pic16/libio/i2c/i2cclose.c b/device/lib/pic16/libio/i2c/i2cclose.c
new file mode 100644 (file)
index 0000000..13ef805
--- /dev/null
@@ -0,0 +1,10 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+void i2c_close(void)
+{
+  SSPCON1 &= 0xdf;
+}
diff --git a/device/lib/pic16/libio/i2c/i2cdrdy.c b/device/lib/pic16/libio/i2c/i2cdrdy.c
new file mode 100644 (file)
index 0000000..bd61b3c
--- /dev/null
@@ -0,0 +1,13 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+unsigned char i2c_drdy(void)
+{
+  if(SSPSTATbits.BF)
+    return (+1);
+  else
+    return (0);
+}
diff --git a/device/lib/pic16/libio/i2c/i2cidle.c b/device/lib/pic16/libio/i2c/i2cidle.c
new file mode 100644 (file)
index 0000000..cd84383
--- /dev/null
@@ -0,0 +1,9 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_idle(void)
+{
+  while((SSPCON2 & 0x1f) | (SSPSTATbits.R_W));
+}
diff --git a/device/lib/pic16/libio/i2c/i2cnack.c b/device/lib/pic16/libio/i2c/i2cnack.c
new file mode 100644 (file)
index 0000000..ca2ac68
--- /dev/null
@@ -0,0 +1,10 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_nack(void)
+{
+  SSPCON2bits.ACKDT = 0;
+  SSPCON2bits.ACKEN = 1;
+}
diff --git a/device/lib/pic16/libio/i2c/i2copen.c b/device/lib/pic16/libio/i2c/i2copen.c
new file mode 100644 (file)
index 0000000..bbb486e
--- /dev/null
@@ -0,0 +1,32 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_open(unsigned char mode, unsigned char slew, unsigned char addr_brd)
+{
+  SSPSTAT &= 0x3f;
+  SSPCON1 = 0;
+  SSPCON2 = 0;
+  SSPCON1 |= mode;
+  SSPSTAT |= slew;
+  
+  
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+
+  TRISBbits.TRISB1 = 1;
+  TRISBbits.TRISB0 = 1;
+
+#else  /* all other devices */
+
+  TRISCbits.TRISC3 = 1;
+  TRISCbits.TRISC2 = 1;
+
+#endif
+
+  SSPADD = addr_brd;
+
+  SSPCON1 |= 0x20;
+}
+
diff --git a/device/lib/pic16/libio/i2c/i2creadc.c b/device/lib/pic16/libio/i2c/i2creadc.c
new file mode 100644 (file)
index 0000000..09f5bcd
--- /dev/null
@@ -0,0 +1,11 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+unsigned char i2c_readchar(void)
+{
+  SSPCON2bits.RCEN = 1;
+  while( !I2C_DRDY() );
+  return ( SSPBUF );
+}
diff --git a/device/lib/pic16/libio/i2c/i2creads.c b/device/lib/pic16/libio/i2c/i2creads.c
new file mode 100644 (file)
index 0000000..6157599
--- /dev/null
@@ -0,0 +1,26 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+char i2c_readstr(_I2CPARAM_SPEC unsigned char *ptr, unsigned char len)
+{
+  unsigned char count=0;
+  
+  while( len-- ) {
+    *ptr++ = i2c_readchar();
+    
+    while(SSPCON2bits.RCEN) {
+      if(PIR2bits.BCLIF)return (-1);
+      count++;
+    
+      if(len) {
+        I2C_ACK();
+        while(SSPCON2bits.ACKEN);
+      }
+    }
+  }
+  
+  return count;
+}
diff --git a/device/lib/pic16/libio/i2c/i2crestart.c b/device/lib/pic16/libio/i2c/i2crestart.c
new file mode 100644 (file)
index 0000000..1635746
--- /dev/null
@@ -0,0 +1,9 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_restart(void)
+{
+  SSPCON2bits.RSEN = 1;
+}
diff --git a/device/lib/pic16/libio/i2c/i2cstart.c b/device/lib/pic16/libio/i2c/i2cstart.c
new file mode 100644 (file)
index 0000000..cae7491
--- /dev/null
@@ -0,0 +1,9 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_start(void)
+{
+  SSPCON2bits.SEN = 1;
+}
diff --git a/device/lib/pic16/libio/i2c/i2cstop.c b/device/lib/pic16/libio/i2c/i2cstop.c
new file mode 100644 (file)
index 0000000..d348bbe
--- /dev/null
@@ -0,0 +1,9 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_stop(void)
+{
+  SSPCON2bits.PEN = 1;
+}
diff --git a/device/lib/pic16/libio/i2c/i2cwritec.c b/device/lib/pic16/libio/i2c/i2cwritec.c
new file mode 100644 (file)
index 0000000..9008331
--- /dev/null
@@ -0,0 +1,15 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+char i2c_writechar(unsigned char dat)
+{
+  SSPBUF = dat;
+  if( SSPCON1bits.WCOL ) {
+    return -1;
+  } else {
+    while( I2C_DRDY() );
+    return 0;
+  }
+}
diff --git a/device/lib/pic16/libio/i2c/i2cwrites.c b/device/lib/pic16/libio/i2c/i2cwrites.c
new file mode 100644 (file)
index 0000000..09d9f51
--- /dev/null
@@ -0,0 +1,32 @@
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+char i2c_writestr(unsigned char *ptr)
+{
+  while( *ptr ) {
+    if( SSPCON1bits.SSPM3 ) {
+      if(i2c_writechar( *ptr )) {
+        return (-3);
+      }
+      I2C_IDLE();
+      if( SSPCON2bits.ACKSTAT ) {
+        return (-2);
+      }
+    } else {
+      PIR1bits.SSPIF = 0;
+      SSPBUF = *ptr;
+      SSPCON1bits.CKP = 1;
+      while( !PIR1bits.SSPIF );
+      
+      if((!SSPSTATbits.R_W) && ( !SSPSTATbits.BF )) {
+        return (-2);
+      }
+    }
+    
+    ptr++;
+  }
+
+  return 0;
+}
index 2774f75bc9245f784f8d1744671bc94786ca6cde..5aed8cd23da14f92a9d734fd7a8c8ca03920cc32 100644 (file)
@@ -16,9 +16,12 @@ DIRS =       char \
                int \
                long \
                float \
-               gptr \
-               lregs
+               gptr
 
+#              lregs
+#              fixed16_16
+
+LOBJS  = $(patsubst %,%/*.o,$(DIRS))
 
 LIB    = libsdcc.lib
 
@@ -30,7 +33,7 @@ build-libraries:
        for dir in $(DIRS) ; do  \
                $(MAKE) -C $$dir ; \
        done;
-       gplib -c $(LIB) char/*.o int/*.o long/*.o float/*.o gptr/*.o lregs/*.o
+       gplib -c $(LIB) $(LOBJS)
        mv -v $(LIB) ../bin
        
 
index eba686d7e367b5b2a8179270721c94baa1adf3ed..9e8bfc5f15caea90dab707e7150273abb4b0c04f 100644 (file)
@@ -19,21 +19,30 @@ PRJDIR      = ../../../../..
 
 LIBC_INC_DIR   = $(PRJDIR)/device/include/pic16
 
-COMPILE_FLAGS  += $(MODELFLAGS) --pomit-config-words --pomit-ivt --denable-peeps --optimize-goto --obanksel=2 --i-code-in-asm
+COMPILE_FLAGS  += $(MODELFLAGS) $(OPT_FLAGS)
+
 CFLAGS = --nostdinc -I$(LIBC_INC_DIR)
 
 CFILES = $(patsubst %,%.c,$(SRCS))
 OFILES = $(patsubst %.c,%.o,$(CFILES))
 
+SFILES = $(patsubst %,%.S,$(AS_SRCS))
+SOFILES        = $(patsubst %.S,%.o,$(SFILES))
+
 %.o: %.c
        $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
 
+.S.o:
+       $(AS) -c $<
 
-all: build-library
+
+all: build-library clean-intermediate-no-asm
 
 clean-intermediate:
        $(RM) -f *.lst *.asm *.dump* *.p *.d *.adb
 
+clean-intermediate-no-asm:
+       $(RM) -f *.lst *.dump* *.p *.d *.adb
 
 clean: clean-intermediate
        $(RM) -f $(LIB) *.o
@@ -45,5 +54,5 @@ dep .depend:
                $(SED) s/.rel/.o/g .tmpdepend >> .depend; \
                $(RM) -f .tmpdepend; \
        done;
-
+       if [ ! -e .depend ]; then touch .depend ; fi ;
 include .depend
index 917bac8d55d51e89492129762fea91b85016f15c..be6b04a5fc7b44abbf00128ea3e43281f7f88cce 100644 (file)
@@ -35,7 +35,8 @@ SRCS  =       fs2schar \
                uint2fs \
                ulong2fs
 
-#COMPILE_FLAGS += --obanksel=9
+LOCAL_FLAGS    =
+COMPILE_FLAGS  += $(LOCAL_FLAGS)
 
 include ../Makefile.rules
 
@@ -43,7 +44,7 @@ all: build-library
 
 build-library: $(LIB)
 
-$(LIB): $(OFILES)
+$(LIB): $(OFILES) clean-intermediate-no-asm
        @echo Creating $(LIB) ...
        @for object in $(OFILES) ; do \
                if [ ! -e $(LIB) ]; then \
diff --git a/device/lib/pic16/pics.all b/device/lib/pic16/pics.all
new file mode 100644 (file)
index 0000000..6ab84b9
--- /dev/null
@@ -0,0 +1,18 @@
+242
+248
+252
+258
+442
+448
+452
+458
+1220
+2220
+6520
+6620
+6680
+6720
+8520
+8620
+8680
+8720
index 0fc9c1652bde987add918450abf6cc94261980d0..75dd6b48c2844439cac9b21d68962c3557b0cce8 100644 (file)
@@ -85,6 +85,7 @@ extern code struct
 
 #define tblrdpostinc   tblrd*+
 
+
 /* the variable initialisation routine */
 void _do_cinit (void)
 {
index 752113cade8fa3eb42d90812ea2ef3847b4b9b5a..2c211266192251a6999ab64d8248df7701c1c7db 100644 (file)
@@ -16028,8 +16028,8 @@ Example:
 char foo;
 \layout Standard
 
-In order for this pragma to work there are some changes that must be made
- in the .lkr script used in link stage.
+In order for this pragma to work extra SECTION directives should be added
+ in the .lkr script.
  In the following example a sample .lkr file is shown:
 \layout LyX-Code
 
@@ -16092,16 +16092,16 @@ SECTION    NAME=CONFIG     ROM=config
 
 \layout LyX-Code
 
-SECTION    NAME=bank0      RAM=gpr0
+SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
 \layout LyX-Code
 
-SECTION    NAME=bank1      RAM=gpr1
+SECTION    NAME=bank1      RAM=gpr1       # should be added to link
 \layout LyX-Code
 
-SECTION    NAME=bank2      RAM=gpr2
+SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
 \layout LyX-Code
 
-SECTION    NAME=bank3      RAM=gpr3
+SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
 \layout LyX-Code
 
 SECTION    NAME=bank4      RAM=gpr4
@@ -16113,6 +16113,234 @@ SECTION    NAME=bank5      RAM=gpr5
 The linker will recognise the section name set in the pragma statement and
  will position the variable at the memory bank set with the RAM field at
  the SECTION line in the linker script file.
+\layout List
+\labelwidthstring 00.00.0000
+
+library instructs the linker to use a library module.
+\newline 
+Usage:
+\layout LyX-Code
+
+#pragma library module_name
+\layout Standard
+
+
+\emph on 
+module_name
+\emph default 
+ can be any library or object file (including its path).
+ Note that there are four reserved keywords which have special meaning.
+ These are:
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="6" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="block" valignment="top" leftline="true" width="20page%">
+<column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Keyword
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Description
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Module to link
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+ignore
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+ignore all library pragmas
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+(none)
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+c
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the C library
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libc18f
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+math
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the Math libarary
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libm18f
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+io
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the I/O library
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libio18f*
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+debug
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the debug library
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libdebug
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\newline 
+* is the device number, i.e.
+ 452 for PIC18F452 MCU.
+\layout Standard
+
+This feature allows for linking with specific libraries withoug having to
+ explicit name them in the command line.
+ Note that the 
+\noun on 
+ignore
+\noun default 
+ keyword will reject all modules specified by the library pragma.
 \layout Subsection
 
 Header Files
@@ -16168,6 +16396,47 @@ Libraries are created with gplib which is part of the gputils package
 \end_inset 
 
 .
+\layout Subsubsection
+
+Building the libraries
+\layout Standard
+
+Before using SDCC/pic16 there are some libraries that need to be compiled.
+ This process is not done automatically by SDCC since not all users use
+ SDCC for pic16 projects.
+ So each user should compile the libraries separately.
+\layout Standard
+
+The steps to compile the pic16 libraries under Linux are:
+\layout LyX-Code
+
+cd device/lib/pic16
+\layout LyX-Code
+
+./configure
+\layout LyX-Code
+
+make
+\layout LyX-Code
+
+cd ..
+\layout LyX-Code
+
+make model-pic16
+\layout LyX-Code
+
+su -c 'make install'     # install the libraries, you need the root password
+\layout Standard
+
+If you need to install the headers to, do:
+\layout LyX-Code
+
+cd device/include
+\layout LyX-Code
+
+su -c 'make install'     # install the headers, you need the root password
+\layout LyX-Code
+
 \layout Subsection
 
 Memory Models
@@ -16450,6 +16719,8 @@ Large
 stack model is currently not working properly throughout the code generator.
  So its use is not advised.
  Also there are some other points that need special care:
+\newline 
+
 \layout Enumerate
 
 Do not create stack sections with size more than one physical bank (that
index d308c9b7dd294a09a3b93aeb54c1de507e5f2d88..59d80d18681b57fb82d2df402e59b9994c50f229 100644 (file)
@@ -6,6 +6,7 @@ PRJDIR = ..
 clean:
        rm -f *core *[%~] *.[oa] *.output
        rm -f .[a-z]*~ \#*
+       rm -f version.h
        rm -f $(PRJDIR)/bin/sdcc$(EXEEXT) sdcc$(EXEEXT)
        for port in $(CLEANALLPORTS) ; do\
          $(MAKE) -C $$port -f ../port-clean.mk clean ;\
index e9b64a7875aa9c027db62037f8c4530d4454c85c..70e132b96ee3affb997e8411f49ee48ac7b6e521 100644 (file)
@@ -6,7 +6,7 @@
   Bug Fixes  -  Wojciech Stryjewski  wstryj1@tiger.lsu.edu (1999 v2.1.9a)
   PIC port   -  Scott Dattalo scott@dattalo.com (2000)
   PIC16 port -  Martin Dubuc m.dubuc@rogers.com (2002)
-             -  Vangelis Rokas vrokas@otenet.gr (2003,2004)
+             -  Vangelis Rokas vrokas@otenet.gr (2003,2004,2005)
   
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
@@ -648,11 +648,29 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result)
     }
 #endif
 
+
+#if 0
+    if(sym->iaccess) {
+      if(space->paged) {
+        fprintf(stderr, "%s:%d symbol %s points to paged data\n", __FILE__, __LINE__, sym->name);
+
+        sym->aop = aop = newAsmop (AOP_PAGED);
+        aop->aopu.aop_dir = sym->rname ;
+        aop->size = getSize(sym->type);
+       DEBUGpic16_emitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
+       pic16_allocDirReg( IC_LEFT(ic) );
+        return aop;
+      }
+      assert( 0 );
+    }
+#endif
+    
 #if 1
     /* assign depending on the storage class */
     /* if it is on the stack or indirectly addressable */
     /* space we need to assign either r0 or r1 to it   */    
-    if (sym->onStack || sym->iaccess) {
+    if (sym->onStack)  // || sym->iaccess)
+    {
       pCodeOp *pcop[4];
       int i;
       
@@ -857,6 +875,10 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result)
        else if(sym->onStack) {
                aop->size = PTRSIZE;
         } else {
+          if(SPEC_SCLS(sym->etype) == S_PDATA) {
+            fprintf(stderr, "%s: %d symbol in PDATA space\n", __FILE__, __LINE__);
+            aop->size = FPTRSIZE;
+          } else
                assert( 0 );
        }
 
@@ -1172,6 +1194,7 @@ void pic16_aopOp (operand *op, iCode *ic, bool result)
     b) has a spill location */
     if (sym->isspilt || sym->nRegs == 0) {
 
+//      debugf2("%s:%d symbol %s\tisspilt: %d\tnRegs: %d\n", sym->isspilt, sym->nRegs);
       DEBUGpic16_emitcode(";","%d",__LINE__);
         /* rematerialize it NOW */
         if (sym->remat) {
@@ -1545,6 +1568,21 @@ char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname)
       strcpy(rs,s);   
       return rs;
 
+#if 0
+    case AOP_PAGED:
+      DEBUGpic16_emitcode(";","oops AOP_PAGED did this %s\n",s);
+      if (offset) {
+       sprintf(s,"(%s + %d)",
+               aop->aopu.aop_dir,
+               offset);
+      } else
+           sprintf(s,"%s",aop->aopu.aop_dir);
+      DEBUGpic16_emitcode(";","oops AOP_PAGED did this %s\n",s);
+      rs = Safe_calloc(1,strlen(s)+1);
+      strcpy(rs,s);   
+      return rs;
+#endif
+
     case AOP_STA:
         rs = Safe_strdup(PCOR(aop->aopu.stk.pop[offset])->r->name);
         return (rs);
@@ -1943,6 +1981,12 @@ pCodeOp *pic16_popGet (asmop *aop, int offset) //, bool bit16, bool dname)
       DEBUGpic16_emitcode(";","%d\tAOP_DIR", __LINE__);
       return pic16_popRegFromString(aop->aopu.aop_dir, aop->size, offset, NULL);
        
+#if 0
+    case AOP_PAGED:
+      DEBUGpic16_emitcode(";","%d\tAOP_DIR", __LINE__);
+      return pic16_popRegFromString(aop->aopu.aop_dir, aop->size, offset, NULL);
+#endif
+
     case AOP_REG:
       {
        int rIdx;
index b3b4d4e79caa78d6f6085ad50ccafe984ea2e2b7..a570358a684be58910c1f0cfe1c9ccf10b6ee5c5 100644 (file)
@@ -43,28 +43,28 @@ static char _defaultRules[] =
 static char *_pic16_keywords[] =
 {
   "at",
-  "bit",
+//  "bit",
   "code",
   "critical",
   "register",
   "data",
   "far",
-  "idata",
+//  "idata",
   "interrupt",
   "near",
   "pdata",
   "reentrant",
   "sfr",
-  "sbit",
+//  "sbit",
   "using",
-  "xdata",
+//  "xdata",
   "_data",
   "_code",
   "_generic",
   "_near",
-  "_xdata",
+//  "_xdata",
   "_pdata",
-  "_idata",
+//  "_idata",
   "_naked",
   NULL
 };
@@ -137,6 +137,15 @@ set *sectNames=NULL;                       /* list of section listed in pragma directives */
 set *sectSyms=NULL;                    /* list of symbols set in a specific section */
 set *wparamList=NULL;
 
+struct {
+  unsigned ignore: 1;
+  unsigned want_libc: 1;
+  unsigned want_libm: 1;
+  unsigned want_libio: 1;
+  unsigned want_libdebug: 1;
+} libflags = { 0, 0, 0, 0, 0 };
+  
+
 static int
 _process_pragma(const char *sz)
 {
@@ -272,7 +281,7 @@ _process_pragma(const char *sz)
                        
                        ssym->section = snam;
                                
-#if 1
+#if 0
                        fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
                                ssym->name, snam->name, snam);
 #endif
@@ -283,6 +292,7 @@ _process_pragma(const char *sz)
          return 0;
        }
        
+       /* #pragma wparam function1[, function2[,...]] */
        if(startsWith(ptr, "wparam")) {
          char *fname = strtok((char *)NULL, WHITECOMMA);
          
@@ -295,6 +305,35 @@ _process_pragma(const char *sz)
             
           return 0;
         }
+        
+        /* #pragma library library_module */
+        if(startsWith(ptr, "library")) {
+          char *lmodule = strtok((char *)NULL, WHITE);
+        
+            if(lmodule) {
+              /* lmodule can be:
+               * c     link the C library
+               * math  link the math library
+               * io    link the IO library
+               * debug link the debug libary
+               * anything else, will link as-is */
+              if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
+              else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
+              else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
+              else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
+              else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
+              else {
+                if(!libflags.ignore) {
+                  fprintf(stderr, "link library %s\n", lmodule);
+                  addSetHead(&libFilesSet, lmodule);
+                }
+              }
+            }
+            
+            return 0;
+        }
+                
+              
        
   return 1;
 }
@@ -334,9 +373,9 @@ OPTION pic16_optionsTable[]= {
        { 0,    NO_DEFLIBS,             &pic16_options.nodefaultlibs,   "do not link default libraries when linking"},
        { 0,    "--pno-banksel",        &pic16_options.no_banksel,      "do not generate BANKSEL assembler directives"},
        { 0,    OPT_BANKSEL,            NULL,                           "set banksel optimization level (default=0 no)"},
-       { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
-       { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
-       { 0,    "--pleave-reset-vector",&pic16_options.leave_reset,     "when omitting IVT leave RESET vector"},
+//     { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
+//     { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
+//     { 0,    "--pleave-reset-vector",&pic16_options.leave_reset,     "when omitting IVT leave RESET vector"},
        { 0,    STACK_MODEL,            NULL,                           "use stack model 'small' (default) or 'large'"},
 
        { 0,    "--debug-xtra",         &pic16_debug_verbose,   "show more debug info in assembly output"},
@@ -546,6 +585,23 @@ static void _pic16_linkEdit(void)
           shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
 
        shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
+
+       if(!libflags.ignore) {
+         if(libflags.want_libc)
+           addSet(&libFilesSet, Safe_strdup("libc18f.lib"));
+        
+          if(libflags.want_libm)
+            addSet(&libFilesSet, Safe_strdup("libm18f.lib"));
+        
+          if(libflags.want_libio) {
+            sprintf(temp, "libio%s.lib", pic16->name[1]);      /* build libio18f452.lib name */
+            addSet(&libFilesSet, Safe_strdup(temp));
+          }
+        
+          if(libflags.want_libdebug)
+            addSet(&libFilesSet, Safe_strdup("libdebug.lib"));
+        }
+
        shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
        
        lcmd = msprintf(linkValues, lfrm);
@@ -562,6 +618,7 @@ static void _pic16_linkEdit(void)
 /* forward declarations */
 extern const char *pic16_linkCmd[];
 extern const char *pic16_asmCmd[];
+extern set *asmOptionsSet;
 
 static void
 _pic16_finaliseOptions (void)
@@ -595,10 +652,18 @@ _pic16_finaliseOptions (void)
       pic16_options.leave_reset = 0;
     }
     
+    if(options.model == MODEL_SMALL)
+      addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
+    else
+    if(options.model == MODEL_LARGE)
+      addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
+    
     if(STACK_MODEL_LARGE) {
       addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
+      addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
     } else {
       addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
+      addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
     }
 }
 
@@ -904,14 +969,14 @@ PORT pic16_port =
     "CSEG    (CODE)",          // code
     "DSEG    (DATA)",          // data
     "ISEG    (DATA)",          // idata
-    NULL,                                      // pdata
+    "PSEG    (DATA)",          // pdata
     "XSEG    (XDATA)",         // xdata
     "BSEG    (BIT)",           // bit
     "RSEG    (DATA)",          // reg
     "GSINIT  (CODE)",          // static
     "OSEG    (OVR,DATA)",      // overlay
     "GSFINAL (CODE)",          // post static
-    "HOME       (CODE)",       // home
+    "HOME    (CODE)",  // home
     NULL,                      // xidata
     NULL,                      // xinit
     NULL,                      // default location for auto vars
index b12a47d128be3cf3bab4743a1d41c8347c752771..bfeeac608e7f3381765908abf2b47a3b9dfe31c4 100644 (file)
@@ -778,8 +778,12 @@ pic16_allocDirReg (operand *op )
 
        if(IS_ITEMP(op))return NULL;
        
+//     if(IS_STATIC(OP_SYM_ETYPE(op)))return NULL;
+       
+       if(IN_STACK(OP_SYM_ETYPE(op)))return NULL;
+       
        debugLog ("%s:%d symbol name %s\n", __FUNCTION__, __LINE__, name);
-//     fprintf(stderr, "%s symbol name %s\n", __FUNCTION__,name);
+//     fprintf(stderr, "%s symbol name %s\tSTATIC:%d\n", __FUNCTION__,name, IS_STATIC(OP_SYM_ETYPE(op)));
 
        {
                if(SPEC_CONST ( OP_SYM_ETYPE(op)) && (IS_CHAR ( OP_SYM_ETYPE(op)) )) {
@@ -2940,10 +2944,11 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
     debugLog ("  %d - result is not temp\n", __LINE__);
   }
 
+//  if(IS_VALOP(IC_RIGHT(ic)))return 0;
 
 /* See BUGLOG0001 - VR */
 #if 1
-  if (!IS_ITEMP (IC_RIGHT (ic))) {
+  if (!IS_ITEMP (IC_RIGHT (ic)) /*&& (!IS_PARM(IC_RESULT(ic)))*/) {
     debugLog ("  %d - not packing - right is not temp\n", __LINE__);
     pic16_allocDirReg(IC_RIGHT (ic));
     return 0;