summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-04-03 14:48:00 +0200
committerneoraider <devnull@localhost>2007-04-03 14:48:00 +0200
commitdc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5 (patch)
tree758cc525af6b6fca0af22482ec51c70017dbb7fc
downloadrc2007-rescue-dc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5.tar
rc2007-rescue-dc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5.zip
Neues Rescue-Programm angefangen (2)
-rw-r--r--adc.c18
-rw-r--r--adc.h10
-rw-r--r--avr.c16
-rw-r--r--avr.h16
-rw-r--r--hardware.c6
-rw-r--r--hardware.h24
-rw-r--r--util.h9
7 files changed, 99 insertions, 0 deletions
diff --git a/adc.c b/adc.c
new file mode 100644
index 0000000..192d36c
--- /dev/null
+++ b/adc.c
@@ -0,0 +1,18 @@
+#include "adc.h"
+
+#include <avr/io.h>
+
+
+void initADC() {
+ ADMUX = (1<<REFS0);
+ ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
+}
+
+uint16_t getADCValue(int port) {
+ ADMUX = (1<<REFS0)|(1<<ADLAR)|(port&0x07);
+ ADCSRA |= (1<<ADSC);
+
+ while(!(ADCSRA & (1<<ADIF)));
+
+ return ADC;
+}
diff --git a/adc.h b/adc.h
new file mode 100644
index 0000000..6131590
--- /dev/null
+++ b/adc.h
@@ -0,0 +1,10 @@
+#ifndef _ROBOCUP_ADC_H_
+#define _ROBOCUP_ADC_H_
+
+#include <stdint.h>
+
+
+void initADC();
+uint16_t getADCValue(int port);
+
+#endif
diff --git a/avr.c b/avr.c
new file mode 100644
index 0000000..ac303d0
--- /dev/null
+++ b/avr.c
@@ -0,0 +1,16 @@
+#include "avr.h"
+#include "util.h"
+
+void setMotorSpeed(MOTOR *motor, int speed) {
+ if(speed > 0) {
+ *motor->port &= ~motor->revMask;
+ *motor->port |= motor->fwdMask;
+ }
+ else if(speed < 0) {
+ *motor->port &= ~motor->fwdMask;
+ *motor->port |= motor->revMask;
+ }
+ else *motor->port |= motor->fwdMask|motor->revMask;
+
+ *motor->pwmPort = CLAMP(0, ABS(speed), 255);
+}
diff --git a/avr.h b/avr.h
new file mode 100644
index 0000000..3727bdf
--- /dev/null
+++ b/avr.h
@@ -0,0 +1,16 @@
+#ifndef _ROBOCUP_AVR_H_
+#define _ROBOCUP_AVR_H_
+
+#include <stdint.h>
+
+
+typedef struct {
+ volatile uint8_t *port;
+ volatile uint8_t *pwmPort;
+ uint8_t fwdMask;
+ uint8_t revMask;
+} MOTOR;
+
+void setMotorSpeed(MOTOR *motor, int speed);
+
+#endif
diff --git a/hardware.c b/hardware.c
new file mode 100644
index 0000000..6bc329e
--- /dev/null
+++ b/hardware.c
@@ -0,0 +1,6 @@
+#include "hardware.h"
+
+
+void initHardware() {
+
+}
diff --git a/hardware.h b/hardware.h
new file mode 100644
index 0000000..9b2bcb7
--- /dev/null
+++ b/hardware.h
@@ -0,0 +1,24 @@
+#ifndef _ROBOCUP_HARDWARE_H_
+#define _ROBOCUP_HARDWARE_H_
+
+#include "avr.h"
+
+#include <avr/io.h>
+
+
+static const MOTOR MOTOR1 = {
+ &PORTD, &OCR1BL, 0x01, 0x02
+};
+
+static const MOTOR MOTOR2 = {
+ &PORTD, &OCR1AL, 0x04, 0x08
+};
+
+static const MOTOR MOTOR3 = {
+ &PORTB, &OCR0, 0x01, 0x02
+};
+
+
+void initHardware();
+
+#endif
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..1fea3ae
--- /dev/null
+++ b/util.h
@@ -0,0 +1,9 @@
+#ifndef _ROBOCUP_UTIL_H_
+#define _ROBOCUP_UTIL_H_
+
+#define MIN(a,b) ((a<b)?a:b)
+#define MAX(a,b) ((a>b)?a:b)
+#define CLAMP(min,x,max) ((x<min)?min:(x>max)?max:x)
+#define ABS(a) ((a<0)?-a:a)
+
+#endif