Worked examples — SpaceWire — high-speed serial link standard for spacecraft
5.5.27 · D3· Coding › Embedded Systems & Real-Time Software › SpaceWire — high-speed serial link standard for spacecraft
Yeh page ek drill floor hai. Parent note ne machinery build ki thi; yahan hum use har tarah ke input se guzarte hain jo wo face kar sakta hai — boring middle cases, weird edges, aur exam traps.
Kisi bhi formula se pehle, ek promise: hum sirf wahi symbols use karenge jo aapke paas parent note se already hain. Agar kuch naya chahiye, pehle plain words mein build karenge.
The scenario matrix
SpaceWire ke har problem ko in case classes mein se kisi ek mein daala ja sakta hai. Har column ek lever hai jise extreme par push kiya ja sakta hai, aur har extreme apne tarike se ek naive formula ko tod deta hai.
| Case class | Jo lever push ho raha hai | Example jo ise cover karta hai |
|---|---|---|
| DS encoding — normal run | mixed bits, dono lines toggle karti hain | Example 1 |
| DS encoding — degenerate | identical bits ki ek run (Data flat) | Example 2 |
| Parity — odd vs even count | 1-bits ki sankhya odd hai, phir even | Example 3 |
| Parity — all-zero / all-one | do extreme bytes | Example 4 |
| Wormhole vs store-forward — long packet | kaafi saare cargo bytes | Example 5 |
| Wormhole — tiny packet limit | cargo → 0 (sirf header) | Example 6 |
| Flow control — short cable | RTT chhota, buffer aasaan | Example 7 |
| Flow control — long cable (real world) | RTT bada, credits scarce | Example 8 |
| Exam twist — mixed units / trap | Mbps vs MB, ns vs μs | Example 9 |
Table ko is tarah padho: "kya galat ho sakta hai?" Identical bits ki ek run Data line ki timing ko khatam kar deti hai. Ek all-zero byte parity ko trivial lagata hai (asal mein hai nahi). Ek zero-length packet latency formula ko sirf header tak collapse kar deta hai. Neeche har example apne cell ke saath tagged hai.
Warm-up: do tools jo hum baar baar use karte hain
Recall Do invariants (parent note se)
Data-Strobe rule — har bit period mein dono lines mein se exactly ek change hoti hai: jahan ka matlab XOR hai (1 agar dono inputs alag hain, 0 agar match karte hain).
Ek wormhole route ki latency: = hops ki sankhya (switches), = per-switch delay, = payload ko line rate par stream karne ka time.
Inhe nazar mein rakho. Aadhe examples sirf yahi formulas hain jo ek edge tak push kiye gaye hain.
Example 1 — DS encoding, normal run
Pehle forecast karo: guess karo ki Strobe in 5 bits mein kitni baar toggle karega. (Hint: yeh sirf tab toggle karta hai jab Data nahi karta.)
Steps.
-
Data line = bit value khud. Toh Data se guzarta hai (starting state 0 hai, phir 5 bits). Yeh step kyun? Parent note ka poora point yahi hai: Data encode nahi hota, yeh hai. Chaalaki Strobe mein rehti hai.
-
Strobe rule: Strobe tab change karta hai jab Data ne nahi kiya ho. Har bit ko pehle waale se compare karo:
- (bit 1): Data ne change kiya → Strobe hold karta hai.
- (bit 2): Data ne change kiya → Strobe hold karta hai.
- (bit 3): Data same → Strobe toggle karta hai.
- (bit 4): Data ne change kiya → Strobe hold karta hai.
- (bit 5): Data same → Strobe toggle karta hai. Yeh step kyun? Yeh guarantee karta hai ki "exactly ek line har bit mein move kare," jo timing anchor hai.
-
Tabulate karo (Data, Strobe) har bit ke baad, (0,0) se shuru karke:
| bit# | Data | Strobe | kisne toggle kiya | |
|---|---|---|---|---|
| 1 | 1 | 1 | 0 | Data |
| 2 | 0 | 0 | 0 | Data |
| 3 | 0 | 0 | 1 | Strobe |
| 4 | 1 | 1 | 1 | Data |
| 5 | 1 | 1 | 0 | Strobe |
Figure dekho: top trace Data hai, middle Strobe hai, aur bottom red trace recovered clock hai — har bit par ek clean edge.

