display has now a refresh timer to totally refresh the display contents (to prevent EMC issues) Fixed PCBA names git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@229 05563f52-14a8-4384-a975-3d1654cca0fa
405 lines
12 KiB
C
405 lines
12 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 "stm32f10x_it.h"
|
|
|
|
#include "stm32f10x_exti.h"
|
|
#include "stm32f10x_rtc.h"
|
|
#include "stm32f10x_spi.h"
|
|
#include "stm32f10x_usart.h"
|
|
|
|
#include "Display.h"
|
|
#include "Logger.h"
|
|
#include "led.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)
|
|
{
|
|
int colCounter;
|
|
for (colCounter = 0; colCounter < KEYPAD_NUMBER_OF_COLUMNS; 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)
|
|
// {
|
|
// }
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* @brief Function: USART1_IRQHandler
|
|
*
|
|
* Dedicated Interrupt Service Routine for USART1
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
|
|
void USART1_IRQHandler(void)
|
|
{
|
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
|
|
|
|
|
//! Transmission register empty interrupt
|
|
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
|
|
{
|
|
|
|
//! Receive element from usart transmission queue
|
|
|
|
struct usartQueueItem usartTxItem;
|
|
|
|
xQueueReceiveFromISR(uart1->txQueue, &usartTxItem, &higherPriorityTaskWoken);
|
|
//! Write one byte to the transmit data register
|
|
USART_SendData(USART1, usartTxItem.byte);
|
|
//! check if queue is empty -> all bytes transmit
|
|
if(pdTRUE == xQueueIsQueueEmptyFromISR(uart1->txQueue))
|
|
{
|
|
//! Disable the COMPORT Transmit interrupt and release semaphore
|
|
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
|
|
xSemaphoreGiveFromISR(uart1->txSemaphore, &higherPriorityTaskWoken);
|
|
}
|
|
}
|
|
|
|
//! Current interrupt is triggered by USART_RXNE (receive register not empty)
|
|
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
|
|
{
|
|
//! Read one byte from the receive data register
|
|
|
|
struct usartQueueItem usartRxItem;
|
|
//! Reading from reception register automatically clears the RXNE interrupt
|
|
usartRxItem.byte = (unsigned char) 0xFF & USART_ReceiveData(USART1);
|
|
//! Add the byte to the bluetooth RX queue
|
|
//! In case of a full queue, the data is dumped
|
|
(void)xQueueSendFromISR(uart1->rxQueue, &usartRxItem, &higherPriorityTaskWoken);
|
|
}
|
|
|
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
|
}
|
|
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* @brief Function: USART3_IRQHandler
|
|
*
|
|
* Dedicated Interrupt Service Routine for USART3
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
|
|
void USART3_IRQHandler(void)
|
|
{
|
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
|
|
|
|
|
//! Transmission register empty interrupt
|
|
if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
|
|
{
|
|
|
|
//! Receive element from usart transmission queue
|
|
|
|
struct usartQueueItem usartTxItem;
|
|
|
|
xQueueReceiveFromISR(uart3->txQueue, &usartTxItem, &higherPriorityTaskWoken);
|
|
//! Write one byte to the transmit data register
|
|
USART_SendData(USART3, usartTxItem.byte);
|
|
//! check if queue is empty -> all bytes transmit
|
|
if(pdTRUE == xQueueIsQueueEmptyFromISR(uart3->txQueue))
|
|
{
|
|
//! Disable the COMPORT Transmit interrupt and release semaphore
|
|
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
|
|
xSemaphoreGiveFromISR(uart3->txSemaphore, &higherPriorityTaskWoken);
|
|
}
|
|
}
|
|
|
|
//! Current interrupt is triggered by USART_RXNE (receive register not empty)
|
|
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
|
|
{
|
|
//! Read one byte from the receive data register
|
|
|
|
struct usartQueueItem usartRxItem;
|
|
//! Reading from reception register automatically clears the RXNE interrupt
|
|
usartRxItem.byte = (unsigned char) 0xFF & USART_ReceiveData(USART3);
|
|
//! Add the byte to the bluetooth RX queue
|
|
//! In case of a full queue, the data is dumped
|
|
(void)xQueueSendFromISR(uart3->rxQueue, &usartRxItem, &higherPriorityTaskWoken);
|
|
}
|
|
|
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
|
}
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* @brief Function: SPI1_IRQHandler
|
|
*
|
|
* Dedicated Interrupt Service Routine for SPI1
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
void SPI1_IRQHandler (void)
|
|
{
|
|
static 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)
|
|
{
|
|
static 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 EXTI4_IRQHandler(void)
|
|
{
|
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
|
|
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
|
EXTI_ClearITPendingBit(EXTI_Line4);
|
|
|
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
|
}
|
|
|
|
void EXTI9_5_IRQHandler (void)
|
|
{
|
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
|
|
|
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
|
|
{
|
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
|
EXTI_ClearITPendingBit(EXTI_Line5);
|
|
}
|
|
else if (EXTI_GetITStatus(EXTI_Line6) != RESET)
|
|
{
|
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
|
EXTI_ClearITPendingBit(EXTI_Line6);
|
|
}
|
|
else if (EXTI_GetITStatus(EXTI_Line7) != RESET)
|
|
{
|
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
|
EXTI_ClearITPendingBit(EXTI_Line7);
|
|
}
|
|
else if (EXTI_GetITStatus(EXTI_Line8) != RESET)
|
|
{
|
|
LOGGER_INFO_ISR("EXT8 ISR");
|
|
EXTI_ClearITPendingBit(EXTI_Line8);
|
|
}
|
|
else if (EXTI_GetITStatus(EXTI_Line9) != RESET)
|
|
{
|
|
LOGGER_INFO_ISR("EXT9 ISR");
|
|
EXTI_ClearITPendingBit(EXTI_Line9);
|
|
}
|
|
|
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
|
}
|
|
|
|
|
|
extern struct Display* display;
|
|
void RTC_IRQHandler(void)
|
|
{
|
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
|
|
|
if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
|
|
{
|
|
/* Clear the RTC Second interrupt */
|
|
RTC_ClearITPendingBit(RTC_IT_SEC);
|
|
|
|
xSemaphoreGiveFromISR(rtc->secondSync, &higherPriorityTaskWoken);
|
|
Display_feedRefreshCounter(display);
|
|
if (ledGreen->status)
|
|
{
|
|
LED_turnOff(ledGreen);
|
|
}
|
|
else
|
|
{
|
|
LED_turnOn(ledGreen);
|
|
}
|
|
|
|
/* Wait until last write operation on RTC registers has finished */
|
|
RTC_WaitForLastTask();
|
|
|
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
|
}
|
|
}
|