Ejemplo n.º 1
0
/* EP0 TX handler, called when EP0 interrupt happened and in TX state, 
     or EP0 just translate from IDLE to TX state */
static void USB_Endpoint0_Tx(void)
{
	kal_int32 nBytes;

	/* Determine number of bytes to send */
	if (gUsbDevice.ep0info.nBytesLeft <= USB_EP0_MAXP) 
	{
		nBytes = gUsbDevice.ep0info.nBytesLeft;
		gUsbDevice.ep0info.nBytesLeft = 0;
	}
	else 
	{
		nBytes = USB_EP0_MAXP;
		gUsbDevice.ep0info.nBytesLeft -= USB_EP0_MAXP;
	}

	/* send out data */
	USB_EPFIFOWrite (0, nBytes, gUsbDevice.ep0info.pData);

	/* update data pointer and  prepare for next transaction */
	gUsbDevice.ep0info.pData = (kal_uint8 *)gUsbDevice.ep0info.pData + nBytes;
	
	if (nBytes < USB_EP0_MAXP) 
	{
		gUsbDevice.ep0_state = USB_EP0_IDLE;
		/* last data, set end as true*/
		USB_Update_EP0_State(USB_EP0_DRV_STATE_WRITE_RDY, KAL_FALSE, KAL_TRUE);
	}
	else
	{
		USB_Update_EP0_State(USB_EP0_DRV_STATE_WRITE_RDY, KAL_FALSE, KAL_FALSE);
	}
}
Ejemplo n.º 2
0
static void USB2UART_CtrlDCD(UART_PORT port, IO_level SDCD, module_type ownerid)
{
    kal_uint32 savedMask;
    kal_bool  b_set_intr;
    kal_uint8  ep_num = 0;
#ifdef USB_20_ENABLE
    kal_uint32 max_intr_pkt_size;
#endif


#ifndef  __PRODUCTION_RELEASE__
    USB_Dbg_Trace(USB_ACM_SEND_INTERRUPT, drv_get_current_time(), g_UsbACM.intr_state, 0);

    if(ownerid != USB2UARTPort.ownerid)
    {
        EXT_ASSERT( 0, (kal_uint32) ownerid, USB2UARTPort.ownerid, 0);
    }
#endif

    savedMask = SaveAndSetIRQMask();
    if((g_UsbACM.intr_state == ACM_INTR_IDLE)&&(gUsbDevice.is_configured_now == KAL_TRUE))
    {
        b_set_intr = KAL_TRUE;
        g_UsbACM.is_intr_pending_pkt = KAL_FALSE;
        ep_num = g_UsbACM.intrpipe->byEP;
    }
    else
    {
        b_set_intr = KAL_FALSE;
        g_UsbACM.is_intr_pending_pkt = KAL_TRUE;
    }

    if(SDCD == io_high)
        g_UsbACM.intr_pkt.Data = SERIAL_STATE_BRXCARRIER;
    else if (SDCD == io_low)
        g_UsbACM.intr_pkt.Data = 0x00;
    else
        ASSERT(0);
    RestoreIRQMask(savedMask);

    if(b_set_intr == KAL_TRUE)
    {
#ifdef USB_20_ENABLE
        if(USB_Is_High_Speed() == KAL_TRUE)
            max_intr_pkt_size = USB_EP_INTR_MAXP_HS;
        else
            max_intr_pkt_size = USB_EP_INTR_MAXP_FS;

        if(max_intr_pkt_size > sizeof(UsbAcm_Intr_Pkt))
#else
        if(USB_EP_INTR_MAXP > sizeof(UsbAcm_Intr_Pkt))
#endif
        {
            g_UsbACM.intr_state = ACM_INTR_SEND_LAST_PKT;

#ifndef  __PRODUCTION_RELEASE__
            /* send only one short packet */
            USB_Dbg_Trace(USB_ACM_SEND_INTERRUPT2, drv_get_current_time(), g_UsbACM.intr_state, 0);
            drv_trace1(TRACE_FUNC, USBACM_INTR, g_UsbACM.intr_pkt.Data);
//			kal_prompt_trace(MOD_USB, "ACM INTR %d", g_UsbACM.intr_pkt.Data);
#endif
            USB_EPFIFOWrite(ep_num, sizeof(UsbAcm_Intr_Pkt), (kal_uint8 *)&g_UsbACM.intr_pkt);
            USB_EP_Bulk_Tx_Ready(ep_num);
        }
        else
        {
            g_UsbACM.intr_state = ACM_INTR_SEND_ONE_PKT;

#ifndef  __PRODUCTION_RELEASE__
            /* send one max packet */
            USB_Dbg_Trace(USB_ACM_SEND_INTERRUPT1, drv_get_current_time(), g_UsbACM.intr_state, 0);
            drv_trace1(TRACE_FUNC, USBACM_INTR, g_UsbACM.intr_pkt.Data);
//			kal_prompt_trace(MOD_USB, "ACM INTR %d", g_UsbACM.intr_pkt.Data);
#endif
#ifdef USB_20_ENABLE
            USB_EPFIFOWrite(ep_num, max_intr_pkt_size, (kal_uint8 *)&g_UsbACM.intr_pkt);
#else
            USB_EPFIFOWrite(ep_num, USB_EP_INTR_MAXP, (kal_uint8 *)&g_UsbACM.intr_pkt);
#endif
            USB_EP_Bulk_Tx_Ready(ep_num);
        }
    }
}