rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
sent_hw_icu.cpp File Reference

Functions

static void icuperiodcb (ICUDriver *icup, size_t index)
 
static void icuovercapture (ICUDriver *icup, size_t index)
 
static void icuperiodcb_in1 (ICUDriver *icup)
 
static void icuovercapture_in1 (ICUDriver *icup)
 
void startSent ()
 
void stopSent ()
 

Variables

static uint16_t lastPulse [SENT_INPUT_COUNT]
 
static bool overcapture [SENT_INPUT_COUNT]
 
static ICUConfig icucfg [SENT_INPUT_COUNT]
 

Function Documentation

◆ icuovercapture()

static void icuovercapture ( ICUDriver *  icup,
size_t  index 
)
static

Definition at line 62 of file sent_hw_icu.cpp.

63{
64 UNUSED(icup);
65 overcapture[index] = true;
66}
UNUSED(samplingTimeSeconds)
static bool overcapture[SENT_INPUT_COUNT]

Referenced by icuovercapture_in1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ icuovercapture_in1()

static void icuovercapture_in1 ( ICUDriver *  icup)
static

Definition at line 74 of file sent_hw_icu.cpp.

75{
76 icuovercapture(icup, 0);
77}
static void icuovercapture(ICUDriver *icup, size_t index)
Here is the call graph for this function:

◆ icuperiodcb()

static void icuperiodcb ( ICUDriver *  icup,
size_t  index 
)
static

Definition at line 34 of file sent_hw_icu.cpp.

35{
36 uint16_t clocks;
37 uint8_t flags = 0;
38 const ICUConfig *icucfg = icup->config;
39
40 if ((icucfg->channel == ICU_CHANNEL_1) || (icucfg->channel == ICU_CHANNEL_2)) {
41 /* channel 1 and channel 2 supports period measurements */
42 clocks = icuGetPeriodX(icup);
43 } else {
44 /* this is freerunnig timer and we need to calculate period using just captured timer value and previous one */
45 /* TODO: support 32 bit timers too? */
46 uint16_t val = icuGetWidthX(icup);
47
48 /* can overflow */
49 clocks = val - lastPulse[index];
50
51 lastPulse[index] = val;
52 }
53
54 if (overcapture[index]) {
55 flags |= SENT_FLAG_HW_OVERFLOW;
56 overcapture[index] = false;
57 }
58
59 SENT_ISR_Handler(index, clocks, flags);
60}
void SENT_ISR_Handler(uint8_t channel, uint16_t clocks, uint8_t flags)
Definition sent.cpp:73
static ICUConfig icucfg[SENT_INPUT_COUNT]
static uint16_t lastPulse[SENT_INPUT_COUNT]

Referenced by icuperiodcb_in1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ icuperiodcb_in1()

static void icuperiodcb_in1 ( ICUDriver *  icup)
static

Definition at line 69 of file sent_hw_icu.cpp.

70{
71 icuperiodcb(icup, 0);
72}
static void icuperiodcb(ICUDriver *icup, size_t index)
Here is the call graph for this function:

◆ startSent()

void startSent ( )

Definition at line 95 of file sent_hw_icu.cpp.

95 {
96 for (int i = 0; i < SENT_INPUT_COUNT; i++) {
98
99 if (!isBrainPinValid(sentPin)) {
100 continue;
101 }
102
103 ICUConfig *cfg = &icucfg[i];
104 ICUDriver *icu;
105 iomode_t pinAF;
106 uint32_t baseClock;
107
108 if (getIcuParams(sentPin, &pinAF, &icu, &cfg->channel, &baseClock) != true) {
109 /* this pin has no ICU functionality or ICU driver is not enabled for TIM on this pin */
110 criticalError("No ICU on selected SENT pin");
111 continue;
112 }
113
114 efiSetPadMode("SENT", sentPin, PAL_MODE_ALTERNATE(pinAF));
115
116 icuStart(icu, cfg);
117 icuStartCapture(icu);
118 icuEnableNotifications(icu);
119 }
120}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
static constexpr engine_configuration_s * engineConfiguration
uint32_t iomode_t
Digital I/O modes.
Definition hal_pal_lld.h:83
bool getIcuParams(brain_pin_e hwPin, iomode_t *af_ptr, ICUDriver **icu_ptr, icuchannel_t *channel_ptr, uint32_t *clock_ptr)
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by applyNewHardwareSettings(), and initSent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopSent()

void stopSent ( )

Definition at line 122 of file sent_hw_icu.cpp.

122 {
123 for (int i = 0; i < SENT_INPUT_COUNT; i++) {
125
126 if (!isBrainPinValid(sentPin)) {
127 continue;
128 }
129
130 ICUDriver *icu;
131
132 if (getIcuParams(sentPin, NULL, &icu, NULL, NULL) != true) {
133 /* this pin has no ICU functionality or ICU driver is not enabled for TIM on this pin */
134 /* throw error? */
135 continue;
136 }
137
138 icuDisableNotifications(icu);
139 icuStopCapture(icu);
140 icuStop(icu);
141
142 efiSetPadUnused(sentPin);
143 }
144}
engine_configuration_s & activeConfiguration
void efiSetPadUnused(brain_pin_e brainPin)
Definition io_pins.cpp:20

Referenced by applyNewHardwareSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ icucfg

ICUConfig icucfg[SENT_INPUT_COUNT]
static
Initial value:
=
{
{
.mode = ICU_INPUT_ACTIVE_LOW,
.frequency = SENT_ICU_FREQ,
.width_cb = NULL,
.period_cb = icuperiodcb_in1,
.overflow_cb = NULL,
.channel = ICU_CHANNEL_1,
.dier = 0U,
.arr = 0xFFFFFFFFU,
.overcapture_cb = icuovercapture_in1,
}
}
static void icuovercapture_in1(ICUDriver *icup)
static void icuperiodcb_in1(ICUDriver *icup)

Definition at line 80 of file sent_hw_icu.cpp.

81{
82 {
83 .mode = ICU_INPUT_ACTIVE_LOW,
84 .frequency = SENT_ICU_FREQ,
85 .width_cb = NULL,
86 .period_cb = icuperiodcb_in1,
87 .overflow_cb = NULL,
88 .channel = ICU_CHANNEL_1, /* will be overwriten on startSent() */
89 .dier = 0U,
90 .arr = 0xFFFFFFFFU,
91 .overcapture_cb = icuovercapture_in1,
92 }
93};

Referenced by icuperiodcb(), and startSent().

◆ lastPulse

uint16_t lastPulse[SENT_INPUT_COUNT]
static

Definition at line 31 of file sent_hw_icu.cpp.

Referenced by icuperiodcb().

◆ overcapture

bool overcapture[SENT_INPUT_COUNT]
static

Definition at line 32 of file sent_hw_icu.cpp.

Referenced by icuovercapture(), and icuperiodcb().

Go to the source code of this file.