2022-09-10 21:40:24 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-09-10 21:40:24 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Powered by XM6 TypeG Technology.
|
|
|
|
// Copyright (C) 2016-2020 GIMONS
|
|
|
|
// Copyright (C) 2022 akuker
|
|
|
|
//
|
|
|
|
// [ High resolution timer ]
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "hal/systimer.h"
|
2022-12-03 04:20:27 +00:00
|
|
|
#include "hal/systimer_allwinner.h"
|
|
|
|
#include "hal/systimer_raspberry.h"
|
2022-11-09 07:40:26 +00:00
|
|
|
#include <sys/mman.h>
|
2022-09-10 21:40:24 +00:00
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
#include "hal/gpiobus.h"
|
|
|
|
#include "hal/sbc_version.h"
|
2022-11-09 07:40:26 +00:00
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
#include "shared/log.h"
|
2022-11-09 07:40:26 +00:00
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
bool SysTimer::initialized = false;
|
|
|
|
bool SysTimer::is_allwinnner = false;
|
|
|
|
bool SysTimer::is_raspberry = false;
|
2022-11-09 07:40:26 +00:00
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
std::unique_ptr<PlatformSpecificTimer> SysTimer::systimer_ptr;
|
2022-11-09 07:40:26 +00:00
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
void SysTimer::Init()
|
|
|
|
{
|
|
|
|
LOGTRACE("%s", __PRETTY_FUNCTION__)
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
if (SBC_Version::IsRaspberryPi()) {
|
|
|
|
systimer_ptr = make_unique<SysTimer_Raspberry>();
|
|
|
|
is_raspberry = true;
|
|
|
|
} else if (SBC_Version::IsBananaPi()) {
|
|
|
|
systimer_ptr = make_unique<SysTimer_AllWinner>();
|
|
|
|
is_allwinnner = true;
|
|
|
|
}
|
|
|
|
systimer_ptr->Init();
|
|
|
|
initialized = true;
|
|
|
|
}
|
2022-09-10 21:40:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
// Get system timer low byte
|
|
|
|
uint32_t SysTimer::GetTimerLow()
|
|
|
|
{
|
|
|
|
return systimer_ptr->GetTimerLow();
|
2022-09-10 21:40:24 +00:00
|
|
|
}
|
2022-12-03 04:20:27 +00:00
|
|
|
// Get system timer high byte
|
|
|
|
uint32_t SysTimer::GetTimerHigh()
|
|
|
|
{
|
|
|
|
return systimer_ptr->GetTimerHigh();
|
2022-09-10 21:40:24 +00:00
|
|
|
}
|
2022-12-03 04:20:27 +00:00
|
|
|
// Sleep for N nanoseconds
|
2022-10-25 00:21:40 +00:00
|
|
|
void SysTimer::SleepNsec(uint32_t nsec)
|
2022-09-10 21:40:24 +00:00
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
systimer_ptr->SleepNsec(nsec);
|
2022-09-10 21:40:24 +00:00
|
|
|
}
|
2022-12-03 04:20:27 +00:00
|
|
|
// Sleep for N microseconds
|
2022-10-25 00:21:40 +00:00
|
|
|
void SysTimer::SleepUsec(uint32_t usec)
|
2022-09-10 21:40:24 +00:00
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
systimer_ptr->SleepUsec(usec);
|
2022-09-10 21:40:24 +00:00
|
|
|
}
|