STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/CEC/CEC_DataExchange/stm32f0xx_it.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file CEC/CEC_DataExchange/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_DataExchange 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] = {0}; 00049 __IO uint8_t ReceivedFrame1 = 0; 00050 uint8_t send_inc = 0, rcv_inc = 0; 00051 extern uint8_t HeaderBlockValueToSend; 00052 uint16_t TransErrorCode1 = 0; 00053 uint16_t RecepErrorCode = 0; 00054 uint8_t ByteNumber = 0; 00055 00056 /* Private function prototypes -----------------------------------------------*/ 00057 /* Private functions ---------------------------------------------------------*/ 00058 00059 /******************************************************************************/ 00060 /* Cortex-M0 Processor Exceptions Handlers */ 00061 /******************************************************************************/ 00062 00063 /** 00064 * @brief This function handles NMI exception. 00065 * @param None 00066 * @retval None 00067 */ 00068 void NMI_Handler(void) 00069 { 00070 } 00071 00072 /** 00073 * @brief This function handles Hard Fault exception. 00074 * @param None 00075 * @retval None 00076 */ 00077 void HardFault_Handler(void) 00078 { 00079 /* Go to infinite loop when Hard Fault exception occurs */ 00080 while (1) 00081 { 00082 } 00083 } 00084 00085 /** 00086 * @brief This function handles SVCall exception. 00087 * @param None 00088 * @retval None 00089 */ 00090 void SVC_Handler(void) 00091 { 00092 } 00093 00094 /** 00095 * @brief This function handles PendSVC exception. 00096 * @param None 00097 * @retval None 00098 */ 00099 void PendSV_Handler(void) 00100 { 00101 } 00102 00103 /** 00104 * @brief This function handles SysTick Handler. 00105 * @param None 00106 * @retval None 00107 */ 00108 void SysTick_Handler(void) 00109 { 00110 } 00111 00112 /******************************************************************************/ 00113 /* STM32F0xx Peripherals Interrupt Handlers */ 00114 /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 00115 /* available peripheral interrupt handler's name please refer to the startup */ 00116 /* file (startup_stm32f0xx.s). */ 00117 /******************************************************************************/ 00118 #ifdef USE_STM32072B_EVAL 00119 /** 00120 * @brief This function handles EXTI Lines 2 and 3 interrupts requests. 00121 * @param None 00122 * @retval None 00123 */ 00124 void EXTI2_3_IRQHandler(void) 00125 { 00126 00127 for (send_inc=0;send_inc<10;send_inc++) 00128 { 00129 TransmitBuffer[send_inc]=0; 00130 } 00131 00132 send_inc =0; 00133 STM_EVAL_LEDOff(LED1); 00134 STM_EVAL_LEDOff(LED2); 00135 STM_EVAL_LEDOff(LED3); 00136 STM_EVAL_LEDOff(LED4); 00137 00138 /* Generate rising edge on Joystick button to detect when we push Joystick button to initiate 00139 transmission */ 00140 if(EXTI_GetITStatus(RIGHT_BUTTON_EXTI_LINE) != RESET) 00141 { 00142 TransmitBuffer[send_inc++] = 0x46; 00143 ByteNumber = 0x02; 00144 00145 /* Clear RIGHT Button EXTI line pending bit */ 00146 EXTI_ClearITPendingBit(RIGHT_BUTTON_EXTI_LINE); 00147 } 00148 else if(EXTI_GetITStatus(LEFT_BUTTON_EXTI_LINE) != RESET) 00149 { 00150 TransmitBuffer[send_inc++] = 0x9F; 00151 ByteNumber = 0x02; 00152 00153 /* Clear LEFT Button EXTI line pending bit */ 00154 EXTI_ClearITPendingBit(LEFT_BUTTON_EXTI_LINE); 00155 } 00156 00157 send_inc =0; 00158 /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */ 00159 CEC_SendData(HeaderBlockValueToSend); 00160 00161 /* Initiate Message Transmission */ 00162 CEC_StartOfMessage(); 00163 00164 } 00165 #endif /* USE_STM32072B_EVAL */ 00166 00167 /** 00168 * @brief This function handles EXTI Lines 4 to 15 interrupts requests. 00169 * @param None 00170 * @retval None 00171 */ 00172 void EXTI4_15_IRQHandler(void) 00173 { 00174 00175 for (send_inc=0;send_inc<10;send_inc++) 00176 { 00177 TransmitBuffer[send_inc]=0; 00178 } 00179 00180 send_inc =0; 00181 STM_EVAL_LEDOff(LED1); 00182 STM_EVAL_LEDOff(LED2); 00183 STM_EVAL_LEDOff(LED3); 00184 STM_EVAL_LEDOff(LED4); 00185 00186 /* Generate rising edge on Joystick button to detect when we push Joystick button to initiate 00187 transmission */ 00188 00189 if(EXTI_GetITStatus(UP_BUTTON_EXTI_LINE) != RESET) 00190 { 00191 TransmitBuffer[send_inc++] = 0x44; 00192 TransmitBuffer[send_inc++] = 0x41; 00193 ByteNumber = 0x03; 00194 00195 /* Clear UP Button EXTI line pending bit */ 00196 EXTI_ClearITPendingBit(UP_BUTTON_EXTI_LINE); 00197 } 00198 #ifdef USE_STM320518_EVAL 00199 else if(EXTI_GetITStatus(RIGHT_BUTTON_EXTI_LINE) != RESET) 00200 { 00201 TransmitBuffer[send_inc++] = 0x46; 00202 ByteNumber = 0x02; 00203 00204 /* Clear RIGHT Button EXTI line pending bit */ 00205 EXTI_ClearITPendingBit(RIGHT_BUTTON_EXTI_LINE); 00206 } 00207 else if(EXTI_GetITStatus(LEFT_BUTTON_EXTI_LINE) != RESET) 00208 { 00209 TransmitBuffer[send_inc++] = 0x9F; 00210 ByteNumber = 0x02; 00211 00212 /* Clear LEFT Button EXTI line pending bit */ 00213 EXTI_ClearITPendingBit(LEFT_BUTTON_EXTI_LINE); 00214 } 00215 #endif /* USE_STM320518_EVAL */ 00216 else if(EXTI_GetITStatus(DOWN_BUTTON_EXTI_LINE) != RESET) 00217 { 00218 TransmitBuffer[send_inc++] = 0x44; 00219 TransmitBuffer[send_inc++] = 0x42; 00220 ByteNumber = 0x03; 00221 00222 /* Clear DOWN Button EXTI line pending bit */ 00223 EXTI_ClearITPendingBit(DOWN_BUTTON_EXTI_LINE); 00224 } 00225 00226 send_inc =0; 00227 /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */ 00228 CEC_SendData(HeaderBlockValueToSend); 00229 00230 /* Initiate Message Transmission */ 00231 CEC_StartOfMessage(); 00232 00233 } 00234 00235 /** 00236 * @brief This function handles CEC global interrupt request. 00237 * @param None 00238 * @retval None 00239 */ 00240 #ifdef USE_STM320518_EVAL 00241 void CEC_IRQHandler(void) 00242 { 00243 /********************** Reception *******************************************/ 00244 /* Check if a reception error occured */ 00245 if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR)) 00246 { 00247 RecepErrorCode = CEC->ISR; 00248 CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR); 00249 ReceivedFrame1 = 2; 00250 } 00251 00252 if (CEC_GetITStatus(CEC_IT_RXBR)) 00253 { 00254 /* Check if the byte received is a Header */ 00255 if (rcv_inc == 0) 00256 { 00257 ReceiveBuffer[rcv_inc] = ((CEC_ReceiveData() >> 4) & 0x0F); 00258 rcv_inc++; 00259 } 00260 else /* Receive each byte except header and opcode in the reception buffer */ 00261 { 00262 ReceiveBuffer[rcv_inc] = CEC_ReceiveData(); 00263 rcv_inc++; 00264 } 00265 CEC_ClearITPendingBit(CEC_IT_RXBR); 00266 } 00267 00268 /* Check if the byte received is the last one of the message */ 00269 if (CEC_GetITStatus(CEC_IT_RXEND)) 00270 { 00271 ReceivedFrame1 = 1; 00272 00273 /* Clear all reception flags */ 00274 CEC_ClearITPendingBit(CEC_IT_RXEND); 00275 } 00276 00277 /********************** Transmission ****************************************/ 00278 /* Check if a transmission error occurred */ 00279 if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST)) 00280 { 00281 TransErrorCode1 = CEC->ISR; 00282 CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST); 00283 /* KO */ 00284 /* Turn on LED3 */ 00285 STM_EVAL_LEDOn(LED3); 00286 #ifdef LCD_DISPLAY 00287 LCD_SetBackColor(LCD_COLOR_RED); 00288 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status : Failed"); 00289 #endif /* LCD_DISPLAY */ 00290 } 00291 00292 /* Check if end of message bit is set in the data to be transmitted */ 00293 if (CEC_GetITStatus(CEC_IT_TXEND)) 00294 { 00295 CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR); 00296 /* OK */ 00297 /* Turn on LED1 */ 00298 STM_EVAL_LEDOn(LED1); 00299 #ifdef LCD_DISPLAY 00300 LCD_SetBackColor(LCD_COLOR_CYAN); 00301 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status: Succeeded"); 00302 #endif /* LCD_DISPLAY */ 00303 } 00304 /* Check if data byte has been sent */ 00305 else if (CEC_GetITStatus(CEC_IT_TXBR)) 00306 { 00307 /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */ 00308 if (send_inc == (ByteNumber - 1)) 00309 { 00310 CEC_EndOfMessage(); 00311 CEC_SendData(TransmitBuffer[send_inc++]); 00312 } 00313 else 00314 { 00315 /* Put the byte in the TX Buffer */ 00316 CEC_SendData(TransmitBuffer[send_inc++]); 00317 } 00318 CEC_ClearITPendingBit(CEC_IT_TXBR); 00319 } 00320 } 00321 #else 00322 void CEC_CAN_IRQHandler(void) 00323 { 00324 /********************** Reception *******************************************/ 00325 /* Check if a reception error occured */ 00326 if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR)) 00327 { 00328 RecepErrorCode = CEC->ISR; 00329 CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR); 00330 ReceivedFrame1 = 2; 00331 } 00332 00333 if (CEC_GetITStatus(CEC_IT_RXBR)) 00334 { 00335 /* Check if the byte received is a Header */ 00336 if (rcv_inc == 0) 00337 { 00338 ReceiveBuffer[rcv_inc] = ((CEC_ReceiveData() >> 4) & 0x0F); 00339 rcv_inc++; 00340 } 00341 else /* Receive each byte except header and opcode in the reception buffer */ 00342 { 00343 ReceiveBuffer[rcv_inc] = CEC_ReceiveData(); 00344 rcv_inc++; 00345 } 00346 CEC_ClearITPendingBit(CEC_IT_RXBR); 00347 } 00348 00349 /* Check if the byte received is the last one of the message */ 00350 if (CEC_GetITStatus(CEC_IT_RXEND)) 00351 { 00352 ReceivedFrame1 = 1; 00353 00354 /* Clear all reception flags */ 00355 CEC_ClearITPendingBit(CEC_IT_RXEND); 00356 } 00357 00358 /********************** Transmission ****************************************/ 00359 /* Check if a transmission error occurred */ 00360 if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST)) 00361 { 00362 TransErrorCode1 = CEC->ISR; 00363 CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST); 00364 /* KO */ 00365 /* Turn on LED3 */ 00366 STM_EVAL_LEDOn(LED3); 00367 #ifdef LCD_DISPLAY 00368 LCD_SetBackColor(LCD_COLOR_RED); 00369 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status : Failed"); 00370 #endif /* LCD_DISPLAY */ 00371 } 00372 00373 /* Check if end of message bit is set in the data to be transmitted */ 00374 if (CEC_GetITStatus(CEC_IT_TXEND)) 00375 { 00376 CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR); 00377 /* OK */ 00378 /* Turn on LED1 */ 00379 STM_EVAL_LEDOn(LED1); 00380 #ifdef LCD_DISPLAY 00381 LCD_SetBackColor(LCD_COLOR_CYAN); 00382 LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status: Succeeded"); 00383 #endif /* LCD_DISPLAY */ 00384 } 00385 /* Check if data byte has been sent */ 00386 else if (CEC_GetITStatus(CEC_IT_TXBR)) 00387 { 00388 /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */ 00389 if (send_inc == (ByteNumber - 1)) 00390 { 00391 CEC_EndOfMessage(); 00392 CEC_SendData(TransmitBuffer[send_inc++]); 00393 } 00394 else 00395 { 00396 /* Put the byte in the TX Buffer */ 00397 CEC_SendData(TransmitBuffer[send_inc++]); 00398 } 00399 CEC_ClearITPendingBit(CEC_IT_TXBR); 00400 } 00401 } 00402 #endif /* USE_STM320518_EVAL */ 00403 00404 00405 /** 00406 * @brief This function handles PPP interrupt request. 00407 * @param None 00408 * @retval None 00409 */ 00410 /*void PPP_IRQHandler(void) 00411 { 00412 }*/ 00413 00414 /** 00415 * @} 00416 */ 00417 00418 /** 00419 * @} 00420 */ 00421 00422 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/