From: Walter Fetter Lages Date: Sun, 20 May 2018 05:55:16 +0000 (-0300) Subject: Fix bugs. X-Git-Tag: v1.4.3^0 X-Git-Url: http://git.ece.ufrgs.br/?a=commitdiff_plain;h=9ef2833f04364429abacbdfcaae756d40fd53759;p=aic.git Fix bugs. --- diff --git a/IODaemon/IODaemon.java b/IODaemon/IODaemon.java index 023354f..5edbf7b 100644 --- a/IODaemon/IODaemon.java +++ b/IODaemon/IODaemon.java @@ -32,7 +32,7 @@ import java.lang.*; class IODaemon extends Thread { static final int BASE=0x800000; - static final int ST=50; + static final int ST=500; static AIC aic; static Host host; diff --git a/MotorTest/MotorTest.java b/MotorTest/MotorTest.java index fb2b079..18f321b 100644 --- a/MotorTest/MotorTest.java +++ b/MotorTest/MotorTest.java @@ -62,12 +62,12 @@ class MotorTest aic.brake.release(); - for(i=0;(i <= 24) && run;i++) iter(i); + for(i=0;(i <= 12) && run;i++) iter(i); while(run) { - for(i=24;(i >= -24) && run;i--) iter(i); - for(i=-24;(i <= 24) && run;i++) iter(i); + for(i=12;(i >= -12) && run;i--) iter(i); + for(i=-12;(i <= 12) && run;i++) iter(i); } aic.off(); } diff --git a/lib/Makefile b/lib/Makefile index 5c14870..a24cb12 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -105,10 +105,15 @@ encoder.tlib: encoder.mpp ${ASM} ${ASMOPT} encoder.mpp pwm.mpp: pwm.a51 ${TINIINC} ${ASMINC}/aicpld.inc - ${ASMMACRO} -I${ASMINC} pwm.a51 + ${ASMMACRO} -I${ASMINC} -e- pwm.a51 -pwm.tlib: pwm.mpp - ${ASM} ${ASMOPT} pwm.mpp +pwm.tlib: pwm.mpp tlib/pwm.mpp + cat tlib/pwm.mpp pwm.mpp > pwm.tmp.mpp + echo end >> pwm.tmp.mpp + ${ASM} ${ASMOPT} pwm.tmp.mpp + +tlib/pwm.mpp: tlib/pwm.a51 + $(MAKE) -C tlib pwm.mpp AIC.jar: ${PKGPATH}/PLD.class\ ${PKGPATH}/CtrlRegister.class\ @@ -163,7 +168,7 @@ clean: $(MAKE) -C tlib clean distclean: clean - rm -rf AIC.jar *.a + rm -rf AIC.jar *.a aicio.mpp.lib $(MAKE) -C tlib distclean uninstall: diff --git a/lib/pwm.a51 b/lib/pwm.a51 index 7370e5b..1c551fa 100644 --- a/lib/pwm.a51 +++ b/lib/pwm.a51 @@ -31,6 +31,8 @@ $include(i8254.inc) $include(aicpld.inc) $include(aicmacro.inc) +_bpx EQU 01Eh ; _bpx (frame pointer) mapped to R8_B3:R7_B3 +_ap EQU 01Dh ; _ap mapped to R6_B3 ; data saved in big-endian mode ; PWM base address @@ -119,8 +121,17 @@ duty50: inc dptr ; point dptr to timer 1 ; Initializes PWM ; void pwm_initialize(unsigned long base,unsigned int min_count,unsigned int count); pwm_initialize: - clr a - lcall Natlib_LoadPrimitive ; get first parameter in R3:R2:R1:R0 + push _bpx ; SDCC style preface code + push _bpx+1 + mov _bpx,sp + mov _bpx+1,esp + anl _bpx+1,#3 + + + mov r0,dpl ; parameter in b:dpx:dph:dpl + mov r1,dph ; BUG IN SDCC MANUAL! + mov r2,dpx + mov r3,b push R0_B0 push R1_B0 @@ -140,18 +151,49 @@ pwm_initialize: STORE24 #pwm_base ; store PWM address - mov a,#1h - lcall Natlib_LoadPrimitive ; get second parameter in R3:R2:R1:R0 - mov dptr,#pwm_min_count ; stores it - mov a,r1 - movx @dptr,a + mov a,_bpx + clr c + subb a,#06 ; second parameter is base pointer-6 + mov b,a ; point dpx:dptr to it + mov a,_bpx+1 + subb a,#0 + mov dpx,#40h + mov dph,a + mov dpl,b + + movx a,@dptr ; min_count LSB + mov b,a inc dptr - mov a,r0 - movx @dptr,a - - mov a,#2h - lcall Natlib_LoadPrimitive ; get third parameter in R3:R2:R1:R0 + movx a,@dptr ; min_count MSB + mov dptr,#pwm_min_count ; stores it + movx @dptr,a + inc dptr + mov a,b + movx @dptr,a + + mov a,_bpx + clr c + subb a,#8 ; third parameter is base pointer-8 + mov b,a ; point dpx:dptr to it + mov a,_bpx+1 + subb a,#0 + mov dpx,#040h + mov dph,a + mov dpl,b + + movx a,@dptr ; store in dph:dpl + inc dptr + mov b,a + movx a,@dptr + mov dph,a + mov dpl,b + + mov sp,_bpx ; SDCC style epilogue code + mov esp,_bpx+1 + pop _bpx+1 + pop _bpx + ; to fall over max count should be in dph:dpl ljmp pwm_set_count ; fall over to native_setCount diff --git a/lib/tlib/Makefile b/lib/tlib/Makefile index b7a128d..7de5da2 100644 --- a/lib/tlib/Makefile +++ b/lib/tlib/Makefile @@ -51,7 +51,7 @@ encoder.mpp: encoder.a51 ${TINIINC} ${ASMMACRO} -I${ASMINC} encoder.a51 pwm.mpp: pwm.a51 ${TINIINC} - ${ASMMACRO} -I${ASMINC} pwm.a51 + ${ASMMACRO} -I${ASMINC} -e- pwm.a51 install: diff --git a/lib/tlib/pwm.a51 b/lib/tlib/pwm.a51 index ff7601d..d335686 100644 --- a/lib/tlib/pwm.a51 +++ b/lib/tlib/pwm.a51 @@ -48,7 +48,7 @@ native_setCount: lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0 ; only the lower 16 bits are usefull - mov dph,r1 ; SDCC parameters in dph:dpl + mov dph,r1 ; SDCC parameter in dph:dpl mov dpl,r0 ; BUG IN SDCC MANUAL! lcall pwm_set_count @@ -59,46 +59,44 @@ native_setCount: ; Initializes PWM ; private static native void initialize(int base,int min_count,int count); native_initialize: - clr a - lcall Natlib_LoadPrimitive ; get first parameter in R3:R2:R1:R0 - + mov a,#2h + lcall Natlib_LoadPrimitive ; get third parameter in R3:R2:R1:R0 + push R0_B0 push R1_B0 - push R2_B0 - mov dptr,#CONTROL ; compute Control address - lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0 + mov a,#1h + lcall Natlib_LoadPrimitive ; get second parameter in R3:R2:R1:R0 - STORE24 #ctrlbase ; store Control register address + push R0_B0 + push R1_B1 - pop R2_B0 - pop R1_B0 - pop R0_B0 + clr a + lcall Natlib_LoadPrimitive ; get first parameter in R3:R2:R1:R0 - mov dptr,#PWM ; compute PWM address - lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0 + mov b,r3 ; SDCC parameter in b:dpx:dph:dpl + mov dpx,r2 ; BUG IN SDCC MANUAL! + mov dph,r1 + mov dpl,r0 - STORE24 #pwmbase ; store PWM address - mov a,#1h - lcall Natlib_LoadPrimitive ; get second parameter in R3:R2:R1:R0 - mov dptr,#min_count ; stores it - mov a,r1 - movx @dptr,a - inc dptr - mov a,r0 - movx @dptr,a + lcall pwm_initialize - mov a,#2h - lcall Natlib_LoadPrimitive ; get third parameter in R3:R2:R1:R0 + pop ACC ; fix-up stack + pop ACC + pop ACC + pop ACC - ljmp set_count ; fall over to native_setCount + clr a ; sucess + ret ; Finalizes PWM ; public native void finalize() native_finalize: lcall pwm_finalize + + clr a ; sucess ret ; Sets the duty-cycle of PWM @@ -107,7 +105,7 @@ native_setDuty: clr a lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0 - mov b,r3 ; SDCC parameters in b:dpx:dph:dpl + mov b,r3 ; SDCC parameter in b:dpx:dph:dpl mov dpx,r2 ; BUG IN SDCC MANUAL! mov dph,r1 mov dpl,r0 @@ -128,12 +126,16 @@ native_setDuty: native_on: lcall pwm_on + + clr a ; sucess ret ; Turns the PWM off ; public static native void off() native_off: lcall pwm_off + + clr a ; sucess ret end diff --git a/motortst/motortst.cpp b/motortst/motortst.cpp index 42a5071..ff4da51 100644 --- a/motortst/motortst.cpp +++ b/motortst/motortst.cpp @@ -73,19 +73,19 @@ int main(int argc,char *argv[]) aic->motor.on(); aic->brake.release(); - for(i=0;(i <= 24) && run;i++) + for(i=0;(i <= 12) && run;i++) { if(kbhit()) run=0; iter(aic,i); } while(run) { - for(i=24;(i > -24) && run;i--) + for(i=12;(i > -12) && run;i--) { if(kbhit()) run=0; iter(aic,i); } - for(i=-24;(i <= 24) && run;i++) + for(i=-12;(i <= 12) && run;i++) { if(kbhit()) run=0; iter(aic,i);