From: Jan "Yenya" Kasprzak Date: Fri, 19 Jul 2013 16:16:20 +0000 (+0200) Subject: Error flags, error reporting X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=220d48069967aaae91c303f84b98f2bb36a51425;p=bike-lights.git Error flags, error reporting - all error flags are in the bit array err_flags, including braking and booting (this is unused yet, the idea is to report successful boot and pwmled init somehow). - error status is reported as num_pattern(err, 1) by the status LED - error status (if any) can be cleared by pressing the button 1 (which takes precedence over the panic mode) --- diff --git a/firmware/battery.c b/firmware/battery.c index 542d20e..4763f05 100644 --- a/firmware/battery.c +++ b/firmware/battery.c @@ -114,7 +114,9 @@ unsigned char battery_gauge() #if 0 if (battery_adcval && rv == 1) - battery_critical = 1; + err_flags.err_battery = 1; + else + err_flags.err_battery = 0; #endif #if 0 diff --git a/firmware/control.c b/firmware/control.c index c351ca8..a0d2451 100644 --- a/firmware/control.c +++ b/firmware/control.c @@ -75,21 +75,24 @@ pattern_t test_pattern[] = { }; #endif -volatile unsigned char braking; +volatile err_flags_t err_flags; static unsigned char dim_mode, towbar_mode; void init_control() { dim_mode = 0; towbar_mode = 0; - braking = 0; + err_flags.any_flag = 0; +#ifdef notyet + err_flags.booting = 1; +#endif pwmled_select_brightness(); } void brake_on() { - braking = 1; + err_flags.braking = 1; gpio_set(0, 1); led_set_pattern(N_STATUS_LED, status_led_pattern_select()); pwmleds_update_mode(); @@ -97,7 +100,7 @@ void brake_on() void brake_off() { - braking = 0; + err_flags.braking = 0; gpio_set(0, 0); led_set_pattern(N_STATUS_LED, status_led_pattern_select()); pwmleds_update_mode(); @@ -112,8 +115,21 @@ void toggle_dim_mode() void set_panic_mode() { - led_set_pattern(0, panic_pattern); - led_set_pattern(N_ILLUM_LED, panic_pattern); + // if error, clean it up + if (err_flags.booting) + err_flags.booting = 0; + else if (err_flags.err_pwmled2) + err_flags.err_pwmled2 = 0; + else if (err_flags.err_pwmled1) + err_flags.err_pwmled1 = 0; + else if (err_flags.err_pwmled0) + err_flags.err_pwmled0 = 0; + else if (err_flags.err_battery) + err_flags.err_battery = 0; + else { + led_set_pattern(0, panic_pattern); + led_set_pattern(N_ILLUM_LED, panic_pattern); + } } pattern_t *pwmled_pattern_select() @@ -121,7 +137,7 @@ pattern_t *pwmled_pattern_select() #ifdef TEST_PATTERN return tmp_pattern; #endif - if (battery_critical) + if (err_flags.err_battery) return slow_pattern; switch (ambient_zone) { @@ -136,7 +152,22 @@ pattern_t *pwmled_pattern_select() pattern_t *status_led_pattern_select() { - if (braking) + if (err_flags.booting) + return number_pattern(1, 1); + + if (err_flags.err_pwmled2) + return number_pattern(5, 1); + + if (err_flags.err_pwmled1) + return number_pattern(4, 1); + + if (err_flags.err_pwmled0) + return number_pattern(3, 1); + + if (err_flags.err_battery) + return number_pattern(2, 1); + + if (err_flags.braking) return on_pattern; if (buttons_setup_in_progress()) @@ -151,7 +182,7 @@ pattern_t *illumination_led_pattern_select() if (buttons_setup_in_progress()) return buttons_setup_status1_pattern_select(); - if (battery_critical) + if (err_flags.err_battery) return NULL; switch (ambient_zone) { @@ -183,7 +214,7 @@ void pwmled_select_brightness() { uint16_t brightness = PWMLED_BRIGHTNESS(0, 2, 1, 0, 2); // default - if (battery_critical) { + if (err_flags.err_battery) { brightness = PWMLED_BRIGHTNESS(0, 0, 0, 0, 0); } else if (ambient_zone == 0) { if (dim_mode) diff --git a/firmware/lights.h b/firmware/lights.h index 71051e9..3af09cd 100644 --- a/firmware/lights.h +++ b/firmware/lights.h @@ -124,14 +124,24 @@ pattern_t *buttons_setup_status0_pattern_select(); pattern_t *buttons_setup_status1_pattern_select(); /* battery.c */ -extern volatile unsigned char battery_critical; void battery_adc(); void init_battery(); unsigned char battery_gauge(); /* control.c */ extern pattern_t on_pattern[]; -extern volatile unsigned char braking; +typedef union { + unsigned char any_flag; + struct { + unsigned char booting : 1; + unsigned char braking : 1; + unsigned char err_battery : 1; + unsigned char err_pwmled0 : 1; + unsigned char err_pwmled1 : 1; + unsigned char err_pwmled2 : 1; + }; +} err_flags_t; +extern volatile err_flags_t err_flags; void init_control(); void brake_on(); diff --git a/firmware/pattern.c b/firmware/pattern.c index 83a932e..b4edcc4 100644 --- a/firmware/pattern.c +++ b/firmware/pattern.c @@ -110,7 +110,7 @@ void pwmleds_update_mode() mode1 = (mode >> 2) & 1; mode2 = (mode >> 3) & 3; - if (braking && !battery_critical) { + if (err_flags.braking && !err_flags.err_battery) { mode0 = 2; if (mode2 == 2) mode2 = 3; diff --git a/firmware/pwmled.c b/firmware/pwmled.c index 7c4324c..30b10f1 100644 --- a/firmware/pwmled.c +++ b/firmware/pwmled.c @@ -225,6 +225,12 @@ static inline void pwmled_err(unsigned char n) log_byte(n); log_word(jiffies); log_flush(); + + switch (n) { + case 0: err_flags.err_pwmled0 = 1; break; + case 1: err_flags.err_pwmled1 = 1; break; + case 2: err_flags.err_pwmled2 = 1; break; + } }