Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c
mmi 5e6e8a8ff5 Stability Fix
Clearing flags instead of ITStatus seems to improve stability in EXTI interrupts

Added ASSERT functionality for STM std periphery library

Also busy updating the HW validation menu


git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@411 05563f52-14a8-4384-a975-3d1654cca0fa
2017-12-22 14:09:08 +00:00

324 lines
9.3 KiB
C

// -----------------------------------------------------------------------------
/// @file stm32f10x_it.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file stm32f10x_it.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "FreeRTOS.h"
#include "misc.h"
#include "queue.h"
#include "semphr.h"
#include "hsb-mrts.h"
#include "stm32f10x_it.h"
#include "stm32f10x_exti.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_spi.h"
#include "stm32f10x_usart.h"
#include "Display.h"
#include "Error.h"
#include "repairMenu.h"
#include "repairProcess.h"
#include "Leds.h"
#include "Logger.h"
#include "platform.h"
#include "rtc.h"
#include "spi.h"
#include "uart.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
void IRQ_setInterruptProperties(uint8_t irqChannel, uint8_t preemptionPriority, uint8_t subPriority, FunctionalState command)
{
NVIC_InitTypeDef NVIC_InitStructure; //! Define empty NVIC structure
NVIC_InitStructure.NVIC_IRQChannel = irqChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preemptionPriority;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = subPriority;
NVIC_InitStructure.NVIC_IRQChannelCmd = command;
//! initialize the interrupts interface will all configured items
NVIC_Init(&NVIC_InitStructure);
}
void IRQ_setKeypadEXTI(struct Keypad* self, FunctionalState command)
{
if (self->initialized)
{
int colCounter;
for (colCounter = 0; colCounter < self->numberOfColumns; colCounter++)
{
self->column[colCounter].EXTI_InitStruct.EXTI_LineCmd = command;
EXTI_Init(&self->column[colCounter].EXTI_InitStruct);
}
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
// void SVC_Handler(void)
// {
// }
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
// void PendSV_Handler(void)
// {
// }
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
// void SysTick_Handler(void)
// {
// }
void HardFault_Handler(void)
{
while (1);
}
/** ----------------------------------------------------------------------------
* @brief Function: SPI1_IRQHandler
*
* Dedicated Interrupt Service Routine for SPI1
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
void SPI1_IRQHandler (void)
{
signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
//! Transmission register empty interrupt
if(SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE) != RESET)
{
//! Receive element from usart transmission queue
struct spiQueueItem spiTxItem;
xQueueReceiveFromISR(spi1->txQueue, &spiTxItem, &higherPriorityTaskWoken);
//! Write one byte to the transmit data register
SPI_I2S_SendData(SPI1, spiTxItem.byte);
//! check if queue is empty -> all bytes transmit
if(pdTRUE == xQueueIsQueueEmptyFromISR(spi1->txQueue))
{
//! Disable the COMPORT Transmit interrupt and release semaphore
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);
xSemaphoreGiveFromISR(spi1->txSemaphore, &higherPriorityTaskWoken);
}
}
//! Current interrupt is triggered by USART_RXNE (receive register not empty)
if(SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_RXNE) != RESET)
{
//! Read one byte from the receive data register
struct spiQueueItem spiRxItem;
//! Reading from reception register automatically clears the RXNE interrupt
spiRxItem.byte = (unsigned char) 0xFF & SPI_I2S_ReceiveData(SPI1);
//! Add the byte to the bluetooth RX queue
//! In case of a full queue, the data is dumped
(void)xQueueSendFromISR(spi1->rxQueue, &spiRxItem, &higherPriorityTaskWoken);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
/** ----------------------------------------------------------------------------
* @brief Function: SPI3_IRQHandler
*
* Dedicated Interrupt Service Routine for SPI3
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
void SPI3_IRQHandler (void)
{
signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
//! Transmission register empty interrupt
if(SPI_I2S_GetITStatus(SPI3, SPI_I2S_IT_TXE) != RESET)
{
//! Receive element from usart transmission queue
struct spiQueueItem spiTxItem;
xQueueReceiveFromISR(spi3->txQueue, &spiTxItem, &higherPriorityTaskWoken);
//! Write one byte to the transmit data register
SPI_I2S_SendData(SPI3, spiTxItem.byte);
//! check if queue is empty -> all bytes transmit
if(pdTRUE == xQueueIsQueueEmptyFromISR(spi3->txQueue))
{
//! Disable the COMPORT Transmit interrupt and release semaphore
SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, DISABLE);
xSemaphoreGiveFromISR(spi3->txSemaphore, &higherPriorityTaskWoken);
}
}
//! Current interrupt is triggered by USART_RXNE (receive register not empty)
if(SPI_I2S_GetITStatus(SPI3, SPI_I2S_IT_RXNE) != RESET)
{
//! Read one byte from the receive data register
struct spiQueueItem spiRxItem;
//! Reading from reception register automatically clears the RXNE interrupt
spiRxItem.byte = (unsigned char) 0xFF & SPI_I2S_ReceiveData(SPI3);
//! Add the byte to the bluetooth RX queue
//! In case of a full queue, the data is dumped
(void)xQueueSendFromISR(spi3->rxQueue, &spiRxItem, &higherPriorityTaskWoken);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
void EXTI0_IRQHandler(void)
{
signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
xSemaphoreGiveFromISR(interlock->semaphore, &higherPriorityTaskWoken);
EXTI_ClearITPendingBit(EXTI_Line0);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
void EXTI1_IRQHandler(void)
{
signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
xSemaphoreGiveFromISR(interlock->semaphore, &higherPriorityTaskWoken);
EXTI_ClearITPendingBit(EXTI_Line1);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
void EXTI4_IRQHandler(void)
{
signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
if(EXTI_GetFlagStatus(EXTI_Line4) != RESET)
{
EXTI_ClearFlag(EXTI_Line4);
IRQ_setKeypadEXTI(keypad, DISABLE);
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
void EXTI9_5_IRQHandler (void)
{
signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
Led_on(LED_ONBOARD_GREEN);
if (EXTI_GetFlagStatus(EXTI_Line5) != RESET)
{
EXTI_ClearFlag(EXTI_Line5);
IRQ_setKeypadEXTI(keypad, DISABLE);
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
}
else if (EXTI_GetFlagStatus(EXTI_Line6) != RESET)
{
EXTI_ClearFlag(EXTI_Line6);
IRQ_setKeypadEXTI(keypad, DISABLE);
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
}
else if (EXTI_GetFlagStatus(EXTI_Line7) != RESET)
{
EXTI_ClearFlag(EXTI_Line7);
IRQ_setKeypadEXTI(keypad, DISABLE);
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
}
else if (EXTI_GetFlagStatus(EXTI_Line8) != RESET)
{
EXTI_ClearFlag(EXTI_Line8);
}
else if (EXTI_GetFlagStatus(EXTI_Line9) != RESET)
{
EXTI_ClearFlag(EXTI_Line9);
}
Led_off(LED_ONBOARD_GREEN);
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}