Department of Electrical and Computer Engineering, University of Calgary ENCM511...

12
Department of Electrical and Computer Engineering, University of Calgary ENCM511 FINAL EXAM December 18 th , 2012 3 HOURS PLEASE WRITE CLEARLY. USE AN HB GRADE OR SOFTER (DARKER) PENCIL! WHAT CAN’T BE READ WILL MARKED WRONG. CLOSED BOOK EXAM DO NOT BRING ANY UNAUTHORIZED MATERIAL INTO THE EXAM ROOM The student is provided with a copy of the Blackfin reference sheet as part of the exam handout. This sheet includes some 68K code examples. Information on the ARM processor is also provided NO CALCULATORS ARE ALLOWED IN THIS EXAM Attempt all FIVE questions from SECTION A and ONE question from SECTION B. The questions have different marks and difficulty associated with them IF YOU ATTEMPT MORE THAN ONE QUESTION FROM SECTION B, ONLY THE FIRST QUESTION WILL BE MARKED MAXIMUM MARKS AVAILABLE ACROSS 6 QUESTIONS – APPROXIMATELY 100 A hint of the time to spend on each part of a question is given by the relative number of marks associated with that question part. Answer the questions in the space provided on the exam sheet. The space and marks allocated are an indication of the depth of the answer expected. If you were an engineer at work, you would be expected to answer questions by coming quickly to the point. The same is true in this exam. Be careful that you don’t unintentionally waste time writing an extremely lengthy answer giving every known detail about a concept when a short precise answer, PREFERABLE IN POINT FORM, is what is required to fill the 2 or 3 lines provided for the answer. Make sure that you PROVIDE ADEQUATE DOCUMENTATION of code and answers as marks are allocated for this documentation. Follow standard VisualDSP++ compiler / assembler conventions used in this class and recommended safe practices in your coding. Some of the concepts in this course are subjective – meaning that there may be more than one valid answer. Make sure that you support your answer. If the question says – which processor is better Blackfin or ARM in this situation, then answering Blackfin will give you no marks, even if true. Support why that answer is true, preferably with examples in point form. As always, I expect engineers to have a good understanding of where they are doing well in a project and where they are doing poorly. ON THIS PAGE, provide an estimate of the mark you expect for each question, and the total mark for the exam. A bonus of 1/2 mark is given for each estimate within 10% of the actual mark for each question and a bonus of 2 marks for predicting your final exam mark. Section A Attempt all questions Section B Attempt ONE question 1 Blackfin knowledge (12 marks) 6 ENCM511 on ARM or 68K processors (Design) (20 marks) 2 Blackfin assembly code translation from C++ (15 marks) 7 Hardware testing (20 marks) 3 Blackfin interfacing -- Lab 4 SPI interface and J-TAG (15 marks) 8 Design own ENCM511 question and answer it (20 marks) 4 TTCOS knowledge: Loop-the-loop Car controller (C++ Design) (20 marks) 5 Interrupted subroutines (20 marks) TOTAL / 102 SECTION A DO ALL Q1 / 12 Q2 / 15 Q3 / 15 Q4 / 20 Q5 / 20 SECTION B ONLY ONE Q6 / 20 Q7 / 20 Q8 / 20 TOTAL / 102 + bonus of 4 As always, I don’t expect people to know every detail in my course for an A. So as always, 80% is an excellent mark on this final. A > 80% B > 70% C > 60% D > 45% PAGE 1 OF 12

Transcript of Department of Electrical and Computer Engineering, University of Calgary ENCM511...

Page 1: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

Department of Electrical and Computer Engineering, University of Calgary

ENCM511 FINAL EXAM December 18th, 2012 3 HOURS

PLEASE WRITE CLEARLY. USE AN HB GRADE OR SOFTER (DARKER) PENCIL! WHAT CAN’T BE READ WILL MARKED WRONG.

CLOSED BOOK EXAM DO NOT BRING ANY UNAUTHORIZED MATERIAL

