exti uses a queue (#4027)
* exti uses a queue * TRIGGER_BAIL_IF_SELF_STIM
This commit is contained in:
parent
c602618550
commit
0bf672cd4d
|
@ -28,8 +28,7 @@ struct ExtiChannel
|
||||||
ExtiCallback Callback = nullptr;
|
ExtiCallback Callback = nullptr;
|
||||||
void* CallbackData;
|
void* CallbackData;
|
||||||
|
|
||||||
efitick_t Timestamp = 0;
|
// Name is also used as an enable bit
|
||||||
|
|
||||||
const char* Name = nullptr;
|
const char* Name = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,6 +42,8 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
efiAssertVoid(OBD_PCM_Processor_Fault, msg, "efiExtiEnablePin msg must not be null");
|
||||||
|
|
||||||
ioportid_t port = getHwPort(msg, brainPin);
|
ioportid_t port = getHwPort(msg, brainPin);
|
||||||
if (port == NULL) {
|
if (port == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -68,10 +69,9 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.Name = msg;
|
|
||||||
channel.Callback = cb;
|
channel.Callback = cb;
|
||||||
channel.CallbackData = cb_data;
|
channel.CallbackData = cb_data;
|
||||||
channel.Timestamp = 0;
|
channel.Name = msg;
|
||||||
|
|
||||||
ioline_t line = PAL_LINE(port, index);
|
ioline_t line = PAL_LINE(port, index);
|
||||||
palEnableLineEvent(line, mode);
|
palEnableLineEvent(line, mode);
|
||||||
|
@ -102,7 +102,6 @@ void efiExtiDisablePin(brain_pin_e brainPin)
|
||||||
palDisableLineEvent(line);
|
palDisableLineEvent(line);
|
||||||
|
|
||||||
/* mark unused */
|
/* mark unused */
|
||||||
channel.Timestamp = 0;
|
|
||||||
channel.Name = nullptr;
|
channel.Name = nullptr;
|
||||||
channel.Callback = nullptr;
|
channel.Callback = nullptr;
|
||||||
channel.CallbackData = nullptr;
|
channel.CallbackData = nullptr;
|
||||||
|
@ -123,21 +122,79 @@ static inline void triggerInterrupt() {
|
||||||
NVIC->STIR = I2C1_EV_IRQn;
|
NVIC->STIR = I2C1_EV_IRQn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ExtiQueueEntry {
|
||||||
|
efitick_t Timestamp;
|
||||||
|
uint8_t Channel;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, size_t TSize>
|
||||||
|
class ExtiQueue {
|
||||||
|
public:
|
||||||
|
void push(const T& val) {
|
||||||
|
if ((m_write == m_read - 1) || (m_write == TSize - 1 && m_read == 0)) {
|
||||||
|
// queue full, drop
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
arr[m_write] = val;
|
||||||
|
m_write++;
|
||||||
|
|
||||||
|
// wrap end of list
|
||||||
|
if (m_write == TSize) {
|
||||||
|
m_write = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expected<T> pop() {
|
||||||
|
if (m_read == m_write) {
|
||||||
|
// Queue empty
|
||||||
|
return unexpected;
|
||||||
|
}
|
||||||
|
|
||||||
|
T value = arr[m_read];
|
||||||
|
m_read++;
|
||||||
|
|
||||||
|
// wrap end of list
|
||||||
|
if (m_read == TSize) {
|
||||||
|
m_read = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
T arr[TSize];
|
||||||
|
|
||||||
|
uint8_t m_read = 0;
|
||||||
|
uint8_t m_write = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static ExtiQueue<ExtiQueueEntry, 32> queue;
|
||||||
|
|
||||||
CH_IRQ_HANDLER(STM32_I2C1_EVENT_HANDLER) {
|
CH_IRQ_HANDLER(STM32_I2C1_EVENT_HANDLER) {
|
||||||
OSAL_IRQ_PROLOGUE();
|
OSAL_IRQ_PROLOGUE();
|
||||||
|
|
||||||
for (size_t i = 0; i < 16; i++) {
|
while (true) {
|
||||||
auto& channel = channels[i];
|
|
||||||
|
|
||||||
// get the timestamp out under lock
|
// get the timestamp out under lock
|
||||||
// todo: lock freeeeee!
|
// todo: lock freeeeee!
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
auto timestamp = channel.Timestamp;
|
auto result = queue.pop();
|
||||||
channel.Timestamp = 0;
|
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
|
// Queue empty, we're done here.
|
||||||
|
if (!result) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& entry = result.Value;
|
||||||
|
auto& timestamp = entry.Timestamp;
|
||||||
|
|
||||||
if (timestamp != 0) {
|
if (timestamp != 0) {
|
||||||
channel.Callback(channel.CallbackData, timestamp);
|
auto& channel = channels[entry.Channel];
|
||||||
|
|
||||||
|
if (channel.Name) {
|
||||||
|
channel.Callback(channel.CallbackData, timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,11 +208,7 @@ void handleExtiIsr(uint8_t index) {
|
||||||
extiGetAndClearGroup1(1U << index, pr);
|
extiGetAndClearGroup1(1U << index, pr);
|
||||||
|
|
||||||
if (pr & (1 << index)) {
|
if (pr & (1 << index)) {
|
||||||
auto& timestamp = channels[index].Timestamp;
|
queue.push({getTimeNowNt(), index});
|
||||||
|
|
||||||
if (timestamp == 0) {
|
|
||||||
timestamp = getTimeNowNt();
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerInterrupt();
|
triggerInterrupt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,7 @@ static ioline_t camLines[CAM_INPUTS_COUNT];
|
||||||
static void shaft_callback(void *arg, efitick_t stamp) {
|
static void shaft_callback(void *arg, efitick_t stamp) {
|
||||||
// do the time sensitive things as early as possible!
|
// do the time sensitive things as early as possible!
|
||||||
TRIGGER_BAIL_IF_DISABLED
|
TRIGGER_BAIL_IF_DISABLED
|
||||||
//#if HW_CHECK_MODE
|
TRIGGER_BAIL_IF_SELF_STIM
|
||||||
// TRIGGER_BAIL_IF_SELF_STIM
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
int index = (int)arg;
|
int index = (int)arg;
|
||||||
ioline_t pal_line = shaftLines[index];
|
ioline_t pal_line = shaftLines[index];
|
||||||
|
@ -43,9 +41,7 @@ static void shaft_callback(void *arg, efitick_t stamp) {
|
||||||
|
|
||||||
static void cam_callback(void *arg, efitick_t stamp) {
|
static void cam_callback(void *arg, efitick_t stamp) {
|
||||||
TRIGGER_BAIL_IF_DISABLED
|
TRIGGER_BAIL_IF_DISABLED
|
||||||
//#if HW_CHECK_MODE
|
TRIGGER_BAIL_IF_SELF_STIM
|
||||||
// TRIGGER_BAIL_IF_SELF_STIM
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
int index = (int)arg;
|
int index = (int)arg;
|
||||||
ioline_t pal_line = camLines[index];
|
ioline_t pal_line = camLines[index];
|
||||||
|
|
|
@ -26,9 +26,8 @@ int icuFallingCallbackCounter = 0;
|
||||||
static void vvtRisingCallback(void *arg) {
|
static void vvtRisingCallback(void *arg) {
|
||||||
efitick_t now = getTimeNowNt();
|
efitick_t now = getTimeNowNt();
|
||||||
TRIGGER_BAIL_IF_DISABLED
|
TRIGGER_BAIL_IF_DISABLED
|
||||||
#if HW_CHECK_MODE
|
|
||||||
TRIGGER_BAIL_IF_SELF_STIM
|
TRIGGER_BAIL_IF_SELF_STIM
|
||||||
#endif
|
|
||||||
int index = (int)arg;
|
int index = (int)arg;
|
||||||
|
|
||||||
#if EFI_TOOTH_LOGGER
|
#if EFI_TOOTH_LOGGER
|
||||||
|
@ -43,9 +42,8 @@ static void vvtRisingCallback(void *arg) {
|
||||||
static void vvtFallingCallback(void * arg) {
|
static void vvtFallingCallback(void * arg) {
|
||||||
efitick_t now = getTimeNowNt();
|
efitick_t now = getTimeNowNt();
|
||||||
TRIGGER_BAIL_IF_DISABLED
|
TRIGGER_BAIL_IF_DISABLED
|
||||||
#if HW_CHECK_MODE
|
|
||||||
TRIGGER_BAIL_IF_SELF_STIM
|
TRIGGER_BAIL_IF_SELF_STIM
|
||||||
#endif
|
|
||||||
int index = (int)arg;
|
int index = (int)arg;
|
||||||
#if EFI_TOOTH_LOGGER
|
#if EFI_TOOTH_LOGGER
|
||||||
if (!engineConfiguration->displayLogicLevelsInEngineSniffer) {
|
if (!engineConfiguration->displayLogicLevelsInEngineSniffer) {
|
||||||
|
@ -62,9 +60,8 @@ static void shaftRisingCallback(bool isPrimary) {
|
||||||
efitick_t stamp = getTimeNowNt();
|
efitick_t stamp = getTimeNowNt();
|
||||||
|
|
||||||
TRIGGER_BAIL_IF_DISABLED
|
TRIGGER_BAIL_IF_DISABLED
|
||||||
#if HW_CHECK_MODE
|
|
||||||
TRIGGER_BAIL_IF_SELF_STIM
|
TRIGGER_BAIL_IF_SELF_STIM
|
||||||
#endif
|
|
||||||
icuRisingCallbackCounter++;
|
icuRisingCallbackCounter++;
|
||||||
|
|
||||||
// icucnt_t last_width = icuGetWidth(icup); so far we are fine with system time
|
// icucnt_t last_width = icuGetWidth(icup); so far we are fine with system time
|
||||||
|
@ -76,9 +73,7 @@ static void shaftFallingCallback(bool isPrimary) {
|
||||||
efitick_t stamp = getTimeNowNt();
|
efitick_t stamp = getTimeNowNt();
|
||||||
|
|
||||||
TRIGGER_BAIL_IF_DISABLED
|
TRIGGER_BAIL_IF_DISABLED
|
||||||
#if HW_CHECK_MODE
|
|
||||||
TRIGGER_BAIL_IF_SELF_STIM
|
TRIGGER_BAIL_IF_SELF_STIM
|
||||||
#endif
|
|
||||||
|
|
||||||
icuFallingCallbackCounter++;
|
icuFallingCallbackCounter++;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue