mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(driver_twai): fixed fd data bitrate error on slow bitrate
This commit is contained in:
@@ -21,9 +21,15 @@
|
||||
#define TWAI_LL_TSEG1_MIN 0
|
||||
#define TWAI_LL_TSEG2_MIN 1
|
||||
#define TWAI_LL_BRP_MAX TWAIFD_BRP
|
||||
#define TWAI_LL_PROP_MAX TWAIFD_PROP
|
||||
#define TWAI_LL_TSEG1_MAX TWAIFD_PH1
|
||||
#define TWAI_LL_TSEG2_MAX TWAIFD_PH2
|
||||
#define TWAI_LL_SJW_MAX TWAIFD_SJW
|
||||
#define TWAI_LL_BRP_MAX_FD TWAIFD_BRP_FD
|
||||
#define TWAI_LL_PROP_MAX_FD TWAIFD_PROP_FD
|
||||
#define TWAI_LL_TSEG1_MAX_FD TWAIFD_PH1_FD
|
||||
#define TWAI_LL_TSEG2_MAX_FD TWAIFD_PH2_FD
|
||||
#define TWAI_LL_SJW_MAX_FD TWAIFD_SJW_FD
|
||||
#define TWAI_LL_TIMER_DIV_MAX TWAIFD_TIMER_STEP
|
||||
|
||||
#define TWAIFD_IDENTIFIER_BASE_S 18 // Start bit of std_id in IDENTIFIER_W of TX buffer or RX buffer
|
||||
@@ -310,17 +316,6 @@ static inline void twaifd_ll_clr_intr_status(twaifd_dev_t *hw, uint32_t intr_mas
|
||||
}
|
||||
|
||||
/* ------------------------ Bus Timing Registers --------------------------- */
|
||||
/**
|
||||
* @brief Check if the brp value valid
|
||||
*
|
||||
* @param brp Bit rate prescaler value
|
||||
* @return true or False
|
||||
*/
|
||||
static inline bool twaifd_ll_check_brp_validation(uint32_t brp)
|
||||
{
|
||||
return (brp >= TWAI_LL_BRP_MIN) && (brp <= TWAI_LL_BRP_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set bus timing nominal bit rate
|
||||
*
|
||||
|
||||
@@ -21,9 +21,15 @@
|
||||
#define TWAI_LL_TSEG1_MIN 0
|
||||
#define TWAI_LL_TSEG2_MIN 1
|
||||
#define TWAI_LL_BRP_MAX TWAIFD_BRP
|
||||
#define TWAI_LL_PROP_MAX TWAIFD_PROP
|
||||
#define TWAI_LL_TSEG1_MAX TWAIFD_PH1
|
||||
#define TWAI_LL_TSEG2_MAX TWAIFD_PH2
|
||||
#define TWAI_LL_SJW_MAX TWAIFD_SJW
|
||||
#define TWAI_LL_BRP_MAX_FD TWAIFD_BRP_FD
|
||||
#define TWAI_LL_PROP_MAX_FD TWAIFD_PROP_FD
|
||||
#define TWAI_LL_TSEG1_MAX_FD TWAIFD_PH1_FD
|
||||
#define TWAI_LL_TSEG2_MAX_FD TWAIFD_PH2_FD
|
||||
#define TWAI_LL_SJW_MAX_FD TWAIFD_SJW_FD
|
||||
#define TWAI_LL_TIMER_DIV_MAX TWAIFD_TIMER_STEP
|
||||
|
||||
#define TWAIFD_IDENTIFIER_BASE_S 18 // Start bit of std_id in IDENTIFIER_W of TX buffer or RX buffer
|
||||
@@ -309,17 +315,6 @@ static inline void twaifd_ll_clr_intr_status(twaifd_dev_t *hw, uint32_t intr_mas
|
||||
}
|
||||
|
||||
/* ------------------------ Bus Timing Registers --------------------------- */
|
||||
/**
|
||||
* @brief Check if the brp value valid
|
||||
*
|
||||
* @param brp Bit rate prescaler value
|
||||
* @return true or False
|
||||
*/
|
||||
static inline bool twaifd_ll_check_brp_validation(uint32_t brp)
|
||||
{
|
||||
return (brp >= TWAI_LL_BRP_MIN) && (brp <= TWAI_LL_BRP_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set bus timing nominal bit rate
|
||||
*
|
||||
|
||||
@@ -121,13 +121,14 @@ void twai_hal_deinit(twai_hal_context_t *hal_ctx);
|
||||
void twai_hal_configure(twai_hal_context_t *hal_ctx, const twai_timing_config_t *t_config, const twai_filter_config_t *f_config, uint32_t clkout_divider);
|
||||
|
||||
/**
|
||||
* @brief Check if the brp value valid for hardware register
|
||||
* @brief Check if the timing value valid for hardware register
|
||||
*
|
||||
* @param hal_ctx Context of the HAL layer
|
||||
* @param brp Bit rate prescaler value
|
||||
* @param t_config Pointer to timing configuration structure
|
||||
* @param is_fd True if the timing is for FD data, false for classic TWAI
|
||||
* @return true or False
|
||||
*/
|
||||
bool twai_hal_check_brp_validation(twai_hal_context_t *hal_ctx, uint32_t brp);
|
||||
bool twai_hal_check_timing_valid(twai_hal_context_t *hal_ctx, const twai_timing_advanced_config_t *t_config, bool is_fd);
|
||||
|
||||
/**
|
||||
* @brief Configure the TWAI timing
|
||||
|
||||
@@ -91,9 +91,17 @@ void twai_hal_configure(twai_hal_context_t *hal_ctx, const twai_timing_config_t
|
||||
twai_ll_set_clkout(hal_ctx->dev, clkout_divider);
|
||||
}
|
||||
|
||||
bool twai_hal_check_brp_validation(twai_hal_context_t *hal_ctx, uint32_t brp)
|
||||
bool twai_hal_check_timing_valid(twai_hal_context_t *hal_ctx, const twai_timing_advanced_config_t *t_config, bool is_fd)
|
||||
{
|
||||
return twai_ll_check_brp_validation(brp);
|
||||
(void) is_fd;
|
||||
bool valid = true;
|
||||
if (t_config) {
|
||||
valid &= twai_ll_check_brp_validation(t_config->brp);
|
||||
valid &= (t_config->sjw >= 1) && (t_config->sjw <= TWAI_LL_SJW_MAX);
|
||||
valid &= (t_config->tseg_1 >= TWAI_LL_TSEG1_MIN) && (t_config->tseg_1 <= TWAI_LL_TSEG1_MAX);
|
||||
valid &= (t_config->tseg_2 >= TWAI_LL_TSEG2_MIN) && (t_config->tseg_2 <= TWAI_LL_TSEG2_MAX);
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
void twai_hal_configure_timing(twai_hal_context_t *hal_ctx, const twai_timing_advanced_config_t *t_config)
|
||||
|
||||
@@ -46,9 +46,25 @@ void twai_hal_deinit(twai_hal_context_t *hal_ctx)
|
||||
memset(hal_ctx, 0, sizeof(twai_hal_context_t));
|
||||
}
|
||||
|
||||
bool twai_hal_check_brp_validation(twai_hal_context_t *hal_ctx, uint32_t brp)
|
||||
bool twai_hal_check_timing_valid(twai_hal_context_t *hal_ctx, const twai_timing_advanced_config_t *t_config, bool is_fd)
|
||||
{
|
||||
return twaifd_ll_check_brp_validation(brp);
|
||||
bool valid = true;
|
||||
if (t_config) {
|
||||
if (is_fd) {
|
||||
valid &= (t_config->brp >= TWAI_LL_BRP_MIN) && (t_config->brp <= TWAI_LL_BRP_MAX_FD);
|
||||
valid &= (t_config->prop_seg <= TWAI_LL_PROP_MAX_FD);
|
||||
valid &= (t_config->tseg_1 <= TWAI_LL_TSEG1_MAX_FD);
|
||||
valid &= (t_config->tseg_2 >= TWAI_LL_TSEG2_MIN) && (t_config->tseg_2 <= TWAI_LL_TSEG2_MAX_FD);
|
||||
valid &= (t_config->sjw >= 1) && (t_config->sjw <= TWAI_LL_SJW_MAX_FD);
|
||||
} else {
|
||||
valid &= (t_config->brp >= TWAI_LL_BRP_MIN) && (t_config->brp <= TWAI_LL_BRP_MAX);
|
||||
valid &= (t_config->prop_seg <= TWAI_LL_PROP_MAX);
|
||||
valid &= (t_config->tseg_1 <= TWAI_LL_TSEG1_MAX);
|
||||
valid &= (t_config->tseg_2 >= TWAI_LL_TSEG2_MIN) && (t_config->tseg_2 <= TWAI_LL_TSEG2_MAX);
|
||||
valid &= (t_config->sjw >= 1) && (t_config->sjw <= TWAI_LL_SJW_MAX);
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
void twai_hal_configure_timing(twai_hal_context_t *hal_ctx, const twai_timing_advanced_config_t *t_config)
|
||||
|
||||
Reference in New Issue
Block a user