Skip to content

Commit

Permalink
spi irq handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 11, 2020
1 parent 98985ac commit 936e362
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
14 changes: 14 additions & 0 deletions src/eez/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ void mainTask(const void *) {
////////////////////////////////////////////////////////////////////////////////

#if defined(EEZ_PLATFORM_STM32)

namespace eez {
void readIntcapRegisterShortcut(int slotIndex);
}

extern "C" void SystemClock_Config(void);

extern "C" void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName) {
Expand All @@ -195,10 +200,19 @@ extern "C" void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *p
extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
using namespace eez;
if (GPIO_Pin == SPI2_IRQ_Pin) {
if (g_slots[0]->moduleType == MODULE_TYPE_DCP405) {
readIntcapRegisterShortcut(0);
}
sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 0, 0);
} else if (GPIO_Pin == SPI4_IRQ_Pin) {
if (g_slots[1]->moduleType == MODULE_TYPE_DCP405) {
readIntcapRegisterShortcut(1);
}
sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 1, 0);
} else if (GPIO_Pin == SPI5_IRQ_Pin) {
if (g_slots[2]->moduleType == MODULE_TYPE_DCP405) {
readIntcapRegisterShortcut(2);
}
sendMessageToPsu(PSU_MESSAGE_SPI_IRQ, 2, 0);
}

Expand Down
12 changes: 12 additions & 0 deletions src/eez/modules/dib-dcp405/dib-dcp405.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <eez/gui/gui.h>

#if defined(EEZ_PLATFORM_STM32)
#include <main.h>

#include <eez/drivers/tmp1075.h>
#include <eez/drivers/tc77.h>
#endif
Expand Down Expand Up @@ -827,6 +829,8 @@ struct DcpChannel : public Channel {
if (isOutputEnabled() && isHwOvpEnabled(*this)) {
protectionEnter(ovp, true);
}
} else if (!(intcap & (1 << IOExpander::IO_BIT_IN_PWRGOOD))) {
NVIC_SystemReset();
}
}
#endif
Expand Down Expand Up @@ -1079,4 +1083,12 @@ void tickDacRamp(uint32_t tickCount) {
}

} // namespace dcp405

void readIntcapRegisterShortcut(int slotIndex) {
dcp405::DcpChannel *channel = (dcp405::DcpChannel *)Channel::getBySlotIndex(slotIndex, 0);
if (channel) {
channel->ioexp.readIntcapRegister();
}
}

} // namespace eez
4 changes: 4 additions & 0 deletions src/eez/modules/dib-dcp405/ioexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ void IOExpander::init() {
HAL_GPIO_WritePin(OE_SYNC_GPIO_Port, OE_SYNC_Pin, GPIO_PIN_RESET);
#endif

readIntcapRegister();

#endif
}

Expand Down Expand Up @@ -255,6 +257,8 @@ void IOExpander::reinit() {

write(reg, value);
}

readIntcapRegister();
}
#endif

Expand Down
10 changes: 10 additions & 0 deletions src/eez/modules/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ int PsuModule::getChannelSettingsPageId() {
return eez::gui::PAGE_ID_CH_SETTINGS;
}

int PsuModule::getSlotSettingsPageId() {
return eez::gui::PAGE_ID_CH_SETTINGS;
}

void PsuModule::resetPowerChannelProfileToDefaults(int channelIndex, uint8_t *buffer) {
auto &channel = Channel::get(channelIndex);
auto parameters = (ProfileParameters *)buffer;
Expand Down Expand Up @@ -932,6 +936,9 @@ bool powerUp() {
// turn on Power On (PON) bit of ESE register
reg_set_esr_bits(ESR_PON);

HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

InfoTrace("Power up (v%s)\n", MCU_FIRMWARE);

// play power up tune on success
Expand Down Expand Up @@ -987,6 +994,9 @@ void powerDown() {

powerDownChannels();

HAL_NVIC_DisableIRQ(EXTI9_5_IRQn);
HAL_NVIC_DisableIRQ(EXTI15_10_IRQn);

board::powerDown();

g_powerIsUp = false;
Expand Down
1 change: 1 addition & 0 deletions src/eez/modules/psu/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct PsuModule : public Module {
void setEnabled(bool value) override;

int getChannelSettingsPageId() override;
int getSlotSettingsPageId() override;

void resetPowerChannelProfileToDefaults(int channelIndex, uint8_t *buffer) override;
void getPowerChannelProfileParameters(int channelIndex, uint8_t *buffer) override;
Expand Down
7 changes: 7 additions & 0 deletions src/eez/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ bool isPsuThread() {
}

void sendMessageToPsu(HighPriorityThreadMessage messageType, uint32_t messageParam, uint32_t timeoutMillisec) {
if (!g_highPriorityMessageQueueId) {
return;
}

osMessagePut(g_highPriorityMessageQueueId, QUEUE_MESSAGE(messageType, messageParam), timeoutMillisec);

#if defined(EEZ_PLATFORM_SIMULATOR)
Expand Down Expand Up @@ -469,6 +473,9 @@ bool isLowPriorityThread() {
}

void sendMessageToLowPriorityThread(LowPriorityThreadMessage messageType, uint32_t messageParam, uint32_t timeoutMillisec) {
if (!g_lowPriorityMessageQueueId) {
return;
}
osMessagePut(g_lowPriorityMessageQueueId, QUEUE_MESSAGE(messageType, messageParam), timeoutMillisec);
}

Expand Down
17 changes: 6 additions & 11 deletions src/third_party/stm32_cubeide/Core/Src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void MX_GPIO_Init(void)

/*Configure GPIO pins : PAPin PAPin */
GPIO_InitStruct.Pin = SPI2_IRQ_Pin|SPI5_IRQ_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Expand Down Expand Up @@ -215,7 +215,7 @@ void MX_GPIO_Init(void)

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = SPI4_IRQ_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SPI4_IRQ_GPIO_Port, &GPIO_InitStruct);

Expand All @@ -226,11 +226,8 @@ void MX_GPIO_Init(void)
HAL_GPIO_Init(ENC_SW_GPIO_Port, &GPIO_InitStruct);

/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);

}

Expand Down Expand Up @@ -324,7 +321,7 @@ void MX_GPIO_Init(void)

/*Configure GPIO pins : PAPin PAPin */
GPIO_InitStruct.Pin = SPI2_IRQ_Pin|SPI5_IRQ_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Expand Down Expand Up @@ -379,7 +376,7 @@ void MX_GPIO_Init(void)

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = SPI4_IRQ_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SPI4_IRQ_GPIO_Port, &GPIO_InitStruct);

Expand All @@ -391,10 +388,8 @@ void MX_GPIO_Init(void)

/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

Expand Down

0 comments on commit 936e362

Please sign in to comment.