EL648 – Real Time Embedded Systems
Real Time Embedded Systems
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
EL648 – Real Time Embedded Systems
Instructions: Answer all questions on this paper. You may use any reference materials from class or
from our class websites and/or reference sheets.
Question 1:
Although GPIO is not specifically part of this exam, we spent a significant amount of time in class
discussing how to read and write memory using both C and assembly. Since our architecture uses
memory mapped I/O, setting up the GPIO registers is simply reading and writing the appropriate
memory locations. The following algorithm can be used for our controller to do a block GPIO write,
meaning writing all port pins (15 in total) simultaneously, for any port (say PORTA).
PORTA has a base address of 0x40020000
A. Set each pin in the MODER register to general purpose output mode
B. Set each pin in the OTYPER register to output push-pull
C. Set each pin in the PUPDR register to 0, meaning no pull up or down resistor
D. Set the ODR register bits to a 1 or 0, depending on if the pin is turned on or off.
a. Write a C function:
uint32_t BlockWritePortA(uint16_t PinVals) {
//Code Here
}
PinVals is a 16 bit number with 1’s in positions to turn “on” and 0’s in the pin positions to turn
“off”. The function should implement algorithms parts A., B., C. and D. described above and
return the value of the ODR register above. Note, the addresses of the registers (memory) are
the Base Address + Offset as indicated above.
b. Write an ARM assembly function called “_BlockWritePortA” that implements part A
above.
NOTE: Be careful how you use LDR, as there are limits to the “mem” parameter!
.globl _BlockWritePortA
.syntax unified
_BlockWritePortA
;
; Code Here
;
bx lr
c. Write the short C program that calls the ARM Assembly function _BlockWritePortA in its
main();
Question 1 Solution:
Question 2:
Consider the following ARM assembly code segment.
a. Accurately comment each line of code
b. Describe what parameters r0 and r1 (passed into the function) are used for.
c. What are each of the local variables r4-r8 used for?
d. What is the purpose of this function?
e. Explain in detail the specific purpose of “stmfd” and “ldmfd” in this function.