Ejemplo n.º 1
0
void Chap9_SetInterface(void)
{
    UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;

    if(dir)
        Chap9_StallEP0InControlRead();


    if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
        Chap9_StallEP0InControlRead();



    else
    {

        if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
        {
            ALTERNATIVE_SETTING = 0;
            Chap9_SingleTransmitEP0(0,0);
        }

        else if (ControlData.DeviceRequest.wValue == 1 && ControlData.DeviceRequest.wIndex == 0)
        {
            ALTERNATIVE_SETTING = 1;
            Chap9_SingleTransmitEP0(0,0);
        }
        else
        {
            Chap9_StallEP0InControlWrite();
        }
    }

}
Ejemplo n.º 2
0
void Chap9_SetConfiguration(void)
{
  
	if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
	{
		if(ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 0)
		{
			if (ControlData.DeviceRequest.wValue == 0)
			{
				/* put device in unconfigured state */
				bD13flags.bits.configuration = 0;
				bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 1;
				Chap9_SingleTransmitEP0(0, 0);
			}
			else if (ControlData.DeviceRequest.wValue == 1)
			{
                printf("configured \n");
				/* Configure device */
				bD13flags.bits.configuration = 1;
				bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 0;
				bUSBCheck_Device_State.State_bits.DEVICE_CONFIGURATION_STATE = 1;
				Chap9_SingleTransmitEP0(0, 0);
			}

			else
				Chap9_StallEP0InControlWrite();
		}
	}

	else
	{
		if (ControlData.DeviceRequest.wValue == 0)
		{
			/* put device in unconfigured state */
			bD13flags.bits.configuration = 0;
			bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 1;
			bUSBCheck_Device_State.State_bits.DEVICE_CONFIGURATION_STATE = 0;
			Chap9_SingleTransmitEP0(0, 0);

		}

		else if (ControlData.DeviceRequest.wValue == 1)
		{
			/* Configure device */
			bD13flags.bits.configuration = 1;
			bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 0;
			bUSBCheck_Device_State.State_bits.DEVICE_CONFIGURATION_STATE = 1;
			Chap9_SingleTransmitEP0(0, 0);
		}
		else
			Chap9_StallEP0InControlWrite();
	}

}
Ejemplo n.º 3
0
void Chap9_GetConfiguration(void)
{
    UCHAR   c = bD13flags.bits.configuration;
    UCHAR   j;

    if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
    {
        j = 0;
        Chap9_SingleTransmitEP0(&j, 1);
    }

    else
    {
        if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 1)
        {

        Chap9_SingleTransmitEP0(&c, 1);
        }
    }

}
Ejemplo n.º 4
0
void Chap9_GetInterface(void)
{

    if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
        Chap9_StallEP0InControlRead();


    else
    {

        if ((ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 1))
            Chap9_SingleTransmitEP0(&ALTERNATIVE_SETTING, 1);      //txdat
        else
            Chap9_StallEP0InControlRead();
    }

}
Ejemplo n.º 5
0
void EnableIsoMode()
{
	IsoMode = 0;
	if( ControlData.DeviceRequest.wLength == 0)
	{
		IsoMode &= ~ControlData.DeviceRequest.wIndex;
		IsoMode |= ControlData.DeviceRequest.wValue;

		printf("IsoMode %x\n",IsoMode );

		if(IsoMode&ISO_LOOP)
		{

		   RaiseIRQL();
		   bD13flags.bits.ISO_state = ISO_LOOP;
		   LowerIRQL();

		   IsoDisable =0;
		   IsoInPattern = 0;
		   IsoInPktLen = ISO_FIFOSIZE_512;
		   IsoOutPattern = 0;
		   IsoOutPktLen = ISO_FIFOSIZE_512;

		}
		else
		{

			 if(IsoMode&ISO_OUT)
			 {

			   RaiseIRQL();
			   bD13flags.bits.ISO_state = ISO_OUT;
			   LowerIRQL();

			   IsoDisable =0;
			   IsoOutPattern = 0;
			   IsoOutPktLen = ISO_FIFOSIZE_512;
			   printf("Iso-Out Pattern %x, PktLen %u bytes\n",IsoInPattern,IsoOutPktLen);

			 }
			 if(IsoMode&ISO_IN)
			 {
				bD13flags.bits.ISO_state = ISO_IN;

			   IsoDisable =0;
			   IsoInPattern = 0;
			   IsoInPktLen = ISO_FIFOSIZE_512;

				//IOWR(ISP1362_BASE,D13_COMMAND_PORT, D13CMD_EP_VALID_BUF+EPINDEX4EP06);
                USB_DC_CMD_WRITE(D13CMD_EP_VALID_BUF+EPINDEX4EP06);
				printf("Iso-IN  Pattern %x, PktLen %u bytes\n",IsoInPattern,IsoInPktLen);
			 }

		}

		Chap9_SingleTransmitEP0(0, 0);
	}
	else
	{
		Chap9_StallEP0();
	}
}
Ejemplo n.º 6
0
void Chap9_SetAddress(void)
{

    UCHAR   j;

    {
        RaiseIRQL();
        disable();
        if(!ControlData.Abort)
        {
            if(bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE)
            {
                if((ControlData.DeviceRequest.wValue & DEVICE_ADDRESS_MASK) != 0 )
                {
                    bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE = 0;
                    Hal4D13_SetAddressEnable((UCHAR)(ControlData.DeviceRequest.wValue &
                                            DEVICE_ADDRESS_MASK), 1);
                    bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 1;
                    Chap9_SingleTransmitEP0(0, 0);

                }

                else
                    bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE = 1;
            }

            else if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
            {
                if((ControlData.DeviceRequest.wValue & DEVICE_ADDRESS_MASK) == 0 )
                {
                    Hal4D13_SetAddressEnable((UCHAR)(ControlData.DeviceRequest.wValue &
                                            DEVICE_ADDRESS_MASK), 1);
                    bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE = 1;
                    bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 0;
                    Chap9_SingleTransmitEP0(0, 0);

                }

                else
                {
                    bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE = 0;
                    Hal4D13_SetAddressEnable((UCHAR)(ControlData.DeviceRequest.wValue &
                                            DEVICE_ADDRESS_MASK), 1);
                    bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 1;
                    Chap9_SingleTransmitEP0(0, 0);

                }

            }

            else
            {

                bUSBCheck_Device_State.State_bits.DEVICE_CONFIGURATION_STATE = 0;
                bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 0;
                bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE = 1;
                j = DEV_BEHAVIOUR_NOT_SPECIFIED;
                Chap9_SingleTransmitEP0(&j, 0);
            }

        }
        LowerIRQL();
        enable();

    }
    printf("Addr %x\n",Hal4D13_GetAddress());
}
Ejemplo n.º 7
0
void Chap9_SetFeature(void)
{
  UCHAR   endp = 0;
    UCHAR   bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
    USHORT  wFeature = ControlData.DeviceRequest.wValue;
  

    if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
    {
        switch(bRecipient)
        {
        case USB_RECIPIENT_DEVICE:
            if(wFeature == USB_FEATURE_REMOTE_WAKEUP)
            {
                bD13flags.bits.remote_wakeup = 1;
                Chap9_SingleTransmitEP0(0, 0);
            }
            else
            {
                Chap9_StallEP0InControlWrite();
            }
            break;

        case USB_RECIPIENT_ENDPOINT:
            if( wFeature == USB_FEATURE_ENDPOINT_STALL)
            {
                if( ControlData.DeviceRequest.wIndex == 0x00 )
                    endp = -1;

                Hal4D13_SetEndpointStatus(endp+1, D13REG_EPSTS_STALL);
                Chap9_SingleTransmitEP0(0, 0);

            }
            else
                Chap9_StallEP0InControlWrite();

            break;
        default:
            Chap9_StallEP0InControlWrite();
            break;
        }
    }


    else
    {
        if( ControlData.DeviceRequest.wLength == 0 )
        {
            switch(bRecipient)
            {
            case USB_RECIPIENT_DEVICE:
                if(wFeature == USB_FEATURE_REMOTE_WAKEUP)
                {
                    bD13flags.bits.remote_wakeup = 1;
                    Chap9_SingleTransmitEP0(0, 0);
                }
                else
                {
                    Chap9_StallEP0InControlWrite();
                }
                break;
            case USB_RECIPIENT_ENDPOINT:
                if( wFeature == USB_FEATURE_ENDPOINT_STALL)
                {
                    if( ControlData.DeviceRequest.wIndex == 0x00 )
                        endp = -1;
                    else
                        endp = (UCHAR)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);

                    Hal4D13_SetEndpointStatus(endp+1, D13REG_EPSTS_STALL);

                    Chap9_SingleTransmitEP0(0, 0);

                }
                else
                {
                    Hal4D13_SetEndpointStatus(endp+1, 0);
                    Chap9_SingleTransmitEP0(0, 0);
                }
                break;
            default:
                Chap9_StallEP0InControlWrite();
                break;
            }
        }
    }



}
Ejemplo n.º 8
0
void Chap9_GetStatus(void)
{
    UCHAR   endp, txdat[2];
    UCHAR   c;
    UCHAR   bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;


    if(bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE)
    {
    switch(bRecipient)
            {
            case USB_RECIPIENT_DEVICE:
                    if(bD13flags.bits.remote_wakeup == 1)
                        txdat[0] = DEVSTS_SELFPOWERED|DEVSTS_REMOTEWAKEUP;   /* remote wakeup and Self-powered */
                    else
                        txdat[0] = DEVSTS_SELFPOWERED;   /* Self-powered*/
                    txdat[1]=0;

                    Chap9_SingleTransmitEP0(txdat, 2);
                    break;

            case USB_RECIPIENT_INTERFACE:

                    Chap9_StallEP0InControlRead();
                    break;

            case USB_RECIPIENT_ENDPOINT:

                    if( ControlData.DeviceRequest.wIndex == 0x00 )
                    {
                        endp = -1;
                        c = Hal4D13_GetEndpointStatusWOInteruptClear(endp + 1);
                        if(c & D13REG_EPSTS_STALL)
                            txdat[0] = ENDPSTS_HALT;   /* Halt */
                        else
                            txdat[0] = 0;

                        txdat[1] = 0;

                        Chap9_SingleTransmitEP0(txdat, 2);
                    }
                    else
                        Chap9_StallEP0InControlRead();

                    break;

            default:
                    Chap9_StallEP0InControlRead();
                    break;
            }
    }


    else
    {
        if(ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wLength == 2 )
        {
            switch(bRecipient)
            {
            case USB_RECIPIENT_DEVICE:
                    if(bD13flags.bits.remote_wakeup == 1)
                        txdat[0] = DEVSTS_SELFPOWERED|DEVSTS_REMOTEWAKEUP;   /* remote wakeup and Self-powered */
                    else
                        txdat[0] = DEVSTS_SELFPOWERED;   /* Self-powered*/
                    txdat[1]=0;

                    Chap9_SingleTransmitEP0(txdat, 2);
                    break;

            case USB_RECIPIENT_INTERFACE:
                    txdat[0]=0;
                    txdat[1]=0;

                    Chap9_SingleTransmitEP0(txdat, 2);
                    break;

            case USB_RECIPIENT_ENDPOINT:

                    if( ControlData.DeviceRequest.wIndex == 0x00 )
                        endp = -1;
                    else
                        endp = (UCHAR)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);

                    c = Hal4D13_GetEndpointStatusWOInteruptClear(endp + 1);
                    if(c & D13REG_EPSTS_STALL)
                        txdat[0] = ENDPSTS_HALT;   /* Halt */
                    else
                        txdat[0] = 0;

                    txdat[1] = 0;

                    Chap9_SingleTransmitEP0(txdat, 2);
                    break;

            default:
                    Chap9_StallEP0InControlRead();
                    break;
            }
        }
    }

}