Exam 1. Date: September 28 th, 2016

EE319K Fall 2016 Exam 1 Page 1 Exam 1 Date: ​September 28​th​, 2016 UT EID: _______________________________________ Printed Name: ______________...
Author: Cory Shelton
6 downloads 0 Views 376KB Size
EE319K Fall 2016 Exam 1

Page 1

Exam 1

Date: ​September 28​th​, 2016

UT EID:

_______________________________________

Printed Name: _________________________________ ______________________________________ Last,

First

Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat on this exam: Signature:



_______________________________________ Instructions: ● Closed book and closed notes. No books, no papers, no data sheets (other than the last two pages of this Exam) ● No devices other than pencil, pen, eraser (no calculators, no electronic devices), please turn cell phones off. ● Please be sure that your answers to all questions (and all supporting work that is required) are contained in the space (boxes) provided. ​Anything outside the boxes/blanks will be ignored in grading. You may use the back of the sheets for scratch work. ● You have 90 minutes, so allocate your time accordingly. ● For all questions, unless otherwise stated, find the most efficient (time, resources) solution. ● Unless otherwise stated, make all I/O accesses friendly. ● Please read the entire exam before starting.

Problem 1

30

Problem 2

10

Problem 3

15

Problem 4

20

Problem 5

25

Total

100

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 2

Q1) [Circuits + I/O Interfacing – 30 points] [10 pts] ​Design a circuit that interfaces a positive logic LED to the Port B pin 6 and a negative logic input switch to Port B pin 7. Assume that the micro-controller’s output voltage high is 3.3V. The LED's operating point is 2.0V at 10mA. The V​OL of the 7406 driver is 0.6V. Pick resistors appropriately and assume you have 5V, 3.3V, and ground to which you can connect your components. The symbols for each part are given below for your convenience – use the minimum number of components to construct the interfaced system. You may draw additional components if necessary. Show calculations for resistor value(s).

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 3

[10 pts] ​You must write firmware for the embedded system to run the device above. In addition to the specifications listed above in the previous part, logic will be input on Port B pins 4 and 5. Pin 4 will serve as an emergency shut down for the system. If a logic 0 is detected, the system should shut down. Pin 5 receives the negative logic state that the LED should be set to. Write the port initialization for this system (including the logic from the previous part). Unfriendly code will receive half credit. Some registers that could be used are listed below:

SYCTL_RCGCGPIO_R GPIO_PORTB_DATA_R GPIO_PORTB_DIR_R GPIO_PORTB_AFSEL_R GPIO_PORTB_PUR_R GPIO_PORTB_PDR_R GPIO_PORTB_DEN_R

EQU EQU EQU EQU EQU EQU EQU

0x400FE608 0x400053FC 0x40005400 0x40005420 0x40005510 0x40005600 0x4000551C

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 4

[10 pts] ​Now, instead of simply turning the LED on and off, you are to implement a program “Adjust_Duty_Cycle.asm” that controls the brightness of the LED. Complete the program below (in Assembly). Remember that PE6 is a positive logic output to the LED. PE5 (input) will decide whether the LED increases or decreases in brightness. You may write more than one line per part. Write your code on the following page. Do not write code for any line with “​…;​” Provide your answers on the next page.

LED_MAX_TIME_ON EQU 0x0A LED_MIN_TIME_OFF EQU 0x00 WAIT_1MS_COUNT EQU 0x00004FFF … ; EQU statements from previous part and other pseudo-ops here Init … ; … ; … ; … ; … ;

Initialization from previous part R0-current time on of the LED, init to 0 R1-current time off of the LED, init to 10 R2-current state of the LED brightness, 1 is increasing, 0 is decreasing, init to 0

B MainLoop; End Initialization MainLoop _____________; 1) Load R3 with PE5 input and set branch condition BEQ Increase_Brightness BNE Decrease_Brightness CheckShutDown _____________; BEQ TurnOff B MainLoop Increase_Brightness ​ ​; ​ ​; ​ ​; BL Wait ; B CheckShutDown Decrease_Brightness; … ; BL Wait B CheckShutDown Wait; ​

​ … ; … ; BX LR;

​; ​ ;

2) Detect emergency shutdown

3) to increase the duty cycle you have to check current time on, if ​less than ​max_time_on, increase time on by 1 and decrease time on by 1 if ​equal​, do not change either value. Code already written

Assume WAIT_1MS_COUNT is for 4 cycle loop 4) wait 1ms for each value in current LED time on 5) turn LED off Code written. Waits 1ms for each value in current LED time off turns LED on

TurnOff ALIGN END Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

1)

2)

3)

4)

5)

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

Page 5

EE319K Fall 2016 Exam 1

Page 6

Q2) [Delay/SysTick – 10 points] You are assigned to a project where you have to work on a code module that samples Sensor HJKL at a frequency of 10 Hz. The microcontroller itself will be running at a max bus clock frequency of 80 MHz. You were hired to replace an employee who abruptly decided to quit and start a rock climbing and yoga studio. They left you with some hastily written code for the ​hjklModule()​function before they left. Here is a snippet of the codebase for the device:

