GCC Code Coverage Report


Directory: ../../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 12.5% 7 / 0 / 56
Functions: 25.0% 2 / 0 / 8
Branches: 9.7% 3 / 0 / 31

driver/ignition/ignition.c
Line Branch Exec Source
1 /*******************************************************************************
2 *
3 * FILE:
4 * ignition.c
5 *
6 * DESCRIPTION:
7 * Contains API function to the engine controller ignition system and
8 * contintuity readings
9 *
10 * COPYRIGHT:
11 * Copyright (c) 2025 Sun Devil Rocketry.
12 * All rights reserved.
13 *
14 * This software is licensed under terms that can be found in the LICENSE
15 * file in the root directory of this software component.
16 * If no LICENSE file comes with this software, it is covered under the
17 * BSD-3-Clause.
18 *
19 * https://opensource.org/license/bsd-3-clause
20 *
21 *******************************************************************************/
22
23
24 /*------------------------------------------------------------------------------
25 Standard Includes
26 ------------------------------------------------------------------------------*/
27 #include <stdbool.h>
28
29
30 /*------------------------------------------------------------------------------
31 MCU Pins
32 ------------------------------------------------------------------------------*/
33 #if defined( FLIGHT_COMPUTER )
34 #include "sdr_pin_defines_A0002.h"
35 #elif defined( ENGINE_CONTROLLER )
36 #include "sdr_pin_defines_L0002.h"
37 #elif defined( FLIGHT_COMPUTER_LITE )
38 #include "sdr_pin_defines_A0007.h"
39 #endif
40
41 /*------------------------------------------------------------------------------
42 Project Includes
43 ------------------------------------------------------------------------------*/
44 #include "main.h"
45 #include "ignition.h"
46
47
48 /*------------------------------------------------------------------------------
49 Static Variables
50 ------------------------------------------------------------------------------*/
51 bool ign_switch_enabled = true;
52
53 /*------------------------------------------------------------------------------
54 Procedures
55 ------------------------------------------------------------------------------*/
56
57
58 /*******************************************************************************
59 * *
60 * PROCEDURE: *
61 * ign_cmd_execute *
62 * *
63 * DESCRIPTION: *
64 * Executes an ignition subcommand based on user input from the sdec *
65 * terminal *
66 * *
67 *******************************************************************************/
68 ✗ IGN_STATUS ign_cmd_execute
69 (
70 IGN_SUBCOMMAND ign_subcommand
71 )
72 {
73 /*------------------------------------------------------------------------------
74 Local Variables
75 ------------------------------------------------------------------------------*/
76 ✗ IGN_STATUS ign_status = 0; /* Status code returned by ignite API function */
77
78 /*------------------------------------------------------------------------------
79 Call API function
80 ------------------------------------------------------------------------------*/
81 ✗ switch( ign_subcommand )
82 {
83 #if defined( FLIGHT_COMPUTER )
84 /* Deploy main */
85 ✗ case IGN_MAIN_DEPLOY_CODE:
86 {
87 ✗ ign_status = ign_deploy_main();
88 ✗ break;
89 }
90
91 /* Deploy drogue */
92 ✗ case IGN_DROGUE_DEPLOY_CODE:
93 {
94 ✗ ign_status = ign_deploy_drogue();
95 ✗ break;
96 }
97 ✗ case IGN_ENABLE_TEST_CODE:
98 {
99 ✗ ign_switch_enabled = !ign_switch_enabled;
100 ✗ ign_status = IGN_OK;
101 ✗ break;
102 }
103
104 #elif defined( ENGINE_CONTROLLER )
105 /* Light ematch */
106 case IGN_FIRE_CODE:
107 {
108 ign_status = ign_ignite();
109 break;
110 }
111
112 #endif /* #elif defined( ENGINE_CONTROLLER ) */
113
114 /* Return continuity information */
115 ✗ case IGN_CONT_CODE:
116 {
117 ✗ ign_status = ign_get_cont_info();
118 ✗ break;
119 }
120
121 /* Unrecognized subcommand code: call error handler */
122 default:
123 {
124 return IGN_UNRECOGNIZED_CMD;
125 break;
126 }
127 }
128
129 /* Return the response code */
130 return ign_status;
131
132 } /* ign_cmd_execute */
133
134
135 #if defined( ENGINE_CONTROLLER )
136 /*******************************************************************************
137 * *
138 * PROCEDURE: *
139 * ign_ignite *
140 * *
141 * DESCRIPTION: *
142 * Asserts the ignition signal to ignite the engine ematch. Returns a *
143 * response code indicating if the ignition occured succesfully *
144 * *
145 *******************************************************************************/
146 IGN_STATUS ign_ignite
147 (
148 void
149 )
150 {
151 /*------------------------------------------------------------------------------
152 API function implementation
153 ------------------------------------------------------------------------------*/
154
155 /* Check for e-match/switch continuity */
156 if ( !ign_ematch_cont() )
157 {
158 /* No continuity across ematch and/or switch */
159 return IGN_EMATCH_CONT_FAIL;
160 }
161
162 /* Check that power supply is not USB */
163
164 /* Assert ignition signal for 10 ms */
165 HAL_GPIO_WritePin(FIRE_GPIO_PORT, FIRE_PIN, GPIO_PIN_SET );
166 HAL_Delay( IGN_BURN_DELAY );
167 HAL_GPIO_WritePin(FIRE_GPIO_PORT, FIRE_PIN, GPIO_PIN_RESET);
168
169 /* Check ematch continuity to check that ematch was lit */
170 if ( !ign_ematch_cont() )
171 {
172 return IGN_SUCCESS;
173 }
174 else /* Ignition unsuccessful */
175 {
176 return IGN_FAIL;
177 }
178
179 } /* ignite */
180 #endif /* #if defined( ENGINE_CONTROLLER ) */
181
182 /*******************************************************************************
183 * *
184 * PROCEDURE: *
185 * ign_get_cont_info *
186 * *
187 * DESCRIPTION: *
188 * Polls each continuity pin and sets the continuity bits in the *
189 * response code *
190 * *
191 *******************************************************************************/
192 ✗ IGN_STATUS ign_get_cont_info
193 (
194 void
195 )
196 {
197 /*------------------------------------------------------------------------------
198 Local Variables
199 ------------------------------------------------------------------------------*/
200 ✗ IGN_STATUS ign_status = 0; /* Status code to be returned */
201
202
203 /*------------------------------------------------------------------------------
204 Call API functions
205 ------------------------------------------------------------------------------*/
206
207 #if defined( ENGINE_CONTROLLER )
208 /* Poll the ematch continuity pin */
209 if ( ign_ematch_cont() )
210 {
211 ign_status |= IGN_E_CONT_MASK;
212 }
213
214 /* Poll the solid propellant continuity pin */
215 if ( ign_solid_prop_cont() )
216 {
217 ign_status |= IGN_SP_CONT_MASK;
218 }
219
220 /* Poll the nozzle continuity pin */
221 if ( ign_nozzle_cont() )
222 {
223 ign_status |= IGN_NOZ_CONT_MASK;
224 }
225 #elif ( defined( FLIGHT_COMPUTER ) || defined( FLIGHT_COMPUTER_LITE ) )
226 /* Poll the switch continuity pin */
227 ✗ if ( ign_switch_cont() )
228 {
229 ✗ ign_status |= IGN_SWITCH_MASK;
230 }
231
232 /* Poll the main parachute deployment continuity pin */
233 ✗ if ( ign_main_cont() )
234 {
235 ✗ ign_status |= IGN_MAIN_CONT_MASK;
236 }
237
238 /* Poll the drogue parachute deployment continuity pin */
239 ✗ if ( ign_drogue_cont() )
240 {
241 ✗ ign_status |= IGN_DROGUE_CONT_MASK;
242 }
243 #endif /* elif defined( FLIGHT_COMPUTER ) */
244
245 /* Return the status code */
246 ✗ return ign_status;
247
248 } /* ign_get_cont_info */
249
250
251 #if defined( ENGINE_CONTROLLER )
252 /*******************************************************************************
253 * *
254 * PROCEDURE: *
255 * solid_prop_cont *
256 * *
257 * DESCRIPTION: *
258 * Returns TRUE if there is continuity across the solid propellant wire *
259 * screw terminals *
260 * *
261 *******************************************************************************/
262 bool ign_solid_prop_cont
263 (
264 void
265 )
266 {
267
268 /* Check MCU GPIO State */
269 uint8_t solid_prop_cont_pinstate = HAL_GPIO_ReadPin(SP_CONT_GPIO_PORT, SP_CONT_PIN);
270
271 /* Return true if GPIO state is high*/
272 if ( solid_prop_cont_pinstate == 0 )
273 {
274 return true;
275 }
276 else
277 {
278 return false;
279 }
280
281 } /* ign_solid_prop_cont */
282
283
284 /*******************************************************************************
285 * *
286 * PROCEDURE: *
287 * ign_nozzle_cont *
288 * *
289 * DESCRIPTION: *
290 * Returns TRUE if there is continuity across the nozzle wire screw *
291 * terminals *
292 * *
293 *******************************************************************************/
294 bool ign_nozzle_cont
295 (
296 void
297 )
298 {
299
300 /* Check MCU GPIO State */
301 uint8_t nozzle_cont_pinstate = HAL_GPIO_ReadPin(NOZ_CONT_GPIO_PORT, NOZ_CONT_PIN);
302
303 /* Return true if GPIO state is high*/
304 if ( nozzle_cont_pinstate == 0 )
305 {
306 return true;
307 }
308 else
309 {
310 return false;
311 }
312
313 } /* ign_nozzle_cont */
314
315
316 /*******************************************************************************
317 * *
318 * PROCEDURE: *
319 * ign_ematch_cont *
320 * *
321 * DESCRIPTION: *
322 * Returns TRUE if there is continuity across the ematch and switch screw *
323 * terminals *
324 * *
325 *******************************************************************************/
326 bool ign_ematch_cont
327 (
328 void
329 )
330 {
331 /* Check MCU GPIO State */
332 uint8_t ematch_cont_pinstate = HAL_GPIO_ReadPin(E_CONT_GPIO_PORT, E_CONT_PIN);
333
334 /* Return true if GPIO state is low */
335 if ( ematch_cont_pinstate == 0 )
336 {
337 return false;
338 }
339 else
340 {
341 return true;
342 }
343
344 } /* ign_ematch_cont */
345
346 #endif /* #if defined( ENGINE_CONTROLLER ) */
347
348
349 #if ( defined( FLIGHT_COMPUTER ) || defined( FLIGHT_COMPUTER_LITE ) )
350 /*******************************************************************************
351 * *
352 * PROCEDURE: *
353 * ign_deploy_main *
354 * *
355 * DESCRIPTION: *
356 * Asserts the ignition signal to ignite the main parachute deployment *
357 * ematch. Returns a response code indicating if the ignition occured *
358 * succesfully *
359 * *
360 *******************************************************************************/
361 ✗ IGN_STATUS ign_deploy_main
362 (
363 void
364 )
365 {
366 /*------------------------------------------------------------------------------
367 API function implementation
368 ------------------------------------------------------------------------------*/
369
370 /* Check continuities before deploying*/
371 ✗ if ( !ign_switch_cont() )
372 {
373 return IGN_SWITCH_FAIL;
374 }
375 ✗ else if ( !ign_main_cont() )
376 {
377 return IGN_MAIN_CONT_FAIL;
378 }
379 else /* Continuity is good for main */
380 {
381 /* Assert ignition signal for 10 ms */
382 ✗ HAL_GPIO_WritePin( MAIN_GPIO_PORT, MAIN_PIN, GPIO_PIN_SET );
383 ✗ HAL_Delay( IGN_BURN_DELAY );
384 ✗ HAL_GPIO_WritePin( MAIN_GPIO_PORT, MAIN_PIN, GPIO_PIN_RESET );
385 }
386
387 /* Check ematch continuity to check that ematch was lit */
388 ✗ if ( !ign_main_cont() )
389 {
390 return IGN_SUCCESS;
391 }
392 else /* Ignition unsuccessful */
393 {
394 ✗ return IGN_MAIN_FAIL;
395 }
396
397 } /* ign_deploy_main */
398
399
400 /*******************************************************************************
401 * *
402 * PROCEDURE: *
403 * ign_deploy_drogue *
404 * *
405 * DESCRIPTION: *
406 * Asserts the ignition signal to ignite the drogue parachute deployment *
407 * ematch. Returns a response code indicating if the ignition occured *
408 * succesfully *
409 * *
410 *******************************************************************************/
411 ✗ IGN_STATUS ign_deploy_drogue
412 (
413 void
414 )
415 {
416 /*------------------------------------------------------------------------------
417 API function implementation
418 ------------------------------------------------------------------------------*/
419
420 /* Check continuities before deploying*/
421 ✗ if ( !ign_switch_cont() )
422 {
423 return IGN_SWITCH_FAIL;
424 }
425 ✗ else if ( !ign_drogue_cont() )
426 {
427 return IGN_DROGUE_CONT_FAIL;
428 }
429 else /* Continuity is good for drogue */
430 {
431 /* Assert ignition signal for 10 ms */
432 ✗ HAL_GPIO_WritePin( DROGUE_GPIO_PORT, DROGUE_PIN, GPIO_PIN_SET );
433 ✗ HAL_Delay( IGN_BURN_DELAY );
434 ✗ HAL_GPIO_WritePin( DROGUE_GPIO_PORT, DROGUE_PIN, GPIO_PIN_RESET );
435 }
436
437 /* Check ematch continuity to check that ematch was lit */
438 ✗ if ( !ign_drogue_cont() )
439 {
440 return IGN_SUCCESS;
441 }
442 else /* Ignition unsuccessful */
443 {
444 ✗ return IGN_DROGUE_FAIL;
445 }
446
447 } /* ign_deploy_drogue */
448
449
450 /*******************************************************************************
451 * *
452 * PROCEDURE: *
453 * ign_main_cont *
454 * *
455 * DESCRIPTION: *
456 * Returns TRUE if there is continuity across the main parachute *
457 * deployment ematch *
458 * *
459 *******************************************************************************/
460 ✗ bool ign_main_cont
461 (
462 void
463 )
464 {
465
466 /* Check MCU GPIO State */
467 ✗ uint8_t main_cont_pinstate = HAL_GPIO_ReadPin( MAIN_CONT_GPIO_PORT, MAIN_CONT_PIN );
468
469 /* Return true if GPIO state is low */
470 ✗ if ( main_cont_pinstate == 0 )
471 {
472 return false;
473 }
474 else
475 {
476 ✗ return true;
477 }
478
479 } /* ign_main_cont */
480
481
482 /*******************************************************************************
483 * *
484 * PROCEDURE: *
485 * ign_drogue_cont *
486 * *
487 * DESCRIPTION: *
488 * Returns TRUE if there is continuity across the drogue parachute *
489 * deployment ematch *
490 * *
491 *******************************************************************************/
492 ✗ bool ign_drogue_cont
493 (
494 void
495 )
496 {
497
498 /* Check MCU GPIO State */
499 ✗ uint8_t drogue_cont_pinstate = HAL_GPIO_ReadPin( DROGUE_CONT_GPIO_PORT,
500 DROGUE_CONT_PIN );
501
502 /* Return true if GPIO state is low */
503 ✗ if ( drogue_cont_pinstate == 0 )
504 {
505 return false;
506 }
507 else
508 {
509 ✗ return true;
510 }
511
512 } /* drogue_cont */
513 #endif /* #if defined( FLIGHT_COMPUTER ) */
514
515
516 #if ( defined( FLIGHT_COMPUTER ) || defined( FLIGHT_COMPUTER_LITE ) )
517 /*******************************************************************************
518 * *
519 * PROCEDURE: *
520 * ign_switch_cont *
521 * *
522 * DESCRIPTION: *
523 * Returns TRUE if there is continuity across the switch screw terminals *
524 * *
525 *******************************************************************************/
526 778 bool ign_switch_cont
527 (
528 void
529 )
530 {
531 /* Check MCU GPIO State */
532 778 uint8_t switch_cont_pinstate = HAL_GPIO_ReadPin(SWITCH_GPIO_PORT, SWITCH_PIN);
533
534 /* Return true if GPIO state is low */
535
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 777 times.
778 if ( switch_cont_pinstate == 0 )
536 {
537 return false;
538 }
539 else
540 {
541 1 return true;
542 }
543
544 } /* switch_cont */
545
546
547 /*******************************************************************************
548 * *
549 * PROCEDURE: *
550 * ign_switch_armed *
551 * *
552 * DESCRIPTION: *
553 * Wrapper for ign_switch_cont that allows disabling the switch. *
554 * *
555 *******************************************************************************/
556 775 bool ign_switch_armed
557 (
558 void
559 )
560 {
561
1/2
✓ Branch 0 taken 775 times.
✗ Branch 1 not taken.
775 if( !ign_switch_enabled )
562 {
563 return false;
564 }
565
566 775 return ign_switch_cont();
567
568 } /* switch_armed */
569 #endif /* #if defined( FLIGHT_COMPUTER ) */
570
571
572 /*******************************************************************************
573 * END OF FILE *
574 *******************************************************************************/
575