# HG changeset patch # User Malte Bayer # Date 1323351220 -3600 # Node ID da820f13849820befe7f9bc255b594690589755f # Parent 4f4326794ba4d335b3a7097cb289c2a19a1a39a5 switched sysclk to u32 diff -r 4f4326794ba4 -r da820f138498 blackbox/main.c --- a/blackbox/main.c Wed Dec 07 17:22:58 2011 +0100 +++ b/blackbox/main.c Thu Dec 08 14:33:40 2011 +0100 @@ -19,6 +19,11 @@ char countdownstart[] PROGMEM="!COUNTDOWN\n"; char racestart[] PROGMEM="!RACE START\n"; +typedef union { + uint32_t u32; + uint16_t word[2]; // high, low word + uint8_t byte[4]; // all four bytes +} u32; static unsigned char s[10]; static uint8_t countdown, countdown_loops; @@ -31,8 +36,7 @@ #define MAX_SLOTS 6 -volatile uint16_t sysclk_ms_low = 0; -volatile uint16_t sysclk_ms_high = 0; +volatile u32 sysclk; volatile uint8_t sysclk_packettimer = 0; volatile uint8_t speedlimit[MAX_SLOTS]; @@ -152,7 +156,7 @@ void jumpstart(uint8_t controller) { if (jumpstart_time[controller] == 0) { - jumpstart_time[controller] = sysclk_ms_low; + jumpstart_time[controller] = sysclk.word[1]; // low word RS232_putc('~'); RS232_putc('0'-controller); RS232_putc(','); @@ -271,8 +275,8 @@ car0_old = TIMER1_500NS; car1_old = TIMER1_500NS; - sysclk_ms_low++; // increment 500ns timer - if (sysclk_ms_low == 0) sysclk_ms_high++; // increment upper 16bits + sysclk.word[1]++; // increment 500ns timer low word + if (sysclk.word[1] == 0) sysclk.word[0]++; // increment upper 16bits } ISR ( TIMER2_COMP_vect ) { @@ -391,6 +395,8 @@ fuel[i] = 100; jumpstart_time[i] = 0; } + sysclk.word[1] = 0; + sysclk.word[0] = 0; } void countdown_progress(void) { @@ -408,8 +414,8 @@ case 2: LED(4, 1); break; case 1: LED(5, 1); break; case 0: { // RACE START! - sysclk_ms_low = 1; - sysclk_ms_high = 0; + sysclk.word[1] = 1; + sysclk.word[0] = 0; LEDS_OFF(); LED(3, 1); mode = 3; @@ -423,11 +429,11 @@ if (car0 != car0_state) { car0_state = car0; if (car0_state != 0) { - diff_high = sysclk_ms_high - lap_time_start_high[car0-1]; - diff_low = sysclk_ms_low - lap_time_start_low[car0-1]; // this could be a bug ;) + diff_high = sysclk.word[0] - lap_time_start_high[car0-1]; + diff_low = sysclk.word[1] - lap_time_start_low[car0-1]; // this could be a bug ;) if ( (diff_high > 0) || (diff_low>2000) ) { // minimum 1 second for 1 lap! - lap_time_start_low[car0-1] = sysclk_ms_low; - lap_time_start_high[car0-1] = sysclk_ms_high; + lap_time_start_low[car0-1] = sysclk.word[1]; + lap_time_start_high[car0-1] = sysclk.word[0]; lap_time_low[car0-1] = diff_low; lap_time_high[car0-1] = diff_high; RS232_putc('L'); @@ -447,11 +453,11 @@ if (car1 != car1_state) { car1_state = car1; if (car1_state != 0) { - diff_high = sysclk_ms_high - lap_time_start_high[car1-1]; - diff_low = sysclk_ms_low - lap_time_start_low[car1-1]; // this could be a bug ;) + diff_high = sysclk.word[0] - lap_time_start_high[car1-1]; + diff_low = sysclk.word[1] - lap_time_start_low[car1-1]; // this could be a bug ;) if ( (diff_high > 0) || (diff_low>2000) ) { // minimum 1 second for 1 lap! - lap_time_start_low[car1-1] = sysclk_ms_low; - lap_time_start_high[car1-1] = sysclk_ms_high; + lap_time_start_low[car1-1] = sysclk.word[1]; + lap_time_start_high[car1-1] = sysclk.word[0]; lap_time_low[car1-1] = diff_low; lap_time_high[car1-1] = diff_high; RS232_putc('L'); @@ -517,8 +523,8 @@ RS232_puts_p(prepare); } else if (mode == 1) { // Initiate race countdown - sysclk_ms_low = 1; - sysclk_ms_high = 0; + sysclk.word[1] = 1; + sysclk.word[0] = 0; countdown = 5; countdown_loops = COUNTDOWN_DELAY; mode = 2;