The large capacity movable memory embodiment of the USB interface of the present invention's design comprises the mobile memory plate that is made of hardware circuit, and control software and the driver two parts in the PC main frame end of embedding PC main frame end form. Wherein, the general structure of mobile memory plate as shown in Figure 1, among the figure:
1, J1 is the USB interface plug among the figure, is the joint that this memory card is connected with the USB interface of PC main frame, and its type is the male joint of USB-A mouth; D+ in the usb bus and D-are a pair of holding wire of checking the mark, and directly link to each other with the usb signal spool pin of CPU.
2, U6 (CMPWR) device is the CMPWR150 chip, this chip from the VCC of usb bus (+5V) line obtains power supply, and is converted into the output voltage of 3.3V, to supply with CPU, Flash memory or EEPROM.
3, U1 (EZUSB_80) is microprocessor AN2131QC; This processor passes through 8 data/address bus, and general output port links to each other with Flash memory (U3, U4), links to each other with EEPROM (U8) by the I2C bus. Its major function is to realize the USB interface agreement, carries out exchanges data with the PC main frame by usb bus, simultaneously by output timing control the Flash memory read-write, the operation such as wipe; Also can be by the startup of I2C bus realization from EEPROM. Because the present invention can realize the function that downloads from the PC main frame, so this EEPROM is an alternative devices.
4, U3, U4 (KM29U128T) are the Flash memory, and it connects with CPU by 8 data/address bus and the IO port of CPU; Its major function is to carry out data storage.
5, U8 (24LC00/01/64) is alternative EEPROM, links to each other with CPU by the I2C bus, and the executable program of storage CPU is finished the startup of CPU, to accelerate the toggle speed of this memory card during its Main Function.
6, Y1 is the crystal oscillator of 12MHz, and the working pulse of 12MHz is provided for CPU by the crystal oscillator input pin of CPU.
7, J2, J3, J4 are the hardware configuration wire jumper of this memory card, by wire jumper, can identify capacity and the sheet number of Flash memory.
Embodiment and the function of the main device of this memory card are respectively described below:
Microprocessor: the AN2131QC that adopts Cypress company; The kernel of this microprocessor is general 8051CPU, but 51 processors of a enhancement mode, cpu frequency is 24MHz, the instruction cycle is 4CLK; And this CPU is integrated USB interface engine and transceiver is a very high processor of the ratio of performance to price of the present invention that is suitable for. Its inner integrated module comprises: 8051 microprocessors of USB difference transceiver, USB SIE, enhancement mode and the RAM memory of 8K byte.
Flash memory: the Flash memory of the TC58256 series of the KM29U6400T of employing Samsung company~KM29U256T series or Toshiba company, this memory is the FLASH chip of a kind of address and multiplexed data bus, be characterized in storage density large (the monolithic capacity can not wait to the 128M byte from the 8M byte), little (20mm * the 12mm * 2mm) of volume, (chip pin compatibility of different capabilities) easy to use, low price, 8,051 two chip selection signals that provide can be provided, can be realized by an IO port all SECO of FLASH fully.
Power supply chip: realize that the 5V of USB interface is to the 3.3V voltage of microprocessor and Flash needs, adoptable model mainly contains the Max882 of Maxim company or the CMPWR150 of California Micro Devices company, and its rated operational current is 500mA.
EEPROM: this memory card hardware itself is a bare machine, its control program can be in access PC main frame downloading-running in the automatic slave driver; The upgrading of the very convenient program of these characteristics, and effectively reduce the cost of system; But shortcoming is exactly the process need 1-2 second of downloading. In order to consider different user's requests, this memory card has kept the position of ROM of the I2C of a 8KB, to make things convenient for the user to select, the characteristics of using EEPROM are exactly to start (just having realized startup in the time of access PC main frame) moment, also possess the characteristics that can upgrade at any time, shortcoming is exactly that cost slightly is improved. The model of the EEPROM that present embodiment adopts is AT24LC64 or the CAT24WC08 of Atmel company.
Other devices mainly are 1 of the crystal oscillators of 12MHz, 1 of light emitting diode, and resistance, electric capacity are some, and the function of these devices and the model of selecting all belong to general general knowledge, in this outline.
Software of the present invention comprises that the driver that runs on PC main frame end and the control program that moves sub-memory card hardware end consist of, because the automatic download of the control program that the present invention can realize the memory card hardware end from the PC main frame, so running on the control program of memory card hardware end actual is to leave in the driver of download code of PC main frame end, only in the USB interface of memory card hardware access PC main frame of the present invention, just automatically download to memory card and move, be called " the control software that embeds PC main frame end " so will run on the control program of memory card hardware end of the present invention. The control software of embedding PC main frame end and the overall structure of the driver embodiment in the PC main frame are as shown in Figure 2. Wherein, embed the control software of PC main frame end by the system mode machine, the IO driver of usb protocol stack and Flash forms; Driver in the PC main frame of the present invention is by the driver that is implemented in the download code of the present invention on the PC host operating system usb protocol stack, and device driver and IO port drivers three parts of the present invention of the present invention's normal operation form.
The control software that embeds PC main frame end refers to that mainly computing and the control program of 8051 little processing of this memory card, the main thought of design are the thought that adopts micro-kernel; Because the disposal ability of 8051CPU is limited, design philosophy of the present invention is 8051 only to be used for realizing basic, the simplest usb protocol and data transport service, and the realization of the function that other are complicated is placed on the powerful PC main frame end of disposal ability and realizes.
Example structure and the function of the control software of embedding PC main frame end of the present invention are shown as shown in Figure 3. Mainly comprise following three parts:
(1) system mode machine;
(2) usb protocol stack;
(3) the IO driver of Flash.
Wherein, state machine is the control main program, and it is responsible for dispatching the work of usb protocol stack and Flash driver; The USB protocol stack mainly be responsible for to be processed the agreement of USB, realizes data transmit-receive with the driver of PC main frame by usb bus, comprises the order that sends to state machine and common file data in the data; The Flash driver is responsible for mainly realizing and the communication of Flash that the machine that is main state realizes carrying out with Flash the passage of exchanges data, namely by the SECO of Flash, realizes that data are to the storage of Flash and from the upper reading out data of Flash.
State machine is the control main program of the control software of this embedding PC main frame end, mainly safeguards the functions such as the mutual exclusion between each treatment state, mutual conversion, realizes the scheduling of task. The implementation method embodiment of this state machine comprises:
1. definition status:
1) idle condition (Idle), CPU does not have task carrying out;
2) query State (Quest), CPU responds the querying command of PC
3) Flash erase status (Erase), CPU carries out the erase operation of Flash
4) Flash read states (Read), CPU carries out the operation of reading Flash
5) Flash writes state (Write), and CPU carries out the operation of writing Flash
2. define 2 operations:
1) remove current state operation (Clear), CPU compulsory withdrawal current state is returned idle condition;
2) reset operation (Reset), under any state, the equal executive system reset function of CPU
3. realize the conversion of state machine state, as shown in Figure 4, may further comprise the steps:
1) the wiping of state machine, read and write enter state and can only enter under idle condition;
2) query State can enter under any state;
3) under the idle condition, receive the Erase order, then enter erase status; All can not enter erase status under other states; After executing the Erase order, return idle condition;
4) under the idle condition, receive the Read order, then enter reading state; All can not enter reading state under other states; After executing the Read order, return idle condition;
5) under the idle condition, receive the Write order, then enter write state; All can not enter write state under other states; After executing the Write order, return idle condition;
6) at idle condition, erase status, read states and write state, if receive the Quest order, enter at once query State, until after executing query manipulation, return the front state of query State that enters.
7) between each state of state machine mutual exclusion mechanism is set, namely as long as current state does not finish (comprising that nature finishes and force to finish), state machine just can not carry out the state switching so. Mutual exclusion mechanism is the basic guarantee that guarantees each read-write operation integrality and correctness.
Above-mentioned mutual exclusion mechanism embodiment adopts the token method, specifically comprises the steps:
1) PC end program is carried out certain operation (such as reading and writing, wiping etc.) at needs, before entering certain state, must by the order pipeline, send a Quest order, application tokens to the present invention;
2) this memory card is received the Quest order, returns at once current token attribute, namely belongs to that state;
3) PC end program need to check the attribute of token, if current operation token number Idel state, PC end program has the right to apply for tokens so, otherwise PC end program must wait for, until the token attribute is Idel;
4) if it is Idel that PC end detects the token attribute that this memory card returns, program needs again to submit to this memory card by the order pipeline so needs the operation carried out, apply for simultaneously tokens;
5) after this memory card is received this application, check resource, check current token, if it is enough to meet resource, and current state is just carried out state switching, juxtaposition token attribute by the operation of application when being Idel;
6) after PC end program is submitted operation application, for guaranteeing to apply for successfully, still need to carry out a Quest order before each operation, confirm current token attribute to one's name.
This usb protocol stack mainly comprises the USB1.0 standard protocol stack; Three partial contents of ping-pong buffer are downloaded and arranged to program automatically: wherein, it is the new function that increases on USB standard protocol stack basis that program downloads automatically; In order to improve the speed of transfer of data, definition data transmit-receive buffering area is set to ping-pong buffer in the usb protocol stack. The concrete methods of realizing embodiment of each several part is described as follows:
The implementation method of USB1.0 standard protocol stack may further comprise the steps as shown in Figure 5:
Be connection status when 1) this memory card accesses usb bus, if there is the HUB of USB, the present invention just enters powering state so; When powering state, if HUB resets, perhaps lose the connection of HUB, the present invention returns connection status so;
2) at powering state, if receive the reset command of usb bus, the present invention enters default setting;
3) at default setting, if receive Address Assigned (configuration address) order of PC main frame, then the present invention enters adressed state;
4) in adressed state, if receive the inquiry of PC main frame or the order of configuration is set, the present invention just enters the configuration shape
5) when default setting, addressing attitude and configuration attitude, if power interruptions all will be returned powering state; If receive the reset command of USB bus, all will return default attitude;
6) when powering state, default attitude, addressing attitude and configuration attitude, if usb bus does not have signal transmission, then the present invention enters suspended state, with saves energy.
The purpose that realizes this function is exactly to finish the initialization operation of the present invention and PC main frame, is called " enumerating " (Enumeration) in usb protocol, and detailed process is as follows: connection status
This state refers to that this memory card can be connected on the USB interface or disconnects from interface, is first step that this memory card is started working.
Powering state (Powered):
The working power of this memory card is that 5V power supply from USB interface obtains, therefore, after the USB interface of this memory card access PC end, obtain the 5V power supply from the power line of usb bus, conversion chip by DC-DC, being converted to the operating voltage of 3.3V, supplying with the AN2131 microprocessor, is that microprocessor is started working; The operating current that this memory card needs is about 60mA.
Default setting:
After this memory card powers up, before receiving reset signal from bus, it should not respond the bus transmission. After receiving reset signal, the present invention's addressable that just becomes at the default addresses for use place.
Address state:
Before entering address state, the PC main frame at first must be identified the present invention number (ID) of this memory card, whether to differentiate a legal USB device, this operation is to be 0 by sending the address to usb bus, end points is " obtaining device context " (Get Descriptor) order of 0 (endpoint0), possesses end points 0 (endpoint0) because any equipment is all default, and must be that 0 packet responds to the address, therefore this memory card returns oneself device context to the PC main frame, and the description list content of this memory card is as shown in table 1:
Table 1
Side-play amount | The territory | Size | Value | Describe |
0
|
Blength
|
1
|
0x12
| The byte number of this description list |
1
|
BdecriptorType
|
1
|
0x01
| The description list kind is equipment |
2
|
BcdUSB
|
2
|
0x0001
| USB device explanation version number's (binary-coded decimal) of this equipment and description list compatibility |
4
|
BdeviceClass
|
1
|
0x00
| If the value in this territory of equipment class code be 0 one each interface be set down point out its class, and individual interface works alone separately. If the value in this territory is between 1~FEH, then equipment is supported different classes at different interfaces. And these interfaces may not work alone. This value has been pointed out, the class definition of these interface collectives. If this territory is made as FFH, then the class of this equipment is defined by manufacturer. |
5
|
BdeviceSubClass
|
1
|
0x00
| The concrete meaning of these code values of subclass code is according to the bDeviceClass territory. Be zero such as the bDeviceClass territory, this territory also must be for zero being FFH such as the bDeviceClass territory, all values reservation in this territory. |
6
|
BDevicePortocol
|
1
|
00x00
| The value of these yards of agreement code is decided on the value of bDeviceClass and bDevieeSubClass. If the agreement that the class on the equipment support equipment basis is relevant, this code mark the value in the equipment class explanation. |
| | | | If the value in this territory is zero, this equipment relevant agreement of support equipment class on Equipment Foundations not then. Yet, it may be on interface basis the relevant agreement of support equipment class. If the value in this territory is FFH, this equipment uses the agreement of manufacturer's definition. |
7
|
BMaxPacketSize0
|
1
|
0x40
| The maximum bag size (only 8,16,32,64 is legal value) of end points 0 |
8
|
IdVendor
|
2
|
0x0547
| Manufacturer's sign (by the USB standard value of paying) |
10
|
IdProduct
|
2
|
0x1002
| Product marking (by manufacturer's value of paying) |
12
|
BcdDevice
| |
0x0001
| Equipment issue number (binary-coded decimal) |
14
|
IManufacturer
| |
0x01
| The index of the word string of manufacturer's information is described. |
15
|
IProduct
| |
0x02
| The index of the word string of product information is described. |
16
|
ISerialNumber
| |
0x00
| The index of the word string of equipment Serial Number information is described. |
17
|
BNumConfiguratio
| |
0x01
| The possible number that arranges |
After the PC main frame is received the device context of this memory card, number load corresponding driver of the present invention according to the device id in the table, if success, the PC main frame sends a SetAddress order by end points 0 and address 0 to this memory card again, distribute a unique USB address for this memory card, after this memory card is received PC main frame SetAddress order, the address that the PC main frame is given deposits register in, later on this mobile memory of PC host access all uses this address, and this memory card is also only to the response package of this address. Configured (configuration status)
Before the normal operation of this memory card, the present invention must correctly be disposed. The content of configuration is exactly that PC is by sending " obtaining allocation list " (GetConfiguration ()), obtain content the allocation list from this memory card, and carry out resource distribution by this content at PC end, perhaps to this allocation list make amendment (SetConfiguration). The allocation list content of this memory card is as shown in table 2:
Table 2
Side-play amount | The territory | Size | Value | Describe |
0
|
bLength
|
1
|
0x01
| The byte number of this description list. |
1
|
BDescriptorType
|
1
|
0x02
| Configuration description list type |
2
|
WTotalLength
|
2
|
0x002e
| The overall length of this configuration information (comprising configuration, interface, the description list of end points and equipment class and manufacturer's definition) |
4
|
BNumInterfaces
|
1
|
0x01
| The interface number that this configuration is supported |
5
|
BCongfigurationValue
|
1
|
0x01
| In SetConfiguration () request, be used as parameter and select this configuration. |
6
|
IConfiguration
|
1
|
0x03
| The word string description list index of this configuration is described |
7
|
BmAttributes
|
1
|
0xa0
| Configuration feature: D7: keep (being made as one) D6: self-supporting power D5: Remote Wake Up D4..0: keep (being made as one) one not only with the bus power supply but also there is the equipment of self-supporting power can point out in the MaxPower territory electric weight that need to get from bus. And D6 is set is one. Run time the practical power pattern can be obtained by GetStatus (DEVICE) request. |
8
|
MaxPower
|
1
|
0x30
| The bus power supply amount of expending under this configuration. Take 2mA as a unit. |
Abort state
For saving power supply, this memory card enters abort state automatically when detection is transmitted less than bus. When ending, the internal state of this memory card maintenance itself comprises its address and configuration.
The automatic download of program is important characteristics of the present invention, the performing a programme that is 8051 microprocessors in the memory card of the present invention does not need ROM to preserve, but can leave in the driver of the present invention of PC main frame end, and finish the download of program and bring into operation in the moment of this memory card access usb bus. The core concept that realizes this function is to utilize the AN2131 microprocessor (to have device id 1 as a default initial USB device, PID=0x2131) access PC main frame, the PC main frame loads the device drives corresponding to ID1, and this driver mainly comprises program from default end points endpoint0 to this memory card that download performing a programme by; After this memory card is received performing a programme, move at once this program, then carry out reset (the usb bus reseting pin by AN2131 carries out) of usb bus, the PC main frame is identified this memory card equipment again, this moment this memory card Returning equipment ID2 (the real device id of this memory card, PID)=0x1002), the PC main frame loads the final driver of this memory card according to this ID, thereby makes this memory card begin normal operation. The realization of this function is to have utilized characteristics a: AN2131 of AN2131 microprocessor not when working procedure, can be used as the default USB equipment with equipment VID=0x2131, this equipment has the default configuration of usb protocol, namely have end points 0, can the data of end points 0 be responded.
Program of the present invention is downloaded concrete methods of realizing embodiment as shown in Figure 6 automatically, may further comprise the steps:
1) when this memory card access usb bus, the PC main frame will to transmissions Get Descriptor (obtaining description list) order, require USB device Returning equipment number and trading company of factory;
2) this memory card at first returns the VID=0547 (ID of production firm) of initialization apparatus, PID=2131 (product IDs):
3) after the PC main frame obtains the original equipment ID of this memory card, will in the USB device Driver Library of PC host operating system, search the device drives (this ID is corresponding to the driver that downloads of the present invention) corresponding to above-mentioned ID, and load;
4) in a single day the PC host operating system loads the driving that downloads of this memory card, and the data pipe that this program provides by this memory card initialization apparatus at once is to this memory card download executable programs;
5) after this memory card is received the program of download, move at once and become the equipment of this memory card normal operation;
6) this memory card produces once the signal of new USB device access bus, makes the PC main frame again identify this memory card;
7) the PC main frame is received the signal of new equipment access, repeat 1,2,3 above-mentioned steps, load corresponding to VID=0547 the device drives of PID=1002, device drives when this driving is the normal operation of this memory card, thus the process that program is downloaded automatically finished.
Because the present invention possesses the function of hardware implement program dynamic download, thereby makes it to possess state-of-the-art software upgrading function; For traditional hardware system, program generally is stored among the erasable EEPROM or Flash, the user is in upgrade software, in case accidental interruption operation midway or the wrong program of having upgraded, with the physical fault that causes hardware device correctly not start. And program of the present invention is to leave PC main frame end in, and the user can arbitrarily change and drive and the unlikely physical equipment that affects.
The design of ping-pong buffers mainly is in order to accelerate data transmit-receive of the present invention; Because very fast of the processing speed of PC main frame, and the transfer rate of usb bus is unusual height also, reach as high as 12Mbps, but the speed of the microprocessor of this memory card is relatively just slow, if each end points only uses a buffering area, data transfer speed will greatly be reduced, and design principle is as follows:
Condition:
1, the actual transfer rate of usb bus is 900Kbyte/S (being 7.2Mbps);
2, buffering position 64 bytes of end points (can only equal length 64 bytes of the maximum packet of USB);
3, the mean instruction execution time of AN2131 is 160nS;
4,64 byte datas are sent into Flash, on average need to carry out 400 instructions.
Calculate:
The 64B data are at the transmission time of usb bus T1=64/900K=69444nS,
AN2131 processes the time T 2=400 of 64 bytes * 160=64000nS.
If end points only uses a buffering area, after the PC main frame must wait for that this memory card is handled 64 byte datas of receiving so, could send the data of next 64 bytes, this moment, actual message transmission rate was:
V=64/(T1+T2)=468Kbyte/S
Data transfer speed is far below the transfer rate of the 900Kbyte/S of usb bus at this moment; If use 2 buffering areas, clearly, because usb bus transmits the time 69444nS of 64 bytes greater than the processing time 64000nS of microprocessor, therefore, behind the buffering area of complete 64 bytes of microprocessor processes, the PC main frame is not also finished to the transfer of data of another one buffering area, so the data transmission bauds of this moment just equals the transmission speed 900Kbye/S of usb bus. Therefore, the use of ping-pong buffer, the message transmission rate that roughly can double.
Ping-pong buffer program of the present invention comprises the sending and receiving of data, wherein sends the implementation method embodiment of data as shown in Figure 7, comprises the steps:
1) this memory card is received the data of usb bus, inquire about at once the flag bit of Buffer1 (buffering area 1), if empty, then write the data packet Buffer1, the flag bit of this buffering area of juxtaposition was 1 (expiring), and the most backward PC main frame sends and receives successful handshake ACK;
2) if Buffer1 is full, then then inquiry Buffer2, if Buffer2 is empty, then repeat and same operation during the Buffer1 sky; If Buffer2 also is full, then represent the excessive velocities that the PC main frame sends, this memory card is processed and is not come, and then abandons the data of this reception, and returns the unsuccessful handshake NAK of reception to the PC main frame.
The method of the receive data of the ping-pong buffer of present embodiment comprises the steps: as shown in Figure 8
1) microprocessor of this memory card at first checks the sign of Buffer1, if Busy1=1, representing that this buffering area receives has expired data, so these data is write Flash, and juxtaposition is masked as 0 (expression Buffer1 is for empty); If Busy1=0, expression does not have data, then directly enters following operation;
2) handle Buffer1 after, then check the sign of Buffer2, if data are arranged, then write Flash, then empty flag bit; If there are not data, then repeat the operation of the first step.
The IO driver of the Flash of present embodiment has mainly been set up the wiring method that body intersects on the basis of Flash standard time sequence. Owing to the design feature of Flash, determined the asymmetry of Flash access time; Take the KM29U128T chip of Samsung company as example, the time of reading a page data (512 byte) is 10uS, and be 350uS the average time that writes a page data; One page data is sent to the data/address bus of Flash from usb bus, perhaps from the average time that the data/address bus of Flash is sent to usb bus be 300uS, therefore:
Inside of the present invention read transfer rate=512/ (300+10)=12.6Mbps
Inside of the present invention write transfer rate=512/ (300+350)=6Mbps
This shows, Flash to write time-delay be the bottleneck of writing speed of the present invention, if do not take measures, add the time delay of the transfer of data of USB bus and PC main frame end, actual writing speed can only reach 3~4Mbps.
The core concept of body interleaving techniques is exactly to utilize the parallel work-flow of multi-disc Flash to improve writing speed; Because Flash has the flowing water of reading, so the body interleaving techniques does not improve read operation. Because volume of the present invention is very little, so generally only adopt two Flash.
The write operation realization flow that the body of present embodiment intersects as shown in Figure 9. Comprise that step is as follows:
1) enter page write operation after, at first judge whether recto of page address to be written, if it is prepare data are write among the Flash1; Otherwise prepare data are write among the Flash2;
2) the R/B pin of inspection Flash1 judges whether Flash1 is idle; If idle, data write Flash, otherwise continue query State, until write after the free time;
3) write the operation of Flash2 with the operation that writes Flash1.
Because the read operation of Flash has the flowing water characteristic, thus the process of reading still employing sequentially read, namely run through first the data on the Flash1, then read the data on the Flash2. Certainly, if realize complete file body interleaving access, also need the support of the driver of PC end.
Driver in the PC main frame of the present invention comprises the driver of standard usb protocol stack of PC host operating system and the present invention's driver itself.
The driver of the standard usb protocol stack of PC host operating system mainly comprises:
The USB physical interface of PCI-Enumeriator:PC main frame is connected with CPU by pci bus;
The driving of the usb protocol stack of OpenHCI.SYS:PC host operating system, open PC console controller interface
Drive (Open Host Controller Interface);
The driving of the usb protocol stack of UHCD.SYS:PC host operating system, the USBPC console controller drives
(USB host controller drivers);
The driving of the usb protocol stack of USBD.SYS:PC host operating system, USB device drives;
The driving of the usb protocol stack of USBHUB.SYS:PC host operating system, the hub of USB drives;
The present invention's driver itself comprises:
EDStart.SYS: the driver of download code of the present invention;
EasyDisk.SYS: the device driver of the present invention's normal operation;
EDIOSP.SYS: IO port driver of the present invention (IOS Port).
The driver of download code of the present invention and the device driver of normal operation all adopt the exploitation of WDM form, have good compatibility.
The major function of downloading the driver of code is exactly to download executable programs of the present invention, carries out the initialization of equipment. Download the driver flow process of code as shown in figure 10, may further comprise the steps:
1) IRP_MJ_POWER and IRP_MJ_PNP all are IRP parameters of PC host operating system, when this memory card accessed, the driving USBD.SYS of PC host operating system can transmit these parameters by the entrance function DriverEntry () of EDStart.SYS;
2) the miscellaneous function code is the usb protocol stack acquisition by the PC host operating system equally;
3) when the miscellaneous function code is sweep equipment, represent that this memory card thrown off usb bus, the function IoDetachDevice () and the IoDeleteDevice () that call the sweep equipment that PC host operating system usb protocol stack provides this moment come sweep equipment;
4) when the miscellaneous function code is other, download of the present invention this moment drives does not carry out any action, only simply returns;
5) the present invention and download to this memory card of resetting in the flow chart is by the USBD.SYS Transfer Parameters of URB parameter block to lower floor, use in the usb protocol VenderRequest (producer's request command) order with
It is as follows that the URB structure that the driver of code uses is downloaded in communication of the present invention, the present invention:
urb→UrbHeader.Length= sizeof(struct
_URB_CONTROL_VENDOR_OR_CLASS_REQUEST)
urb→UrbHeader.Function=URB_FUNCTION_VENDOR_DEVICE
urb→UrbControlVendorClassRequest.TransferBufferLength=1
urb→UrbControlVendorClassRequest.TransferBuffer=&resetBit;
urb→UrbControlVendorClassRequest.TransferBufferMDL=NULL
urb→UrbControlVendorClassRequest.Request=EZDSK_LOAD_INTERNAL
urb→UrbControlVendorClassRequest.Value=CPUCS_REG;
urb→UrbControlVendorClassRequest.Index=0;
The device driver of normal operation of the present invention realizes by PC host operating system standard driver form. The device driver of this normal operation is the present invention's employed driving that works; Finish the download of program as the present invention after, just start working with the equipment of a new access, this moment, the PC host operating system just loaded the device driver of normal operation of the present invention. The device driver of normal operation of the present invention mainly comprises: the management of access device and provide IO operation for upper layer application.
The management of access device mainly comprises: the plug and play management of equipment and the power management of equipment.
The power management of present device does not carry out a lot of works for the treatment of, only obtains power supply type of the present invention from the USB driving of bottom PC host operating system, and power supply status is not processed and revised.
Obtain to such an extent that the IRP parameter of power supply mainly contains from bottom:
IRP_MN_SET_POWER (the IRP parameter of power attributes is set)
IRP_MN_QUERY_POWER (the IRP parameter of inquiry power attributes)
Can also know power supply status and the power supply content of equipment by the auxiliary parameter of these IRP parameters.
Plug and play of the present invention (Plug and Play, be called for short PNP) management is a very important function, the access of main treatment facility, stops and deleting; The present invention has fully inherited usb bus and has supported the characteristics that many equipment access simultaneously, can effectively realize accessing simultaneously 64 the present invention; Although usb protocol regulation, at most can 127 equipment of cascade on the bus, but because all equipment all needs to share bandwidth, and the maximum bandwidth of usb bus is 12Mbps, put that in fact to access 127 equipment substantially nonsensical, thereby the present invention's access when only having accomplished to support 64 equipment. Access-in management flow process of the present invention may further comprise the steps as shown in figure 11:
When 1) the present invention accesses usb bus, the PC host operating system will load driver of the present invention, and the PNP message of the present invention's access is passed to driver EasyDisk.SYS of the present invention;
2) driver receives the message of PNP, will enter PNP and process routine;
3) driving checks that at first whether the present device of current driven management is greater than 64;
4) if greater than 64 then return the mistake that surpasses maximum number of devices, otherwise enter next step operation;
5) if less than 64, create so a new equipment, device name is " EZDSK-X ", X represents the number of current example, for example first device name is " EZDSK-0 ", and a plurality of equipment of follow-up access are called after " EZDSl-1 " successively, " EZDSK-2 " etc.;
6) if establishment equipment success is then called IoCreateSymbolicLink () function and set up symbol and connect, the equipment handle that is about to device name and reality carries out related, creates unsuccessfully otherwise return;
7) set up symbol and connect after, return successful sign.
In addition, PNP management of the present invention also needs to process following three IRP of system message:
IRP_MN_START_DEVICE
The function of this IRP is to initialize the present device that has just accessed. By the URB parameter block is set, the USBD.SYS that calls the Pc host operating system by function IoCallDriver () drives, and sends initialization command to the present invention. The structure of URB and content have description in 2.1.1, no longer describe in detail.
IRP_MN_STOP_DEVICE
The function of this IRP is to suspend work of the present invention. Implementation method remains the parameter block by URB, calls the USB driving and transmits.
IRP_MN_REMOVE_DEVICE
The function of this IRP is the present device of oneself disengaging usb bus of deletion, and implementation method is the same.
The most important function of the device driver of the present invention's normal operation is exactly to provide basic IO operation to upper layer application of the present invention, and for this reason, driving of the present invention has defined the control program of some IO operations, uses to make things convenient for upper level applications. The application program on upper strata only needs calling system DeviceIoControl () function, and specifies therein the equipment handle just invented and the IO control program of response, just can call driving of the present invention and carry out IO and operated.
The present invention has defined abundant IO control code, and to finish various IO controls and system mode inquiry, the IO control code is defined as follows:
IOCTL_EZDSK_GET_PIPE_INFO: obtain all transmission pipeline information of the present invention
IOCTL_EZDSK_GET_DEVICE_DESCRIPTOR: obtain device context information
IOCTL_EZDSK_GET_CONFIGURATION_DESCRIPTOR: obtain equipment allocation list information
IOCTL_EZDSK_BULK_WRITE: the write operation of batch transmission
IOCTL_EZDSK_BULK_READ: the read operation of batch transmission
IOCTL_EZDSK_VENDOR_REQUEST: obtain manufacturer's information
IOCTL_EZDSK_GET_CURRENT_CONFIG: obtain current configuration
IOCTL_EZDSK_DOWNLOAD: to download executable programs of the present invention
IOCTL_EZDSK_GET_STRING_DESCRIPTOR: obtain character description list information
IOCTL_EZDSK_RESET: present device resets
IOCTL_EZDSK_GET_CURRENT_FRA_NUMBER: obtain the present frame numbering
The present invention provides IO operation realization flow as shown in figure 12 for upper layer application.
Program procedure is as follows: 1) obtain first the upper strata and call the IO control program parameter that passes over; 2) then set up corresponding URP parameter block according to the IO control program; 3) USB that calls at last bottom drives to carry out the operation of response.
The call method on upper strata:
After finishing the device driver of normal operation, calling of upper layer application is very simple, only need to just can realize corresponding operation by the equipment I O control function of standard, and rules in function calling is as follows:
BOOL DeviceIoControl(
HANDLE hDevice, ∥ points to the handle of present device
DWORD dwIoControlCode, ∥ IO control program
LPVOID lpInBuffer, the buffer pointer of ∥ input data/parameter
DWORD nInBufferSize, the size of the buffering area of ∥ input data/parameter
LPVOID lpOutBuffer, the buffer pointer of ∥ receive data
DWORD nOutBufferSize, the size of the buffering area of ∥ receive data
LPDWORD lpBytesReturned, the byte number of the actual data that receive of ∥
LPOVERLAPPED lpOverlapped ∥ points to the structure of an asynchronous operation)
The major function of IO port drivers EDIOSP.SYS of the present invention is exactly to set up a virtual storage device driver, makes the user operate the present invention as the local hard drive in the operation computer. The device Driver Development for Embedded flow process of the exploitation of this driver and the normal operation of USB is similar, only need to write according to the WDM template of writing the memory device driver among the DDK to get final product. Port drivers is except finishing the virtual memory facilities driving, and its most important function remains the realization of IO operation of the present invention. It to the effect that realizes file system of the present invention.
File system of the present invention comprises the definition of file system and the operation of file system
File system of the present invention is defined as follows:
1) base unit of presents system definition file storage is 16KB.
2) whole dish is comprised of a bootstrap block and follow-up data block;
3) bootstrap block is from the 0th BOB(beginning of block), the 1st the non-bad physical block that finds. In order to raise the efficiency, the regulation bootstrap block can only be positioned at
front 10 physical blocks. Like this, if
front 10 physical blocks all are bad, this dish can't be used for the presents system so; The data structure of bootstrap block is as shown in table 3: table 3
The address | Content | |
0~7B, 8 bytes | Beginning flag " EzDisk " |
8~17B, 10 bytes | The file system type sign, " Interleave " expression body intersection form, " Normal " represents normal format |
18~8K-1B, the 8K-18 byte | Keep |
8K~12K-1 byte | Bad piece reflection, 1 physical block of per 1 bit representation, this position is that 1 expression is bad piece. Can represent altogether 32K piece, namely the heap(ed) capacity of institute's support disc is 512MB; |
12K~16K-1 byte | Take the piece reflection, 1 physical block of per 1 bit representation, this position is that 1 expression is occupied. Can represent altogether 32K piece, namely the heap(ed) capacity of institute's support disc is 512MB. |
Illustrate: if capacity of the present invention greater than 512MB, boot section so of the present invention will take two Block, the space 8K of second Block is used for bad piece map, 8K is with taking the piece map. The capacity that can support this moment will reach 1.5GB. |
4) because upward there is the physical block that breaks down unavoidably in Flash, so the presents system has taked to walk around the design of bad piece storage file; File is Coutinuous store on dish, and each file is comprised of a series of continuous physical blocks. Wherein bad piece may be arranged, but file system can be videoed according to bad piece in when access and automatically skipped these bad pieces. For example, the file header of a file and data are added up and should be taken n piece, and the starting block address of depositing of this document is a, and this document should take from a piece to the a+n-1 piece the altogether interval of n physical block so. If but in this interval, bad piece arranging, this interval will be extended backward so, until all good pieces can just put down this file in interval. Like this, if this document has taken the interval from a piece to the a+n-1+t piece, illustrating has t bad piece in this interval; 5) the 1st of first piece of storing documents the page the space of totally 512 bytes be used for the storing documents head, since the 2nd page of data that are only file itself. Like this, if the size of a file on the PC main frame is m byte, on dish, will take so (m+512-1)/16K+1 good piece; Data structure such as the table 4 of file header: table 4
6) 0 ~ 7B, 8 bytes | 7) beginning flag " EzFile " |
8) 8~11B, 4 bytes | 9) file size, unit: byte can represent less than 4GB's |
10) 12 ~ 19B, 8 bytes | 11) file " modification time |
12) 20~23B, 4 bytes | 13) file " attribute " |
14) 24 ~ 487B, 464 words | 15) filename character string comprises full directory information |
16) 488~507B, 20 words | 17) file password string |
18) 508 ~ 511B, 4 bytes | 19) file type sign " MP3 " is shown not mp3 file, " PCM " recording file, and " * * * " represents other file |
20) owing to the problem of " reading continuously ", last 1 physical block of every Flash does not adopt in the presents system. The institute
With in fact available 1023 physical blocks of the dish of 16MB, and in fact available 2046 physical blocks of the dish of 32MB. 21) in order to improve access speed, in the present invention's access, driver will create this in the internal memory of PC main frame
The map of the boot partition of invention; Know the information of user's action need modification boot partition, driver just can
Upgrade the boot partition table among the Flash. 22) the present invention supports long filenames, multistage catalogue; Filename and directory information all leave the file name word of file header in
In the symbol string. 23) file system of the file system of body interleaved mode and normal mode is basically identical, and main difference is exactly each
All there is an independently file system in sheet Flash, and each file be divided into two independently file deposit.
The operation that file system offers the user mainly comprises: the present invention format, and the writing of file, the reading of file, the deletion of file, rename operation and the defragmentation of the present invention of file operate.
The major function of format manipulation rebulids file system of the present invention exactly, in the first use of the present invention, and in the situation of file system accidental damage, need to carry out format manipulation. Format manipulation will be wiped all data among the Flash. The flow process of format manipulation of the present invention is very simple, and at first whether identification can set up body intersection file system (by the number of hardware circuit recognition memory), then wipes Flash, detects the fail block of Flash, last writing in files system.
File write operation of the present invention comprises that common writing with the body intersection writes two kinds of operations
Common wiring method step of the present invention is as follows: 1) inquiry boot partition map of the present invention, obtain available memory space and initial address; 2) by the memory space occupied information in the file system modification boot partition; 3) file header and data are write Flash according to the form of file system
Writing with common ablation process that body intersects is substantially similar, and main difference is to need the file to be stored order is divided into two parts before the body interleaved, deposits among the different Flash as file independently respectively. Notice that because may there be fail block at random in Flash, the two-part size that file division becomes may be different, the principle of cutting apart is to equate as far as possible, because such depositing in is most effective. Then need when sending data to intersect transmission to cutting apart good file. The body cross-write enters flow chart as shown in figure 13, and performing step is as follows:
1) enters body interleaved routine shield, check at first whether the remaining continuous space of Flash enough deposits current file; If maximum continuous space is deposited current file not, but remaining physical space is enough, then needs to carry out defragmentation; If the continuous space after having put in order is still inadequate, then expression has produced again some new invalid block, then returns the mistake of insufficient space, withdraws from;
2) if find after checking for the first time that the residue continuous space is enough, perhaps defragmentation complete after, current file is enough deposited in the space, then begins divided file;
3) with file by as far as possible equally the principle order be divided into 2 parts, and beginning sends data take page or leaf as unit
File 1 after alternately transmission is cut apart when 4) sending and 2 data are until be sent
Because the present invention carries out initialized the time at access PC, driver is the file header of automatic scan boot partition of the present invention and All Files, and sets up the map of document location of the present invention in the internal memory of PC. Therefore reading of file only needs simply to send initial address to the present invention, and the content that order is read in file gets final product. Read operation also is divided into the body intersection and reads to read with common, body intersect read with common difference of reading in operation very little, unique different be that body intersects and reads to carry out twice read operation, run through first the file that is arranged in Flash1, then read the file that is arranged in Flash2, the simple merging of two files will reading at last gets final product.
The deletion action of file in fact only needs to discharge the block message that this document takies in the boot partition of the present invention and gets final product.
The rename operation of file only needs the file name in the transaction file head to get final product.
Defragmentation of the present invention is to rearrange the position of All Files in the present invention, makes not have the clear area between the file.
The Specifeca tion speeification of present embodiment is as shown in table 5: table 5
Appearance and size |
80mm×22mm×12mm
|
Memory capacity | 8MB-512MB does not wait |
Peak transfer rate | Write: 4Mbps-6Mbps, read: 6Mbps-8Mbps |
The PC host operating system |
Win95/Win98/Win2000
|
Storage life | Erase-write cycles is greater than 1000,000 times |