int32_t bsp_usb_dev_init(uint8_t controller_id) { int32_t result = 0; result = bsp_usb_dev_io_init(controller_id); if (result != 0) { return result; } /* MPU is disabled. All accesses from all bus masters are allowed */ MPU_CESR=0; if (USB_CONTROLLER_KHCI_0 == controller_id) { /* Configure enable USB regulator for device */ //SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1CFG_URWE_MASK; //SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* Enable internal pull-up resistor */ USB_CONTROL_REG(USB0_BASE_PTR) = USB_CONTROL_DPPULLUPNONOTG_MASK; USB_USBTRC0_REG(USB0_BASE_PTR) |= 0x40; /* Software must set this bit to 1 */ /* setup interrupt */ OS_intr_init(soc_get_usb_vector_number(0), BSP_USB_INT_LEVEL, 0, TRUE); } else { /* unknown controller */ result = -1; } return result; }
int32_t bsp_usb_otg_init(uint8_t controller_id) { int32_t result = 0; result = bsp_usb_otg_io_init(controller_id); if (result != 0) { return result; } if (0 == controller_id) { #if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_MQX) /* Configure enable USB regulator for device */ SIM_SOPT1CFG |= (SIM_SOPT1CFG_URWE_MASK); SIM_SOPT1 |= (SIM_SOPT1_USBREGEN_MASK); /* reset USB CTRL register */ USB0_USBCTRL = 0; /* Enable internal pull-up resistor */ USB0_CONTROL = (USB_CONTROL_DPPULLUPNONOTG_MASK); USB0_USBTRC0 |= (0x40); /* Software must set this bit to 1 */ #else /* Configure enable USB regulator for device */ HW_SIM_SOPT1CFG_SET(SIM_SOPT1CFG_URWE_MASK); HW_SIM_SOPT1_SET(SIM_SOPT1_USBREGEN_MASK); /* reset USB CTRL register */ HW_USB_USBCTRL_WR(0); /* Enable internal pull-up resistor */ HW_USB_CONTROL_WR(USB_CONTROL_DPPULLUPNONOTG_MASK); HW_USB_USBTRC0_SET(0x40); /* Software must set this bit to 1 */ #endif /* setup interrupt */ OS_intr_init(soc_get_usb_vector_number(0), BSP_USB_INT_LEVEL, 0, TRUE); } else { /* unknown controller */ result = -1; } return result; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _usb_otg_max3353_init * Returned Value : * Comments : * * *END*----------------------------------------------------------------------*/ uint8_t _usb_otg_max3353_init ( usb_otg_max3353_call_struct_t * otg_max3353_call_ptr ) { usb_otg_state_struct_t * usb_otg_struct_ptr = ((usb_otg_max3353_call_struct_t *)otg_max3353_call_ptr)->otg_handle_ptr; uint8_t channel = otg_max3353_call_ptr->channel; /* configure GPIO for I2C function */ i2c_Init(channel); _bsp_usb_otg_max3353_set_pin_int(FALSE, TRUE); OS_Event_set(usb_otg_struct_ptr->otg_isr_event, USB_OTG_MAX3353_ISR_EVENT); _otg_max3353_enable_disable(channel,TRUE); OS_install_isr(otg_max3353_call_ptr->init_param_ptr->vector, (void (*)(void *))_usb_otg_max3353_isr, otg_max3353_call_ptr); OS_intr_init(otg_max3353_call_ptr->init_param_ptr->vector,otg_max3353_call_ptr->init_param_ptr->priority,0,TRUE); return USB_OK; }
void time_init(void) { if (kHwtimerSuccess != HWTIMER_SYS_Init(&hwtimer, &HWTIMER_LL_DEVIF, HWTIMER_LL_ID, NULL)) { USB_PRINTF("\r\nError: hwtimer initialization.\r\n"); } if (kHwtimerSuccess != HWTIMER_SYS_SetPeriod(&hwtimer, HWTIMER_PERIOD)) { USB_PRINTF("\r\nError: hwtimer set period.\r\n"); } if (kHwtimerSuccess != HWTIMER_SYS_RegisterCallback(&hwtimer, hwtimer_callback, NULL)) { USB_PRINTF("\r\nError: hwtimer callback registration.\r\n"); } if (kHwtimerSuccess != HWTIMER_SYS_Start(&hwtimer)) { USB_PRINTF("\r\nError: hwtimer start.\r\n"); } OS_intr_init(HWTIMER_IRQ_NUM, HWTIMER_IRQ_PRI, 0, TRUE); }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : usb_otg_soc_init * Returned Value : USB status * Comments : * This function performs BSP-specific I/O initialization related to USB * *END*----------------------------------------------------------------------*/ usb_status usb_otg_soc_init ( uint8_t controller_id ) { usb_status ret = USB_OK; ret = usb_otg_soc_clock_config(controller_id, USB_OTG_PLLFLL_CLK); if (USB_OK != ret) { return ret; } if (USB_CONTROLLER_KHCI_0 == controller_id) { g_khci0_otg_init_param.base_ptr = (void*)soc_get_usb_base_address(controller_id); g_khci0_otg_init_param.vector = soc_get_usb_vector_number(controller_id); uint32_t base_address = soc_get_usb_base_address(controller_id); /* Configure enable USB regulator for device */ SIM_HAL_SetUsbVoltRegulatorWriteCmd((SIM_Type*)(SIM_BASE), TRUE); SIM_HAL_SetUsbVoltRegulatorCmd((SIM_Type*)(SIM_BASE), TRUE); /* reset USB CTRL register */ usb_hal_khci_reset_control_register(base_address); /* Enable internal pull-up resistor */ usb_hal_khci_set_internal_pullup(base_address); usb_hal_khci_set_trc0(base_address); /* Software must set this bit to 1 */ /* setup interrupt */ OS_intr_init((IRQn_Type)soc_get_usb_vector_number(controller_id), (uint8_t)g_khci0_otg_init_param.priority, 0, TRUE); } else { ret = USBERR_BAD_STATUS; /* unknown controller */ } return ret; }