Dump EEPROM to ensure low level memory access is working correctly

This commit is contained in:
2024-09-20 18:03:34 +02:00
parent 29b0ace897
commit 190ecea855
5 changed files with 57 additions and 9 deletions

View File

@@ -17,6 +17,7 @@
void Info(const char *fmt, ...); void Info(const char *fmt, ...);
void Error(const char *fmt, ...); void Error(const char *fmt, ...);
void Print(const char *fmt, ...);
#include <util/delay.h> #include <util/delay.h>
#define Sleep(ms) _delay_ms(ms) #define Sleep(ms) _delay_ms(ms)

View File

@@ -10,16 +10,44 @@ static void Puts(const char *str)
} }
} }
static void PrintArgs(const char *fmt, va_list ap)
{
char msg[256];
vsnprintf(msg, sizeof(msg), fmt, ap);
Puts(msg);
}
void Print(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
PrintArgs(fmt, ap);
va_end(ap);
}
void Info(const char *fmt, ...) void Info(const char *fmt, ...)
{ {
va_list ap; va_list ap;
char msg[256];
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap); Puts("[CORE] ");
PrintArgs(fmt, ap);
Puts("\r\n");
va_end(ap);
}
void Error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Puts("[CORE] Error: ");
PrintArgs(fmt, ap);
Puts("\r\n");
va_end(ap); va_end(ap);
Puts("[CORE] "); // XXX: Force reset?
Puts(msg);
Puts("\r\n");
} }

View File

@@ -21,6 +21,15 @@ int MEM_Write(mem_data_t *in)
return 0; return 0;
} }
void MEM_Dump(void)
{
// byte rom[1024];
// Info("Dumping EEPROM memory:");
// for (int i = 0; i < 1024; i++) {
// rom[i] = ReadRaw(i);
// }
}
static int WriteRaw(word addr, byte data) static int WriteRaw(word addr, byte data)
{ {
// The EEMWE bit determines whether setting EEWE to // The EEMWE bit determines whether setting EEWE to
@@ -52,6 +61,15 @@ static int WriteRaw(word addr, byte data)
// No interrupts during EEPROM write // No interrupts during EEPROM write
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// The EEPROM Address Registers EEARH and
// EEARL specify the EEPROM address in the
// 1024bytes EEPROM space. The EEPROM data
// bytes are addressed linearly between 0
// and 1023. The initial value of EEAR is
// undefined. A proper value must be written
// before the EEPROM may be accessed.
EEAR = addr; EEAR = addr;
EEDR = data; EEDR = data;

View File

@@ -8,7 +8,8 @@ struct mem_data_s {
word value[2]; // Values to be written word value[2]; // Values to be written
}; };
int MEM_Read(mem_data_t *out); int MEM_Read(mem_data_t *out);
int MEM_Write(mem_data_t *in); int MEM_Write(mem_data_t *in);
void MEM_Dump(void);
#endif // MAD_CORE_COMMON_MEMORY_H #endif // MAD_CORE_COMMON_MEMORY_H

View File

@@ -75,7 +75,7 @@ static int Init(void)
PWM_Init(); PWM_Init();
MOS_Enable(MOS03); // Lights MOS_Enable(MOS03); // Lights
MOS_Enable(MOS01); // Peltier //MOS_Enable(MOS01); // Peltier
// MOS_Disable(MOS02); // Heating // MOS_Disable(MOS02); // Heating
// Only FAN01 and FAN02 are receiving the correct // Only FAN01 and FAN02 are receiving the correct
@@ -88,7 +88,7 @@ static int Init(void)
// complicated so it might be worth it to switch to // complicated so it might be worth it to switch to
// something like an ATmega328PB. // something like an ATmega328PB.
PWM_SetValue(FAN01, 20); // Fan Peltier Hot side PWM_SetValue(FAN01, 50); // Fan Peltier Hot side
PWM_SetValue(FAN02, 50); // Fan Peltier Cold Side PWM_SetValue(FAN02, 50); // Fan Peltier Cold Side
// PWM_SetValue(FAN03, 20); // Fan Heating // PWM_SetValue(FAN03, 20); // Fan Heating