aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--boo-stanby-watcher/main.c89
1 files changed, 25 insertions, 64 deletions
diff --git a/boo-stanby-watcher/main.c b/boo-stanby-watcher/main.c
index 5c24c1b..519369b 100644
--- a/boo-stanby-watcher/main.c
+++ b/boo-stanby-watcher/main.c
@@ -5,8 +5,8 @@
* -----
* reset - MCU - Vcc2
* module reset (PB3) - MCU - (ADC1) Vcc1 mesurement
- * module set (PB4) - MCU - not used
- * GND - MCU - (PB0) Amp DC control
+ * module set (PB4) - MCU - not used (linked to GND)
+ * GND - MCU - not used (linked to GND)
* -----
*/
@@ -16,7 +16,6 @@ static const uint8_t ADC_DOWN_VALUE = 217;
/* times are in tenth of seconds since ISR is triggered every 0.1s~
* see init_timer */
static const uint8_t SLEPT1_TIMEOUT = 10; /* 1s */
-static const uint8_t SLEPT2_TIMEOUT = 35; /* 3.5s */
static const uint8_t CAPA_TIMEOUT = 10; /* 1s */
static void init_adc()
@@ -149,60 +148,48 @@ static void plug_unset()
PORTB &= ~(1 << PB4); /* deactivate plug modules set */
}
-static void amp_set()
-{
- PORTB |= (1 << PB0);
-}
-
-static void amp_plug_reset()
+static void plug_reset()
{
/* be sure set line is not active before doing a reset else both coil will
* be energized at the same time and thus the behaviour may be
* unpredictable. */
plug_unset();
- /* deactivate amp dc control and activate module reset */
- PORTB &= ~(1 << PB0);
+ /* activate module reset */
PORTB |= (1 << PB3);
}
-static void amp_plug_unreset()
+static void plug_unreset()
{
PORTB &= ~(1 << PB3);
}
static enum states {
- ST_1_AMP_PLUG_OFF,
+ ST_1_PLUG_OFF,
ST_2_PLUG_SET,
- ST_3_PLUG_ON,
- ST_4_IDLE, /* when plug and amp are on we are in idle state */
- ST_5_AMP_PLUG_RESET,
+ ST_3_IDLE, /* when plug is on we are in idle state */
+ ST_4_PLUG_RESET,
/* ST_OFF never reached normally :P it only appears in the diagram */
ST_MAX
-} current_state = ST_1_AMP_PLUG_OFF;
+} current_state = ST_1_PLUG_OFF;
enum events {
EV_1_CAPA_LOADED,
EV_2_SLEPT1,
- EV_3_SLEPT2,
- EV_4_UNLOADING, /* no more current, capa temp power unloading */
+ EV_3_UNLOADING, /* no more current, capa temp power unloading */
EV_MAX
};
static void s0_e0(void); /* do nothing */
static void s1_e1(void);
static void s2_e2(void);
-static void s2_e4(void);
-static void s3_e3(void);
-static void s3_e4(void);
-static void s4_e4(void);
-static void s5_e2(void);
+static void s2s3_e3(void);
+static void s4_e2(void);
static void (*const state_table [ST_MAX][EV_MAX])(void) = {
- {s1_e1, s0_e0, s0_e0, s0_e0},
- {s0_e0, s2_e2, s0_e0, s2_e4},
- {s0_e0, s0_e0, s3_e3, s3_e4},
- {s0_e0, s0_e0, s0_e0, s4_e4},
- {s0_e0, s5_e2, s0_e0, s0_e0},
+ {s1_e1, s0_e0, s0_e0},
+ {s0_e0, s2_e2, s2s3_e3},
+ {s0_e0, s0_e0, s2s3_e3},
+ {s0_e0, s4_e2, s0_e0},
};
static void process_event(enum events new_event)
@@ -212,7 +199,7 @@ static void process_event(enum events new_event)
static void s0_e0(void) {}
-static void s1_e1(void) /* amp&plug off: capa loaded */
+static void s1_e1(void) /* plug off: capa loaded */
{
plug_set();
reset_sleep_time();
@@ -222,41 +209,20 @@ static void s1_e1(void) /* amp&plug off: capa loaded */
static void s2_e2(void) /* plug set: slept1 */
{
plug_unset();
- reset_sleep_time();
- current_state = ST_3_PLUG_ON;
+ current_state = ST_3_IDLE;
}
-static void s2_e4(void) /* plug set: unloading */
+static void s2s3_e3(void) /* plug set or idle: unloading */
{
- amp_plug_reset();
+ plug_reset();
reset_sleep_time();
- current_state = ST_5_AMP_PLUG_RESET;
+ current_state = ST_4_PLUG_RESET;
}
-static void s3_e3(void) /* plug on: slept2 */
+static void s4_e2(void) /* plug reset: slept1 */
{
- amp_set();
- current_state = ST_4_IDLE;
-}
-
-static void s3_e4(void) /* plug on: unloading */
-{
- amp_plug_reset();
- reset_sleep_time();
- current_state = ST_5_AMP_PLUG_RESET;
-}
-
-static void s4_e4(void) /* idle: unloading */
-{
- amp_plug_reset();
- reset_sleep_time();
- current_state = ST_5_AMP_PLUG_RESET;
-}
-
-static void s5_e2(void) /* amp&plug reset: slept1 */
-{
- amp_plug_unreset();
- current_state = ST_1_AMP_PLUG_OFF;
+ plug_unreset();
+ current_state = ST_1_PLUG_OFF;
}
int main()
@@ -270,7 +236,6 @@ int main()
// digital output
DDRB |=
- (1 << PB0) | // Amp DC control
(1 << PB3) | // module reset
(1 << PB4); // module set
PORTB = 0; // outputs set to low and input not set to internal pull-up
@@ -293,13 +258,9 @@ int main()
process_event(EV_2_SLEPT1);
}
- if (get_sleep_time() >= SLEPT2_TIMEOUT) {
- process_event(EV_3_SLEPT2);
- }
-
if (adcval <= ADC_DOWN_VALUE) {
reset_capa_time();
- process_event(EV_4_UNLOADING);
+ process_event(EV_3_UNLOADING);
}
}