From 6474449850aeace128aebe2d7f387ac7c550bcc5 Mon Sep 17 00:00:00 2001 From: vrokas Date: Sat, 22 Jan 2005 18:02:16 +0000 Subject: [PATCH] * .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, git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3648 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- .version | 2 +- ChangeLog | 30 +++ device/include/pic16/adc.h | 2 + device/include/pic16/ctype.h | 3 + device/include/pic16/gstack.h | 3 + device/include/pic16/i2c.h | 121 +++++++++ device/include/pic16/malloc.h | 2 +- device/include/pic16/math.h | 2 + device/include/pic16/stdio.h | 22 +- device/include/pic16/stdlib.h | 10 +- device/lib/pic16/Makefile | 12 +- device/lib/pic16/Makefile.common.in | 5 + device/lib/pic16/configure | 3 + device/lib/pic16/configure.in | 2 + device/lib/pic16/debug/Makefile.rules | 3 +- device/lib/pic16/libc/Makefile | 7 +- device/lib/pic16/libc/Makefile.rules | 11 +- device/lib/pic16/libc/stdio/Makefile | 35 +++ device/lib/pic16/libc/stdio/printf_small.c | 134 ++++++++++ device/lib/pic16/libc/stdlib/Makefile | 3 +- device/lib/pic16/libc/stdlib/ltoa.c | 7 +- device/lib/pic16/libc/stdlib/putchar.c | 39 +++ device/lib/pic16/libdev/Makefile | 46 ++-- device/lib/pic16/libio/Makefile | 22 +- device/lib/pic16/libio/Makefile.rules | 15 +- device/lib/pic16/libio/i2c/Makefile | 46 ++++ device/lib/pic16/libio/i2c/i2cack.c | 11 + device/lib/pic16/libio/i2c/i2cclose.c | 10 + device/lib/pic16/libio/i2c/i2cdrdy.c | 13 + device/lib/pic16/libio/i2c/i2cidle.c | 9 + device/lib/pic16/libio/i2c/i2cnack.c | 10 + device/lib/pic16/libio/i2c/i2copen.c | 32 +++ device/lib/pic16/libio/i2c/i2creadc.c | 11 + device/lib/pic16/libio/i2c/i2creads.c | 26 ++ device/lib/pic16/libio/i2c/i2crestart.c | 9 + device/lib/pic16/libio/i2c/i2cstart.c | 9 + device/lib/pic16/libio/i2c/i2cstop.c | 9 + device/lib/pic16/libio/i2c/i2cwritec.c | 15 ++ device/lib/pic16/libio/i2c/i2cwrites.c | 32 +++ device/lib/pic16/libsdcc/Makefile | 9 +- device/lib/pic16/libsdcc/Makefile.rules | 15 +- device/lib/pic16/libsdcc/float/Makefile | 5 +- device/lib/pic16/pics.all | 18 ++ device/lib/pic16/startup/crt0i.c | 1 + doc/sdccman.lyx | 283 ++++++++++++++++++++- src/clean.mk | 1 + src/pic16/gen.c | 48 +++- src/pic16/main.c | 89 ++++++- src/pic16/ralloc.c | 9 +- 49 files changed, 1178 insertions(+), 83 deletions(-) create mode 100644 device/include/pic16/i2c.h create mode 100644 device/lib/pic16/libc/stdio/Makefile create mode 100644 device/lib/pic16/libc/stdio/printf_small.c create mode 100644 device/lib/pic16/libc/stdlib/putchar.c create mode 100644 device/lib/pic16/libio/i2c/Makefile create mode 100644 device/lib/pic16/libio/i2c/i2cack.c create mode 100644 device/lib/pic16/libio/i2c/i2cclose.c create mode 100644 device/lib/pic16/libio/i2c/i2cdrdy.c create mode 100644 device/lib/pic16/libio/i2c/i2cidle.c create mode 100644 device/lib/pic16/libio/i2c/i2cnack.c create mode 100644 device/lib/pic16/libio/i2c/i2copen.c create mode 100644 device/lib/pic16/libio/i2c/i2creadc.c create mode 100644 device/lib/pic16/libio/i2c/i2creads.c create mode 100644 device/lib/pic16/libio/i2c/i2crestart.c create mode 100644 device/lib/pic16/libio/i2c/i2cstart.c create mode 100644 device/lib/pic16/libio/i2c/i2cstop.c create mode 100644 device/lib/pic16/libio/i2c/i2cwritec.c create mode 100644 device/lib/pic16/libio/i2c/i2cwrites.c create mode 100644 device/lib/pic16/pics.all diff --git a/.version b/.version index e30309f7..f041bc6d 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.4.7 +2.4.8 diff --git a/ChangeLog b/ChangeLog index 2d4c75d4..5fe897c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2005-01-22 Vangelis Rokas + + * .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 * src/SDCCopt.c (killDeadCode): do not throw iCodes away if one diff --git a/device/include/pic16/adc.h b/device/include/pic16/adc.h index 68f3f095..b6815732 100644 --- a/device/include/pic16/adc.h +++ b/device/include/pic16/adc.h @@ -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 diff --git a/device/include/pic16/ctype.h b/device/include/pic16/ctype.h index 3f8cab29..3769e287 100644 --- a/device/include/pic16/ctype.h +++ b/device/include/pic16/ctype.h @@ -39,6 +39,9 @@ #ifndef __CTYPE_H #define __CTYPE_H 1 +/* link the C libarary */ +#pragma library c + #include extern char iscntrl (unsigned char ) ; diff --git a/device/include/pic16/gstack.h b/device/include/pic16/gstack.h index f5ab76dd..c309a7d8 100644 --- a/device/include/pic16/gstack.h +++ b/device/include/pic16/gstack.h @@ -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 index 00000000..eef8b75d --- /dev/null +++ b/device/include/pic16/i2c.h @@ -0,0 +1,121 @@ + +/* + * I2C communications module library header + * + * written by Vangelis Rokas, 2005 + * + * 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 + + +#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__ */ diff --git a/device/include/pic16/malloc.h b/device/include/pic16/malloc.h index cc5f2462..4f9d24e7 100644 --- a/device/include/pic16/malloc.h +++ b/device/include/pic16/malloc.h @@ -17,7 +17,7 @@ #ifndef __MALLOC_H__ #define __MALLOC_H__ -#include <../asm/pic16/features.h> +#pragma library c #define EMULATION 0 diff --git a/device/include/pic16/math.h b/device/include/pic16/math.h index 3ea9245a..c8b58ce0 100644 --- a/device/include/pic16/math.h +++ b/device/include/pic16/math.h @@ -28,6 +28,8 @@ #ifndef __PIC16_MATH_H #define __PIC16_MATH_H 1 +#pragma library math + #include #define PI 3.1415926536 diff --git a/device/include/pic16/stdio.h b/device/include/pic16/stdio.h index e0d52d14..daf5d204 100644 --- a/device/include/pic16/stdio.h +++ b/device/include/pic16/stdio.h @@ -31,6 +31,9 @@ #ifndef __PIC16_STDIO_H #define __PIC16_STDIO_H 1 +/* link the C library */ +#pragma library c + #include #include @@ -44,25 +47,26 @@ 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 */ diff --git a/device/include/pic16/stdlib.h b/device/include/pic16/stdlib.h index 8e522a2c..77ec060b 100644 --- a/device/include/pic16/stdlib.h +++ b/device/include/pic16/stdlib.h @@ -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); diff --git a/device/lib/pic16/Makefile b/device/lib/pic16/Makefile index fee486ad..ba6de15e 100644 --- a/device/lib/pic16/Makefile +++ b/device/lib/pic16/Makefile @@ -15,11 +15,14 @@ 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/*.* diff --git a/device/lib/pic16/Makefile.common.in b/device/lib/pic16/Makefile.common.in index 13e1e2ec..a7d77c5d 100644 --- a/device/lib/pic16/Makefile.common.in +++ b/device/lib/pic16/Makefile.common.in @@ -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 diff --git a/device/lib/pic16/configure b/device/lib/pic16/configure index 5ea2db5e..fcef71c7 100755 --- a/device/lib/pic16/configure +++ b/device/lib/pic16/configure @@ -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 diff --git a/device/lib/pic16/configure.in b/device/lib/pic16/configure.in index d6daa2d1..16034765 100644 --- a/device/lib/pic16/configure.in +++ b/device/lib/pic16/configure.in @@ -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 diff --git a/device/lib/pic16/debug/Makefile.rules b/device/lib/pic16/debug/Makefile.rules index 82548825..c76ece10 100644 --- a/device/lib/pic16/debug/Makefile.rules +++ b/device/lib/pic16/debug/Makefile.rules @@ -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)) diff --git a/device/lib/pic16/libc/Makefile b/device/lib/pic16/libc/Makefile index c73980f2..71b11918 100644 --- a/device/lib/pic16/libc/Makefile +++ b/device/lib/pic16/libc/Makefile @@ -14,10 +14,13 @@ 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 diff --git a/device/lib/pic16/libc/Makefile.rules b/device/lib/pic16/libc/Makefile.rules index b54bc579..582d5bd9 100644 --- a/device/lib/pic16/libc/Makefile.rules +++ b/device/lib/pic16/libc/Makefile.rules @@ -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 index 00000000..3797e4e0 --- /dev/null +++ b/device/lib/pic16/libc/stdio/Makefile @@ -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 +# +# $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 index 00000000..31ef4202 --- /dev/null +++ b/device/lib/pic16/libc/stdio/printf_small.c @@ -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 +#include +#include + +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++; + } +} diff --git a/device/lib/pic16/libc/stdlib/Makefile b/device/lib/pic16/libc/stdlib/Makefile index cb2da82d..b166c469 100644 --- a/device/lib/pic16/libc/stdlib/Makefile +++ b/device/lib/pic16/libc/stdlib/Makefile @@ -21,7 +21,8 @@ SRCS = atof \ ltoa \ malloc \ realloc \ - x_ftoa + x_ftoa \ + putchar CFILES = $(patsubst %,%.c,$(SRCS)) diff --git a/device/lib/pic16/libc/stdlib/ltoa.c b/device/lib/pic16/libc/stdlib/ltoa.c index 30d7772c..84203e8b 100644 --- a/device/lib/pic16/libc/stdlib/ltoa.c +++ b/device/lib/pic16/libc/stdlib/ltoa.c @@ -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 index 00000000..f526c289 --- /dev/null +++ b/device/lib/pic16/libc/stdlib/putchar.c @@ -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 + +/* 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; +} diff --git a/device/lib/pic16/libdev/Makefile b/device/lib/pic16/libdev/Makefile index 3d504a63..0cb604e0 100644 --- a/device/lib/pic16/libdev/Makefile +++ b/device/lib/pic16/libdev/Makefile @@ -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 diff --git a/device/lib/pic16/libio/Makefile b/device/lib/pic16/libio/Makefile index 45242dd0..abbf31d4 100644 --- a/device/lib/pic16/libio/Makefile +++ b/device/lib/pic16/libio/Makefile @@ -11,21 +11,35 @@ # # +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 diff --git a/device/lib/pic16/libio/Makefile.rules b/device/lib/pic16/libio/Makefile.rules index 4a8e9fbe..a7a64aee 100644 --- a/device/lib/pic16/libio/Makefile.rules +++ b/device/lib/pic16/libio/Makefile.rules @@ -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 index 00000000..7ad6f940 --- /dev/null +++ b/device/lib/pic16/libio/i2c/Makefile @@ -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 +# +# $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 index 00000000..e5ad735b --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cack.c @@ -0,0 +1,11 @@ + +#include + +#include + + +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 index 00000000..13ef805c --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cclose.c @@ -0,0 +1,10 @@ + +#include + +#include + + +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 index 00000000..bd61b3c3 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cdrdy.c @@ -0,0 +1,13 @@ + +#include + +#include + + +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 index 00000000..cd843838 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cidle.c @@ -0,0 +1,9 @@ + +#include + +#include + +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 index 00000000..ca2ac68d --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cnack.c @@ -0,0 +1,10 @@ + +#include + +#include + +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 index 00000000..bbb486e6 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2copen.c @@ -0,0 +1,32 @@ + +#include + +#include + +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 index 00000000..09f5bcd5 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2creadc.c @@ -0,0 +1,11 @@ + +#include + +#include + +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 index 00000000..6157599e --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2creads.c @@ -0,0 +1,26 @@ + +#include + +#include + + +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 index 00000000..16357468 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2crestart.c @@ -0,0 +1,9 @@ + +#include + +#include + +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 index 00000000..cae7491c --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cstart.c @@ -0,0 +1,9 @@ + +#include + +#include + +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 index 00000000..d348bbe3 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cstop.c @@ -0,0 +1,9 @@ + +#include + +#include + +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 index 00000000..90083316 --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cwritec.c @@ -0,0 +1,15 @@ + +#include + +#include + +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 index 00000000..09d9f51d --- /dev/null +++ b/device/lib/pic16/libio/i2c/i2cwrites.c @@ -0,0 +1,32 @@ + +#include + +#include + +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; +} diff --git a/device/lib/pic16/libsdcc/Makefile b/device/lib/pic16/libsdcc/Makefile index 2774f75b..5aed8cd2 100644 --- a/device/lib/pic16/libsdcc/Makefile +++ b/device/lib/pic16/libsdcc/Makefile @@ -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 diff --git a/device/lib/pic16/libsdcc/Makefile.rules b/device/lib/pic16/libsdcc/Makefile.rules index eba686d7..9e8bfc5f 100644 --- a/device/lib/pic16/libsdcc/Makefile.rules +++ b/device/lib/pic16/libsdcc/Makefile.rules @@ -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 diff --git a/device/lib/pic16/libsdcc/float/Makefile b/device/lib/pic16/libsdcc/float/Makefile index 917bac8d..be6b04a5 100644 --- a/device/lib/pic16/libsdcc/float/Makefile +++ b/device/lib/pic16/libsdcc/float/Makefile @@ -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 index 00000000..6ab84b9f --- /dev/null +++ b/device/lib/pic16/pics.all @@ -0,0 +1,18 @@ +242 +248 +252 +258 +442 +448 +452 +458 +1220 +2220 +6520 +6620 +6680 +6720 +8520 +8620 +8680 +8720 diff --git a/device/lib/pic16/startup/crt0i.c b/device/lib/pic16/startup/crt0i.c index 0fc9c165..75dd6b48 100644 --- a/device/lib/pic16/startup/crt0i.c +++ b/device/lib/pic16/startup/crt0i.c @@ -85,6 +85,7 @@ extern code struct #define tblrdpostinc tblrd*+ + /* the variable initialisation routine */ void _do_cinit (void) { diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 752113ca..2c211266 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -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 + + + + + + + +\begin_inset Text + +\layout Standard + +Keyword +\end_inset + + +\begin_inset Text + +\layout Standard + +Description +\end_inset + + +\begin_inset Text + +\layout Standard + +Module to link +\end_inset + + + + +\begin_inset Text + +\layout Standard + + +\series bold +ignore +\end_inset + + +\begin_inset Text + +\layout Standard + +ignore all library pragmas +\end_inset + + +\begin_inset Text + +\layout Standard + + +\emph on +(none) +\end_inset + + + + +\begin_inset Text + +\layout Standard + + +\series bold +c +\end_inset + + +\begin_inset Text + +\layout Standard + +link the C library +\end_inset + + +\begin_inset Text + +\layout Standard + + +\emph on +libc18f +\emph default +.lib +\end_inset + + + + +\begin_inset Text + +\layout Standard + + +\series bold +math +\end_inset + + +\begin_inset Text + +\layout Standard + +link the Math libarary +\end_inset + + +\begin_inset Text + +\layout Standard + + +\emph on +libm18f +\emph default +.lib +\end_inset + + + + +\begin_inset Text + +\layout Standard + + +\series bold +io +\end_inset + + +\begin_inset Text + +\layout Standard + +link the I/O library +\end_inset + + +\begin_inset Text + +\layout Standard + + +\emph on +libio18f* +\emph default +.lib +\end_inset + + + + +\begin_inset Text + +\layout Standard + + +\series bold +debug +\end_inset + + +\begin_inset Text + +\layout Standard + +link the debug library +\end_inset + + +\begin_inset Text + +\layout Standard + + +\emph on +libdebug +\emph default +.lib +\end_inset + + + + +\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 diff --git a/src/clean.mk b/src/clean.mk index d308c9b7..59d80d18 100644 --- a/src/clean.mk +++ b/src/clean.mk @@ -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 ;\ diff --git a/src/pic16/gen.c b/src/pic16/gen.c index e9b64a78..70e132b9 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -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; diff --git a/src/pic16/main.c b/src/pic16/main.c index b3b4d4e7..a570358a 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -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 diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index b12a47d1..bfeeac60 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -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; -- 2.30.2