diff --git a/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp b/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp index ef19db03..c7c04c4f 100644 --- a/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp +++ b/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp @@ -13,7 +13,7 @@ #define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET) #define SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0) #define SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0) -#define I2C_DELAY() {for(int xx=0;xx<700;xx++){asm("nop");}} +#define I2C_DELAY() {for(int xx=0;xx<100;xx++){asm("nop");}} SemaphoreHandle_t I2CBB::I2CSemaphore = NULL; StaticSemaphore_t I2CBB::xSemaphoreBuffer; void I2CBB::init() { @@ -269,7 +269,11 @@ bool I2CBB::lock() { if (I2CSemaphore == NULL) { asm("bkpt"); } - return xSemaphoreTake(I2CSemaphore, (TickType_t) 50) == pdTRUE; + bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 50) == pdTRUE; + if (!a) { + asm("bkpt"); + } + return a; } void I2CBB::write_bit(uint8_t val) { diff --git a/workspace/TS100/Core/BSP/Miniware/IRQ.cpp b/workspace/TS100/Core/BSP/Miniware/IRQ.cpp index eac8cdbc..15d26b64 100644 --- a/workspace/TS100/Core/BSP/Miniware/IRQ.cpp +++ b/workspace/TS100/Core/BSP/Miniware/IRQ.cpp @@ -6,6 +6,7 @@ */ #include "IRQ.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 @@ -41,3 +42,7 @@ void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) { void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); } + +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { + InterruptHandler::irqCallback(); +} diff --git a/workspace/TS100/Core/BSP/Miniware/IRQ.h b/workspace/TS100/Core/BSP/Miniware/IRQ.h index 09d79c36..bcd42d04 100644 --- a/workspace/TS100/Core/BSP/Miniware/IRQ.h +++ b/workspace/TS100/Core/BSP/Miniware/IRQ.h @@ -24,6 +24,7 @@ void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); +void HAL_GPIO_EXTI_Callback(uint16_t); #ifdef __cplusplus } diff --git a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp index d2329226..32d020fc 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp +++ b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp @@ -41,59 +41,56 @@ void InterruptHandler::Thread(const void *arg) { (void) arg; union fusb_status status; eventmask_t events; - //TODO use IRQ task notification to unblock this thread to stop it spinning while (true) { /* If the INT_N line is low */ - if (pd_irq_read() == 0) { - /* Read the FUSB302B status and interrupt registers */ - fusb_get_status(&status); - //Check for rx alerts - { - /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ - 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 */ - { - events = 0; - if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) { - events |= PDB_EVT_PRLTX_I_RETRYFAIL; - } - if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) { - events |= PDB_EVT_PRLTX_I_TXSENT; - } - if (events) { - ProtocolTransmit::notify(events); - } - } - /* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset - * thread */ - { - events = 0; - if (status.interrupta & FUSB_INTERRUPTA_I_HARDRST) { - events |= PDB_EVT_HARDRST_I_HARDRST; - } - if (status.interrupta & FUSB_INTERRUPTA_I_HARDSENT) { - events |= PDB_EVT_HARDRST_I_HARDSENT; - } - if (events) { - ResetHandler::notify(events); - } - } - { - /* 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) { - PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP); - } - } + xTaskNotifyWait(0x00, 0x0F, NULL, 5); + /* Read the FUSB302B status and interrupt registers */ + fusb_get_status(&status); + //Check for rx alerts - } else { - osDelay(1); + /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ + if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) { + ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT); } - osDelay(1); + + /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX + * thread */ + + events = 0; + if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) { + events |= PDB_EVT_PRLTX_I_RETRYFAIL; + } + if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) { + events |= PDB_EVT_PRLTX_I_TXSENT; + } + if (events) { + ProtocolTransmit::notify(events); + } + + /* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset + * thread */ + + events = 0; + if (status.interrupta & FUSB_INTERRUPTA_I_HARDRST) { + events |= PDB_EVT_HARDRST_I_HARDRST; + } + if (status.interrupta & FUSB_INTERRUPTA_I_HARDSENT) { + events |= PDB_EVT_HARDRST_I_HARDSENT; + } + if (events) { + ResetHandler::notify(events); + } + + /* 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) { + PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP); + } + } } + +void InterruptHandler::irqCallback() { + xTaskNotify(TaskHandle, 0x0F, eNotifyAction::eSetBits); +} diff --git a/workspace/TS100/Core/Drivers/FUSB302/int_n.h b/workspace/TS100/Core/Drivers/FUSB302/int_n.h index 68dc04d8..e168171e 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/int_n.h +++ b/workspace/TS100/Core/Drivers/FUSB302/int_n.h @@ -24,8 +24,9 @@ class InterruptHandler { public: //Creates the thread to handle the Interrupt pin static void init(); - //TODO handle irq callbacks instead of polling the pin + + static void irqCallback(); private: static void Thread(const void *arg); static osThreadId TaskHandle;