port: HPMicro: decoupling the relationship between busid and usbid
- decoupling the relationship between busid and usbid Signed-off-by: Zhihong Chen <zhihong.chen@hpmicro.com>
This commit is contained in:
@@ -15,12 +15,8 @@
|
|||||||
#error "hpm ehci must enable CONFIG_USB_EHCI_PORT_POWER"
|
#error "hpm ehci must enable CONFIG_USB_EHCI_PORT_POWER"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t hpm_irq_table[] = {
|
static uint32_t _hcd_irqnum[CONFIG_USBHOST_MAX_BUS];
|
||||||
IRQn_USB0,
|
static uint8_t _hcd_busid[CONFIG_USBHOST_MAX_BUS];
|
||||||
#ifdef HPM_USB1_BASE
|
|
||||||
IRQn_USB1
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
static void usb_host_mode_init(USB_Type *ptr)
|
static void usb_host_mode_init(USB_Type *ptr)
|
||||||
{
|
{
|
||||||
@@ -43,8 +39,20 @@ static void usb_host_mode_init(USB_Type *ptr)
|
|||||||
|
|
||||||
void usb_hc_low_level_init(struct usbh_bus *bus)
|
void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||||
{
|
{
|
||||||
|
if (bus->hcd.reg_base == HPM_USB0_BASE) {
|
||||||
|
_hcd_irqnum[bus->hcd.hcd_id] = IRQn_USB0;
|
||||||
|
_hcd_busid[0] = bus->hcd.hcd_id;
|
||||||
|
} else {
|
||||||
|
#ifdef HPM_USB1_BASE
|
||||||
|
if (bus->hcd.reg_base == HPM_USB1_BASE) {
|
||||||
|
_hcd_irqnum[bus->hcd.hcd_id] = IRQn_USB1;
|
||||||
|
_hcd_busid[1] = bus->hcd.hcd_id;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
usb_phy_init((USB_Type *)(bus->hcd.reg_base));
|
usb_phy_init((USB_Type *)(bus->hcd.reg_base));
|
||||||
intc_m_enable_irq(hpm_irq_table[bus->hcd.hcd_id]);
|
intc_m_enable_irq(_hcd_irqnum[bus->hcd.hcd_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_hc_low_level2_init(struct usbh_bus *bus)
|
void usb_hc_low_level2_init(struct usbh_bus *bus)
|
||||||
@@ -76,14 +84,14 @@ extern void USBH_IRQHandler(uint8_t busid);
|
|||||||
|
|
||||||
void isr_usbh0(void)
|
void isr_usbh0(void)
|
||||||
{
|
{
|
||||||
USBH_IRQHandler(0);
|
USBH_IRQHandler(_hcd_busid[0]);
|
||||||
}
|
}
|
||||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
|
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
|
||||||
|
|
||||||
#ifdef HPM_USB1_BASE
|
#ifdef HPM_USB1_BASE
|
||||||
void isr_usbh1(void)
|
void isr_usbh1(void)
|
||||||
{
|
{
|
||||||
USBH_IRQHandler(1);
|
USBH_IRQHandler(_hcd_busid[1]);
|
||||||
}
|
}
|
||||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
|
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ struct hpm_ep_state {
|
|||||||
uint32_t actual_xfer_len;
|
uint32_t actual_xfer_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------*
|
||||||
|
* Variable Definitions
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
/* Driver state */
|
/* Driver state */
|
||||||
struct hpm_udc {
|
struct hpm_udc {
|
||||||
usb_device_handle_t *handle;
|
usb_device_handle_t *handle;
|
||||||
@@ -40,26 +43,8 @@ static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_AL
|
|||||||
static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT) dcd_data_t _dcd_data1;
|
static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT) dcd_data_t _dcd_data1;
|
||||||
#endif
|
#endif
|
||||||
static ATTR_PLACE_AT_NONCACHEABLE usb_device_handle_t usb_device_handle[CONFIG_USBDEV_MAX_BUS];
|
static ATTR_PLACE_AT_NONCACHEABLE usb_device_handle_t usb_device_handle[CONFIG_USBDEV_MAX_BUS];
|
||||||
|
static uint32_t _dcd_irqnum[CONFIG_USBDEV_MAX_BUS];
|
||||||
/*---------------------------------------------------------------------*
|
static uint8_t _dcd_busid[CONFIG_USBDEV_MAX_BUS];
|
||||||
* Macro Typedef Declaration
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
typedef struct {
|
|
||||||
USB_Type* regs; /* register base*/
|
|
||||||
const uint32_t irqnum; /* IRQ number */
|
|
||||||
const uint8_t ep_count; /* Max bi-directional Endpoints */
|
|
||||||
} dcd_controller_t;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------*
|
|
||||||
* Variable Definitions
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
static const dcd_controller_t _dcd_controller[] =
|
|
||||||
{
|
|
||||||
{ .regs = (USB_Type*) HPM_USB0_BASE, .irqnum = IRQn_USB0, .ep_count = USB_SOC_DCD_MAX_ENDPOINT_COUNT },
|
|
||||||
#ifdef HPM_USB1_BASE
|
|
||||||
{ .regs = (USB_Type*) HPM_USB1_BASE, .irqnum = IRQn_USB1, .ep_count = USB_SOC_DCD_MAX_ENDPOINT_COUNT }
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Index to bit position in register */
|
/* Index to bit position in register */
|
||||||
static inline uint8_t ep_idx2bit(uint8_t ep_idx)
|
static inline uint8_t ep_idx2bit(uint8_t ep_idx)
|
||||||
@@ -83,7 +68,20 @@ int usb_dc_init(uint8_t busid)
|
|||||||
|
|
||||||
memset(&g_hpm_udc[busid], 0, sizeof(struct hpm_udc));
|
memset(&g_hpm_udc[busid], 0, sizeof(struct hpm_udc));
|
||||||
g_hpm_udc[busid].handle = &usb_device_handle[busid];
|
g_hpm_udc[busid].handle = &usb_device_handle[busid];
|
||||||
g_hpm_udc[busid].handle->regs = _dcd_controller[busid].regs;
|
g_hpm_udc[busid].handle->regs = (USB_Type *)g_usbdev_bus[busid].reg_base;
|
||||||
|
|
||||||
|
if (g_usbdev_bus[busid].reg_base == HPM_USB0_BASE) {
|
||||||
|
_dcd_irqnum[busid] = IRQn_USB0;
|
||||||
|
_dcd_busid[0] = busid;
|
||||||
|
} else {
|
||||||
|
#ifdef HPM_USB1_BASE
|
||||||
|
if (g_usbdev_bus[busid].reg_base == HPM_USB1_BASE) {
|
||||||
|
_dcd_irqnum[busid] = IRQn_USB1;
|
||||||
|
_dcd_busid[1] = busid;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (busid == 0) {
|
if (busid == 0) {
|
||||||
g_hpm_udc[busid].handle->dcd_data = &_dcd_data0;
|
g_hpm_udc[busid].handle->dcd_data = &_dcd_data0;
|
||||||
} else if (busid == 1) {
|
} else if (busid == 1) {
|
||||||
@@ -100,13 +98,13 @@ int usb_dc_init(uint8_t busid)
|
|||||||
|
|
||||||
usb_device_init(g_hpm_udc[busid].handle, int_mask);
|
usb_device_init(g_hpm_udc[busid].handle, int_mask);
|
||||||
|
|
||||||
intc_m_enable_irq(_dcd_controller[busid].irqnum);
|
intc_m_enable_irq(_dcd_irqnum[busid]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_dc_deinit(uint8_t busid)
|
int usb_dc_deinit(uint8_t busid)
|
||||||
{
|
{
|
||||||
intc_m_disable_irq(_dcd_controller[busid].irqnum);
|
intc_m_disable_irq(_dcd_irqnum[busid]);
|
||||||
|
|
||||||
usb_device_deinit(g_hpm_udc[busid].handle);
|
usb_device_deinit(g_hpm_udc[busid].handle);
|
||||||
|
|
||||||
@@ -325,14 +323,14 @@ void USBD_IRQHandler(uint8_t busid)
|
|||||||
|
|
||||||
void isr_usbd0(void)
|
void isr_usbd0(void)
|
||||||
{
|
{
|
||||||
USBD_IRQHandler(0);
|
USBD_IRQHandler(_dcd_busid[0]);
|
||||||
}
|
}
|
||||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbd0)
|
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbd0)
|
||||||
|
|
||||||
#ifdef HPM_USB1_BASE
|
#ifdef HPM_USB1_BASE
|
||||||
void isr_usbd1(void)
|
void isr_usbd1(void)
|
||||||
{
|
{
|
||||||
USBD_IRQHandler(1);
|
USBD_IRQHandler(_dcd_busid[1]);
|
||||||
}
|
}
|
||||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbd1)
|
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbd1)
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user