In embedded firmware, hardware peripherals must never be accessed unless their clock is enabled.
Accessing a peripheral before enabling its clock can result in bus faults, undefined behavior, or system resets.
Your task is to encode this rule directly into C++ class relationships using dependency-aware composition, such that invalid usage is impossible by design.
The following conditions must be enforced structurally, not by comments or runtime checks:
Any solution that violates these rules is incorrect, even if it compiles.
Program Flow
Driver object inside a local scopeInput
Two space-separated integers:
offset — register offsetvalue — value to writeOutput
The program must print exactly the following lines, in order:
Clock enabled
Peripheral ready
Driver started
Clocked write: <offset> <value>
Driver stopped
Peripheral stopped
Clock disabledConstraints
offset and value are non-negative integers0 ≤ offset ≤ 10240 ≤ value ≤ 65535ClockController must not be created in main()Peripheral must not create or own a clockPeripheral must depend on an existing clock instance
Input
8 55
Expected Output
Clock enabled Peripheral ready Driver started Clocked write: 8 55 Driver stopped Peripheral stopped Clock disabled