app/rev2/error_contract.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /******************************************************************************* | ||
| 2 | * * | ||
| 3 | * FILE: * | ||
| 4 | * error_contract.c * | ||
| 5 | * * | ||
| 6 | * DESCRIPTION: * | ||
| 7 | * Contains error callback table definitions for APPA. * | ||
| 8 | * * | ||
| 9 | * CRITICALITY: * | ||
| 10 | * FQ - Flight Qualified * | ||
| 11 | * * | ||
| 12 | * COPYRIGHT: * | ||
| 13 | * Copyright (c) 2025 Sun Devil Rocketry. * | ||
| 14 | * All rights reserved. * | ||
| 15 | * * | ||
| 16 | * This software is licensed under terms that can be found in the LICENSE * | ||
| 17 | * file in the root directory of this software component. * | ||
| 18 | * If no LICENSE file comes with this software, it is covered under the * | ||
| 19 | * BSD-3-Clause. * | ||
| 20 | * * | ||
| 21 | * https://opensource.org/license/bsd-3-clause * | ||
| 22 | * * | ||
| 23 | *******************************************************************************/ | ||
| 24 | |||
| 25 | /*------------------------------------------------------------------------------ | ||
| 26 | Standard Includes | ||
| 27 | ------------------------------------------------------------------------------*/ | ||
| 28 | #include <stdlib.h> | ||
| 29 | #include "main.h" | ||
| 30 | #include "led.h" | ||
| 31 | #include "math_sdr.h" | ||
| 32 | #include "timer.h" | ||
| 33 | #include "error_sdr.h" | ||
| 34 | #include "buzzer.h" | ||
| 35 | |||
| 36 | |||
| 37 | /*------------------------------------------------------------------------------ | ||
| 38 | Callback Function Prototypes | ||
| 39 | ------------------------------------------------------------------------------*/ | ||
| 40 | static void error_callback_i2c_init | ||
| 41 | ( | ||
| 42 | volatile ERROR_CODE error_code | ||
| 43 | ); | ||
| 44 | |||
| 45 | static void error_callback_lora | ||
| 46 | ( | ||
| 47 | volatile ERROR_CODE error_code | ||
| 48 | ); | ||
| 49 | |||
| 50 | /*------------------------------------------------------------------------------ | ||
| 51 | Callback Table | ||
| 52 | ------------------------------------------------------------------------------*/ | ||
| 53 | volatile ERROR_CALLBACK error_callback_table[] = | ||
| 54 | { | ||
| 55 | { ERROR_BARO_INIT_ERROR , error_callback_i2c_init }, | ||
| 56 | { ERROR_IMU_INIT_ERROR , error_callback_i2c_init }, | ||
| 57 | { ERROR_BARO_I2C_INIT_ERROR , error_callback_i2c_init }, | ||
| 58 | { ERROR_IMU_I2C_INIT_ERROR , error_callback_i2c_init }, | ||
| 59 | { ERROR_I2C_HAL_MSP_ERROR , error_callback_i2c_init }, | ||
| 60 | { ERROR_BARO_CAL_ERROR , error_callback_i2c_init }, | ||
| 61 | { ERROR_LORA_INIT_ERROR , error_callback_lora }, | ||
| 62 | { ERROR_LORA_CMD_ERROR , error_callback_lora } | ||
| 63 | }; | ||
| 64 | uint16_t error_callback_table_size = array_size(error_callback_table); | ||
| 65 | |||
| 66 | |||
| 67 | /*------------------------------------------------------------------------------ | ||
| 68 | Callback Implementations | ||
| 69 | ------------------------------------------------------------------------------*/ | ||
| 70 | |||
| 71 | /******************************************************************************* | ||
| 72 | * * | ||
| 73 | * PROCEDURE: * | ||
| 74 | * error_callback_i2c_init * | ||
| 75 | * * | ||
| 76 | * DESCRIPTION: * | ||
| 77 | * Provides a slightly different error handler for different i2c init * | ||
| 78 | * errors. Temporary function for debugging * | ||
| 79 | * debugging of SunDevilRocketry/Flight-Computer-Firmware#192 * | ||
| 80 | * * | ||
| 81 | *******************************************************************************/ | ||
| 82 | ✗ | void error_callback_i2c_init | |
| 83 | ( | ||
| 84 | volatile ERROR_CODE error_code | ||
| 85 | ) | ||
| 86 | { | ||
| 87 | // ETS TEMP: This callback is temporary while we debug an issue. If you hit this, | ||
| 88 | // please document it in #avionics-firmware and tell us the number of beeps. | ||
| 89 | // We'll match it to our key and record what may have happened. | ||
| 90 | ✗ | led_set_color( LED_RED ); /* set LED to red */ | |
| 91 | |||
| 92 | ✗ | switch ( error_code ) | |
| 93 | { | ||
| 94 | /* seq: 1 beep */ | ||
| 95 | ✗ | case ERROR_BARO_INIT_ERROR: | |
| 96 | ✗ | while(1) | |
| 97 | { | ||
| 98 | ✗ | buzzer_multi_beeps(200, 200, 1); | |
| 99 | ✗ | delay_ms(1000); | |
| 100 | } | ||
| 101 | /* seq: 2 beeps */ | ||
| 102 | ✗ | case ERROR_IMU_INIT_ERROR: | |
| 103 | ✗ | while(1) | |
| 104 | { | ||
| 105 | ✗ | buzzer_multi_beeps(200, 200, 2); | |
| 106 | ✗ | delay_ms(1000); | |
| 107 | } | ||
| 108 | /* seq: 3 beeps */ | ||
| 109 | ✗ | case ERROR_BARO_I2C_INIT_ERROR: | |
| 110 | ✗ | while(1) | |
| 111 | { | ||
| 112 | ✗ | buzzer_multi_beeps(200, 200, 3); | |
| 113 | ✗ | delay_ms(1000); | |
| 114 | } | ||
| 115 | /* seq: 4 beeps */ | ||
| 116 | ✗ | case ERROR_IMU_I2C_INIT_ERROR: | |
| 117 | ✗ | while(1) | |
| 118 | { | ||
| 119 | ✗ | buzzer_multi_beeps(200, 200, 4); | |
| 120 | ✗ | delay_ms(1000); | |
| 121 | } | ||
| 122 | /* seq: 5 beeps */ | ||
| 123 | ✗ | case ERROR_I2C_HAL_MSP_ERROR: | |
| 124 | ✗ | while(1) | |
| 125 | { | ||
| 126 | ✗ | buzzer_multi_beeps(200, 200, 5); | |
| 127 | ✗ | delay_ms(1000); | |
| 128 | } | ||
| 129 | /* seq: 6 beeps */ | ||
| 130 | ✗ | case ERROR_BARO_CAL_ERROR: | |
| 131 | ✗ | while(1) | |
| 132 | { | ||
| 133 | ✗ | buzzer_multi_beeps(200, 200, 6); | |
| 134 | ✗ | delay_ms(1000); | |
| 135 | } | ||
| 136 | /** | ||
| 137 | * GCOVR_EXCL_START | ||
| 138 | * | ||
| 139 | * Protective default case to prevent programmer error. Called by one function that will fall into one | ||
| 140 | * of the above cases. | ||
| 141 | */ | ||
| 142 | − | default: | |
| 143 | − | while(1) | |
| 144 | { | ||
| 145 | /* Constant blinking beep */ | ||
| 146 | − | buzzer_multi_beeps(200, 200, 1); | |
| 147 | } | ||
| 148 | } | ||
| 149 | /** | ||
| 150 | * GCOVR_EXCL_STOP | ||
| 151 | */ | ||
| 152 | |||
| 153 | } /* store_frame */ | ||
| 154 | |||
| 155 | |||
| 156 | ✗ | void error_callback_lora | |
| 157 | ( | ||
| 158 | volatile ERROR_CODE error_code | ||
| 159 | ) | ||
| 160 | { | ||
| 161 | ✗ | while(1) { | |
| 162 | ✗ | led_set_color( LED_RED ); | |
| 163 | ✗ | buzzer_beep(150); | |
| 164 | ✗ | led_set_color( LED_CYAN ); | |
| 165 | ✗ | delay_ms(150); | |
| 166 | } | ||
| 167 | |||
| 168 | } /* error_callback_lora */ | ||
| 169 |