This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6748: Why is there no USB_close() API in pdk_omapl138_1_0_10?

Part Number: TMS320C6748
Other Parts Discussed in Thread: OMAPL138

Hi!

Why does pdk_omapl138_1_0_10 have no USB_close() API?

While developing the USB Audio feature, I have opened the device with USB_open() function, and the Audio input/output function is implemented.

 I want to close the USB Audio device when it disconnects from the PC.How to achieve?

Best Regards!

Shide.Lu

  • Hello,

    Many embedded use cases don't need a close function. If your use case does, you'll need to implement that yourself. The provided software is feature complete and we don't have plans to make any further modifications.

    Thank you.

  • Hi!

    Thanks for reply.

    Before calling USB_open(), I do the soft reset as below:

        /* soft reset the USB controller */

        regVal = HWREG(SOC_USB_0_REGS + 4/*CTRLR*/);
        HWREG(SOC_USB_0_REGS + 4/*CTRLR*/= regVal | 0x01;

     

        if (0 != usb_handle) {
            usb_handle->isOpened = 0;
        }
        
        usb_handle = USB_open(usb_dev_params.instanceNo&usb_dev_params);
    The 1st time is running well, but the 2nd time is not.
    If I want to impletment USB_close(), what steps should be involved?
    Thank you.
  • The three main functions are as follows. And the task for usb_audio_taskFxn() Is created dynamically.

    USB_Handle  usb_handle = 0;
    HwiP_Handle hwiHandle = NULL;
    //*****************************************************************************
    // task function
    //
    //*****************************************************************************
    Void usb_audio_taskFxn(UArg a0, UArg a1)
    {
        USB_Params  usb_dev_params;
        UInt        events;
        uint32_t regVal;

        ///consolePrintf("\nRTOS USB Dev AC example!!\n");
        printf("\nRTOS USB Device Audio Class Example!!\n");

        usb_dev_params.usbMode = USB_DEVICE_AC_MODE;
        usb_dev_params.instanceNo = USB_DEV_INSTANCE;  /* USB port # */
        usb_dev_params.usbClassData = (void*)&g_sAudioDevice;
        
        /* soft reset the USB controller */
        regVal = HWREG(SOC_USB_0_REGS + 4/*CTRLR*/);
        HWREG(SOC_USB_0_REGS + 4/*CTRLR*/= regVal | 0x01;

        if (0 != usb_handle) {
            usb_handle->isOpened = 0;
        }
        
        usb_handle = USB_open(usb_dev_params.instanceNo&usb_dev_params);
        
        if (usb_handle == 0
        {
            ///consolePrintf("Failed to open USB driver\n");
            printf("Failed to open USB driver\n");
            // UART_printStatus("\n Some tests have failed.\n");
            while(1);
        }

        usbdIntrConfig(usb_handle&usb_dev_params);

        ///consolePrintf("Done configuring USB and its interrupt. Example is ready!\n");
        printf("Done configuring USB and its interrupt. Example is ready!\n");
        Event_pend(event_usb_core, Event_Id_NONE, 0xFFFFFFFF, BIOS_NO_WAIT); // 清除所有事件
        while(1)
        {
            /* Main while loop. All USB dev events are handled in interrupt context */
            events = Event_pend(event_usb_core, Event_Id_NONE, USB_CORE_INT_EVNT | USB_CORE_DISCONNECT_EVNT, BIOS_WAIT_FOREVER);

            /* calling the main event handler */
            if (events & USB_CORE_INT_EVNT)
            {
                USB_coreIrqHandler(usb_dev_params.usbHandle&usb_dev_params);
                Osal_EnableInterrupt(SYS_INT_USB0,  OSAL_REGINT_INTVEC_EVENT_COMBINER);
            }
            if (events & USB_CORE_DISCONNECT_EVNT)
            {
                // USB_close(usb_dev_params.instanceNo); // TODO: pdk中没有提供USB_close()接口,所以未能关闭USB设备
                usb_audio_taskFxn_exist = 0;    // 将任务标记为已删除
                Event_post(event_usbUSB_CORE_TASK_EXIT);
                Task_exit();                 // 将任务设置为终结状态
            }
        }
    }

    void usbdIntrConfig(USB_Handle usbHandle, USB_Params* usbDevParams)
    {
        OsalRegisterIntrParams_t interruptRegParams;

        /* Initialize with defaults */
        Osal_RegisterInterrupt_initParams(&interruptRegParams);

        /* Populate the interrupt parameters */
        interruptRegParams.corepacConfig.name=NULL;
        interruptRegParams.corepacConfig.corepacEventNum=SYS_INT_USB0; /* Event going in to CPU */
        interruptRegParams.corepacConfig.intVecNum= OSAL_REGINT_INTVEC_EVENT_COMBINER; /* Host Interrupt vector */
        interruptRegParams.corepacConfig.isrRoutine = (void (*)(uintptr_t))usbCoreIntrHandler;
        interruptRegParams.corepacConfig.arg = (uintptr_t)usbDevParams;

        Osal_RegisterInterrupt(&interruptRegParams,&hwiHandle);

        USB_irqConfig(usbHandleusbDevParams);

    }

    /* main entry point for DWC core interrupt handler with USB Wrapper setup
    * Matching interrupt call-back function API */
    void usbCoreIntrHandler(uint32_t* pUsbParam)
    {
        Event_post(event_usb_coreUSB_CORE_INT_EVNT);
        Osal_DisableInterrupt(SYS_INT_USB0,  OSAL_REGINT_INTVEC_EVENT_COMBINER);
    }

  • Another question, I have called PSCModuleControl() to enable the USB module like this:

    PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);

    Is there any way to know if the USB is connected to the PC or just to the power adapter, before calling the USB_open() function?

     

    Thank you.