summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2003/i/buzz/src/busp/GNUmakefile3
-rw-r--r--2003/i/buzz/src/busp/busp.cc25
-rw-r--r--2003/i/buzz/src/busp/busp.h13
-rw-r--r--2003/i/buzz/src/busp/busp_ir.cc39
-rw-r--r--2003/i/buzz/src/busp/busp_ir.h25
-rw-r--r--2003/i/buzz/src/busp/busp_servo.cc39
-rw-r--r--2003/i/buzz/src/busp/busp_servo.h23
-rw-r--r--2003/i/buzz/src/busp/test_busp.cc99
8 files changed, 257 insertions, 9 deletions
diff --git a/2003/i/buzz/src/busp/GNUmakefile b/2003/i/buzz/src/busp/GNUmakefile
index 28efc6f..e575f30 100644
--- a/2003/i/buzz/src/busp/GNUmakefile
+++ b/2003/i/buzz/src/busp/GNUmakefile
@@ -3,7 +3,8 @@ CXXFLAGS = -Wall -g
CPPFLAGS = -I$(SRCDIR)
TARGETS = test_busp
-test_busp_SOURCES = busp.cc test_busp.cc $(SRCDIR)/erreur/erreur.a
+test_busp_SOURCES = busp.cc busp_ir.cc busp_servo.cc test_busp.cc \
+ $(SRCDIR)/erreur/erreur.a
all: $(TARGETS)
diff --git a/2003/i/buzz/src/busp/busp.cc b/2003/i/buzz/src/busp/busp.cc
index 4c2b03e..0e90475 100644
--- a/2003/i/buzz/src/busp/busp.cc
+++ b/2003/i/buzz/src/busp/busp.cc
@@ -10,12 +10,18 @@
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
+#include <iostream> //Debug
#define BUSP_FILE "/dev/robotbusp"
+// Pointeur vers l'instance unique.
+Busp *Busp::m_instance = 0;
+
// Initialise le busp, open (), signal ().
Busp::Busp ()
{
+ // Sauvegarde le pointeur d'instance.
+ m_instance = this;
// Ouvre le périphérique.
m_fd = open (BUSP_FILE, O_RDONLY);
if (m_fd == -1)
@@ -44,27 +50,39 @@ Busp::~Busp ()
sigaction (SIGUSR1, &sa, 0);
// Ferme le périphérique.
close (m_fd);
+ // Efface le pointeur d'instance.
+ m_instance = 0;
}
// Active les interruptions.
void
Busp::sti (void)
{
- //ioctl (m_fd, PBUS_INTENABLE);
+ ioctl (m_fd, PBUS_INTENABLE);
}
// Désactive les interruptions.
void
Busp::cli (void)
{
- //ioctl (m_fd, PBUS_INTENABLE);
+ ioctl (m_fd, PBUS_INTDISABLE);
}
// Traite le signal envoyé par le kernel lors d'une interruption.
void
Busp::irq (int sig)
{
+ Busp &busp = Busp::getInstance ();
+ // Désactivation des interuptions automatique.
// Récupère le numéro d'intéruption.
+ struct pbus_io io;
+ ioctl (busp.m_fd, PBUS_INTREAD, &io);
+ cout << "irq " << (int) io.ints << endl;
+ // Sous-traite l'interruption.
+ if (io.ints & BuspIr::m_irqMask)
+ busp.m_ir.irq ();
+ // Active à nouveau.
+ busp.sti ();
}
// Ecrire sur le bus.
@@ -75,6 +93,7 @@ Busp::write (int addr, int data)
io.addr = addr;
io.data = data;
ioctl (m_fd, PBUS_WRITE, &io);
+ cout << "write " << addr << " " << data << endl;
}
// Lire sur le bus.
@@ -84,6 +103,6 @@ Busp::read (int addr)
struct pbus_io io;
io.addr = addr;
ioctl (m_fd, PBUS_READ, &io);
+ cout << "read " << addr << " = " << (int) io.data << endl;
return io.data;
}
-
diff --git a/2003/i/buzz/src/busp/busp.h b/2003/i/buzz/src/busp/busp.h
index b7aa328..763665e 100644
--- a/2003/i/buzz/src/busp/busp.h
+++ b/2003/i/buzz/src/busp/busp.h
@@ -3,12 +3,18 @@
// busp.h - Contrôle bas niveau du bus parallèle.
// buzz - Programme du robot Efrei Robotique I1-I2 2003
// Copyright (C) 2003 Nicolas Schodet
+#include "busp_ir.h"
+#include "busp_servo.h"
// Gère le busp coté hard.
class Busp
{
int m_fd;
+ BuspIr m_ir;
+ BuspServo m_servo;
+ static Busp *m_instance;
public:
+ volatile int irqs;
// Initialise le busp, open (), signal ().
Busp ();
// Destructeur.
@@ -23,6 +29,13 @@ class Busp
void write (int addr, int data);
// Lire sur le bus.
int read (int addr);
+ // Reset les périphériques.
+ void reset (void) { write (0, 0); }
+ // Retourne une référence sur l'instance unique.
+ static Busp &getInstance (void) { return *m_instance; }
+ // Retourne une référence sur un module.
+ BuspIr &getIr (void) { return m_ir; }
+ BuspServo &getServo (void) { return m_servo; }
};
diff --git a/2003/i/buzz/src/busp/busp_ir.cc b/2003/i/buzz/src/busp/busp_ir.cc
new file mode 100644
index 0000000..6953818
--- /dev/null
+++ b/2003/i/buzz/src/busp/busp_ir.cc
@@ -0,0 +1,39 @@
+// busp_ir.cc
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+//
+#include "busp_ir.h"
+#include "busp.h"
+
+#include <iostream>
+
+// Constructeur.
+BuspIr::BuspIr ()
+{
+ // Allume la colonne.
+ // TODO
+}
+
+// Destructeur.
+BuspIr::~BuspIr ()
+{
+}
+
+// Traite une interruption.
+void
+BuspIr::irq (void)
+{
+ int pos = Busp::getInstance ().read (m_address);
+ int val = Busp::getInstance ().read (m_address);
+ m_irmap[pos] = val;
+}
+
+// Sort la carte Infra-rouge.
+void
+BuspIr::dump (void)
+{
+ for (int i = 0; i < 256; ++i)
+ {
+ cout << i << " " << m_irmap[i] << endl;
+ }
+}
diff --git a/2003/i/buzz/src/busp/busp_ir.h b/2003/i/buzz/src/busp/busp_ir.h
new file mode 100644
index 0000000..1269215
--- /dev/null
+++ b/2003/i/buzz/src/busp/busp_ir.h
@@ -0,0 +1,25 @@
+#ifndef busp_ir_h
+#define busp_ir_h
+// busp_ir.h
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+
+class BuspIr
+{
+ public:
+ static const unsigned char m_irqMask = 0x10;
+ private:
+ static const int m_address = 3;
+ unsigned char m_irmap[256];
+ public:
+ // Constructeur.
+ BuspIr ();
+ // Destructeur.
+ ~BuspIr ();
+ // Traite une interruption.
+ void irq (void);
+ // Sort la carte Infra-rouge.
+ void dump (void);
+};
+
+#endif // busp_ir_h
diff --git a/2003/i/buzz/src/busp/busp_servo.cc b/2003/i/buzz/src/busp/busp_servo.cc
new file mode 100644
index 0000000..1cef0c4
--- /dev/null
+++ b/2003/i/buzz/src/busp/busp_servo.cc
@@ -0,0 +1,39 @@
+// busp_servo.cc
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+//
+#include "busp_servo.h"
+#include "busp.h"
+
+// Constructeur.
+BuspServo::BuspServo ()
+{
+ for (int i = 0; i < 8; ++i)
+ m_pos[i] = 127;
+}
+
+// Bouge le servo N en POS.
+void
+BuspServo::moveTo (int n, int pos)
+{
+ set (n, pos);
+}
+
+// Bouge le servo N de DIFF.
+void
+BuspServo::move (int n, int diff)
+{
+ set (n, m_pos[n & 0x07] + diff);
+}
+
+// Fait le déplacement effectif.
+void
+BuspServo::set (int n, int pos)
+{
+ if (pos > 255) pos = 255;
+ else if (pos < 0) pos = 0;
+ n &= 0x07;
+ m_pos[n] = pos;
+ Busp::getInstance ().write (m_address, n);
+ Busp::getInstance ().write (m_address, pos);
+}
diff --git a/2003/i/buzz/src/busp/busp_servo.h b/2003/i/buzz/src/busp/busp_servo.h
new file mode 100644
index 0000000..764293b
--- /dev/null
+++ b/2003/i/buzz/src/busp/busp_servo.h
@@ -0,0 +1,23 @@
+#ifndef busp_servo_h
+#define busp_servo_h
+// busp_servo.h
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+
+class BuspServo
+{
+ static const int m_address = 2;
+ int m_pos[8];
+ public:
+ // Constructeur.
+ BuspServo ();
+ // Bouge le servo N en POS.
+ void moveTo (int n, int pos);
+ // Bouge le servo N de DIFF.
+ void move (int n, int diff);
+ private:
+ // Fait le déplacement effectif.
+ void set (int n, int pos);
+};
+
+#endif // busp_servo_h
diff --git a/2003/i/buzz/src/busp/test_busp.cc b/2003/i/buzz/src/busp/test_busp.cc
index 81bc21a..a63417b 100644
--- a/2003/i/buzz/src/busp/test_busp.cc
+++ b/2003/i/buzz/src/busp/test_busp.cc
@@ -7,6 +7,11 @@
#include <iostream>
#include <cstdlib>
+#include <cstring>
+#include <unistd.h>
+
+// Mode de controle des servos.
+void testServos (void);
int
main (int argc, char **argv)
@@ -21,17 +26,39 @@ main (int argc, char **argv)
// Ecriture.
addr = strtol (argv[1], 0, 0);
data = strtol (argv[2], 0, 0);
- cout << "write " << addr << " " << data << endl;
busp.write (addr, data);
break;
case 2:
- // Lecture.
- addr = strtol (argv[1], 0, 0);
- cout << "read " << addr << " = " << busp.read (addr) << endl;
+ if (strcmp (argv[1], "irq") == 0)
+ {
+ // Attend des interuptions.
+ cout << "irq" << endl;
+ char c;
+ cin >> c;
+ }
+ else if (strcmp (argv[1], "servo") == 0)
+ {
+ // Passe en mode contrôle servos.
+ testServos ();
+ }
+ else if (strcmp (argv[1], "reset") == 0)
+ {
+ // Ne fait rien, juste reset.
+ busp.reset ();
+ cout << "reset" << endl;
+ }
+ else
+ {
+ // Lecture.
+ addr = strtol (argv[1], 0, 0);
+ }
break;
default:
cerr << argv[0] << ": teste le bus parallèle." << endl
- << "\t" << argv[0] << " adresse [donnée]" << endl;
+ << "\t" << argv[0] << " <adresse> [<donnée>]" << endl
+ << "\t" << argv[0] << " reset" << endl
+ << "\t" << argv[0] << " irq" << endl
+ << "\t" << argv[0] << " servo" << endl;
return 1;
}
}
@@ -42,3 +69,65 @@ main (int argc, char **argv)
}
return 0;
}
+
+// Mode de controle des servos.
+void
+testServos (void)
+{
+ char c;
+ int diff, servo = 0;
+ cout << "Mode servos\n"
+ "0-9 : choix du servo.\n"
+ "y : -1, h : +1, u : -1, j : +1, i : -20, k : +20\n"
+ "r : reset, g<pos> : goto <pos>\n";
+ while (!cin.eof ())
+ {
+ cin >> c;
+ diff = 0;
+ switch (c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ servo = c - '0';
+ break;
+ case 'y':
+ diff = -1;
+ break;
+ case 'h':
+ diff = 1;
+ break;
+ case 'u':
+ diff = -5;
+ break;
+ case 'j':
+ diff = 5;
+ break;
+ case 'i':
+ diff = -20;
+ break;
+ case 'k':
+ diff = 20;
+ break;
+ }
+ if (diff)
+ {
+ Busp::getInstance ().getServo ().move (servo, diff);
+ }
+ else if (c == 'g')
+ {
+ int pos;
+ cin >> pos;
+ Busp::getInstance ().getServo ().moveTo (servo, pos);
+ }
+ else if (c == 'r')
+ {
+ Busp::getInstance ().reset ();
+ }
+ }
+}