搜档网
当前位置:搜档网 › Adaptive Backstepping Control of a Class of Uncertain Nonlinear Systems

Adaptive Backstepping Control of a Class of Uncertain Nonlinear Systems

Adaptive Backstepping Control of a Class of Uncertain Nonlinear Systems
Adaptive Backstepping Control of a Class of Uncertain Nonlinear Systems

Adaptive Backstepping Control of a Class of Uncertain Nonlinear Systems With Unknown Backlash-Like

Hysteresis

Jing Zhou,Changyun Wen,and Ying Zhang Abstract—In this note,we consider the same cl ass of systems as in a pre-vious paper,i.e.,a cl ass of uncertain dynamic nonl inear systems preceded by unknown backl ash-l ike hysteresis nonl inearities,where the hysteresis is model ed by a differential equation,in the presence of bounded external dis-turbances.By using backstepping technique,robust adaptive backstepping control algorithms are developed.Unlike some existing control schemes for systems with hysteresis,the devel oped backstepping control ers do not re-quire the uncertain parameters within known interval s.Al so,no knowl edge is assumed on the bound of the“disturbance-l ike”term,a combination of the external disturbances and a term separated from the hysteresis model. It is shown that the proposed controllers not only can guarantee global sta-bi ity,but a so transient performance.

Index Terms—Adaptive contro l,backstepping,hysteresis,non l inear system,robust contro.

I.I NTRODUCTION

Hysteresis exists in a wide range of physical systems and devices, such as biology optics,electromagnetism,mechanical actuators,elec-tronic relay circuits and other areas.Control of such systems is typically challenging.For backlash hysteresis,several adaptive control schemes have recently been proposed;see,for example,[1]and[2].In[3]–[5], an inverse hysteresis nonlinearity was constructed.An adaptive hys-teresis inverse cascaded with the plant was employed to cancel the ef-fects of hysteresis.In[1],adyna mic hysteresis model is de?ned to pattern a backlash-like hysteresis rather than constructing an inverse model to mitigate the effects of the hysteresis.However,in[1],the term multiplying the control and the uncertain parameters of the system must be within known intervals and the“disturbance-like”term must be bounded with known bound.Projection was used to handle the“dis-turbance-like”term and unknown parameters.System stability was es-tablished and the tracking error was shown to converge to a residual. In this note,we develop two simple backstepping adaptive control schemes for the same class of nonlinear systems as in[1],with bounded external disturbances included in our case.Besides showing global sta-bility of the system,the transient performance in terms of L2norm of the tracking error is derived to be an explicit function of design param-eters and thus our scheme allows designers to obtain the closed loop behavior by tuning design parameters in an explicit way.In the?rst scheme,a sign function is involved and this can ensure perfect tracking. To avoid possible chattering caused by the sign function,we propose an alternative smooth control law and the tracking error is still ensured to approach a prescribed bound in this case.In our design,the term multiplying the control and the system parameters are not assumed to be within known intervals.The bound of the“disturbance-like”term is not required.To handle such a term,an estimator is used to estimate its bound.

Manuscript received July30,2003;revised March25,2004.Recommended by Associate Editor Hua Wang.

