ArduinoMega2560_SPI 1.0
Cargando...
Buscando...
Nada coincide
diagnosticsEEPROM.cpp
Ir a la documentación de este archivo.
2
3/**
4 * @brief Ejecuta un test de diagnóstico sobre la EEPROM en la dirección indicada.
5 *
6 * El procedimiento realiza:
7 * - Escritura de un valor de prueba en la EEPROM.
8 * - Lectura del valor almacenado.
9 * - Comparación entre valor escrito y leído.
10 * - Informe del estado de memoria libre y usada.
11 * - Limpieza de la dirección probada.
12 *
13 * @param address Dirección de EEPROM a probar (por defecto 0).
14 * @return true si la EEPROM responde correctamente, false en caso contrario.
15 */
16bool DiagnosticsEEPROM::runTest(int address) {
17 standardMessage("🧪 Starting EEPROM diagnostic", __FILE__, __FUNCTION__, __DATE__, __TIME__);
18
19 // Write test value
20 EEPROM.write(address, testValue);
21 delay(10);
22
23 // Read stored value
24 byte readValue = EEPROM.read(address);
25 Serial.print("📥 Value read from EEPROM[");
26 Serial.print(address);
27 Serial.print("]: ");
28 Serial.println(readValue);
29
30 // Show memory status
31 int freeMem = getFreeMemory();
32 Serial.print("📊 Estimated free memory: ");
33 Serial.print(freeMem);
34 Serial.println(" bytes");
35
36 Serial.print("📦 Estimated used memory: ");
37 Serial.print(RAMEND - freeMem);
38 Serial.println(" bytes");
39
40 // Check if value matches
41 if (readValue == testValue) {
42 Serial.println("✅ EEPROM is responding correctly.");
43 clearEEPROM(address);
44 standardHeaderFull("EEPROM diagnostic completed", __FILE__, __FUNCTION__, __DATE__, __TIME__);
45 return true;
46 } else {
47 Serial.println("❌ EEPROM error: value mismatch.");
48 clearEEPROM(address);
49 standardHeaderFull("EEPROM diagnostic failed", __FILE__, __FUNCTION__, __DATE__, __TIME__);
50 return false;
51 }
52}
53
54
55/**
56 * @brief Limpia la EEPROM en la dirección indicada escribiendo 0xFF.
57 *
58 * Tras limpiar, lee nuevamente el valor para verificar la operación.
59 *
60 * @param address Dirección de EEPROM a limpiar.
61 */
63 EEPROM.write(address, 0xFF);
64 delay(10);
65
66 byte clearedValue = EEPROM.read(address);
67 Serial.print("🧹 EEPROM cleared. New value at [");
68 Serial.print(address);
69 Serial.print("]: ");
70 Serial.println(clearedValue);
71}
72
73
74/**
75 * @brief Estima la cantidad de memoria RAM libre disponible en el sistema.
76 *
77 * Este método funciona en placas basadas en AVR como Arduino Mega 2560.
78 * Calcula la memoria libre comparando la posición actual de la pila con el heap.
79 *
80 * @return Número de bytes libres en RAM.
81 */
83 extern unsigned int __heap_start;
84 extern void *__brkval;
85 int freeMemory;
86
87 if ((int)__brkval == 0) {
88 freeMemory = ((int)&freeMemory) - ((int)&__heap_start);
89 } else {
90 freeMemory = ((int)&freeMemory) - ((int)__brkval);
91 }
92
93 return freeMemory;
94}
static int getFreeMemory()
Estimates the amount of free RAM available on the system. Works on AVR-based boards like Arduino Mega...
static const byte testValue
Value used for EEPROM testing.
static void clearEEPROM(int address)
Clears the EEPROM at the specified address by writing 0xFF.
static bool runTest(int address=0)
Runs a diagnostic test on the EEPROM at the specified address. Writes a test value,...
void standardMessage(const char *message, const char *file, const char *function, const char *date, const char *time)
Prints an enriched log message to the serial monitor.
Definition msg.cpp:15
void standardHeaderFull(const char *message, const char *file, const char *function, const char *date, const char *time, uint16_t width=120, char deco='-')
Prints a decorated header with centered text and padding on both sides.
Definition msg.cpp:121