INTO THE EXAM ROOM The student is provided with a copy of the Blackfin reference sheet as

part of the exam handout. This sheet includes some 68K code examples. Information on the ARM processor is also provided

NO CALCULATORS ARE ALLOWED IN THIS EXAM

Attempt all FIVE questions from SECTION A and ONE question from SECTION B.

The questions have different marks and difficulty associated with them

IF YOU ATTEMPT MORE THAN ONE QUESTION FROM SECTION B, ONLY THE FIRST QUESTION WILL BE MARKED

MAXIMUM MARKS AVAILABLE ACROSS 6 QUESTIONS – APPROXIMATELY 100

A hint of the time to spend on each part of a question is given by the relative number of marks associated with that question part. Answer the questions in the space provided on the exam sheet. The space and marks allocated are an indication of the depth of the answer expected.

If you were an engineer at work, you would be expected to answer questions by coming

quickly to the point. The same is true in this exam. Be careful that you don’t unintentionally waste time writing an extremely lengthy answer giving every known detail about a concept when a short precise answer, PREFERABLE IN POINT FORM, is what is required to fill the 2 or 3 lines provided for the answer.

Make sure that you PROVIDE ADEQUATE DOCUMENTATION of code and answers as

marks are allocated for this documentation. Follow standard VisualDSP++ compiler / assembler conventions used in this class and recommended safe practices in your coding.

Some of the concepts in this course are subjective – meaning that there may be more than one

valid answer. Make sure that you support your answer. If the question says – which processor is better Blackfin or ARM in this situation, then answering Blackfin will give you no marks, even if true. Support why that answer is true, preferably with examples in point form.

As always, I expect engineers to have a good understanding of where they are doing well in a project and where they are doing poorly. ON THIS PAGE, provide an estimate of the mark you expect for each question, and the total mark for the exam. A bonus of 1/2 mark is given for each estimate within 10% of the actual mark for each question and a bonus of 2 marks for predicting your final exam mark.

Section A

Attempt all questions Section B

Attempt ONE question 1 Blackfin knowledge (12 marks) 6 ENCM511 on ARM or 68K processors

(Design) (20 marks) 2 Blackfin assembly code translation from C++

(15 marks) 7 Hardware testing (20 marks)

3 Blackfin interfacing -- Lab 4 SPI interface and J-TAG (15 marks)

8 Design own ENCM511 question and answer it (20 marks)

4 TTCOS knowledge: Loop-the-loop Car controller (C++ Design) (20 marks)

5 Interrupted subroutines (20 marks)

TOTAL / 102

SECTION ADO ALL

Q1 / 12 Q2 / 15 Q3 / 15 Q4 / 20 Q5 / 20 SECTION B ONLY ONE Q6 / 20 Q7 / 20 Q8 / 20 TOTAL / 102 + bonus of 4 As always, I don’t expect people to know every detail in my course for an A. So as always, 80% is an excellent mark on this final. A > 80% B > 70% C > 60% D > 45%

PAGE 1 OF 12

Page 2: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

EXTRA PAGE IF NEEDED

PAGE 2 OF 12

Page 3: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

ATTEMPT ALL QUESTIONS IN SECTION A Q1 A) Let’s start with a little humour – Translate the following expression into hexadecimal to get a famous Shakespeare quotation :-) (42 + 1) | ! (42 + 1) 1 marks B) You are at an embedded systems internship interview and need to explain software engineering ideas to the interviewer (a previous ENCM511 student). The interviewer suggests that you treat writing Section A of this exam as ‘a project’, and pretend you made two mistakes when answering the ISR problem Q1 C. You discover and correct one of these mistakes before moving onto Q2, and recognize that you made another mistake in Q1C when you see the hint during the interrupt question Q5. Now use this example to explain to the interviewer the software engineering ideas of ‘project phases’, and the concept and cost to a firm of mistakes, errors and defects made during a project. 5 marks

