0
0
Embedded Cprogramming~10 mins

Clock gating for power saving in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable clock gating for the peripheral.

Embedded C
CLK_CTRL_REG |= [1];  // Enable clock gating
Drag options to blanks, or click blank then click option'
ACLK_GATE_DISABLE
BCLK_GATE_ENABLE
CCLK_ALWAYS_ON
DCLK_RESET
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the disable or reset option instead of enable.
2fill in blank
medium

Complete the code to disable clock gating for the peripheral.

Embedded C
CLK_CTRL_REG &= ~[1];  // Disable clock gating
Drag options to blanks, or click blank then click option'
ACLK_GATE_ENABLE_BIT
BCLK_GATE_ENABLE
CCLK_GATE_ENABLE_MASK
DCLK_GATE_DISABLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using the enable constant instead of the bit mask.
3fill in blank
hard

Fix the error in the clock gating control code.

Embedded C
if ((CLK_CTRL_REG & [1]) == 0) {
    enable_clock_gating();
}
Drag options to blanks, or click blank then click option'
ACLK_GATE_DISABLE_BIT
BCLK_GATE_RESET_BIT
CCLK_GATE_STATUS_BIT
DCLK_GATE_ENABLE_BIT
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the disable or reset bit instead of the enable bit.
4fill in blank
hard

Fill both blanks to create a clock gating control macro.

Embedded C
#define SET_CLOCK_GATING(reg, bit) \
    do { \
        (reg) [1]= (bit); \
    } while(0)

#define CLEAR_CLOCK_GATING(reg, bit) \
    do { \
        (reg) [2]= (bit); \
    } while(0)
Drag options to blanks, or click blank then click option'
A|
B&
C~
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND to set bits or OR to clear bits.
5fill in blank
hard

Fill all three blanks to implement a function that gates clock based on enable flag.

Embedded C
void clock_gate_control(volatile uint32_t *reg, uint32_t bit, bool enable) {
    if (enable) {
        *reg [1]= bit;  // Enable clock gating
    } else {
        *reg [2]= [3] bit;  // Disable clock gating
    }
}
Drag options to blanks, or click blank then click option'
A|=
B&=
C~
D^=
Attempts:
3 left
💡 Hint
Common Mistakes
Using XOR or other operators incorrectly for bit setting/clearing.