void hjklModule(void){ unsigned int numIter = _________; // TODO: calculate this ​(a) for(unsigned int i = 0; i < numIter; i++ ){} // delay loop​(b) sampleSensor( SENSOR_HJKL ); } ... int main(void){ while(1){ // main loop to execute code for the modules hjklModule(); } }

[5 pts] ​Looks like you need to address that TODO. After looking at the disassembly, you assess that the for loop on line ​(b) takes 10 cycles for each iteration. Assuming that we’re running at the max bus clock frequency and that the amount of time the other code takes to execute is negligible, what should the value at ​(a)​ in the code be? Show your work. Remember that the sensor is being sampled at 10 Hz.

[5 pts] ​Write down a generic formula to determine ​N, the value for ​numIter​, based on any arbitrary clock frequency ​f, the target delay time ​t, and delay loop cycle count ​c.

N=

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 7

Q3) [Logic – 15 points] ​You are tasked with implementing an algorithm that can convert data between Big Endian and Little Endian. [2 pts] ​Fill in the boxes with Big Endian and Little Endian formats for ​0xDEADBEAF 0x0

0x0

Big Endian

Little Endian

[3 pts] ​You are given Machine X, an unknown machine to you. You need to figure out if Machine X implements Big Endian, Little Endian or something else. Devise a clever algorithm. You must draw a flowchart of your algorithm, using all the proper symbols. No C & assembly. Flow chart will be accepted.

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 8

[10 pts] ​Write a ​ASM ​subroutine that converts an integer array from Little Endian to Big Endian formats. The subroutine receives one argument: The base address of the array that containing the Little Endian values. The input array’s length is always 16 and its precision is always 4 bytes. The subroutine will convert all of the elements from the input array into a return array, whose base address will be returned by the subroutine. The caller subroutine assumes AAPCS so the callee subroutine must therefore use AAPCS. Implement your subroutine. Comment your code (points will be deducted otherwise).

; define any data structures you require below here

; subroutine code below here

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 9

Q4) [Stack – 20 points] ​The following program finds the maximum of 4 values passed through the stack.

; Caller, uses stack for passing parameters MOV

R0,#12

MOV

R1,#5

MOV

R2,#22

; Callee, receives 4 signed numbers on the stack and puts back only the maximum number on the stack numM RN 1 ; current number max RN 2 ; maximum so far count RN 0 ; how many elements

MOV

R3,#7

Max4

PUSH {R0-R3} ​;(Q3a) BL

Max4

POP {R3}

;​(Q3d)

Again

Next

POP MOV POP CMP BLT MOV SUBS BNE PUSH BX

{max} count,#3 {numM} numM, max Next max, numM count,#1 Again {max} LR

;​(Q3b)

;​(Q3c)

[4 pts] ​Instead of using POP instructions to access elements stored on the stack (e.g. ​POP {numM}​), you are told to provide the capability to access the ​Nth element from the top of the stack (i.e., where SP is pointing) without changing the stack pointer location. Write an assembly subroutine that can do this. ​You must use the least number of instructions possible for full score​.

; input -- R0 contains the Nth element you have to return ; output -- R0 should contain the Nth element on return ReturnNthStackElement

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 10

[16 pts] ​For the given max finding code, show the state of the stack at each of the locations indicated (e.g. Q3a) -- just after that instruction’s execution. The “Initial SP” points to the stack just prior to (Q3a). (Q3a)

(Q3b)

R0 = ______________

R2 = ______________

R0 = ______________

R2 = ______________

R1 = ______________

R3 = ______________

R1 = ______________

R3 = ______________

SP = ______________

SP = ______________

(Q3c)

(Q3d)

R0 = ______________

R2 = ______________

R0 = ______________

R2 = ______________

R1 = ______________

R3 = ______________

R1 = ______________

R3 = ______________

SP = ______________

SP = ______________

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 11

Q5) [C Basics – 25 points] [5 pts] ​GIven an ​int​ array and the array length, fix the following code that wants to increment all the elements in the array by 1. There are 5 errors.

int x[10]; void functionFoo(void) { int index = 1 while(index if Z==1 or N!=V Less than or equal, signed ≤ indirect to location specified by Rm to subroutine at label to subroutine indirect specified by Rm ; enable interrupts (I=0) ; disable interrupts (I=1)

Logical instructions AND{S} {Rd,} Rn, ; Rd=Rn&op2 ORR{S} {Rd,} Rn, ; Rd=Rn|op2

(op2 is 32 bits) (op2 is 32 bits)

Prof. Janapa Reddi, Ce Wei, Schuyler Christensen, Brandon Nguyen September 28th​ ​ , 2016 3:00pm—4:30pm

EE319K Fall 2016 Exam 1

Page 15

EOR{S} {Rd,} Rn, ; Rd=Rn^op2 (op2 is 32 bits) BIC{S} {Rd,} Rn, ; Rd=Rn&(~op2) (op2 is 32 bits) ORN{S} {Rd,} Rn, ; Rd=Rn|(~op2) (op2 is 32 bits) LSR{S} Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR{S} Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR{S} Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR{S} Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL{S} Rd, Rm, Rs ; shift left Rd=Rm