Disclosure of Invention
The invention provides a universal serial bus device, which comprises a data buffer memory, a terminal and a connecting port. The data buffer memory comprises a first buffer area and a second buffer area. The first buffer is used for storing a first data. The second buffer is used for storing a second data. The endpoints correspond to the first and second buffers. The connection port is used for coupling a host. When the host issues a bulk input request, the endpoint reads the first or second buffer according to a buffer conversion flag.
In one embodiment, when the buffer conversion flag is a first value, the endpoint reads the first buffer to provide a first data to the host. When the buffer conversion flag is a second value, the endpoint reads the second buffer to provide a second data to the host.
In another possible embodiment, the buffer conversion flag is set to the second value when the endpoint starts to provide the first data to the host. The buffer conversion flag is set to the first value when the endpoint starts providing the host with the second data.
The invention also provides an access method which is suitable for the universal serial bus device. The USB device has a data buffer memory. The data buffer memory comprises a first buffer area and a second buffer area. The access method of the invention comprises the following steps: setting an endpoint corresponding to the first buffer area and the second buffer area; receiving an external instruction; when the external instruction is a bulk input request, the first or second buffer is read according to a buffer conversion flag.
In one embodiment, when the buffer conversion flag is a first value, the first buffer is read to provide a first data to an external host. When the buffer conversion flag is a second value, the second buffer is read to provide a second data to an external host.
In another possible embodiment, the buffer conversion flag is changed from the first value to the second value when the endpoint starts providing the first data to the external host. The buffer conversion flag is changed from the second value to the first value when the endpoint starts providing the external host with the second data.
The access method of the present invention can be implemented by the usb device of the present invention, and the usb device is hardware capable of executing a specific function, or can be stored in a storage medium in the form of a program code and implemented by combining with specific hardware. When the program code is loaded into and executed by an electronic device, processor, computer, or machine, the electronic device, processor, computer, or machine becomes a universal serial bus device for practicing the invention.
Detailed Description
In order to make the objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below. The present description provides various examples to illustrate the technical features of various embodiments of the present invention. The configuration of the elements in the embodiments is for illustration only and not for limiting the invention. In addition, the reference numerals in the embodiments are partially repeated to simplify the description, and do not indicate the relationship between the different embodiments.
FIG. 1 is a schematic diagram of an operating system of the present invention. As shown, the operating system 100 includes a host 110 and a Universal Serial Bus (USB) device 120. The host 110 includes a connection port 111 for coupling with a usb device 120. In the present embodiment, the connection port 111 is a USB 2.0 connection port. The present invention does not limit the number of usb devices. In other embodiments, the host 110 may be coupled to more USB devices. In this example, the host 110 assigns different addresses to different USB devices.
The USB device 120 includes end points (endpoints) 121-124, a data buffer 125 and a connection port 128. In one possible embodiment, the USB Device 120 is a Full-Speed Device (Full-Speed Device) with a transmission rate up to 12 Mbps.
The connection port 128 is for coupling to the host 110. In one embodiment, the connection port 128 is coupled to the host 110 via a connection line 130. In another possible embodiment, connection port 128 plugs directly into connection port 111 of host 110. In this example, the connection port 128 is also a USB 2.0 connection port.
The terminals 121-124 are coupled between the connection port 128 and the data buffer memory 125. The endpoints 121-124 correspond to different types of transmissions. In the present embodiment, the endpoints 121-124 share a data buffer 125. In one embodiment, each endpoint communicates with the host 110 through a corresponding virtual pipe (virtual pipe). The number of endpoints is not limited by the invention. In other embodiments, the usb device 120 may have more terminals.
The host 110 enables a corresponding function using at least one endpoint in the usb device 120. For example, if the usb device 120 has both mouse and usb functions, the host 110 may utilize a first specific endpoint inside the usb device 120 to perform an interrupt transfer (interrupt transfer) for activating the mouse function. IN this example, the first particular endpoint makes an interrupt IN (interrupt IN) transmission. In addition, the host 110 may utilize a second specific endpoint and a third specific endpoint within the usb device 120 to perform a bulk transfer (bulk transfer) for reading data or writing data. IN this case, the second specific endpoint performs a bulk-IN (bulk-IN) transfer, and the third specific endpoint performs a bulk-OUT (bulk-OUT) transfer. Therefore, when the host 110 wants to use a specific function of the usb device 120, the host 110 only needs to designate the corresponding endpoint to use the function of the usb device 120.
In this embodiment, the endpoints 121 and 122 perform a control transfer (control transfer) for controlling the transfer command and status operations, such as setting up the USB device, obtaining information about the USB device, sending commands to the USB device, etc. IN one embodiment, the endpoint 121 performs a control IN transfer to provide data from the data buffer memory 125 to the host 110, and the endpoint 122 performs a control OUT transfer to write output data from the host 110 to the data buffer memory 125. In addition, endpoints 123 and 124 perform a Bulk transfer (Bulk Transfers) for Bulk data Transfers. In this embodiment, the endpoint 123 performs a bulk-in transfer for providing data from the data buffer memory 125 to the host 110, and the endpoint 124 performs a bulk-out transfer for writing output data from the host 110 to the data buffer memory 125. In the present embodiment, the endpoint 123 corresponds to the buffers 126 and 127 of the data buffer 125. In other embodiments, the usb device 120 may have other terminals for interrupt transmission. In this example, the endpoint performing the interrupt transmission transmits a small amount of data with a fixed speed.
The present invention is not limited to the type of data buffer memory 125. In one embodiment, the data buffer 125 is a Volatile Memory (Volatile Memory), such as a Dynamic Random Access Memory (DRAM) or a Static Random Access Memory (SRAM). In one possible embodiment, the storage space of the data buffer memory 125 is 512 Bytes.
In addition, the present invention is not limited to the size of the buffers 126 and 127. In one embodiment, the storage space of the buffer 126 is the same as the storage space of the buffer 127. For example, the storage space of the buffers 126 and 127 are 64 Bytes. In this embodiment, the start address of the buffer 126 is 0108 and the end address thereof is 0147, and the start address of the buffer 127 is 01C8 and the end address thereof is 0207. Thus, buffer 127 is not adjacent to buffer 126. In other examples, buffer 127 may be adjacent to buffer 126. In this example, the ending address of buffer 126 is 0147, and the starting address of buffer 127 is 0148.
IN the present embodiment, when the host 110 issues a Bulk input request (Bulk IN transfer), the endpoint 123 reads the buffer 126 or the buffer 127 according to a buffer toggle flag (buffer toggle flag). In one possible embodiment, the initial value of the buffer switch flag BUFTOG is a value of 0. Since the buffer conversion flag BUFTOG is 0, a write circuit (not shown) writes a data DT1 in the buffer 126. At this time, if the host 110 issues a bulk-in request, the endpoint 123 reads the buffer 126 to provide the data DT1 to the host 110 since the buffer conversion flag BUFTOG is 0.
When the endpoint 123 starts to provide the data DT1 to the host 110, a hardware configuration (not shown) changes the buffer conversion flag BUFTOG to a value of 1. Since the buffer conversion flag BUFTOG is a value of 1, a write circuit (not shown) writes a data DT2 in the buffer 127. Therefore, when the host 110 issues a large input request again, the endpoint 123 reads the buffer 127 to provide the data DT2 to the host 110 since the buffer conversion flag BUFTOG is 1.
When the endpoint 123 starts to provide data DT2 to the host 110, the hardware configuration changes the buffer conversion flag BUFTOG to a value of 0. Accordingly, a write circuit (not shown) writes a data DT3 in the buffer 126. At this point, if the host 110 issues a large input request again, the endpoint 123 reads the buffer 126 to provide the data DT3 to the host 110 since the buffer conversion flag BUFTOG is 0.
When the endpoint 123 starts providing data DT3 to the host 110, the hardware configuration (not shown) changes the buffer conversion flag BUFTOG to a value of 1. Since the buffer conversion flag BUFTOG is 1, a write circuit (not shown) writes a data DT4 in the buffer 127. Therefore, when the host 110 issues a large input request again, the endpoint 123 reads the buffer 127 to provide the data DT4 to the host 110 since the buffer conversion flag BUFTOG is 1.
Because the host 110 can read the data of the two buffers only through a single endpoint (e.g. 123) in the usb device 120, and does not need to read the data of the two buffers through the two endpoints, it can avoid the situation that the multiple functions of the composite device cannot be realized simultaneously due to the shortage of the endpoints, thereby reducing the number of the endpoints used when a function is realized in the usb device 120. In addition, by using two buffers, the occurrence of the situation that the usb device 120 temporarily has no data to transmit to the host 110 or cannot receive data from the host 110 can be reduced, thereby improving the efficiency of the usb device 120. In addition, by determining the value of the buffer conversion flag BUFTOG, the data can be automatically switched between the two buffers to write the data into the free buffer in advance, thereby increasing the access speed.
FIG. 2 is a schematic flow chart of an accessing method according to the present invention. The access method of the invention is suitable for the universal serial bus device. The USB device has a data buffer memory. The data buffer memory comprises a first buffer area and a second buffer area. The present invention does not limit the type and size of the data buffer. In one embodiment, the data buffer is a static random access memory with 512Bytes of storage space.
First, an endpoint in the usb device is set to correspond to the first and second buffers (step S211). In one embodiment, the endpoint is configured to perform a bulk-in transfer. The present invention does not limit the location of the first and second buffers in the data buffer memory. In one possible embodiment, the first buffer area is adjacent to or not adjacent to the second buffer area. In other embodiments, the storage space of the first buffer and the storage space of the second buffer may be the same or different.
Then, an external command is received (step S212). In this embodiment, the external command is provided by a host. The host requests the USB device to output data or provides data to the USB device through an external command. When the external instruction is a bulk input request, the first or second buffer is read according to a buffer conversion flag (step S213).
In the present embodiment, step S213 includes steps S214 to S216. In step S214, it is determined whether the buffer status flag is a first value (e.g., 0). When the buffer conversion flag is the first value, the first buffer is read to provide the host with a first data (step S215). In one embodiment, the buffer conversion flag is changed to a second value (e.g., 1) after the first data is initially provided to the host. At this time, the write priority of the first buffer is higher than the write priority of the second buffer. In this example, if there is new data (e.g., third data) to be written, the first buffer is written preferentially.
When the buffer conversion flag is not the first value (e.g., the value 1), the second buffer is read (step S216) to provide the host with a second data. At this time, since the buffer conversion flag is not the first value, a third data is written into the first buffer. In addition, the buffer conversion flag is changed to the first value when the second data is provided to the host. At this time, the writing priority of the second buffer is higher than that of the first buffer. Therefore, if new data (e.g., fourth data) is to be written, the data is written preferentially in the second buffer.
The access methods of the present invention, or certain aspects or portions thereof, may exist in the form of program code. The program code may be stored in a storage medium, such as a floppy disk, a compact disk, a hard disk, or any other machine-readable (e.g., computer-readable) storage medium, or is a computer program product, which is not limited to external forms, wherein, when the program code is loaded into and executed by a machine, such as a computer, the machine becomes a universal serial bus (usb) device for practicing the invention.
The program code may also be transmitted over some transmission medium, such as over electrical wiring or cabling, through fiber optics, or via any other form of transmission, wherein, when the program code is received and loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the invention. When implemented in a general-purpose processing unit, the program code combines with the processing unit to provide a unique apparatus that operates analogously to specific logic circuits.
Unless otherwise defined, all terms (including technical and scientific terms) used herein are to be interpreted as commonly understood by one of ordinary skill in the art to which this invention belongs. Moreover, unless expressly stated otherwise, the definition of a term in a general dictionary shall be construed as being consistent with its meaning in the context of the relevant art and shall not be construed as an idealized or overly formal meaning.
Although the present invention has been described with reference to the above preferred embodiments, it should be understood that various changes and modifications can be made by those skilled in the art without departing from the spirit and scope of the invention. For example, the systems, devices, or methods described in the embodiments of the present invention may be implemented in hardware, software, or a combination of hardware and software. Therefore, the protection scope of the present invention is subject to the protection scope defined by the claims.