C) A student is initializing the Blackfin PF interrupts and has stopped at the end of the PFInterruptsInit( ) code. Based on the VDSP screen capture above and the value in FIO_MASK_A, which 4 PF input lines does the student want to use to cause interrupts? 1 mark Based on this picture the student has placed an inverter on one of PF input lines – which one? 1 mark Based on this picture, the student is planning to have some PF inputs to cause edge interrupts – which ones? 1 mark Assume that the student has correctly set the SIC_IMASK and the IMASK to allow PF Interrupts. Based on this picture, which of the PF interrupts will actually work? Explain how you know? 3 marks There are 12 marks available for this question. Transfer your prediction to the exam’s front page. PAGE 3 OF 12

Page 4: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

Q2. In ENCM515, we will look at developing some basic DSP (digital signal processing) algorithms. You can do a lot of that on the Blackfin. This routine below is a modification of the ProcessData( ) used in the labs. Essentially the routine captures 128 input audio values into an array, calculates an average and outputs the same averaged audio value. 128 times. This is a low-pass filter (averages out all high frequencies). Translate the following “C++” code into Blackfin assembly code following the coding conventions for this course. 15 marks (First error free)

Blackfin Assembly code C++ code #include <Blackfin. h> #include <Blackfin. h>

#define NUMPTS_CAPTURED 128 extern volatile int audioIn; extern volatile int audioOut; volatile int numPts = 0; volatile int average = 0; volatile int capturedAudio[NUMPTS_CAPTURED];

.global _ ProcessData_Fv; _ ProcessData_Fv:

void ProcessData (void) { // TTCOS pre-emptive task

// Insert value into an array an up-date the array pointer – rather like the SPI-Handler in Lab 4 capturedAudio[numPts++] = audioIn; // Show some of the bits of numPts in the LEDs to show something is happening; and demonstrate you can call a CPP function from assembly code ( Lab. 1) WriteLEDCPP(numPts);

// Output same calculated audio signal 128 time // Acts as low pass filter (First Lab in ENCM515) audioOut = average;

// If the audio buffer is full – calculate the average of all captured signals if (numPts >= NUMPTS_CAPTURED ) { int sum = 0;

for ( int count = 0; count < NUMPTS_CAPTURED; count++) {

sum = sum + capturedAudio[count];

}

average = sum / NUMPTS_CAPTURED; (HINT: use shift)

numPts = 0; // Reset the array pointer to start refilling the // audio buffer. In ENCM515 you will learn the better technique of using audio double buffering

}

_ ProcessData_Fv.END: RTS; }

There are 15 marks available on this page. Transfer your prediction to the exam’s front page. PAGE 4 OF 12

Page 5: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

A

B)

C) Q3 As I mentioned to you in class, I consider that the J-TAG interface probably the most important invention made to make embedded system development more reliable. The figure is a schematic showing wires coming out of the J-TAG interface which you used in Labs 1, 2, 3 and 4 to connect between VDSP and the Blackfin. In this question the J-TAG interface is being used to debug “2” boards that make up an embedded system. A) On Fig. 1 -- Draw all wires (as lines) to correctly connect the J-TAG interface pins (on the PC) with the TDI, TCK and TDO

pins on the 2 “circuit boards” of the embedded system (2 marks)

B) Draw arrows on the wires you have drawn to show the direction of the signals that travel between the TDI, TCK and TDO pins on the circuit boards and the PC J-TAG interface. (2 marks)

C ) Although Fig. C is only a screen-capture of the J-TAG interface schematic, I am surprised that no GROUND WIRE connections are shown on the JTAG interface. Explain the problems that would / could occur in LAB. 4 if the SPI interface and the LCD were not properly GROUNDED (had a common ground wire). (2 marks) For bonus marks, a student modified Lab 4 so that the Blackfin SPI interface would control 2 SPI-devices. ( Let’s suppose the LCD and accelerometer) D) Draw a labeled schematic picture of the connections between the Blackfin and two SPI devices. 3 marks E) Use this schematic, answer in point form, explain the important changes the student would have to change his / her

