⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flexray_handler.c

📁 基于freescale MC9S12XF512 MCU
💻 C
📖 第 1 页 / 共 2 页
字号:
        protocol_state = Fr_get_POC_state();    /* Load current POC state */
    }  
   
    /* Initialize startup */
    return_value = Fr_start_communication();
    if(return_value == FR_NOT_SUCCESS)
        Failed(4);   /* Call debug function in case of any error */
    
    protocol_state = Fr_get_POC_state();    /* Load current POC state */
    
    /* Wait till the FR CC is not in the FR_POCSTATE_NORMAL_ACTIVE */
    while(Fr_get_POC_state() != FR_POCSTATE_NORMAL_ACTIVE)  
    {
        protocol_state = Fr_get_POC_state();    /* Load current POC state */
    }
    
    protocol_state = Fr_get_POC_state();    /* Load current POC state */

    /* The first initialization of the MB 1 */
    tx_return_value = Fr_transmit_data(TX_SLOT_4, &tx_data_4[0], 16);
    if(tx_return_value == FR_TXMB_NO_ACCESS)
        Failed(4);   /* Call debug function in case of any error */

    /* The first initialization of the MB */
    tx_return_value = Fr_transmit_data(TX_SLOT_5, &tx_data_5[0], 16);
    if(tx_return_value == FR_TXMB_NO_ACCESS)
        Failed(6);   /* Call debug function in case of any error */
 
    /* The first initialization of the MB */
    tx_return_value = Fr_transmit_data(TX_SLOT_62, &tx_data_62[0], 8);
    if(tx_return_value == FR_TXMB_NO_ACCESS)
        Failed(7);   /* Call debug function in case of any error */

    /* The first initialization of the MB */
    tx_return_value = Fr_transmit_data(TX_SLOT_63, &tx_data_63[0], 8);
    if(tx_return_value == FR_TXMB_NO_ACCESS)
        Failed(8);   /* Call debug function in case of any error */

    
    /* No FlexRay interrupt is enabled */

    wakeup_status = Fr_get_wakeup_state();  /* Load current wakeup status */
}
    
/******************************************************************************/
/**
* \brief    FlexRay events handler
* \author   Jaime Orozco
* \param    void
* \return   void
*/
    
void vfnFlexRay_Handler(void)
{
    /* Check whether or not the communication cycle has been started  */
    cycle_starts = Fr_check_cycle_start(&current_cycle);
        
        if(cycle_starts)    /* Did the communication cycle start? */
        {
            /* TRANSMIT SINGLE BUFFER - update transmit MB 1 with new data */
            tx_status = Fr_check_tx_status(TX_SLOT_4);  
            
            /* Check whether data has been transmitted */
            if(tx_status == FR_TRANSMITTED)
            {
                tx_data_4[0] -= 100;    /* Decrement variable */
                
                /* Update transmit MB with new data */
                tx_return_value = Fr_transmit_data(TX_SLOT_4, &tx_data_4[0], 16);  
				
				/* Increment variable in case of MB access error */
				if(tx_return_value == FR_TXMB_NO_ACCESS) mb_access_error++; 
				
				LED_OFF(D25);   /* Clear LED indicator */
             }

            /* TRANSMIT DOUBLE BUFFER 
               update double transmit MB 4 with new data */
            /* Check whether data has been transferred or transmitted */
            tx_status = Fr_check_tx_status(TX_SLOT_5);  
            
            /* Update commit side of double MB in case that 
               Internal Message Transfer has been performed */
            if((tx_status == FR_TRANSMITTED) || 
               (tx_status == FR_INTERNAL_MESSAGE_TRANSFER_DONE))
            {
                tx_data_5[0] += 100;  /* Increment variable */
                
                /* Update transmit MB with new data */
                tx_return_value = Fr_transmit_data(TX_SLOT_5, &tx_data_5[0], 16); 
                 
                /* Increment variable in case of MB access error */
                if(tx_return_value == FR_TXMB_NO_ACCESS) mb_access_error++;                                  
            }

            /* TRANSMIT BUFFER - update transmit MB 11 with new data */
            tx_status = Fr_check_tx_status(TX_SLOT_62);   
            
            /* Check whether data has been transmitted */
            if(tx_status == FR_TRANSMITTED)
            {
                tx_data_62[0] += 50;    /* Increment variable */
                
                /* Update transmit MB with new data */
                tx_return_value = Fr_transmit_data(TX_SLOT_62, &tx_data_62[0], 0); 
                
                /* Increment variable in case of MB access error */
                if(tx_return_value == FR_TXMB_NO_ACCESS) mb_access_error++;        
                
                LED_OFF(D28);   /* Clear LED indicator */
            }

            /* RECEIVE BUFFER - copy received data from receive MB 2 */
            /* Check whether the MB has been updated in last matching slot */            
            rx_status = Fr_check_rx_status(RX_SLOT_1);  
            
            if(rx_status == FR_RECEIVED) /* MB data field updated in last slot */
            {
                /* Copy data into given data array */
                rx_return_value = Fr_receive_data(RX_SLOT_1, &rx_data_1[0],
                                                  &rx_data_length, &rx_status_slot);
                                                  
                /* Increment variable - to be transmitted later on */                                  
                tx_data_5[1]++;        
                
                /* Copy slot status into variable - to be transmitted later on */                 
                tx_data_5[2] = rx_status_slot;     
                     
                /* Increment variable in case of MB access error */
                if(rx_return_value == FR_RXMB_NO_ACCESS) mb_access_error++;        
                
                LED_OFF(D23);   /* Clear LED indicator */
            }
            
            /* Increment variable - to be transmitted later on */         
            tx_data_5[3]++;	
            						    
            /* Store current cycle number into transmit data array */
            tx_data_5[4] = current_cycle;              
            
            /* Check whether the CHI related error has been occured */
            /* Increment variable if CHI error occured  */
            if(Fr_check_CHI_error() != 0) chi_error++; 
            
            /* Store the number of the CHI related errors */ 
            tx_data_5[6] = chi_error;                   
            
            /* Check whether or not the frame transmission 
               across boundary has been occured */
            /* Increment variable if error occured */
            if(Fr_check_transmission_across_boundary(FR_CHANNEL_AB)) 
                transmission_across_boundary++;
            
            /* Store the number of errors */
            tx_data_5[7] = transmission_across_boundary;    
            
            /* Check whether or not the frame transmission in dynamic segment
               exceeded the dynamic segment boundary */
            /* Increment variable if error occured */
            if(Fr_check_violation(FR_CHANNEL_AB)) violation++;
            
            tx_data_5[8] = violation;    /* Store the number of errors */
        }

        /* Check whether or not the protocol engine has detected 
           an internal protocol error */
        /* TRUE -> Protocol engine goes into the FR_POCSTATE_HALT state */  
        protocol_error = Fr_check_internal_protocol_error();    

        /* TRANSMIT BUFFER - update transmit MB 12 with new data */
        /* Check whether data has been transmitted */
        tx_status = Fr_check_tx_status(TX_SLOT_63);     
        if(tx_status == FR_TRANSMITTED)
        {
            tx_data_63[0] -= 50;    /* Decrement variable */
            
            /* Update transmit MB with new data */
            tx_return_value = Fr_transmit_data(TX_SLOT_63, &tx_data_63[0], 0); 
            
            /* Increment variable in case of MB access error */ 
            if(tx_return_value == FR_TXMB_NO_ACCESS) mb_access_error++;                    
        }
        
        /* Store the value of access errors to the transmit data array */
    tx_data_5[5] = mb_access_error;   
    
}

/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -