diff --git a/src/log.c b/src/log.c index 32a124a..5b2fc85 100644 --- a/src/log.c +++ b/src/log.c @@ -5,7 +5,7 @@ #include "time.h" static uint16_t number; -static uint16_t i = 0; +static int i = 0; static uint32_t MY_SectorAddrs; static uint8_t MY_SectorNum; @@ -15,8 +15,8 @@ int log_unix_timestamp(RTC_TimeTypeDef *gTime, RTC_DateTypeDef *gDate) { int t_of_day; t.tm_year = (int)gDate->Year + 2000 - 1900; // Year - 1900 - t.tm_mon = (int)gDate->Month - 1; // Month, where 0 = jan - t.tm_mday = (int)gDate->Date; // Day of the month + t.tm_mon = (int)gDate->Month - 1; // Month, where 0 = jan + t.tm_mday = (int)gDate->Date; // Day of the month t.tm_hour = (int)gTime->Hours + (gTime->TimeFormat == RTC_HOURFORMAT12_PM ? 12 : 0); t.tm_min = (int)gTime->Minutes; t.tm_sec = (int)gTime->Seconds; @@ -43,7 +43,7 @@ void log_rtc_setup(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *gTime, RTC_DateType HAL_RTC_SetDate(hrtc, gDate, RTC_FORMAT_BIN); } -void log_set_start_number(uint16_t this_number){ +void log_set_start_number(uint16_t this_number) { number = this_number; } @@ -51,43 +51,49 @@ int log_update_number(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *gTime, RTC_DateT int timestamp; number = this_number; - HAL_RTC_GetTime(hrtc, gTime, RTC_FORMAT_BIN); + HAL_RTC_GetTime(hrtc, gTime, RTC_FORMAT_BIN); HAL_RTC_GetDate(hrtc, gDate, RTC_FORMAT_BIN); - timestamp = log_unix_timestamp(gTime, gDate); + + if (i > 131066) { + i = 0; + } else { + hcomm->SrcMemory.size = hcomm->SrcMemory.size + 6; + } + + timestamp = log_unix_timestamp(gTime, gDate); flashWrite(i, ×tamp, 1, DATA_TYPE_32); flashWrite(i + 4, &this_number, 1, DATA_TYPE_16); - hcomm->SrcMemory.size = hcomm->SrcMemory.size + 6; i = i + 6; return timestamp; } -//functions definitions -//1. Erase Sector +// functions definitions +// 1. Erase Sector void flashEraseSector(uint8_t sector_num) { HAL_FLASH_Unlock(); - //Erase the required Flash sector + // Erase the required Flash sector FLASH_Erase_Sector(sector_num, FLASH_VOLTAGE_RANGE_3); HAL_FLASH_Lock(); } -//2. Set Sector Adress +// 2. Set Sector Adress void flashSetSectorAddrs(uint8_t sector, uint32_t addrs) { MY_SectorNum = sector; MY_SectorAddrs = addrs; } -//3. Write Flash +// 3. Write Flash void flashWrite(uint32_t idx, void *wrBuf, uint32_t Nsize, DataTypeDef dataType) { uint32_t flashAddress = MY_SectorAddrs + idx; - //Erase sector before write - // flashEraseSector(MY_SectorAddr); + // Erase sector before write + // flashEraseSector(MY_SectorAddr); - //Unlock Flash + // Unlock Flash HAL_FLASH_Unlock(); - //Write to Flash + // Write to Flash switch (dataType) { case DATA_TYPE_8: for (uint32_t i = 0; i < Nsize; i++) { @@ -110,10 +116,10 @@ void flashWrite(uint32_t idx, void *wrBuf, uint32_t Nsize, DataTypeDef dataType) } break; } - //Lock the Flash space + // Lock the Flash space HAL_FLASH_Lock(); } -//4. Read Flash +// 4. Read Flash void flashRead(uint32_t idx, void *rdBuf, uint32_t Nsize, DataTypeDef dataType) { uint32_t flashAddress = MY_SectorAddrs + idx;