diff --git a/Source/error.c b/Source/error.c new file mode 100644 --- /dev/null +++ b/Source/error.c @@ -0,0 +1,80 @@ +// +// Error: Provides a simple interface for asserting and checking errors +// + +#include "error.h" +#include "stm32f0xx_hal.h" + +#include + + +volatile uint32_t err_reg; +volatile uint8_t num_errors_asserted = 0; + +// Moderately detailed messages corresponding to each error enum +char * error_message[] = +{ + "RS485 parse fail", +}; + +// Set the passed error flag +void error_assert(uint8_t errno) +{ + // Errno invalid: exceeds bit length of error register + if(errno >= 32) + return; + + // Set error flag + err_reg |= (1<= 32) + return; + + // Set error flag + err_reg |= (1< 0; +} + +// Return 1 if any error has occurred +uint8_t error_occurred(void) +{ + return err_reg > 0; +} + +// Return the number of errors that have occurred +uint8_t error_count(void) +{ + return num_errors_asserted; +}