J.Zhou and C.Wen are with the School of Electrical and Electronic En-gineering,Nanyang Technological University,Singapore639798,Singapore (e-mail:zhoujing@https://www.sodocs.net/doc/5414261447.html,.sg;ecywen@https://www.sodocs.net/doc/5414261447.html,.sg).

Y.Zhang is with Singapore Institute of Manufacturing Technology,Singapore 638075,Singapore.

Digital Object Identi?er10.1109/TAC.2004.835398

This note is organized as follows.Section II states the problem of this note and assumptions on the nonlinear systems.Sections III presents the adaptive control design based on the backstepping tech-nique and analyzes the stability and performance.Simulation results are presented in Section IV.Finally,Section V concludes this note.

II.P ROBLEM S TATEMENT

We consider the same class of systems as in[1].For completeness, the system model is given as follows:

x(n)(t)+

r

i=1

a i Y

i x(t);_x(t);...;x(n01)(t

)=b!(v)+ d(t)

(1) where Y i are known continuous linear or nonlinear functions, d(t)de-notes bounded external disturbances,parameters a i are unknown con-stants and control gain b is unknown bounded constant,v is the control input,!(v)denotes hysteresis type of nonlinearity described by

d!

dt

= dv

dt

(cv0!)+B1dv

dt(2) where ;c,a nd B1are constants,c>0is the slope of the lines satis-fying c>B1.Based on the analysis in[1],this equation can be solved explicitly

!(t)=cv(t)+d1(v)(3)

d1(v)=[!00cv0]e0 (v0v)sgn_v

+e0 v sgn_v

v

v

[B10c]e (sgn_v)d :(4)

The solution indicates that dynamic(2)can be used to model a class of backlash-like hysteresis as shown in Fig.1,where the parameters = 1;c=3:1635,a nd B1=0:345,the input signal v(t)=6:5sin(2:3t) and the initial condition!(0)=0.For d1(v),it is bounded as shown in[1].

From the solution structure(3)of model(2),(1)becomes

x(n)(t)+

r

i=1

a i Y

i x(t);_x(t);...;x(n01)(t

)= v(t)+d(t)

(5) where =bc and d(t)=bd1(v(t))+ d(t).The effect of d(t)is due to both external disturbances and bd1(v(t)).We call d(t)a“disturba nce-like”term for simplicity of presentation and use D to denote its bound. Now,(5)is rewritten in the following form:

_x1=x2

..

.

_x n01=x n

_x n=0

r

i=1

a i Y i x1(t);x2(t);...;x(n01)(t)

+ v(t)+d(t)

=a T Y+ v(t)+d(t)(6) where

x1=x;x2=_x;...;x n=x(n01)

a=[0a1;0a2;...;0a r]T

Y=[Y1;Y2;...;Y r]T:

0018-9286/04$20.00?2004IEEE

Fig.1.Hysteresis curves.

For the development of control laws,the following assumptions are made.

Assumption1:The uncertain parameters b and c are such that > 0.

Assumption2:The desired trajectory y r(t)and its(n01)th-order derivatives are known and bounded.

The control objectives are to design backstepping adaptive control laws such that

?the closed loop is globally stable in sense that all the signals in the loop are uniformly ultimately bounded;

?the tracking error x(t)0y r(t)is adjustable during the tran-sient period by an explicit choice of design parameters and lim t!1x(t)0y r(t)=0or lim t!1j x(t)0y r(t)j 1for an arbitrary speci?ed bound 1.

Remark1:Compared with[1],the uncertain parameters and a i are not assumed inside known intervals.The bound D for d(t)is not as-sumed to be known and it will be estimated by our adaptive controllers. Also the control objectives are not only to ensure global stability,but also transient performance.

III.D ESIGN OF A DAPTIVE C ONTROLLERS

Before presenting the adaptive control design using the backstepping technique in[6]and[7]to achieve the desired control objectives,the following change of coordinates is made:

z1=x10y r(7)

z i=x i0y(i01)

r

0 i01;i=2;3;...;n(8)

where i01is the virtual control at the i th step and will be determined in later discussion.In the following,two control schemes are proposed.A.Control Scheme I

To illustrate the backstepping procedures,only the last step of the design,i.e.,step n,is elaborated in details.

?Step1:We start with the equation for the tracking error z1ob-tained from(6)to(8)

_z1=z2+ 1:(9) We design the virtual control law 1as

1=0c1z1(10) where c1is a positive design parameter.From(9)and(10),we have

z1_z1=0c1z21+z1z2:(11)?Step i(i=2;...;n01):Choose

i=0c i z i0z i01+_ i0

1x1;...;x i01;y r;...;y(i01)

r(12) where c i;i=2;...;n01are positive design parameters.From

(8)and(12),we obtain

z i_z i=0z i01z i0c i z2i+z i z i+1:(13)?Step n:From(6)and(8),we obtain

_z n= v(t)+a T Y+d(t)0y(n)r0_ n01:(14) Then,the adaptive control law is designed as follows:

v=^e v(15)

v=0c n z n0z n010^a T Y

0sgn(z n)^D+y(n)r+_ n01(16)

Fig.2.Tracking error-Scheme I.

_^e =0 v z n (17)_^a =0Y z n (18)_^D = j z n j

(19)

where c n ; ,a nd are three positive design parameters,0is a

positive–de?nite matrix,^e

;^a ,a nd ^D are estimates of e =1= ;a ,and D .Let ~e

=e 0^e ;~a =a 0^a ,a nd ~D =D 0^D .Note that v (t )in (14)can be expressed as

v = ^e v = v 0 ~e v :

(20)

From (14),(16),and (20),we obtain

_z n =0c n z n 0z n 01+~a T Y 0sgn(z n )^D +d (t )0 ~e v :

(21)

We de?ne Lyapunov function as

V =

n

i =1

12z 2i +12~a T 001

~a + 2 ~e 2+12

~D 2:

(22)

Then,the derivative of V along with (6)and (15)to (19)is given

by

_V

=

n i =1

z i _z i +~a T 001_~

a + ~e _~e +1

~D _~D

n

i =1

c i z 2i +~a T 001(0Y z n 0_^

a )0 ~e ( v z n +_^e

)+1

~D ( j z n j 0_^D )(23)=0

n

i =1

c i z 2

i

(24)

where we have used (11),(13),(21),and the fact that z n d (t )

j z n j D to obtain (52).

We then have the following stability and performance results based on this scheme.

Theorem 1:Consider the uncertain nonlinear system (1)satisfying Assumptions 1–2.With the application of controller (15)and the pa-rameter update laws (17)–(19),the following statements hold.?The resulting closed-loop system is globally stable.?The asymptotic tracking is achieved,i.e.,

lim t !1

[x (t )0y r (t )]=0:

(25)

?The transient tracking error performance is given by k x (t )0y r (t )k 2 1

p

c 1

1

2~a (0)T 001~a (0)+ 2

~e (0)2

+12

~

D (0)2

1=2

:(26)

Proof:From (24),we established that V is non increasing.

Hence,z i ;i =1;...;n;^e

;^a ;^D are bounded.By applying the LaSalle–Yoshizawa theorem in [7]to (24),it further follows that z i (t )!0;i =1;...;n as t !1,which implies that lim t !1[x (t )0y r (t )]=0.From (24),we also have that

k z 1k 2

2

=10

j z 1( )j 2d

1

c 1

(V (0)0V (1))

1

c 1

V (0)(27)

Fig.3.Control signal v(t)-Scheme I.

Thus,by setting z i(0)=0;i=1;...;n,we obtain

V(0)=1

2~a(0)T001~a(0)+

2

~e(0)2+1

2

~D(0)2(28)

adecrea sing function of ; ,a nd0,independent of c1.This means that the bound resulting from(27)and(28)is

k z1k2 1p

c1

1

2

~a(0)T001~a(0)+

2

~e(0)2+1

2

~

D(0)2

1=2

:

(29)

444

Remark2:From Theorem1,the following conclusions can be ob-

tained.

?The transient performance depends on the initial estimate errors ~e(0);~a(0);~D(0),and the explicit design parameters.The closer the initial estimates^e(0);^a(0),a nd^D(0)to the true values e;a, and D,the better the transient performance.

?The bound for k x(t)0y r(t)k2is an explicit function of de-sign parameters and thus computable.We can decrease the effects of the initial error estimates on the transient performance by in-creasing the adaptation gains ; ,a nd0.

?To improve the tracking error performance we can also increase

the gain c1.However,increasing c1will in?uence other perfor-

mance such as k_x0_y r k2as shown later.

Since_V 0,immediately from(22)we know

V(t)

=

n

i=1

1

2

z2i+1

2

~a T001~a+

2

~e2+1

2

~D2 V(0):

Then

k z i k1 2V(0);i=1;...;n(30)

k~a k1 (0)2V(0)(31)

From(7),(8)for i=2,and(10),we get

k_x0_y r k2=k z20c1z1k2

k z2k2+c1k z1k2:(32)

Similar to the proof of(29),we can get k z2k 2 V(0)=

p

c2and,

thus

k_x0_y r

k2 1p

c2

+

p

c1V(0)(33)

From(33),we can see that increasing c1also increase the error k_x0

_y r k2.This suggests?xing the gain c1to some acceptable value and

adjust the other gains such as ; ,a nd0.

B.Control Scheme II

In the previous scheme,adiscontinuous function sgn(z n)is involved

in the control and this may cause chattering.To avoid this,we now

propose an alternative smooth control scheme.

First,we de?ne afunction sg i(z i)as follows:

sg i(z i

)

=

z i

j z i j

;j z i j i

z i

( 2i0z2i)n0i+2+j z i j

;j z i j< i

(34)

Fig.4.Tracking error-Scheme II.

where i (i =1;...;n )is a positive design parameter.It can be shown that sg i (z i )is (n 0i +2)th-order differentiable.We also design a function f i (z i )as

f i (z i )

=

1;j z i j i 0;

j z i j < i :(35)

Then,we can get

sg i (z i )f i (z i )

=

1;z i i 0;j z i j < i 01;z i i

(36)

To ensure the resultant functions are differentiable,we replace

z 2

i

by (j z i j 0 i )n 0i +2

f i in the Lyapunov functions for i =1;...;n in Sec-tion 3.1and we also replace z i by (j z i j 0 i )n 0i +1s

g i in the design procedure as detailed here.

?Step 1:We design virtual control law 1as 1=0c 1+

1

4

(j z 1j 0 1)n sg 1(z 1)0( 2+1)sg 1(z 1)

(37)

where c 1is a positive design parameter.We choose Lyapunov function V 1as

V 1=

1

n +1

(j z 1j 0 1)n +1f 1:(38)

Then,the derivative of V 1is

_V

1=(j z 1j 0 1)n f 1sg 1(z 1)_z 1 0c 1+1

4

(j z 1j 0 1)2n f 1

+(j z 1j 0 1)n (j z 2j 0 201)f 1

(39)

where (9)and (37)have been used.

?Step 2:We design virtual control law 2as 2=0c 2+

5

4

(j z 2j 0 2)n 01sg 2(z 2)

+_ 10( 3+1)sg 2(z 2)(40)

where c 2is positive design parameter.We design Lyapunov func-tion V 2as

V 2=

1

n

(j z 2j 0 2)n f 2+V 1:(41)

Then,the derivative of V 2is _V

2

2i =1

(j z i j 0 i )2(n 0i +1)f i +M 2

+(j z 2j 0 2)n 01(j z 3j 0 301)f 2

(42)

where M 2=0(1=4)(j z 1j 0 1)2n f 1+(j z 1j 0 1)n (j z 2j 0 20

1)f 10(j z 2j 0 2)2(n 01)f 2.Now,we show that M 2<0.It is clear that M 2 0for j z 2j < 2+1.For j z 2j 2+1

M 2 014(j z 1j 0 1)2n f 1+14

(j z 1j 0 1)2n f 2

1

+(j z 2j 0 201)2

0(j z 2j 0 2)2(n 01)

<(j z 2j 0 2)20(j z 2j 0 2)2(n 01)

=(j z 2j 0 2)2(10(j z 2j 0 2)2(n 02)) 0:

(43)

Then,(42)is written as

_V

2 0

2i =1

c i (j z i j 0 i )2(n 0i +1)f i

+(j z 2j 0 2)n 01(j z 3j 0 301)f 2:(44)

Fig.5.Control signal v(t)-Scheme II.

?Step i(i=3;...;n01):Choose

i=0c i+5

4

(j z i j0 i)n0i+1sg i(z i)+_ i01

0( i+1+1)sg i(z i)(45) where c i is a positive design parameter.

?Step n:The control law and parameter update laws are designed as follows:

v=^e v(46)

v=0(c n+1)(j z n j0 n)sg n(z n)0^a T Y

0sg n^D+y(n)r+_ n01(47) _^e=0 v(j z

n j0 n)f n sg n(z n)(48) _^a=0Y(j z

n j0 n)f n sg n(z n)(19) _^D= (j z

n j0 n)f n(50) where c n; ,a nd are three positive design parameters,0is a positive–de?nite matrix,and^e;^a,a nd^D are estimates of e= 1= ;a and D.We de?ne a Lyapunov function as

V=

n

i=1

1

n0i+2

(j z i j0 i)n0i+2f i+1

2

~a T001~a

+

2

~e2+1

2

~D2:(51)

Then,the derivative of V is given by

_V=_V

n01(j z n j0 n)2f n sg n(z n)_z n+~a T001

_~a

+

~e_~e+1

~D_~D

n

i=1

c i(j z i j0 i)2(n0i+1)f i

+~a T001(0Y(j z n j0 n)f n sg n(z n)0_^a)

~e( v(j z n j0 n)f n sg n(z n)+_^e)

+1

~D( (j z

n j0 n)f n0

_^D)(52)

=0

n

i=1

c i(j z i j0 i)2(n0i+1)f i(53)

where(6),(37),(40),and(46)–(50)have been used.

Theorem2:Consider the uncertain nonlinear system(1)satisfying

Assumptions1and2.With the application of controller(46)and the

parameter update laws(48)to(50),the following statements hold.

?The resulting closed-loop system is globally stable.

?The tracking error approaches 1asymptotically,i.e.,

lim

t!1

j x(t)0y r(t)j= 1:(54)

?The transient tracking error performance is given by

k x(t)0y r(t)k2 1+1

c2n

1

1

2

~a(0)T001~a(0)

+

2

~e(0)2+1

2

~D(0)

2

1=2n

(55)

with z i(0)= i;i=1;...;n.

Proof:Based on(53),the results can be shown by following sim-

ilar steps to that of Theorem1.444

Note that similar remarks made in Remark2are also applicable here.

IV .S IMULATION S TUDIES

In this section,we illustrate the aforementioned methodologies on the same example system in [1]which is described as

_x =a

10e 0x (t )

1+e +b!(t )

(56)

where !represents the output of the hysteresis nonlinearity.The actual parameter values are b =1and a =1.Without con-trol,i.e.,!(t )=0,(56)is unstable as shown in [1],because

_x =(10e 0x (t ))=(1+e 0x (t ))>0for x >0,a nd _x

<0for x <0.The objective is to control the system state x to follow adesired trajectory y r (t )=12:5sin(2:3t )as in [1].

In the simulation of Scheme I,the robust adaptive control law (15)–(19)was used,taking c 1=0:9; =0=0:1; =0:2.The ini-tial values are chosen as follows:^e

(0)=0:8=3;^a (0)=1:5;^D (0)=2;x (0)=1:05,a nd v (0)=0which are the same as in [1].The simulation results presented in the Figs.2and 3are system tracking error and input.

In the simulation of Scheme II by using the robust adaptive control law (46)–(50),we choose c 1; ; ;0,and the initial values to be same as before and 1=0:1.The simulation results presented in Figs.4and 5are system tracking error and input.Clearly,all the results verify our theoretical ?ndings and show the effectiveness of the control schemes.

V .C ONCLUSION

This note presents two backstepping adaptive controller design schemes for a class of uncertain nonlinear single-input–single-output system preceded by unknown backlash-like hysteresis nonlinearities,where the hysteresis is modeled by a differential equation,in the presence of bounded external disturbances.In the ?rst scheme,a sign function is involved and this can ensure perfect tracking.To avoid possible chattering caused by the sign function,we propose an alternative smooth control law and the tracking error is still ensured to approach a prescribed bound in this case.Unlike some existing control schemes,the developed backstepping controls do not require the model parameters within known intervals and the knowledge on the bound of “disturbance-like”term is not required.Besides showing global stability,we also give an explicit bound on the L 2performance of the tracking error in terms of design parameters.Simulation results illustrates the effectiveness of our schemes.

To further improve system performance such as the tracking error,especially in the case without using sign functions,it is worthy to take the system hysteresis into account in the controller design,instead of only considering its effect like bounded disturbances.The ?rst step of achieving this is perhaps to obtain an ef?cient adaptive hysteresis in-verse,which is still unclear and currently under investigation.

R EFERENCES

[1] C.Y .Su,Y .Stepanenko,J.Svoboda,and T.P.Leung,“Robust adap-tive control of a class of nonlinear systems with unknown backlash-like hysteresis,”IEEE Trans.Automat.Contr.,vol.45,pp.2427–2432,Dec.2000.

[2]T.E.Pare and J.P.How,“Robust stability and performance analysis of

systems with hysteresis nonlinearities,”in Proc.Amer.Control Conf.,1998,pp.1904–1908.

[3]N.J.Ahmad and F.Khorrami,“Adaptive control of systems with back-lash hysteresis at the input,”in Proc.Amer.Control Conf.,1999,pp.3018–3022.

[4]G.Tao and P.V .Kokotovic,“Adaptive control of plants with unknown

hysteresis,”IEEE Trans.Automat.Contr.,vol.40,pp.200–212,Feb.1995.

[5]X.Sun,W.Zhang,and Y .Jin,“Stable adaptive control of backlash non-linear systems with bounded disturbance,”in Proc.31st Conf.Decision Control ,1992,pp.274–275.

[6]Y .Zhang,C.Wen,and Y .Soh,“Adaptive backstepping control design

for systems with unknown high-frequency gain,”IEEE Trans.Automat.Contr.,vol.45,pp.2350–2354,Dec.2000.

[7]M.Krstic,I.Kanellakopoulos,and P.V .Kokotovic,Nonlinear and Adap-tive Control Design .New York:Wiley,1995.

On Compensation of Wave Re?ections in Transmission

Lines and Applications to the Overvoltage

Problem AC Motor Drives

Romeo Ortega,Alessandro de Rinaldis,Mark W.Spong,

Sangcheol Lee,and Kwanghee Nam

Abstract—In several practical applications actuators are interconnected to a controlled plant through long cables.If the actuator operates at a fast sampling rate (with respect to the propagation delay of the cable)and its impedance cannot be negl ected,wave re?ections wil occur and the trans-mitted pulse will be deformed—degrading the control quality.In this note,exploiting the scattering variables representation of the transmission line,we provide a framework for the design of active compensators to reduce the wave re?ection probl em.The compensators,impl ementabl e with regul ated current and vo tage sources,can be p aced either on the actuator side or the p ant side,and the on y required prior know edge is the transmission line characteristic impedance and the propagation delay.An adaptive im-plementation that obviates the need of the lines characteristic impedance,but stil requires the knowl edge of the propagation del ay,is al so presented.We prove the existence of an ideal scheme that transforms the line into a pure de ay transfer which,unfortunate y,yie ds an i -posed interconnec-tion and therefore has to be approximated for its practical application.The proposed design method is illustrated with a benchmark ac drives example consisting of a pulsewidth modulation inverter and an induction motor.Index Terms—Impedance,in?nite dimensiona systems,motor contro ,overvol tage,pul sewidth modul ation (PWM)inverter,re?ection coef?cient,transmission ines,wave equation.

I.I NTRODUCTION

In this note,we are interested in the problem of compensation of the wave effects that appear when a fast sampling actuator,with non-negligible impedance,is coupled to the controlled plant through long feeding cables.In this case,the connecting cables behave as a trans-mission line inducing a wave re?ection that deforms the transmitted

Manuscript received November 5,2002;revised September 23,2003and March 26,2004.Recommended by Associate Editor Hua Wang.This work was supported in part by the National Science Foundation under Grant INT-0128656,by the U.S.Of?ce of Naval Research under Grant N00014-02-1-0011,by the KOSEF—Ariel Cooperation Programme between Korea and France,and by the European Project GeoPlex (code IST-2001-34166).

R.Ortega and A.de Rinaldis are with the Laboratorie des Signaux et Systèmes,CNRS-SUPELEC,Gif-sur-Yvette 91192,France (e-mail:or-tega@lss.supelec.fr;derinaldis@lss.supelec.fr).

M.W.Spong is with the Coordinated Science Lab,University of Illinois,Urbana,IL 61801USA (e-mail:m-spong@https://www.sodocs.net/doc/5414261447.html,).

S.Lee is with the Mechatronics Research Group,Korea Electrotechnology Research Institute,ChangWon 641-120,Korea (e-mail:sclee@keri.re.kr).K.Nam is with the Department of Electronic and Electrical Engineering,Po-hang University of Science and Technology,Pohang 790-784,Korea (e-mail:kwnam@postech.ac.kr).

Digital Object Identi?er 10.1109/TAC.2004.835405

0018-9286/04$20.00?2004IEEE

usb驱动程序教程

编写Windows https://www.sodocs.net/doc/5414261447.html,的usb驱动程序教程 Windows https://www.sodocs.net/doc/5414261447.html, 是微软推出的功能强大的嵌入式操作系统,国内采用此操作系统的厂商已经很多了,本文就以windows https://www.sodocs.net/doc/5414261447.html,为例,简单介绍一下如何开发windows https://www.sodocs.net/doc/5414261447.html, 下的USB驱动程序。 Windows https://www.sodocs.net/doc/5414261447.html, 的USB系统软件分为两层: USB Client设备驱动程序和底层的Windows CE实现的函数层。USB设备驱动程序主要负责利用系统提供的底层接口配置设备,和设备进行通讯。底层的函数提本身又由两部分组成,通用串行总线驱动程序(USBD)模块和较低的主控制器驱动程序(HCD)模块。HCD负责最最底层的处理,USBD模块实现较高的USBD函数接口。USB设备驱动主要利用 USBD接口函数和他们的外围设备打交道。 USB设备驱动程序主要和USBD打交道,所以我们必须详细的了解USBD提供的函数。 主要的传输函数有: abourttransfer issuecontroltransfer closetransfer issuein te rruptransfer getisochresult issueisochtransfer gettransferstatus istransfercomplete issuebulktransfer issuevendortransfer 主要的用于打开和关闭usbd和usb设备之间的通信通道的函数有: abortpipetransfers closepipe isdefaultpipehalted ispipehalted openpipe resetdefaultpipe resetpipe 相应的打包函数接口有: getframelength getframenumber releaseframelengthcontrol setframelength takeframelengthcontrol 取得设置设备配置函数: clearfeature setdescriptor getdescriptor setfeature

USB驱动程序编写

USB驱动程序编写 linux下usb驱动编写(内核2.4)——2.6与此接口有区别2006-09-15 14:57我们知道了在Linux 下如何去使用一些最常见的USB设备。但对于做系统设计的程序员来说,这是远远不够的,我们还需要具有驱动程序的阅读、修改和开发能力。在此下篇中,就是要通过简单的USB驱动的例子,随您一起进入USB驱动开发的世界。 USB骨架程序(usb-skeleton),是USB驱动程序的基础,通过对它源码的学习和理解,可以使我们迅速地了解USB驱动架构,迅速地开发我们自己的USB硬件的驱动。 USB驱动开发 在掌握了USB设备的配置后,对于程序员,我们就可以尝试进行一些简单的USB驱动的修改和开发了。这一段落,我们会讲解一个最基础USB框架的基础上,做两个小的USB驱动的例子。 USB骨架 在Linux kernel源码目录中driver/usb/usb-skeleton.c为我们提供了一个最基础的USB驱动程序。我们称为USB骨架。通过它我们仅需要修改极少的部分,就可以完成一个USB设备的驱动。我们的USB驱动开发也是从她开始的。 那些linux下不支持的USB设备几乎都是生产厂商特定的产品。如果生产厂商在他们的产品中使用自己定义的协议,他们就需要为此设备创建特定的驱动程序。当然我们知道,有些生产厂商公开他们的USB协议,并帮助Linux驱动程序的开发,然而有些生产厂商却根本不公开他们的USB协议。因为每一个不同的协议都会产生一个新的驱动程序,所以就有了这个通用的USB驱动骨架程序,它是以pci 骨架为模板的。 如果你准备写一个linux驱动程序,首先要熟悉USB协议规范。USB主页上有它的帮助。一些比较典型的驱动可以在上面发现,同时还介绍了USB urbs的概念,而这个是usb驱动程序中最基本的。 Linux USB 驱动程序需要做的第一件事情就是在Linux USB 子系统里注册,并提供一些相关信息,例如这个驱动程序支持那种设备,当被支持的设备从系统插入或拔出时,会有哪些动作。所有这些信息都传送到USB 子系统中,在usb骨架驱动程序中是这样来表示的: static struct usb_driver skel_driver = { name: skeleton, probe: skel_probe, disconnect: skel_disconnect, fops: &skel_fops, minor: USB_SKEL_MINOR_BASE, id_table: skel_table,

USB设备驱动程序设计

USB设备驱动程序设计 引言 USB 总线是1995 年微软、IBM 等公司推出的一种新型通信标准总线, 特点是速度快、价格低、独立供电、支持热插拔等,其版本从早期的1.0、1.1 已经发展到目前的2.0 版本,2.0 版本的最高数据传输速度达到480Mbit/s,能 满足包括视频在内的多种高速外部设备的数据传输要求,由于其众多的优点,USB 总线越来越多的被应用到计算机与外设的接口中,芯片厂家也提供了多种USB 接口芯片供设计者使用,为了开发出功能强大的USB 设备,设计者往往 需要自己开发USB 设备驱动程序,驱动程序开发一直是Windows 开发中较难 的一个方面,但是通过使用专门的驱动程序开发包能减小开发的难度,提高工 作效率,本文使用Compuware Numega 公司的DriverStudio3.2 开发包,开发了基于NXP 公司USB2.0 控制芯片ISP1581 的USB 设备驱动程序。 USB 设备驱动程序的模型 USB 设备驱动程序是一种典型的WDM(Windows Driver Model)驱动程序,其程序模型如图1 所示。用户应用程序工作在Windows 操作系统的用户模式层,它不能直接访问USB 设备,当需要访问时,通过调用操作系统的 API(Application programming interface)函数生成I/O 请求信息包(IRP),IRP 被传输到工作于内核模式层的设备驱动程序,并通过驱动程序完成与UBS 外设通 信。设备驱动程序包括两层:函数驱动程序层和总线驱动程序层,函数驱动程 序一方面通过IRP 及API 函数与应用程序通信,另一方面调用相应的总线驱动 程序,总线驱动程序完成和外设硬件通信。USB 总线驱动程序已经由操作系统 提供,驱动程序开发的重点是函数驱动程序。 USB 设备驱动程序的设计

最新开发usb驱动程序的方法连载一

最新开发usb驱动程序的方法连载一 开发usb驱动程序的方法(连载二) NT还有更多其他的对象,例如中断对象、Controller对象、定时器对象等等,但在我们开发的驱动程序中并没有用到,因此在这里不做介绍。 I/O缓冲策略 很明显的,驱动程序和客户应用程序经常需要进行数据交换,但我们知道驱动程序和客户应用程序可能不在同一个地址空间,因此操作系统必须解决两者之间的数据交换。这就就设计到设备的I/O缓冲策略。 读写请求的I/O缓冲策略 前面说到通过设置Device对象的Flag可以选择控制处理读写请求的I/O缓冲策略。下面对这些缓冲策略分别做一介绍。 1、缓冲I/O(DO_BUFFERED_IO) 在读写请求的一开始,I/O管理器检查用户缓冲区的可访问性,然后分配与调用者的缓冲区一样大的非分页池,并把它的地址放在IRP的AssociatedIrp.SystemBuffer域中。驱动程序就利用这个域来进行实际数据的传输。 对于IRP_MJ_READ读请求,I/O管理器还把IRP的UserBuffer域设置成调用者缓冲区的用户空间地址。当请求完成时,I/O管理器利用这个地址将数据从驱动程序的系统空间拷贝回调用者的缓冲区。对于IRP_MJ_WRITE写请求,UserBuffer被设置为NULL,并把用户缓冲区的数据拷贝到系统缓冲区中。 2、直接I/O(DO_DIRECT_IO) I/O管理器首先检查用户缓冲区的可访问性,并在物理内存中锁定它。然后它为该缓冲区创建一个内存描述表(MDL),并把MDL的地址存放在IRP的MdlAddress域中。AssociatedIrp.SystemBuffer和 UserBuffer 都被设置为NULL。驱动程序可以调用函数 MmGetSystemAddressForMdl得到用户缓冲区的系统空间地址,从而进行数据操作。这个函数将调用者的缓冲区映射到非份页的地址空间。驱动程序完成I/O请求后,系统自动从系统空间解除缓冲区的映射。 3、这两种方法都不是 这种情况比较少用,因为这需要驱动程序自己来处理缓冲问题。 I/O管理器仅把调用者缓冲区的用户空间地址放到IRP的UserBuffer 域中。我们并不推荐这种方式。 IOCTL缓冲区的缓冲策略 IOCTL请求涉及来自调用者的输入缓冲区和返回到调用者的输出缓冲区。为了理解IOCTL请求,我们先来看看WIN32 API DeviceIoControl函数的原型。 BOOL DeviceIoControl ( HANDLE hDevice, // 设备句柄 DWORD dwIoControlCode, // IOCTL请求操作代码 LPVOID lpInBuffer, // 输入缓冲区地址 DWORD nInBufferSize, // 输入缓冲区大小 LPVOID lpOutBuffer, // 输出缓冲区地址 DWORD nOutBufferSize, // 输出缓冲区大小 LPDWORD lpBytesReturned, // 存放返回字节数的指针

开发usb驱动程序的方法(连载一)

开发usb驱动程序的方法(连载一) 开始驱动程序设计 下面的文字是从Microsoft的DDK帮助中节选出来的,它让我们明白在开始设计驱动程序应该注意些什么问题,这些都是具有普遍意义的开发准则。应该支持哪些I/O请求在开始写任何代码之前,应该首先确定我们的驱动程序应该处理哪些IRP例程。 如果你在设计一个设备驱动程序,你应该支持和其他相同类型设备的NT驱动程序相同的IRP_MJ_XXX 和IOCTL请求代码。 如果你是在设计一个中间层NT驱动程序,应该首先确认你下层驱动程序所管理的设备,因为一个高层的驱动程序必须具有低层驱动程序绝大多数IRP_MJ_XXX例程入口。高层驱动程序在接到I/O 请求时,在确定自身IRP当前堆栈单元参数有效的前提下,设置好IRP中下一个低层驱动程序的堆栈单元,然后再调用IoCallDriver 将请求传递给下层驱动程序处理。 一旦决定好了你的驱动程序应该处理哪些IRP_MJ_XXX,就可以开始确定驱动程序应该有多少个Dispatch例程。当然也可以考虑把某些 RP_MJ_XXX处理的例程合并为同一例程处理。例如在ChangerDisk 和 VDisk里,对IRP_MJ_CREATE和IRP_MJ_CLOSE处理的例程就是同一函数。对IRP_MJ_READ和IRP_MJ_WRITE处理的例程也是同一个函数。 应该有多少个Device对象? 一个驱动程序必须为它所管理的每个可能成为I/O请求的目标的物理和逻辑设备创建一个命名Device对象。一些低层的驱动程序还可能要创建一些不确定数目的Device对象。例如一个硬盘驱动程序必须为每一个物理硬盘创建一个Device对象,同时还必须为每个物理磁盘上的每个逻辑分区创建一个Device对象。一个高层驱动驱动程序必须为它所代表的虚拟设备创建一个Device 对象,这样更高层的驱动程序才能连接它们的Device对象到这个驱动程序的Device对象。另外,一个高层驱动程序通常为它低层驱动程序所创建的Device对象创建一系列的虚拟或逻辑Device对象。 尽管你可以分阶段来设计你的驱动程序,因此一个处在开发阶段的驱动程序不必一开始就创建出所有它将要处理的所有Device对象。但从一开始就确定好你最终要创建的所有Device对象将有助于设计者所要解决的任何同步问题。另外,确定所要创建的Device对象还有助于你定义Device对象的Device Extension 的内容和数据结构。 开始驱动程序开发 驱动程序的开发是一个从粗到细逐步求精的过程。NT DDK的src\ 目录下有一个庞大的样板代码,几乎覆盖了所有类型的设备驱动程序、高层驱动程序和过滤器驱动程序。在开始开发你的驱动程序之前,你应该在这个样板库下面寻找是否有和你所要开发的类似类型的例程。例如我们所开发的驱动程序,虽然DDK 对USB描述得不是很详细,我们还是可以在src\storage\class目录发现很多和USB设备有关的驱动程序。下面我们来看开发驱动程序的基本步骤。 最简的驱动程序框架 1、写一个DriverEntry例程,在里面调用IoCreateDevice创建一个Device对象。 2、写一个处理IRP_MJ_CREA TE请求的Dispatch例程的基本框架 (参见DDK Kernel-Mode Drivers 4.4.3描述的一个DispatchCreate 例程所要完成的最基本工作。当然写了DispatchCreate例程后,要在DriverEntry 例程为IRP_MJ_CREA TE初始化例程入口)。如果驱动程序创建了多于一个Device对象,则必须为IRP_MJ_CLOSE 请求写一个例程,该例程通常情况下可以和DispatchCreate共用一个例程,参见参见DDK Kernel-Mode Drivers 4.4.3。 3、编译连接你的驱动程序。

USB驱动程序的编写采用WDM驱动程序

U S B驱动程序的编写采用W D M驱动程序 Document serial number【UU89WT-UU98YT-UU8CB-UUUT-UUT108】

USB驱动程序的编写采用WDM 驱动程序。WDM 驱动程序是一些例程的集合,它们被动地存在,等待主机系 统软件(PnP 管理器、I/O 管理器、电源管理器等)来调用或激活它们。具体驱动程序不同,其所包含 的例程也不同。一个WDM 驱动程序的基本组成包括以下5个例程:(1)驱动程序入口例程:处理驱动程序的初始化。 (2)即插即用例程:处理PnP 设备的添加、删除和停止。 (3)分发例程:处理用户应用程序发出的各种 I/O 请求。 (4)电源管理例程:处理电源管理请求。 (5)卸载例程:处理驱动程序的卸载。 包含文件: , , , , , makefile,sources) 在文件中,包含了上述五个例程: 中定义了各种数据结构还有各种IOCTL控制码,用于不同数据的读写。

中实现了各种驱动例程。包含了上述五个所说例程外还包含了其他例程,课程从下面的驱动 程序入口例程得出一些信息。 驱动程序入口例程: NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { NTSTATUS ntStatus = STATUS_SUCCESS; PDEVICE_OBJECT deviceObject = NULL; DriverObject->MajorFunction[IRP_MJ_CREATE] = Ezusb_Create; DriverObject->MajorFunction[IRP_MJ_CLOSE] = Ezusb_Close; ources. If you want to add a new source # file to this

编写USB驱动程序步骤

编写USB驱动程序步骤: 1所有usb驱动都必须创建主要结构体struct usb_driver struct usb_driver ->struct module *owner (有他可正确对该驱动程序引用计数,应为THIS_MODULE) ->const char *name (驱动名字,运行时可在查看 /sys/bus/usb/drivers/) ->const struct usb_device_id *id_table (包含该驱动可支持的所有不同类型的驱动设备,没添探测回调函数不会被调用) ->int (*probe)(struct usb_interface *intf,const struct usb_device_id *id) (usb驱动探测函数,确认后struct usb_interface 应恰当初始化,然后返0,如果出错则返负值) ->void(*disconnect)(struct usb_interface *intf) (当struct usb_interface 被从系统中移除或驱动正从usb核心中卸载时,usb核心将调用此函数)代码实例: static struct usb_driver skel_driver={ .owner = THIS_MODULE, .name = "skeleton", .id_table = skel_table, .probe = skel_probe, .disconnect = skel_disconnect, }; ↓ 2usb_register()注册将struct usb_driver 注册到usb核心,传统是在usb驱动程序模块初始化代码中完成该工作的

USB键盘驱动程序

/* * $Id: usbkbd.c,v 1.27 2001/12/27 10:37:41 vojtech Exp $ * * Copyright (c) 1999-2001 Vojtech Pavlik * * USB HIDBP Keyboard support */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Should you need to contact me, the author, you can do so either by * e-mail - mail your message to , or by paper mail: * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic */ #include #include #include #include #include #include #include /* * Version Information */ #define DRIVER_VERSION "" #define DRIVER_AUTHOR "Vojtech Pavlik " #define DRIVER_DESC "USB HID Boot Protocol keyboard driver" #define DRIVER_LICENSE "GPL"

USB驱动编程指南

USB驱动编写指南 1 概念:模块和设备文件 1.1模块 模块是在核空间运行的程序,实际上是一种目标对象文件,没有,不能独立运行,但是可以装载到系统中作为核的一部分运行,从而可以动态扩充核的功能。模块最主要的用处就是用来实现设备驱动程序。Linux下对于一个硬件的驱动,可以有两种方式:直接加载到核代码中,启动核时就会驱动此硬件设备。另一种就是以模块方式,编译生成一个.ko文件(在2.4以下核中是用.o作模块文件,我们以2.6的核为准,以下同)。当应用程序需要时再加载到核空间运行。所以我们所说的一个硬件的驱动程序,通常指的就是一个驱动模块。 1.2设备文件 设备文件对于一个设备,它可以在/dev下面存在一个对应的逻辑设备节点,这个节点以文件的形式存在,但它不是普通意义上的文件,它是设备文件,更确切的说,它是设备节点。这个节点是通过mknod命令建立的,其中指定了主设备号和次设备号。主设备号表明了某一类设备,一般对应着确定的驱动程序;次设备号一般是区分不同属性,例如不同的使用方法,不同的位置,不同的操作。这个设备号是从/proc/devices文件中获得的,所以一般是先有驱动程序在核中,才有设备节点在目录中。这个设备号(特指主设备号)的主要作用,就是声明设备所使用的驱动程序。驱动程序和设备号是一一对应的,当你打开一个设备文件时,操作系统就已经知道这个设备所对应的驱动程序。对于一个硬件,Linux是这样来进行驱动的:首先,我们必须提供一个.ko的驱动模块文件。我们要使用这个驱动程序,首先要加载它,我们可以用insmod xxx.ko,这样驱动就会根据自己的类型(字符设备类型或块设备类型,例如鼠标就是字符设备而硬盘就是块设备)向系统注册,注册成功系统会反馈一个主设备号,这个主设备号就是系统对它的唯一标识。驱动就是根据此主设备号来创建一个一般放置在/dev目录下的设备文件。在我们要访问此硬件时,就可以对设备文件通过open、read、write、close等命令进行。而驱动就会接收到相应的read、write操作而根据自己的模块中的相应函数进行操作了。 2 USB驱动程序如何应用 了解了上述理论后,我们就可以动手写驱动程序,如果你基本功好,而且写过linux下的硬件驱动,USB的硬件驱动和pci_driver很类似,那么写USB的驱动就比较简单了,如果你只是大体了解了linux的硬件驱动,那也不要紧,因为在linux的核源码中有一个框架程序可以拿来借用一下,这个框架程序在/usr/src/~(你的核版本,以下同)/drivers/usb下,文件名为usb-skeleton.c。写一个USB的驱动程序最基本的要做四件事:驱动程序要支持的设备、注册USB驱动程序、探测和断开、提交和控制urb(USB请求块)(当然也可以不用urb 来传输数据,下文我们会说到)。 2.1驱动程序支持的设备 驱动程序支持的设备有一个结构体struct usb_device_id,这个结构体提供了一列不同类型的该驱动程序支持的USB设备,对于一个只控制一个特定的USB设备的驱动程序来说,struct usb_device_id表被定义为: /* 驱动程序支持的设备列表*/ static struct usb_device_id skel_table = { { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },

USB驱动程序编写和安装导入

10分钟完成一个USB驱动程序 很多写Windows Device Driver的开发人员基本上都是使用Windows DDK进行开发的。但是,现在也有不少人都开始借助一些辅助工具。笔者去年开始接触到riverStudio,发现它真的是一个不错的开发工具,不仅写代码的时候思路清晰,而且和DDK的结合很好。 当然,也有很多人觉得用DriverStudio不够正宗,或者说不能很好的理解Windows Device Driver的架构。我感觉这就有点像MFC和SDK的关系,关于这个问题在很多地方都有争论,比如在万千新闻组上,就讨论了将近2个月。每个人都有自己的最爱,都有自己的习惯,只要你能把事情做好,我想用什么方法应该都是一样的。如果你已经习惯了用DDK开发,那完全还可以继续用下去;如果你觉得DriverStudio不错,那尝试用一个可以给你按照OOP概念来编程的工具有什么不好呢? 在驱动开发网上,经常看到有人询问一些关于DriverStudio的使用的问题。我正好很有幸用它作了几个驱动程序,包括VXD, KMD和WDM,稍微有点心得,因此想写下来给大家作一个小小的参考。如果其中有错误,欢迎大家给我指出,谢谢。 下面我就介绍一下用DriverStudio开发一个USB驱动程序的过程。这个USB设备有3个双向端点,每个端点的配置如下: EP 类型地址buffer(Bytes) 0 IN/OUT Control 0x80/0x00 16/16 1 IN/OUT Bulk 0x81/0x01 16/16 2 IN/OUT Bulk 0x82/0x02 64/64 我们的驱动程序需要实现的功能就是控制设备上的LED灯的亮和灭,以及通过Endpoint 2对设备进行读写。 由于DriveStudio由几个部分组成,我们写这个驱动程序只要用到DriverWorks,因此下面我们就简称它为DW。在这里,我们假定读者已经正确的安装了DW,并且已经编译好了各个库文件。 1. 首先,我们通过快捷方式“Setup DDK and Start MSVC“来启动VC IDE。这个快捷方式所指向的程序,会进行一些必要的设置,然后再启动VC IDE,这样我们的程序就可以使用DDK和DW的头文件和库了。 2. 从VC IDE的菜单"DriverStudio"中选择"DriverWizard", 在如图1所示的对话框中, 写上项目名称. 在这里, 我们将这个项目称为: TEST, 所在的目录为D:\TEST. 然后点按钮"Next >".

usb驱动程序的编写采用wdm驱动程序

USB驱动程序的编写采用WDM 驱动程序。WDM 驱动程序是一些例程的集合,它们被动地存在,等待主机系 统软件(PnP 管理器、I/O 管理器、电源管理器等)来调用或激活它们。具体驱动程序不同,其所包含 的例程也不同。一个WDM 驱动程序的基本组成包括以下5个例程: (1)驱动程序入口例程:处理驱动程序的初始化。 (2)即插即用例程:处理PnP 设备的添加、删除和停止。 (3)分发例程:处理用户应用程序发出的各种 I/O 请求。 (4)电源管理例程:处理电源管理请求。 (5)卸载例程:处理驱动程序的卸载。 包含文件: , , , , , makefile,sources) 在文件中,包含了上述五个例程: 中定义了各种数据结构还有各种IOCTL控制码,用于不同数据的读写。 中实现了各种驱动例程。包含了上述五个所说例程外还包含了其他例程,课程从下面的驱动 程序入口例程得出一些信息。

驱动程序入口例程: NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { NTSTATUS ntStatus = STATUS_SUCCESS; PDEVICE_OBJECT deviceObject = NULL; DriverObject->MajorFunction[IRP_MJ_CREATE] = Ezusb_Create; DriverObject->MajorFunction[IRP_MJ_CLOSE] = Ezusb_Close; ources. If you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the driver components of the Windows NT DDK # !INCLUDE $(NTMAKEENV) 不要编辑这个文件。事实上每个WDM程序所需要的makefile的内容都是一样的,只需要简单地copy 一个makefile到新的项目中就可以了

开发usb驱动程序的方法

开发驱动程序的方法(连载一) 开始驱动程序设计 下面的文字是从的帮助中节选出来的,它让我们明白在开始设计驱动程序应该注意些什么问题,这些都是具有普遍意义的开发准则。应该支持哪些请求在开始写任何代码之前,应该首先确定我们的驱动程序应该处理哪些例程。 如果你在设计一个设备驱动程序,你应该支持和其他相同类型设备的驱动程序相同的和请求代码。 如果你是在设计一个中间层驱动程序,应该首先确认你下层驱动程序所管理的设备,因为一个高层的驱动程序必须具有低层驱动程序绝大多数例程入口。高层驱动程序在接到请求时,在确定自身当前堆栈单元参数有效的前提下,设置好中下一个低层驱动程序的堆栈单元,然后再调用将请求传递给下层驱动程序处理。 一旦决定好了你的驱动程序应该处理哪些,就可以开始确定驱动程序应该有多少个例程。当然也可以考虑把某些处理的例程合并为同一例程处理。例如在和里,对和处理的例程就是同一函数。对和处理的例程也是同一个函数。 应该有多少个对象? 一个驱动程序必须为它所管理的每个可能成为请求的目标的物理和逻辑设备创建一个命名对象。一些低层的驱动程序还可能要创建一些不确定数目的对象。例如一个硬盘驱动程序必须为每一个物理硬盘创建一个对象,同时还必须为每个物理磁盘上的每个逻辑分区创建一个对象。 一个高层驱动驱动程序必须为它所代表的虚拟设备创建一个对象,这样更高层的驱动程序才能连接它们的对象到这个驱动程序的对象。另外,一个高层驱动程序通常为它低层驱动程序所创建的对象创建一系列的虚拟或逻辑对象。 尽管你可以分阶段来设计你的驱动程序,因此一个处在开发阶段的驱动程序不必一开始就创建出所有它将要处理的所有对象。但从一开始就确定好你最终要创建的所有对象将有助于设计者所要解决的任何同步问题。另外,确定所要创建的对象还有助于你定义对象的的内容和数据结构。 开始驱动程序开发 驱动程序的开发是一个从粗到细逐步求精的过程。的\ 目录下有一个庞大的样板代码,几乎覆盖了所有类型的设备驱动程序、高层驱动程序和过滤器驱动程序。在开始开发你的驱动程序之前,你应该在这个样板库下面寻找是否有和你所要开发的类似类型的例程。例如我们所开发的驱动程序,虽然对描述得不是很详细,我们还是可以在\\目录发现很多和设备有关的驱动程序。下面我们来看开发驱动程序的基本步骤。 最简的驱动程序框架 、写一个例程,在里面调用创建一个对象。 、写一个处理请求的例程的基本框架 (参见 4.4.3描述的一个例程所要完成的最基本工作。当然写了例程后,要在例程为初始化例程入口)。如果驱动程序创建了多于一个对象,则必须为请求写一个例程,该例程通常情况下可以和共用一个例程,参见参见。 、编译连接你的驱动程序。 用下面的方法来测试你的驱动程序。 首先按上面介绍的方法安装好驱动程序。 其次我们还得为逻辑设备名称和目标对象名称之间建立起符号连接,我们在前面已经知道对象名称对用户模式是不可见的,是不能直接通过来访问的,只能访问逻辑设备名称。我们可以通过修改注册表来建立这两种名称之间的符号连接。运行在\\ \ \\ \ 下建立起符号连接(这种符号连接也可以在驱动程序里调用函数来创建)。

(简易USB驱动)开发指导

实验七(2)设备驱动开发指导 块设备种类多,使用广泛,其驱动程序的开发也比字符设备复杂。通过本实验,大家要开发一个实际块设备(U盘)的驱动程序,将能够更深入地掌握块设备驱动程序的开发方法。Linux下已经有一个通用的U盘驱动程序usb-storage.o,其源程序放在目录drivers\usb\storage下(相对于内核源码根目录)。但这个驱动的实现相当复杂,本实验希望开发一个相对简单些的U盘驱动程序,不求高性能,只求结构明朗、清晰易懂,主要是让大家掌握一个实际块设备的驱动方式,从而加深理解。 事实上,本实验开发的驱动程序应该能够适用于所有基于Bulkonly传输协议的USB大容量存储设备(USB Mass Storage),比如USB移动硬盘和USB外置光驱,USB闪存盘(U 盘)只是其中的一种。由于USB大容量存储设备具有容量大、速度快、连接灵活、即插即用、总线供电等优点,它们得到了广泛使用,掌握这类设备驱动程序的开发技术无疑具有很强的实用性。 实验内容 编写一个U盘驱动程序myudisk,只要求能够驱动某个型号的U盘,能够支持U盘的常规操作,如命令hexdump、mke2fs和mount等。同时,要求在系统内核日志中显示出U盘的容量。若有余力,可增加多分区支持功能。 实验基础和思路 在教材中P130,讲解了如何编写一个Ramdisk块设备驱动程序(sbull.c),称为radimo;在文献《Linux Device Drivers》讲解了如何编写一个USB设备驱动程序,并以Linux源代码中的usb-skeleton.c为例。虽然前者驱动的并不是一个实际的块设备,且后者又只是针对usb字符设备,但是它们提供了一个不错的基础,通过合并我们就能基本得到一个支持usb块设备的驱动程序。之所以说基本得到,是因为合并后只是有了块设备、USB设备的驱动支持框架,但还缺一样:对U盘(USB块设备)的实际访问操作。USB块设备的访问方法与USB字符设备区别很大,有一套复杂的协议。把这样一套协议研究清楚,将花费大量时间,也远离了我们驱动程序开发的核心。这是一大难点,为此我们专门编写了一个U盘访问函数(myudisk_Bulk_transport),以减轻工作量。下一节将对该函数的使用方法和工作过程进行专门讲解。 简言之,合并radimo和usb-skeleton这两个参考驱动程序,以构造整体框架,调用帮助函数myudisk_Bulk_transport以访问U盘,从而打造一个简洁的U盘驱动程序。本节接下来介绍这两个参考驱动程序:radimo和usb-skeleton,着重讲解其工作原理及合并关键环节。 参考驱动程序一:块设备驱动程序sbull 请参看教材P130

USB上位机驱动程序环境搭建

USB上位机驱动程序环境搭建(一)WinXP SP1+DS3.2+XP DDK+VC6.0 分享修改 我使用的是WinXP SP2+DS3.2+XP DDK+VC6.0英文版,以下为DS3.2版本的安装过程: 1.安装英文原版Visual studio 6.0,同时要记住注册环境变量。 2.安装XPDDK,安装时候注意需要将所有的组件、工具、例子等都安装(避免出现头文件和链接库找不到的问题); 3.安装DS3.2; 4.通过DriverStudio菜单{C:\Documents and Settings\All Users\「开始」菜单\程序\Compuware DriverStudio\Develop}下的DDK Build Settings子菜单启动VC,不要去点桌面上的快捷方式。 5.用Open Workspace打开位于DS安装目录的 ……\DriverWorks\Source\vdwlibs.dsw。 6. 选择VC的Build菜单,选择batch Build,在之后的对话框中选择"Select x86",然后点击Rebuld all.等待编译成功,编译成功后, vdw_wdm.lib会在{E:\Program Files\Compuware\DriverStudio\DriverWorks\lib\i386\checked(或是free)}下。 7. 打开位于……\DriverWorks\Examples\wdm\hellowdm.dsw,然后编译(用VC的编译和用DS增加的编译钮都可以)。如果你可以在其目录中找到hellowdm.sys你就成功了。如果程序报警:不能找到kcsq.h,可到{E:\Program

USB驱动开发(一)

一USB的框架 提到USB的框架,先看一张很经典的架构图 总结一句话就是:设备通常有一个或多个配置,配置通常有一个或多个接口,接口通常有一个或多个设置,接口有零或多个端点。 设备描述符是用来记录设备的通用信息,比如供应商ID、产品ID和修订ID,支持的设备类、子类和适用的协议以及默认端点的最大包大小等 struct usb_device_descriptor { _ _u8 bLength; //描述符长度 _ _u8 bDescriptorType; //描述符类型编号 _ _le16 bcdUSB; //USB版本号 _ _u8 bDeviceClass; //USB分配的设备类code _ _u8 bDeviceSubClass; // USB分配的子类code _ _u8 bDeviceProtocol; //USB分配的协议code _ _u8 bMaxPacketSize0; //endpoint0最大包大小 _ _le16 idVendor; //厂商编号 _ _le16 idProduct; //产品编号 _ _le16 bcdDevice; //设备出厂编号 _ _u8 iManufacturer; //描述厂商字符串的索引 _ _u8 iProduct; //描述产品字符串的索引 _ _u8 iSerialNumber; //描述设备序列号字符串的索引 _ _u8 bNumConfigurations; //可能的配置数量 } _ _attribute_ _ ((packed)); 配置描述符可以包含一个或多个配置,比如USB设备的低功耗模式和高功耗模式可分别对应一个配置。但是存在多个配置时,在使用USB设备前,必须为其选择一个合适的配置。USB设备的每一个配置都必须有一个配置描述符。 struct usb_config_descriptor { _ _u8 bLength; //描述符长度 _ _u8 bDescriptorType; //描述符类型编号 _ _le16 wTotalLength; //配置所返回的所有数据的大小 _ _u8 bNumInterfaces; // 配置所支持的接口数

studio10分钟完成一个USB驱动程序

10分钟完成一个USB驱动程序 (Rayyang2000倾情奉献) 很多写Windows Device Driver的开发人员基本上都是使用Windows DDK进行开发的。但是,现在也有不少人都开始借助一些辅助工具。笔者去年开始接触到driverStudio,发现它真的是一个不错的开发工具,不仅写代码的时候思路清晰,而且和DDK的结合很好。 当然,也有很多人觉得用DriverStudio不够正宗,或者说不能很好的理解Windows Device Driver的架构。我感觉这就有点像MFC和SDK的关系,关于这个问题在很多地方都有争论,比如在万千新闻组上,就讨论了将近2个月。每个人都有自己的最爱,都有自己的习惯,只要你能把事情做好,我想用什么方法应该都是一样的。如果你已经习惯了用DDK开发,那完全还可以继续用下去;如果你觉得DriverStudio不错,那尝试用一个可以给你按照OOP概念来编程的工具有什么不好呢? 在驱动开发网上,经常看到有人询问一些关于DriverStudio的使用的问题。我正好很有幸用它作了几个驱动程序,包括VXD, KMD和WDM,稍微有点心得,因此想写下来给大家作一个小小的参考。如果其中有错误,欢迎大家给我指出,谢谢。 下面我就介绍一下用DriverStudio开发一个USB驱动程序的过程。这个USB设备有3个双向端点,每个端点的配置如下: EP 类型地址 buffer(Bytes) 0 IN/OUT Control 0x80/0x00 16/16 1 IN/OUT Bulk 0x81/0x01 16/16 2 IN/OUT Bulk 0x82/0x02 64/64 我们的驱动程序需要实现的功能就是控制设备上的LED灯的亮和灭,以及通过Endpoint 2对设备进行读写。由于DriveStudio由几个部分组成,我们写这个驱动程序只要用到DriverWorks,因此下面我们就简称它为DW。在这里,我们假定读者已经正确的安装了DW,并且已经编译好了各个库文件。 1. 首先,我们通过快捷方式“Setup DDK and Start MSVC“来启动VC IDE。这个快捷方式所指向的程序,会进行一些必要的设置,然后再启动VC IDE,这样我们的程序就可以使用DDK和DW的头文件和库了。 2. 从VC IDE的菜单"DriverStudio"中选择"DriverWizard", 在如图1所示的对话框中, 写上项目名称. 在这里, 我们将这个项目称为: TEST, 所在的目录为D:\TEST. 然后点按钮"Next >".

相关主题