mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
Merge branch 'bugfix/twai_brp_div_init' into 'master'
TWAI: Initialize brp_div field to zero, fix register field name, and remove sdkconfig form caps See merge request espressif/esp-idf!9924
This commit is contained in:
@@ -339,7 +339,12 @@ esp_err_t twai_driver_install(const twai_general_config_t *g_config, const twai_
|
|||||||
TWAI_CHECK(g_config->rx_queue_len > 0, ESP_ERR_INVALID_ARG);
|
TWAI_CHECK(g_config->rx_queue_len > 0, ESP_ERR_INVALID_ARG);
|
||||||
TWAI_CHECK(g_config->tx_io >= 0 && g_config->tx_io < GPIO_NUM_MAX, ESP_ERR_INVALID_ARG);
|
TWAI_CHECK(g_config->tx_io >= 0 && g_config->tx_io < GPIO_NUM_MAX, ESP_ERR_INVALID_ARG);
|
||||||
TWAI_CHECK(g_config->rx_io >= 0 && g_config->rx_io < GPIO_NUM_MAX, ESP_ERR_INVALID_ARG);
|
TWAI_CHECK(g_config->rx_io >= 0 && g_config->rx_io < GPIO_NUM_MAX, ESP_ERR_INVALID_ARG);
|
||||||
TWAI_CHECK(TWAI_BRP_IS_VALID(t_config->brp), ESP_ERR_INVALID_ARG);
|
#if (CONFIG_ESP32_REV_MIN >= 2)
|
||||||
|
TWAI_CHECK(t_config->brp >= TWAI_BRP_MIN && t_config->brp <= TWAI_BRP_MAX_ECO, ESP_ERR_INVALID_ARG);
|
||||||
|
#else
|
||||||
|
TWAI_CHECK(t_config->brp >= TWAI_BRP_MIN && t_config->brp <= TWAI_BRP_MAX, ESP_ERR_INVALID_ARG);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
twai_obj_t *p_twai_obj_dummy;
|
twai_obj_t *p_twai_obj_dummy;
|
||||||
|
@@ -20,6 +20,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TWAI Constants
|
* @brief TWAI Constants
|
||||||
@@ -59,7 +60,7 @@ extern "C" {
|
|||||||
#define TWAI_TIMING_CONFIG_5KBITS() {.brp = 800, .tseg_1 = 15, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
#define TWAI_TIMING_CONFIG_5KBITS() {.brp = 800, .tseg_1 = 15, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
||||||
#define TWAI_TIMING_CONFIG_10KBITS() {.brp = 400, .tseg_1 = 15, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
#define TWAI_TIMING_CONFIG_10KBITS() {.brp = 400, .tseg_1 = 15, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
||||||
#endif
|
#endif
|
||||||
#if (TWAI_BRP_MAX > 128)
|
#if (TWAI_BRP_MAX > 128) || (CONFIG_ESP32_REV_MIN >= 2)
|
||||||
#define TWAI_TIMING_CONFIG_12_5KBITS() {.brp = 256, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
#define TWAI_TIMING_CONFIG_12_5KBITS() {.brp = 256, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
||||||
#define TWAI_TIMING_CONFIG_16KBITS() {.brp = 200, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
#define TWAI_TIMING_CONFIG_16KBITS() {.brp = 200, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
||||||
#define TWAI_TIMING_CONFIG_20KBITS() {.brp = 200, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
#define TWAI_TIMING_CONFIG_20KBITS() {.brp = 200, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||||
|
@@ -20,20 +20,12 @@ extern "C" {
|
|||||||
|
|
||||||
#warning soc/can_caps.h is deprecated, please use soc/twai_caps.h instead
|
#warning soc/can_caps.h is deprecated, please use soc/twai_caps.h instead
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
/* ---------------------------- Compatibility ------------------------------- */
|
/* ---------------------------- Compatibility ------------------------------- */
|
||||||
|
|
||||||
#if (CONFIG_ESP32_REV_MIN >= 2)
|
#define CAN_BRP_MIN 2
|
||||||
#define CAN_BRP_DIV_SUPPORTED 1
|
#define CAN_BRP_MAX 128
|
||||||
#define CAN_BRP_DIV_THRESH 128
|
#define CAN_BRP_MAX_ECO 256
|
||||||
#define CAN_BRP_IS_VALID(brp) (((brp) >= 2 && (brp) <= 128 && ((brp) & 0x1) == 0) || ((brp) >= 132 && (brp) <= 256 && ((brp) & 0x3) == 0))
|
#define CAN_BRP_DIV_THRESH 128
|
||||||
#define CAN_BRP_MAX 256
|
|
||||||
#else
|
|
||||||
#define CAN_BRP_IS_VALID(brp) ((brp) >= 2 && (brp) <= 128 && ((brp) & 0x1) == 0)
|
|
||||||
#define CAN_BRP_MAX 128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CAN_SUPPORT_MULTI_ADDRESS_LAYOUT 1
|
#define CAN_SUPPORT_MULTI_ADDRESS_LAYOUT 1
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -18,22 +18,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#define TWAI_BRP_MIN 2
|
||||||
|
#define TWAI_BRP_MAX 128
|
||||||
//Chip specific TWAI related macros
|
#define TWAI_BRP_MAX_ECO 256
|
||||||
#if __DOXYGEN__ || (CONFIG_ESP32_REV_MIN >= 2)
|
#define TWAI_BRP_DIV_THRESH 128
|
||||||
#define TWAI_BRP_DIV_SUPPORTED 1
|
|
||||||
#define TWAI_BRP_DIV_THRESH 128
|
|
||||||
//Any even number from 2 to 128, or multiples of 4 from 132 to 256
|
|
||||||
#define TWAI_BRP_IS_VALID(brp) (((brp) >= 2 && (brp) <= 128 && ((brp) & 0x1) == 0) || ((brp) >= 132 && (brp) <= 256 && ((brp) & 0x3) == 0))
|
|
||||||
#define TWAI_BRP_MAX 256
|
|
||||||
#else
|
|
||||||
//Any even number from 2 to 128
|
|
||||||
#define TWAI_BRP_IS_VALID(brp) ((brp) >= 2 && (brp) <= 128 && ((brp) & 0x1) == 0)
|
|
||||||
#define TWAI_BRP_MAX 128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Chip specific TWAI capabilities
|
|
||||||
#define TWAI_SUPPORT_MULTI_ADDRESS_LAYOUT 1
|
#define TWAI_SUPPORT_MULTI_ADDRESS_LAYOUT 1
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -18,10 +18,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Chip specific TWAI related macros
|
#define TWAI_BRP_MIN 2
|
||||||
//Any even number from 2 to 32768
|
#define TWAI_BRP_MAX 32768
|
||||||
#define TWAI_BRP_IS_VALID(brp) ((brp) >= 2 && (brp) <= 32768 && ((brp) & 0x1) == 0)
|
|
||||||
#define TWAI_BRP_MAX 32768
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ typedef volatile struct twai_dev_s {
|
|||||||
uint32_t es: 1; /* SR.6 Error Status */
|
uint32_t es: 1; /* SR.6 Error Status */
|
||||||
uint32_t bs: 1; /* SR.7 Bus Status */
|
uint32_t bs: 1; /* SR.7 Bus Status */
|
||||||
uint32_t ms: 1; /* SR.8 Miss Status */
|
uint32_t ms: 1; /* SR.8 Miss Status */
|
||||||
uint32_t reserved24: 23; /* Internal Reserved */
|
uint32_t reserved23: 23; /* Internal Reserved */
|
||||||
};
|
};
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
} status_reg; /* Address 2 */
|
} status_reg; /* Address 2 */
|
||||||
|
@@ -38,7 +38,7 @@ extern "C" {
|
|||||||
#define CAN_MSG_FLAG_SELF TWAI_MSG_FLAG_SELF
|
#define CAN_MSG_FLAG_SELF TWAI_MSG_FLAG_SELF
|
||||||
#define CAN_MSG_FLAG_DLC_NON_COMP TWAI_MSG_FLAG_DLC_NON_COMP
|
#define CAN_MSG_FLAG_DLC_NON_COMP TWAI_MSG_FLAG_DLC_NON_COMP
|
||||||
|
|
||||||
#if (TWAI_BRP_MAX > 128)
|
#if (TWAI_BRP_MAX > 128) || (CONFIG_ESP32_REV_MIN >= 2)
|
||||||
#define CAN_TIMING_CONFIG_12_5KBITS() TWAI_TIMING_CONFIG_12_5KBITS()
|
#define CAN_TIMING_CONFIG_12_5KBITS() TWAI_TIMING_CONFIG_12_5KBITS()
|
||||||
#define CAN_TIMING_CONFIG_16KBITS() TWAI_TIMING_CONFIG_16KBITS()
|
#define CAN_TIMING_CONFIG_16KBITS() TWAI_TIMING_CONFIG_16KBITS()
|
||||||
#define CAN_TIMING_CONFIG_20KBITS() TWAI_TIMING_CONFIG_20KBITS()
|
#define CAN_TIMING_CONFIG_20KBITS() TWAI_TIMING_CONFIG_20KBITS()
|
||||||
|
@@ -28,6 +28,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include "hal/twai_types.h"
|
#include "hal/twai_types.h"
|
||||||
#include "soc/twai_periph.h"
|
#include "soc/twai_periph.h"
|
||||||
|
|
||||||
@@ -336,8 +337,8 @@ static inline uint32_t twai_ll_get_and_clear_intrs(twai_dev_t *hw)
|
|||||||
*/
|
*/
|
||||||
static inline void twai_ll_set_enabled_intrs(twai_dev_t *hw, uint32_t intr_mask)
|
static inline void twai_ll_set_enabled_intrs(twai_dev_t *hw, uint32_t intr_mask)
|
||||||
{
|
{
|
||||||
#ifdef TWAI_BRP_DIV_SUPPORTED
|
#if (CONFIG_ESP32_REV_MIN >= 2)
|
||||||
//ESP32 Rev 2 has brp div. Need to mask when setting
|
//ESP32 Rev 2 or later has brp div field. Need to mask it out
|
||||||
hw->interrupt_enable_reg.val = (hw->interrupt_enable_reg.val & 0x10) | intr_mask;
|
hw->interrupt_enable_reg.val = (hw->interrupt_enable_reg.val & 0x10) | intr_mask;
|
||||||
#else
|
#else
|
||||||
hw->interrupt_enable_reg.val = intr_mask;
|
hw->interrupt_enable_reg.val = intr_mask;
|
||||||
@@ -362,11 +363,13 @@ static inline void twai_ll_set_enabled_intrs(twai_dev_t *hw, uint32_t intr_mask)
|
|||||||
*/
|
*/
|
||||||
static inline void twai_ll_set_bus_timing(twai_dev_t *hw, uint32_t brp, uint32_t sjw, uint32_t tseg1, uint32_t tseg2, bool triple_sampling)
|
static inline void twai_ll_set_bus_timing(twai_dev_t *hw, uint32_t brp, uint32_t sjw, uint32_t tseg1, uint32_t tseg2, bool triple_sampling)
|
||||||
{
|
{
|
||||||
#ifdef TWAI_BRP_DIV_SUPPORTED
|
#if (CONFIG_ESP32_REV_MIN >= 2)
|
||||||
if (brp > TWAI_BRP_DIV_THRESH) {
|
if (brp > TWAI_BRP_DIV_THRESH) {
|
||||||
//Need to set brp_div bit
|
//Need to set brp_div bit
|
||||||
hw->interrupt_enable_reg.brp_div = 1;
|
hw->interrupt_enable_reg.brp_div = 1;
|
||||||
brp /= 2;
|
brp /= 2;
|
||||||
|
} else {
|
||||||
|
hw->interrupt_enable_reg.brp_div = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
hw->bus_timing_0_reg.brp = (brp / 2) - 1;
|
hw->bus_timing_0_reg.brp = (brp / 2) - 1;
|
||||||
|
Reference in New Issue
Block a user