0
0
Embedded Cprogramming~20 mins

Clock gating for power saving in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Clock Gating Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this clock gating simulation code?

Consider the following embedded C code simulating clock gating behavior. What will be printed when this code runs?

Embedded C
#include <stdio.h>

int main() {
    int clock_enabled = 0;
    int power_consumption = 100; // base power

    if (clock_enabled) {
        power_consumption += 50;
        printf("Clock is enabled. Power consumption: %d\n", power_consumption);
    } else {
        printf("Clock is gated. Power consumption: %d\n", power_consumption);
    }
    return 0;
}
AClock is gated. Power consumption: 150
BClock is enabled. Power consumption: 150
CClock is gated. Power consumption: 100
DClock is enabled. Power consumption: 100
Attempts:
2 left
💡 Hint

Check the value of clock_enabled and how it affects power consumption.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes clock gating?

Choose the statement that correctly explains the purpose of clock gating in embedded systems.

AClock gating duplicates the clock signal to multiple modules for synchronization.
BClock gating disables the clock signal to unused modules to reduce power consumption.
CClock gating permanently turns off the power supply to a module.
DClock gating increases the clock frequency to improve performance.
Attempts:
2 left
💡 Hint

Think about how clock gating helps save power without turning off the entire module.

🔧 Debug
advanced
2:00remaining
Identify the error in this clock gating code snippet

What error will this embedded C code produce when compiled?

Embedded C
void clock_gate(int enable) {
    if enable {
        // Enable clock
    } else {
        // Disable clock
    }
}

int main() {
    clock_gate(1);
    return 0;
}
ASyntaxError: Missing parentheses in if statement
BTypeError: Invalid argument type for clock_gate
CRuntimeError: Infinite loop detected
DNo error, code compiles and runs
Attempts:
2 left
💡 Hint

Check the syntax of the if statement in C.

🚀 Application
advanced
1:30remaining
How many clock gating states are possible in this code?

Given this code controlling clock gating for two modules, how many unique clock gating states can the system have?

Embedded C
typedef struct {
    int module1_clock;
    int module2_clock;
} ClockControl;

int main() {
    ClockControl cc = {0, 0};
    // module1_clock and module2_clock can be 0 (gated) or 1 (enabled)
    return 0;
}
A4
B3
C2
D1
Attempts:
2 left
💡 Hint

Each module clock can be either gated or enabled independently.

Predict Output
expert
2:30remaining
What is the output of this clock gating control function?

Analyze the following embedded C code that simulates clock gating control. What will be printed?

Embedded C
#include <stdio.h>

void clock_gate(int *clock, int enable) {
    *clock = enable ? 1 : 0;
}

int main() {
    int clock_signal = 0;
    clock_gate(&clock_signal, 1);
    clock_gate(&clock_signal, 0);
    if (clock_signal) {
        printf("Clock enabled\n");
    } else {
        printf("Clock gated\n");
    }
    return 0;
}
AClock enabled
BCompilation error
CNo output
DClock gated
Attempts:
2 left
💡 Hint

Trace the changes to clock_signal after each function call.