lab 4 SPI software to control these two devices and why these changes are necessary. NOTE: I don’t want code details – I want a discussion and explanation of the software architecture design changes. 6 marks

There are 15 marks on this page. Transfer your mark prediction to the exam’s front page. PAGE 5 OF 12

Page 6: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

Q4. DESIGN QUESTION – In A301, I have had Warren design and implement a loop the loop car set -- see picture to the side I never got the chance to see it running. So I would like you to design and code it for me.

I see the following TTCOS tasks as being necessary 20 marks main( ) – sets up the TTCOS environment and activates the tasks InitAllInterfaces( ). This initializes all the Blackfin registers to make the system run. WRITTEN FOR YOU There are 4 infra-red light sensors build into the track IR_A, IR_B, IR_C and IR_D, which are sent to the

Blackfin over lines PF8 to PF11 respectively. Warren has not yet given me the documentation for the sensors, so I do not know how they work. Let’s assume

that the sensors go low when the car is over the top of the sensor, and high again after the car has passed by. A Blackfin output line is used to control the car speed using a pulse width modulated (PWM) approach. The

larger the duty cycle on this line, the faster the car will go. IR_A sensor is just before the loop-the-loop section of the track. High speed is needed in this section or the car

will fall off the loop-the-loop track! IR_B and IR_D sensors are just before the corners – much slower speed is needed or else the car will slide off the

corners and crash in these sections. IR_C sensor is just before the ‘straight away’, more speed is needed but not as much as during the loop-the-loop. You’ll need some speed information. You will need to code so that, IF the car does not crash, the car will take 2

seconds to go through the loop-the-loop part of the track (A to B) and 3 seconds to go around the rest of the track. The car is placed at the corner before the loop-the-loop at the beginning of the lab. If you really want to use other Blackfin functionality than just the GPIO lines, you can state that the

CORE_TIMER, TIMER0, TIMER1, TIMER2 or SPI are configured and ready to go as part of InitAllInterfaces( ). SIMPLY STATE THE CONFIGURATION AND IT IS DONE! – No interrupts are allowed since TTCOS has its own.

StartCar_With_SlowSpeed( ) This starts the car at a slow speed so that the laboratory can be activated in a controlled manner. ReadSwitches( ) This transfers the PF input signal lines to a global variable PFvalue to be used by any other TTCOS tasks. CarPositionSensor_SlowDown( ) checks the global variable PFvalue to see if the car has just passed over the corner sensors and sets the global variable this_Amount_Of_Speed_Needed as required to control the car speed. CarPositionSensor_SpeedUp( ) checks the global variable PFvalue to see if the car has just passed over the sensor at the start of the straight away or before the loop-the-loop and sets the global variable this_Amount_Of_Speed_Needed as required to control the car speed. SendThePowerNeeded( ) checks the global variable this_Amount_Of_Speed_Needed and generates the necessary pulse-width modulated drive signal to drive the car at the correct speed.

Design and implement all the tasks in C++. (except InitAllInterfaces( ) which is written for you). Note this is an open ended design question – WATCH your time. It will be marked based on both design and coding components. I want all the tasks described above to be implemented, but good design of the embedded software could

drastically reduce the amount of code that is necessary to write. 20 marks available -- Transfer your mark prediction to the exam’s front page. PAGE 6 OF 12

Page 7: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

20 marks available -- Transfer your mark prediction to the exam’s front page. PAGE 7 OF 12

Page 8: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

