📄 usb.html
字号:
<TR> <TD VALIGN=MIDDLE><PRE>#define Usb_enable_int ( ) ( IEN1 |= MSK_EUSB ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_disable_int ( ) ( IEN1 &= ~MSK_EUSB ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE></PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_enable_reset_int ( ) ( USBIEN |= MSK_EEORINT ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_enable_resume_int ( ) ( USBIEN |= MSK_EWUPCPU ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_enable_sof_int ( ) ( USBIEN |= MSK_ESOFINT ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_enable_suspend_int ( ) ( USBIEN |= MSK_ESPINT ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_disable_reset_int ( ) ( USBIEN &= ~MSK_EEORINT ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_disable_resume_int ( ) ( USBIEN &= ~MSK_EWUPCPU ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_disable_sof_int ( ) ( USBIEN &= ~MSK_ESOFINT ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define Usb_disable_suspend_int ( ) ( USBIEN &= ~MSK_ESPINT ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE></PRE></TD></TABLE><P>This macro swaps the Uchar order in words.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>x : (Uint16) the 16 bit word to swap return: (Uint16) the 16 bit word x with the 2 bytes swaped </PRE></TD></TABLE><HR><H2> Functions </H2><A NAME="configure_usb_clock"></A><H3> configure_usb_clock </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#configure_usb_clock">configure_usb_clock</A> ( void ) </PRE></TD></TABLE><P>This function configure the PLL to generate the 48MHz clock required bythe USB controller, considering the FOSC defined in the "config.h" file.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: noneThe possible value for FOSC are : 3000 ( 3MHz) 6000 ( 6MHz) 8000 ( 8MHz) 12000 (12MHz) 16000 (16MHz) 18000 (18MHz) 20000 (20MHz) 24000 (24MHz) 32000 (32MHz) 40000 (40MHz) 48000 (48MHz) 0000 (frequency auto-dectection)</PRE></TD></TABLE><H4> Example </H4><PRE>#define FOSC 8000 // 8MHzconfigure_usb_clock();</PRE><HR><A NAME="usb_configure_endpoint"></A><H3> usb_configure_endpoint </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#usb_configure_endpoint">usb_configure_endpoint</A> ( Uchar ep_num , Uchar ep_type ) </PRE></TD></TABLE><P>This function configures an endpoint with the selected type.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>ep_num: Number of the endpoint to configureep_type: Type to configure The possible types are: CONTROL BULK_IN BULK_OUT INTERRUPT_IN INTERRUPT_OUT ISOCHRONOUS_IN ISOCHRONOUS_OUTreturn: none</PRE></TD></TABLE><H4> Example </H4><PRE>usb_configure_endpoint(0,CONTROL);</PRE><H4> Note </H4><P>The endpoint 0 shall always be configured in CONTROL type.<HR><A NAME="usb_get_nb_byte"></A><H3> usb_get_nb_byte </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>Uchar <A HREF="#usb_get_nb_byte">usb_get_nb_byte</A> ( void ) </PRE></TD></TABLE><P>This function returns the number of byte stored in the currently selectedendpoint.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: number of byte stored in the currently selected endpoint</PRE></TD></TABLE><H4> Note </H4><P>This function shall be launched only for OUT endpoints after each receiptand before any other operation.This function shall not be used if the declared FIFO size is more than255 bytes. In this case, use the usb_get_nb_byte_epw function.<HR><A NAME="usb_get_nb_byte_epw"></A><H3> usb_get_nb_byte_epw </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>Uint16 <A HREF="#usb_get_nb_byte_epw">usb_get_nb_byte_epw</A> ( void ) </PRE></TD></TABLE><P>This function returns the number of byte stored in the endpoint 6.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: number of byte stored in the endpoint .</PRE></TD></TABLE><H4> Note </H4><P>This function shall be launched only for OUT endpoints after each receiptand before any other operation.This function shall be used if the declared FIFO size is more than255 bytes.<HR><A NAME="usb_halt_endpoint"></A><H3> usb_halt_endpoint </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#usb_halt_endpoint">usb_halt_endpoint</A> ( Uchar ep_num ) </PRE></TD></TABLE><P>This function sends a STALL handshake for the next Host request. A STALLhandshake will be send for each next request untill a SETUP or a Clear HaltFeature occurs for this endpoint.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>ep_num: number of the addressed endpointreturn: none</PRE></TD></TABLE><HR><A NAME="usb_read_packet"></A><H3> usb_read_packet </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>Uchar * <A HREF="#usb_read_packet">usb_read_packet</A> ( Uchar ep_num , Uchar * rbuf , Uchar data_length ) </PRE></TD></TABLE><P>This function moves the data stored in the selected endpoint fifo tothe address specified by *rbuf.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>ep_num: number of the addressed endpoint*rbuf: address of the first data to write with the USB datadata_length: number of bytes to readreturn: address of the next Ucharto send</PRE></TD></TABLE><H4> Example </H4><PRE>while(!(Usb_rx_complete)); // wait new packet receivedusb_read_packet(4,&first_data,usb_get_nb_byte); // read packet from ep 4Usb_clear_rx(); // acknowledge the transmit</PRE><H4> Note </H4><P>rbuf is incremented of 'data_length'.<HR><A NAME="usb_reset_endpoint"></A><H3> usb_reset_endpoint </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#usb_reset_endpoint">usb_reset_endpoint</A> ( Uchar ep_num ) </PRE></TD></TABLE><P>This function resets the endpoint fifo. This should be performed beforethe first use of an endpoint and after a Clear Halt Feature for theendpoint<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: none</PRE></TD></TABLE><HR><A NAME="usb_select_endpoint_interrupt"></A><H3> usb_select_endpoint_interrupt </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>Uchar usb_select_enpoint_interrupt ( void ) </PRE></TD></TABLE><P>This function select the endpoint where an event occurs and returns thenumber of this endpoint. If no event occurs on the endpoints, thisfunction returns 0.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: endpoint number</PRE></TD></TABLE><HR><A NAME="usb_send_ep0_packet"></A><H3> usb_send_ep0_packet </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>Uchar * <A HREF="#usb_send_ep0_packet">usb_send_ep0_packet</A> ( Uchar * tbuf , Uchar data_length ) </PRE></TD></TABLE><P>This function moves the data pointed by tbuf to the default Controlendpoint fifo and sends it through the USB.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>*tbuf: address of the first data to senddata_length: number of bytes to sendreturn: address of the next Ucharto send</PRE></TD></TABLE><H4> Example </H4><PRE>usb_send_ep0_packet(&first_data,0x20); // send packetwhile(!(Usb_tx_complete)); // wait packet ACK'ed by the HostUsb_clear_tx_complete(); // acknowledge the transmit</PRE><H4> Note </H4><P>tbuf is incremented of 'data_length'.<HR><A NAME="usb_send_packet"></A><H3> usb_send_packet </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>Uchar * <A HREF="#usb_send_packet">usb_send_packet</A> ( Uchar ep_num , Uchar * tbuf , Uchar data_length ) </PRE></TD></TABLE><P>This function moves the data pointed by tbuf to the selected endpoint fifoand sends it through the USB.<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>ep_num: number of the addressed endpoint*tbuf: address of the first data to senddata_length: number of bytes to sendreturn: address of the next Uchar to send</PRE></TD></TABLE><H4> Example </H4><PRE>usb_send_packet(3,&first_data,0x20); // send packet on the endpoint #3while(!(Usb_tx_complete)); // wait packet ACK'ed by the HostUsb_clear_tx_complete(); // acknowledge the transmit</PRE><H4> Note </H4><P>tbuf is incremented of 'data_length'.<HR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -