# Project specific
# TINI executable
*.tini
+*.mpp
+*.lst
+*.tlib
# Text editor
# Backup files
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ Brake Real Time Test
+ User Interface Module
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+import com.dalsemi.system.*;
+
+public class BrakeRtTest
+{
+ public static native int startRealtime(int period);
+ public static native void stopRealtime();
+
+ public static void main(String[] args)
+ {
+ System.out.println("BrakeRtTest");
+ System.out.println("Copyright (C) Walter Fetter Lages, 2005.\n");
+
+ int tfms=0;
+ if(args.length==1)
+ {
+ tfms=Integer.parseInt(args[0]);
+ }
+ else
+ {
+ System.out.println("Usage:\tBrakeRtTest ms");
+ System.exit(1);
+ }
+
+ System.out.print("Loading native library...");
+ System.loadLibrary("braketest.tlib");
+ System.out.println("done.");
+
+ int us=10000;
+ System.out.print("Starting real-time timer with "+us+" us period...");
+ int period=startRealtime(us);
+ System.out.println("done.");
+ System.out.println("Effective period: "+period+" us.");
+
+ System.out.println("Running BrakeRtTest for "+tfms+" ms...");
+ long t0=TINIOS.uptimeMillis();
+ long t=0;
+ while(t <= tfms)
+ {
+ t=TINIOS.uptimeMillis()-t0;
+ System.out.print("t="+t+" ms");
+ }
+ System.out.println("...done.");
+
+ System.out.print("Stoping real-time timer...");
+ stopRealtime();
+ System.out.println("done.");
+ }
+}
--- /dev/null
+CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar
+APIDBPATH=-d /opt/tini/bin/tini.db
+TINIRTAIPATH=${HOME}/src/tini/rtai
+LIBPATH=-PATH ${TINIRTAIPATH}/lib/rtai.jar
+JAVAFLAGS=-O -target 1.1 -source 1.3
+ASMINC=-I/opt/tini/native/lib
+ASMOPT=-f 1.15 -p 390 -l
+ASMMACRO=/opt/tini/native/bin/Linux/macro
+ASM=/opt/tini/native/bin/Linux/a390
+CC=sdcc
+CFLAGS=-mTININative -S --use-accelerator
+CINCLUDE=-I${TINIRTAIPATH}/include -I../include
+CMPFLAGS=${CFLAGS} ${CINCLUDE}
+
+all: BrakeRtTest.tini
+
+BrakeRtTest.class: BrakeRtTest.java
+ javac ${CLASSPATH} ${JAVAFLAGS} BrakeRtTest.java
+
+braketest.mpp: braketest.a51
+ ${ASMMACRO} ${ASMINC} -e- braketest.a51
+
+globals.mpp: globals.a51
+ ${ASMMACRO} ${ASMINC} -e- globals.a51
+
+braketest.tlib: braketest.mpp globals.mpp ../lib/aicio.mpp.lib
+ cat braketest.mpp globals.mpp ../lib/aicio.mpp.lib > tmp.mpp
+ echo end >> tmp.mpp
+ ${ASM} ${ASMOPT} tmp.mpp
+ mv tmp.tlib braketest.tlib
+ mv tmp.lst braketest.lst
+
+braketest.a51: braketest.c
+ ${CC} ${CMPFLAGS} braketest.c
+
+BrakeRtTest.tini: BrakeRtTest.class braketest.tlib
+ java ${CLASSPATH} TINIConvertor -n braketest.tlib -f BrakeRtTest.class ${APIDBPATH} -o BrakeRtTest.tini
+
+
+clean:
+ rm -f *.bak *~ BrakeRtTest.class braketest.tlib braketest.mpp braketest.lst braketest.a51 globals.mpp tmp.mpp tmp.lst
+
+distclean: clean
+ rm -f BrakeRtTest.tini
+
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ Brake Real Time Test
+ Real Time Module
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+#include<aicio.h>
+
+#define BASE 0x800000
+
+void initialize(void)
+{
+ brake_initialize(BASE);
+}
+
+/* public static native int startRealtime(int period) */
+long Native_startRealtime(void) _JavaNative
+{
+ volatile long period = NatLib_LoadInt(0);
+
+ _asm
+
+ mov T2CON,#00h ; clear TR2 = disable timer 2
+ anl IE,#0dfh ; clear ET2 = disable timer 2 interrupt
+
+ mov dps,#1
+ mov dptr,#braketest
+ mov a,#2bh ; timer 2
+ call System_InstallInterrupt
+ mov dps,#00h
+
+ anl CKCON,#0dfh ; clear T2M = timer 2 uses clock/12
+ mov T2MOD,#00h ; clear DCEN = counts up only
+
+; TINI oscillator is 18432000 => counter=0c400h=100Hz
+ mov RCAP2L,#00h ; count reload LSB
+ mov TL2,#00h ; count LSB
+ mov RCAP2H,#0c4h ; count reload MSB
+ mov TH2,#0c4h ; count MSB
+
+ orl IP,#20h ; set PT2 = set timer 2 interrupt to high priority
+ orl IE,#20h ; set ET2 = enable timer 2 interrupt
+
+ mov T2CON,#04h ; set TR2 = enable timer 2
+ _endasm;
+
+ initialize();
+
+ return period;
+}
+
+/* public static native void stopRealtime() */
+void Native_stopRealtime(void) _JavaNative
+{
+ _asm
+ mov T2CON,#00h ; clear TR2 = disable timer 2
+ anl IE,#0dfh ; clear ET2 = disable timer 2 interrupt
+ anl IP,#0dfh ; clear PT2 = set timer 2 interrupt to normal priority
+ _endasm;
+}
+
+static void int2ack(void)
+{
+ _asm
+ anl T2CON,#7fh ; clear TF2 = clears timer 2 overflow
+ _endasm;
+}
+
+static void braketest(void) interrupt
+{
+ static int time=0;
+
+ int2ack();
+
+ if(time) brake_apply(); else brake_release();
+ time=~time;
+}
+
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; Brake Real Time Test
+; Real Time Module Global Variables
+; Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************/
+
+
+braketest_time_1_1: db 0,0,0,0
+ end
+2005.08.12 Criado o programa DoorDaemon, para implementar a abertura de
+ uma porta conectada no sinal de freio da AIC atraves da
+ Internet, utilizando um protocolo CHAP com sha-1.
+
+2005.06.03 Criada versao 1.4.2
+
+ Criada a biblioteca aicio.mpp.lib, com funcoes implementadas
+ que podem ser chamadas a partir de modulos de tempo real em
+ C para acessar o hardware da AIC. Codigos fontes dos metodos
+ nativos que acessam o hardware modificados para usarem a
+ biblioteca aicio.mpp.lib.
+
+ Criado o programa PID, que implementa em tempo real o
+ prototipo de um controlador PID, com transferencia de
+ referencias e variaveis de saida entre a interface com o
+ usuario e o modulo de tempo real.
+
+ Criados os programas BrakeRtTest e IndexRtTest para de teste
+ do freio e do indice em tempo real em C.
+
2005.01.06 Criada versao 1.4.1
2004.12.05 Corrigido bug nas inicializacao das classes AIC_CAN e
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ Door Daemon
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+import br.ufrgs.eletro.AIC.*;
+import com.dalsemi.system.*;
+import com.dalsemi.tininet.*;
+import java.net.*;
+
+class DoorDaemon extends Thread
+{
+ private static final int BASE=0x800000;
+ private static final int DD_PORT=9880;
+
+ private TINIDatagramSocket ddsock;
+
+ static AIC aic;
+
+ public static void main(String[] args)
+ {
+ int i;
+ int hostarg=0;
+
+ System.out.println("AIC Door Daemon");
+ System.out.println("Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>.\n");
+
+ try
+ {
+ aic=new AIC(BASE,24.0,20e3,2000);
+
+ TINIDatagramSocket ddsock=new TINIDatagramSocket(DD_PORT);
+
+ byte[] buff= new byte[256];
+ DatagramPacket p=new DatagramPacket(buff,256);
+
+ byte[] rmadd= new byte[18];
+
+ for(;;)
+ {
+
+ ddsock.receive(p,rmadd,0);
+
+ Chap chap=new Chap(rmadd);
+ chap.start();
+ sleep(1000);
+ chap.stop();
+ }
+ }
+ catch (Exception all)
+ {
+ all.printStackTrace();
+ }
+ }
+}
+
+
+class Chap extends DoorDaemon
+{
+ // socket for transmitting challenge
+ private TINIDatagramSocket chsock;
+ private InetAddress chaddr;
+ private int chport;
+
+ public Chap(byte[] rmadd)
+ {
+ try
+ {
+ chsock=new TINIDatagramSocket();
+ int chip=(((int)rmadd[12]) << 24) | (((int)rmadd[13]) << 16) | (((int)rmadd[14]) << 8) | (int)rmadd[15];
+ chaddr=InetAddress.getByName(rmadd[12]+"."+rmadd[13]+"."+rmadd[14]+"."+rmadd[15]);
+ chport=(((int)rmadd[16]) << 8) | (int)rmadd[17];
+ }
+ catch (Exception all)
+ {
+ all.printStackTrace();
+ }
+ }
+
+ public void run()
+ {
+ int challenge=Security.getRandom();
+ byte[] chbuff=new byte[4];
+
+ byte[] passwd="abcd".getBytes();
+
+ for(int i=0;i < 4;i++)
+ {
+ chbuff[i]=(byte)((challenge >> (8*i)) & 0xff);
+ passwd[i]=(byte)(chbuff[i] ^ passwd[i]);
+ }
+ byte[] hash=Security.hashMessage(passwd);
+
+ try
+ {
+ DatagramPacket chp=new DatagramPacket(chbuff,4,chaddr,chport);
+ chsock.send(chp);
+
+ byte[] respbuff= new byte[256];
+ DatagramPacket respp=new DatagramPacket(respbuff,256);
+
+ chsock.receive(respp);
+
+ if(respbuff==hash)
+ {
+ aic.on();
+ aic.brake.release();
+ sleep(1000);
+ aic.brake.apply();
+ aic.off();
+ }
+ }
+ catch (Exception all)
+ {
+ all.printStackTrace();
+ }
+ }
+}
+
+
--- /dev/null
+CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar:/opt/tini/bin/modules.jar:../lib/AIC.jar
+APIDBPATH=-d /opt/tini/bin/tini.db
+DEPPATH=-p /opt/tini/bin/modules.jar
+DEPFILE=-x /opt/tini/bin/owapi_dep.txt
+DEPNAME=
+#-add CAN
+LIBPATH=-path ../lib/AIC.jar
+NATLIB=-n brake.tlib -n encoder.tlib -n index.tlib -n pwm.tlib
+JAVAFLAGS=-O -target 1.1 -source 1.3
+TARGET= aic1 aic2 aic3 aic4 aic5
+
+all: DoorDaemon.tini
+
+DoorDaemon.class: DoorDaemon.java ../lib/AIC.jar
+ javac ${JAVAFLAGS} ${CLASSPATH} DoorDaemon.java
+
+DoorDaemon.tini: DoorDaemon.class ../lib/AIC.jar
+ java ${CLASSPATH} BuildDependency ${DEPNAME} ${DEPFILE} ${DEPPATH} -f DoorDaemon.class ${APIDBPATH} -o DoorDaemon.tini ${LIBPATH} ${NATLIB}
+
+clean:
+ rm -f *.bak *~ *.class
+
+distclean: clean
+ rm -f DoorDaemon.tini
+
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ Index Real Time Test
+ User Interface Module
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+import com.dalsemi.system.*;
+
+public class IndexRtTest
+{
+ public static native int startRealtime(int period);
+ public static native void stopRealtime();
+ public static native boolean getIndex();
+
+ public static void main(String[] args)
+ {
+ System.out.println("IndexRtTest");
+ System.out.println("Copyright (C) Walter Fetter Lages, 2005.\n");
+
+ int tfms=0;
+ if(args.length==1)
+ {
+ tfms=Integer.parseInt(args[0]);
+ }
+ else
+ {
+ System.out.println("Usage:\tIndexRtTest ms");
+ System.exit(1);
+ }
+
+ System.out.print("Loading native library...");
+ System.loadLibrary("indextest.tlib");
+ System.out.println("done.");
+
+ int us=10000;
+ System.out.print("Starting real-time timer with "+us+" us period...");
+ int period=startRealtime(us);
+ System.out.println("done.");
+ System.out.println("Effective period: "+period+" us.");
+
+ System.out.println("Running IndexRtTest for "+tfms+" ms...");
+ long t0=TINIOS.uptimeMillis();
+ long t=0;
+ while(t <= tfms)
+ {
+ t=TINIOS.uptimeMillis()-t0;
+ System.out.print("t="+t+" ms");
+ System.out.println("\tindex="+getIndex());
+ }
+ System.out.println("...done.");
+
+ System.out.print("Stoping real-time timer...");
+ stopRealtime();
+ System.out.println("done.");
+ }
+}
--- /dev/null
+CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar
+APIDBPATH=-d /opt/tini/bin/tini.db
+TINIRTAIPATH=${HOME}/src/tini/rtai
+LIBPATH=-PATH ${TINIRTAIPATH}/lib/rtai.jar
+JAVAFLAGS=-O -target 1.1 -source 1.3
+ASMINC=-I/opt/tini/native/lib
+ASMOPT=-f 1.15 -p 390 -l
+ASMMACRO=/opt/tini/native/bin/Linux/macro
+ASM=/opt/tini/native/bin/Linux/a390
+CC=sdcc
+CFLAGS=-mTININative -S --use-accelerator
+CINCLUDE=-I${TINIRTAIPATH}/include -I../include
+CMPFLAGS=${CFLAGS} ${CINCLUDE}
+
+all: IndexRtTest.tini
+
+IndexRtTest.class: IndexRtTest.java
+ javac ${CLASSPATH} ${JAVAFLAGS} IndexRtTest.java
+
+indextest.mpp: indextest.a51
+ ${ASMMACRO} ${ASMINC} -e- indextest.a51
+
+globals.mpp: globals.a51
+ ${ASMMACRO} ${ASMINC} -e- globals.a51
+
+indextest.tlib: indextest.mpp globals.mpp ../lib/aicio.mpp.lib
+ cat indextest.mpp globals.mpp ../lib/aicio.mpp.lib > tmp.mpp
+ echo end >> tmp.mpp
+ ${ASM} ${ASMOPT} tmp.mpp
+ mv tmp.tlib indextest.tlib
+ mv tmp.lst indextest.lst
+
+indextest.a51: indextest.c
+ ${CC} ${CMPFLAGS} indextest.c
+
+IndexRtTest.tini: IndexRtTest.class indextest.tlib
+ java ${CLASSPATH} TINIConvertor -n indextest.tlib -f IndexRtTest.class ${APIDBPATH} -o IndexRtTest.tini
+
+
+clean:
+ rm -f *.bak *~ IndexRtTest.class indextest.tlib indextest.mpp indextest.lst indextest.a51 globals.mpp tmp.mpp tmp.lst
+
+distclean: clean
+ rm -f IndexRtTest.tini
+
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; Index Real Time Test
+; Real Time Module Global Variables
+; Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************/
+
+
+index: db 0,0,0,0
+ end
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ Brake Real Time Test
+ Real Time Module
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+#include<aicio.h>
+
+#define BASE 0x800000
+
+extern volatile long index;
+
+void initialize(void)
+{
+ index_initialize(BASE);
+}
+
+/* public static native int startRealtime(int period) */
+long Native_startRealtime(void) _JavaNative
+{
+ volatile long period = NatLib_LoadInt(0);
+
+ _asm
+
+ mov T2CON,#00h ; clear TR2 = disable timer 2
+ anl IE,#0dfh ; clear ET2 = disable timer 2 interrupt
+
+ mov dps,#1
+ mov dptr,#indextest
+ mov a,#2bh ; timer 2
+ call System_InstallInterrupt
+ mov dps,#00h
+
+ anl CKCON,#0dfh ; clear T2M = timer 2 uses clock/12
+ mov T2MOD,#00h ; clear DCEN = counts up only
+
+; TINI oscillator is 18432000 => counter=0c400h=100Hz
+ mov RCAP2L,#00h ; count reload LSB
+ mov TL2,#00h ; count LSB
+ mov RCAP2H,#0c4h ; count reload MSB
+ mov TH2,#0c4h ; count MSB
+
+ orl IP,#20h ; set PT2 = set timer 2 interrupt to high priority
+ orl IE,#20h ; set ET2 = enable timer 2 interrupt
+
+ mov T2CON,#04h ; set TR2 = enable timer 2
+ _endasm;
+
+ initialize();
+
+ return period;
+}
+
+/* public static native void stopRealtime() */
+void Native_stopRealtime(void) _JavaNative
+{
+ _asm
+ mov T2CON,#00h ; clear TR2 = disable timer 2
+ anl IE,#0dfh ; clear ET2 = disable timer 2 interrupt
+ anl IP,#0dfh ; clear PT2 = set timer 2 interrupt to normal priority
+ _endasm;
+}
+
+static void int2ack(void)
+{
+ _asm
+ anl T2CON,#7fh ; clear TF2 = clears timer 2 overflow
+ _endasm;
+}
+
+static void indextest(void) interrupt
+{
+ int2ack();
+
+ index=index_read();
+}
+
+/* public static native boolean getIndex() */
+long Native_getIndex(void) _JavaNative
+{
+ return index;
+}
+
JointTest \
MotorReset \
MotorTest \
- PIDDaemon \
+ PID \
StrobeTest \
+ DoorDaemon \
aicd \
braketst \
encodertst \
ASM=/opt/tini/native/bin/Linux/a390
CC=sdcc
CFLAGS=-mTININative -S --use-accelerator
-CINCLUDE=-I${TINIRTAIPATH}/include
+CINCLUDE=-I${TINIRTAIPATH}/include -I../include
CMPFLAGS=${CFLAGS} ${CINCLUDE}
all: PID.tini
globals.mpp: globals.a51
${ASMMACRO} ${ASMINC} globals.a51
-pid.tlib: pid.mpp globals.mpp
- cat pid.mpp globals.a51 > tmp.mpp
+pid.tlib: pid.mpp globals.mpp ../lib/aicio.mpp.lib
+ cat pid.mpp ../lib/aicio.mpp.lib globals.mpp > tmp.mpp
${ASM} ${ASMOPT} tmp.mpp
mv tmp.tlib pid.tlib
mv tmp.lst pid.lst
System.out.println("Running PID for "+tfms+" ms...");
long t0=TINIOS.uptimeMillis();
long t=0;
- while(t <= tfms)
+ while(t <= tfms || true)
{
t=TINIOS.uptimeMillis()-t0;
System.out.print("t="+t+" ms");
float ref=((float)t)/2;
- setReference(ref);
- System.out.println("\treference="+ref+"\toutput="+getOutput());
+// setReference(ref);
+ System.out.print("\treference="+ref);
+ System.out.println("\toutput="+getOutput());
}
System.out.println("...done.");
output: db 0,0,0,0
-th: db 0,0
+;th: db 0,0
reference: db 0,0,0,0
+controller_time_1_1: db 0,0,0,0
end
*******************************************************************************/
+#include<aicio.h>
+
+#define BASE 0x800000
+
extern volatile float output;
extern volatile float reference;
+void initialize(void)
+{
+ brake_initialize(BASE);
+}
+
/* public static native int startRealtime(int period) */
long Native_startRealtime(void) _JavaNative
{
mov T2CON,#04h ; set TR2 = enable timer 2
_endasm;
+
+ initialize();
return period;
}
static void controller(void) interrupt
{
+ static int time=0;
+
int2ack();
+ if(time) brake_apply(); else brake_release();
+ time=~time;
+
output=reference;
}
--- /dev/null
+/******************************************************************************
+ Actuator Interface Card
+ I/O Interface Library
+
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+#ifndef _AICIO_H
+#define _AICIO_H
+
+/** @file aicio.h
+* I/O Interface Library
+* @author Walter Fetter Lages <w.fetter@ieee.org>
+* @since AIC-1.4.2
+*/
+
+/** @defgroup aicio AIC I/O Interface
+@{
+*/
+
+/** Initializes brake
+* @param base Base address for on board devices
+* @since AIC-1.4.2
+*/
+extern void brake_initialize(unsigned long base);
+
+/** Applies the electromagnetic brake
+* @since AIC-1.4.2
+*/
+extern void brake_apply(void);
+
+/** Releases the electromagnetic brake
+* @since AIC-1.4.2
+*/
+extern void brake_release(void);
+
+/** Initializes Index
+* @param base Base address for on board devices
+* @since AIC-1.4.2
+*/
+extern void index_initialize(unsigned long base);
+
+/** Reads the sync-switch
+* @return the sync-switch state
+* @since AIC-1.4.2
+*/
+extern unsigned long index_read(void);
+
+/** Sets the frequency of PWM in cycles of 10MHz
+* @param count number of cycles from 10 to 65530. Default
+* value is 500
+* @since AIC-1.4.2
+*/
+extern void pwm_set_count(unsigned int count);
+
+/** Sets the frequency of PWM
+* @param frequency frequency in Hz from 152.60Hz to 1MHz. Default
+* value is 20KHz
+* @since AIC-1.4.2
+*/
+extern void pwm_set_freq(float frequency);
+
+/** Returns the frequency of PWM
+* @return PWM frequency in Hz
+* @since AIC-1.4.2
+*/
+//extern double pwm_get_freq(void);
+
+/** PWM initialization
+* @param base Base address for on board devices
+* @param min_count MIN_COUNT
+* @param count frequency of PWM in cycles of 10MHz. Number of cycles
+* from 10 to 65530.
+* @since AIC-1.4.2
+*/
+extern void pwm_initialize(unsigned long base,unsigned int min_count,unsigned int count);
+
+/** Finalizes the PWM
+* @since AIC-1.4.2
+*/
+extern void pwm_finalize(void);
+
+/** Sets the duty-cycle of PWM
+* @param dutycycle to be used by PWM as a float from 0 to 1.0
+* @return the count value programmed to the PWM timer
+* @since AIC-1.4.2
+*/
+extern unsigned long pwm_set_duty(float dutycycle);
+
+/** Sets the duty-cycle of PWM
+* @param dutycycle to be used by PWM as a int from 0 to 1000000
+* @return the count value programmed to the PWM timer
+* @since AIC-1.4.2
+*/
+extern unsigned long pwm_set_duty(unsigned long dutycycle);
+
+/** Turns the PWM on
+* @since AIC-1.4.2
+*/
+extern void pwm_on(void);
+
+/** Turns the PWM off
+* @since AIC-1.4.2
+*/
+extern void pwm_off(void);
+
+/**
+@}
+*/
+#endif
+++ /dev/null
-/opt/tini/native/lib/apiequ.inc
\ No newline at end of file
NATINC=/opt/tini/native/lib
ASMINC=../include
-TINIINC=${ASMINC}/tini.inc ${ASMINC}/tinimacro.inc ${ASMINC}/ds80c390.inc
+TINIINC=${ASMINC}/tini.inc ${ASMINC}/tinimacro.inc ${ASMINC}/ds80c390.inc ${ASMINC}/apiequ.inc
ASMOPT=-f 1.15 -p 390 -l
ASMMACRO=/opt/tini/native/bin/Linux/macro
ASM=/opt/tini/native/bin/Linux/a390
CMPFLAGS= ${FLAGS} ${INCLUDE}
LDFLAGS= ${LIBDIR} ${LIBS}
-all: AIC.jar libaic.a
+all: AIC.jar libaic.a aicio.mpp.lib
${PKGPATH}/PLD.class: PLD.java
javac ${JAVAFLAGS} ${CLASSPATH} -d . PLD.java
${ASMINC}/ds80c390.inc: ${NATINC}/ds80c390.inc
ln -s ${NATINC}/ds80c390.inc ${ASMINC}/ds80c390.inc
+
+${ASMINC}/apiequ.inc: ${NATINC}/apiequ.inc
+ ln -s ${NATINC}/apiequ.inc ${ASMINC}/apiequ.inc
brake.mpp: brake.a51 ${TINIINC} ${ASMINC}/aicpld.inc
- ${ASMMACRO} -I${ASMINC} brake.a51
+ ${ASMMACRO} -I${ASMINC} -e- brake.a51
-brake.tlib: brake.mpp
- ${ASM} ${ASMOPT} brake.mpp
+brake.tlib: tlib/brake.mpp brake.mpp
+ cat tlib/brake.mpp brake.mpp > brake.tmp.mpp
+ echo end >> brake.tmp.mpp
+ ${ASM} ${ASMOPT} brake.tmp.mpp
+tlib/brake.mpp: tlib/brake.a51
+ $(MAKE) -C tlib brake.mpp
+
index.mpp: index.a51 ${TINIINC} ${ASMINC}/aicpld.inc
- ${ASMMACRO} -I${ASMINC} index.a51
+ ${ASMMACRO} -I${ASMINC} -e- index.a51
-index.tlib: index.mpp
- ${ASM} ${ASMOPT} index.mpp
-
-t.tlib: t.mpp
- ${ASM} ${ASMOPT} t.mpp
+index.tlib: tlib/index.mpp index.mpp
+ cat tlib/index.mpp index.mpp > index.tmp.mpp
+ echo end >> index.tmp.mpp
+ ${ASM} ${ASMOPT} index.tmp.mpp
+tlib/index.mpp: tlib/index.a51
+ $(MAKE) -C tlib index.mpp
+
encoder.mpp: encoder.a51 ${TINIINC} ${ASMINC}/aicpld.inc
${ASMMACRO} -I${ASMINC} encoder.a51
libaic.a: aic.o aicudp.o aiccan.o aicsim.o aichost.o aichostudp.o aichostcan.o
ar -crvs libaic.a aic.o aicudp.o aiccan.o aicsim.o aichost.o aichostudp.o aichostcan.o
+aicio.mpp.lib: brake.mpp index.mpp
+ cat brake.mpp index.mpp > aicio.mpp.lib
+
install:
install -m 0644 libaic.a ${LIBINST}
install -m 0644 AIC.jar ${LIBINST}
install -m 0755 -d ${INCLUDEINST}/cpp
install -m 0644 ../include/*.h ${INCLUDEINST}/cpp
+ $(MAKE) -C tlib install
clean:
rm -rf *.o *~ *.bak *.class ../include/{*.bak,*~} br *.tlib *.mpp ${TINIINC} *.lst
+ $(MAKE) -C tlib clean
distclean: clean
rm -rf AIC.jar *.a
+ $(MAKE) -C tlib distclean
uninstall:
rm ${LIBINST}/libaic.a
rm ${LIBINST}/AIC.jar
rm ${INCLUDEINST}/cpp/aic.h
rm ${INCLUDEINST}/cpp/aicnet.h
+ $(MAKE) -C tlib uninstall
;******************************************************************************
;
; Actuator Interface Card
-; Brake Native Methods
-; Copyright (C) 2004 Walter Fetter Lages <w.fetter@ieee.org>
+; Brake Functions
+; Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
;
; 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
$include(aicpld.inc)
$include(aicmacro.inc)
-; Native library initialization routine
-; This routine must exist
-; This routine must be at offset 0
-; If -f and -p options are used, a390 relocates this routine
-; to another offset
-; Label is meaningless and is not used by Java Sytem.LoadLibrary()
-lib_init:
- clr a ; success
- ret
-
; data saved in big-endian mode
; Brake base address
-base: db 0,0,0
+brake_base: db 0,0,0
; Initializes Brake
-; private static native void initialize(int base);
-native_initialize:
- clr a
- lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+; void brake_initialize(unsigned long base);
+brake_initialize:
+ mov r0,dpl ; parameter in b:dpx:dph:dpl
+ mov r1,dph ; BUG IN SDCC MANUAL!
+ mov r2,dpx
+ mov r3,b
mov dptr,#CONTROL ; compute brake address
lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0
- STORE24 #base ; store brake address
+ STORE24 #brake_base ; store brake address
clr a ; success
ret
; Applies the electromagnetic brakes
-; public static native void apply()
-native_apply:
- LOAD24 #base ; get brake address
+; void brake_apply(void)
+brake_apply:
+ LOAD24 #brake_base ; get brake address
SET_STRETCH STRETCH
ret
; Releases the electromagnetic brake
-; public static native void release()
-native_release:
- LOAD24 #base ; get brake address
+; void brake_release(void)
+brake_release:
+ LOAD24 #brake_base ; get brake address
SET_STRETCH STRETCH
;******************************************************************************
;
; Actuator Interface Card
-; Index Native Methods
-; Copyright (C) 2004 Walter Fetter Lages <w.fetter@ieee.org>
+; Index Function
+; Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
;
; 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
$include(aicpld.inc)
$include(aicmacro.inc)
-; Native library initialization routine
-; This routine must exist
-; This routine must be at offset 0
-; If -f and -p options are used, a390 relocates this routine
-; to another offset
-; Label is meaningless and is not used by Java Sytem.LoadLibrary()
-lib_init:
- clr a ; success
- ret
-
; data saved in big-endian mode
; Index base address
-base: db 0,0,0
+index_base: db 0,0,0
; Initializes Index
-; private static final native void initialize(int base);
-native_initialize:
- clr a
- lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+; void index_initialize(unsigned long base);
+index_initialize:
+ mov r0,dpl ; parameter in b:dpx:dph:dpl
+ mov r1,dph ; BUG IN SDCC MANUAL!
+ mov r2,dpx
+ mov r3,b
mov dptr,#CONTROL ; compute index address
lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0
- STORE24 #base ; store index address
+ STORE24 #index_base ; store index address
clr a ; success
ret
; Reads the sync-switch
; returns the sync-switch state
-; public static native boolean read()
-native_read:
- LOAD24 #base ; get index address
+; unsigned long index_read(void)
+index_read:
+ LOAD24 #index_base ; get index address
SET_STRETCH STRETCH
RESTORE_STRETCH r0
anl a,#01h
- mov r0,a ; return value in R3:R2:R1:R0
- clr a ; sucess
- mov r1,a
- mov r2,a
- mov r3,a
+ mov dpl,a ; return value in b:dpx:dph:dpl
+ clr a ; BUG IN SDCC MANUAL!
+ mov dph,a
+ mov dpx,a
+ mov b,a
ret
;******************************************************************************
;
; Actuator Interface Card
-; PWM Native Methods
-; Copyright (C) 2004 Walter Fetter Lages <w.fetter@ieee.org>
+; PWM Functions
+; Copyright (C) 2004, 2005 Walter Fetter Lages <w.fetter@ieee.org>
;
; 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
$include(aicpld.inc)
$include(aicmacro.inc)
-; Native library initialization routine
-; This routine must exist
-; This routine must be at offset 0
-; If -f and -p options are used, a390 relocates this routine
-; to another offset
-; Label is meaningless and is not used by Java Sytem.LoadLibrary()
-lib_init:
- clr a ; success
- ret
; data saved in big-endian mode
; PWM base address
-pwmbase: db 0,0,0
+pwm_base: db 0,0,0
; PWM frequency in cycles of 10MHz
-max_count: db 0,0
+pwm_max_count: db 0,0
; minimal value to load in PWM
-min_count: db 0,0
+pwm_min_count: db 0,0
; Control Register base address
-ctrlbase: db 0,0,0
+pwm_ctrl_base: db 0,0,0
; Sets the frequency of PWM in cycles of 10MHz
-; public static native void setCount(int count)
-native_setCount:
- clr a
- lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+; void pwm_set_count(unsigned int count)
+pwm_set_count:
+ mov r0,dpl ; parameter in dph:dpl
+ mov r1,dph ; BUG IN SDCC MANUAL!
-set_count: LOAD24 #pwmbase ; get PWM address
+ LOAD24 #pwm_base ; get PWM address
mov a,#CTRL_8254 ; compute control register address
ADD_DPTR_0_A
SET_STRETCH STRETCH
ENTER_PCE_SPACE_AND_PUSH_STATE #0
- mov a,#RATE_BIN_8254 ; set timer 0 mode
+ mov a,#RATE_BIN_8254 ; set timer 0 mode
movx @dptr,a
mov a,#ONE_SHOT_BIN_8254 ; set timer 1 mode
EXIT_PCE_SPACE_AND_POP_STATE
inc DPS ; save count
- mov dptr,#max_count
+ mov dptr,#pwm_max_count
movx @dptr,a ; store count msB
inc dptr
mov a,r2 ; store count lsB
ret
; Initializes PWM
-; private static native void initialize(int base,int min_count,int count);
-native_initialize:
+; 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
mov dptr,#CONTROL ; compute Control address
lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0
- STORE24 #ctrlbase ; store Control register address
+ STORE24 #pwm_ctrl_base ; store Control register address
pop R2_B0
pop R1_B0
mov dptr,#PWM ; compute PWM address
lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0
- STORE24 #pwmbase ; store PWM address
+ STORE24 #pwm_base ; store PWM address
mov a,#1h
lcall Natlib_LoadPrimitive ; get second parameter in R3:R2:R1:R0
- mov dptr,#min_count ; stores it
+ mov dptr,#pwm_min_count ; stores it
mov a,r1
movx @dptr,a
inc dptr
mov a,#2h
lcall Natlib_LoadPrimitive ; get third parameter in R3:R2:R1:R0
- ljmp set_count ; fall over to native_setCount
+ ljmp pwm_set_count ; fall over to native_setCount
; Finalizes PWM
-; public native void finalize()
-native_finalize:
- LOAD24 #pwmbase ; get pwm address
+; void finalize(void)
+pwm_finalize:
+ LOAD24 #pwm_base ; get pwm address
inc DPS ; get count msB
- mov dptr,#max_count
+ mov dptr,#pwm_max_count
movx a,@dptr
mov r1,a
inc dptr ; get count lsB
SET_STRETCH STRETCH
- ljmp duty50 ; fall over to native setCounter
+ ljmp duty50 ; fall over to native pwm_set_count
; Sets the duty-cycle of PWM
-; public static native int setDuty(int dutycycle)
-native_setDuty:
- clr a
- lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+; unsigned long pwm_set_duty(unsigned long dutycycle)
+pwm_set_duty:
+ mov r0,dpl ; parameter in b:dpx:dph:dpl
+ mov r1,dph ; BUG IN SDCC MANUAL!
+ mov r2,dpx
+ mov r3,b
mov a,r3 ; ensures R3:R2:R1:R0 >= 0
jnb ACC.7,parmpos
mov MCNT1,#00h ; R1:R0 * max_count using
mov MB,r0 ; math accelarator
mov MB,r1
- mov dptr,#max_count ; load max_count in R1_B1:R0:B1
+ mov dptr,#pwm_max_count ; load max_count in R1_B1:R0:B1
movx a,@dptr
mov R1_B1,a
inc dptr
subb a,r1
mov r1,a
- mov dptr,#min_count ; check if count < min_count
+ mov dptr,#pwm_min_count ; check if count < min_count
movx a,@dptr
mov r3,a
inc dptr
mov r0,R2_B0
mov r1,R3_B0
-countok: LOAD24 #pwmbase ; get PWM address
+countok: LOAD24 #pwm_base ; get PWM address
mov a,#TIMER1_8254 ; compute timer 1 address
ADD_DPTR_0_A
RESTORE_STRETCH r0 ; restore original stretch value
- mov r0,b ; return count in R3:R2:R1:R0
-
- clr a ; success
+ mov dpl,b ; return count in b:dbx:dph:dpl
+ mov dph,r1
+
+ clr a
- mov r2,a
- mov r3,a
+ mov dpx,a
+ mov b,a
ret
; Turns the PWM on
-; public static native void on()
-
-native_on:
- LOAD24 #ctrlbase ; get control register address
+; void pwm_on(void)
+pwm_on:
+ LOAD24 #pwm_ctrl_base ; get control register address
SET_STRETCH STRETCH
ret
; Turns the PWM off
-; public static native void off()
-native_off:
- LOAD24 #ctrlbase ; get control register address
+; void pwm_off(void)
+pwm_off:
+ LOAD24 #pwm_ctrl_base ; get control register address
SET_STRETCH STRETCH
--- /dev/null
+CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar:/opt/tini/bin/modules.jar:.
+APIDBPATH=-d /opt/tini/bin/tini.db
+PKGPATH=br/ufrgs/eletro/AIC
+JAVAFLAGS=-O -target 1.1 -source 1.3
+
+NATINC=/opt/tini/native/lib
+ASMINC=../../include
+TINIINC=${ASMINC}/tini.inc ${ASMINC}/tinimacro.inc ${ASMINC}/ds80c390.inc
+ASMOPT=-f 1.15 -p 390 -l
+ASMMACRO=/opt/tini/native/bin/Linux/macro
+ASM=/opt/tini/native/bin/Linux/a390
+
+CFLAGS = -O2 -Wall -march=i486
+INCLUDE = -I. -I${HOME}/include
+
+CPPFLAGS =
+CPPINCLUDE = -I${HOME}/include/cpp -I/usr/local/include/cpp -I../../include
+LIB = ${HOME}/lib
+
+LIBINST=/usr/local/lib
+INCLUDEINST=/usr/local/include
+
+INCLUDE=${CINCLUDE} ${CPPINCLUDE}
+FLAGS= ${CFLAGS} ${CPPFLAGS} -DDEBUG
+LIBDIR=${CLIBDIR} ${CPPLIBDIR}
+LIBS=${CLIBS} ${CPPLIBS}
+
+CMP= g++
+CMPFLAGS= ${FLAGS} ${INCLUDE}
+LDFLAGS= ${LIBDIR} ${LIBS}
+
+all: brake.mpp index.mpp encoder.mpp pwm.mpp
+
+
+${ASMINC}/tini.inc: ${NATINC}/tini.inc
+ ln -s ${NATINC}/tini.inc ${ASMINC}/tini.inc
+
+${ASMINC}/tinimacro.inc: ${NATINC}/tinimacro.inc
+ ln -s ${NATINC}/tinimacro.inc ${ASMINC}/tinimacro.inc
+
+${ASMINC}/ds80c390.inc: ${NATINC}/ds80c390.inc
+ ln -s ${NATINC}/ds80c390.inc ${ASMINC}/ds80c390.inc
+
+brake.mpp: brake.a51 ${TINIINC}
+ ${ASMMACRO} -I${ASMINC} -e- brake.a51
+
+index.mpp: index.a51 ${TINIINC}
+ ${ASMMACRO} -I${ASMINC} -e- index.a51
+
+encoder.mpp: encoder.a51 ${TINIINC}
+ ${ASMMACRO} -I${ASMINC} encoder.a51
+
+pwm.mpp: pwm.a51 ${TINIINC}
+ ${ASMMACRO} -I${ASMINC} pwm.a51
+
+install:
+
+clean:
+ rm -rf *.o *~ *.bak *.class ../include/{*.bak,*~} br *.tlib *.mpp ${TINIINC} *.lst
+
+distclean: clean
+ rm -rf AIC.jar *.a
+
+uninstall:
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; Brake Native Methods
+; Copyright (C) 2004, 2005 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************
+
+$include(tini.inc)
+$include(ds80c390.inc)
+$include(tinimacro.inc)
+
+$include(aicpld.inc)
+$include(aicmacro.inc)
+
+; Native library initialization routine
+; This routine must exist
+; This routine must be at offset 0
+; If -f and -p options are used, a390 relocates this routine
+; to another offset
+; Label is meaningless and is not used by Java Sytem.LoadLibrary()
+lib_init:
+ clr a ; success
+ ret
+
+; Initializes Brake
+; private static native void initialize(int base);
+native_initialize:
+ clr a
+ lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+
+ mov b,r3 ; SDCC parameters in b:dpx:dph:dpl
+ mov dpx,r2 ; BUG IN SDCC MANUAL!
+ mov dph,r1
+ mov dpl,r0
+
+ lcall brake_initialize
+
+ clr a ; success
+ ret
+
+; Applies the electromagnetic brakes
+; public static native void apply()
+native_apply:
+
+ lcall brake_apply
+
+ clr a ; success
+ ret
+
+; Releases the electromagnetic brake
+; public static native void release()
+native_release:
+
+ lcall brake_release
+
+ clr a ; success
+ ret
+
+ end
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; Encoder Native Methods
+; Copyright (C) 2004 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************
+
+$include(tini.inc)
+$include(ds80c390.inc)
+$include(tinimacro.inc)
+
+$include(aicpld.inc)
+$include(aicmacro.inc)
+
+; Native library initialization routine
+; This routine must exist
+; This routine must be at offset 0
+; If -f and -p options are used, a390 relocates this routine
+; to another offset
+; Label is meaningless and is not used by Java Sytem.LoadLibrary()
+lib_init:
+ clr a ; success
+ ret
+
+; data saved in big-endian mode
+; Encoder base address
+base: db 0,0,0
+
+; Initializes Encoder
+; private static native void initialize(int base);
+native_initialize:
+ clr a
+
+ lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+
+ mov dptr,#ENCODER ; compute encoder address
+ lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0
+
+ STORE24 #base ; store encoder address
+
+ SET_STRETCH STRETCH
+
+ ENTER_PCE_SPACE_AND_PUSH_STATE #0
+ clr a ; clear encoder
+ movx @dptr,a
+ EXIT_PCE_SPACE_AND_POP_STATE
+
+ RESTORE_STRETCH r0
+
+ clr a ; sucess
+ ret
+
+; Finalizes Encoder
+; public native void finalize()
+native_finalize:
+
+ ; fall-through to native_clear:
+
+; Clears the counter on the quadrature decoder chip
+; public void clear()
+native_clear:
+ LOAD24 #base ; get encoder address
+
+ SET_STRETCH STRETCH
+
+ ENTER_PCE_SPACE_AND_PUSH_STATE #0
+ clr a
+ movx @dptr,a ; clear counter
+ EXIT_PCE_SPACE_AND_POP_STATE
+
+ RESTORE_STRETCH r0
+
+ clr a ; success
+ ret
+
+; Gets the count on the quadrature decoder chip
+; return the number of pulses (in 2-complement) since the last time
+; the counter was cleared
+; public static native int getCount()
+native_getCount:
+ LOAD24 #base ; get encoder address
+
+ SET_STRETCH STRETCH
+
+ ENTER_PCE_SPACE_AND_PUSH_STATE #0
+ movx a,@dptr ; get count high byte
+ mov r1,a ; return value in R3:R2:R1:R0
+
+ rlc a ; sign extension to 32 bits
+ clr a ; r1 > 0 extend with 0s
+ jnc posextend
+ cpl a ; r1 < 0 extend with 1s
+posextend: mov r2,a ; return value in R3:R2:R1:R0
+ mov r3,a
+
+ inc dptr
+ movx a,@dptr ; get count low byte
+ EXIT_PCE_SPACE_AND_POP_STATE
+
+ RESTORE_STRETCH r0
+
+ mov r0,a ; return value in R3:R2:R1:R0
+
+ clr a ; success
+ ret
+
+
+; Gets the count and clearsthe counter on the quadrature decoder chip
+; return the number of pulses (in 2-complement) since the last time
+; the counter was cleared
+; public static native int getCountAndClear()
+native_getCountAndClear:
+ LOAD24 #base ; get encoder address
+
+ SET_STRETCH STRETCH
+
+ ENTER_PCE_SPACE_AND_PUSH_STATE #0
+ movx a,@dptr ; get count high byte
+ mov r1,a ; return value in R3:R2:R1:R0
+
+ rlc a ; sign extension to 32 bits
+ clr a ; r1 > 0 extend with 0s
+ jnc posextend1
+ cpl a ; r1 < 0 extend with 1s
+posextend1: mov r2,a ; return value in R3:R2:R1:R0
+ mov r3,a
+
+ inc dptr
+ movx a,@dptr ; get count low byte
+ movx @dptr,a ; clear counter
+ EXIT_PCE_SPACE_AND_POP_STATE
+
+ RESTORE_STRETCH r0
+
+ mov r0,a ; return value in R3:R2:R1:R0
+
+ clr a ; success
+ ret
+
+ end
+
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; Index Native Methods
+; Copyright (C) 2004, 2005 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************
+
+$include(tini.inc)
+$include(ds80c390.inc)
+$include(tinimacro.inc)
+
+$include(aicpld.inc)
+$include(aicmacro.inc)
+
+; Native library initialization routine
+; This routine must exist
+; This routine must be at offset 0
+; If -f and -p options are used, a390 relocates this routine
+; to another offset
+; Label is meaningless and is not used by Java Sytem.LoadLibrary()
+lib_init:
+ clr a ; success
+ ret
+
+
+; Initializes Index
+; private static final native void initialize(int base);
+native_initialize:
+ clr a
+ lcall Natlib_LoadPrimitive ; get parameter in R3:R2:R1:R0
+
+ mov b,r3 ; SDCC parameters in b:dpx:dph:dpl
+ mov dpx,r2 ; BUG IN SDCC MANUAL!
+ mov dph,r1
+ mov dpl,r0
+
+ lcall index_initialize
+
+ clr a ; success
+ ret
+
+; Reads the sync-switch
+; returns the sync-switch state
+; public static native boolean read()
+native_read:
+ lcall index_read ; SDCC returns value in b:dpx:dph:dpl
+
+ mov r0,dpl ; java native return value in R3:R2:R1:R0
+ mov r1,dph
+ mov r2,dpx
+ mov r3,b
+
+ clr a ; sucess
+ ret
+
+ end
+
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; PWM Native Methods
+; Copyright (C) 2004, 2005 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************
+
+$include(tini.inc)
+$include(ds80c390.inc)
+$include(tinimacro.inc)
+
+$include(i8254.inc)
+$include(aicpld.inc)
+$include(aicmacro.inc)
+
+; Native library initialization routine
+; This routine must exist
+; This routine must be at offset 0
+; If -f and -p options are used, a390 relocates this routine
+; to another offset
+; Label is meaningless and is not used by Java Sytem.LoadLibrary()
+lib_init:
+ clr a ; success
+ ret
+
+; Sets the frequency of PWM in cycles of 10MHz
+; public static native void setCount(int count)
+native_setCount:
+ clr a
+ 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 dpl,r0 ; BUG IN SDCC MANUAL!
+
+ lcall pwm_set_count
+
+ clr a ; success
+ ret
+
+; 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
+
+ push R0_B0
+ push R1_B0
+ push R2_B0
+
+ mov dptr,#CONTROL ; compute Control address
+ lcall Add_Dptr1_24 ; dptr=dptr+R2:R1:R0
+
+ STORE24 #ctrlbase ; store Control register address
+
+ pop R2_B0
+ pop R1_B0
+ pop R0_B0
+
+ mov dptr,#PWM ; compute PWM address
+ lcall Add_Dptr1_24 ; dptr=dptr+R2:R1: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
+
+ mov a,#2h
+ lcall Natlib_LoadPrimitive ; get third parameter in R3:R2:R1:R0
+
+ ljmp set_count ; fall over to native_setCount
+
+
+; Finalizes PWM
+; public native void finalize()
+native_finalize:
+ lcall pwm_finalize
+ ret
+
+; Sets the duty-cycle of PWM
+; public static native int setDuty(int dutycycle)
+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 dpx,r2 ; BUG IN SDCC MANUAL!
+ mov dph,r1
+ mov dpl,r0
+
+ lcall pwm_set_duty ; SDCC returns value in dph:dpl
+
+ mov r0,dpl ; java native return value in R3:R2:R1:R0
+ mov r1,dph
+ mov r2,dpx
+ mov r3,b
+
+ clr a ; sucess
+ ret
+
+
+; Turns the PWM on
+; public static native void on()
+
+native_on:
+ lcall pwm_on
+ ret
+
+; Turns the PWM off
+; public static native void off()
+native_off:
+ lcall pwm_off
+ ret
+
+ end
+
--- /dev/null
+CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar
+APIDBPATH=-d /opt/tini/bin/tini.db
+TINIRTAIPATH=${HOME}/src/tini/rtai
+LIBPATH=-PATH ${TINIRTAIPATH}/lib/rtai.jar
+JAVAFLAGS=-O -target 1.1 -source 1.3
+ASMINC=-I/opt/tini/native/lib
+ASMOPT=-f 1.14 -p 390 -l
+ASMMACRO=/opt/tini/native/bin/Linux/macro
+ASM=/opt/tini/native/bin/Linux/a390
+CC=sdcc
+CFLAGS=-mTININative -S --use-accelerator
+CINCLUDE=-I${TINIRTAIPATH}/include
+CMPFLAGS=${CFLAGS} ${CINCLUDE}
+
+all: PID.tini
+
+PID.class: PID.java
+ javac ${CLASSPATH} ${JAVAFLAGS} PID.java
+
+pid.mpp: pid.a51
+ ${ASMMACRO} ${ASMINC} -e- pid.a51
+
+globals.mpp: globals.a51
+ ${ASMMACRO} ${ASMINC} globals.a51
+
+pid.tlib: pid.mpp globals.mpp ${TINIRTAIPATH}/lib/globals.mpp
+ cat pid.mpp ${TINIRTAIPATH}/lib/globals.mpp globals.a51 > tmp.mpp
+ ${ASM} ${ASMOPT} tmp.mpp
+ mv tmp.tlib pid.tlib
+ mv tmp.lst pid.lst
+
+pid.a51: pid.c
+ ${CC} ${CMPFLAGS} pid.c
+
+PID.tini: PID.class pid.tlib
+ java ${CLASSPATH} TINIConvertor -n pid.tlib -f PID.class ${APIDBPATH} -o PID.tini
+
+
+clean:
+ rm -f *.bak *~ PID.class pid.tlib pid.mpp pid.lst pid.a51 globals.mpp tmp.mpp tmp.lst
+
+distclean: clean
+ rm -f PID.tini
+
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ PID
+ User Interface Module
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+import com.dalsemi.system.*;
+
+public class PID
+{
+ public static native int startRealtime(int period);
+ public static native void stopRealtime();
+ public static native void setReference(int reference);
+ public static native int getOutput();
+
+ public static void main(String[] args)
+ {
+ System.out.println("PID");
+ System.out.println("Copyright (C) Walter Fetter Lages, 2005.\n");
+
+ int tfms=0;
+ if(args.length==1)
+ {
+ tfms=Integer.parseInt(args[0]);
+ }
+ else
+ {
+ System.out.println("Usage:\tPID ms");
+ System.exit(1);
+ }
+
+ System.out.print("Loading native library...");
+ System.loadLibrary("pid.tlib");
+ System.out.println("done.");
+
+ int us=10000;
+ System.out.print("Starting real-time timer with "+us+" us period...");
+ int period=startRealtime(us);
+ System.out.println("done. Effective period: "+period+" us.");
+
+ System.out.print("Running PID for "+tfms+" ms...");
+ long t0=TINIOS.uptimeMillis();
+ long t=0;
+ while(t <= tfms)
+ {
+ t=TINIOS.uptimeMillis()-t0;
+ System.out.print("t="+t+" ms");
+ int ref=(int)t/2;
+ setReference(ref);
+ System.out.println("\treference="+ref+"\toutput="+getOutput());
+ }
+ System.out.println("...done.");
+
+ System.out.print("Stoping real-time timer...");
+ stopRealtime();
+ System.out.println("done.");
+ }
+}
--- /dev/null
+;******************************************************************************
+;
+; Actuator Interface Card
+; PID
+; Real Time Module Global Variables
+; Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+;
+; 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 Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+;
+; You can also obtain a copy of the GNU General Public License
+; at <http://www.gnu.org/licenses>.
+;
+;*******************************************************************************/
+
+
+output: db 0,0,0,0
+th: db 0,0
+reference: db 0,0,0,0
+ end
--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ PID
+ Real Time Module
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ 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 Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+#include <rtai_sched.h>
+
+#include <pthread.h>
+
+extern volatile long *output;
+extern volatile pthread_t th;
+extern volatile long *reference;
+
+/* By now this is not actually a thread as it should be,
+ but a function that is called at each timer interrupt */
+void *count(void *arg)
+{
+// volatile long *output=(volatile long *)arg;
+// for(;;)
+// {
+// rt_wait_period();
+ *output=*reference;
+// }
+}
+
+RTIME Native_startRealtime(void) _JavaNative
+{
+ volatile long period = NatLib_LoadInt(0);
+ RTIME count=micro2count(period);
+ start_rt_timer(count);
+ pthread_create(&th,NULL,count,output);
+ return count2micro(count);
+}
+
+void Native_stopRealtime(void) _JavaNative
+{
+ pthread_cancel(th);
+ stop_rt_timer();
+}
+
+
+long Native_getOutput(void) _JavaNative
+{
+ return output;
+}
+
+void Native_setReference(void) _JavaNative
+{
+ *reference = NatLib_LoadInt(0);
+}