GCC Code Coverage Report


Directory: mod/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 11 / 3 / 14
Functions: 100.0% 2 / 1 / 3
Branches: 100.0% 6 / 0 / 6

error_sdr/error_sdr.c
Line Branch Exec Source
1 /**
2 *******************************************************************************
3 * @file error_sdr.c
4 * @brief Contains error-related functions for SDR code.
5 *******************************************************************************
6 * @copyright
7 *
8 * Copyright (c) 2026 Sun Devil Rocketry.
9 * All rights reserved.
10 *
11 * This software is licensed under terms that can be found in the LICENSE file
12 * in the root directory of this software component.
13 * If no LICENSE file comes with this software, it is covered under the
14 * BSD-3-Clause.
15 *
16 * https://opensource.org/license/bsd-3-clause
17 *
18 *******************************************************************************
19 */
20
21
22 /*------------------------------------------------------------------------------
23 Standard Includes
24 ------------------------------------------------------------------------------*/
25 #include <string.h>
26 #include <stdbool.h>
27
28 /*------------------------------------------------------------------------------
29 Project Includes
30 ------------------------------------------------------------------------------*/
31 #include "main.h"
32 #include "math_sdr.h"
33 #include "error_sdr.h"
34
35 #if defined( STM32H750xx ) || defined( STM32H733xx )
36 #include "stm32h7xx_hal.h"
37 #include "led.h"
38 #elif defined( F1_TESTBED )
39 // LEDs not supported. Provide a stub.
40 typedef enum {
41 LED_RED,
42 LED_BLUE,
43 LED_GREEN,
44 LED_PURPLE,
45 LED_CYAN,
46 LED_YELLOW,
47 LED_WHITE
48 } LED_COLOR;
49
50 void led_set_color( LED_COLOR color )
51 {} // stub
52 #endif
53
54 /*------------------------------------------------------------------------------
55 Internal function prototypes
56 ------------------------------------------------------------------------------*/
57 #ifdef USE_CALLBACK_TABLE
58 static volatile ERROR_CALLBACK* callback_table_lookup
59 (
60 volatile ERROR_CODE error_code
61 );
62 #endif
63
64 static void dflt_error_handler
65 (
66 volatile ERROR_CODE error_code
67 );
68
69 /*------------------------------------------------------------------------------
70 Global Variables
71 ------------------------------------------------------------------------------*/
72
73 /* Contract: Callback table must be defined by the project.
74 Implementation not provided by the module. */
75 #ifdef USE_CALLBACK_TABLE
76 extern volatile ERROR_CALLBACK error_callback_table[];
77 extern uint16_t error_callback_table_size;
78 #endif
79
80 /*------------------------------------------------------------------------------
81 Static Variables
82 ------------------------------------------------------------------------------*/
83
84 TEXT_MESSAGE last_warning;
85 bool is_pending_warning = false;
86
87 TEXT_MESSAGE last_info;
88 bool is_pending_info = false;
89
90 /* Default error handler for table misses or undefined tables. Can be overridden. */
91 volatile ERROR_CALLBACK default_error_handler = { 0, dflt_error_handler };
92
93 /*------------------------------------------------------------------------------
94 API Functions
95 ------------------------------------------------------------------------------*/
96
97
98
99 /**
100 * @brief Dispatches an error to its registered callback or default handler.
101 * @param error_code Error code to handle.
102 */
103 2 void error_fail_fast
104 (
105 volatile ERROR_CODE error_code
106 )
107 {
108 #if defined(USE_CALLBACK_TABLE)
109 /*------------------------------------------------------------------------------
110 Local Variables
111 ------------------------------------------------------------------------------*/
112 2 volatile ERROR_CALLBACK* error_callback_ptr;
113
114 /*------------------------------------------------------------------------------
115 Implementation
116 ------------------------------------------------------------------------------*/
117 2 error_callback_ptr = callback_table_lookup( error_code );
118
119 /* If error is in table, use its callback and return. */
120
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if( error_callback_ptr != NULL)
121 {
122 1 error_callback_ptr->error_callback( error_code );
123 1 return;
124 }
125 #endif
126
127 /*------------------------------------------------------------------------------
128 Default to Legacy Handling (table not defined or callback not found)
129 ------------------------------------------------------------------------------*/
130 1 default_error_handler.error_callback( error_code );
131
132 } /* error_fail_fast */
133
134
135 #if defined(USE_CALLBACK_TABLE)
136
137 /**
138 * @brief Finds the callback associated with an error code.
139 * @param error_code Error code to find.
140 * @return Pointer to the matching callback, or NULL if none exists.
141 */
142 2 static volatile ERROR_CALLBACK* callback_table_lookup
143 (
144 volatile ERROR_CODE error_code
145 )
146 {
147
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 time.
5 for( uint16_t i = 0; i < error_callback_table_size; i++ )
148 {
149
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if( error_callback_table[i].error_code == error_code )
150 {
151 1 return &( error_callback_table[i] );
152 }
153 }
154
155 return NULL;
156
157 } /* callback_table_lookup */
158 #endif
159
160
161 /**
162 * GCOVR_EXCL_START
163 *
164 * This whole function is excluded due to the control flow trap. It is impossible
165 * to return from this function. This case can be reached, but the whole point of
166 * getting here is that an error is unrecoverable, so via analysis we can prove
167 * that this will not return.
168 */
169
170 /**
171 * @brief Handles an unrecoverable error using the default error trap.
172 * @param error_code Error code that caused the unrecoverable failure.
173 */
174 − static void dflt_error_handler
175 (
176 volatile ERROR_CODE error_code
177 )
178 {
179 − led_set_color( LED_RED );
180 − while(1); /* Control flow trap */
181
182 } /* dflt_error_handler */
183 /**
184 * GCOVR_EXCL_STOP
185 */
186
187 /**
188 * END OF FILE *
189 */
190