From 854189d720c6aeb5671676a43032fd2608012259 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 5 Apr 2021 15:05:12 +1000 Subject: [PATCH] Add manual irq line check for the int task for PD --- source/Core/BSP/BSP_PD.h | 1 + source/Core/BSP/Miniware/IRQ.cpp | 7 +++++++ source/Core/BSP/Pine64/IRQ.cpp | 4 ++++ source/Core/Drivers/FUSB302/int_n.cpp | 19 ++++++++++++------- source/Core/Drivers/FUSB302/pdb_conf.h | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/source/Core/BSP/BSP_PD.h b/source/Core/BSP/BSP_PD.h index a0dde7c2..f2c97802 100644 --- a/source/Core/BSP/BSP_PD.h +++ b/source/Core/BSP/BSP_PD.h @@ -8,5 +8,6 @@ #ifndef USER_BSP_PD_H_ #define USER_BSP_PD_H_ #include "BSP.h" +bool getFUS302IRQLow(); // Return true if the IRQ line is still held low #endif /* USER_BSP_PD_H_ */ diff --git a/source/Core/BSP/Miniware/IRQ.cpp b/source/Core/BSP/Miniware/IRQ.cpp index 5a5ffd0e..05689ef5 100644 --- a/source/Core/BSP/Miniware/IRQ.cpp +++ b/source/Core/BSP/Miniware/IRQ.cpp @@ -6,7 +6,9 @@ */ #include "IRQ.h" +#include "Pins.h" #include "int_n.h" + /* * Catch the IRQ that says that the conversion is done on the temperature * readings coming in Once these have come in we can unblock the PID so that it @@ -32,3 +34,8 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { (void)GPIO_Pin; InterruptHandler::irqCallback(); } + +bool getFUS302IRQLow() { + // Return true if the IRQ line is still held low + return HAL_GPIO_ReadPin(INT_PD_GPIO_Port, INT_PD_Pin) == GPIO_PIN_RESET; +} \ No newline at end of file diff --git a/source/Core/BSP/Pine64/IRQ.cpp b/source/Core/BSP/Pine64/IRQ.cpp index 1a3be266..9285bb16 100644 --- a/source/Core/BSP/Pine64/IRQ.cpp +++ b/source/Core/BSP/Pine64/IRQ.cpp @@ -118,6 +118,10 @@ void EXTI5_9_IRQHandler(void) { #endif } +bool getFUS302IRQLow() { + // Return true if the IRQ line is still held low + return (RESET == gpio_input_bit_get(FUSB302_IRQ_GPIO_Port, FUSB302_IRQ_Pin)); +} // These are unused for now void I2C0_EV_IRQHandler(void) {} diff --git a/source/Core/Drivers/FUSB302/int_n.cpp b/source/Core/Drivers/FUSB302/int_n.cpp index 3fc3e246..57bd466e 100644 --- a/source/Core/Drivers/FUSB302/int_n.cpp +++ b/source/Core/Drivers/FUSB302/int_n.cpp @@ -17,6 +17,7 @@ #include "int_n.h" #include "BSP.h" +#include "BSP_PD.h" #include "fusb302b.h" #include "fusbpd.h" #include "policy_engine.h" @@ -39,9 +40,11 @@ void InterruptHandler::Thread(const void *arg) { union fusb_status status; while (true) { /* If the INT_N line is low */ - if (xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 1000 : 10) == pdPASS) { - // delay slightly so we catch the crc with better timing - osDelay(1); + if (!getFUS302IRQLow()) { + if (xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 100 : 10) == pdPASS) { + // delay slightly so we catch the crc with better timing + // osDelay(1); + } } /* Read the FUSB302B status and interrupt registers */ fusb_get_status(&status); @@ -68,9 +71,11 @@ void InterruptHandler::Thread(const void *arg) { } } void InterruptHandler::irqCallback() { - if (TaskHandle != NULL) { - BaseType_t taskWoke = pdFALSE; - xTaskNotifyFromISR(TaskHandle, 0, eNotifyAction::eNoAction, &taskWoke); - portYIELD_FROM_ISR(taskWoke); + if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { + if (TaskHandle != NULL) { + BaseType_t taskWoke = pdFALSE; + xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetValueWithOverwrite, &taskWoke); + portYIELD_FROM_ISR(taskWoke); + } } } diff --git a/source/Core/Drivers/FUSB302/pdb_conf.h b/source/Core/Drivers/FUSB302/pdb_conf.h index 181eb669..7e50295f 100644 --- a/source/Core/Drivers/FUSB302/pdb_conf.h +++ b/source/Core/Drivers/FUSB302/pdb_conf.h @@ -25,7 +25,7 @@ /* PD Buddy thread priorities */ #define PDB_PRIO_PE (osPriorityAboveNormal) -#define PDB_PRIO_PRL (osPriorityNormal) -#define PDB_PRIO_PRL_INT_N (osPriorityBelowNormal) +#define PDB_PRIO_PRL (osPriorityAboveNormal) +#define PDB_PRIO_PRL_INT_N (osPriorityAboveNormal) #endif /* PDB_CONF_H */