change(soc): vectorize bitscrambler regsiter layout

This commit is contained in:
morris
2024-11-13 14:33:07 +08:00
parent ab75a94877
commit 83c9cffd2b
7 changed files with 259 additions and 154 deletions
-5
View File
@@ -30,11 +30,6 @@ if(CONFIG_SOC_KEY_MANAGER_SUPPORTED)
list(APPEND srcs "huk_hal.c")
endif()
if(CONFIG_SOC_BITSCRAMBLER_SUPPORTED)
list(APPEND srcs "${target}/bitscrambler_periph.c")
endif()
if(NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)
if(CONFIG_SOC_MMU_PERIPH_NUM)
list(APPEND srcs "mmu_hal.c")
@@ -1,29 +0,0 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "hal/bitscrambler_hal.h"
const bitscrambler_regs_t bitscramblers_reg[2]={
{ //BITSCRAMBLER_DIR_TX
.inst_cfg0=&BITSCRAMBLER.tx_inst_cfg0,
.inst_cfg1=&BITSCRAMBLER.tx_inst_cfg1,
.lut_cfg0=&BITSCRAMBLER.tx_lut_cfg0,
.lut_cfg1=&BITSCRAMBLER.tx_lut_cfg1,
.trailing_bits=&BITSCRAMBLER.tx_tailing_bits,
.ctrl=&BITSCRAMBLER.tx_ctrl,
.state=&BITSCRAMBLER.tx_state,
},
{ //BITSCRAMBLER_DIR_RX
//Note that this assumes the RX and TX registers are exactly the same. If there's
//ever a chip where this is not the case, we need to rework this.
.inst_cfg0=(bitscrambler_tx_inst_cfg0_reg_t*)&BITSCRAMBLER.rx_inst_cfg0,
.inst_cfg1=(bitscrambler_tx_inst_cfg1_reg_t*)&BITSCRAMBLER.rx_inst_cfg1,
.lut_cfg0=(bitscrambler_tx_lut_cfg0_reg_t*)&BITSCRAMBLER.rx_lut_cfg0,
.lut_cfg1=(bitscrambler_tx_lut_cfg1_reg_t*)&BITSCRAMBLER.rx_lut_cfg1,
.trailing_bits=(bitscrambler_tx_tailing_bits_reg_t*)&BITSCRAMBLER.rx_tailing_bits,
.ctrl=(bitscrambler_tx_ctrl_reg_t*)&BITSCRAMBLER.rx_ctrl,
.state=(bitscrambler_tx_state_reg_t*)&BITSCRAMBLER.rx_state,
}
};
@@ -12,11 +12,8 @@
#include <stdbool.h>
#include "soc/bitscrambler_struct.h"
#include "hal/bitscrambler_types.h"
#include "hal/bitscrambler_hal.h"
#include "hal/misc.h"
#include "soc/hp_sys_clkrst_struct.h"
#include "soc/hp_system_struct.h"
#include "hal/hal_utils.h"
#include "hal/misc.h"
#ifdef __cplusplus
@@ -25,20 +22,12 @@ extern "C" {
#define BITSCRAMBLER_LL_GET_HW(num) (((num) == 0) ? (&BITSCRAMBLER) : NULL)
//Note: Most of the register operations refer tx_something fields. Because they
//are done to bitscramblers_reg[dir] members and rx register fields are the
//same, this code works for RX as well.
//Note: This code entirely ignores the 'hw' argument, which is fine, as for now
//we only have one BitScrambler peripheral. If we have a chip that has more, we
//need to do something to use hw to select one of multiple bitscramblers_reg
//versions.
/**
* @brief Select peripheral BitScrambler is attached to
*
* @param hw BitScrambler hardware instance address.
* @param dir Direction, BITSCRAMBLER_DIR_TX or BITSCRAMBLER_DIR_RX
* @param peri Peripheral to select, should pick the value from soc/bitscrambler_peri_select.h
*/
static inline void bitscrambler_ll_select_peripheral(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, int peri)
{
@@ -57,7 +46,7 @@ static inline void bitscrambler_ll_select_peripheral(bitscrambler_dev_t *hw, bit
*/
static inline void bitscrambler_ll_enable(bitscrambler_dev_t *hw, bitscrambler_direction_t dir)
{
bitscramblers_reg[dir].ctrl->tx_ena=1;
hw->ctrl[dir].ena = 1;
}
/**
@@ -68,7 +57,7 @@ static inline void bitscrambler_ll_enable(bitscrambler_dev_t *hw, bitscrambler_d
*/
static inline void bitscrambler_ll_disable(bitscrambler_dev_t *hw, bitscrambler_direction_t dir)
{
bitscramblers_reg[dir].ctrl->tx_ena=0;
hw->ctrl[dir].ena = 0;
}
@@ -83,9 +72,9 @@ static inline void bitscrambler_ll_disable(bitscrambler_dev_t *hw, bitscrambler_
*/
static inline void bitscrambler_ll_instmem_write(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, int inst_idx, int word_idx, uint32_t data)
{
bitscramblers_reg[dir].inst_cfg0->tx_inst_idx=inst_idx;
bitscramblers_reg[dir].inst_cfg0->tx_inst_pos=word_idx;
bitscramblers_reg[dir].inst_cfg1->tx_inst=data;
hw->inst_cfg[dir].cfg0.inst_idx = inst_idx;
hw->inst_cfg[dir].cfg0.inst_pos = word_idx;
hw->inst_cfg[dir].cfg1.inst = data;
}
/**
@@ -100,9 +89,9 @@ static inline void bitscrambler_ll_instmem_write(bitscrambler_dev_t *hw, bitscra
*/
static inline uint32_t bitscrambler_ll_instmem_read(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, int inst_idx, int word_idx)
{
bitscramblers_reg[dir].inst_cfg0->tx_inst_idx=inst_idx;
bitscramblers_reg[dir].inst_cfg0->tx_inst_pos=word_idx;
return bitscramblers_reg[dir].inst_cfg1->tx_inst;
hw->inst_cfg[dir].cfg0.inst_idx = inst_idx;
hw->inst_cfg[dir].cfg0.inst_pos = word_idx;
return hw->inst_cfg[dir].cfg1.inst;
}
/**
@@ -113,9 +102,10 @@ static inline uint32_t bitscrambler_ll_instmem_read(bitscrambler_dev_t *hw, bits
* @param word_idx Word within the LUT to write to
* @param data Data to write
*/
static inline void bitscrambler_ll_lutmem_write(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, int word_idx, uint32_t data) {
bitscramblers_reg[dir].lut_cfg0->tx_lut_idx=word_idx;
bitscramblers_reg[dir].lut_cfg1->tx_lut=data;
static inline void bitscrambler_ll_lutmem_write(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, int word_idx, uint32_t data)
{
hw->lut_cfg[dir].cfg0.lut_idx = word_idx;
hw->lut_cfg[dir].cfg1.lut = data;
}
/**
@@ -127,7 +117,7 @@ static inline void bitscrambler_ll_lutmem_write(bitscrambler_dev_t *hw, bitscram
*/
static inline void bitscrambler_ll_set_lut_width(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_lut_width_t width)
{
bitscramblers_reg[dir].lut_cfg0->tx_lut_mode=width;
hw->lut_cfg[dir].cfg0.lut_mode = width;
}
/**
@@ -138,7 +128,7 @@ static inline void bitscrambler_ll_set_lut_width(bitscrambler_dev_t *hw, bitscra
*/
static inline int bitscrambler_ll_get_lut_width(bitscrambler_dev_t *hw, bitscrambler_direction_t dir)
{
return bitscramblers_reg[dir].lut_cfg0->tx_lut_mode;
return hw->lut_cfg[dir].cfg0.lut_mode;
}
/**
@@ -150,7 +140,7 @@ static inline int bitscrambler_ll_get_lut_width(bitscrambler_dev_t *hw, bitscram
*/
static inline void bitscrambler_ll_enable_loopback(bitscrambler_dev_t *hw, bool en)
{
hw->sys.loop_mode=en?1:0;
hw->sys.loop_mode = en ? 1 : 0;
}
/**
@@ -162,7 +152,7 @@ static inline void bitscrambler_ll_enable_loopback(bitscrambler_dev_t *hw, bool
*/
static inline void bitscrambler_ll_set_cond_mode(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_cond_mode_t mode)
{
bitscramblers_reg[dir].ctrl->tx_cond_mode=mode;
hw->ctrl[dir].cond_mode = mode;
}
/**
@@ -174,7 +164,7 @@ static inline void bitscrambler_ll_set_cond_mode(bitscrambler_dev_t *hw, bitscra
*/
static inline void bitscrambler_ll_set_prefetch_mode(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_prefetch_mode_t mode)
{
bitscramblers_reg[dir].ctrl->tx_fetch_mode=mode;
hw->ctrl[dir].fetch_mode = mode;
}
/**
@@ -186,7 +176,7 @@ static inline void bitscrambler_ll_set_prefetch_mode(bitscrambler_dev_t *hw, bit
*/
static inline void bitscrambler_ll_set_eof_mode(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_eof_mode_t mode)
{
bitscramblers_reg[dir].ctrl->tx_eof_mode=mode;
hw->ctrl[dir].eof_mode = mode;
}
/**
@@ -198,7 +188,7 @@ static inline void bitscrambler_ll_set_eof_mode(bitscrambler_dev_t *hw, bitscram
*/
static inline void bitscrambler_ll_set_dummy_mode(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_dummy_mode_t mode)
{
bitscramblers_reg[dir].ctrl->tx_rd_dummy=mode;
hw->ctrl[dir].rd_dummy = mode;
}
/**
@@ -210,7 +200,7 @@ static inline void bitscrambler_ll_set_dummy_mode(bitscrambler_dev_t *hw, bitscr
*/
static inline void bitscrambler_ll_set_halt_mode(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_halt_mode_t mode)
{
bitscramblers_reg[dir].ctrl->tx_halt_mode=mode;
hw->ctrl[dir].halt_mode = mode;
}
/**
@@ -222,7 +212,7 @@ static inline void bitscrambler_ll_set_halt_mode(bitscrambler_dev_t *hw, bitscra
*/
static inline void bitscrambler_ll_set_tailing_bits(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, int bitcount)
{
HAL_FORCE_MODIFY_U32_REG_FIELD((*bitscramblers_reg[dir].trailing_bits), tx_tailing_bits, bitcount);
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->tailing_bits[dir], tailing_bits, bitcount);
}
/**
@@ -233,8 +223,8 @@ static inline void bitscrambler_ll_set_tailing_bits(bitscrambler_dev_t *hw, bits
*/
static inline void bitscrambler_ll_reset_fifo(bitscrambler_dev_t *hw, bitscrambler_direction_t dir)
{
bitscramblers_reg[dir].ctrl->tx_fifo_rst=1;
bitscramblers_reg[dir].ctrl->tx_fifo_rst=0;
hw->ctrl[dir].fifo_rst = 1;
hw->ctrl[dir].fifo_rst = 0;
}
/**
@@ -245,8 +235,8 @@ static inline void bitscrambler_ll_reset_fifo(bitscrambler_dev_t *hw, bitscrambl
*/
static inline void bitscrambler_ll_clear_eof_trace(bitscrambler_dev_t *hw, bitscrambler_direction_t dir)
{
bitscramblers_reg[dir].state->tx_eof_trace_clr=1;
bitscramblers_reg[dir].state->tx_eof_trace_clr=0;
hw->state[dir].eof_trace_clr = 1;
hw->state[dir].eof_trace_clr = 0;
}
/**
@@ -258,8 +248,8 @@ static inline void bitscrambler_ll_clear_eof_trace(bitscrambler_dev_t *hw, bitsc
*/
static inline void bitscrambler_ll_set_state(bitscrambler_dev_t *hw, bitscrambler_direction_t dir, bitscrambler_set_state_t state)
{
bitscramblers_reg[dir].ctrl->tx_pause=(state==BITSCRAMBLER_SET_STATE_PAUSE)?1:0;
bitscramblers_reg[dir].ctrl->tx_halt=(state==BITSCRAMBLER_SET_STATE_HALT)?1:0;
hw->ctrl[dir].pause = (state == BITSCRAMBLER_SET_STATE_PAUSE) ? 1 : 0;
hw->ctrl[dir].halt = (state == BITSCRAMBLER_SET_STATE_HALT) ? 1 : 0;
}
/**
@@ -272,10 +262,18 @@ static inline void bitscrambler_ll_set_state(bitscrambler_dev_t *hw, bitscramble
*/
static inline bitscrambler_state_t bitscrambler_ll_current_state(bitscrambler_dev_t *hw, bitscrambler_direction_t dir)
{
if (bitscramblers_reg[dir].state->tx_in_idle) return BITSCRAMBLER_STATE_IDLE;
if (bitscramblers_reg[dir].state->tx_in_run) return BITSCRAMBLER_STATE_RUN;
if (bitscramblers_reg[dir].state->tx_in_wait) return BITSCRAMBLER_STATE_WAIT;
if (bitscramblers_reg[dir].state->tx_in_pause) return BITSCRAMBLER_STATE_PAUSED;
if (hw->state[dir].in_idle) {
return BITSCRAMBLER_STATE_IDLE;
}
if (hw->state[dir].in_run) {
return BITSCRAMBLER_STATE_RUN;
}
if (hw->state[dir].in_wait) {
return BITSCRAMBLER_STATE_WAIT;
}
if (hw->state[dir].in_pause) {
return BITSCRAMBLER_STATE_PAUSED;
}
return BITSCRAMBLER_STATE_UNKNOWN;
}
@@ -6,35 +6,10 @@
#pragma once
#include "sdkconfig.h"
#if CONFIG_SOC_BITSCRAMBLER_SUPPORTED
#include "soc/bitscrambler_struct.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* @brief The TX and RX BitScramblers have registers that work in the same way, but that are
* in different locations. This struct defines those registers; if we address the TX and
* RX bitscramblers through this we can mostly use the same code for both.
*/
typedef struct {
volatile bitscrambler_tx_inst_cfg0_reg_t *inst_cfg0;
volatile bitscrambler_tx_inst_cfg1_reg_t *inst_cfg1;
volatile bitscrambler_tx_lut_cfg0_reg_t *lut_cfg0;
volatile bitscrambler_tx_lut_cfg1_reg_t *lut_cfg1;
volatile bitscrambler_tx_tailing_bits_reg_t *trailing_bits;
volatile bitscrambler_tx_ctrl_reg_t *ctrl;
volatile bitscrambler_tx_state_reg_t *state;
} bitscrambler_regs_t;
extern const bitscrambler_regs_t bitscramblers_reg[2];
#ifdef __cplusplus
}
#endif
#endif
+26 -36
View File
@@ -19,85 +19,75 @@ typedef enum {
} bitscrambler_direction_t;
/**
* @brief BitScrambler LUT width
* @brief BitScrambler LUT (look up table) width
*/
typedef enum {
BITSCRAMBLER_LUT_WIDTH_8BIT = 0,
BITSCRAMBLER_LUT_WIDTH_16BIT = 1,
BITSCRAMBLER_LUT_WIDTH_32BIT = 2
BITSCRAMBLER_LUT_WIDTH_8BIT = 0, /*!< 8-bit LUT */
BITSCRAMBLER_LUT_WIDTH_16BIT = 1, /*!< 16-bit LUT */
BITSCRAMBLER_LUT_WIDTH_32BIT = 2, /*!< 32-bit LUT */
} bitscrambler_lut_width_t;
/**
* @brief BitScrambler loopback select
* @brief EOF signal generating mode of bitscrambler
*/
typedef enum {
BITSCRAMBLER_LOOP_DISABLE = 0,
BITSCRAMBLER_LOOP_ENABLE = 1
} bitscrambler_loop_mode_t;
/**
* @brief EOF mode of bitscrambler
*/
typedef enum {
BITSCRAMBLER_EOF_MODE_READ = 0,
BITSCRAMBLER_EOF_MODE_WRITE = 1
BITSCRAMBLER_EOF_MODE_READ = 0, /*!< EOF is counted by reading the source FIFO */
BITSCRAMBLER_EOF_MODE_WRITE = 1, /*!< EOF is counted by writing the destination FIFO */
} bitscrambler_eof_mode_t;
/**
* @brief Condition mode of bitscrambler
*/
typedef enum {
BITSCRAMBLER_COND_MODE_LESSTHAN = 0,
BITSCRAMBLER_COND_MODE_NOTEQUAL = 1
BITSCRAMBLER_COND_MODE_LESSTHAN = 0, /*!< Use "<=" to generate the condition */
BITSCRAMBLER_COND_MODE_NOTEQUAL = 1, /*!< Use "!=" to generate the condition */
} bitscrambler_cond_mode_t;
/**
* @brief Condition mode of bitscrambler
* @brief Prefetch mode of bitscrambler
*/
typedef enum {
BITSCRAMBLER_PREFETCH_ENABLED = 0,
BITSCRAMBLER_PREFETCH_DISABLED = 1
BITSCRAMBLER_PREFETCH_ENABLED = 0, /*!< Hardware prefetch is enabled */
BITSCRAMBLER_PREFETCH_DISABLED = 1, /*!< Hardware prefetch is disabled, but the bitscrambler instructions can still do the prefetch */
} bitscrambler_prefetch_mode_t;
/**
* @brief Condition mode of bitscrambler
* @brief Halt mode of bitscrambler
*/
typedef enum {
BITSCRAMBLER_HALT_WAIT_WRITES = 0,
BITSCRAMBLER_HALT_IGNORE_WRITES = 1
BITSCRAMBLER_HALT_WAIT_WRITES = 0, /*!< Wait data write back */
BITSCRAMBLER_HALT_IGNORE_WRITES = 1, /*!< Ignore write data back */
} bitscrambler_halt_mode_t;
/**
* @brief Condition mode of bitscrambler
* @brief Dummy mode of bitscrambler
*/
typedef enum {
BITSCRAMBLER_DUMMY_MODE_HALT = 0,
BITSCRAMBLER_DUMMY_MODE_DUMMY = 1
BITSCRAMBLER_DUMMY_MODE_HALT = 0, /*!< Halt and wait the read data */
BITSCRAMBLER_DUMMY_MODE_DUMMY = 1, /*!< Ignore the read data */
} bitscrambler_dummy_mode_t;
/**
* @brief Condition mode of bitscrambler
* @brief Commands to set the state of bitscrambler
*/
typedef enum {
BITSCRAMBLER_SET_STATE_RUN,
BITSCRAMBLER_SET_STATE_HALT,
BITSCRAMBLER_SET_STATE_PAUSE
BITSCRAMBLER_SET_STATE_RUN, /*!< Run */
BITSCRAMBLER_SET_STATE_HALT, /*!< Halt */
BITSCRAMBLER_SET_STATE_PAUSE, /*!< Pause */
} bitscrambler_set_state_t;
/**
* @brief Status of bitscrambler
*/
typedef enum {
BITSCRAMBLER_STATE_IDLE,
BITSCRAMBLER_STATE_RUN,
BITSCRAMBLER_STATE_WAIT,
BITSCRAMBLER_STATE_PAUSED,
BITSCRAMBLER_STATE_IDLE, /*!< Idle (halt) */
BITSCRAMBLER_STATE_RUN, /*!< Running */
BITSCRAMBLER_STATE_WAIT, /*!< Waiting data write back */
BITSCRAMBLER_STATE_PAUSED, /*!< Paused */
BITSCRAMBLER_STATE_UNKNOWN /*!< Invalid, should never be returned */
} bitscrambler_state_t;
#ifdef __cplusplus
}
#endif