|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// The LL layer for UHCI register operations. |
| 8 | +// Note that most of the register operations in this layer are non-atomic operations. |
| 9 | + |
| 10 | +#pragma once |
| 11 | +#include <stdio.h> |
| 12 | +#include "hal/uhci_types.h" |
| 13 | +#include "soc/uhci_struct.h" |
| 14 | +#include "soc/pcr_struct.h" |
| 15 | +#include "hal/misc.h" |
| 16 | + |
| 17 | +#ifdef __cplusplus |
| 18 | +extern "C" { |
| 19 | +#endif |
| 20 | + |
| 21 | +#define UHCI_LL_GET_HW(num) (((num) == 0) ? (&UHCI) : (NULL)) |
| 22 | +#define UHCI_LL_MAX_RECEIVE_PACKET_THRESHOLD (8192) |
| 23 | + |
| 24 | +typedef enum { |
| 25 | + UHCI_RX_BREAK_CHR_EOF = 0x1, |
| 26 | + UHCI_RX_IDLE_EOF = 0x2, |
| 27 | + UHCI_RX_LEN_EOF = 0x4, |
| 28 | + UHCI_RX_EOF_MAX = 0x7, |
| 29 | +} uhci_rxeof_cfg_t; |
| 30 | + |
| 31 | +/** |
| 32 | + * @brief Enable the bus clock for UHCI module |
| 33 | + * |
| 34 | + * @param group_id Group ID |
| 35 | + * @param enable true to enable, false to disable |
| 36 | + */ |
| 37 | +static inline void uhci_ll_enable_bus_clock(int group_id, bool enable) |
| 38 | +{ |
| 39 | + (void)group_id; |
| 40 | + PCR.uhci_conf.uhci_clk_en = enable; |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * @brief Reset the UHCI module |
| 45 | + * |
| 46 | + * @param group_id Group ID |
| 47 | + */ |
| 48 | +static inline void uhci_ll_reset_register(int group_id) |
| 49 | +{ |
| 50 | + (void)group_id; |
| 51 | + PCR.uhci_conf.uhci_rst_en = 1; |
| 52 | + PCR.uhci_conf.uhci_rst_en = 0; |
| 53 | +} |
| 54 | + |
| 55 | +static inline void uhci_ll_init(uhci_dev_t *hw) |
| 56 | +{ |
| 57 | + typeof(hw->conf0) conf0_reg; |
| 58 | + conf0_reg.val = 0; |
| 59 | + conf0_reg.clk_en = 1; |
| 60 | + hw->conf0.val = conf0_reg.val; |
| 61 | + hw->conf1.val = 0; |
| 62 | +} |
| 63 | + |
| 64 | +static inline void uhci_ll_attach_uart_port(uhci_dev_t *hw, int uart_num) |
| 65 | +{ |
| 66 | + hw->conf0.uart_sel = uart_num; |
| 67 | +} |
| 68 | + |
| 69 | +static inline void uhci_ll_set_seper_chr(uhci_dev_t *hw, uhci_seper_chr_t *seper_char) |
| 70 | +{ |
| 71 | + if (seper_char->sub_chr_en) { |
| 72 | + hw->conf0.seper_en = 1; |
| 73 | + typeof(hw->esc_conf0) esc_conf0_reg; |
| 74 | + esc_conf0_reg.val = hw->esc_conf0.val; |
| 75 | + |
| 76 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf0_reg, seper_char, seper_char->seper_chr); |
| 77 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf0_reg, seper_esc_char0, seper_char->sub_chr1); |
| 78 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf0_reg, seper_esc_char1, seper_char->sub_chr2); |
| 79 | + hw->esc_conf0.val = esc_conf0_reg.val; |
| 80 | + hw->escape_conf.tx_c0_esc_en = 1; |
| 81 | + hw->escape_conf.rx_c0_esc_en = 1; |
| 82 | + } else { |
| 83 | + hw->conf0.seper_en = 0; |
| 84 | + hw->escape_conf.val = 0; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +static inline void uhci_ll_set_swflow_ctrl_sub_chr(uhci_dev_t *hw, uhci_swflow_ctrl_sub_chr_t *sub_ctr) |
| 89 | +{ |
| 90 | + typeof(hw->escape_conf) escape_conf_reg; |
| 91 | + escape_conf_reg.val = hw->escape_conf.val; |
| 92 | + |
| 93 | + if (sub_ctr->flow_en == 1) { |
| 94 | + typeof(hw->esc_conf2) esc_conf2_reg; |
| 95 | + esc_conf2_reg.val = hw->esc_conf2.val; |
| 96 | + typeof(hw->esc_conf3) esc_conf3_reg; |
| 97 | + esc_conf3_reg.val = hw->esc_conf3.val; |
| 98 | + |
| 99 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf2_reg, esc_seq1, sub_ctr->xon_chr); |
| 100 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf2_reg, esc_seq1_char0, sub_ctr->xon_sub1); |
| 101 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf2_reg, esc_seq1_char1, sub_ctr->xon_sub2); |
| 102 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf3_reg, esc_seq2, sub_ctr->xoff_chr); |
| 103 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf3_reg, esc_seq2_char0, sub_ctr->xoff_sub1); |
| 104 | + HAL_FORCE_MODIFY_U32_REG_FIELD(esc_conf3_reg, esc_seq2_char1, sub_ctr->xoff_sub2); |
| 105 | + escape_conf_reg.tx_11_esc_en = 1; |
| 106 | + escape_conf_reg.tx_13_esc_en = 1; |
| 107 | + escape_conf_reg.rx_11_esc_en = 1; |
| 108 | + escape_conf_reg.rx_13_esc_en = 1; |
| 109 | + hw->esc_conf2.val = esc_conf2_reg.val; |
| 110 | + hw->esc_conf3.val = esc_conf3_reg.val; |
| 111 | + } else { |
| 112 | + escape_conf_reg.tx_11_esc_en = 0; |
| 113 | + escape_conf_reg.tx_13_esc_en = 0; |
| 114 | + escape_conf_reg.rx_11_esc_en = 0; |
| 115 | + escape_conf_reg.rx_13_esc_en = 0; |
| 116 | + } |
| 117 | + hw->escape_conf.val = escape_conf_reg.val; |
| 118 | +} |
| 119 | + |
| 120 | +static inline void uhci_ll_enable_intr(uhci_dev_t *hw, uint32_t intr_mask) |
| 121 | +{ |
| 122 | + hw->int_ena.val |= intr_mask; |
| 123 | +} |
| 124 | + |
| 125 | +static inline void uhci_ll_disable_intr(uhci_dev_t *hw, uint32_t intr_mask) |
| 126 | +{ |
| 127 | + hw->int_ena.val &= (~intr_mask); |
| 128 | +} |
| 129 | + |
| 130 | +static inline void uhci_ll_clear_intr(uhci_dev_t *hw, uint32_t intr_mask) |
| 131 | +{ |
| 132 | + hw->int_clr.val = intr_mask; |
| 133 | +} |
| 134 | + |
| 135 | +static inline uint32_t uhci_ll_get_intr(uhci_dev_t *hw) |
| 136 | +{ |
| 137 | + return hw->int_st.val; |
| 138 | +} |
| 139 | + |
| 140 | +static inline void uhci_ll_rx_set_eof_mode(uhci_dev_t *hw, uint32_t eof_mode) |
| 141 | +{ |
| 142 | + if (eof_mode & UHCI_RX_BREAK_CHR_EOF) { |
| 143 | + hw->conf0.uart_rx_brk_eof_en = 1; |
| 144 | + } |
| 145 | + if (eof_mode & UHCI_RX_IDLE_EOF) { |
| 146 | + hw->conf0.uart_idle_eof_en = 1; |
| 147 | + } |
| 148 | + if (eof_mode & UHCI_RX_LEN_EOF) { |
| 149 | + hw->conf0.len_eof_en = 1; |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +static inline void uhci_ll_rx_set_packet_threshold(uhci_dev_t *hw, uint16_t length) |
| 154 | +{ |
| 155 | + hw->pkt_thres.pkt_thrs = length; |
| 156 | +} |
| 157 | + |
| 158 | +#ifdef __cplusplus |
| 159 | +} |
| 160 | +#endif |
0 commit comments