Verify: Strobe exactly bits 3 aur 5 par toggle hua ("same as previous" ke dono cases) → 2 toggles, forecast se match. Har column mein, {Data, Strobe} mein se exactly ek ne change kiya. ✓
Example 2 — DS encoding, identical bits ka degenerate run
Forecast: agar hum sirf Data line bhejtey, toh receiver chaar identical 1s ke across kya dekhta? (Answer: ek flat line — koi edges nahi, koi timing nahi.)
Steps.
-
Data line flat hai. ke liye Data se shuru karke: yeh ek baar utha () phir 1 par ruk jaata hai. Pehle bit ke baad zero Data transitions hain. Yeh step kyun? Yeh bilkul wohi disaster hai jiske liye DS banaya gaya tha — identical bits ki ek lambi run single wire par timing mitaa deti hai.
-
Strobe ab saari timing carry karta hai. Yahan har bit "same as previous" hai, toh Strobe bits 2, 3, 4 par toggle karta hai. Yeh step kyun? Invariant Strobe ko force karta hai jab bhi Data nahi move kar sakta, toh koi bit period silent nahi rehta.
-
Recovered clock phir bhi har bit par tick karta hai, kyunki har period mein ek line move hui.
Figure dekho: Data (top) flat hai jabki Strobe (middle) kaam kar raha hai; recovered clock (red) phir bhi chaar edges dikhata hai.

