mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-21 02:56:49 +00:00
soc/ll: workaround compiler bug that generate 8/16 bits inst instead of 32 bits one
update all struct headers to be more "standardized":
- bit fields are properly wrapped with struct
- bitwidth sum should be 32 within same struct, so that it's correctly padded with reserved bits
- bit field should be uint32_t
- typedef volatile struct xxx{} yyy;: xxx must exists. refer: https://github.com/espressif/esp-idf/pull/3199
added helper macros to force peripheral registers being accessed in 32 bitwidth
added a check script into ci
This commit is contained in:
@@ -32,6 +32,7 @@ extern "C" {
|
||||
#include "hal/misc.h"
|
||||
#include "hal/twai_types.h"
|
||||
#include "soc/twai_periph.h"
|
||||
#include "soc/twai_struct.h"
|
||||
|
||||
/* ------------------------- Defines and Typedefs --------------------------- */
|
||||
|
||||
@@ -491,7 +492,7 @@ static inline void twai_ll_parse_err_code_cap(twai_dev_t *hw,
|
||||
*/
|
||||
static inline void twai_ll_set_err_warn_lim(twai_dev_t *hw, uint32_t ewl)
|
||||
{
|
||||
hw->error_warning_limit_reg.ewl = ewl;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->error_warning_limit_reg, ewl, ewl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -531,7 +532,7 @@ static inline uint32_t twai_ll_get_rec(twai_dev_t *hw)
|
||||
*/
|
||||
static inline void twai_ll_set_rec(twai_dev_t *hw, uint32_t rec)
|
||||
{
|
||||
hw->rx_error_counter_reg.rxerr = rec;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->rx_error_counter_reg, rxerr, rec);
|
||||
}
|
||||
|
||||
/* ------------------------ TX Error Count Register ------------------------- */
|
||||
@@ -559,7 +560,7 @@ static inline uint32_t twai_ll_get_tec(twai_dev_t *hw)
|
||||
*/
|
||||
static inline void twai_ll_set_tec(twai_dev_t *hw, uint32_t tec)
|
||||
{
|
||||
hw->tx_error_counter_reg.txerr = tec;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->tx_error_counter_reg, txerr, tec);
|
||||
}
|
||||
|
||||
/* ---------------------- Acceptance Filter Registers ----------------------- */
|
||||
@@ -578,8 +579,8 @@ static inline void twai_ll_set_acc_filter(twai_dev_t* hw, uint32_t code, uint32_
|
||||
uint32_t code_swapped = HAL_SWAP32(code);
|
||||
uint32_t mask_swapped = HAL_SWAP32(mask);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
hw->acceptance_filter.acr[i].byte = ((code_swapped >> (i * 8)) & 0xFF);
|
||||
hw->acceptance_filter.amr[i].byte = ((mask_swapped >> (i * 8)) & 0xFF);
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->acceptance_filter.acr[i], byte, ((code_swapped >> (i * 8)) & 0xFF));
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->acceptance_filter.amr[i], byte, ((mask_swapped >> (i * 8)) & 0xFF));
|
||||
}
|
||||
hw->mode_reg.afm = single_filter;
|
||||
}
|
||||
@@ -614,7 +615,7 @@ static inline void twai_ll_get_rx_buffer(twai_dev_t *hw, twai_ll_frame_buffer_t
|
||||
{
|
||||
//Copy RX buffer registers into frame
|
||||
for (int i = 0; i < 13; i++) {
|
||||
rx_frame->bytes[i] = hw->tx_rx_buffer[i].byte;
|
||||
rx_frame->bytes[i] = HAL_FORCE_READ_U32_REG_FIELD(hw->tx_rx_buffer[i], byte);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,8 +795,8 @@ static inline void twai_ll_save_reg(twai_dev_t *hw, twai_ll_reg_save_t *reg_save
|
||||
reg_save->bus_timing_1_reg = (uint8_t) hw->bus_timing_1_reg.val;
|
||||
reg_save->error_warning_limit_reg = (uint8_t) hw->error_warning_limit_reg.val;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
reg_save->acr_reg[i] = hw->acceptance_filter.acr[i].byte;
|
||||
reg_save->amr_reg[i] = hw->acceptance_filter.amr[i].byte;
|
||||
reg_save->acr_reg[i] = HAL_FORCE_READ_U32_REG_FIELD(hw->acceptance_filter.acr[i], byte);
|
||||
reg_save->amr_reg[i] = HAL_FORCE_READ_U32_REG_FIELD(hw->acceptance_filter.amr[i], byte);
|
||||
}
|
||||
reg_save->rx_error_counter_reg = (uint8_t) hw->rx_error_counter_reg.val;
|
||||
reg_save->tx_error_counter_reg = (uint8_t) hw->tx_error_counter_reg.val;
|
||||
@@ -821,8 +822,8 @@ static inline void twai_ll_restore_reg(twai_dev_t *hw, twai_ll_reg_save_t *reg_s
|
||||
hw->bus_timing_1_reg.val = reg_save->bus_timing_1_reg;
|
||||
hw->error_warning_limit_reg.val = reg_save->error_warning_limit_reg;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
hw->acceptance_filter.acr[i].byte = reg_save->acr_reg[i];
|
||||
hw->acceptance_filter.amr[i].byte = reg_save->amr_reg[i];
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->acceptance_filter.acr[i], byte, reg_save->acr_reg[i]);
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->acceptance_filter.amr[i], byte, reg_save->amr_reg[i]);
|
||||
}
|
||||
hw->rx_error_counter_reg.val = reg_save->rx_error_counter_reg;
|
||||
hw->tx_error_counter_reg.val = reg_save->tx_error_counter_reg;
|
||||
|
||||
Reference in New Issue
Block a user