Skip to content

Commit

Permalink
[drivers][bsp][reness] Add Etherkit bsp and RZ series driver compatib…
Browse files Browse the repository at this point in the history
…ility adaptation
  • Loading branch information
kurisaW committed Feb 19, 2025
1 parent 12fded1 commit bf0fed2
Show file tree
Hide file tree
Showing 148 changed files with 91,722 additions and 167 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bsp_buildings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ jobs:
- "renesas/ra8d1-vision-board"
- "renesas/rzt2m_rsk"
- "renesas/rzn2l_rsk"
- "renesas/rzn2l_etherkit"
- "frdm-k64f"
- "xplorer4330/M4"
- RTT_BSP: "nuvoton"
Expand Down
2 changes: 1 addition & 1 deletion bsp/renesas/libraries/HAL_Drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if GetDepend(['BSP_USING_TIM']):
if GetDepend(['BSP_USING_ETH']):
src += ['drv_eth.c']

if GetDepend(['BSP_USING_CAN']):
if GetDepend(['BSP_USING_CAN']) or GetDepend('BSP_USING_CANFD'):
src += ['drv_can.c']

if GetDepend(['BSP_USING_SDHI']):
Expand Down
22 changes: 13 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/drv_config.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-07-29 KyleChan first version
* 2022-12-7 Vandoul ADD ra4m2
*/
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-07-29 KyleChan first version
* 2022-12-7 Vandoul ADD ra4m2
*/

#ifndef __DRV_CONFIG_H__
#define __DRV_CONFIG_H__
Expand Down Expand Up @@ -145,6 +145,10 @@ extern "C"
#include "rzt/uart_config.h"
#include "rzt/timer_config.h"

#ifdef BSP_USING_CANFD
#include "rzt/canfd_config.h"
#endif

#ifdef BSP_USING_PWM
#include "rzt/pwm_config.h"
#endif
Expand Down
85 changes: 85 additions & 0 deletions bsp/renesas/libraries/HAL_Drivers/config/rzt/can_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-02-11 kurisaW first version
*/

#ifndef __CAN_CONFIG_H__
#define __CAN_CONFIG_H__

#include <rtthread.h>
#include "hal_data.h"

#ifdef __cplusplus
extern "C"
{
#endif

#if defined(BSP_USING_CAN0)
#ifndef CANFD0_CONFIG
#define CANFD0_CONFIG \
{ \
.name = "canfd0", \
.num_of_mailboxs = 48, \
.p_api_ctrl = &g_canfd0_ctrl, \
.p_cfg = &g_canfd0_cfg, \
}
#endif /* CAN0_CONFIG */
#endif /* BSP_USING_CAN0 */

#if defined(BSP_USING_CAN1)
#ifndef CANFD1_CONFIG
#define CANFD1_CONFIG \
{ \
.name = "canfd1", \
.num_of_mailboxs = 48, \
.p_api_ctrl = &g_canfd1_ctrl, \
.p_cfg = &g_canfd1_cfg, \
}
#endif /* CAN1_CONFIG */
#endif /* BSP_USING_CAN1 */

const canfd_afl_entry_t p_canfd0_afl[CANFD_CFG_AFL_CH0_RULE_NUM] =
{
{
.id =
{
.id = 0x00,
.frame_type = CAN_FRAME_TYPE_DATA,
.id_mode = CAN_ID_MODE_STANDARD
},
.destination =
{
.minimum_dlc = CANFD_MINIMUM_DLC_0,
.rx_buffer = CANFD_RX_MB_NONE,
.fifo_select_flags = CANFD_RX_FIFO_0
}
},
};

const canfd_afl_entry_t p_canfd1_afl[CANFD_CFG_AFL_CH1_RULE_NUM] =
{
{
.id =
{
.id = 0x01,
.frame_type = CAN_FRAME_TYPE_DATA,
.id_mode = CAN_ID_MODE_STANDARD
},
.destination =
{
.minimum_dlc = CANFD_MINIMUM_DLC_1,
.rx_buffer = CANFD_RX_MB_NONE,
.fifo_select_flags = CANFD_RX_FIFO_1
}
},
};

#ifdef __cplusplus
}
#endif
#endif
31 changes: 27 additions & 4 deletions bsp/renesas/libraries/HAL_Drivers/drv_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2021-10-29 mazhiyuan first version
* 2025-02-11 kurisaW support can and canfd drivers for RZ family
*/

#include "drv_can.h"
Expand Down Expand Up @@ -47,6 +48,18 @@ static const struct ra_baud_rate_tab can_baud_rate_tab[] =
{CAN10kBaud, 4, 14, 5, 1 + 249}
};

