blackbox/main.c

changeset 2
6c59b4293fa9
parent 0
9b7de464f0ea
child 3
1a0ef40ef458
--- a/blackbox/main.c	Mon Nov 14 20:32:30 2011 +0100
+++ b/blackbox/main.c	Mon Nov 14 21:15:11 2011 +0100
@@ -7,42 +7,12 @@
 #include <avr/pgmspace.h>
 #include <util/delay.h>
 
-#include "main.h"
-
 #include "driver/rs232.h"
 #include "driver/adc.h"
 
+#include "main.h"
 #include "lowlevel.h"
 
-//#include "driver/manchester.h"
-
-/*
-// Hardware config
-#define LAP_COUNTER_PORT        PORTB
-#define LAP_COUNTER             PB2
-
-#define MODUL_PORT              PORTD
-#define MODUL_ST4               PD5
-#define MODUL_ST6               PD6
-
-#define I2C_PORT                PORTC
-#define I2C_SDA                 PC0
-#define I2C_SCL                 PC1
-
-
-#define SW_PACECAR_PORT         PORTC
-#define SW_START_PORT           PORTB
-#define SW_TANK_PORT            PORTB
-#define SW_PACECAR              PC6
-#define SW_TANK                 PB0
-#define SW_START                PB1
-
-#define SPEAKER_PORT            PORTD
-#define SPEAKER                 PD7
-
-*/
-
-
 void init_hardware(void) {
     RS232_init(); // initialize RS485 interface
     RS232_puts_p(PSTR("CARRERA beta loading\n"));
@@ -245,20 +215,12 @@
     return insert_queue(tmp, 9);
 }
 
-/*
-TODO: DIE TIMER1 ISR DARF DIE ADC NICHT ABFRAGEN, NICHTMAL PAKETE BAUEN, NUR TRIGGERN
-DIE PAKETE MÜSSEN IN DER MAIN UNIT GEBAUT WERDEN UND IN EINE QUEUE GESCHOBEN WERDEN
-EINES VORBAUEN IN Q+1, DIE TIMER2 ISR MUSS DANN Q = Q+1 und Q+1 = 0 SETZEN, ERST DANN DARF
-NEUES PAKET IN Q+1 EINGEFÜGT WERDEN
-*/
-
-
 ISR ( TIMER1_COMPA_vect ) {
     //OCR2 = 0xFF; // make sure that timer2 is synced to timer1, give enough cycles to prepare
     LED(4,2);
     // trigger packet transfer:
     transmit_len = transmit_len_next;
-    
+
     // here is some more time to do something else...
 }
 
@@ -280,81 +242,44 @@
     RAIL_POWER_PORT |= _BV(RAIL_POWER);
 
     while (1) {
-        //RS232_putc(PIN(RAIL_DETECT_PORT));
-
         // check for short circuit on the rails
-        if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
-            _delay_ms(1);
-            if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
-                cli(); // disable ALL Interrupts
-                RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power
-                RS232_puts_p(PSTR("!!! SHORT CIRCUIT ON RAILS, POWERED OFF !!!\n"));
-                while (1) {
-                    LED(1, 0);
-                    _delay_ms(100);
-                    LED(1, 1);
-                    _delay_ms(100);
-                }
-            }
-        }
-
-
-
+        check_rails_shortcut();
 
-    switch (packet_index) {
-        case 1:
-            if (do_program(7, 19, 0)) packet_index++; // reset
-            //do_program(7, 16, 3); // led an startampel
-            //do_program(0, 4, 0); //
-            break;
-        case 2:
-            if (do_pace_ghost()) packet_index++;
-            break;
-        case 3:
-            if (do_active()) packet_index++;
-            break;
-        case 4:
-            if (do_controller(0)) packet_index++;
-            break;
-        case 5:
-            if (do_controller(4)) packet_index++;
-            break;
-        case 6:
-            if (do_controller(1)) packet_index++;
-            break;
-        case 7:
-            if (do_controller(5)) packet_index++;
-            break;
-        case 8:
-            if (do_controller(2)) packet_index++;
-            break;
-        case 9:
-            if (do_active()) packet_index++;
-            break;
-        case 10:
-            if (do_controller(3)) packet_index = 1;
-            // last packet, so reset packet index
-            break;
-    }
-
-
-
-
-/*
-        do_controller(0);
-        itoa (transmit_len_queue, s, 10);
-        RS232_puts(s);
-        RS232_putc(' ');
-        itoa (transmit_buffer_queue, s, 2);
-        RS232_puts(s);
-        
-        RS232_putc('\n');
-*/
-/*
-        itoa (tmp, s, 2);
-        RS232_puts(s);
-        RS232_putc('\n');
-*/
+        switch (packet_index) {
+            case 1:
+                if (do_program(7, 19, 0)) packet_index++; // reset
+                //do_program(7, 16, 3); // led an startampel
+                //do_program(0, 4, 0); //
+                break;
+            case 2:
+                if (do_pace_ghost()) packet_index++;
+                break;
+            case 3:
+                if (do_active()) packet_index++;
+                break;
+            case 4:
+                if (do_controller(0)) packet_index++;
+                break;
+            case 5:
+                if (do_controller(4)) packet_index++;
+                break;
+            case 6:
+                if (do_controller(1)) packet_index++;
+                break;
+            case 7:
+                if (do_controller(5)) packet_index++;
+                break;
+            case 8:
+                if (do_controller(2)) packet_index++;
+                break;
+            case 9:
+                if (do_active()) packet_index++;
+                break;
+            case 10:
+                if (do_controller(3)) packet_index = 1;
+                // last packet, so reset packet index
+                break;
+        }
 
 
     } // main loop end

mercurial