Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into wip_main
Browse files Browse the repository at this point in the history
  • Loading branch information
thegabriele97 committed Dec 21, 2021
2 parents d0a5e05 + 82c9e64 commit f6cd688
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -43,51 +43,57 @@ 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;
}

int log_update_number(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *gTime, RTC_DateTypeDef *gDate, uint16_t this_number, struct COMM_Handle *hcomm) {
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, &timestamp, 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++) {
Expand All @@ -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;

Expand Down

0 comments on commit f6cd688

Please sign in to comment.