rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
hw_layer
microsecond_timer
microsecond_timer_gpt.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
port_microsecond_timer.h
"
3
4
#if EFI_PROD_CODE && HAL_USE_GPT
5
6
void
portSetHardwareSchedulerTimer
(efitick_t nowNt, efitick_t setTimeNt) {
7
int32_t deltaTimeUs = NT2US((int32_t)setTimeNt - (int32_t)nowNt);
8
9
// If already set, reset the timer
10
if
(GPTDEVICE.state == GPT_ONESHOT) {
11
gptStopTimerI(&GPTDEVICE);
12
}
13
14
if
(GPTDEVICE.state != GPT_READY) {
15
firmwareError
(
ObdCode::CUSTOM_HW_TIMER
,
"HW timer state %d"
, GPTDEVICE.state);
16
return
;
17
}
18
19
// Start the timer
20
gptStartOneShotI(&GPTDEVICE, deltaTimeUs);
21
}
22
23
static
void
hwTimerCallback
(
GPTDriver
*) {
24
portMicrosecondTimerCallback
();
25
}
26
27
/*
28
* The specific 1MHz frequency is important here since 'setHardwareUsTimer' method takes microsecond parameter
29
* For any arbitrary frequency to work we would need an additional layer of conversion.
30
*/
31
static
constexpr
GPTConfig
gpt5cfg
= { 1000000,
/* 1 MHz timer clock.*/
32
hwTimerCallback
,
/* Timer callback.*/
33
0, 0 };
34
35
void
portInitMicrosecondTimer
() {
36
gptStart(&GPTDEVICE, &
gpt5cfg
);
37
efiAssertVoid(
ObdCode::CUSTOM_ERR_TIMER_STATE
, GPTDEVICE.state == GPT_READY,
"hw state"
);
38
}
39
40
#endif
// EFI_PROD_CODE
41
42
// This implementation just uses the generic port counter - this usually returns a count of CPU cycles since start
43
uint32_t
getTimeNowLowerNt
() {
44
return
port_rt_get_counter_value();
45
}
firmwareError
void firmwareError(ObdCode code, const char *fmt,...)
Definition
error_handling.cpp:670
portMicrosecondTimerCallback
void portMicrosecondTimerCallback()
Definition
microsecond_timer.cpp:98
getTimeNowLowerNt
uint32_t getTimeNowLowerNt()
Definition
microsecond_timer_gpt.cpp:43
portSetHardwareSchedulerTimer
void portSetHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt)
Definition
microsecond_timer_gpt.cpp:6
hwTimerCallback
static void hwTimerCallback(GPTDriver *)
Definition
microsecond_timer_gpt.cpp:23
portInitMicrosecondTimer
void portInitMicrosecondTimer()
Definition
microsecond_timer_gpt.cpp:35
gpt5cfg
static constexpr GPTConfig gpt5cfg
Definition
microsecond_timer_gpt.cpp:31
ObdCode::CUSTOM_HW_TIMER
@ CUSTOM_HW_TIMER
ObdCode::CUSTOM_ERR_TIMER_STATE
@ CUSTOM_ERR_TIMER_STATE
pch.h
port_microsecond_timer.h
GPTConfig
Driver configuration structure.
Definition
hal_gpt_lld.h:207
GPTDriver
Structure representing a GPT driver.
Definition
hal_gpt_lld.h:239
Generated on Sat Sep 27 2025 00:10:06 for rusEFI by
1.9.8