Subroutine void Set_numInterrupts(void); Interrupt service routine 01 LINK 16; 101 volatile int numInterrupts = 24; 02 R0 = 1; 102 03 P0.L = lo(numInterrupts); 103 Ex_Interrupt_Handler(MyCode) { 04 P0.H = hi(numInterrupts); 104 ClearInterrupt( ); // 42 cycles to execute 05 R0 += 2; 105 numInterrupts++ // 4 cycles to execute 06 [P0] = R0; 106 Ssync( ); // 22 cycles to execute 07 ssync( ); 107 } 08 RTS 108 Q5. HINT FOR Q1C as promised. Computer engineer on holiday counting number of suitcases from airline. :-) A) The Blackfin subroutine and interrupt service routine shown above are loaded into the processor. The subroutine is now executed, and no interrupts occur. What will be the value in numInterrupts after the subroutine RTS has been executed (Line 08)? (1 mark) B) If you switched to mixed mode in VDSP, what would you see as the last instruction of the interrupt service routine? (1 mark) The Blackfin subroutine and interrupt service routine shown above are re-loaded into the processor. The subroutine is now executed. One interrupt occurs during the time that Line 02 is executed – This means that the instruction 02 is stopped from being executed and then allowed to complete execution without another interrupt. Another interrupt occurs during the time that Line 04 is executed, and another during Line 05 and a final interrupt occurs during the time that Line 07 is executed C) What is the value in numInterrupts before line 01 is executed ? (1 mark) D) What is the value in numInterrupts before line 03 is executed? (1 mark) E) What is the value in numInterrupts before line 06 is executed? (1 mark) F) What is the value in numInterrupts after line 07 has finished execution? -- Explain your answer in detail as I think a “race” condition is possible. What is a race condition? (5 marks) G) If you assume that every line of code in the subroutine takes 1 cycle to complete if no interrupts occur, then how long will the subroutine take to execute if the four interrupt occurs as described above. Explain your answer. (3 marks). H) When the subroutine line 08 (RTS) finishes executing, the code will probably crash (with or without the interrupts occuring. Why? (2 marks) I) The diagram shows the standard four parts of an ‘ideal’ Blackfin instruction. Explain how the instruction stages must be modified to support interrupts, and then use this model to explain how the Blackfin instruction R0 +=1; is executed and interrupt during execution 5 marks

There are 20 marks available on this page – Transfer your mark estimate to the front page PAGE 8 OF 12

Page 9: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

ATTEMPT ANY QUESTION IN SECTION B DO NOT ATTEMPT TWO QUESTIONS AS ONLY THE FIRST WILL BE MARKED

Q6. MOTOROLA OR ARM QUESTION: To make this question a little easier to answer, assume the following things A processor that behaves exactly like a Blackfin processor but needs to be programmed using Motorola or ARM assembly language syntax

and coding conventions (e.g. NOT R1 = R2 but MOVE.L D2, D1 on the Motorola or MOVS R1, R2 on the ARM processor) Assume that this “Motorola or ARM Blackfin” has 8-bit GPIO registers bits (0 to 7) and 8-bit LED interface. 20 marks

68K or ARM ASSEMBLY LANGUAGE CODE

enum {LED_OFF, LED_ON, UNKNOWN}; #define u16 unsigned short int

u16 MT_LEDstate[4] = {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN};

.

// Code to Toggle LED interface – switches between LED whichLED on and off

void MT_FlashLED(int whichLED) { u16 LEDbit = whichLED - 1; // u16 LEDmask = 1 << LEDbit; u16 currentLED_AfterMask = (uTTCOS_ReadLED( ) & ~LEDmask) & 0xF;

u16 nextState = UNKNOWN; switch (MT_LEDstate[LEDbit]) { case UNKNOWN: // Move to known state nextState = LED_OFF; break;

case LED_OFF: // Turn LED off uTTCOS_WriteLED(currentLED_AfterMask); nextState = LED_ON; break;

case LED_ON: uTTCOS_WriteLED(currentLED_AfterMask | LEDmask); nextState = LED_OFF; break; }

MT_LEDstate[LEDbit] = nextState;

}

Design and translate this code into 68K or ARM assembly code using course coding conventions of this course.

Page 10: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

7) One of the hardest things to know with embedded systems is the following – You have programmed the SPI interface – but are the board connections broken? – bad solder joints and the like. A new internship student is asked to investigate the feasibility of a number of solutions to overcome this hardware software co-design problem. . i) Solution 1 – Bed of nails examining the SPI clock, chip select lines and MOSI lines. ii) Solution 2 – Loop back – essentially connect the MOSI of the Blackfin SPI back to its own MISO line iii) Solution 3 – Send SPI signals to a second Blackfin programmed to echo back the signals to the first Blackfin iv) Solution 4 – Hook all the SPI lines to the Blackfin’s own GPIO pins, and use the Blackfin own I/O lines as a logic analyser.

