// ----------------------------------------------------------------------------- /// @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 "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) // { // } /** ---------------------------------------------------------------------------- * @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 EXTI0_IRQHandler(void) { static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(interlock->semaphore, &higherPriorityTaskWoken); EXTI_ClearITPendingBit(EXTI_Line0); portEND_SWITCHING_ISR(higherPriorityTaskWoken); } void EXTI1_IRQHandler(void) { static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(interlock->semaphore, &higherPriorityTaskWoken); EXTI_ClearITPendingBit(EXTI_Line1); 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) { EXTI_ClearITPendingBit(EXTI_Line8); } else if (EXTI_GetITStatus(EXTI_Line9) != RESET) { EXTI_ClearITPendingBit(EXTI_Line9); } portEND_SWITCHING_ISR(higherPriorityTaskWoken); }