1
0
forked from me/IronOS
This commit is contained in:
Ben V. Brown
2020-06-17 18:14:17 +10:00
parent 4c2fb11d32
commit 6d23617670
5 changed files with 61 additions and 53 deletions

View File

@@ -13,7 +13,7 @@
#define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET) #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 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 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; SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
StaticSemaphore_t I2CBB::xSemaphoreBuffer; StaticSemaphore_t I2CBB::xSemaphoreBuffer;
void I2CBB::init() { void I2CBB::init() {
@@ -269,7 +269,11 @@ bool I2CBB::lock() {
if (I2CSemaphore == NULL) { if (I2CSemaphore == NULL) {
asm("bkpt"); 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) { void I2CBB::write_bit(uint8_t val) {

View File

@@ -6,6 +6,7 @@
*/ */
#include "IRQ.h" #include "IRQ.h"
#include "int_n.h"
/* /*
* Catch the IRQ that says that the conversion is done on the temperature * 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 * 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) { void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback(); FRToSI2C::CpltCallback();
} }
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
InterruptHandler::irqCallback();
}

View File

@@ -24,6 +24,7 @@ void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_GPIO_EXTI_Callback(uint16_t);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -41,22 +41,21 @@ void InterruptHandler::Thread(const void *arg) {
(void) arg; (void) arg;
union fusb_status status; union fusb_status status;
eventmask_t events; eventmask_t events;
//TODO use IRQ task notification to unblock this thread to stop it spinning
while (true) { while (true) {
/* If the INT_N line is low */ /* If the INT_N line is low */
if (pd_irq_read() == 0) { xTaskNotifyWait(0x00, 0x0F, NULL, 5);
/* Read the FUSB302B status and interrupt registers */ /* Read the FUSB302B status and interrupt registers */
fusb_get_status(&status); fusb_get_status(&status);
//Check for rx alerts //Check for rx alerts
{
/* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) { if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {
ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT); ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT);
} }
}
/* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX
* thread */ * thread */
{
events = 0; events = 0;
if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) { if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) {
events |= PDB_EVT_PRLTX_I_RETRYFAIL; events |= PDB_EVT_PRLTX_I_RETRYFAIL;
@@ -67,10 +66,10 @@ void InterruptHandler::Thread(const void *arg) {
if (events) { if (events) {
ProtocolTransmit::notify(events); ProtocolTransmit::notify(events);
} }
}
/* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset /* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset
* thread */ * thread */
{
events = 0; events = 0;
if (status.interrupta & FUSB_INTERRUPTA_I_HARDRST) { if (status.interrupta & FUSB_INTERRUPTA_I_HARDRST) {
events |= PDB_EVT_HARDRST_I_HARDRST; events |= PDB_EVT_HARDRST_I_HARDRST;
@@ -81,19 +80,17 @@ void InterruptHandler::Thread(const void *arg) {
if (events) { if (events) {
ResetHandler::notify(events); ResetHandler::notify(events);
} }
}
{
/* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy /* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy
* Engine thread */ * Engine thread */
if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP
&& status.status1 & FUSB_STATUS1_OVRTEMP) { && status.status1 & FUSB_STATUS1_OVRTEMP) {
PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP); PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP);
} }
}
} }
} else { void InterruptHandler::irqCallback() {
osDelay(1); xTaskNotify(TaskHandle, 0x0F, eNotifyAction::eSetBits);
}
osDelay(1);
}
} }

View File

@@ -24,8 +24,9 @@ class InterruptHandler {
public: public:
//Creates the thread to handle the Interrupt pin //Creates the thread to handle the Interrupt pin
static void init(); static void init();
//TODO handle irq callbacks instead of polling the pin
static void irqCallback();
private: private:
static void Thread(const void *arg); static void Thread(const void *arg);
static osThreadId TaskHandle; static osThreadId TaskHandle;