Skip to content

Commit

Permalink
Consolidate logging (#101)
Browse files Browse the repository at this point in the history
Consolidate logging functions, removed fellowAddLog() variants
Move rtc implementation to core project
  • Loading branch information
petschau authored Oct 14, 2023
1 parent a5fc7cd commit cd42b4c
Show file tree
Hide file tree
Showing 52 changed files with 6,160 additions and 6,120 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,86 +1,90 @@
#pragma once

#include "DEFS.H"

class RtcOkiMsm6242rs;
typedef uint16_t (RtcOkiMsm6242rs::*RtcOkiMsm6242rsRegisterGetter)();
typedef void (RtcOkiMsm6242rs::*RtcOkiMsm6242rsRegisterSetter)(uint16_t data);

class RtcOkiMsm6242rs
{
private:
RtcOkiMsm6242rsRegisterGetter _registerGetters[16];
RtcOkiMsm6242rsRegisterSetter _registerSetters[16];
time_t _rtcLastActualTime; // Timestamp for when _rtcTime was set. Used to calculate time passed since then.
time_t _rtcTime; // The RTC value as set by programs.
int _rtcWeekdayModifier; // The weekday difference set by a program.

uint16_t _irqFlag;
uint16_t _holdFlag;
uint16_t _thirtySecAdjFlag;
uint16_t _busyFlag;
uint16_t _maskFlag;
uint16_t _itrptStdFlag;
uint16_t _t0Flag;
uint16_t _t1Flag;
uint16_t _restFlag;
uint16_t _stopFlag;
uint16_t _twentyFourTwelveFlag;
uint16_t _testFlag;

struct tm* GetCurrentOrHeldTime();
void SetCurrentTime(struct tm *datetime);

int GetRegisterNumberFromAddress(uint32_t address);

uint16_t GetFirstDigit(int value);
void SetFirstDigit(struct tm& datetime, int& value, uint16_t data);
void ReplaceFirstDigit(int& value, int new_digit);

uint16_t GetSecondDigit(int value);
void SetSecondDigit(struct tm& datetime, int& value, uint16_t data);
void ReplaceSecondDigit(int& value, int new_digit);
void ReplaceSecondDigitAllowBCDOverflow(int& value, int new_digit);

uint16_t GetSecondRegister();
void SetSecondRegister(uint16_t data);
uint16_t GetTenSecondRegister();
void SetTenSecondRegister(uint16_t data);
uint16_t GetMinuteRegister();
void SetMinuteRegister(uint16_t data);
uint16_t GetTenMinuteRegister();
void SetTenMinuteRegister(uint16_t data);
uint16_t GetHourRegister();
void SetHourRegister(uint16_t data);
uint16_t GetTenHourRegister();
void SetTenHourRegister(uint16_t data);
uint16_t GetDayRegister();
void SetDayRegister(uint16_t data);
uint16_t GetTenDayRegister();
void SetTenDayRegister(uint16_t data);
uint16_t GetMonthRegister();
void SetMonthRegister(uint16_t data);
uint16_t GetTenMonthRegister();
void SetTenMonthRegister(uint16_t data);
uint16_t GetYearRegister();
void SetYearRegister(uint16_t data);
uint16_t GetTenYearRegister();
void SetTenYearRegister(uint16_t data);
uint16_t GetWeekRegister();
void SetWeekRegister(uint16_t data);
uint16_t GetControlRegisterD();
void SetControlRegisterD(uint16_t data);
uint16_t GetControlRegisterE();
void SetControlRegisterE(uint16_t data);
uint16_t GetControlRegisterF();
void SetControlRegisterF(uint16_t data);

void InitializeRegisterGetters();
void InitializeRegisterSetters();

public:
uint16_t read(uint32_t address);
void write(uint16_t data, uint32_t address);
void logRtcTime(char *msg);
RtcOkiMsm6242rs();
};
#pragma once

#include <cstdint>
#include <ctime>
#include "Service/ILog.h"

class RtcOkiMsm6242rs;
typedef uint16_t (RtcOkiMsm6242rs::*RtcOkiMsm6242rsRegisterGetter)();
typedef void (RtcOkiMsm6242rs::*RtcOkiMsm6242rsRegisterSetter)(uint16_t data);

class RtcOkiMsm6242rs
{
private:
Service::ILog* _log;

RtcOkiMsm6242rsRegisterGetter _registerGetters[16];
RtcOkiMsm6242rsRegisterSetter _registerSetters[16];
time_t _rtcLastActualTime; // Timestamp for when _rtcTime was set. Used to calculate time passed since then.
time_t _rtcTime; // The RTC value as set by programs.
int _rtcWeekdayModifier; // The weekday difference set by a program.

uint16_t _irqFlag;
uint16_t _holdFlag;
uint16_t _thirtySecAdjFlag;
uint16_t _busyFlag;
uint16_t _maskFlag;
uint16_t _itrptStdFlag;
uint16_t _t0Flag;
uint16_t _t1Flag;
uint16_t _restFlag;
uint16_t _stopFlag;
uint16_t _twentyFourTwelveFlag;
uint16_t _testFlag;

struct tm* GetCurrentOrHeldTime();
void SetCurrentTime(struct tm *datetime);

int GetRegisterNumberFromAddress(uint32_t address);

uint16_t GetFirstDigit(int value);
void SetFirstDigit(struct tm& datetime, int& value, uint16_t data);
void ReplaceFirstDigit(int& value, int new_digit);

uint16_t GetSecondDigit(int value);
void SetSecondDigit(struct tm& datetime, int& value, uint16_t data);
void ReplaceSecondDigit(int& value, int new_digit);
void ReplaceSecondDigitAllowBCDOverflow(int& value, int new_digit);

uint16_t GetSecondRegister();
void SetSecondRegister(uint16_t data);
uint16_t GetTenSecondRegister();
void SetTenSecondRegister(uint16_t data);
uint16_t GetMinuteRegister();
void SetMinuteRegister(uint16_t data);
uint16_t GetTenMinuteRegister();
void SetTenMinuteRegister(uint16_t data);
uint16_t GetHourRegister();
void SetHourRegister(uint16_t data);
uint16_t GetTenHourRegister();
void SetTenHourRegister(uint16_t data);
uint16_t GetDayRegister();
void SetDayRegister(uint16_t data);
uint16_t GetTenDayRegister();
void SetTenDayRegister(uint16_t data);
uint16_t GetMonthRegister();
void SetMonthRegister(uint16_t data);
uint16_t GetTenMonthRegister();
void SetTenMonthRegister(uint16_t data);
uint16_t GetYearRegister();
void SetYearRegister(uint16_t data);
uint16_t GetTenYearRegister();
void SetTenYearRegister(uint16_t data);
uint16_t GetWeekRegister();
void SetWeekRegister(uint16_t data);
uint16_t GetControlRegisterD();
void SetControlRegisterD(uint16_t data);
uint16_t GetControlRegisterE();
void SetControlRegisterE(uint16_t data);
uint16_t GetControlRegisterF();
void SetControlRegisterF(uint16_t data);

void InitializeRegisterGetters();
void InitializeRegisterSetters();

public:
uint16_t read(uint32_t address);
void write(uint16_t data, uint32_t address);
void logRtcTime(char *msg);
RtcOkiMsm6242rs(Service::ILog* log);
};
1 change: 1 addition & 0 deletions fellow/SRC/WinFellow.Core/Service/ILog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Service
virtual void AddLog(const char*, ...) = 0;
virtual void AddLogList(const std::list<std::string>& messages) = 0;
virtual void AddLog2(char* msg) = 0;
virtual void AddTimelessLog(const char* format, ...) = 0;

ILog() = default;
virtual ~ILog() = default;
Expand Down
12 changes: 12 additions & 0 deletions fellow/SRC/WinFellow.Core/Service/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ namespace Service
}
}

