0
0
Embedded Cprogramming~10 mins

Sleep modes overview 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 enter the CPU into idle sleep mode.

Embedded C
void enter_sleep_mode() {
    __asm__("[1]");
}
Drag options to blanks, or click blank then click option'
Asleep
Bhalt
Cnop
Dwfi
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nop' which does nothing but does not sleep.
Using 'halt' which may stop the CPU but is not standard for idle sleep.
2fill in blank
medium

Complete the code to enable deep sleep mode by setting the SLEEPDEEP bit.

Embedded C
void enable_deep_sleep() {
    SCB->SCR |= [1];
}
Drag options to blanks, or click blank then click option'
ASCB_SCR_SLEEPDEEP_Msk
BSCB_SCR_SLEEPONEXIT_Msk
CSCB_SCR_SEVONPEND_Msk
DSCB_SCR_SLEEP_Msk
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong bit mask like SLEEPONEXIT which controls sleep on ISR exit.
Using a non-existent mask like SLEEP_Msk.
3fill in blank
hard

Fix the error in the code to correctly clear the SLEEPDEEP bit to exit deep sleep mode.

Embedded C
void disable_deep_sleep() {
    SCB->SCR &= ~[1];
}
Drag options to blanks, or click blank then click option'
ASCB_SCR_SLEEP_Msk
BSCB_SCR_SLEEPDEEP_Msk
CSCB_SCR_SEVONPEND_Msk
DSCB_SCR_SLEEPONEXIT_Msk
Attempts:
3 left
💡 Hint
Common Mistakes
Clearing the wrong bit like SLEEPONEXIT.
Using the bit mask without negation.
4fill in blank
hard

Fill both blanks to create a dictionary mapping sleep mode names to their descriptions.

Embedded C
const char* sleep_modes[] = {"Idle", "[1]", "[2]"};
Drag options to blanks, or click blank then click option'
AStandby
BHibernate
CSleep
DDeep
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Sleep' which is generic and not a specific mode.
Using 'Deep' alone without proper context.
5fill in blank
hard

Fill all three blanks to complete the function that sets the sleep mode and enters sleep.

Embedded C
void set_sleep_mode_and_enter(int mode) {
    switch(mode) {
        case 0:
            SCB->SCR &= ~[1];
            break;
        case 1:
            SCB->SCR |= [2];
            break;
        default:
            return;
    }
    __asm__("[3]");
}
Drag options to blanks, or click blank then click option'
ASCB_SCR_SLEEPDEEP_Msk
BSCB_SCR_SLEEPONEXIT_Msk
Cwfi
Dnop
Attempts:
3 left
💡 Hint
Common Mistakes
Using different bit masks for clearing and setting.
Using 'nop' instead of 'wfi' to enter sleep.