still debugging

This commit is contained in:
2020-11-05 22:14:08 +01:00
parent 264664763b
commit 5e6093377f
7 changed files with 45 additions and 40 deletions

View File

@ -67,39 +67,44 @@ inline static void __EEPROM_CS(GPIO_PinState v) {
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, v);
}
static uint16_t swap(uint16_t i) {
return ((i & 0x00ff) << 8) | ((i & 0xff00) >> 8);
}
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) {
t_spiMsg msg = {
.s.cmd = EEPROM_WRITE,
.s.addr = addr
.s.addr = swap(addr)
};
memcpy(msg.s.data, buf, len);
coloredMsg(LOG_HIGH, "w: %02x %02x %02x", msg.b[0], msg.b[1], msg.b[2]);
coloredMsg(LOG_HIGH, "b: %02x %02x %02x %02x %02x %02x %02x %02x", msg.s.data[0], msg.s.data[1], msg.s.data[2], msg.s.data[3], msg.s.data[4], msg.s.data[5], msg.s.data[6], msg.s.data[7]);
uint8_t writeEnable = EEPROM_WREN;
coloredMsg(LOG_HIGH, "1");
__EEPROM_CS(LOW);
HAL_SPI_Transmit(&eepromSpi, &writeEnable, 1, HAL_MAX_DELAY);
__EEPROM_CS(HIGH);
coloredMsg(LOG_HIGH, "2");
__EEPROM_CS(LOW);
HAL_SPI_Transmit(&eepromSpi, msg.b, ((uint16_t)(len+3)), HAL_MAX_DELAY);
__EEPROM_CS(HIGH);
coloredMsg(LOG_HIGH, "3");
}
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) {
t_spiMsg txMsg = {
.s.cmd = EEPROM_READ,
.s.addr = addr
.s.addr = swap(addr)
};
coloredMsg(LOG_HIGH, "r: %02x %02x %02x", txMsg.b[0], txMsg.b[1], txMsg.b[2]);
t_spiMsg rxMsg;
coloredMsg(LOG_YELLOW, "len: %d", len);
__EEPROM_CS(LOW);
HAL_SPI_TransmitReceive(&eepromSpi, txMsg.b, rxMsg.b, ((uint16_t)(len+3)), HAL_MAX_DELAY);
__EEPROM_CS(HIGH);
coloredMsg(LOG_HIGH, "b: %02x %02x %02x %02x %02x %02x %02x %02x", rxMsg.s.data[0], rxMsg.s.data[1], rxMsg.s.data[2], rxMsg.s.data[3], rxMsg.s.data[4], rxMsg.s.data[5], rxMsg.s.data[6], rxMsg.s.data[7]);
memcpy(buf, rxMsg.s.data, len);
}
@ -115,7 +120,7 @@ static void eepromHourlyUpdateDeviceStats(void *handle) {
}
void eepromInit() {
logMsg("eeI, read header, %d, %d", sizeof(eepromHeader), sizeof(eepromHeader.b));
logMsg("eeI, read header");
eepromRead(EEPROM_HEADER_ADDR, eepromHeader.b, sizeof(eepromHeader));
coloredMsg(LOG_RED, "eeI, magic: %08x", eepromHeader.s.magic);
@ -162,6 +167,6 @@ void eepromInit() {
coloredMsg(LOG_GREEN, "eeI, about to write device stats with updated power cycles counter");
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
schAdd(eepromHourlyUpdateDeviceStats, NULL, 0, 60 * 1000);
coloredMsg(LOG_GREEN, "eeI, hourly device stats update scheduled");
// schAdd(eepromHourlyUpdateDeviceStats, NULL, 0, 10 * 1000);
// coloredMsg(LOG_GREEN, "eeI, hourly device stats update scheduled");
}

View File

@ -186,11 +186,11 @@ void my_setup_2() {
eepromInit();
frontendInit();
frontendSetThreshold(240);
// frontendInit();
// frontendSetThreshold(240);
schAdd(scheduleMBusRequest, NULL, 0, 1000);
schAdd(triggerMBusRequest, NULL, 0, 100);
// schAdd(scheduleMBusRequest, NULL, 0, 1000);
// schAdd(triggerMBusRequest, NULL, 0, 100);
}
void my_loop() {