Summary of the invention
The technical problem to be solved in the present invention is, a kind of bus arbitration method and arbitration device are provided, it is fair all to compare on time and weight, and the time-delay of this referee method and device is fixed and be smaller, is applicable to that communication system realizes sharing and arbitration of high-speed bus master slave mode.Particularly in the middle of the many systems of slave unit, the efficient of arbitration can not descend with the increase of slave unit.
The above-mentioned technical problem of the present invention solves like this, constructs a kind of bus arbitration method of determining the usufructuary justice of high-speed bus in base station system, comprises the steps:
The bus application that produces in the same clock cycle is sampled;
Add up the number of application in the same clock cycle, and by the priority of application time application is sorted, give each application a queue order value, the precedence that this numerical value representative application arrives is carried out the time arbitration to each application;
Each the bus application that produces in the same clock cycle is produced a weight;
According to the weight of each application, in the application that arrives simultaneously in the same clock cycle, carry out the weight arbitration, one that selects the weight maximum gives the bus right to use.
In the bus arbitration method of above-mentioned justice, described the bus application that produces in same clock cycle is carried out also comprising the steps: in the sampling step applying for that to N+1 line samples with same clock, produce the bus application when detecting the trailing edge of applying on the line, the application that arrives in the same sampling period will produce the bus application simultaneously.
In the bus arbitration method of above-mentioned justice, the number of application in the same clock cycle of described statistics, and by the priority of application time application is carried out also comprising the steps in the ordered steps;
Adopt the mode of formation to sort, the sequence number that is positioned at queue heads is decided to be 1, is that 0 expression is not in the middle of the sequence;
The application accumulator is added up the number that arrives application in the same clock cycle, and rear of queue generator initial value is 1, and the initial sequence number of expression rear of queue is 1;
The rear of queue generator is current numerical value and ask the result of accumulator to add up, and represents that new application arrives, and rear of queue moves backward; The application counter subtracts 1 after application is allowed to, represent that an application removes in the middle of formation, rear of queue forward mobile 1.
Obtain present rear of queue sequence number from the rear of queue generator, with this sequence number as this application at the initialization sequence of formation number, just this application is connected rear of queue, the rear of queue generator adds 1 simultaneously, upgrade the position of rear of queue, all applications are arranged in the middle of the formation according to the chronological order of sampling, wherein the sequence number of queue heads is 1, and what deposit is the application that arrives the earliest.
In the bus arbitration method of above-mentioned justice, also comprise the steps: in the described step that each the bus application that produces in same clock cycle is produced a weight
The operating position of statistics bus is decided to be the weight height with taking the few application of bus number of times, and in the system of N slave unit, minimum weight is decided to be 0, the highest N that is decided to be.
In the bus arbitration method of above-mentioned justice, described of selecting the weight maximum gives also to comprise the steps: in the bus right to use
In the middle of the live application line of output, find out the application of weight maximum, concrete steps are as follows: application form is shown S0_REQ0 ... S0_REQN, weight table is shown 0 ... N is expressed as binary system L (k) 2
k+ L (k-1) 2
(k-1)+ ... + L (0) 2
0
Check at first in the weight of live application whether L (k) is arranged is 1, if having, then maximum weight is inevitable greater than 2
k, then weight greater than 2
kApplication carry out the second level and select S20-S2N, otherwise, weight less than 2
kApplication carry out the second level and select;
Said process is expressed as on logic realization:
After the selection of K=LOG2 (N+1) level, can select the application of weight maximum;
After an application obtains bus grant, the weight of this application is made as minimum, weight all adds 1 than the weight of its little application, through after the arbitration of several times weight is carried out the several times adjustment, at last, N+1 application still is in N+1 the different weight, and weight is relevant with the time interval of once using bus, and the time is long more, weight is big more, weight is big more, allows to use the probability of bus just high more, guarantees that each slave unit uses the time of bus.
Another problem of the present invention solves like this, construct a kind of bus arbitration device of in base station system, determining the usufructuary justice of high-speed bus, comprise the time moderator, weight moderator and output interface, described time moderator is delivered in the described weight moderator after the bus application that produces in same clock cycle being sampled and by the priority of application time application being sorted, described weight moderator produces a weight to each application and according to the weight of each application, in the application that arrives simultaneously in the same clock cycle, one that selects the weight maximum gives the bus right to use.
In the bus arbitration device of above-mentioned justice, described time moderator is included in the sampler of in the same clock N+1 application line being sampled, be connected the application accumulator that is used to add up arrival application number in the same clock cycle with described sampler, the rear of queue generator that application in the described accumulator is sorted, the queue management device that described rear of queue generator is managed, described queue management device obtains present rear of queue sequence number from the rear of queue generator, with this sequence number as this application at the initialization sequence of formation number, be arranged in the formation of exporting to the weight moderator.
In the bus arbitration device of above-mentioned justice, described weight moderator comprises the multistage weight selector that serial connection connects, the weight generator that is connected with described multistage weight selector, described weight generator produces a weight to each application, described multistage selector is according to the weight of each application, the application that arrives when the time moderator is exported, after the multistage selection of multistage weight selector, one that selects the weight maximum gives the bus right to use by described output interface output.
Implement the bus arbitration method and the device of justice provided by the invention, have following advantage: adopt two instance arbitration, elder generation's elapsed time moderator guarantees first to file, uses earlier; Pass through the weight moderator again, guarantee that the user takies the fairness of bus; For realizing the fairness of time, this method adopts the application queue mode, gives each application a queue order value, the precedence that this numerical value representative application arrives.By this numerical value relatively, just can realize first to file, earlier the arbitration principle that allows.In order to realize the fairness of weight, this method is added up the historical operating position of bus, and higher weight is given in low application to access times, thereby guarantees the fairness that bus is used; Arbitration result is by the bus user's label that is authorized to (GNT NUM) and allow to use bus signals (GNT) to form.The user who hangs bus down determines whether to enjoy bus according to arbitration result.
Embodiment
As shown in Figure 1, sampler T samples to N+1 application line with same clock, produce the bus application when detecting the trailing edge of applying on the line, the application that arrives in the same sampling period will produce the bus application simultaneously, so the precision of time moderator is a clock cycle.The time moderator adopts the mode of formation to realize that the sequence number of queue heads is 1, is that 0 expression does not have in the middle of the sequence, and the specific implementation process is as follows:
The application accumulator is added up the number that arrives application in the same clock cycle, and rear of queue generator initial value is 1, and the sequence number that goes out the beginning of expression rear of queue is 1.The rear of queue generator is current numerical value and ask the result of accumulator to add up, and represents that new application arrives, and rear of queue moves backward.The application counter subtracts 1 after application is allowed to, represent that an application removes in the middle of formation, rear of queue forward mobile 1.Illustrate, the value of supposing a certain moment rear of queue generator is P, apply for that pulse SRQ (I) arrives this moment, queue management device (I) just obtains present rear of queue sequence number P from the rear of queue generator, with P as this application at the initialization sequence of formation number, just this application is connected rear of queue, rear of queue generator D adds 1 simultaneously, upgrades the position of rear of queue.Like this, all applications just according to the chronological order of sampling, are arranged in the middle of the formation, and wherein the header sequence of formation number is 1, and what deposit is the application that arrives the earliest.
New application obtains to be in the initialization sequence number of rear of queue from rear of queue generator D, queue management device (B0-BN) is according to feedback information: bus arbitration answer signal (ACK) and the bus user's label (GNT_NUM) that is authorized to, upgrade each application position in formation.Wherein ACK is that arbitration result is received by slave unit, can carry out the cue mark of the arbitration of next application.GNT_NUM is suitable for the label of the application of bus for the permission of arbitration output.The process that queue management device upgrades sequence number is as follows: receiving ack signal, showing that label is that the slave unit of GNT_NUM has received arbitration result, so the sequence number of its application is clearly 0, be about to this application and clear out of formation.Be not equal to GNT_NUM and be in the application (being that sequence number is 1) of queue heads for other label, be maintained 1.The application of other non-queue heads (sequence number is greater than 1), sequence number subtracts 1, i.e. and the application in the formation is toward reach.Queue management device also will be in the application of queue heads simultaneously and be sent to the weight moderator.
The output of the time that the is input as moderator of weight moderator, its output comprise that bus user's label (GNT_NUM), the bus arbitration result of mandate export indication (GNT).Wherein GNT_NUM and GNT give the bus application slave unit that label is GNT_NUM the bus right to use as final arbitration result output.
As shown in Figure 1, multistage weight selector S, weight generator has been formed the weight moderator jointly.Weight generator, fair is weight of each application generation, and selector is according to the weight of application, and the application that arrives when the time moderator is exported, one that selects the weight maximum gives the bus right to use.
The weight generator operation principle: it is actually a bus and uses the historical statistics device, and in the system of N slave unit, minimum weight is 0, is up to N.The historical operating position of algorithm statistics bus allows take the few application weight height of bus number of times.
Algorithm is as follows:
Compose weight initial value I for the application of label I, shown in Fig. 2 a, after an application (label is I) acquisition bus grant, the weight of this application is made as minimum, weight all adds 1 than the weight of its little application, as Fig. 2 b.Through after the arbitration of several times, weight generator has been carried out the several times adjustment with the mode of Fig. 2 b to weight, and is last, and N+1 application still is in N+1 the different weight, but the corresponding weight of each application this moment has not had initialized regular like that.But the weight of each application is on statistics, and weight is relevant with the time interval of once using bus, and the time is long more, and weight is big more.Weight is big more, allows to use the probability of bus just high more, and this just guarantees the time of the use bus of each slave unit.
The function of the realization of selector S in the middle of effective output application line of time moderator output, is found out the application of weight maximum for adopting the algorithm to component selections.Specific algorithm is as follows: application S0_REQ0 ... S0_REQN, weight 0 ... N is expressed as binary system L (k) 2
k+ L (k-1) 2
(k-1)+ ... + L (0) 2
0Check at first in the weight of live application whether L (k) is arranged is 1, if having, then maximum weight is inevitable greater than 2
k, then weight greater than 2
kApplication be sent to second level selector S20-S2N, otherwise, weight less than 2
kApplication be sent to second level selector.Said process can be expressed as on logic realization:
Available Boolean expression is expressed as
So, finally select the application of weight maximum through multistage selection.Adopt this mode will pass through the application that K=LOG2 (N+1) level selector just can be selected the weight maximum.Certainly, selector also can adopt the bubbling method to realize, but number of comparisons increases along with the increase of N, and it is bigger that hardware realizes going up time-delay.
The weight moderator is exported a bus use authority from high to low according to the weight of each application at every turn.The answer signal that is detected slave unit by output interface adapter " hurries " (BUSY), discovery BUSY signal then will be exported ack signal, with GNT_NUM together, control time moderator and weight moderator carry out the arbitration of next application, what new arbitration result was subjected to slave unit replys the BUSY signal controlling, just exports after waiting the slave unit that uses bus to discharge bus.Like this, two moderators just can carry out next arbitrated procedure in bus between the operating period, use and finish can export the result immediately, reduce the time delay of arbitration, thereby improve the utilization ratio of bus.
The inventive method can adopt VHDL language to write, and device can adopt the FLEX10K50 of ALTERA company to realize.