CS代考 ECE3375B: Final Examination

Instructions:
ECE3375B: Final Examination
Profs. Isaac & Leod Exam Starts: 14:00, 2021 04 27
• The final examination is take-home and open-book. You may use any printed or electronic resources to complete this exam.

Copyright By PowCoder代写 加微信 powcoder

• You should not collaborate with other students in this class or ask for help from other people (including online tutorial websites). Doing so constitutes an academic offence!
• In the event that two or more students submit suspiciously similar answers, the course instructors reserve the right to request personal interviews with students to check their understanding of their submissions.
• You should not distribute you exam paper after the exam, or upload questions to an online tutorial site.
• You should submit your final answers to the “Final Examination” Assignments module on OWL.
• You must be prepared to submit a digital copy of you answers and any rough work, diagrams, comments, etc. you would like us to see for when marking your exam. Your submission should include all answers as a single PDF. You do not have to include this exam question paper in your submission.
• Your uploaded answers must be within the upload size limit of 20 MB. This is large enough for most text/- graphics, but if you photograph written work with a high-resolution camera, you may need to reduce the size of the images.
• It is each student’s responsibility to ensure they can submit legible, digitized answers to the “Final Exami- nation” Assignments module within the time limit provided.
• Late submission is accepted, with a penalty of 50% per hour after the deadline.
◦ You have four (4) hours to complete the examination. This includes the time required to digitize and
upload your answers. Please manage your time wisely.
◦ If you experience serious technical difficulties, you need to let Prof. McLeod know as soon as possible, but there is no guarantee accommodations can, or will, be made.
• The entire exam is worth 50 marks.
• University policy states that cheating, including plagiarism, on an examination is a scholastic offence. The commission of a scholastic offence is attended by academic penalties which might include expulsion from the program. If you are caught cheating, there will be no second warning.
Submit your completed exam paper by 18:00 on Tuesday, April 27th 2021

Microcontroller Concepts [20 marks]
What is the difference between full-duplex and half-duplex UART hardware? [3 marks]
You (an expert in programming microcontrollers) have written a slick Assembly program for an ARM Cortex-A9 microcontroller with a cool ISR to handle interrupts on a GPIO port, labelled gpio_isr. Your buddy steals your code, keeps the GPIO interrupts in place, but also adds a bl gpio_isr within the main program. What are some problems that might occur with this? [3 marks]
We need to use a 16-bit count-up timer with a 10 MHz clock to time an interval of 2 ms. What value should we write to the appropriate data register on the timer so it will count for this interval? [2 marks]
A 16-bit count-down timer with a 2 MHz clock currently has the value 0xCE44 in the counter’s data register. How long will it take the timer to complete this interval? [2 marks]
A 6-bit successive approximation register (SAR) analog-to-digital converter (ADC) with a voltage reference of 3.3 V is converting a 2.25 V signal. Complete the following table showing the binary search process. [3 marks]
Step Bit Pattern
1 2 3 4 5 6
Digitized Voltage (V)
A UART communications frame is defined as 9-1-2. The following set of pulses is received: 0b0010101011111 (the first pulse received is on the left, the last is on the right). Is this data correctly formatted and uncor- rupted? Explain your answer. [2 marks]
A peripheral on the DE1-SoC has IRQ #173. What is the appropriate set-enable bit and the appropriate the set-enable register (ICDISERn) for this peripheral in the GIC? [3 marks]
We wish to enable interrupts on the DE1-SoC for push button 2. Assume the GIC is already configured, the exception vector table already written, and global interrupts are already enabled. How do you enable interrupts on the specific hardware? [2 marks]

