1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * @file switch_debouncer.c
 * @brief Implementierung des EPB-Schalter-Debouncers.
 *
 * @arch SWA-006
 * @reqs SWE-025
 *
 * ASIL: QM.
 */
#include "switch_debouncer.h"

typedef struct {
    SwitchState current;
    SwitchState candidate;
    uint8_t     candidate_count;
} DebouncerCtx;

static DebouncerCtx s_ctx;

static SwitchState raw_to_candidate(SwitchRaw raw)
{
    if (raw.apply_raw && !raw.release_raw) {
        return SWITCH_APPLY;
    }
    if (raw.release_raw && !raw.apply_raw) {
        return SWITCH_RELEASE;
    }
    return SWITCH_NEUTRAL;
}

EpbStatus switch_init(void)<--- The function 'switch_init' is never used.
{
    s_ctx.current = SWITCH_NEUTRAL;
    s_ctx.candidate = SWITCH_NEUTRAL;
    s_ctx.candidate_count = 0U;
    return EPB_OK;
}

void switch_step_10ms(SwitchRaw raw)<--- The function 'switch_step_10ms' is never used.
{
    const SwitchState observed = raw_to_candidate(raw);

    if (observed == s_ctx.candidate) {
        if (s_ctx.candidate_count < SWITCH_DEBOUNCE_SAMPLES) {
            ++s_ctx.candidate_count;
        }
    } else {
        s_ctx.candidate = observed;
        s_ctx.candidate_count = 1U;
    }

    if (s_ctx.candidate_count >= SWITCH_DEBOUNCE_SAMPLES) {
        s_ctx.current = s_ctx.candidate;
    }
}

SwitchState switch_get_state(void)<--- The function 'switch_get_state' is never used.
{
    return s_ctx.current;
}