ECE 486 Support Libraries
err486.h
Go to the documentation of this file.
1 /*!
2  * @file
3  *
4  * @brief Error Handling for ECE 486 STM32L476G-Discovery Interface
5  * @author Don Hummels
6  * @date Jan, 2016
7  *
8  * Defines error flags and error indication mechanisms for the ECE 486 interface
9  * to the STM32L476-Discovery development boards
10  *
11  */
12 
13 /*!
14  * @page ErrorHandling Error Handling Interface
15  *
16  * When an error is detected, an error code is recorded in a circularly accessed
17  * global error buffer (#errorbuf), and the red LED (Port D, Pin 14) is lit to indicate the
18  * error condition to the user. Users may then use a debugger to investigate
19  * error buffer to learn the cause of the most recent sequence of errors.
20  *
21  * An error message is also written to the output serial port for the first error
22  * thrown.
23  *
24  * - When debugging, examine #errorbuf to learn the most recent sequence of errors.
25  * - #errorbuf[] is of length #ERRORBUFLEN, and is written to circularly, so that when
26  * the buffer is filled, errors continue to be written by restarting at the start of the array.
27  * - The global #erroridx gives the index into #errorbuf at which the next error
28  * will be stored. The most recent error is stored at index #erroridx - 1.
29  * - An error is "thrown" by calling @code
30  * #include "err486.h"
31  * ...
32  * flagerror(error_code);
33  * @endcode where @a error_code is an integer value to be stored in the #errorbuf array
34  * - Predefined error codes are provided in err486.h for #SAMPLE_OVERRUN,
35  * #MEMORY_ALLOCATION_ERROR, #DAC_CONFIG_ERROR, #ADC_CONFIG_ERROR, #SETBLOCKSIZE_ERROR
36  * - flagerror(error_code) also displays the error code on the LCD, and writes an error
37  * message using printf()
38  */
39 
40 /*!
41  * @defgroup ECE486_Error ECE 486 Discovery Interface Error Handling
42  * @{
43  */
44 
45 
46 #ifndef __ERR486__
47 #define __ERR486__
48 
49 #include "init486.h"
50 
51 #define ERRORBUFLEN 100 //!< Number of errors to record in a circular buffer
52 
53 /*!
54  * @defgroup ECE486_Error_Codes ECE 486/Discovery Error Codes
55  * @{
56  */
57 #define SAMPLE_OVERRUN 2 //!< ADC buffer filled before the user serviced the buffer
58 #define MEMORY_ALLOCATION_ERROR 3 //!< malloc() or calloc() returned NULL
59 #define DAC_CONFIG_ERROR 4
60 #define ADC_CONFIG_ERROR 5
61 #define SETBLOCKSIZE_ERROR 6 //!< setblocksize() must be called BEFORE initialize()
62 #define UART_CONFIG_ERROR 7
63 #define CLOCK_CONFIG_ERROR 8
64 /*! @} End of ECE486_Error_Codes Group */
65 
66 
67 /* --------- Globals --------------------------- */
68 
69 /*!
70  * @brief Circular buffer to store the most recent error codes
71  */
72 extern int errorbuf[];
73 
74 /*!
75  * @brief Index of the NEXT error to be written into the errorbuf array
76  */
77 extern int erroridx;
78 
79 /*!
80  * @defgroup ErrorFunctions Error Handling Functions
81  * @{
82  */
83 
84 /*!
85  * @brief Initialization routine to set up error buffers
86  *
87  * Called once, at program start-up: Sets all error codes in errorbuf[i]
88  * to zero, and clears the red LED.
89  */
90 void initerror();
91 
92 /*!
93  * @brief Records and indicates an error condition
94  *
95  * - Writes the input value @a errorcode into the #errorbuf array
96  * - Circularly increments the error index #erroridx
97  * - Indicates an error by lighting the red LED
98  */
99 void flagerror(
100  int errorcode //!< [in] Error code to be stored in #errorbuf[#erroridx]
101 );
102 
103 /*! @} End of ErrorFunctions group */
104 /*! @} End of ECE486_Error group */
105 #endif
void initerror()
Initialization routine to set up error buffers.
Definition: err486.c:34
int erroridx
Index of the NEXT error to be written into the errorbuf array.
Definition: err486.c:29
void flagerror(int errorcode)
Records and indicates an error condition.
Definition: err486.c:48
int errorbuf[]
Circular buffer to store the most recent error codes.
Definition: err486.c:27
STM32L476-Discovery configuration routines to support ECE 486.