From: johanknol Date: Fri, 2 Feb 2001 15:39:24 +0000 (+0000) Subject: update examples to use tinibios X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=6e06762225ea15cfc24f9572ca4b5680c1b094a3;p=fw%2Fsdcc update examples to use tinibios git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@564 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/device/examples/ds390/clock390/Makefile b/device/examples/ds390/clock390/Makefile index e5ebe099..caa9b3a0 100644 --- a/device/examples/ds390/clock390/Makefile +++ b/device/examples/ds390/clock390/Makefile @@ -3,16 +3,17 @@ CC = sdcc MFLAGS = -mds390 --model-flat24 --stack-10bit LFLAGS = --xram-loc 0x100080 --code-loc 0x10000 -Wl-r +OBJECTS = clock390.rel + all: clock390.hex clean: rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk -clock390.hex: clock390.ihx +clock390.hex: $(OBJECTS) + $(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS) packihx clock390.ihx >clock390.hex - -clock390.ihx: clock390.rel lcd.rel - $(CC) $(MFLAGS) $(LFLAGS) clock390.rel lcd.rel + #tinitalk -c execute clock390.hex %.rel: %.c $(CC) -c $(MFLAGS) $< diff --git a/device/examples/ds390/clock390/clock390.c b/device/examples/ds390/clock390/clock390.c index a2b0785a..d1f12edb 100644 --- a/device/examples/ds390/clock390/clock390.c +++ b/device/examples/ds390/clock390/clock390.c @@ -1,64 +1,31 @@ -/* This example compiles right out of the box for TINI after you did a - make install of sdcc (latest revision :). - - Just do a "make" which compiles and compresses it a little. - Than use JavaKit to load clock390.hex (it goes into bank 1, see Makefile) - Type 'E' in JavaKit and enjoy :) */ - -/* if you are using the (default) interrupt scheme for serial i/o, - you need to include this in the main program, so the vector will - be initialized */ -#include - -#include #include -#include "lcd.h" - -volatile unsigned long milliSeconds=0; - -#define RELOAD_VALUE 18432000/2/1000 // appr. 1ms -void Timer2Handler (void) interrupt 5 using 1 { - TF2=0; // reset overflow flag - milliSeconds++; - // that's all for now :) -} - -// we can't just use milliSeconds -unsigned long GetMilliSeconds(void) { - unsigned long ms; - ET2=0; - ms=milliSeconds; - ET2=1; - return ms; -} +/* If you don't have an lcd display, don't worry, it will just + toggle some bits in the void, but ok +*/ +#define USE_LCD void main (void) { unsigned long ms, seconds, oldSeconds=-1; - printf ("\n\rStarting timer 2 test.\n\r"); + printf ("\nStarting systemclock test.\n"); - // initialise timer - ET2=0; // disable timer interrupts initially - T2CON=0; // stop, timer mode, autoreload - T2MOD&=0xf4; - - TL2=RTL2=(-RELOAD_VALUE)&0xff; - TH2=RTH2=(-RELOAD_VALUE)>>8; - TR2=1; // run - - ET2=1; // enable timer interrupts - - // now do something +#ifdef USE_LCD LcdInit(); - LcdLPutString(0, "Testing timer2"); + LcdLPutString(0, "Testing clock"); LcdLPutString(2, "ms: "); +#endif + while (1) { - ms=GetMilliSeconds(); + ms=ClockTicks(); seconds=ms/1000; + +#ifdef USE_LCD LcdLPrintf (2 + (4<<8), "%ld", ms); +#endif + if (seconds!=oldSeconds) { - printf ("%02d:%02d.%02d\n\r", (int)seconds/3600, + printf ("%02d:%02d.%02d\n", (int)seconds/3600, (int)(seconds/60)%60, (int)seconds%60); oldSeconds=seconds; @@ -66,6 +33,12 @@ void main (void) { cpl P3.5 ; toggle led _endasm; } + if (Serial0CharArrived()) { + switch (getchar()) { + case '2': CpuSpeed(2); break; + case '4': CpuSpeed(4); break; + } + } } } diff --git a/device/examples/ds390/hello390/Makefile b/device/examples/ds390/hello390/Makefile index 73cb15ae..e165af46 100644 --- a/device/examples/ds390/hello390/Makefile +++ b/device/examples/ds390/hello390/Makefile @@ -1,10 +1,9 @@ -hello390.hex: hello390.ihx - packihx hello390.ihx >hello390.hex - -hello390.ihx: hello390.c +hello390.hex: hello390.c sdcc -mds390 --model-flat24 --stack-10bit \ --xram-loc 0x100080 --code-loc 0x10000 \ -Wl-r hello390.c + packihx hello390.ihx >hello390.hex + #tinitalk -c execute hello390.hex clean: rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk diff --git a/device/examples/ds390/hello390/hello390.c b/device/examples/ds390/hello390/hello390.c index b735641b..5504f736 100644 --- a/device/examples/ds390/hello390/hello390.c +++ b/device/examples/ds390/hello390/hello390.c @@ -1,17 +1,5 @@ -/* This example compiles right out of the box for TINI after you did a - make install of sdcc (latest revision :). - - Just do a "make" which compiles and compresses it a little. - Than use JavaKit to load hello390.hex (it goes into bank 1, see Makefile) - Type 'E' in JavaKit and enjoy :) */ - -/* if you are using the (default) interrupt scheme for serial i/o, - you need to include this in the main program, so the vector will - be initialized */ -#include - #include void main (void) { - printf ("\n\rHello from 390.\n\rSee you, bye..."); + printf ("\nHello from 390.\nSee you, bye..."); } diff --git a/device/examples/ds390/i2c390/Makefile b/device/examples/ds390/i2c390/Makefile index b6d233de..d077d0f5 100644 --- a/device/examples/ds390/i2c390/Makefile +++ b/device/examples/ds390/i2c390/Makefile @@ -3,18 +3,17 @@ CC = sdcc MFLAGS = -mds390 --model-flat24 --stack-10bit LFLAGS = --xram-loc 0x100080 --code-loc 0x10000 -Wl-r +OBJECTS = i2c390.rel ds1621.rel pcf8591.rel + all: i2c390.hex clean: rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk -OBJECTS = i2c390.rel i2clole.rel ds1621.rel pcf8591.rel - -i2c390.hex: i2c390.ihx - packihx i2c390.ihx >i2c390.hex - -i2c390.ihx: $(OBJECTS) +i2c390.hex: $(OBJECTS) $(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS) + packihx i2c390.ihx >i2c390.hex + #tinitalk -c execute i2c390.hex %.rel: %.c $(CC) -c $(MFLAGS) $< diff --git a/device/examples/ds390/i2c390/ds1621.c b/device/examples/ds390/i2c390/ds1621.c index f91ac5ff..7592991b 100644 --- a/device/examples/ds390/i2c390/ds1621.c +++ b/device/examples/ds390/i2c390/ds1621.c @@ -1,7 +1,6 @@ -#include "i2clole.h" -#include "ds1621.h" - +#include +#include "ds1621.h" float ReadDS1621(char address) { float temperature; diff --git a/device/examples/ds390/i2c390/i2c390.c b/device/examples/ds390/i2c390/i2c390.c index c034a6e7..7bd00d37 100644 --- a/device/examples/ds390/i2c390/i2c390.c +++ b/device/examples/ds390/i2c390/i2c390.c @@ -1,20 +1,3 @@ -/* This example compiles right out of the box for TINI after you did a - make install of sdcc (latest revision :). - - It prints the value of the DS1621 temperature sensor (at address 2) - and the 4 values of the PCF8591 ad-convertor (at address 0). - It (ab)uses the CAN CTX and CTR pins of the DS80C390. - Make sure you have pull-up resistors connected or it WON'T work. - - Just do a "make" which compiles and compresses it a little. - Than use JavaKit to load i2c390.hex (it goes into bank 1, see Makefile) - Type 'E' in JavaKit and enjoy :) */ - -/* if you are using the (default) interrupt scheme for serial i/o, - you need to include this in the main program, so the vector will - be initialized */ -#include - #include #include "ds1621.h" diff --git a/device/examples/ds390/i2c390/pcf8591.c b/device/examples/ds390/i2c390/pcf8591.c index c6f3981c..82d6420f 100644 --- a/device/examples/ds390/i2c390/pcf8591.c +++ b/device/examples/ds390/i2c390/pcf8591.c @@ -1,4 +1,5 @@ -#include "i2clole.h" +#include + #include "pcf8591.h" unsigned char ReadPCF8591(char address, char channel) { diff --git a/device/examples/ds390/i2c390/pcf8591.h b/device/examples/ds390/i2c390/pcf8591.h index 72f10b5a..7e38b39d 100644 --- a/device/examples/ds390/i2c390/pcf8591.h +++ b/device/examples/ds390/i2c390/pcf8591.h @@ -1,2 +1,3 @@ #define PCF8591_ID 0x90 + extern unsigned char ReadPCF8591(char address, char channel); diff --git a/device/lib/ds390/Makefile b/device/lib/ds390/Makefile index 78a0ee89..1ea1235e 100755 --- a/device/lib/ds390/Makefile +++ b/device/lib/ds390/Makefile @@ -2,7 +2,7 @@ CC = ../../../bin/sdcc #VERBOSE = --verbose -OBJECTS = tinibios.rel memcpyx.rel +OBJECTS = tinibios.rel memcpyx.rel rtc390.rel lcd390.rel i2c390.rel SOURCES = $(patsubst %.rel,%.c,$(OBJECTS)) diff --git a/device/lib/ds390/tinibios.c b/device/lib/ds390/tinibios.c index 3a6743aa..d70e4427 100755 --- a/device/lib/ds390/tinibios.c +++ b/device/lib/ds390/tinibios.c @@ -44,7 +44,8 @@ unsigned char _sdcc_external_startup(void) // CKCON|=0xc0; // default stretch cycles for MOVX - CKCON = (CKCON&0xf8)|(CPU_MOVX_STRETCH&0x07); + //CKCON = (CKCON&0xf8)|(CPU_MOVX_STRETCH&0x07); + CKCON=0xf9; // use internal 4k RAM as data(stack) memory at 0x400000 and // move CANx memory access to 0x401000 and upwards @@ -61,13 +62,13 @@ unsigned char _sdcc_external_startup(void) pop ar0; lsb - mov _ESP,#0x00; reinitialize the stack - mov _SP,#0x00 - mov _TA,#0xaa; timed access mov _TA,#0x55 mov _ACON,#0x06; 24 bit addresses, 10 bit stack at 0x400000 + mov _ESP,#0x00; reinitialize the stack + mov _SP,#0x00 + ; restore the 24-bit return address push ar0; lsb push ar1 @@ -357,7 +358,7 @@ void Serial1Init (unsigned long baud, unsigned char buffered) { // set the baud rate Serial1Baud(baud); - serial0Buffered=buffered; + serial1Buffered=buffered; if (buffered) { RI_1=TI_1=0; // clear "pending" interrupts @@ -455,8 +456,7 @@ void Serial1Flush() { // now let's go for the clock stuff -//#define TIMER_0_RELOAD_VALUE 18432000L/2/1000 // appr. 1ms - +// these REALLY need to be in data space for the irq routine! static data unsigned long milliSeconds=0; static data unsigned int timer0ReloadValue; @@ -469,27 +469,55 @@ void ClockInit() { case 2: // not tested yet default: timerReloadValue/=2; break; } - timer0ReloadValue=timerReloadValue; + timer0ReloadValue=~timerReloadValue; // initialise timer 0 ET0=0; // disable timer interrupts initially TCON = (TCON&0xcc)|0x00; // stop timer, clear overflow TMOD = (TMOD&0xf0)|0x01; // 16 bit counter - CKCON|=0x80; // timer uses xtal/4 + CKCON|=0x08; // timer uses xtal/4 - TL0=~(timer0ReloadValue&0xff); - TH0=~(timer0ReloadValue>>8); + TL0=timer0ReloadValue&0xff; + TH0=timer0ReloadValue>>8; ET0=1; // enable timer interrupts TR0=1; // start timer } +// This needs to be SUPER fast. What we really want is: + +#if 0 void ClockIrqHandler (void) interrupt 1 { - // we have lost some time here - TL0=~(timer0ReloadValue&0xff); - TH0=~(timer0ReloadValue>>8); + TL0=timer0ReloadValue&0xff; + TH0=timer0ReloadValue>>8; milliSeconds++; - // that's all for now :) } +#else +// but look at the code, and the pushes and pops, so: +#pragma EXCLUDE b,dpl,dph,dpx +void ClockIrqHandler (void) interrupt 1 { + _asm + mov _TL0,_timer0ReloadValue + mov _TH0,_timer0ReloadValue+1 + mov a,#0x01 + add a,_milliSeconds+0 + mov _milliSeconds,a + jnc _ClockIrqHandlerDone + clr a + addc a,_milliSeconds+1 + mov _milliSeconds+1,a + jnc _ClockIrqHandlerDone + clr a + addc a,_milliSeconds+2 + mov _milliSeconds+1,a + jnc _ClockIrqHandlerDone + clr a + addc a,_milliSeconds+3 + mov _milliSeconds+1,a + _ClockIrqHandlerDone: + _endasm; +} +#pragma EXCLUDE NONE +#endif // we can't just use milliSeconds unsigned long ClockTicks(void) {