LCOV - code coverage report
Current view: top level - src - switch_debouncer.c (source / functions) Hit Total Coverage
Test: coverage.clean.info Lines: 23 23 100.0 %
Date: 2026-05-13 07:33:50 Functions: 4 4 100.0 %

          Line data    Source code
       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 {
      13             :     SwitchState current;
      14             :     SwitchState candidate;
      15             :     uint8_t     candidate_count;
      16             : } DebouncerCtx;
      17             : 
      18             : static DebouncerCtx s_ctx;
      19             : 
      20          50 : static SwitchState raw_to_candidate(SwitchRaw raw)
      21             : {
      22          50 :     if (raw.apply_raw && !raw.release_raw) {
      23          24 :         return SWITCH_APPLY;
      24             :     }
      25          26 :     if (raw.release_raw && !raw.apply_raw) {
      26          12 :         return SWITCH_RELEASE;
      27             :     }
      28          14 :     return SWITCH_NEUTRAL;
      29             : }
      30             : 
      31          10 : EpbStatus switch_init(void)
      32             : {
      33          10 :     s_ctx.current = SWITCH_NEUTRAL;
      34          10 :     s_ctx.candidate = SWITCH_NEUTRAL;
      35          10 :     s_ctx.candidate_count = 0U;
      36          10 :     return EPB_OK;
      37             : }
      38             : 
      39          50 : void switch_step_10ms(SwitchRaw raw)
      40             : {
      41          50 :     const SwitchState observed = raw_to_candidate(raw);
      42             : 
      43          50 :     if (observed == s_ctx.candidate) {
      44          36 :         if (s_ctx.candidate_count < SWITCH_DEBOUNCE_SAMPLES) {
      45          34 :             ++s_ctx.candidate_count;
      46             :         }
      47             :     } else {
      48          14 :         s_ctx.candidate = observed;
      49          14 :         s_ctx.candidate_count = 1U;
      50             :     }
      51             : 
      52          50 :     if (s_ctx.candidate_count >= SWITCH_DEBOUNCE_SAMPLES) {
      53          10 :         s_ctx.current = s_ctx.candidate;
      54             :     }
      55          50 : }
      56             : 
      57          20 : SwitchState switch_get_state(void)
      58             : {
      59          20 :     return s_ctx.current;
      60             : }

Generated by: LCOV version 1.14