Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

EE3220 Class Quiz #3 (Closed Book) Time Limit = 60 minutes Revision 1.

Name: _____________________________
Student ID: _____________________________

SECTION 1: SHORT QUESTIONS (36/100 points)

1. A microcontroller PWM signal is used to drive the MOSFET of a buck (step-down) power converter. The
PWM period is 255us with 255 PWM steps.

At 5V output voltage, the PWM on-time is 100us and the PWM off-time is 155us. (6 points)

What is the MOSFET switching frequency (in Hz)? 1/(255us) = 3.92kHz (1 pt)
______________________________________

What is the duty cycle at 5V (in %)? 100us/(255us) = 39.2% (1 pt)


______________________________________

What is the duty cycle at 2.5V (in %)? 39.2% x 2.5V/(5V) = 19.6% (2 pt)
______________________________________

What is the maximum output voltage (in V)? 5V x 255 / 100 = 12.75V (2 pt)
______________________________________

2. Which of the following statements related to Asynchronous Communication are True (T)? (4 points)
• Asynchronous Communication is always faster than Synchronous Communication. T / F
• Asynchronous Communication is always slower than Synchronous Communication. T / F
• Modern DRAM (DDR4) uses Asynchronous Communication. T/F
• UART uses Asynchronous Communication. T/F

3. In a Cortex-M4 embedded system, an EXC_RETURN value (e.g. 0xFFFFFFF9) is loaded into the link
register (R14) during an interrupt service routine (ISR). Check if the following statements are True (T) or
False (F). (4 points)
• EXC_RETURN specifies if the interrupted routine is using the main stack pointer. T/F
• The loading of EXC_RETURN to R14 is done is software. T/F
• The ISR must check the EXC_RETURN value in software. T/F
• The original R14 value is saved before EXC_RETURN value is loaded. T/F

4. In a Cortex-M4 embedded system, a certain hardware interrupt may be disabled by using either
NVIC_DisableIRQ(IRQ_num) or __disable_irq() CMSIS API?

What are the differences between these two CMSIS API? (4 points)
The first API disables a specific maskable interrupts, meaning that other maskable
_______________________________________________________________________________________
interrupts may still be active.
_______________________________________________________________________________________
The second API disables all maskable interrupts.
_______________________________________________________________________________________

_______________________________________________________________________________________

Page 1 of 6
EE3220 Class Quiz #3 (Closed Book) Time Limit = 60 minutes Revision 1.0

5. In an ARM SOC, the same reset vector is used for cold boot (power-on reset) and warm boot (pushing reset
button). Check if the following statements are True (T) or False (F). (4 points)

• Registers are not saved in a warm reset. T/F

• Among all interrupts, the reset interrupt has the highest priority. T/F

• The reset interrupt cannot be disabled. T/F

• The software cannot distinguish between cold boot and warm boot. T/F

6. The C programming language is used in many embedded systems. Check if the following statements are
True (T) or False (F). (4 points)

• Unlike Assembly, C does not support a direct branch or a jump. T/F

• Unlike Assembly, a C runtime library is usually needed to run C programs. T/F

• C macros may optionally perform type check. T/F

• All C comments are removed in the C preprocessing stage. T/F

7. A linker is called after C compilation. Describe what a linker does. (4 points)

Check if any library files are needed and include them. Assign physical addresses in
_______________________________________________________________________________________

object codes. Cross reference all object files. Check for any missing references. Check
_______________________________________________________________________________________
for any memory issue. Create a single linked file.
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

8. In an embedded system, a certain C program may occasionally crash. There is an integer array (with 512
elements) declared inside the main() function. The problem goes away if the array is declared as “static”
instead of “auto”. Give a possible explanation. Separately, the same integer array may be implemented
using “malloc”. Explain if this is a good idea. (6 points)
Declaring an array within main function or outside main function should not make any
_______________________________________________________________________________________
difference unless the stack segment runs out of space.
_______________________________________________________________________________________
The stack segment size might be too small.
_______________________________________________________________________________________

As stack and heap usually share the same memory space, the suggested solution is
_______________________________________________________________________________________

ineffective.
_______________________________________________________________________________________

_______________________________________________________________________________________

Page 2 of 6
EE3220 Class Quiz #3 (Closed Book) Time Limit = 60 minutes Revision 1.0

SECTION 2: LONG QUESTIONS (64/100 points)

9. Assume a Cortex-M4 processor is running in Thread Mode with its register and stack values listed in Table 9.1.

An interrupt occurs, which prompts the processor to save its registers (R0, R1, R2, R3, R12, LR, PC, xPSR) to its

stack. Assume the interrupt vector is located at 0x0000B000 and the EXC_RETURN value is 0xFFFFFFFD.

Write the new register and stack values in the beginning of the interrupt service routine. Hints: a lower register is

stored to a lower stack address and a higher register is stored to a higher stack address. (16 points)

Table 9.1: Before Interrupt Occurs

R0 0x0 Address Content Address Content


