Receive ID from FLEXRAY Frame with an 16-bit MC9S12XF512MLM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Receive ID from FLEXRAY Frame with an 16-bit MC9S12XF512MLM

Jump to solution
925 Views
Kartoon67
Contributor III

Hi,

 

I’m using the microprocessor MC9S12XF512MLM from freescale company. And, we bought the Development Tool Card Freescale for developing a software. I have some questions about the example program include in the CD-ROM which is provided with the developing card.

They had made an function which can send a FLEXRAY frame, and a function for receiving that frame. This two works properly, but I have some problem to get the ID of my frame when I try to receive it.

 

Can you help me about that?

 

The program from receiving a frame it the following :

 

Fr_rx_MB_status_type Fr_receive_data(uint16 Fr_buffer_idx, uint16 *Fr_data_ptr,                                     uint8 *Fr_data_length_ptr,uint16 *Fr_slot_status_ptr){    volatile uint16 * FR_DATA_FAR header_MB_ptr;    // Message buffer header pointer    volatile uint16 * FR_DATA_FAR Fr_CC_data_ptr;   // Reference to data array    volatile uint16 temp_value_1 = 0;           // Temporary variable used for bit operation    volatile uint16 temp_value_2 = 0;           // Temporary variable used for bit operation    volatile uint16 Fr_MB_registers_offset_add_temp; // Temporary offset adress of message buffer registers    volatile uint8 Fr_data_length;              // Data payload length    uint16 Fr_p;                                // Temporary counter used for copying    // Temporary offset address of MB registers    //Fr_MB_registers_offset_add_temp = Fr_buffers_config_ptr[Fr_buffer_info_set_index].buffer_index_init * 4;    Fr_MB_registers_offset_add_temp = Fr_buffer_idx * 4;       // Read the MB Configuration, Control and Status reg.    temp_value_1 = Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp];        temp_value_1 |= FrMBCCSR_LCKT;      // Set Lock Trigger bit    Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;  // Lock MB    // Read the MB again for checking if the MB is locked    temp_value_2 = Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp];      if(temp_value_2 & FrMBCCSR_LCKS)            // Is the MB locked?    {        // Clear Receive Buffer Interrupt Flag            temp_value_2 &= 0xF900;                 // Select only necessary bits            temp_value_2 |= FrMBCCSR_MBIF;          // Set MBIF flag - clear RX MB interrupt flag         Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_2;  // Clear Transmit Buffer Interrupt Flag        // Load current MB index        Fr_buffer_idx = Fr_CC_reg_ptr[FrMBIDXR0 + Fr_MB_registers_offset_add_temp];        // Calculate the message buffer header         header_MB_ptr = ((volatile uint16 * FR_DATA_FAR)(Fr_HW_config_ptr->CC_FlexRay_memory_base_address) + Fr_buffer_idx * 5);                // Read Slot Status         temp_value_2 = header_MB_ptr[4];        // Load Slot Status Information        *Fr_slot_status_ptr = temp_value_2;     // Store the slot status into Fr_slot_status_ptr            // If DUP == 1 : Frame header and MB data field updated        if(temp_value_1 & FrMBCCSR_DUP)         {   // Yes, Valid non-null frame received            // Calculate MB Data pointer            Fr_CC_data_ptr = ((volatile uint16 * FR_DATA_FAR)(Fr_HW_config_ptr->CC_FlexRay_memory_base_address) + \                             (header_MB_ptr[3] / 2));            // Load data length from Frame header reg.            Fr_data_length = (uint8)(header_MB_ptr[1] & 0x007F);   // Load the data payload length value from Frame header register                        // Copy data            for(Fr_p = 0; Fr_p < Fr_data_length; Fr_p++)            {                Fr_data_ptr[Fr_p] = Fr_CC_data_ptr[Fr_p];   // Copy all items            }        }        else    // DUP == 0 : Data has not been updated, however NULL frame may have been received        {            // Attempt to unlock MB            // Read the MBCCSRn register and select only necessary bits            temp_value_1 = (Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] & 0xF900);            temp_value_1 |= FrMBCCSR_LCKT;            Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;            // Check if at least one valid frame has been received - from Slot Status reg., VFA and VFB bits            if((temp_value_2 & FrF_HEADER_VFA) || (temp_value_2 & FrF_HEADER_VFB)) // Valid frame received?            {   // Yes, DUP == 0 and VFA or VFB == 1 -> NFA or NFB == 0 -> valid null frame receved                *Fr_data_length_ptr = 0x00;             // Store the length "0" into Fr_data_length_ptr                return FR_RXMB_NULL_FRAME_RECEIVED;     // Valid null frame has been received            }            else    // No valid frame received            {                return FR_RXMB_NOT_RECEIVED;       // No valid frame has been received            }        }    }    else    {        // Clear Receive Buffer Interrupt Flag            temp_value_1 &= 0xF900;                 // Select only necessary bits            temp_value_1 |= FrMBCCSR_MBIF;          // Set MBIF flag - clear RX MB interrupt flag         Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;  // Clear Transmit Buffer Interrupt Flag        return FR_RXMB_NO_ACCESS;         // The receive MB has not been successfully locked    }    // Attempt to unlock MB    // Read the MBCCSRn register and select only necessary bits    temp_value_1 = (Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] & 0xF900);    temp_value_1 |= FrMBCCSR_LCKT;    Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;        *Fr_data_length_ptr = Fr_data_length;   // Store length into Fr_data_length_ptr    return FR_RXMB_RECEIVED;                // The receive MB has been updated with new data}

 

 

 

Thanks you in advance,

 

Best Regards.

Labels (1)
0 Kudos
Reply
1 Solution
603 Views
Kartoon67
Contributor III

So, i find my problem. I'm going to post the solution, maybe it can be useful for someone else :

 

For the ID you have to use the header_MB_ptr, calculate in this function. The variable, give to you the first 2 bytes of a FLEXRAY Frame. For that, you can take the 11bits from the LSB of that variable, and you have the ID from the frame.

 

 

 

Fr_rx_MB_status_type Fr_receive_data(uint16 Fr_buffer_idx, uint16 *Fr_data_ptr,                                     uint8 *Fr_data_length_ptr,uint16 *Fr_slot_status_ptr,uint16 *Fr_ID_Frame_ptr){    volatile uint16 * FR_DATA_FAR header_MB_ptr;    // Message buffer header pointer    volatile uint16 * FR_DATA_FAR Fr_CC_data_ptr;   // Reference to data array    volatile uint16 Fr_ID_Frame;    volatile uint16 temp_value_1 = 0;           // Temporary variable used for bit operation    volatile uint16 temp_value_2 = 0;           // Temporary variable used for bit operation    volatile uint16 Fr_MB_registers_offset_add_temp; // Temporary offset adress of message buffer registers    volatile uint8 Fr_data_length;              // Data payload length    uint16 Fr_p;                                // Temporary counter used for copying    // Temporary offset address of MB registers    //Fr_MB_registers_offset_add_temp = Fr_buffers_config_ptr[Fr_buffer_info_set_index].buffer_index_init * 4;    Fr_MB_registers_offset_add_temp = Fr_buffer_idx * 4;       // Read the MB Configuration, Control and Status reg.    temp_value_1 = Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp];        temp_value_1 |= FrMBCCSR_LCKT;      // Set Lock Trigger bit    Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;  // Lock MB    // Read the MB again for checking if the MB is locked    temp_value_2 = Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp];      if(temp_value_2 & FrMBCCSR_LCKS)            // Is the MB locked?    {        // Clear Receive Buffer Interrupt Flag            temp_value_2 &= 0xF900;                 // Select only necessary bits            temp_value_2 |= FrMBCCSR_MBIF;          // Set MBIF flag - clear RX MB interrupt flag         Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_2;  // Clear Transmit Buffer Interrupt Flag        // Load current MB index        Fr_buffer_idx = Fr_CC_reg_ptr[FrMBIDXR0 + Fr_MB_registers_offset_add_temp];        // Calculate the message buffer header         header_MB_ptr = ((volatile uint16 * FR_DATA_FAR)(Fr_HW_config_ptr->CC_FlexRay_memory_base_address)+ Fr_buffer_idx * 5);                Fr_ID_Frame = (header_MB_ptr[0]&0x07FF);                *Fr_ID_Frame_ptr = Fr_ID_Frame;                // Read Slot Status         temp_value_2 = header_MB_ptr[4];        // Load Slot Status Information        *Fr_slot_status_ptr = temp_value_2;     // Store the slot status into Fr_slot_status_ptr            // If DUP == 1 : Frame header and MB data field updated        if(temp_value_1 & FrMBCCSR_DUP)         {   // Yes, Valid non-null frame received            // Calculate MB Data pointer            Fr_CC_data_ptr = ((volatile uint16 * FR_DATA_FAR)(Fr_HW_config_ptr->CC_FlexRay_memory_base_address) + \                             (header_MB_ptr[3] / 2));            // Load data length from Frame header reg.            Fr_data_length = (uint8)(header_MB_ptr[1] & 0x007F);   // Load the data payload length value from Frame header register                        // Copy data            for(Fr_p = 0; Fr_p < Fr_data_length; Fr_p++)            {                Fr_data_ptr[Fr_p] = Fr_CC_data_ptr[Fr_p];   // Copy all items            }        }        else    // DUP == 0 : Data has not been updated, however NULL frame may have been received        {            // Attempt to unlock MB            // Read the MBCCSRn register and select only necessary bits            temp_value_1 = (Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] & 0xF900);            temp_value_1 |= FrMBCCSR_LCKT;            Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;            // Check if at least one valid frame has been received - from Slot Status reg., VFA and VFB bits            if((temp_value_2 & FrF_HEADER_VFA) || (temp_value_2 & FrF_HEADER_VFB)) // Valid frame received?            {   // Yes, DUP == 0 and VFA or VFB == 1 -> NFA or NFB == 0 -> valid null frame receved                *Fr_data_length_ptr = 0x00;             // Store the length "0" into Fr_data_length_ptr                return FR_RXMB_NULL_FRAME_RECEIVED;     // Valid null frame has been received            }            else    // No valid frame received            {                return FR_RXMB_NOT_RECEIVED;       // No valid frame has been received            }        }    }    else    {        // Clear Receive Buffer Interrupt Flag            temp_value_1 &= 0xF900;                 // Select only necessary bits            temp_value_1 |= FrMBCCSR_MBIF;          // Set MBIF flag - clear RX MB interrupt flag         Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;  // Clear Transmit Buffer Interrupt Flag        return FR_RXMB_NO_ACCESS;         // The receive MB has not been successfully locked    }    // Attempt to unlock MB    // Read the MBCCSRn register and select only necessary bits    temp_value_1 = (Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] & 0xF900);    temp_value_1 |= FrMBCCSR_LCKT;    Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;        *Fr_data_length_ptr = Fr_data_length;   // Store length into Fr_data_length_ptr    return FR_RXMB_RECEIVED;                // The receive MB has been updated with new data}

 

View solution in original post

0 Kudos
Reply
2 Replies
603 Views
Kartoon67
Contributor III

Can someone help me?  I try until monday to extract the ID of a frame and it don't work...

 

Thanks,

0 Kudos
Reply
604 Views
Kartoon67
Contributor III

So, i find my problem. I'm going to post the solution, maybe it can be useful for someone else :

 

For the ID you have to use the header_MB_ptr, calculate in this function. The variable, give to you the first 2 bytes of a FLEXRAY Frame. For that, you can take the 11bits from the LSB of that variable, and you have the ID from the frame.

 

 

 

Fr_rx_MB_status_type Fr_receive_data(uint16 Fr_buffer_idx, uint16 *Fr_data_ptr,                                     uint8 *Fr_data_length_ptr,uint16 *Fr_slot_status_ptr,uint16 *Fr_ID_Frame_ptr){    volatile uint16 * FR_DATA_FAR header_MB_ptr;    // Message buffer header pointer    volatile uint16 * FR_DATA_FAR Fr_CC_data_ptr;   // Reference to data array    volatile uint16 Fr_ID_Frame;    volatile uint16 temp_value_1 = 0;           // Temporary variable used for bit operation    volatile uint16 temp_value_2 = 0;           // Temporary variable used for bit operation    volatile uint16 Fr_MB_registers_offset_add_temp; // Temporary offset adress of message buffer registers    volatile uint8 Fr_data_length;              // Data payload length    uint16 Fr_p;                                // Temporary counter used for copying    // Temporary offset address of MB registers    //Fr_MB_registers_offset_add_temp = Fr_buffers_config_ptr[Fr_buffer_info_set_index].buffer_index_init * 4;    Fr_MB_registers_offset_add_temp = Fr_buffer_idx * 4;       // Read the MB Configuration, Control and Status reg.    temp_value_1 = Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp];        temp_value_1 |= FrMBCCSR_LCKT;      // Set Lock Trigger bit    Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;  // Lock MB    // Read the MB again for checking if the MB is locked    temp_value_2 = Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp];      if(temp_value_2 & FrMBCCSR_LCKS)            // Is the MB locked?    {        // Clear Receive Buffer Interrupt Flag            temp_value_2 &= 0xF900;                 // Select only necessary bits            temp_value_2 |= FrMBCCSR_MBIF;          // Set MBIF flag - clear RX MB interrupt flag         Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_2;  // Clear Transmit Buffer Interrupt Flag        // Load current MB index        Fr_buffer_idx = Fr_CC_reg_ptr[FrMBIDXR0 + Fr_MB_registers_offset_add_temp];        // Calculate the message buffer header         header_MB_ptr = ((volatile uint16 * FR_DATA_FAR)(Fr_HW_config_ptr->CC_FlexRay_memory_base_address)+ Fr_buffer_idx * 5);                Fr_ID_Frame = (header_MB_ptr[0]&0x07FF);                *Fr_ID_Frame_ptr = Fr_ID_Frame;                // Read Slot Status         temp_value_2 = header_MB_ptr[4];        // Load Slot Status Information        *Fr_slot_status_ptr = temp_value_2;     // Store the slot status into Fr_slot_status_ptr            // If DUP == 1 : Frame header and MB data field updated        if(temp_value_1 & FrMBCCSR_DUP)         {   // Yes, Valid non-null frame received            // Calculate MB Data pointer            Fr_CC_data_ptr = ((volatile uint16 * FR_DATA_FAR)(Fr_HW_config_ptr->CC_FlexRay_memory_base_address) + \                             (header_MB_ptr[3] / 2));            // Load data length from Frame header reg.            Fr_data_length = (uint8)(header_MB_ptr[1] & 0x007F);   // Load the data payload length value from Frame header register                        // Copy data            for(Fr_p = 0; Fr_p < Fr_data_length; Fr_p++)            {                Fr_data_ptr[Fr_p] = Fr_CC_data_ptr[Fr_p];   // Copy all items            }        }        else    // DUP == 0 : Data has not been updated, however NULL frame may have been received        {            // Attempt to unlock MB            // Read the MBCCSRn register and select only necessary bits            temp_value_1 = (Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] & 0xF900);            temp_value_1 |= FrMBCCSR_LCKT;            Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;            // Check if at least one valid frame has been received - from Slot Status reg., VFA and VFB bits            if((temp_value_2 & FrF_HEADER_VFA) || (temp_value_2 & FrF_HEADER_VFB)) // Valid frame received?            {   // Yes, DUP == 0 and VFA or VFB == 1 -> NFA or NFB == 0 -> valid null frame receved                *Fr_data_length_ptr = 0x00;             // Store the length "0" into Fr_data_length_ptr                return FR_RXMB_NULL_FRAME_RECEIVED;     // Valid null frame has been received            }            else    // No valid frame received            {                return FR_RXMB_NOT_RECEIVED;       // No valid frame has been received            }        }    }    else    {        // Clear Receive Buffer Interrupt Flag            temp_value_1 &= 0xF900;                 // Select only necessary bits            temp_value_1 |= FrMBCCSR_MBIF;          // Set MBIF flag - clear RX MB interrupt flag         Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;  // Clear Transmit Buffer Interrupt Flag        return FR_RXMB_NO_ACCESS;         // The receive MB has not been successfully locked    }    // Attempt to unlock MB    // Read the MBCCSRn register and select only necessary bits    temp_value_1 = (Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] & 0xF900);    temp_value_1 |= FrMBCCSR_LCKT;    Fr_CC_reg_ptr[FrMBCCSR0 + Fr_MB_registers_offset_add_temp] = temp_value_1;        *Fr_data_length_ptr = Fr_data_length;   // Store length into Fr_data_length_ptr    return FR_RXMB_RECEIVED;                // The receive MB has been updated with new data}

 

0 Kudos
Reply