⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_desc.c

📁 ARM9200开发板的ROM boot程序源码1.0
💻 C
📖 第 1 页 / 共 2 页
字号:
	u_int usbState = at91_usb_get_state(USB_PIPE_REF(pPipe));

	/* Check request arguments */
	if (pSetup->wValue != 0 || pSetup->wLength != 1)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) ) {
		/* If an application handler exists, transmit the request */
		if (getInterface)
			(*getInterface)(pPipe, pSetup->wIndex);
		else
			usbDescRequestError(pPipe);
	}
	/* =================== Address state ================= */
	else if ( (usbState & USB_FADDEN) )
		usbDescRequestError(pPipe);
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
}

/* ************************************ */
/* usbDescGetStatus                     */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request returns status for  */
/*     the specified endpoint           */
/* ************************************ */
void usbDescGetStatus(
		void (*getStatus) (),         /* Pointer to application request handler */
		SPipe *pPipe,               /* Default Pipe Handler */
		USBSetupData *pSetup)        /* Descriptor type */
{
	u_int usbState  = at91_usb_get_state(USB_PIPE_REF(pPipe));
	u_int recipient = (pSetup->bmRequestType & 0x1F);

	/* Check request arguments */
	if (recipient > 2 || pSetup->wValue != 0 || pSetup->wLength != 2)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
	else if (recipient == 0 && pSetup->wIndex != 0)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) ) {
		if (getStatus)
			(*getStatus)(pPipe, recipient, pSetup->wIndex);
		else
			usbDescRequestError(pPipe);
	}
	/* =================== Address state ================= */
	else if ( (usbState & USB_FADDEN) ) {
		if (pSetup->wIndex != 0 || !getStatus)
			usbDescRequestError(pPipe);
		else
			(*getStatus)(pPipe, recipient, pSetup->wIndex);
	}
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
}

/* ************************************ */
/* usbDescSetAddress                    */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request sets the device     */
/*     address for all device accesses  */
/* ************************************ */
void usbDescSetAddress(
	void (*setAddress) (),        /* Pointer to application request handler */
	SPipe *pPipe,               /* Default Pipe Handler */
	USBSetupData *pSetup)         /* Descriptor type */
{
	u_int usbState  = at91_usb_get_state(USB_PIPE_REF(pPipe));

	/* Check request arguments */
	if ((pSetup->wValue >= 127) || pSetup->wIndex != 0 || pSetup->wLength != 0)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) )
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
	/* ============ Address or Default state ============= */
	else {
		/* Enter the address state if the value != 0 */
		usbDescSendStatus(pPipe);
		// Wait for TX Complete
		if (setAddress)
			(*setAddress)(pPipe, pSetup->wValue);
	}
}

/* ************************************ */
/* usbDescSetConfiguration              */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request sets the device     */
/*     configuration                    */
/* ************************************ */
void usbDescSetConfiguration(
	void (*setConfiguration) (),  /* Pointer to application request handler */
	SPipe *pPipe,               /* Default Pipe Handler */
	USBSetupData *pSetup)         /* Descriptor type */
{
	u_int usbState  = at91_usb_get_state(USB_PIPE_REF(pPipe));

	/* Check request arguments */
	if ((pSetup->wValue & 0xFF00) || pSetup->wIndex != 0 || pSetup->wLength != 0)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) ) {
		if (pSetup->wValue == 0) {
			/* Device enters Address State */
			at91_usb_set_state(USB_PIPE_REF(pPipe), USB_FADDEN);
			usbDescSendStatus(pPipe);
		}
		else {
			if (setConfiguration)
				(*setConfiguration)(pPipe, pSetup->wValue);
			else
				usbDescRequestError(pPipe);
		}
	}
	/* =================== Address state ================= */
	else if ( (usbState & USB_FADDEN) ) {
		if (pSetup->wValue == 0)
			/* Device remains in Address State */
			usbDescSendStatus(pPipe);
		else {
			if (setConfiguration)
				(*setConfiguration)(pPipe, pSetup->wValue);
			else
				usbDescRequestError(pPipe);
		}
	}
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
}

/* ************************************ */
/* usbDescSetDescriptor                 */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request may be used to      */
/*     update existing descripotrs or   */
/*     new descriptors may be added     */
/* ************************************ */
void usbDescSetDescriptor(
		void (*setDescriptor) (),     /* Pointer to application request handler */
		SPipe *pPipe,               /* Default Pipe Handler */
		USBSetupData *pSetup)         /* Descriptor type */
{
	u_int usbState  = at91_usb_get_state(USB_PIPE_REF(pPipe));

	/* ================ Configured or Address state ================= */
	if ( ((usbState & USB_CONFG) || (usbState & USB_FADDEN))) {
		if (setDescriptor)
			(*setDescriptor) (
				pPipe,
				(pSetup->wValue >> 8),   /* Descriptor type */
				(pSetup->wValue & 0xFF), /* Descriptor index */
				pSetup->wIndex,          /* Language ID */
				pSetup->wLength);        /* Desriptor length */
		else
			usbDescRequestError(pPipe);
	}
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

}

