STM32F10x_StdPeriph_Examples/CEC/stm32f10x_it.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    CEC/stm32f10x_it.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main Interrupt Service Routines.
00008   *          This file provides template for all exceptions handler and 
00009   *          peripherals interrupt service routine.
00010   ******************************************************************************
00011   * @copy
00012   *
00013   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00014   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00015   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00016   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00017   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00018   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00019   *
00020   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00021   */ 
00022 
00023 /* Includes ------------------------------------------------------------------*/
00024 #include "stm32f10x_it.h"
00025 #include "stm32_eval.h"
00026 
00027 /** @addtogroup STM32F10x_StdPeriph_Examples
00028   * @{
00029   */
00030 
00031 /** @addtogroup CEC_Example
00032   * @{
00033   */ 
00034 
00035 /* Private typedef -----------------------------------------------------------*/
00036 /* Private define ------------------------------------------------------------*/
00037 /* Private macro -------------------------------------------------------------*/
00038 /* Private variables ---------------------------------------------------------*/
00039 /* Receive buffer */
00040 uint8_t ReceiveBuffer[10];
00041 /* Transmit buffer */
00042 uint8_t TransmitBuffer[10] = {0xDF, 0x12, 0xD3, 0x56, 0x97, 
00043                               0xA1, 0xEC, 0x7B, 0x4F, 0x22};
00044 __IO uint8_t ReceivedFrame = 0;
00045 uint8_t send_inc = 0, rcv_inc = 0;
00046 uint8_t HeaderBlockValueToSend = 0;
00047 uint8_t InitiatorAddress = 0;
00048 uint8_t TransErrorCode = 0;
00049 uint8_t RecepErrorCode = 0;
00050 extern uint8_t ByteNumber;
00051 
00052 /* Private function prototypes -----------------------------------------------*/
00053 /* Private functions ---------------------------------------------------------*/
00054 
00055 /******************************************************************************/
00056 /*            Cortex-M3 Processor Exceptions Handlers                         */
00057 /******************************************************************************/
00058 
00059 /**
00060   * @brief   This function handles NMI exception.
00061   * @param  None
00062   * @retval None
00063   */
00064 void NMI_Handler(void)
00065 {
00066 }
00067 
00068 /**
00069   * @brief  This function handles Hard Fault exception.
00070   * @param  None
00071   * @retval None
00072   */
00073 void HardFault_Handler(void)
00074 {
00075   /* Go to infinite loop when Hard Fault exception occurs */
00076   while (1)
00077   {
00078   }
00079 }
00080 
00081 /**
00082   * @brief  This function handles Memory Manage exception.
00083   * @param  None
00084   * @retval None
00085   */
00086 void MemManage_Handler(void)
00087 {
00088   /* Go to infinite loop when Memory Manage exception occurs */
00089   while (1)
00090   {
00091   }
00092 }
00093 
00094 /**
00095   * @brief  This function handles Bus Fault exception.
00096   * @param  None
00097   * @retval None
00098   */
00099 void BusFault_Handler(void)
00100 {
00101   /* Go to infinite loop when Bus Fault exception occurs */
00102   while (1)
00103   {
00104   }
00105 }
00106 
00107 /**
00108   * @brief  This function handles Usage Fault exception.
00109   * @param  None
00110   * @retval None
00111   */
00112 void UsageFault_Handler(void)
00113 {
00114   /* Go to infinite loop when Usage Fault exception occurs */
00115   while (1)
00116   {
00117   }
00118 }
00119 
00120 /**
00121   * @brief  This function handles SVCall exception.
00122   * @param  None
00123   * @retval None
00124   */
00125 void SVC_Handler(void)
00126 {
00127 }
00128 
00129 /**
00130   * @brief  This function handles Debug Monitor exception.
00131   * @param  None
00132   * @retval None
00133   */
00134 void DebugMon_Handler(void)
00135 {
00136 }
00137 
00138 /**
00139   * @brief  This function handles PendSVC exception.
00140   * @param  None
00141   * @retval None
00142   */
00143 void PendSV_Handler(void)
00144 {
00145 }
00146 
00147 /**
00148   * @brief  This function handles SysTick Handler.
00149   * @param  None
00150   * @retval None
00151   */
00152 void SysTick_Handler(void)
00153 {
00154 }
00155 
00156 /**
00157   * @brief  This function handles EXTI Lines 9 to 5 interrupts requests.
00158   * @param  None
00159   * @retval None
00160   */
00161 void EXTI9_5_IRQHandler(void)
00162 {
00163   /* Generate rising edge on Key button to detect when we push key button to initiate 
00164      transmission */
00165   if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET)
00166   {
00167     /* Turn on LED3 */
00168     STM_EVAL_LEDOn(LED3);
00169 
00170     /* Build the Header block to send */
00171     HeaderBlockValueToSend = (((MY_DEVICE_ADDRESS & 0xF) << 4) | (FOLLOWER & 0xF));
00172 
00173     /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */
00174     CEC_SendDataByte(HeaderBlockValueToSend);
00175 
00176     /* Initiate Message Transmission */
00177     CEC_StartOfMessage();
00178 
00179     /* Clear Key Button EXTI line pending bit */
00180     EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE);
00181   }
00182 }
00183 
00184 /**
00185   * @brief  This function handles CEC global interrupt request.
00186   * @param  None
00187   * @retval None
00188   */
00189 void CEC_IRQHandler(void)
00190 {
00191   /* Turn on LED4 */
00192   STM_EVAL_LEDOn(LED4);
00193 /********************** Reception *********************************************/
00194   /* Check if a reception error occured */
00195   if (CEC_GetFlagStatus(CEC_FLAG_RERR))
00196   {
00197     /* Set receive status bit (Error) */
00198     RecepErrorCode = CEC->ESR;
00199     CEC_ClearFlag(CEC_FLAG_RERR | CEC_FLAG_RSOM | CEC_FLAG_REOM  | CEC_FLAG_RBTF);
00200   }
00201   else if (CEC_GetFlagStatus(CEC_FLAG_RBTF))
00202   {
00203     /* Check if the byte received is the last one of the message */
00204     if (CEC_GetFlagStatus(CEC_FLAG_REOM))
00205     {
00206       ReceiveBuffer[rcv_inc] = CEC_ReceiveDataByte();
00207       rcv_inc++;
00208       ReceivedFrame = 1;
00209     }
00210     /* Check if the byte received is a Header */
00211     else if (CEC_GetFlagStatus(CEC_FLAG_RSOM))
00212     {
00213  
00214       InitiatorAddress = ((CEC_ReceiveDataByte() >> 4) & 0x0F);
00215       rcv_inc = 0;
00216     }
00217     /* Receive each byte except header in the reception buffer */
00218     else 
00219     {
00220       ReceiveBuffer[rcv_inc] = CEC_ReceiveDataByte();
00221       rcv_inc++;
00222     }
00223     /* Clear all reception flags */
00224     CEC_ClearFlag(CEC_FLAG_RSOM | CEC_FLAG_REOM  | CEC_FLAG_RBTF);
00225   }
00226 
00227 /********************** Transmission ******************************************/
00228   /* Check if a transmission error occured */
00229   if (CEC_GetFlagStatus(CEC_FLAG_TERR))
00230   {
00231     TransErrorCode = CEC->ESR;
00232     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
00233    
00234   }
00235   /* Check if end of message bit is set in the data to be transmitted */
00236   else if (CEC_GetFlagStatus(CEC_FLAG_TEOM))
00237   {
00238     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_RBTF);
00239     CEC_EndOfMessageCmd(DISABLE);
00240   }
00241   /* Check if data byte has been sent */
00242   else if (CEC_GetFlagStatus(CEC_FLAG_TBTRF))
00243   {
00244     /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */
00245     if (send_inc == (ByteNumber - 1))
00246     {
00247       CEC_SendDataByte(TransmitBuffer[send_inc]);
00248       send_inc++;
00249       CEC_ClearFlag(CEC_FLAG_TBTRF);
00250       CEC_EndOfMessageCmd(ENABLE);
00251     }
00252     else
00253     {
00254       /* Put the byte in the TX Buffer */
00255       CEC_SendDataByte(TransmitBuffer[send_inc]);
00256       send_inc++;
00257       CEC_ClearFlag(CEC_FLAG_TBTRF);
00258     }
00259   }
00260 }
00261 
00262 /******************************************************************************/
00263 /*                 STM32F10x Peripherals Interrupt Handlers                   */
00264 /*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
00265 /*  available peripheral interrupt handler's name please refer to the startup */
00266 /*  file (startup_stm32f10x_xx.s).                                            */
00267 /******************************************************************************/
00268 
00269 /**
00270   * @brief  This function handles PPP interrupt request.
00271   * @param  None
00272   * @retval None
00273   */
00274 /*void PPP_IRQHandler(void)
00275 {
00276 }*/
00277 
00278 /**
00279   * @}
00280   */ 
00281 
00282 /**
00283   * @}
00284   */ 
00285   
00286 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32