A) Discuss the relative merit of these four solutions – meaning the likelihood of avoiding hardware defects 8 marks

B) Use the E-UNIT syntax, develop tests for solution 4 to check whether the SPI chip select line is operating correctly and whether (if you put the value 0xA0A in SPI_TXBR) the MOSI line is working. Assume you have access to (can use) all GPIO functions from Lab 1, all timer functions from Lab 3 and all SPI functions from Lab. 4 12 marks

8) – Don’t you just hate it when you have done research beyond the course content because that area interested you you have heavily reviewed one area you thought the instructor kept on emphasizing and then the examiner does not ask any questions in that area! As promised, here is a chance to overcome that problem and show your true knowledge of interfacing and embedded systems.

Design a question related to, or extending, this embedded systems course AND answer it.

TO RECEIVE THE FULL 20 MARKS the question should satisfy the following criteria DO NOT WRITE QUESTIONS INVOLVING A LOT OF CODE TRANSLATION.

Such questions and answer will be considered similar to questions Q1 to Q7, and therefore WILL NOT RECEIVE MANY MARKS.

Be at a difficulty level appropriate for a final exam question in the 3rd / 4th year of an Electrical and Computer Engineering program. Quick test – Would it be suitable for next year’s final?

The question should NOT be equivalent to any exam question already asked in this course or this or recent finals.

Questions and answers that are a simple regurgitation of a concept handled in class or laboratory will receive a D grade (3 – 6 marks or less).

Questions and answers that give a new insight into a concept handled in class or laboratory will receive a C or a B grade (8 – 14 marks).

Questions that, under different circumstances, would present A CHALLENGE FOR YOU to answer in either Section A or Section B of a final exam will receive B or A grade (14 and up), if answered correctly. A good mark on this question would be 15 to 17 marks out of 20 (B+ / A-)

Students who have spend time ahead of the exam planning Q8 questions that lead to answers that are clear and concise are more likely to receive higher marks. This means no long-winded answers that look like they have been thought up on the spur of the moment.

PLEASE BRING THE QUESTIONS AND ANSWERS INTO THE EXAM IN YOUR HEAD AS NO ADDITIONAL MATERIALS ARE ALLOWED IN THIS EXAM!

Marking exams is normally as much fun as watching paint dry. Questions that entertain and give the impression – “that’s clever and well thought out” – or leave the instructor wanting to boast to other instructors about what you suggested – are more likely to receive higher marks.

In 2009, the answer to this question led to a job for one ENCM511 student. DO NOT SPEND SO MUCH TIME ON THIS QUESTION THAT YOU DO NOT HAVE TIME TO COMPLETE THE OTHER QUESTIONS PAGE 10 OF 12

Page 11: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

ANSWER Q7 or Q8 HERE – ATTEMPT 1 QUESTION. THE SECOND WILL NOT BE MARKED

There are 20 marks available for Section B. Transfer your prediction to the front page. PAGE 11 OF 12

Page 12: Department of Electrical and Computer Engineering, University of Calgary ENCM511 …people.ucalgary.ca/~smithmr/2016webs/encm511_16/... · 2016. 11. 26. · December 18th, 2012 3

There are 20 marks available for Section B. Transfer your estimate to the front page. PAGE 12 OF 12