Referring to Fig. 1, micro memory according to band USB (universal serial bus) plug provided by the invention, comprise that a flat package 100 and part are loaded on its inner circuit board (dotting among the figure), be formed with a rectangular depression portion on the shell, so that insert the USB interface of personal computer and pull up this micro memory from this USB interface, USB interface wherein is denoted as J1, and this shell can also be used translucent material, is convenient to see the pilot lamp that is loaded on the internal circuit board.
Referring to Fig. 2 and 3, as a preferred embodiment of the present invention, usb circuit 1 is installed on the described circuit board, microcontroller 2 and flash memory 3, described usb circuit 1 is connected with the USB interface of personal computer by USB plug, described microcontroller circuit 2 and described usb circuit 1 and the multi-thread respectively two-way address that is connected in of flash memory circuit 3, data, on the control bus, the data that personal computer will be preserved are delivered to usb circuit 1 by USB interface earlier, usb circuit 1 is delivered to microcontroller circuit 2 to data by bus again, 2 pairs of data of microcontroller circuit are handled, and then by bus data are delivered to flash circuit 3; The data that read are delivered to microcontroller circuit 2 by flash circuit 3 by bus, 2 pairs of data of microcontroller circuit are handled, and then data are delivered to usb circuit 1 by bus, usb circuit 1 is sent personal computer back to by USB interface again, and the clock source of described microcontroller (2) is provided by described usb circuit (1).Therefore this mode not only can be carried out the encryption and decryption processing of data easily, and the several data protected mode is provided; But also minimizing components and parts number that can amplitude peak reduces cost, and improved the yield rate of reliability and product.
As another kind of preferred embodiment of the present invention, as shown in Figure 7, multi-thread respectively two-way address, the data bus of being connected to of described usb circuit 1, described microcontroller circuit 2 and described flash memory circuit 3; The control bus of described microcontroller 2 is electrically connected with described usb circuit 1 and described flash memory 3 by analog switching circuit 4.Its concrete circuit is as follows: the two-way connection analog switching circuit 4 of described microcontroller circuit 2 control buss, and other has many control lines to connect analog switching circuit 4 and it is controlled; The two-way connection analog switching circuit 4 of the control bus of usb circuit 1; The two-way connection analog switching circuit 4 of the control bus of flash memory circuit 3.The data that personal computer will be preserved are delivered to usb circuit 1 by USB interface earlier, usb circuit 1 is delivered to microcontroller circuit 2 to message by control bus again, 2 pairs of analog switching circuits 4 of microcontroller circuit are controlled, make analog switching circuit 4 be in special state, 2 pairs of control buss of microcontroller circuit are controlled, and make data directly deliver to flash memory circuit 3 by data bus by usb circuit 1 and store; During reading of data, control by 2 pairs of analog switching circuits 4 of microcontroller circuit earlier, make analog switching circuit 4 be in special state, 2 pairs of control buss of microcontroller circuit are controlled, make data directly deliver to usb circuit 1 by data bus by flash memory circuit 3, usb circuit 1 is sent personal computer back to by USB interface again; This mode can reduce the intermediate link of streams data, can improve the throughput of data, reduces data time.
As shown in Figure 3, in the above preferred embodiment that provides, described microcontroller 2 is electrically connected with a condition indication circuit, described condition indication circuit comprises a light emitting diode D2 and resistance R 8, D2 and R8 series connection, the D2 positive pole connects positive source, 14 pin (I/O port) of another termination of R8 U2, show that by this light emitting diode D2 realization state it can show the duty of this micro memory.
As shown in Figure 3, in the above preferred embodiment that provides, described usb circuit 1 is that interface chip U1, crystal resonator Y1, resistance R 1~R4, capacitor C 1~C4, light emitting diode D1, diode D3 and D4, magnetic bead FB1 and FB2, the USB plug J1 of PDIUSBD12 constitutes by model, wherein, D1 and R1 series connection, the anodal positive source that connects of D1,21 pin of another termination of R1 U1 are used for showing the state of USB circuit; C3 and C4 parallel connection, two ends connect positive source and ground respectively, D3 and D4 series connection, and positive pole meets FB1, and negative pole connects positive source, constitutes the step-down filtering circuit, powers to system; The Y1 two ends connect 22,23 pin of C1, C2 and U1 respectively, and C1, C2 other end ground connection are formed oscillatory circuit; The FB1 two ends connect 1 pin and the D4 positive pole of J1 respectively, and the FB2 two ends connect 4 pin and the ground of J1 respectively, constitute low-pass filter, can reduce high frequency interference; 25,26 pin of U1 connect 2,3 pin of J1 respectively through R2, R3, with main-machine communication; 18,19 pin of R4 two termination U1; 18,20,24,27 pin of U1 connect positive source; The 5 pin ground connection of U1, U1 meets USB1.0 and USB1.1 agreement, finishes the data communication of USB.
As shown in Figure 3, in the above preferred embodiment that provides, described microcontroller 2 is made up of microprocessor chip U2, resistance R 5~R8, light emitting diode D2, and the termination power positive pole of R5, R6, the other end connect 13,12 pin of U2 respectively, and pull-up current is provided; The termination power positive pole of R7,9 pin of another termination U2 provide power-on reset signal; D2 and R8 series connection, the D2 positive pole connects positive source, 14 pin of another termination of R8 U2, the state of demonstration microcontroller; Data bus 32~39 pin of U2 are connected with control line with the data of usb circuit U1 respectively with control line 30,16,17,12,28 pin, and U1 is controlled and communicates by letter; Clock incoming line 19 pin of U2 connect clock division output line 13 pin of U1, provide the clock source by U1 to U2.
In the above preferred embodiment that provides, described microprocessor chip U2 can adopt AVR90 or 8051 series, when adopting AVR90 series, microcontroller 2 is electrically connected with an interface J2,1,2,3,4 pin of J2 connect 9,8,7,6 pin of U2 respectively, utilize this interface can realize the function of online programming.
As shown in Figure 3, in the above preferred embodiment that provides, described flash memory 3 is that the flash memory chip U3 by TC58 or K9 series constitutes, and data line 29~32,41~44 pin of U3 are connected with data line 32~39 pin of U2; The control line 6~9 of described U3 and 16~19 pin are connected with control line 4,13,17,27,3,2,16,1 pin of U2 respectively and are connected, by the read-write process of described microcontroller 2 these flash memories 3 of control.
The present invention does not need mechanical fetch equipment, is pure electronics mode access data, and its operation is realized by software.
Before the reading/writing method of the micro memory that describes band USB (universal serial bus) plug provided by the invention in detail, at first explain or define some relevant technical terms that relate to:
So-called USB interface, USB wherein is the abbreviation of original text Universal Serial Bus, i.e. USB (universal serial bus), and its standard is formulated jointly by Compaq, Intel, Microsoft, NEC, be intended to make be connected more simple and conveniently between personal computer and peripheral hardware, versatility is better;
" operating system upper layer drivers ", meaning by operating system provides, and the program of service is provided to application program.This instructions special secondary school refers to file system driver and SCSI class driver;
" device driver " means the specific program corresponding to certain equipment, service is provided for the operating system upper layer drivers, and this instructions special secondary school refers to the device driver of USB interface quickflashing external memory device;
" operating system bsp driver ", meaning by operating system provides, and aims at the program that some general-purpose interface is controlled, and it provides service for some device driver.This instructions special secondary school refers to the USB interface bsp driver;
" microcontroller program ", mean in the microcontroller of the equipment of being solidificated in the Host Command that receives by certain general-purpose interface to be responded, make corresponding operation, and result or state turned back to main frame, the operating system bsp driver of it and main frame is communicated by letter.This instructions specially refers to the program of microcontroller in the USB interface quickflashing external memory device;
The invention provides data in the micro memory of band USB (universal serial bus) plug to deposit in and read with the data block be that unit carries out, wherein the data block size is determined by used flash memory chip characteristic.
Describe the reading/writing method of the micro memory of band USB (universal serial bus) plug provided by the invention in detail below in conjunction with accompanying drawing:
Referring to Fig. 4, shown in it according to the Control Software hierarchy chart of micro memory under WINDOWS98 operating system of band USB (universal serial bus) plug of the present invention.This Control Software is a driver, comprises operating system upper layer drivers (comprising file system driver and SCSI class driver), device driver (comprising SCSI miniport driver and USB driver), USB bsp driver (comprising usb hub driver and usb host controller driver) and microcontroller program.Wherein said microcontroller program is moved solidifying in microcontroller U1 and in microcontroller U1, and control flash memory chip U3 and USB interface chip U1 communicate by letter with the USB bsp driver; Described USB bsp driver is to be provided by operating system under WINDOWS98/2000, LINUX and MAC OS, the bsp driver that under WINDOWS NT, uses the applicant to provide, and it is responsible for communicating by letter of main control system USB interface and device driver; Described device driver is based upon on the USB bsp driver, explain and operation requests that complete operation system or application program are sent the micro memory of band USB (universal serial bus) plug, described operating system upper layer drivers is provided by operating system, and provide service to application program, be responsible for simultaneously sending the read-write requests of application program to device driver.
As shown in Figure 4, after application program sends a read request, this read request at first is sent to file system driver and SCSI class driver, be given to the SCSI miniport driver again, the SCSI miniport driver can be the form of current request conversion cost matching requirements, and passing to the USB driver of this device, the USB driver can send to the request of changing the USB bsp driver, and finally passes to the usb circuit of this device by USB interface.
Referring to Fig. 5, wherein show the driver process flow diagram that the micro memory with band USB (universal serial bus) plug of the present invention provides.Its basic operation process in turn includes the following steps:
As step S
501Shown in, after the micro memory of band USB (universal serial bus) plug inserted the USB socket of main frame, foregoing circuit in the storer will obtain power supply from USB interface, microcontroller U2 resets thereupon and begins to carry out built-in microcontroller program: at first carry out initialization, the effect of this part program is an initial parameter of setting microcontroller U2 and USB interface chip U1; After the work of setting is finished, microcontroller U2 will enter waiting status, wait for that main frame sends request (being that the USB interface chip produces interruption);
As step S
502Shown in, after the USB interface chip U1 initialization, main frame will detect has equipment to connect on the USB interface.The USB bsp driver that is provided by operating system will send a series of requests and install to this, and microcontroller U2 can carry out by USB interface chip U1 and interrupt the interrupt service routine that causes, by each request of interrupt service routine processing host;
As step S
503Shown in, after above-mentioned Request Processing finishes, host operating system will at first load the USB driver in the device driver of writing for this storer that is installed in advance in the host hard drive;
As step S
504Shown in, behind above-mentioned USB driver loaded, the USB driver can at first create a device object and the notifying operation system has new equipment to connect;
As step S
514Shown in, operating system loads the SCSI miniport driver of this storer;
Enter step S then
515, after the USB of this storer driver and SCSI miniport driver all were loaded in the system, main frame carried out initialization and creates a new driver symbol according to device signal;
Enter afterwards and wait for operation steps S
516, after main frame sends a request, then enter step S
517, the operating system upper layer drivers judges whether to be the file read operation, if judged result is sure, then enters step S
518, by calling USB driver read block; As judged result is to negate, and then enters step S
519, judge whether to be the file write operation, if judged result is sure, then enter step S
520,, enter step S then by calling USB driver read block
521, merge new data block and call USB driving writing data blocks; If judged result negates then to enter step S
522, the operating system upper layer drivers judges whether to be unit deletion, if judged result is sure, then enters step S
524, the present invention is unloaded by system; As judged result is to negate, and then enters step S
523, return error message.
As shown in Figure 5, in above-mentioned steps, step S
518, S
521, S
523Promptly enter step S after complete
505, enter the wait solicited status;
As step S
506Shown in, after this storer obtains a request, judge that at first whether this request is read request, if judged result is sure, then enters step S
507, by calling USB bottom layer driving, reading of data; If judged result negates then to enter the determining step S of write request
508If judged result is sure, then enter step S
509,, write data by calling the USB bottom layer driving; If judged result negates then to enter the determining step S of the request of extracting
510If judged result is sure, then enter step S
512, handle and the sweep equipment connection, enter step S then
513, unloaded by system; If judged result negates then to return error message.
When said process carried out, the microcontroller program was also carried out control corresponding, and its flow process in turn includes the following steps as shown in Figure 6: step S
601, this storer inserts computing machine; Step S
602, hardware initialization; Step S
603, wait for and interrupting; Step S
604, the microcontroller program judges whether into USB interrupts, if judged result negates then to turn back to step S
603, wait for and interrupting; If judged result is sure, then enter interrupt service routine, this program at first judges whether to be control transmission, enters step S
605If judged result is sure, then enter step S
606, the disposal system request after disposing, then turns back to step S
603, wait for and interrupting; If judged result negates then to enter step S
607, this program judges whether into the piece transmission, if judged result negates then to turn back to step S
603, wait for and interrupting; If judged result is sure, then enter step S
608, handle self-defined request, after disposing, turn back to step S
603, wait for and interrupting.Afterwards when this device when USB interface is pulled up, then enter S
609Extract step, this microcontroller program quits work, main frame can detect above-mentioned state automatically simultaneously, and notifies the USB driver equipment of this device to remove.The USB driver can carry out some necessary processing, cancels the read-write requests that those are not finished, the sweep equipment object.Because the USB driver has been deleted the device object of being created by it, so after the unloading of the USB driver of this device, the SCSI miniport driver also can be operated system's unloading thereupon.
After above-mentioned preparation was finished substantially, the SCSI miniport driver can first fetch equipment information specific, began then to wait for that application program sends " read/write " request, and so far the initial work of hardware and software is finished, and the present invention enters the read-write requests state of waiting for;
After the USB interface chip received the request that main frame sends by USB interface, the USB interface chip can send a look-at-me to microcontroller, and microcontroller can change carries out interrupt service routine.Interrupt service routine can be analyzed the request that main frame is sent, microcontroller can write down the block description that main frame will read after finding to be read request, can from flash memory chip, read a blocks of data then at every turn and beam back main frame, all send up to the data of all requirements by the USB interface chip.
Issue these data of main frame and can pass to the SCSI miniport driver by the USB driver of this device, and finally pass to application program, read operation is so far finished.
Similar with said process, after operating system is received the write request that application program sends, also can earlier the SCSI miniport driver be passed in this request, convert thereof into the form of this matching requirements by the SCSI miniport driver.But because flash memory chip can only monoblock write, so the SCSI miniport driver can read earlier a part of data from this device, and the data that will write are merged into complete data block with the data of reading back and write this device afterwards more then.After data write and finish, the SCSI miniport driver can return to file system driver to mode of operation.
Be described in detail the read operation process of this micro memory below in conjunction with accompanying drawing 8, in turn include the following steps:
1) as step S among the figure
801, S
802Expression, at first the application program of host operating system is sent a read command to the operating system upper layer drivers;
2) as step S
803Shown in, the operating system upper layer drivers judges whether mentioned order is the read operation of this device, is to negate as judged result, then enters S
804Shown step stops carrying out this order; As judged result is sure, then enters step S
805, read request is given to device driver;
3) at step S
805, device driver is converted to the command sequence of operating system bsp driver to read request, enters step S then
806
4) at step S
806, device driver is according to command sequence calling system bsp driver;
5) after above-mentioned steps is finished, enter step S
807, the operating system bsp driver is passed to the microcontroller program by USB interface;
6) after above-mentioned steps is finished, enter step S
808, the microcontroller program is made respective operations, and promptly microcontroller writes down the block description that main frame will read, and reads a blocks of data then at every turn and beam back main frame by the USB interface chip from flash memory chip, enters step S then
809, the microcontroller program is sent result and state back to the operating system bsp driver; " result " described herein is meant the data that read from this micro memory, and " state " is meant whether read operation is finished;
7) at step S
809In, the operating system bsp driver is with result and state Returning equipment driver;
8) enter step S then
810, device driver repeats to finish 4,5,6,7 steps according to result and state, up to finishing the operation that total data reads, enters step S then
811, data and state are returned to the operating system upper layer drivers;
9) after above-mentioned steps is finished, enter step S
811, the operating system upper layer drivers returns to application program with data and state again, promptly enters step S
812
As shown in Figure 9, main frame is as follows to the step that the micro memory of band USB (universal serial bus) plug of the present invention writes data:
1) as step S among the figure
901, S
902Expression, host application program sends a write order to the operating system upper layer drivers;
2) as step S
903, the operating system upper layer drivers judges whether this order is the write operation of this device, is to negate as judged result, then enters step S
904, stop carrying out this order; As judged result is sure, then enters step S
905, write request is given to device driver;
3) enter step S then
906, device driver is carried out the read operation of corresponding data piece earlier, and " corresponding data piece " described herein is meant the inner original data of micro memory of the present invention;
4) at step S
906, device driver is converted to read request the command sequence of operating system bsp driver;
5) at step S
906, device driver is according to command sequence call operation system bottom driver;
6) at step S
906, the command code that the operating system bsp driver will define is passed to the microcontroller program by USB interface;
7) at step S
906, the microcontroller program is made respective operations, and sends result and state back to the operating system bsp driver;
8) at step S
906, the operating system bsp driver is with result and state Returning equipment driver;
9) at step S
906, device driver repeats to finish 5,6,7,8 steps according to result and state, reads up to finishing data block, and data are stored in buffer zone, because the process of above-mentioned reading of data is identical with aforementioned read operation process, so is reduced to step S in the process flow diagram
906
10) after above-mentioned steps is finished, enter step S
907, unchanged data are merged into new data block and are stored in buffer zone in data that device driver will be rewritten and the buffer zone;
11) enter step S then
908, device driver is converted to write request the command sequence of operating system bsp driver;
12) enter step S then
909, device driver is according to command sequence call operation system bottom driver;
13) enter step S then
910, the command code that the operating system bsp driver will define is passed to the microcontroller program by USB interface;
14) enter step S then
911, the microcontroller program is made respective operations, comprising wiping and write operation, enters step S then
912, and send state back to the operating system bsp driver; " state " is meant whether write operation is finished;
15) at step S
912, the operating system bsp driver is with result and state Returning equipment driver;
16) enter step S then
913, device driver repeats to finish 12,13,14,15 steps according to result and state, all writes up to the data of finishing in the buffer zone, enters step S then
914, state is returned to the operating system upper layer drivers;
17) after above-mentioned steps is finished, enter step S
915, the operating system upper layer drivers returns to application program with state.