Merge branch 'refactor/hal_util_bitwise_reverse8' into 'master'

hal: add util function to reverse a 8bit byte

See merge request espressif/esp-idf!26532
This commit is contained in:
morris
2023-10-20 09:43:15 +08:00
7 changed files with 45 additions and 23 deletions

View File

@@ -10,6 +10,7 @@
#include <stdbool.h>
#include "hal/assert.h"
#include "hal/misc.h"
#include "hal/hal_utils.h"
#include "hal/gdma_types.h"
#include "hal/gdma_ll.h"
#include "soc/ahb_dma_struct.h"
@@ -558,7 +559,7 @@ static inline void ahb_dma_ll_tx_crc_set_lfsr_data_mask(ahb_dma_dev_t *dev, uint
dev->out_crc[channel].crc_data_en_addr.tx_crc_data_en_addr_chn = crc_bit;
if (reverse_data_mask) {
// "& 0xff" because the hardware only support 8-bit data
data_mask = _bitwise_reverse(data_mask & 0xFF);
data_mask = hal_utils_bitwise_reverse8(data_mask & 0xFF);
}
HAL_FORCE_MODIFY_U32_REG_FIELD(dev->out_crc[channel].crc_data_en_wr_data, tx_crc_data_en_wr_data_chn, data_mask);
}
@@ -619,7 +620,7 @@ static inline void ahb_dma_ll_rx_crc_set_lfsr_data_mask(ahb_dma_dev_t *dev, uint
dev->in_crc[channel].crc_data_en_addr.rx_crc_data_en_addr_chn = crc_bit;
if (reverse_data_mask) {
// "& 0xff" because the hardware only support 8-bit data
data_mask = _bitwise_reverse(data_mask & 0xFF);
data_mask = hal_utils_bitwise_reverse8(data_mask & 0xFF);
}
HAL_FORCE_MODIFY_U32_REG_FIELD(dev->in_crc[channel].crc_data_en_wr_data, rx_crc_data_en_wr_data_chn, data_mask);
}

View File

@@ -10,6 +10,7 @@
#include <stdbool.h>
#include "hal/assert.h"
#include "hal/misc.h"
#include "hal/hal_utils.h"
#include "hal/gdma_types.h"
#include "hal/gdma_ll.h"
#include "soc/axi_dma_struct.h"
@@ -504,7 +505,7 @@ static inline void axi_dma_ll_tx_crc_set_lfsr_data_mask(axi_dma_dev_t *dev, uint
dev->out[channel].crc.tx_crc_data_en_addr.tx_crc_data_en_addr_chn = crc_bit;
if (reverse_data_mask) {
// "& 0xff" because the hardware only support 8-bit data
data_mask = _bitwise_reverse(data_mask & 0xFF);
data_mask = hal_utils_bitwise_reverse8(data_mask & 0xFF);
}
HAL_FORCE_MODIFY_U32_REG_FIELD(dev->out[channel].crc.tx_crc_data_en_wr_data, tx_crc_data_en_wr_data_chn, data_mask);
}
@@ -565,7 +566,7 @@ static inline void axi_dma_ll_rx_crc_set_lfsr_data_mask(axi_dma_dev_t *dev, uint
dev->in[channel].crc.rx_crc_data_en_addr.rx_crc_data_en_addr_chn = crc_bit;
if (reverse_data_mask) {
// "& 0xff" because the hardware only support 8-bit data
data_mask = _bitwise_reverse(data_mask & 0xFF);
data_mask = hal_utils_bitwise_reverse8(data_mask & 0xFF);
}
HAL_FORCE_MODIFY_U32_REG_FIELD(dev->in[channel].crc.rx_crc_data_en_wr_data, rx_crc_data_en_wr_data_chn, data_mask);
}

View File

@@ -82,15 +82,6 @@ static inline void gdma_ll_reset_register(int group_id)
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define gdma_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; gdma_ll_reset_register(__VA_ARGS__)
__attribute__((always_inline))
static inline uint8_t _bitwise_reverse(uint8_t n)
{
n = ((n & 0xf0) >> 4) | ((n & 0x0f) << 4);
n = ((n & 0xcc) >> 2) | ((n & 0x33) << 2);
n = ((n & 0xaa) >> 1) | ((n & 0x55) << 1);
return n;
}
#ifdef __cplusplus
}
#endif