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