# HG changeset patch # User Malte Bayer # Date 1321301711 -3600 # Node ID 6c59b4293fa9bc9a11716ee685423e75719cb46a # Parent 91246416e201283ca28229d90bedd33439ecd7b3 finished: rails short circuit check diff -r 91246416e201 -r 6c59b4293fa9 blackbox/lowlevel.c --- a/blackbox/lowlevel.c Mon Nov 14 20:32:30 2011 +0100 +++ b/blackbox/lowlevel.c Mon Nov 14 21:15:11 2011 +0100 @@ -1,5 +1,9 @@ +#include +#include +#include #include "stdint.h" #include "main.h" +#include "driver/rs232.h" void LED(uint8_t num, uint8_t state) { switch (num) { @@ -34,3 +38,34 @@ } break; } } + +void check_rails_shortcut(void) { + // 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")); + LED(1, 1); + LED(2, 1); + LED(3, 0); + LED(4, 0); + LED(5, 0); + while (1) { + LED(1, 2); + LED(2, 2); + LED(4, 2); + LED(5, 2); + _delay_ms(100); + LED(3, 2); + _delay_ms(100); + LED(3, 2); + _delay_ms(100); + LED(3, 2); + _delay_ms(100); + LED(3, 2); + } + } + } +} \ No newline at end of file diff -r 91246416e201 -r 6c59b4293fa9 blackbox/lowlevel.h --- a/blackbox/lowlevel.h Mon Nov 14 20:32:30 2011 +0100 +++ b/blackbox/lowlevel.h Mon Nov 14 21:15:11 2011 +0100 @@ -3,6 +3,7 @@ #include "main.h" void LED(uint8_t num, uint8_t state); +void check_rails_shortcut(void); #endif diff -r 91246416e201 -r 6c59b4293fa9 blackbox/main.c --- 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 #include -#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