R1 0x1 0x20000FE0 0x100 0xB0001FE0 0x200
R2 0x2 0x20000FE4 0x101 0xB0001FE4 0x201
R3 0x3 0x20000FE8 0x102 0xB0001FE8 0x202
R4 0x4 0x20000FEC 0x103 0xB0001FEC 0x203
R5 0x5 0x20000FF0 0x104 0xB0001FF0 0x204
R6 0x6 0x20000FF4 0x105 0xB0001FF4 0x205
R7 0x7 0x20000FF8 0x106 0xB0001FF8 0x206
R8 0x8 0x20000FFC 0x107 0xB0001FFC 0x207
R9 0x9 0x20001000 0x108 0xB0002000 0x208
R10 0x10 0x20001004 0x109 0xB0002004 0x209
R11 0x11 0x20001008 0x110 0xB0002008 0x210
R12 0x12 0x2000100C 0x111 0xB000200C 0x211
R13 (SP) 0xB0002000 0x20001010 0x112 0xB0002010 0x212
R14 (LR) 0x0000A000 0x20001014 0x113 0xB0002014 0x213
R15 (PC) 0x0000A800 0x20001018 0x114 0xB0002018 0x214
xPSR 0x21000000 0x2000101C 0x115 0xB000201C 0x215
MSP 0x20001000 0x20001020 0x116 0xB0002020 0x216
PSP 0xB0002000 0x20001024 0x117 0xB0002024 0x217

Beginning of the Interrupt Service Routine (ISR)

R0 0x0 Address Content Address Content


R1 0x1 0x20000FE0 0x0 0xB0001FE0 0x200
R2 0x2 0x20000FE4 0x1 0xB0001FE4 0x201
R3 0x3 0x20000FE8 0x2 0xB0001FE8 0x202
R4 0x4 0x20000FEC 0x3 0xB0001FEC 0x203
R5 0x5 0x20000FF0 0x12 0xB0001FF0 0x204
R6 0x6 0x20000FF4 0x0000A000 0xB0001FF4 0x205
R7 0x7 0x20000FF8 0x0000A800 0xB0001FF8 0x206
R8 0x8 0x20000FFC 0x21000000 0xB0001FFC 0x207
R9 0x9 0x20001000 0x108 0xB0002000 0x208
R10 0x10 0x20001004 0x109 0xB0002004 0x209
R11 0x11 0x20001008 0x110 0xB0002008 0x210
R12 0x12 0x2000100C 0x111 0xB000200C 0x211
R13 (SP) 0x20000FE0 0x20001010 0x112 0xB0002010 0x212
R14 (LR) 0xFFFFFFFD 0x20001014 0x113 0xB0002014 0x213
R15 (PC) 0x0000B000 0x20001018 0x114 0xB0002018 0x214
xPSR 0x21000000 0x2000101C 0x115 0xB000201C 0x215
MSP 0x20000FE0 0x20001020 0x116 0xB0002020 0x216
PSP 0xB0002000 0x20001024 0x117 0xB0002024 0x217

Page 3 of 6
EE3220 Class Quiz #3 (Closed Book) Time Limit = 60 minutes Revision 1.0

10. A “critical section” is often used in an embedded system. Explain when and why a “critical section” is used.

Describe the potential issues when there are too many “critical sections.”

_______________________________________________________________________________________
Critical section is used to support atomic operation, avoiding race conditions
and potential data inconsistency among multiple threads. (4 points)
_______________________________________________________________________________________

Too many critical sections can cause performance degradation, potential


_______________________________________________________________________________________
system deadlocks, priority inversion, resource under-utilization. (4 points)
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

Two different students implement two different “critical sections” (Implementation 1 and Implementation 2).

Discuss their differences. (16 points)

Implementation 1 Implementation 2

void getDateTime(TimeType* ptr) { void getDateTime(TimeType* ptr) {


uint32_t m; __disable_irq();
m = __get_PRIMASK(); ptr->hour = current_time.hour;
__disable_irq(); ptr->minute = current_time.minute;
ptr->hour = current_time.hour; ptr->second = current_time.second;
ptr->minute = current_time.minute; __enable_irq();
ptr->second = current_time.second; }
__set_PRIMASK(m);
}

Implementation 1 is preferred.
_______________________________________________________________________________________
Implementation 2 may inadvertently enable interrupts.
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

Page 4 of 6
EE3220 Class Quiz #3 (Closed Book) Time Limit = 60 minutes Revision 1.0

11. Convert the following “factorial” assembly function to an equivalent “factorial” C function. How many bytes are
pushed onto stack in each recursive function call. How many bytes are pushed o stack when factorial(100)

is called. Explain why recursive functions are seldom used in an embedded system. (16 points)

; Argument: n is passed in register r1


; Returns: Result is returned in register r0
factorial:
push {lr}
cmp r1, #0
beq base_case
push {r1}
sub r1, r1, #1
bl factorial
pop {r1}
mul r0, r0, r1
pop {lr}
bx lr
base_case:
mov r0, #1
pop {lr}
bx lr

int factorial (int n) {


If (n == 0)
return 1;
return n*factorial(n-1);
}

100 x 8 bytes + 4 bytes (last step) = 804 bytes.

It is difficult to design a proper stack size, and difficult to debug any related bug.

Page 5 of 6
EE3220 Class Quiz #3 (Closed Book) Time Limit = 60 minutes Revision 1.0

12. The “RBIT” instruction is used to reverse the bits in a word, and the “REV” instruction is used to reverse the byte

order in a word. What are the applications of these two instructions? (6 points)

Data communication with another system with a different endianness (e.g. Internet).
_______________________________________________________________________________________
RBIT can be used for bit data transmission (like UART). REV can be used for byte data
_______________________________________________________________________________________
transmission (like Internet).
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

What are the values of R0, R1, R2 after the following operations? Show your work. (10 points)

MOV r0, #0x5678


MOVT r0, #0x4321
RBIT r1, r0
REV r2, r1

R0: 0x43215678
_______________________________________________________________________________________

R1: 0x1E6A8432
_______________________________________________________________________________________

_______________________________________________________________________________________
R2: 0x32846A1E
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

Page 6 of 6

You might also like