ECE 486 Support Libraries
err486.c
Go to the documentation of this file.
1 /*!
2  * @file
3  * @brief Implementation of error handling routines for ECE 486
4  * @author Don Hummels
5  * @date Jan, 2013
6  */
7 
8 /*
9  Sets up a global error (circular) buffer. When flagerror() is called, a value
10  corresponding to that error is pushed into the buffer. The header file contains
11  the list of #define's that match error numbers with their errors. When an error
12  occurs, the red LED on port D, pin 14 will light up, and remain lit.
13 */
14 
15 #include "stm32l4xx_hal.h"
16 #include "stm32l476g_discovery.h"
17 
18 #include "err486.h"
19 #include "init486.h"
20 #include "stm32l476g_discovery_glass_lcd.h"
21 
22 static void print_error(int index);
23 
26 
29 int erroridx = 0;
30 
31 /*
32  * initerror() is called once to set up the global error buffer
33  */
34 void initerror()
35 {
36  int i;
37 
38  for (i=0; i<ERRORBUFLEN; i++) errorbuf[i] = 0;
39 
40  //turn off our error indicating LED
41  BSP_LED_Off(ERROR_LED);
42 }
43 
44 /*
45  flagerror() is called when an error occurs.
46  errorcode is written to the error buffer.
47 */
48 void flagerror(int errorcode)
49 {
50  char err_str[8];
51 
52  // Display the first error on the LCD if available
53  if (first_error == 0) {
54  first_error = errorcode;
55  sprintf(err_str, "ERR %2d", errorcode);
56  BSP_LCD_GLASS_DisplayString((uint8_t*)err_str);
57  print_error(errorcode);
58  }
59 
60  //turn on our error indicating LED
61  BSP_LED_On(ERROR_LED);
62 
63 
64  // Store an array of the most recent errors for examination by a debugger.
65  errorbuf[erroridx] = errorcode;
66  erroridx++;
67  if (erroridx == ERRORBUFLEN) erroridx = 0;
68 }
69 
70 static void print_error(int index){
71 
72  char* error;
73 
74  if(index == 2) error = "SAMPLE_OVERRUN";
75  else if(index == 3) error = "MEMORY_ALLOCATION_ERROR";
76  else if(index == 4) error = "DAC_CONFIG_ERROR";
77  else if(index == 5) error = "ADC_CONFIG_ERROR";
78  else if(index == 6) error = "SETBLOCKSIZE_ERROR";
79  else if(index == 7) error = "INVALID_MIC_SAMPLE_RATE";
80  else if(index == 8) error = "CLOCK_CONFIG_ERROR";
81  else if(index == 13) error = "DEBUG_ERROR";
82  else error = "UNKNOWN";
83 
84  printf("\n*** ERROR %d ***: %s\n",index, error);
85 }
void initerror()
Initialization routine to set up error buffers.
Definition: err486.c:34
int first_error
Definition: err486.c:28
Num_Channels_In
Number of input audio channels.
Definition: init486.h:144
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
enum Num_Channels_Out Output_Configuration
Definition: init486.c:87
int errorbuf[ERRORBUFLEN]
Circular buffer to store the most recent error codes.
Definition: err486.c:27
Error Handling for ECE 486 STM32L476G-Discovery Interface.
STM32L476-Discovery configuration routines to support ECE 486.
#define ERROR_LED
Red LED, STM32L476G-Discovery.
Definition: init486.h:39
#define ERRORBUFLEN
Number of errors to record in a circular buffer.
Definition: err486.h:51
enum Num_Channels_In Input_Configuration
Definition: init486.c:88
Num_Channels_Out
Number of output audio channels.
Definition: init486.h:153
static void print_error(int index)
Definition: err486.c:70