23.11.2012 Views

The FEE Server Control Engine of the ALICE-TRD - Westfälische ...

The FEE Server Control Engine of the ALICE-TRD - Westfälische ...

The FEE Server Control Engine of the ALICE-TRD - Westfälische ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

5 <strong>The</strong> <strong>FEE</strong><strong>Server</strong> <strong>Control</strong> <strong>Engine</strong><br />

mcm_info [ s l ] . hopcount =<br />

mcm_info [ s l ] . l i n k =0;<br />

s l _ l e f t * 2 − s l −1;<br />

}<br />

i f ( s l >= s l _ r i g h t ) {<br />

mcm_info [ s l ] . dest = no_<strong>of</strong>_slaves − s l +1;<br />

mcm_info [ s l ] . hopcount = ( no_<strong>of</strong>_slaves−s l _ r i g h t ) * 2 − (<br />

no_<strong>of</strong>_slaves−s l ) ;<br />

mcm_info [ s l ] . l i n k =1;<br />

}<br />

broadcast_info . data [ 0 ] . hopcount_write= s l _ l e f t * 2 −1; / / l e f t<br />

p a r t o f t h e l i n k p a i r<br />

broadcast_info . data [ 1 ] . hopcount_write =( no_<strong>of</strong>_slaves − s l _ r i g h t )<br />

* 2 +1; / / r i g h t p a r t o f t h e l i n k p a i r<br />

Listing 5.3: Code to recalculate <strong>the</strong> slave IDs <strong>of</strong> <strong>the</strong> MCMs and <strong>the</strong> broadcast hopcounters in<br />

case <strong>of</strong> a bridged linkpair. sl is <strong>the</strong> slave ID <strong>of</strong> <strong>the</strong> MCM in an unbridged linkpair,<br />

no_<strong>of</strong>_slaves <strong>the</strong> total number <strong>of</strong> MCMs in <strong>the</strong> linkpair (34 or 36), sl_left <strong>the</strong> number<br />

<strong>of</strong> MCMs in <strong>the</strong> ’left’ part and sl_right <strong>the</strong> number <strong>of</strong> MCMs in <strong>the</strong> ’right’ part <strong>of</strong> <strong>the</strong><br />

linkpair<br />

When <strong>the</strong> calculation is finished <strong>the</strong> control flow returns to learnConfig() <strong>of</strong> SCSNBus. At<br />

this point it is known which MCMs have to be bridged but <strong>the</strong> MCMs <strong>the</strong>mselves are not<br />

bridged yet. <strong>The</strong> function SCSNBus::learnConfig() calls * SCSNBusBridge::getSlavesToBridge<br />

(void) for each linkpair to get <strong>the</strong> list <strong>of</strong> MCMs to bridge. In each linkpair ei<strong>the</strong>r no, one,<br />

or two MCMs have to be bridged. <strong>The</strong> function SCSNBus::learnConfig() creates <strong>the</strong> correct<br />

SCSN commands and sends <strong>the</strong>m to <strong>the</strong> MCMs (see next section). If no MCMs have to<br />

be bridge this step is skipped.<br />

Afterwards <strong>the</strong> configuration process is finished and <strong>the</strong> control flow returns to <strong>the</strong><br />

function which has called SCSNBus::learnConfig().<br />

5.3.2 Access Synchronisation<br />

In <strong>the</strong> <strong>FEE</strong><strong>Server</strong> two threads run in parallel. One thread handles commands and configurations<br />

received from <strong>the</strong> ICL and <strong>the</strong> o<strong>the</strong>r thread monitors <strong>the</strong> DCS board sensors and<br />

<strong>the</strong> MCM temperature sensors.<br />

At this point a problem occurs. <strong>The</strong> sensor readout in <strong>the</strong> second thread runs independently<br />

<strong>of</strong> command handling thread but both threads need hardware access. Nei<strong>the</strong>r can<br />

<strong>the</strong> SCSN bus be accessed by both threads at <strong>the</strong> same time nor is it possible to read out<br />

<strong>the</strong> DCS board sensors and access <strong>the</strong> SCSN bus in parallel. To solve this problem <strong>the</strong><br />

mutex mechanism 6 is used.<br />

In <strong>the</strong> control engine <strong>the</strong> mutex administration and <strong>the</strong> interface to open and close<br />

<strong>the</strong> SCSN Bus are encapsulated in <strong>the</strong> class SCSNGuardian (lib<strong>TRD</strong>). <strong>The</strong> constructor <strong>of</strong><br />

SCSNGuardian locks <strong>the</strong> mutex and opens <strong>the</strong> SCSN bus interface and <strong>the</strong> destructor unlocks<br />

<strong>the</strong> mutex and closes <strong>the</strong> SCSN bus interface. Each time a thread needs SCSN bus<br />

6 <strong>The</strong> mutex mechanism is a programming technique for inter-thread synchronization. One thread locks <strong>the</strong><br />

mutex as soon as it enters a function block which cannot run in parallel. If <strong>the</strong> o<strong>the</strong>r thread now tries to<br />

lock <strong>the</strong> mutex because it also enters a function block which cannot run in parallel, this thread is stopped<br />

as long as <strong>the</strong> mutex remains locked. When <strong>the</strong> mutex is now unlocked by <strong>the</strong> first thread <strong>the</strong> second<br />

thread can lock <strong>the</strong> mutex and continues execution.<br />

64

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!