demo-epb  v1.0
Elektrische Parkbremse - slohmaier Dev Process Demo
switch_debouncer.c
gehe zur Dokumentation dieser Datei
1 /**
2  * @file switch_debouncer.c
3  * @brief Implementierung des EPB-Schalter-Debouncers.
4  *
5  * @arch SWA-006
6  * @reqs SWE-025
7  *
8  * ASIL: QM.
9  */
10 #include "switch_debouncer.h"
11 
12 typedef struct {
15  uint8_t candidate_count;
16 } DebouncerCtx;
17 
19 
21 {
22  if (raw.apply_raw && !raw.release_raw) {
23  return SWITCH_APPLY;
24  }
25  if (raw.release_raw && !raw.apply_raw) {
26  return SWITCH_RELEASE;
27  }
28  return SWITCH_NEUTRAL;
29 }
30 
32 {
36  return EPB_OK;
37 }
38 
40 {
41  const SwitchState observed = raw_to_candidate(raw);
42 
43  if (observed == s_ctx.candidate) {
46  }
47  } else {
48  s_ctx.candidate = observed;
50  }
51 
54  }
55 }
56 
58 {
59  return s_ctx.current;
60 }
EpbStatus
Definition: epb_types.h:13
@ EPB_OK
Definition: epb_types.h:14
SwitchState
Definition: epb_types.h:36
@ SWITCH_APPLY
Definition: epb_types.h:38
@ SWITCH_RELEASE
Definition: epb_types.h:39
@ SWITCH_NEUTRAL
Definition: epb_types.h:37
SwitchState current
uint8_t candidate_count
SwitchState candidate
uint8_t apply_raw
Definition: epb_types.h:43
uint8_t release_raw
Definition: epb_types.h:44
static DebouncerCtx s_ctx
static SwitchState raw_to_candidate(SwitchRaw raw)
SwitchState switch_get_state(void)
void switch_step_10ms(SwitchRaw raw)
EpbStatus switch_init(void)
EPB-Schalter mit Software-Entprellung.
#define SWITCH_DEBOUNCE_SAMPLES
Step-Zyklus 10 ms.