Skip to content

Commit

Permalink
onSpiIrq and onSpiDmaTransferCompleted handler in tick
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Feb 15, 2021
1 parent b88c346 commit b93a11c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 61 deletions.
24 changes: 12 additions & 12 deletions src/eez/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,35 +208,35 @@ extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
}
#endif

if (g_isBooted) {
sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 0);
} else {
// if (g_isBooted) {
// sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 0);
// } else {
g_slots[0]->onSpiIrq();
}
// }
} else if (GPIO_Pin == SPI4_IRQ_Pin) {
#if CONF_SURVIVE_MODE
if (g_slots[1]->moduleType == MODULE_TYPE_DCP405) {
readIntcapRegisterShortcut(1);
}
#endif

if (g_isBooted) {
sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 1);
} else {
// if (g_isBooted) {
// sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 1);
// } else {
g_slots[1]->onSpiIrq();
}
// }
} else if (GPIO_Pin == SPI5_IRQ_Pin) {
#if CONF_SURVIVE_MODE
if (g_slots[2]->moduleType == MODULE_TYPE_DCP405) {
readIntcapRegisterShortcut(2);
}
#endif

if (g_isBooted) {
sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 2);
} else {
// if (g_isBooted) {
// sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 2);
// } else {
g_slots[2]->onSpiIrq();
}
// }
} else if (g_mcuRevision < MCU_REVISION_R3B3 && GPIO_Pin == R2B4_SD_DETECT_Pin) {
eez::psu::sd_card::onSdDetectInterrupt();
} else if (GPIO_Pin == ENC_A_Pin || GPIO_Pin == ENC_B_Pin) {
Expand Down
9 changes: 8 additions & 1 deletion src/eez/modules/dib-dcp405/dib-dcp405.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct DcpChannel : public Channel {

bool valueBalancing = false;

bool spiIrq = false;

DcpChannel(uint8_t slotIndex, uint8_t channelIndex, uint8_t subchannelIndex)
: Channel(slotIndex, channelIndex, subchannelIndex)
{
Expand Down Expand Up @@ -276,6 +278,11 @@ struct DcpChannel : public Channel {
return;
}

if (spiIrq) {
spiIrq = false;
onSpiIrq();
}

ioexp.tick();

#if !CONF_SKIP_PWRGOOD_TEST
Expand Down Expand Up @@ -969,7 +976,7 @@ struct DcpModule : public PsuModule {
#if defined(EEZ_PLATFORM_STM32)
void onSpiIrq() {
auto dcpChannel = (DcpChannel *)Channel::getBySlotIndex(slotIndex);
dcpChannel->onSpiIrq();
dcpChannel->spiIrq = true;
}
#endif

Expand Down
24 changes: 12 additions & 12 deletions src/eez/modules/dib-mio168/dib-mio168.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2022,23 +2022,23 @@ struct Mio168Module : public Module {

void onSpiIrq() {
spiReady = true;
if (g_isBooted) {
stateTransition(EVENT_SLAVE_READY);
}
// if (g_isBooted) {
// stateTransition(EVENT_SLAVE_READY);
// }
}

void onSpiDmaTransferCompleted(int status) override {
if (g_isBooted) {
if (status == bp3c::comm::TRANSFER_STATUS_OK) {
stateTransition(EVENT_DMA_TRANSFER_COMPLETED);
} else {
reportDmaTransferFailed(status);
stateTransition(EVENT_DMA_TRANSFER_FAILED);
}
} else {
// if (g_isBooted) {
// if (status == bp3c::comm::TRANSFER_STATUS_OK) {
// stateTransition(EVENT_DMA_TRANSFER_COMPLETED);
// } else {
// reportDmaTransferFailed(status);
// stateTransition(EVENT_DMA_TRANSFER_FAILED);
// }
// } else {
spiDmaTransferCompleted = true;
spiDmaTransferStatus = status;
}
// }
}

void onPowerDown() override {
Expand Down
24 changes: 12 additions & 12 deletions src/eez/modules/dib-prel6/dib-prel6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,23 +541,23 @@ struct Prel6Module : public Module {

void onSpiIrq() {
spiReady = true;
if (g_isBooted) {
stateTransition(EVENT_SLAVE_READY);
}
// if (g_isBooted) {
// stateTransition(EVENT_SLAVE_READY);
// }
}

void onSpiDmaTransferCompleted(int status) override {
if (g_isBooted) {
if (status == bp3c::comm::TRANSFER_STATUS_OK) {
stateTransition(EVENT_DMA_TRANSFER_COMPLETED);
} else {
reportDmaTransferFailed(status);
stateTransition(EVENT_DMA_TRANSFER_FAILED);
}
} else {
// if (g_isBooted) {
// if (status == bp3c::comm::TRANSFER_STATUS_OK) {
// stateTransition(EVENT_DMA_TRANSFER_COMPLETED);
// } else {
// reportDmaTransferFailed(status);
// stateTransition(EVENT_DMA_TRANSFER_FAILED);
// }
// } else {
spiDmaTransferCompleted = true;
spiDmaTransferStatus = status;
}
// }
}

void onPowerDown() override {
Expand Down
24 changes: 12 additions & 12 deletions src/eez/modules/dib-smx46/dib-smx46.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,23 +582,23 @@ struct Smx46Module : public Module {

void onSpiIrq() {
spiReady = true;
if (g_isBooted) {
stateTransition(EVENT_SLAVE_READY);
}
// if (g_isBooted) {
// stateTransition(EVENT_SLAVE_READY);
// }
}

void onSpiDmaTransferCompleted(int status) override {
if (g_isBooted) {
if (status == bp3c::comm::TRANSFER_STATUS_OK) {
stateTransition(EVENT_DMA_TRANSFER_COMPLETED);
} else {
reportDmaTransferFailed(status);
stateTransition(EVENT_DMA_TRANSFER_FAILED);
}
} else {
// if (g_isBooted) {
// if (status == bp3c::comm::TRANSFER_STATUS_OK) {
// stateTransition(EVENT_DMA_TRANSFER_COMPLETED);
// } else {
// reportDmaTransferFailed(status);
// stateTransition(EVENT_DMA_TRANSFER_FAILED);
// }
// } else {
spiDmaTransferCompleted = true;
spiDmaTransferStatus = status;
}
// }
}

void onPowerDown() override {
Expand Down
24 changes: 12 additions & 12 deletions src/eez/platform/stm32/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {

deselect(slotIndex);

if (g_isBooted) {
sendMessageToPsu(PSU_MESSAGE_SPI_DMA_TRANSFER_COMPLETED, slotIndex | (TRANSFER_STATUS_OK << 8));
} else {
// if (g_isBooted) {
// sendMessageToPsu(PSU_MESSAGE_SPI_DMA_TRANSFER_COMPLETED, slotIndex | (TRANSFER_STATUS_OK << 8));
// } else {
g_slots[slotIndex]->onSpiDmaTransferCompleted(TRANSFER_STATUS_OK);
}
// }
}

void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
Expand All @@ -328,17 +328,17 @@ void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
deselect(slotIndex);

if (handle[slotIndex]->ErrorCode == HAL_SPI_ERROR_CRC) {
if (g_isBooted) {
sendMessageToPsu(PSU_MESSAGE_SPI_DMA_TRANSFER_COMPLETED, slotIndex | (TRANSFER_STATUS_CRC_ERROR << 8));
} else {
// if (g_isBooted) {
// sendMessageToPsu(PSU_MESSAGE_SPI_DMA_TRANSFER_COMPLETED, slotIndex | (TRANSFER_STATUS_CRC_ERROR << 8));
// } else {
g_slots[slotIndex]->onSpiDmaTransferCompleted(TRANSFER_STATUS_CRC_ERROR);
}
// }
} else {
if (g_isBooted) {
sendMessageToPsu(PSU_MESSAGE_SPI_DMA_TRANSFER_COMPLETED, slotIndex | (TRANSFER_STATUS_ERROR << 8));
} else {
// if (g_isBooted) {
// sendMessageToPsu(PSU_MESSAGE_SPI_DMA_TRANSFER_COMPLETED, slotIndex | (TRANSFER_STATUS_ERROR << 8));
// } else {
g_slots[slotIndex]->onSpiDmaTransferCompleted(TRANSFER_STATUS_ERROR);
}
// }
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/eez/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#include <eez/libs/sd_fat/sd_fat.h>
#include <eez/libs/image/jpeg.h>

volatile uint32_t g_debugVarTick;
volatile uint32_t g_debugVarDiff;

////////////////////////////////////////////////////////////////////////////////

#if defined(EEZ_PLATFORM_STM32)
Expand Down Expand Up @@ -202,6 +205,9 @@ void highPriorityThreadOneIter() {
g_lastTickCountMs = millis();
#endif

g_debugVarDiff = g_lastTickCountMs - g_debugVarTick;
g_debugVarTick = g_lastTickCountMs;

psu::tick();
}

Expand Down

0 comments on commit b93a11c

Please sign in to comment.