/* ************************************ */
/* usbDescSetFeature                    */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request is used to set or   */
/*     enable a specific feature        */
/* ************************************ */
void usbDescSetFeature(
	void (*setFeature) (),        /* Pointer to application request handler */
	SPipe *pPipe,               /* Default Pipe Handler */
	USBSetupData *pSetup)         /* Descriptor type */
{
	u_int usbState = at91_usb_get_state(USB_PIPE_REF(pPipe));
	u_int recipient = (pSetup->bmRequestType & 0x1F);

	/* Check request arguments */
	if (recipient > 2 || pSetup->wLength != 0)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) ) {
		if (setFeature)
			(*setFeature) (pPipe, recipient, pSetup->wIndex, pSetup->wValue);
		else
			usbDescRequestError(pPipe);
	}
	/* =================== Address state ================= */
	else if ( (usbState & USB_FADDEN) ) {
		/* This request is valid in Address State only when reference endpoint 0 */
		if (recipient != 2 || pSetup->wIndex != 0)
			usbDescRequestError(pPipe);
		else {
			if (setFeature)
				(*setFeature) (pPipe, recipient, pSetup->wIndex, pSetup->wValue);
			else
				usbDescRequestError(pPipe);
		}
	}
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
}

/* ************************************ */
/* usbDescSetInterface                  */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request allows the host to  */
/*     select an alternate setting for  */
/*     the specified interface          */
/* ************************************ */
void usbDescSetInterface(
	void (*setInterface) (),      /* Pointer to application request handler */
	SPipe *pPipe,               /* Default Pipe Handler */
	USBSetupData *pSetup)         /* Descriptor type */
{
	u_int usbState = at91_usb_get_state(USB_PIPE_REF(pPipe));

	/* Check request arguments */
	if (pSetup->wLength != 0)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) ) {
		if (setInterface)
			(*setInterface) (pPipe, pSetup->wIndex, pSetup->wValue);
		else
			usbDescRequestError(pPipe);
	}
	/* =================== Address state ================= */
	else if ( (usbState & USB_FADDEN) )
		usbDescRequestError(pPipe);
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescSendStatus(pPipe);
}

/* ************************************ */
/* usbDescSynchFrame                    */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request is used to set and  */
/*     then report an ep's synch.frame. */
/* ************************************ */
void usbDescSynchFrame(
		void (*synchFrame) (),        /* Pointer to application request handler */
		SPipe *pPipe,               /* Default Pipe Handler */
		USBSetupData *pSetup)         /* Descriptor type */
{
	u_int usbState = at91_usb_get_state(USB_PIPE_REF(pPipe));

	/* Check request arguments */
	if (pSetup->wValue != 0 || pSetup->wLength != 2)
		/* Device behavior not specified */
		usbDescRequestError(pPipe);

	/* ================ Configured state ================= */
	else if ( (usbState & USB_CONFG) ) {
		if (synchFrame)
			(*synchFrame) (pPipe, pSetup->wIndex);
		else
			usbDescRequestError(pPipe);
	}
	/* =================== Address state ================= */
	else if ( (usbState & USB_FADDEN) )
		usbDescRequestError(pPipe);
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		usbDescRequestError(pPipe);
}

/* ************************************ */
/* usbDescSynchFrame                    */
/*                                      */
/* Arguments:                           */
/*     pPipe: pointer to default pipe   */
/*            handler                   */
/*     pEp:   pointer to endpoint       */
/*            standard USB descriptor   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     Configure USB endpoints according*/
/*     to the endpoint descriptor       */
/* ************************************ */
void usbDescConfigure(
		StructUSB *pUsb,
		const char epNumber,
		USBEndpointDesc const *pEp)
{
	if (pEp->bEndpointAddress & (1 << 7)) {
		/* IN endpoint */
		switch (pEp->bmAttributes & 0x03) {
		case 0:  at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_CONTROL);                break;
		case 1:  at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_ISOCHRONOUS_IN); break;
		case 2:  at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_BULK_IN);        break;
		default: at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_INTERRUPT_IN);   break;
		}
	}
	else {
		/* OUT endpoint */
		switch (pEp->bmAttributes & 0x03) {
		case 0:  at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_CONTROL);     break;
		case 1:  at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_ISOCHRONOUS_OUT); break;
		case 2:  at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_BULK_OUT);        break;
		default: at91_usb_ep_configure(pUsb, epNumber, USB_EPDS | USB_INTERRUPT_OUT);   break;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -