From 190ecea8559521eaa373287abd42f13a71a6e0d9 Mon Sep 17 00:00:00 2001 From: Leon Krieg Date: Fri, 20 Sep 2024 18:03:34 +0200 Subject: [PATCH] Dump EEPROM to ensure low level memory access is working correctly --- src/common.h | 1 + src/common/common.c | 38 +++++++++++++++++++++++++++++++++----- src/common/memory.c | 18 ++++++++++++++++++ src/common/memory.h | 5 +++-- src/main.c | 4 ++-- 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/common.h b/src/common.h index d075862..18412db 100644 --- a/src/common.h +++ b/src/common.h @@ -17,6 +17,7 @@ void Info(const char *fmt, ...); void Error(const char *fmt, ...); +void Print(const char *fmt, ...); #include #define Sleep(ms) _delay_ms(ms) diff --git a/src/common/common.c b/src/common/common.c index 9107a60..cafc163 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -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, ...) { va_list ap; - char msg[256]; 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); - Puts("[CORE] "); - Puts(msg); - Puts("\r\n"); + // XXX: Force reset? } diff --git a/src/common/memory.c b/src/common/memory.c index 1c3113f..0f38a3d 100644 --- a/src/common/memory.c +++ b/src/common/memory.c @@ -21,6 +21,15 @@ int MEM_Write(mem_data_t *in) 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) { // The EEMWE bit determines whether setting EEWE to @@ -52,6 +61,15 @@ static int WriteRaw(word addr, byte data) // No interrupts during EEPROM write 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; EEDR = data; diff --git a/src/common/memory.h b/src/common/memory.h index a06151b..6eed367 100644 --- a/src/common/memory.h +++ b/src/common/memory.h @@ -8,7 +8,8 @@ struct mem_data_s { word value[2]; // Values to be written }; -int MEM_Read(mem_data_t *out); -int MEM_Write(mem_data_t *in); +int MEM_Read(mem_data_t *out); +int MEM_Write(mem_data_t *in); +void MEM_Dump(void); #endif // MAD_CORE_COMMON_MEMORY_H diff --git a/src/main.c b/src/main.c index 7e0f655..b753c70 100644 --- a/src/main.c +++ b/src/main.c @@ -75,7 +75,7 @@ static int Init(void) PWM_Init(); MOS_Enable(MOS03); // Lights - MOS_Enable(MOS01); // Peltier + //MOS_Enable(MOS01); // Peltier // MOS_Disable(MOS02); // Heating // 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 // 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(FAN03, 20); // Fan Heating