From 0159c37cf27b3c2ec137760ecfda8ffe621388ef Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Mon, 25 Oct 2021 17:28:46 +0800 Subject: [PATCH] usb: Fix LL 8/16 bit register field access This commit addes the 8/16 bit register field access workarounds to the DWC_OTG peripheral. This workaround was applied to all other peripherals in commit 874a720286b78e866684129ce18a6c948c8fa7fe. --- components/hal/include/hal/usbh_ll.h | 68 ++++++++-------------------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 19 insertions(+), 50 deletions(-) diff --git a/components/hal/include/hal/usbh_ll.h b/components/hal/include/hal/usbh_ll.h index a6c03e302a..63f7b8219d 100644 --- a/components/hal/include/hal/usbh_ll.h +++ b/components/hal/include/hal/usbh_ll.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -23,6 +15,8 @@ extern "C" { #include "soc/usbh_struct.h" #include "soc/usb_wrap_struct.h" #include "hal/usb_types_private.h" +#include "hal/misc.h" + /* ----------------------------------------------------------------------------- ------------------------------- Global Registers ------------------------------- @@ -328,7 +322,7 @@ static inline void usb_ll_dis_intrs(usbh_dev_t *hw, uint32_t intr_mask) static inline void usb_ll_set_rx_fifo_size(usbh_dev_t *hw, uint32_t num_lines) { //Set size in words - hw->grxfsiz_reg.rxfdep = num_lines; + HAL_FORCE_MODIFY_U32_REG_FIELD(hw->grxfsiz_reg, rxfdep, num_lines); } // -------------------------- GNPTXFSIZ Register ------------------------------- @@ -337,8 +331,8 @@ static inline void usb_ll_set_nptx_fifo_size(usbh_dev_t *hw, uint32_t addr, uint { usb_gnptxfsiz_reg_t gnptxfsiz; gnptxfsiz.val = hw->gnptxfsiz_reg.val; - gnptxfsiz.nptxfstaddr = addr; - gnptxfsiz.nptxfdep = num_lines; + HAL_FORCE_MODIFY_U32_REG_FIELD(gnptxfsiz, nptxfstaddr, addr); + HAL_FORCE_MODIFY_U32_REG_FIELD(gnptxfsiz, nptxfdep, num_lines); hw->gnptxfsiz_reg.val = gnptxfsiz.val; } @@ -373,8 +367,8 @@ static inline void usbh_ll_set_ptx_fifo_size(usbh_dev_t *hw, uint32_t addr, uint { usb_hptxfsiz_reg_t hptxfsiz; hptxfsiz.val = hw->hptxfsiz_reg.val; - hptxfsiz.ptxfstaddr = addr; - hptxfsiz.ptxfsize = num_lines; + HAL_FORCE_MODIFY_U32_REG_FIELD(hptxfsiz, ptxfstaddr, addr); + HAL_FORCE_MODIFY_U32_REG_FIELD(hptxfsiz, ptxfsize, num_lines); hw->hptxfsiz_reg.val = hptxfsiz.val; } @@ -473,7 +467,7 @@ static inline void usbh_ll_hfir_set_defaults(usbh_dev_t *hw, usb_priv_speed_t sp static inline uint32_t usbh_ll_get_frm_time_rem(usbh_dev_t *hw) { - return hw->hfnum_reg.frrem; + return HAL_FORCE_READ_U32_REG_FIELD(hw->hfnum_reg, frrem); } static inline uint32_t usbh_ll_get_frm_num(usbh_dev_t *hw) @@ -485,7 +479,7 @@ static inline uint32_t usbh_ll_get_frm_num(usbh_dev_t *hw) static inline uint32_t usbh_ll_get_p_tx_queue_top(usbh_dev_t *hw) { - return hw->hptxsts_reg.ptxqtop; + return HAL_FORCE_READ_U32_REG_FIELD(hw->hptxsts_reg, ptxqtop); } static inline uint32_t usbh_ll_get_p_tx_queue_space_avail(usbh_dev_t *hw) @@ -495,20 +489,21 @@ static inline uint32_t usbh_ll_get_p_tx_queue_space_avail(usbh_dev_t *hw) static inline uint32_t usbh_ll_get_p_tx_fifo_space_avail(usbh_dev_t *hw) { - return hw->hptxsts_reg.ptxfspcavail; + return HAL_FORCE_READ_U32_REG_FIELD(hw->hptxsts_reg, ptxfspcavail); } // ----------------------------- HAINT Register -------------------------------- static inline uint32_t usbh_ll_get_chan_intrs_msk(usbh_dev_t *hw) { - return hw->haint_reg.haint; + return HAL_FORCE_READ_U32_REG_FIELD(hw->haint_reg, haint); } // --------------------------- HAINTMSK Register ------------------------------- static inline void usbh_ll_haintmsk_en_chan_intr(usbh_dev_t *hw, uint32_t mask) { + hw->haintmsk_reg.val |= mask; } @@ -817,31 +812,6 @@ static inline void usbh_ll_chan_set_dma_addr_non_iso(volatile usb_host_chan_regs chan->hcdma_reg.non_iso.ctd = qtd_idx; } -static inline void usbh_ll_chan_set_dma_addr_iso(volatile usb_host_chan_regs_t *chan, - void *dmaaddr, - uint32_t ntd) -{ - int n; - if (ntd == 2) { - n = 4; - } else if (ntd == 4) { - n = 5; - } else if (ntd == 8) { - n = 6; - } else if (ntd == 16) { - n = 7; - } else if (ntd == 32) { - n = 8; - } else { //ntd == 64 - n = 9; - } - //Set HCTSIZi - chan->hctsiz_reg.ntd = ntd -1; - chan->hctsiz_reg.sched_info = 0xFF; //Always set to 0xFF for FS - //Set HCDMAi - chan->hcdma_reg.iso.dmaaddr_ctd = (((uint32_t)dmaaddr) & 0x1FF) << (n-3); //ctd is set to 0 -} - static inline int usbh_ll_chan_get_ctd(usb_host_chan_regs_t *chan) { return chan->hcdma_reg.non_iso.ctd; @@ -850,12 +820,12 @@ static inline int usbh_ll_chan_get_ctd(usb_host_chan_regs_t *chan) static inline void usbh_ll_chan_hctsiz_init(volatile usb_host_chan_regs_t *chan) { chan->hctsiz_reg.dopng = 0; //Don't do ping - chan->hctsiz_reg.sched_info = 0xFF; //Schedinfo is always 0xFF for fullspeed. Not used in Bulk/Ctrl channels + HAL_FORCE_MODIFY_U32_REG_FIELD(chan->hctsiz_reg, sched_info, 0xFF); //Schedinfo is always 0xFF for fullspeed. Not used in Bulk/Ctrl channels } static inline void usbh_ll_chan_set_qtd_list_len(volatile usb_host_chan_regs_t *chan, int qtd_list_len) { - chan->hctsiz_reg.ntd = qtd_list_len - 1; //Set the length of the descriptor list + HAL_FORCE_MODIFY_U32_REG_FIELD(chan->hctsiz_reg, ntd, qtd_list_len - 1); //Set the length of the descriptor list } // ---------------------------- HCDMABi Register ------------------------------- diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index cd75dfc3fb..b52fd65b49 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1415,7 +1415,6 @@ components/hal/include/hal/uhci_types.h components/hal/include/hal/usb_hal.h components/hal/include/hal/usb_types_private.h components/hal/include/hal/usbh_hal.h -components/hal/include/hal/usbh_ll.h components/hal/include/hal/wdt_hal.h components/hal/include/hal/wdt_types.h components/hal/interrupt_controller_hal.c