+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
#ifndef __ADC_H__
#define __ADC_H__
+/* link I/O libarary */
+#pragma library io
/* interrupt on/off flag */
#define ADC_INT_OFF 0x00
#ifndef __CTYPE_H
#define __CTYPE_H 1
+/* link the C libarary */
+#pragma library c
+
#include <sdcc-lib.h>
extern char iscntrl (unsigned char ) ;
#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__ */
--- /dev/null
+
+/*
+ * 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__ */
#ifndef __MALLOC_H__
#define __MALLOC_H__
-#include <../asm/pic16/features.h>
+#pragma library c
#define EMULATION 0
#ifndef __PIC16_MATH_H
#define __PIC16_MATH_H 1
+#pragma library math
+
#include <sdcc-lib.h>
#define PI 3.1415926536
#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 */
#ifndef __PIC16_STDLIB_H
#define __PIC16_STDLIB_H 1
+#pragma library c
+
#ifndef NULL
# define NULL (void *)0
#endif
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);
include ./Makefile.common
-DIRS = libdev \
+DIRS = startup \
+ libdev \
libsdcc \
- libc \
- startup \
+ libc \
+ libm \
debug
+
+# libio
all: build-all-libraries
done
+lib-io:
+ $(MAKE) -C libio MODELFLAGS=$(MODELFLAGS)
+
clean: all-clean
$(RM) -f bin/*.*
MM = -MM
MODELFLAGS = -mpic16
+
+OPT_FLAGS += --denable-peeps
+OPT_FLAGS += --obanksel=9
+OPT_FLAGS += --optimize-goto
+OPT_FLAGS += --i-code-in-asm
# 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
# Checks for library functions.
+cp pics.all pics.build
+
AC_CONFIG_FILES([Makefile.common])
AC_OUTPUT
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))
DIRS = ctype \
stdlib \
+ stdio \
string \
utils
-LIB = libp18c.lib
+LOBJS = $(patsubst %,%/*.o,$(DIRS))
+
+LIB = libc18f.lib
all: build-libraries
for dir in $(DIRS) ; do \
$(MAKE) -C $$dir ; \
done;
- gplib -c $(LIB) string/*.o
+ gplib -c $(LIB) $(LOBJS)
mv -v $(LIB) ../bin
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))
$(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
--- /dev/null
+#
+# 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)
+
--- /dev/null
+/*-----------------------------------------------------------------
+ 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++;
+ }
+}
ltoa \
malloc \
realloc \
- x_ftoa
+ x_ftoa \
+ putchar
CFILES = $(patsubst %,%.c,$(SRCS))
{
if (value < 0 && radix == 10) {
*string++ = '-';
- ultoa(-value, string, radix);
- }
- else {
- ultoa(value, string, radix);
+ value = -value;
}
+
+ ultoa(value, string, radix);
}
--- /dev/null
+/*
+ * 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;
+}
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
all: make-lib
-make-lib: $(LFILES)
+make-lib: $(LFILES) clean-intermediate-no-asm
@$(MV) -v $(LFILES) ../bin
$(LFILES): $(OFILES)
clean-intermediate:
$(RM) -f *.lst *.asm *.dump*
+
+clean-intermediate-no-asm:
+ $(RM) -f *.lst *.dump*
clean: clean-intermediate
$(RM) -f *.o
#
#
+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
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))
%.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
--- /dev/null
+#
+# 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)
+
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+void i2c_ack(void)
+{
+ SSPCON2bits.ACKDT = 0;
+ SSPCON2bits.ACKEN = 1;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+void i2c_close(void)
+{
+ SSPCON1 &= 0xdf;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+
+unsigned char i2c_drdy(void)
+{
+ if(SSPSTATbits.BF)
+ return (+1);
+ else
+ return (0);
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_idle(void)
+{
+ while((SSPCON2 & 0x1f) | (SSPSTATbits.R_W));
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_nack(void)
+{
+ SSPCON2bits.ACKDT = 0;
+ SSPCON2bits.ACKEN = 1;
+}
--- /dev/null
+
+#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;
+}
+
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+unsigned char i2c_readchar(void)
+{
+ SSPCON2bits.RCEN = 1;
+ while( !I2C_DRDY() );
+ return ( SSPBUF );
+}
--- /dev/null
+
+#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;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_restart(void)
+{
+ SSPCON2bits.RSEN = 1;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_start(void)
+{
+ SSPCON2bits.SEN = 1;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <i2c.h>
+
+void i2c_stop(void)
+{
+ SSPCON2bits.PEN = 1;
+}
--- /dev/null
+
+#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;
+ }
+}
--- /dev/null
+
+#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;
+}
int \
long \
float \
- gptr \
- lregs
+ gptr
+# lregs
+# fixed16_16
+
+LOBJS = $(patsubst %,%/*.o,$(DIRS))
LIB = libsdcc.lib
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
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
$(SED) s/.rel/.o/g .tmpdepend >> .depend; \
$(RM) -f .tmpdepend; \
done;
-
+ if [ ! -e .depend ]; then touch .depend ; fi ;
include .depend
uint2fs \
ulong2fs
-#COMPILE_FLAGS += --obanksel=9
+LOCAL_FLAGS =
+COMPILE_FLAGS += $(LOCAL_FLAGS)
include ../Makefile.rules
build-library: $(LIB)
-$(LIB): $(OFILES)
+$(LIB): $(OFILES) clean-intermediate-no-asm
@echo Creating $(LIB) ...
@for object in $(OFILES) ; do \
if [ ! -e $(LIB) ]; then \
--- /dev/null
+242
+248
+252
+258
+442
+448
+452
+458
+1220
+2220
+6520
+6620
+6680
+6720
+8520
+8620
+8680
+8720
#define tblrdpostinc tblrd*+
+
/* the variable initialisation routine */
void _do_cinit (void)
{
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
\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
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
\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
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
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 ;\
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
}
#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;
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 );
}
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) {
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);
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;
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
};
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)
{
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
return 0;
}
+ /* #pragma wparam function1[, function2[,...]] */
if(startsWith(ptr, "wparam")) {
char *fname = strtok((char *)NULL, WHITECOMMA);
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;
}
{ 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"},
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);
/* forward declarations */
extern const char *pic16_linkCmd[];
extern const char *pic16_asmCmd[];
+extern set *asmOptionsSet;
static void
_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"));
}
}
"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
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)) )) {
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;