STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/CEC/CEC_MultiAddress/stm32f0xx_it.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file CEC/CEC_MultiAddress/stm32f0xx_it.c 00004 * @author MCD Application Team 00005 * @version V1.4.0 00006 * @date 24-July-2014 00007 * @brief Main Interrupt Service Routines. 00008 * This file provides template for all exceptions handler and 00009 * peripherals interrupt service routine. 00010 ****************************************************************************** 00011 * @attention 00012 * 00013 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00014 * 00015 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00016 * You may not use this file except in compliance with the License. 00017 * You may obtain a copy of the License at: 00018 * 00019 * http://www.st.com/software_license_agreement_liberty_v2 00020 * 00021 * Unless required by applicable law or agreed to in writing, software 00022 * distributed under the License is distributed on an "AS IS" BASIS, 00023 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00024 * See the License for the specific language governing permissions and 00025 * limitations under the License. 00026 * 00027 ****************************************************************************** 00028 */ 00029 00030 /* Includes ------------------------------------------------------------------*/ 00031 #include "stm32f0xx_it.h" 00032 00033 /** @addtogroup STM32F0xx_StdPeriph_Examples 00034 * @{ 00035 */ 00036 00037 /** @addtogroup CEC_MultiAddress 00038 * @{ 00039 */ 00040 00041 /* Private typedef -----------------------------------------------------------*/ 00042 /* Private define ------------------------------------------------------------*/ 00043 /* Private macro -------------------------------------------------------------*/ 00044 /* Private variables ---------------------------------------------------------*/ 00045 /* Receive buffer */ 00046 uint8_t ReceiveBuffer[10]; 00047 /* Transmit buffer */ 00048 uint8_t TransmitBuffer[10] = {0xDF, 0x12, 0xD3, 0x56, 0x97, 00049 0xA1, 0xEC, 0x7B, 0x4F, 0x22}; 00050 __IO uint8_t CECReceivedFrame = 0; 00051 __IO uint8_t send_inc = 0, rcv_inc = 0; 00052 uint8_t HeaderBlockValueToSend = 0; 00053 uint16_t CECTransErrorCode = 0, ReceiverAddress = 0; 00054 uint16_t RecepErrorCode = 0; 00055 uint8_t ByteNumber = 11; 00056 extern uint8_t MyLogicalAddress1, MyLogicalAddress2; 00057 extern uint8_t MyFollowerAddress1, MyFollowerAddress2; 00058 /* Private function prototypes -----------------------------------------------*/ 00059 /* Private functions ---------------------------------------------------------*/ 00060 00061 /******************************************************************************/ 00062 /* Cortex-M0 Processor Exceptions Handlers */ 00063 /******************************************************************************/ 00064 00065 /** 00066 * @brief This function handles NMI exception. 00067 * @param None 00068 * @retval None 00069 */ 00070 void NMI_Handler(void) 00071 { 00072 } 00073 00074 /** 00075 * @brief This function handles Hard Fault exception. 00076 * @param None 00077 * @retval None 00078 */ 00079 void HardFault_Handler(void) 00080 { 00081 /* Go to infinite loop when Hard Fault exception occurs */ 00082 while (1) 00083 { 00084 } 00085 } 00086 00087 /** 00088 * @brief This function handles SVCall exception. 00089 * @param None 00090 * @retval None 00091 */ 00092 void SVC_Handler(void) 00093 { 00094 } 00095 00096 /** 00097 * @brief This function handles PendSVC exception. 00098 * @param None 00099 * @retval None 00100 */ 00101 void PendSV_Handler(void) 00102 { 00103 } 00104 00105 /** 00106 * @brief This function handles SysTick Handler. 00107 * @param None 00108 * @retval None 00109 */ 00110 void SysTick_Handler(void) 00111 { 00112 } 00113 /******************************************************************************/ 00114 /* STM32F0xx Peripherals Interrupt Handlers */ 00115 /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 00116 /* available peripheral interrupt handler's name please refer to the startup */ 00117 /* file (startup_stm32f0xx.s). */ 00118 /******************************************************************************/ 00119 #ifdef USE_STM320518_EVAL 00120 #if defined (DEVICE_1) 00121 /** 00122 * @brief This function handles EXTI Lines 4 to 15 interrupts requests. 00123 * @param None 00124 * @retval None 00125 */ 00126 void EXTI4_15_IRQHandler(void) 00127 { 00128 STM_EVAL_LEDOff(LED1); 00129 STM_EVAL_LEDOff(LED2); 00130 STM_EVAL_LEDOff(LED3); 00131 STM_EVAL_LEDOff(LED4); 00132 00133 /* Generate rising edge on Joystick button to detect when we push Joystick button to initiate 00134 transmission */ 00135 if(EXTI_GetITStatus(RIGHT_BUTTON_EXTI_LINE) != RESET) 00136 { 00137 /* Build the Header block to send */ 00138 HeaderBlockValueToSend = (((MyLogicalAddress1 & 0xF) << 4)|(MyFollowerAddress1 & 0xF)); 00139 00140 /* Clear RIGHT Button EXTI line pending bit */ 00141 EXTI_ClearITPendingBit(RIGHT_BUTTON_EXTI_LINE); 00142 } 00143 else if(EXTI_GetITStatus(LEFT_BUTTON_EXTI_LINE) != RESET) 00144 { 00145 /* Build the Header block to send */ 00146 HeaderBlockValueToSend = (((MyLogicalAddress1 & 0xF) << 4)|(MyFollowerAddress2 & 0xF)); 00147 00148 /* Clear LEFT Button EXTI line pending bit */ 00149 EXTI_ClearITPendingBit(LEFT_BUTTON_EXTI_LINE); 00150 } 00151 00152 /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */ 00153 CEC_SendData(HeaderBlockValueToSend); 00154 00155 /* Initiate Message Transmission */ 00156 CEC_StartOfMessage(); 00157 } 00158 #endif /* DEVICE_1 */ 00159 00160 /** 00161 * @brief This function handles CEC global interrupt request. 00162 * @param None 00163 * @retval None 00164 */ 00165 void CEC_IRQHandler(void) 00166 { 00167 /********************** Reception *******************************************/ 00168 /* Check if a reception error occured */ 00169 if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR)) 00170 { 00171 RecepErrorCode = CEC->ISR; 00172 CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR); 00173 CECReceivedFrame = 2; 00174 } 00175 00176 if (CEC_GetITStatus(CEC_IT_RXBR)) 00177 { 00178 /* Check if the byte received is a Header */ 00179 if (rcv_inc == 0) 00180 { 00181 ReceiverAddress = (CEC_ReceiveData() & 0x0F); 00182 rcv_inc++; 00183 } 00184 else /* Receive each byte except header and opcode in the reception buffer */ 00185 { 00186 ReceiveBuffer[rcv_inc-1] = CEC_ReceiveData(); 00187 rcv_inc++; 00188 } 00189 CEC_ClearITPendingBit(CEC_IT_RXBR); 00190 } 00191 00192 /* Check if the byte received is the last one of the message */ 00193 if (CEC_GetITStatus(CEC_IT_RXEND)) 00194 { 00195 CECReceivedFrame = 1; 00196 rcv_inc = 0; 00197 00198 /* Clear all reception flags */ 00199 CEC_ClearITPendingBit(CEC_IT_RXEND); 00200 } 00201 00202 /********************** Transmission ****************************************/ 00203 /* Check if a transmission error occurred */ 00204 if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST)) 00205 { 00206 CECTransErrorCode = CEC->ISR; 00207 CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST); 00208 /* KO */ 00209 /* Turn on LED3 */ 00210 STM_EVAL_LEDOn(LED3); 00211 #ifdef LCD_DISPLAY 00212 LCD_SetBackColor(LCD_COLOR_RED); 00213 LCD_SetTextColor(LCD_COLOR_WHITE); 00214 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status : Failed"); 00215 #endif /* LCD_DISPLAY */ 00216 } 00217 00218 /* Check if end of message bit is set in the data to be transmitted */ 00219 if (CEC_GetITStatus(CEC_IT_TXEND)) 00220 { 00221 CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR); 00222 /* OK */ 00223 /* Turn on LED1 */ 00224 STM_EVAL_LEDOn(LED1); 00225 #ifdef LCD_DISPLAY 00226 LCD_SetBackColor(LCD_COLOR_GREEN); 00227 LCD_SetTextColor(LCD_COLOR_WHITE); 00228 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status: Succeeded"); 00229 #endif /* LCD_DISPLAY */ 00230 } 00231 /* Check if data byte has been sent */ 00232 else if (CEC_GetITStatus(CEC_IT_TXBR)) 00233 { 00234 /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */ 00235 if (send_inc == (ByteNumber - 1)) 00236 { 00237 CEC_EndOfMessage(); 00238 CEC_SendData(TransmitBuffer[send_inc++]); 00239 send_inc=0; 00240 } 00241 else 00242 { 00243 /* Put the byte in the TX Buffer */ 00244 CEC_SendData(TransmitBuffer[send_inc++]); 00245 } 00246 CEC_ClearITPendingBit(CEC_IT_TXBR); 00247 } 00248 } 00249 #else 00250 #if defined (DEVICE_1) 00251 /** 00252 * @brief This function handles EXTI Lines 2 and 3 interrupts requests. 00253 * @param None 00254 * @retval None 00255 */ 00256 void EXTI2_3_IRQHandler(void) 00257 { 00258 STM_EVAL_LEDOff(LED1); 00259 STM_EVAL_LEDOff(LED2); 00260 STM_EVAL_LEDOff(LED3); 00261 STM_EVAL_LEDOff(LED4); 00262 00263 /* Generate rising edge on Joystick button to detect when we push Joystick button to initiate 00264 transmission */ 00265 if(EXTI_GetITStatus(RIGHT_BUTTON_EXTI_LINE) != RESET) 00266 { 00267 /* Build the Header block to send */ 00268 HeaderBlockValueToSend = (((MyLogicalAddress1 & 0xF) << 4)|(MyFollowerAddress1 & 0xF)); 00269 00270 /* Clear RIGHT Button EXTI line pending bit */ 00271 EXTI_ClearITPendingBit(RIGHT_BUTTON_EXTI_LINE); 00272 } 00273 else if(EXTI_GetITStatus(LEFT_BUTTON_EXTI_LINE) != RESET) 00274 { 00275 /* Build the Header block to send */ 00276 HeaderBlockValueToSend = (((MyLogicalAddress1 & 0xF) << 4)|(MyFollowerAddress2 & 0xF)); 00277 00278 /* Clear LEFT Button EXTI line pending bit */ 00279 EXTI_ClearITPendingBit(LEFT_BUTTON_EXTI_LINE); 00280 } 00281 00282 /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */ 00283 CEC_SendData(HeaderBlockValueToSend); 00284 00285 /* Initiate Message Transmission */ 00286 CEC_StartOfMessage(); 00287 } 00288 #endif /* DEVICE_1 */ 00289 00290 /** 00291 * @brief This function handles CEC global interrupt request. 00292 * @param None 00293 * @retval None 00294 */ 00295 void CEC_CAN_IRQHandler(void) 00296 { 00297 /********************** Reception *******************************************/ 00298 /* Check if a reception error occured */ 00299 if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR)) 00300 { 00301 RecepErrorCode = CEC->ISR; 00302 CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR); 00303 CECReceivedFrame = 2; 00304 } 00305 00306 if (CEC_GetITStatus(CEC_IT_RXBR)) 00307 { 00308 /* Check if the byte received is a Header */ 00309 if (rcv_inc == 0) 00310 { 00311 ReceiverAddress = (CEC_ReceiveData() & 0x0F); 00312 rcv_inc++; 00313 } 00314 else /* Receive each byte except header and opcode in the reception buffer */ 00315 { 00316 ReceiveBuffer[rcv_inc-1] = CEC_ReceiveData(); 00317 rcv_inc++; 00318 } 00319 CEC_ClearITPendingBit(CEC_IT_RXBR); 00320 } 00321 00322 /* Check if the byte received is the last one of the message */ 00323 if (CEC_GetITStatus(CEC_IT_RXEND)) 00324 { 00325 CECReceivedFrame = 1; 00326 rcv_inc = 0; 00327 00328 /* Clear all reception flags */ 00329 CEC_ClearITPendingBit(CEC_IT_RXEND); 00330 } 00331 00332 /********************** Transmission ****************************************/ 00333 /* Check if a transmission error occurred */ 00334 if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST)) 00335 { 00336 CECTransErrorCode = CEC->ISR; 00337 CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST); 00338 /* KO */ 00339 /* Turn on LED3 */ 00340 STM_EVAL_LEDOn(LED3); 00341 #ifdef LCD_DISPLAY 00342 LCD_SetBackColor(LCD_COLOR_RED); 00343 LCD_SetTextColor(LCD_COLOR_WHITE); 00344 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status : Failed"); 00345 #endif /* LCD_DISPLAY */ 00346 } 00347 00348 /* Check if end of message bit is set in the data to be transmitted */ 00349 if (CEC_GetITStatus(CEC_IT_TXEND)) 00350 { 00351 CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR); 00352 /* OK */ 00353 /* Turn on LED1 */ 00354 STM_EVAL_LEDOn(LED1); 00355 #ifdef LCD_DISPLAY 00356 LCD_SetBackColor(LCD_COLOR_GREEN); 00357 LCD_SetTextColor(LCD_COLOR_WHITE); 00358 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status: Succeeded"); 00359 #endif /* LCD_DISPLAY */ 00360 } 00361 /* Check if data byte has been sent */ 00362 else if (CEC_GetITStatus(CEC_IT_TXBR)) 00363 { 00364 /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */ 00365 if (send_inc == (ByteNumber - 1)) 00366 { 00367 CEC_EndOfMessage(); 00368 CEC_SendData(TransmitBuffer[send_inc++]); 00369 send_inc=0; 00370 } 00371 else 00372 { 00373 /* Put the byte in the TX Buffer */ 00374 CEC_SendData(TransmitBuffer[send_inc++]); 00375 } 00376 CEC_ClearITPendingBit(CEC_IT_TXBR); 00377 } 00378 } 00379 #endif /* USE_STM320518_EVAL */ 00380 00381 /** 00382 * @brief This function handles PPP interrupt request. 00383 * @param None 00384 * @retval None 00385 */ 00386 /*void PPP_IRQHandler(void) 00387 { 00388 }*/ 00389 00390 /** 00391 * @} 00392 */ 00393 00394 /** 00395 * @} 00396 */ 00397 00398 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/