II Interfacing with Peripherals [20 marks]
A model 16-bit microcontroller and several peripherals is described at the end of this exam paper in the Ap-
pendix. Use this model microcontroller and peripherals to address the following questions.
You may answer the following by writing C or Assembly code. If you cannot write working code, pseudocode and flowcharts that explain the required implementation will be accepted for partial credit. Include as much specific detail as possible to maximize your grade.
You do not need to write an entire program, just the required lines of code. Providing comments or other annota- tions to your code is recommended. For example, if you are just writing a few lines of C code it would be helpful to add comments to identify which variables should be locally defined and which are global.
If you write C code, please assume that the compiler treats an int as a 16-bit number. If you write Assembly code, remember that the registers and word sizes are 16 bits.
1. Work with GPIO port A for the following.
(a) Provide the code snippet to configure pins 6,7,8,9 to input and 12,13,14,15 to output. Make no assump-
tion on the default state of the pins, and do not modify any other pins. [2 marks]
(b) Provide the code snippet to read from pins 6,7,8,9 and store as a 4-bit number. If you write C code,
store the data in int input_data. If you write Assembly code, store the data in r0. [2 marks]
(c) Provide the code snippet to write the lowest 4 bits of some given data to pins 12,13,14,15. If you write C code, the data is already provided in int output_data. If you write Assembly code, the data is already provided in r0. [2 marks]
2. Write the code snippet to use interval timer A to idle for a 1 s interval. [2 marks]
3. Write the code snippet to use the input capture to record when pin 4 goes high. You may assume this will
happen within the maximum interval on the timer. [2 marks]
4. Work with the ADC for the following.
(a) Write the code snippet to use this ADC to start sampling channel 2. Make sure you do not modify the interrupt enable bit. [2 marks]
(b) Write the code snippet to idle until conversion is complete. If you write C code, store the result in int adc_input. If you write Assembly code, store the result in r0. [2 marks]
5. Work with the UART communications peripheral for the following.
(a) Write the code snippet to configure the UART for 9-0-1 at 4800 baud. [2 marks]
(b) Write the code snippet to send one frame of data on the UART. If you write C code, assume the data to send is in int uart_data. If you write Assembly code, assume the data to send is in r0. The system should hang until the send operation is complete. [2 marks]
6. Write the code snippet to enable interrupts from the output compare peripheral. Make no assumptions about the state of the system or that peripheral, and only change the bits required to enable interrupts from that peripheral. [2 marks]

