Operating systems, software and translators · A level · OCR H446 1.2.1, AQA 7517 4.6.1.4, Eduqas A500QS 2.6 · about 35 min
Hiding the hardware, managing resources, booting from the BIOS, and a driver table for the robot.
[1 mark]What does it mean to say the operating system hides the complexity of the hardware?
[1 mark]Why are device drivers needed?
[1 mark]Put these stages of starting a computer in order.
Number the lines 1 to 4 to put them in the right order.
The BIOS loads the bootstrap loader from the boot device into RAMThe bootloader loads the operating system kernel into RAM and starts itThe power-on self-test checks the essential hardwareThe processor starts running the BIOS from non-volatile memory[1 mark]Why must the BIOS be stored in non-volatile memory?
[1 mark]What does this program print?
drivers = {"lamp": lambda v: f"lamp at {v}%", "fan": lambda v: f"fan at {v} rpm"}
for device, value in [("fan", 900), ("lamp", 40), ("door", 1)]:
if device in drivers:
print(drivers[device](value))
else:
print("no driver:", device)Build a tiny operating system layer for the robot. Write three driver functions, each taking one argument value:
- a driver for "led": value is a colour name string; it sets the LED to that colour;
- a driver for "piezo": value is a frequency in hertz (an integer from 100 to 10000); it plays that note for 0.2 seconds;
- a driver for "motor": value is a distance in centimetres (a positive integer); it drives forward that far at speed 50.
Put them in a dictionary called drivers, keyed by the device names "led", "piezo" and "motor". Then write the system call syscall(device, value). If device is a key in drivers, it calls that driver with value, prints ok: <device> <value>, and returns True. Otherwise it prints error: no driver for <device>, does nothing else, and returns False. Do not test the device name with ==: the table is the whole point.
Finally, call syscall for each (device, value) pair in requests, in order. The robot should end 20 cm ahead with a green LED.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
requests = [("led", "blue"), ("piezo", 880), ("motor", 20), ("camera", "on"), ("led", "green")]Plan your program here, then type it in and press Run.
"turn" that turns right by value degrees, and a request that uses it. Which part of your program had to change, and which did not?syscall refuse a "motor" request when distance() shows a wall closer than the distance asked for. Is that check better in the driver or in the system call? Why?