BEST代写-线上留学生作业代写 & 论文代写专家


C语言代写|EL648 – Real Time Embedded Systems

C语言代写|EL648 – Real Time Embedded Systems



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

NOTE: Be careful how you use LDR, as there are limits to the “mem” parameter!

.globl _BlockWritePortA
.syntax unified
; Code Here
bx lr

c. Write the short C program that calls the ARM Assembly function _BlockWritePortA in its

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.

.globl _MyFunc
stmfd sp!, {r4, r5, r6, r7, r8, lr}
cmp r1, #1
ble end_outer
sub r5, r1, #1
mov r4, r0
mov r6, #0
ldr r7, [r4], 4
ldr r8, [r4]
cmp r7, r8
ble no_go
mov r6, #1
sub r4, r4, 4
swp r8, r8, [r4]
str r8, [r4, 4]!
subs r5, r5, #1
bne loop_start
cmp r6, #0
beq end_outer
mov r6, #0
mov r4, r0
sub r5, r1, #1
b loop_start
ldmfd sp!, {r4, r5, r6, r7, r8, pc}