Verify: 4 bits par recovered clock ke edges ki sankhya = 4 (ek per bit) jabki Data flat tha. Timing preserved. ✓
Example 3 — Parity, odd bit-count byte
Forecast: 1s ko aankhon se gino. Odd ya even? Yeh ek fact dono parity bits decide karta hai.
Steps.
-
Saare aath bits list karo . Ones gino: . Yeh step kyun? Parent note mein flagged classic trap yeh hai ki sirf chhe bits count karo. Aapko saare aath XOR karne chahiye.
-
Saare aath XOR karo — bits ka XOR count ki parity ke barabar hota hai: ones odd hai → XOR . Yeh step kyun? XOR bas yeh hai: "1s ki sankhya odd hai?" ek bit mein pack karke.
-
Parity bits choose karo:
- Even parity ek even total chahta hai → (chhe ones banate hue).
- Odd parity ek odd total chahta hai → (paanch ones rehte hue). Yeh step kyun? Parity wo bit choose karta hai jo group ko target parity mein force kare.
Verify: ke saath, total ones (even ✓). ke saath, total ones (odd ✓). ✓
Example 4 — Parity, do extreme bytes
Forecast: all-zeros "no information" jaisa lagta hai — kya parity kuch karta bhi hai? Aur aath ones — even hai ya odd?
Steps.
-
0x00: zero ones → XOR . Even parity ; odd parity . Yeh step kyun? All-zero byte bhi protect hota hai — ek flipped bit ek akela 1 ban jaata hai aur expected parity tod deta hai.
-
0xFF: aath ones, jo even hai → XOR . Even parity ; odd parity . Yeh step kyun? Aath even hai, toh 0xFF parity ke liye 0x00 jaisa behave karta hai — ek common exam surprise (log sochte hain "all ones = odd").
Verify: XOR(0x00) aur XOR(0xFF) . Dono ko odd-parity bit aur even-parity bit chahiye. ✓
Example 5 — Wormhole vs store-and-forward, long packet
Forecast: ratio guess karo. Long packet + kaafi saare hops wormhole ko hugely favour karna chahiye.
Steps.
-
Body streaming time line rate par: . Yeh step kyun? Bits-per-byte 8 hai; bits ko bits-per-second se divide karne par seconds milte hain.
-
Store-and-forward: 4 switches mein se har ek ko forward karne se pehle poora packet receive karna hoga → . Yeh step kyun? Koi parallelism nahi — har hop full body time pay karta hai.
-
Wormhole: header path ko mein carve karta hai, phir body already-open pipe se ek baar stream hoti hai: . Yeh step kyun? Body bytes wire mein hote hain jabki header aage badh raha hota hai — woh parallelism jo parent note ne stress kiya tha.
Verify: ratio faster. Store-forward , wormhole . ✓
Example 6 — Wormhole limit: header-only packet
Forecast: jab cargo , latency formula sirf hop term tak collapse ho jaana chahiye.
Steps.
-
Body time : essentially koi cargo nahi hone se, . Yeh step kyun? Yeh degenerate limit hai — yeh per-hop cost ko isolate karta hai.
-
Latency . Yeh step kyun? Confirm karta hai ki formula gracefully degrade hota hai; wormhole model mein khud koi hidden minimum-packet penalty nahi hai.
Verify: , poori tarah hop latency se dominated — bilkul wahi limiting behaviour jo humne predict kiya tha. ✓
Example 7 — Flow control, short cable
Forecast: short cable ⇒ credits jaldi return ⇒ tiny buffer. Guess karo ki ek FCT (8 characters) already kaafi hai ya nahi.
Steps.
-
One-way delay . Yeh step kyun? Distance ÷ speed = time; ek bit physically cable travel karne mein itna time leta hai.
-
RTT (credit wapas aana chahiye). Yeh step kyun? Credit tabhi useful hai jab yeh wahaan aur wapas travel kar le.
-
Bytes in flight bytes. Yeh step kyun? Bits-in-flight = rate × RTT; bytes ke liye 8 se divide karo.
-
Ek FCT se compare karo (8 characters grant karta hai). , toh ek FCT is link ko permanently full rakhta hai. Yeh step kyun? Practical sawaal ka jawab: short cables kabhi stall nahi karte.
Verify: in-flight bytes, ek FCT ke 8-character credit se kaafi kam. Koi stall nahi. ✓
Example 8 — Flow control, long cable (real world)
Forecast: lamba cable ⇒ bada RTT ⇒ zyada credit chahiye. Kya ek FCT abhi bhi kaam karega?
Steps.
-
One-way ; RTT . Yeh step kyun? Example 7 jaisi physics, 30× scale up ki.
-
Bytes in flight bytes. Yeh step kyun? Rate × RTT ÷ 8. Yeh woh buffer hai jo aapko stalling avoid karne ke liye outstanding rakhna padega.
-
Credits needed: har FCT characters, toh humein FCT chahiye... lekin boundary par. Harness ya rate double karne par hum 8 se upar chale jaayenge → 2 FCTs. Yeh step kyun? Dikhata hai kyun longer/faster links ko zyada outstanding credit chahiye — RTT-bandwidth product woh design driver hai jo parent note mein naam liya gaya tha.
Verify: in-flight bytes; FCT (bas barely). ✓
Example 9 — Exam twist: unit trap
Forecast: trap b (bits) vs B (bytes) aur M ka matlab hai. Answer ka order of magnitude guess karo.
Steps.
-
Image ko bits mein convert karo. bytes bits. Yeh step kyun? Mbps bits per second count karta hai; payload bytes mein quote kiya gaya hai. Inhe mix karna classic exam kill hai.
-
Rate se divide karo. . Yeh step kyun? Bits ÷ bits-per-second = seconds. Units cleanly cancel hote hain, jo aapka correctness signal hai.
-
Magnitude sanity check karo. 400 Mbps = 50 MB/s; . Bytes ke zariye bhi same answer. Yeh step kyun? Do independent routes agree karein toh koi factor-of-8 slip nahi hua.
Verify: s ms, aur s. ✓
Recall check
Identical bits ki run par Data flat — timing kya bachata hai?
0xFF ke saare aath bits ka XOR?
hops par zero cargo ke saath wormhole latency?
Pipe full rakhne ke liye bytes in flight?
400 Mbps par 1 MB?
Related reading: Wormhole Routing vs Store-and-Forward, LVDS Signaling, RMAP Protocol, Real-Time Determinism, Cosmic Ray Effects on Electronics.