Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 1583

RZV2L: Implementation of CANFD through FSP

$
0
0

Hi, I have added g_canfd0 CANFD Driver in stacks. I need to initialize CANFD in hal_entry.c file.

Kindly provide some reference for RZV2L.

#include "hal_data.h"
/***********************************************************************************************************************
 * Includes
 **********************************************************************************************************************/
#include "r_canfd.h"
#include "r_can_api.h"
#include "r_canfd_cfg.h"
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER

/****************************************************************************************
 * ADDED
 *****************************************************************************************/
#define CAN_EXAMPLE_ID      (0x20)

can_frame_t g_can0_tx_frame;


/*******************************************************************************************************************//**
 * main() is generated by the Configuration editor and is used to generate threads if an RTOS is used.
 * This function is called by main() when no RTOS is used.
 **********************************************************************************************************************/
void hal_entry(void)
{

    /* TODO: add your own code here */
    volatile canfd_error_t g_err_status = (canfd_error_t) 0;

    void canfd_callback (can_callback_args_t * p_args)
    {
        switch (p_args->event)
        {
            case CAN_EVENT_RX_COMPLETE:    /* Receive complete event. */
            {
                /* Read received frame */
                /*memcpy(&g_can0_rx_frame, &p_args->frame, sizeof(can_frame_t));
                /* Handle event */
                break;
            }
            case CAN_EVENT_TX_COMPLETE:    /* Transmit complete event. */
            {
                /* Handle event */
                break;
            }
            case CAN_EVENT_ERR_GLOBAL:                        /* Global error. */
            case CAN_EVENT_ERR_CHANNEL:                       /* Channel error. */
            {
                /* Get error status */
                g_err_status = (canfd_error_t) p_args->error; /* Check error code with canfd_error_t. */
                /* Handle event */
                break;
            }
            default:
            {
                break;
            }
        }
    }

    R_BSP_MODULE_RSTON(FSP_IP_CANFD, 0);

    fsp_err_t err;

    /* Initialize the CAN module */
    err = R_CANFD_Open(&g_canfd0_ctrl, &g_canfd0_cfg);
    /* Handle any errors. This function should be defined by the user. */
    assert(FSP_SUCCESS == err);

    /* Switch to external loopback mode */
    err = R_CANFD_ModeTransition(&g_canfd0_ctrl, CAN_OPERATION_MODE_NORMAL, CAN_TEST_MODE_LOOPBACK_INTERNAL);
    //err = R_CANFD_ModeTransition(&g_canfd0_ctrl, CAN_OPERATION_MODE_NORMAL, CAN_TEST_MODE_LOOPBACK_EXTERNAL);
    assert(FSP_SUCCESS == err);


    /* Setup frame to write to CAN ID 0x20 */
    g_can0_tx_frame.id               = CAN_EXAMPLE_ID;
    g_can0_tx_frame.id_mode          = CAN_ID_MODE_STANDARD;
    g_can0_tx_frame.type             = CAN_FRAME_TYPE_DATA;
    g_can0_tx_frame.data_length_code = 8;
    g_can0_tx_frame.options          = 0;


    /* Write some data to the transmit frame */
    for (uint32_t i = 0; i < 8; i++)
    {
        g_can0_tx_frame.data[i] = (uint8_t) i;
    }

    /* Send data on the bus */
    err = R_CANFD_Write(&g_canfd0_ctrl, CANFD_TX_MB_0, &g_can0_tx_frame);
    assert(FSP_SUCCESS == err);
    /* Wait for a transmit callback event */


    while (1)
    {
        vTaskDelay (1);
    }
        ;
}

/*******************************************************************************************************************//**
 * This function is called at various points during the startup process.  This implementation uses the event that is
 * called right before main() to set up the pins.
 *
 * @param[in]  event    Where at in the start up process the code is currently at
 **********************************************************************************************************************/
void R_BSP_WarmStart(bsp_warm_start_event_t event)
{
    if (BSP_WARM_START_RESET == event)
    {
    }

    if (BSP_WARM_START_POST_C == event)
    {
        /* C runtime environment and system clocks are setup. */

        /* Configure pins. */
        R_IOPORT_Open (&g_ioport_ctrl, &g_bsp_pin_cfg);
    }
}

I want to just transmit data.

Thank you


Viewing all articles
Browse latest Browse all 1583

Trending Articles