blackbox/lowlevel.c

changeset 33
c261350bb394
parent 10
6d6e982bbc41
child 34
d12d095e3282
equal deleted inserted replaced
32:b83d239fe719 33:c261350bb394
48 DDRC = 0; PORTC = 0; 48 DDRC = 0; PORTC = 0;
49 DDRD = 0; PORTD = 0; 49 DDRD = 0; PORTD = 0;
50 50
51 51
52 RS232_init(); // initialize RS485 interface 52 RS232_init(); // initialize RS485 interface
53 RS232_puts_p(PSTR("CARRERA beta loading\n"));
54
55 initADC(); 53 initADC();
56 SFIOR = 0; 54 SFIOR = 0;
57 55
58 // set LED output 56 // set LED output
59 DDR(LED1_PORT) |= _BV(LED1); 57 DDR(LED1_PORT) |= _BV(LED1);
106 //TCCR1B = (1<<CS11) | (1<<CS10); //divide by 64 104 //TCCR1B = (1<<CS11) | (1<<CS10); //divide by 64
107 //TCNT1 = TIMER_7500NS; 105 //TCNT1 = TIMER_7500NS;
108 OCR1A = TIMER1_7500NS; 106 OCR1A = TIMER1_7500NS;
109 TIMSK |= 1<<OCIE1A; //enable timer1 interrupt 107 TIMSK |= 1<<OCIE1A; //enable timer1 interrupt
110 108
111 RS232_puts_p(PSTR("INIT OK\n")); 109 RS232_puts_p(PSTR("FreeSlot Blackbox v1.0\n"));
112 110
113 } 111 }
114 112
115 113
114 void blinkdelay(void) {
115 _delay_ms(100);
116 }
116 117
117 void check_rails_shortcut(void) { 118 void check_rails_shortcut(void) {
118 // check for short circuit on the rails 119 // check for short circuit on the rails
119 uint8_t i = 100; 120 uint8_t i = 100;
120 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) { 121 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
121 while (i>0) { 122 while (i>0) {
122 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) return 0; 123 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) return 0;
123 _delay_us(20); 124 _delay_us(20);
125 i--;
124 } 126 }
125 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) { 127 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
126 cli(); // disable ALL Interrupts 128 cli(); // disable ALL Interrupts
127 RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power 129 RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power
128 RS232_puts_p(PSTR("!!! SHORT CIRCUIT ON RAILS, POWERED OFF !!!\n")); 130 RS232_puts_p(PSTR("!!! SHORT CIRCUIT ON RAILS, POWERED OFF !!!\n"));
134 while (1) { 136 while (1) {
135 LED(1, 2); 137 LED(1, 2);
136 LED(2, 2); 138 LED(2, 2);
137 LED(4, 2); 139 LED(4, 2);
138 LED(5, 2); 140 LED(5, 2);
139 _delay_ms(100); 141 blinkdelay();
140 LED(3, 2); 142 LED(3, 2);
141 _delay_ms(100); 143 blinkdelay();
142 LED(3, 2); 144 LED(3, 2);
143 _delay_ms(100); 145 blinkdelay();
144 LED(3, 2); 146 LED(3, 2);
145 _delay_ms(100); 147 blinkdelay();
146 LED(3, 2); 148 LED(3, 2);
147 } 149 }
148 } 150 }
149 } 151 }
150 } 152 }

mercurial