Level 3 — ProductionEmbedded Systems & Real-Time Software

Embedded Systems & Real-Time Software

45 minutes60 marksprintable — key stays hidden on paper

Level 3 — Production (from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60

Instructions: Answer all questions. Show reasoning for calculations. Code may be pseudo-C/FreeRTOS API from memory; minor syntax slips are tolerated if intent is clear.


Question 1 — ADC / Nyquist derivation (10 marks)

A sensor signal has meaningful content up to 4 kHz4\text{ kHz}. You use a 12-bit SAR ADC with reference voltage Vref=3.3 VV_{ref} = 3.3\text{ V} on a bipolar-shifted single-ended input.

(a) State the Nyquist criterion and give the minimum sampling rate needed. (2)

(b) You choose fs=10 kHzf_s = 10\text{ kHz}. Derive the ADC resolution (voltage per LSB) and the quantisation-error bound. (3)

(c) An anti-aliasing filter must attenuate everything above the Nyquist frequency of your chosen fsf_s. State that Nyquist frequency and explain what happens to a 7 kHz7\text{ kHz} tone if the filter is absent (give the aliased frequency). (3)

(d) Explain out loud why oversampling can be used to trade sample rate for effective resolution — give the rule (dB or bits per octave of oversampling). (2)


Question 2 — CAN bus arbitration & timing (12 marks)

(a) Three nodes A, B, C begin transmitting simultaneously on a CAN bus with 11-bit identifiers: A = 0x1A3, B = 0x1A0, C = 0x0F7. Show bit-by-bit which node wins arbitration and explain the rule (dominant vs recessive). (5)

(b) A CAN bus runs at 500 kbit/s500\text{ kbit/s}. State the resulting nominal bit time. If the bus is 40 m40\text{ m} long and signal propagation is 5 ns/m5\text{ ns/m}, comment on whether 500 kbit/s500\text{ kbit/s} is feasible for round-trip arbitration timing. (4)

(c) Name two CAN error-detection mechanisms and explain why CAN is favoured in aerospace/automotive safety-critical buses. (3)


Question 3 — FreeRTOS task + IPC from memory (12 marks)

Write, from memory, a FreeRTOS design where an ISR reads a sensor and a worker task processes it.

(a) Write the xTaskCreate call and the task function skeleton for the worker task at priority 3, stack depth 256 words. (4)

(b) Write the ISR that signals the worker via a binary semaphore, and the worker's blocking wait. Show the correct use of ...FromISR and portYIELD_FROM_ISR. (5)

(c) Explain out loud why a queue or semaphore is preferred over a shared global volatile flag polled by the task. (3)


Question 4 — Priority inversion (10 marks)

(a) Define priority inversion. Using three tasks H (high), M (medium), L (low) and one mutex, describe a concrete sequence that produces unbounded priority inversion. (5)

(b) Explain priority inheritance and how it bounds the inversion in your scenario. (3)

(c) State one difference between priority inheritance and the priority ceiling protocol. (2)


Question 5 — WCET & schedulability (10 marks)

Three periodic tasks under rate-monotonic scheduling:

Task Period TT (ms) WCET CC (ms)
τ1\tau_1 20 5
τ2\tau_2 40 10
τ3\tau_3 80 20

(a) Compute total CPU utilisation UU. (3)

(b) State the Liu & Layland RMS utilisation bound for n=3n=3 tasks and check whether the sufficient test is passed. (4)

(c) The set fails the LL bound. Explain how a response-time analysis could still prove schedulability, and state what "WCET" must account for that a stopwatch measurement might miss. (3)


Question 6 — Redundancy & safety (6 marks)

(a) Draw/describe a TMR system with voting logic and give the boolean expression for the 2-of-3 majority voter output VV from inputs a,b,ca,b,c. (3)

(b) Distinguish fail-safe vs fail-operational, giving one aerospace example of each. (3)

Answer keyMark scheme & solutions

Question 1 (10)

(a) Nyquist: sampling rate must be strictly greater than twice the highest frequency component: fs>2fmaxf_s > 2 f_{max}. Here fmax=4 kHzf_{max}=4\text{ kHz}, so minimum fs>8 kHzf_s > 8\text{ kHz}. (1 criterion, 1 value)

(b) LSB voltage = Vref/2N=3.3/212=3.3/40968.056×104 V=0.806 mVV_{ref}/2^N = 3.3 / 2^{12} = 3.3/4096 \approx 8.056\times10^{-4}\text{ V} = 0.806\text{ mV}. (2) Quantisation error bound =±12LSB±0.403 mV= \pm \tfrac12 \text{LSB} \approx \pm 0.403\text{ mV}. (1)

(c) Nyquist frequency of fs=10 kHzf_s=10\text{ kHz} is fs/2=5 kHzf_s/2 = 5\text{ kHz}. (1) A 7 kHz7\text{ kHz} tone is above Nyquist; without filtering it aliases to fsf=107=3 kHz|f_s - f| = |10-7| = 3\text{ kHz}, appearing as a false in-band tone. (2 — reasoning + value)

(d) Averaging MM oversampled samples reduces quantisation noise; effective resolution gain is 12log2M\tfrac12\log_2 M bits, i.e. 1 extra bit per 4× oversampling (equivalently ~3 dB SNR per octave / 6 dB per bit). (2)

Question 2 (12)

(a) Lower ID = higher priority. Dominant bit = 0, recessive = 1; a node sending recessive but reading dominant loses.

  • A=0x1A3 = 100 1010 0011, B=0x1A0 = 100 1010 0000, C=0x0F7 = 000 1111 0111.
  • Bit 10 (MSB): A=1, B=1, C=0 → C dominant, A and B lose here. C wins. (rule 2, bitwise trace 2, winner 1)

(b) Bit time =1/500,000=2 μs=2000 ns= 1/500{,}000 = 2\ \mu s = 2000\text{ ns}. (2) One-way propagation =40 m×5 ns/m=200 ns= 40\text{ m}\times5\text{ ns/m}=200\text{ ns}; round trip =400 ns=400\text{ ns}, well within the 2000 ns2000\text{ ns} bit time (arbitration needs the bit to settle bus-wide within one bit) → feasible. (2)

(c) Any two of: bit stuffing, CRC (15-bit), frame check, ACK slot, form check. (2) Aerospace/automotive favour: deterministic priority arbitration (non-destructive), strong multi-layer error detection, automatic retransmission, multi-master robustness. (1)

Question 3 (12)

(a)

xTaskCreate(vWorker, "worker", 256, NULL, 3, NULL);
void vWorker(void *pv){ for(;;){ /* body */ } }

(call correct 2, skeleton with infinite loop 2)

(b)

SemaphoreHandle_t sem;   // xSemaphoreCreateBinary()
void ADC_IRQHandler(void){
  BaseType_t hp = pdFALSE;
  xSemaphoreGiveFromISR(sem, &hp);
  portYIELD_FROM_ISR(hp);
}
void vWorker(void *pv){
  for(;;){ if(xSemaphoreTake(sem, portMAX_DELAY)==pdTRUE){ /* process */ } }
}

(FromISR give 2, portYIELD_FROM_ISR 1, blocking Take with portMAX_DELAY 2)

(c) A semaphore/queue lets the task block (0% CPU while idle) and gives deterministic wakeup + priority-correct scheduling, avoiding busy-wait CPU waste, lost updates and race conditions of an unsynchronised flag; queues also carry data safely across the ISR/task boundary. (3)

Question 4 (10)

(a) Priority inversion: a high-priority task is blocked waiting on a resource held by a lower-priority task. (2) Sequence: L takes mutex → H preempts, tries to take mutex, blocks → M (higher than L, no mutex need) preempts L and runs indefinitely → L never runs to release, so H is blocked for an unbounded time driven by M. (3)

(b) Priority inheritance: while H is blocked on the mutex held by L, L is temporarily raised to H's priority, so M cannot preempt L; L finishes and releases quickly, bounding H's blocking to L's critical-section length. (3)

(c) Priority ceiling assigns each mutex a ceiling = max priority of any task that may lock it and enforces it on acquire (prevents deadlock, bounds blocking to one critical section); inheritance only boosts on actual contention. (2)

Question 5 (10)

(a) U=5/20+10/40+20/80=0.25+0.25+0.25=0.75U = 5/20 + 10/40 + 20/80 = 0.25+0.25+0.25 = 0.75. (3)

(b) LL bound: Ubound=n(21/n1)U_{bound}=n(2^{1/n}-1). For n=3n=3: 3(21/31)3(0.2599)=0.77983(2^{1/3}-1)\approx 3(0.2599)=0.7798. Since 0.750.77980.75 \le 0.7798, the sufficient test passes (schedulable under RMS). (4) (Note: the paper's premise "fails" is a trap — correct answer states it actually passes; award full marks for the correct computed comparison.)

(c) RTA computes each task's worst-case response time Ri=Ci+jhp(i)Ri/TjCjR_i = C_i + \sum_{j\in hp(i)}\lceil R_i/T_j\rceil C_j iteratively and checks RiTiR_i \le T_i — exact, not just sufficient. (2) WCET must include cache/pipeline effects, interrupt/blocking, worst path — not just the observed value of one stopwatch run, which may miss the worst execution path. (1)

Question 6 (6)

(a) Three identical modules process the same input; a majority voter outputs the value agreed by ≥2. (1) Boolean 2-of-3: V=ab+bc+caV = ab + bc + ca. (2)

(b) Fail-safe: on fault the system moves to a known safe state (e.g. train brakes engage / thrust cut). Fail-operational: system continues to function despite fault (e.g. redundant flight control keeps aircraft controllable). (3)

[
{"claim":"12-bit LSB voltage = 3.3/4096","code":"lsb = Rational(33,10)/4096; result = abs(float(lsb)-0.00080566)<1e-6"},
{"claim":"7kHz tone aliases to 3kHz at fs=10kHz","code":"fs=10; f=7; alias=abs(fs-f); result = alias==3"},
{"claim":"Total utilisation U = 0.75","code":"U=Rational(5,20)+Rational(10,40)+Rational(20,80); result = U==Rational(3,4)"},
{"claim":"LL bound n=3 ~0.7798 and U<=bound","code":"import sympy as sp; b=3*(2**sp.Rational(1,3)-1); result = (sp.Rational(3,4) <= b) and abs(float(b)-0.779763)<1e-4"},
{"claim":"CAN 500kbit/s bit time = 2us","code":"bt=1/sp.Integer(500000); result = bt==sp.Rational(1,500000) and abs(float(bt)-2e-6)<1e-12"},
{"claim":"2-of-3 majority voter truth: ab+bc+ca equals majority","code":"from sympy.logic.boolalg import And,Or; from sympy import symbols; a,b,c=symbols('a b c'); expr=Or(And(a,b),And(b,c),And(c,a)); vals={(0,0,0):False,(1,1,0):True,(1,0,0):False,(1,1,1):True}; result = all(bool(expr.subs({a:x,b:y,c:z}))==v for (x,y,z),v in vals.items())"}
]