From 6b671374205ddd5f5bb7c35894c10368b2495c31 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 5 Apr 2021 15:53:10 +1000 Subject: [PATCH] Update int_n.cpp --- source/Core/Drivers/FUSB302/int_n.cpp | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/source/Core/Drivers/FUSB302/int_n.cpp b/source/Core/Drivers/FUSB302/int_n.cpp index 57bd466e..2baa0cc0 100644 --- a/source/Core/Drivers/FUSB302/int_n.cpp +++ b/source/Core/Drivers/FUSB302/int_n.cpp @@ -31,6 +31,7 @@ uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize osStaticThreadDef_t InterruptHandler::TaskControlBlock; void InterruptHandler::init() { + TaskHandle = NULL; osThreadStaticDef(intTask, Thread, PDB_PRIO_PRL_INT_N, 0, TaskStackSize, TaskBuffer, &TaskControlBlock); TaskHandle = osThreadCreate(osThread(intTask), NULL); } @@ -38,16 +39,20 @@ void InterruptHandler::init() { void InterruptHandler::Thread(const void *arg) { (void)arg; union fusb_status status; - while (true) { - /* If the INT_N line is low */ + for (;;) { + // If the irq is low continue, otherwise wait for irq or timeout if (!getFUS302IRQLow()) { - if (xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 100 : 10) == pdPASS) { - // delay slightly so we catch the crc with better timing - // osDelay(1); - } + xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 100 : 10); } /* Read the FUSB302B status and interrupt registers */ fusb_get_status(&status); + + /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ + // This means a message was recieved with a good CRC + if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) { + ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT); + } + /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX * thread */ if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) { @@ -57,12 +62,6 @@ void InterruptHandler::Thread(const void *arg) { ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_RETRYFAIL); } - /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ - // This means a message was recieved with a good CRC - if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) { - ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT); - } - /* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy * Engine thread */ if ((status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP) && (status.status1 & FUSB_STATUS1_OVRTEMP)) { @@ -71,11 +70,9 @@ void InterruptHandler::Thread(const void *arg) { } } void InterruptHandler::irqCallback() { - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - if (TaskHandle != NULL) { - BaseType_t taskWoke = pdFALSE; - xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetValueWithOverwrite, &taskWoke); - portYIELD_FROM_ISR(taskWoke); - } + if (TaskHandle != NULL) { + BaseType_t taskWoke = pdFALSE; + xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetBits, &taskWoke); + portYIELD_FROM_ISR(taskWoke); } }