コード例 #1
0
/**
  * @brief  This function handles CEC interrupt request.
  * @param  None
  * @retval None
  */
void CEC_IRQHandler(void)
{
/********************** Reception *******************************************/
  /* Check if a reception error occurred */
  if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR))
  {
    CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR);
    ReceivedFrame = 2;
  }

  if (CEC_GetITStatus(CEC_IT_RXBR))
  { 
    /* Check if the byte received is a Header */
    if (rcv_inc == 0)
    {   
      Tab_Rx[rcv_inc] = CEC_ReceiveData();
      rcv_inc++; 
    }
    else /* Receive each byte except header and opcode in the reception buffer */
    {
      Tab_Rx[rcv_inc] = CEC_ReceiveData();
      rcv_inc++;
    }
    CEC_ClearITPendingBit(CEC_IT_RXBR);
  }

  /* Check if the byte received is the last one of the message */
  if (CEC_GetITStatus(CEC_IT_RXEND))
  {  
    ReceivedFrame = 1;

    /* Clear all reception flags */
    CEC_ClearITPendingBit(CEC_IT_RXEND);
    rcv_inc =0;
  }

  /********************** Transmission ****************************************/
  /* Check if a transmission error occurred */
  if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST))
  {
    CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST);
    /* KO */
    /* Turn on LED3 */
  }
  
  /* Check if end of message bit is set in the data to be transmitted */
  if (CEC_GetITStatus(CEC_IT_TXEND))
  {
    CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR);
    send_inc = 0;
    /* OK */
    /* Turn on LED1 */
  }
  /* Check if data byte has been sent */
  else if (CEC_GetITStatus(CEC_IT_TXBR))
  {
    /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */
     if (send_inc ==  TxSize )
    {
      CEC_EndOfMessage();
      CEC_SendData(Tab_Tx[send_inc++]);
    }
    else
    {
      /* Put the byte in the TX Buffer */
      CEC_SendData(Tab_Tx[send_inc++]);
    }
    CEC_ClearITPendingBit(CEC_IT_TXBR);
  }
}
コード例 #2
0
ファイル: stm32f0xx_it.c プロジェクト: Amna2013/stm32-test
/**
  * @brief  This function handles CEC global interrupt request.
  * @param  None
  * @retval None
  */
void CEC_IRQHandler(void)
{
  /********************** Reception *******************************************/
  /* Check if a reception error occured */
  if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR))
  {
    RecepErrorCode = CEC->ISR;
    CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR);
    CECReceivedFrame = 2;
  }

  if (CEC_GetITStatus(CEC_IT_RXBR))
  {
    /* Check if the byte received is a Header */
    if (rcv_inc == 0)
    {
      ReceiverAddress = (CEC_ReceiveData() & 0x0F);
      rcv_inc++;
    }
    else /* Receive each byte except header and opcode in the reception buffer */
    {
      ReceiveBuffer[rcv_inc-1] = CEC_ReceiveData();
      rcv_inc++;
    }
    CEC_ClearITPendingBit(CEC_IT_RXBR);
  }

  /* Check if the byte received is the last one of the message */
  if (CEC_GetITStatus(CEC_IT_RXEND))
  {
    CECReceivedFrame = 1;
    rcv_inc = 0;

    /* Clear all reception flags */
    CEC_ClearITPendingBit(CEC_IT_RXEND);
  }

  /********************** Transmission ****************************************/
  /* Check if a transmission error occurred */
  if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST))
  {
    CECTransErrorCode = CEC->ISR;
    CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST);
    /* KO */
    /* Turn on LED3 */
    STM_EVAL_LEDOn(LED3);
#ifdef LCD_DISPLAY
    LCD_SetBackColor(LCD_COLOR_RED);
    LCD_SetTextColor(LCD_COLOR_WHITE);
    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status : Failed");
#endif
  }

  /* Check if end of message bit is set in the data to be transmitted */
  if (CEC_GetITStatus(CEC_IT_TXEND))
  {
    CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR);
    /* OK */
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);
#ifdef LCD_DISPLAY
    LCD_SetBackColor(LCD_COLOR_GREEN);
    LCD_SetTextColor(LCD_COLOR_WHITE);
    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Send status: Succeeded");
#endif
  }
  /* Check if data byte has been sent */
  else if (CEC_GetITStatus(CEC_IT_TXBR))
  {
    /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */
     if (send_inc == (ByteNumber - 1))
    {
      CEC_EndOfMessage();
      CEC_SendData(TransmitBuffer[send_inc++]);
      send_inc=0;
    }
    else
    {
      /* Put the byte in the TX Buffer */
      CEC_SendData(TransmitBuffer[send_inc++]);
    }
    CEC_ClearITPendingBit(CEC_IT_TXBR);
  }
}