#if defined(BSP_USING_CANFD)

#define can_instance_ctrl_t canfd_instance_ctrl_t

#define R_CAN_Open R_CANFD_Open
#define R_BSP_IrqStatusClear R_BSP_IrqClearPending
#define R_CAN_ModeTransition R_CANFD_ModeTransition
#define R_CAN_InfoGet R_CANFD_InfoGet
#define R_CAN_Write R_CANFD_Write

#endif

static rt_uint32_t get_can_baud_index(rt_uint32_t baud)
{
rt_uint32_t len, index;
Expand All @@ -66,13 +79,13 @@ static void ra_can_get_config(void)
struct can_configure config = CANDEFAULTCONFIG;
#ifdef BSP_USING_CAN0
can_obj[CAN0_INDEX].can_dev.config = config;
can_obj[CAN0_INDEX].can_dev.config.msgboxsz = CAN_NO_OF_MAILBOXES_g_can0;
can_obj[CAN0_INDEX].can_dev.config.msgboxsz = 32;
can_obj[CAN0_INDEX].can_dev.config.sndboxnumber = 1;
can_obj[CAN0_INDEX].can_dev.config.ticks = 50;
#endif
#ifdef BSP_USING_CAN1
can_obj[CAN1_INDEX].can_dev.config = config;
can_obj[CAN1_INDEX].can_dev.config.msgboxsz = CAN_NO_OF_MAILBOXES_g_can1;
can_obj[CAN1_INDEX].can_dev.config.msgboxsz = 32;
can_obj[CAN1_INDEX].can_dev.config.sndboxnumber = 1;
can_obj[CAN1_INDEX].can_dev.config.ticks = 50;
#endif
Expand Down Expand Up @@ -168,7 +181,7 @@ rt_err_t ra_can_control(struct rt_can_device *can_dev, int cmd, void *arg)
}
return RT_EOK;
}
int ra_can_sendmsg(struct rt_can_device *can_dev, const void *buf, rt_uint32_t boxno)
rt_ssize_t ra_can_sendmsg(struct rt_can_device *can_dev, const void *buf, rt_uint32_t boxno)
{
struct ra_can *can;
can_frame_t g_can_tx_frame;
Expand All @@ -180,7 +193,13 @@ int ra_can_sendmsg(struct rt_can_device *can_dev, const void *buf, rt_uint32_t b
g_can_tx_frame.id_mode = msg_rt->ide;
g_can_tx_frame.type = msg_rt->rtr;
g_can_tx_frame.data_length_code = msg_rt->len;
#if defined(BSP_USING_CANFD) && defined(BSP_USING_CAN_RZ)
g_can_tx_frame.options = 0;
#elif defined(BSP_USING_CANFD)
g_can_tx_frame.options = CANFD_FRAME_OPTION_FD | CANFD_FRAME_OPTION_BRS;
#else
g_can_tx_frame.options = 0;
#endif
memcpy(g_can_tx_frame.data, msg_rt->data, 8);
can = rt_container_of(can_dev, struct ra_can, can_dev);
RT_ASSERT(boxno < can->config->num_of_mailboxs);
Expand All @@ -193,7 +212,7 @@ int ra_can_sendmsg(struct rt_can_device *can_dev, const void *buf, rt_uint32_t b
return RT_EOK;
}

int ra_can_recvmsg(struct rt_can_device *can_dev, void *buf, rt_uint32_t boxno)
rt_ssize_t ra_can_recvmsg(struct rt_can_device *can_dev, void *buf, rt_uint32_t boxno)
{
struct rt_can_msg *msg_rt = (struct rt_can_msg *)buf;
can_frame_t *msg_ra;
Expand All @@ -205,7 +224,11 @@ int ra_can_recvmsg(struct rt_can_device *can_dev, void *buf, rt_uint32_t boxno)
RT_ASSERT(boxno < can->config->num_of_mailboxs);
if (can->callback_args->mailbox != boxno)
return 0;
#if defined(BSP_USING_CANFD)
msg_ra = &can->callback_args->frame;
#else
msg_ra = can->callback_args->p_frame;
#endif

msg_rt->id = msg_ra->id;
msg_rt->ide = msg_ra->id_mode;
Expand Down
3 changes: 2 additions & 1 deletion bsp/renesas/libraries/HAL_Drivers/drv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static void SysTimerInterrupt(void);
static void reboot(uint8_t argc, char **argv)
{
#ifdef SOC_SERIES_R9A07G0
return;
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_LPC_RESET);
R_BSP_SystemReset();
#else
NVIC_SystemReset();
#endif
Expand Down
Loading

0 comments on commit bf0fed2

Please sign in to comment.