void Log::AddTimelessLog(const char* format, ...)
{
char buffer[WRITE_LOG_BUF_SIZE];
va_list parms;

va_start(parms, format);
_vsnprintf(buffer, WRITE_LOG_BUF_SIZE - 1, format, parms);
va_end(parms);

AddLog2(buffer);
}

void Log::AddLogInternal(FILE* F, char* msg)
{
fprintf(F, "%s", msg);
Expand Down
9 changes: 5 additions & 4 deletions fellow/SRC/WinFellow.Core/Service/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace Service
void AddLogInternal(FILE* F, char* msg);

public:
void AddLogDebug(const char* format, ...);
void AddLog(const char*, ...);
void AddLogList(const std::list<std::string>& messages);
void AddLog2(char* msg);
void AddLogDebug(const char* format, ...) override;
void AddLog(const char*, ...) override;
void AddLogList(const std::list<std::string>& messages) override;
void AddLog2(char* msg) override;
void AddTimelessLog(const char* format, ...) override;

Log();
virtual ~Log();
Expand Down
10 changes: 9 additions & 1 deletion fellow/SRC/WinFellow.Core/VirtualHost/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
// For the time being this has to be a singleton
Core _core = Core();

Core::Core() : Registers(), RegisterUtility(Registers), Sound(nullptr), Uart(nullptr), Drivers(), Log(nullptr), Fileops(nullptr)
Core::Core() :
Registers(),
RegisterUtility(Registers),
Sound(nullptr),
Uart(nullptr),
RtcOkiMsm6242rs(nullptr),
Drivers(),
Log(nullptr),
Fileops(nullptr)
{
}

Expand Down
2 changes: 2 additions & 0 deletions fellow/SRC/WinFellow.Core/VirtualHost/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "CustomChipset/Registers.h"
#include "CustomChipset/RegisterUtility.h"
#include "IO/Uart.h"
#include "IO/RtcOkiMsm6242rs.h"

class Core
{
Expand All @@ -15,6 +16,7 @@ class Core
CustomChipset::RegisterUtility RegisterUtility;
Sound* Sound;
Uart* Uart;
RtcOkiMsm6242rs* RtcOkiMsm6242rs;

Drivers Drivers;
Service::ILog* Log;
Expand Down
2 changes: 2 additions & 0 deletions fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<ClInclude Include="Driver\Drivers.h" />
<ClInclude Include="Driver\ISoundDriver.h" />
<ClInclude Include="Driver\SoundDriverRuntimeConfiguration.h" />
<ClInclude Include="IO\RtcOkiMsm6242rs.h" />
<ClInclude Include="IO\Uart.h" />
<ClInclude Include="NullDriver\Sound\NullSound.h" />
<ClInclude Include="Service\IFileops.h" />
Expand All @@ -45,6 +46,7 @@
<ItemGroup>
<ClCompile Include="CustomChipset\Registers.cpp" />
<ClCompile Include="CustomChipset\RegisterUtility.cpp" />
<ClCompile Include="IO\RtcOkiMsm6242rs.cpp" />
<ClCompile Include="NullDriver\Sound\NullSound.cpp" />
<ClCompile Include="Service\Log.cpp" />
<ClCompile Include="VirtualHost\Core.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClInclude Include="IO\Uart.h">
<Filter>IO</Filter>
</ClInclude>
<ClInclude Include="IO\RtcOkiMsm6242rs.h">
<Filter>IO</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CustomChipset\Registers.cpp">
Expand All @@ -86,5 +89,8 @@
<ClCompile Include="Service\Log.cpp">
<Filter>Service</Filter>
</ClCompile>
<ClCompile Include="IO\RtcOkiMsm6242rs.cpp">
<Filter>IO</Filter>
</ClCompile>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ namespace mock::Core::Service
{
// Stub
}

void LogMock::AddTimelessLog(const char*, ...)
{
// Stub
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ namespace mock::Core::Service
void AddLog(const char*, ...) override;
void AddLog2(char* msg) override;
void AddLogList(const std::list<std::string>& messages) override;
void AddTimelessLog(const char* format, ...) override;
};
}
Loading

0 comments on commit cd42b4c

Please sign in to comment.