III Embedded System Design [10 marks]
The following design problem should be implemented with the model 16-bit microcontroller described in the Appendix.
• You may use any of the peripherals listed in the Appendix.
• Your design must use at least one interrupt-enabled peripheral.
• Please implement the design problem as stated. Make no assumption regarding the initial state of the microprocessor and peripherals — it is necessary to appropriately configure all interrupts and peripheral control registers.
• If certain aspects are vague, or unspecified, make a design choice or an assumption and proceed.
• As always, make sure you clearly state any design choices and assumptions you make. You may answer this question in two steps.
1. Optional: Describe your implementation in human-readable form using any combination of paragraphs, bullet points, comments, diagrams, flow charts, etc. you wish. You can describe the basic program flow, task scheduling, use of local and global variables, use of interrupts, and any design choices and assump- tions. [5 or 0 marks]
2. Mandatory: Write the code in C or Assembly. [5 or 10 marks].
If you do not describe your implementation, we will attempt to infer your design from the code. This may result in you losing marks if we can’t make heads or tails out of what you wrote: if your code is very vague, hard to fol- low, lacks descriptive variable or function names, and/or has no comments, such that we can’t figure out how it is supposed to work, we will not give you the benefit of the doubt unless you also provide a sensible description of the implementation. You may also combine (1) and (2) by writing code and adding arrows linking that code to descriptive annotations, diagrams, flowcharts, etc.
Problem: A custom peripheral can be connected to a GPIO port. Pins 0 to 3 of the GPIO port connect to push buttons that go high when pressed. Pins 8 to 15 of the GPIO port are connected to a single seven-segment display panel. We also have four analog channels with voltages between 0 V and Vref = 5 V. Program the microcon- troller to allow the push buttons to select which of the analog channels to digitize, and display the result in volts (rounded down) on the seven segment display panel. Until another push button is pressed, the display should update once each second.
Analog Channel 1 Analog Channel 2 Analog Channel 3 Analog Channel 4
Microcontroller
If you are writing code in C, you may assume that this function is available:
char hexmap( char digit ) {
// digit = single hexadecimal digit
// returns bit code for displaying that digit on a seven-segment panel

char ss_code;
// some code, just assume it is written and it works return ss_code;
If you are writing code in Assembly, you may assume that this subroutine is available:
push {r1 – r12, lr}
@ single hex digit is in r0
@ some code, just assume it is written and it works
@ bit code for displaying that digit on a seven-segment panel now @ goes into r0
pop {r1 – r12,lr}
Both the C and Assembly code have the same function: they accept an integer valued between 0x0 and 0xF and return the appropriate code for displaying that digit on a seven segment display. (In this exercise only decimal digits between 0 and 5 will be needed.)
You will need to select one of the GPIO ports for the combined push button/display peripheral and configure that port appropriately. You should also describe how the analog input channels are connected to the microcon- troller, and configure as necessary.

This exam uses a model 16-bit microcontroller with simplified structure and peripherals. This microcontroller memory-mapped, uses von Neumann architecture, and is little-endian. It has a 16-bit address bus and a 8-bit data bus.
When writing C code for this microcontroller, please assume that the compiler treats an int as a 16-bit number. If you wish to write Assembly code, you may assume that this microcontroller accepts code with similar mnemon- ics and format as ARMv7 Assembly, and has access to the same general purpose registers (except the registers, and the word size, is only 16-bits). You may also assume that all memory cells are also both byte-addressable and word-addressable, including the registers on peripherals.
The memory map for this microcontroller is shown below.
Peripherals

Interrupts
This model microcontroller has a simple configuration for hardware interrupts. This microcontroller has only one operating mode, and no banked registers.
• Interrupts are enabled in the CPU by setting bits in the special-purpose irqen register, each of the interrupt- enabled hardware peripherals maps to a single bit in this register. This can be done in C with the code:
asm(“msr␣irqen,␣%[ps]” : : [ps]”r”(interrupt_mask));
where int interrupt_mask is the appropriate 16-bit sequence of interrupts to enable or disable. This can
also be done in Assembly with the code:
msr irqen , rX
where rX is a general purpose register (r0, r1, r2, or whatever) that contains the appropriate 16-bit se- quence of interrupts to enable or disable. For example, if you wanted to enable interrupts on IRQ 3 and IRQ 10, the appropriate bit sequence would be zero except bits 3 and 10 set to 1: 0b0000 0100 0000 1000 = 0x0408.
• Interrupts are enabled in hardware by setting the appropriate bit(s) in a control register, as described below for each peripheral.
• The interrupt vector table (IVT) starts at 0x0000 has a row (a word) for each interrupt-enabled hardware peripheral, this row consists of the address for the interrupt service routine (ISR). In C, the ISR must be written with the definition:
void _isr_[iqr]( void )
where [irq] should be replaced with the appropriate IRQ number. In C you only need to write ISRs for interrupts that are enabled, the compiler will figure out the rest. In Assembly, you must define the entire IVT at the start of the program:
1 .section .vectors ,
2 .word unused
3 .word unused
4 .word isr_irq_2
5 .word unused
6 .word unused
7 .word mystrangelabel
8 .word unused
9 .word unused
10 .word unused
11 .word unused
12 .word unused
13 .word lollipop_isr
14 .word unused
15 .word unused
16 .word unused
17 .word unused
@IRQ0 @IRQ1 @IRQ2 @IRQ3 @IRQ4 @IRQ5 @IRQ6 @IRQ7 @IRQ8 @IRQ9 @IRQ10 @IRQ11 @IRQ12 @IRQ13 @IRQ14 @IRQ15
Then you can follow with the main program:
21 .global _start
22 _start:
23 @ your main code

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
@ ISR code for IRQ 2
isr_irq_2:
And later define the ISRs:
@ preserve context
push {r0-r12, lr, sp}
@ main code for ISR
@ does something useful
@ restore context
pop {r0-r12, lr, sp} @ return
subs pc, lr, #2
ISR code for IRQ 5
mystrangelabel:
@ more code
subs pc, lr, #2
@ ISR code for IRQ 11
lollipop_isr:
@ more code
subs pc, lr, #2
@ ISR for unused IRQs
@ this should never happen, so just hang unused:
As you can see, you are free to name the ISRs any silly label you like in Assembly, as long as that label is linked to the correct row of the IVT.
• For the purposes of this exam, if you are writing code in Assembly, it is sufficient to only explicitly provide the rows of the IVT that are used for interrupts — you may assume all other rows for IRQs that are not used already have the address of a suitable subroutine (like unused).
Once irqen is correctly configured, the IVT is set up with the appropriate ISRs, and the peripheral control bits are appropriately set for interrupts, the system is ready to go. Note that the only way to disable all interrupts globally is to set all bits in irqen to zero.

General Purpose Input/Output Ports
This model 16-bit microcontroller has six 16-pin general purpose input/output (GPIO) ports. These have the following structure.
• Data may be written to, or read from, the IO data register. Each bit in this register is independently config- ured for input or output, and maps to a corresponding pin (pin 0 to bit 0, pin 1 to bit 1, up to pin 15 to bit 15).
• Setting a bit to 0 or 1 in the IO control register assigns the corresponding bit in the IO data register to input or output, respectively.
• Setting a bit to 1 in the interrupt control register allows hardware interrupts to be generated when data on the corresponding pin changes. This is usually for pins set to input, but it will still work if pins are set to output and new data is written to that pin.
• A bit is set in the edge capture data register if the value on the corresponding pin changes from 0 to 1 since this register was last read from. Writing any value to this register clears all bits to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 [base] + 0x06:EdgeCaptureDataRegister 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 [base] + 0x04: InterruptControlRegister 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 [base]+0x02:IOControlRegister 151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x00:IODataRegister
The GPIO ports’ addresses and IRQs are as follows.
GPIOA GPIOB GPIOC GPIOD GPIOE GPIOF
Address 0x6000 0x6020 0x6040 0x6060 0x6080 0x60A0 IRQ #2 #3 #4 #5 #6 #7
Q7, Q6, …, Q0
En Q[7..0] N-bit Latch

Interval Timers
This model 16-bit microcontroller has two interval timers. These have the following structure:
• The timer always counts down with an internal clock speed of 1 MHz.
• To set the countdown interval, write the appropriate value to the data register. This also starts the timer. • When the timer is counting down, the current counting time can also be read from the data register.
• Writing to the data register while counting down will overwrite the current count.
• Bit 0 in the status register is set to 1 when the timer reaches zero.
• Writing any value to the status register clears bit 0.
• Bit 0 in the control register is set to enable interrupts.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 [base]+0x04:ControlRegister 151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x02:StatusRegister 151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x00:DataRegister
The timers’ addresses and IRQs are as follows.
Address 0x6400 IRQ #8

Real-Time Interrupt Timer
This model 16-bit microcontroller has a special timer solely for periodically generating interrupts. This timer has the following structure:
• The timer always counts down with an internal clock speed of 1 MHz.
• To set the countdown interval, write the appropriate value to the data register.
• The current count on the timer is hidden and cannot be accessed in software.
• Bit 0 in the status register is set to 1 when the timer reaches zero.
• Writing any value to the status register clears bit 0.
• Bit 0 in the control register is set to enable interrupts, this also starts the timer on countdown-and-repeat mode. Clear bit 0 to stop the timer (and also disable interrupts).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 [base]+0x04:ControlRegister 151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x02:StatusRegister 151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x00:DataRegister
The real-time interrupt timer is at address 0x6800 with IRQ #10.

Output Compare
This model 16-bit microcontroller has one output compare unit. This has the following structure:
• The 16-bit timer counts up at 1 MHz.
• Bits 8, 9, and 10 in the control register are interpreted as as a 3-bit binary number to select one of 8 output pins.
• The output compare unit is linked to pins 0 to 7 of GPIO port B. The appropriate pin on GPIO port B must also be set as output, otherwise the output compare unit will not operate properly.
• Bit 15 of the control register is set to 1 to enable interrupts. Bit 6 is set to 1 to start the timer, it can be cleared to stop the timer. Bit 0 is the value to be checked against the input pin.
• The time interval is loaded into the data register.
• The time interval is compared to the current count, as soon as the count exceeds that interval, the value in control register bit 0 is written to the output pin and the status register bit 0 is set to one.
• Writing any value to the status register will reset (clear) the internal timer.
151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x04:StatusRegister 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 [base]+0x02:ControlRegister 151413121110 9 8 7 6 5 4 3 2 1 0 [base]+0x00:DataRegister
The output compare is at address 0x6C00, with IRQ #11. If interrupts on the output compare are enabled, inter- rupts on the corresponding pin of GPIO port B should be disabled.
Address Bus Data Bus

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com