Försättsblad till tentamen vid Linköpings Universitet

advertisement
TDDI11.2012-05-31.08-12
Försättsblad till tentamen vid Linköpings Universitet
Cover page for exam at Linköping University
Datum för tentamen
2012-05-31
Date of exam
Sal
SU12 - 18
Room
Tid
08:00 - 12:00
Time
Kurskod
TDDI11
Course code
Provkod
DAT1
LADOK code
Kursnamn/benämning
Programmering av inbyggda system
Course name
Embedded software
Institution
IDA
Department
Antal uppgifter som ingår i tentamen
7 uppgifter om totalt 40 poäng
Number of assignments
7 assignments for a total of 40 points
Antal sidor på tentamen
(inkl. försättsbladet)
6
Number of pages including cover
Jour/Kursansvarig
Klas Arvidsson
Responsible/Examiner
klas.arvidsson@liu.se
Telefon under skrivtid
013 - 28 21 46
Phone during exam
013 - 28 21 46
Besöker salen ca kl.
Ca 1h efter tentastart
Time of exam visit
About 1h after exam start
Kursadministratör
Madeleine Häger Dahlqvist
Course administrator
013 - 28 23 60, madeleine.hager.dahlqvist@liu.se
Tillåtna hjälpmedel
Ordlista och enkel miniräknare (+,-,*,/)
Allowed aids
Dictionary and simple pocket calculator (+,-,*,/)
Övrigt
Precise, explained and clearly motivated assumptions, statements and reasoning raise the impression and are required for
highest score. Solve at most one assignment per sheet.
If in doubt, state clearly your interpretation of the question,
your assumptions, and answer according to that.
Preliminary graded: U < 50% < 3 < 67% < 4 < 84% < 5
Grades may be raised or lowered based on overall impression.
Results available after (within) 10 working days.
Other information
Typ av papper
Rutigt, linjerat eller blankt
Paper to use
No preference
Antal anmälda
77
Number of exams
1 (6)
TDDI11.2012-05-31.08-12
General theory part (19p)
Write your answers in the file “solutions.txt”. Save often. Solve all assignments you can answer
fast first. Do not spend more than 1 hour on this part. Get started on the practical part early.
Right-click the desktop to start emacs, a terminal and the communication client.
1. Definition of embedded system (3p)
a) Describe four criteria that are said to distinguish an embedded system. We say it’s an
embedded system when some or all of them is true.
b) Give an example of an embedded application where at least two of the distinguishing criteria
are found. Motivate.
2. This and that (5p)
a) Embedded development sets many non-functional requirements on the system, such as unit
cost or performance. List four other common and important such requirements. (2p)
b) What is a semaphore and when do you use it? (2p)
c) Explain the meaning of a memory map. (1p)
3. Assembly (3p)
An 8-bit processor have two 8-bit registers for 8-bit arithmetic operations, reg1 and reg2. It
also have the following assembly operations (the first operand is the destination):
mov [ADR] regX ;; Move from register to memory
mov regX [ADR] ;; Move from memory to register
add regX regY ;; Addition, regX = regX + regY
adc regX regY ;; Addition, regX = regX + regY + carry
;; Example, X represent the base address of some data
mov reg1 [X+1] ;; Move second byte of X to reg1
Base addresses A, B and C each store one 16-bit integer.
a) Show assembly code to perform the 16-bit addition C = A + B. Assume that reg1 and reg2
are free, and that no other registers exist. Both A and B must remain unmodified. (2p)
b) Presume that operand B is specified to be 4-bits (the highest nibble in the byte is always
zero). Can the 16-bit result overflow? If yes: how do you detect that? If no: why not? (1p)
4. Optimization (4p)
At some point in the development process you may need to optimize code.
a) At which point in the development process do you start to worry about optimizations? (1p)
b) Suggest three things you may want to optimize (three goals of optimization). (1p)
c) Describe two different methods to reach one of your goals in b). (2p)
5. Development methods (4p)
a) Explain why using a development methodology is important. (1p)
b) Give a compelling reason when you would use successive refinement model. (1p)
c) Give a compelling reason when you would avoid successive refinement model. (1p)
d) Give example of a development methodology other than successive refinement. (1p)
2 (6)
TDDI11.2012-05-31.08-12
Microwave oven requirements and specification
The essential parts of a microwave owen are: A microwave generator, A rotating tray, A door,
A set of buttons, A display, A loudspeaker and a micro controller to tie it all together. All
mentioned parts are available for you in this assignment. Your task is to write a program that
behaves as a microwave oven. The requirements are:
1) Microwaves are not possible to turn on until the door has been opened and closed (every
time). The assumption is that food is inserted during the time the oven is open, and that
this requirement prevent us from starting the oven empty by mistake.
2) Microwaves are not possible to turn on unless a time is set.
3) The microwave generator is stopped within 50ms when the door is opened. This is
required by safety regulations.
4) The time counts down when microwaves are on and is paused when microwaves are off.
5) Microwaves are turned off and the speaker beeps during 1 second when the time count
down to zero. (It does not beep (or countdown) unless microwaves was on.)
6) Pressing the start button turn on microwaves and the rotation tray depending on 1) - 2).
7) Time can be set or modified at any time. The first 6 presses on the + button increment the
display by 10 seconds. The next 6 presses increment by 20 seconds, and any more
presses increment by one minute. Any press on the - button halves the set time.
The micro controller uses three memory mapped registers, A, B and READY. A is 8-bit input, B is
8-bit output and READY is 8-bit input/output. The meaning of each bit is given below:
bit
input A
output B
READY
door:
inc:
dec:
start:
beep:
onoff:
position:
value:
READY:
7
6
5
4
the high 4 bits are not used
beep
onoff
position of digit
3
door
2
1
0
start
dec
inc
value of digit on display
set to false before update of display, autoset to true when display is ready
This bit is 1 while the door is open.
This bit is 1 while the + button is held down (no visual feedback).
This bit is 1 while the - button is held down (no visual feedback).
This bit is 1 while the S button is held down (no visual feedback).
Speaker will beep while this is set to 1.
Microwaves are on and tray rotates while this is 1.
A two bit position value (0-3). This decide which of the four display digits that will
be updated with the value in the low 4 bits of B. The digits are numbered left to right
starting at 0.
A four bit value (0-15) that determine one digit to show on the display.
The device controlled by the output B is very slow. To guarantee that all changes to
B is detected you can not write the next value too fast. The procedure to avoid
writing a new value to B too early is to watch this READY signal. Before you update
B you set READY to false. Then you write to B. As soon as READY reverts back to true
B is ready to accept a new value. It is OK that the delay is noticeable on screen.
3 (6)
TDDI11.2012-05-31.08-12
The system should be implemented by three modules (two as state machines).
1) One state machine, SET_TIME, should monitor the + and - buttons (inc and dec). The
output of this state machine is time_set. time_set is 1 at all times when the time set by the
user is above 0. A second output of this state machine is clock. clock is the actual time set
on the display in seconds. The maximum clock is 99:59. This state machine should run
every 200ms and is already implemented for you. It solves requirement 7.
2) A second state machine, HEAT, should use door, start, and time_set as inputs. Outputs
should be beep, onoff and clock. It should solve requirements 1, 2, 4, 5 and 6.
3) A third function takes care of updating the display (position + value) with the current
clock value. You can use seconds_to_display implemented later.
Instructions
If you are unable to solve one assignment, explain that and implement a simpler replacement
for reduced points. Make sure to comment what your code is intended to do in order to get
credits despite flaws. If you encounter small glitches and flaws that you think may affect your
score, use the exam communication client to ask about it (do not spend time on a problem you
are not sure you have to fix). Right-click the desktop to start emacs, a terminal and the
communication client. To get started and check that the given files work you need to execute:
cp given_files/Makefile .
// remember the last dot
cp given_files/main.c .
// all your code go to main.c
gmake
// to compile
./main
// to start application
When this work correctly it will bring up a window presenting a (ugly?) microwave oven. The
given code causes the owen to behave rather erratic. It will be your task to program the correct
behavior of this microwave (see assignments below).
6. Practical implementation (computer part) (14p)
Write all your code in “main.c”. Compile with “gmake”.
a) Your first task is to implement the function set_display(int value). If, for example, value is
the number 1234 the function should update the display to show 12:34. If value is 987654,
then the display will show 76:54. The given code increment a counter and assign it to B over
and over again. You can test your function by instead of assigning B call set_display. Take
care not to modify beep or onoff bits. (6p)
Hints: You will need your bit manipulation skill. Solve this in small steps and test between.
How to write to value without affecting other bits? How to write position? How to update
all four positions and not too fast? How is division by 10 and mod (%) by 10 useful?
b) Implement another function seconds_to_display(int seconds) that set the given number of
seconds on the display, but take minutes into account. If, for example, the function is called
with an argument of 83 seconds it must show 01:23 on the display (one minute and 23
seconds). It is a simple calculation and a single call to set_display(123). (1p)
c) (1) Draw the state machine for HEAT. Look at the specification on previous page. Do not use
the provided state machine template sheet yet. (2) Implement the state machine for HEAT
and test it carefully. (3) Make sure your implementation matches your drawing (or vice
verse). (4) Then fill in the provided state machine template with your final version. (6p)
d) Implement a main program that make sure each state machine is called at proper time
intervals (observe requirement 3 and the intended period of SET_TIME). You should now
have a working microwave oven implementation. (1p)
4 (6)
TDDI11.2012-05-31.08-12
7. Implementation related theory (7p)
Write your answers in the file “solutions.txt”. Save often.
a) Is the given SET_TIME machine a Mealy or Moore machine? Motivate your answer. (1p)
b) Both state machines update clock. Decide for yourself if this is a problem or not. Then use
your best arguments to defend your decision. Good reasoning and motivation is the important
thing for score, not the decision in itself. (2p)
c) You notice that pressing the + or - button is sometimes not detected by the state machine, and
sometimes detected twice before you release the button. Suggest a better implementation of
the given state machine that solves this. (1p)
d) Assume you do no have access to TimerSet nor TimerOn functions. Instead you have access
to a low level 8-bit hardware counter connected to a 100kHz clock. It will generate an
interrupt every time it overflows from 255 back to 0. Explain the code needed to reset
timer_period_elapsed every 50ms by using this hardware counter. An exact measurement is
important (give or take a microsecond). (2p)
e) The following four timing diagrams show two updates of the slow display (output B) and the
READY signal. Which version follow the specification for READY given on page 3? (1p)
________
__
READY
\________/ \____
_______ ________ ________ 1)
B
_______X________X________
________
READY
B
__
\________/ \____
_________ ___________ ___
_________X___________X___
________
READY
B
2)
__
\________/ \____
_________ ______ ________
_________X______X________
________
READY
B
__
\________/ \____
_______ _____________ ___
_______X_____________X___
3)
4)
Some people claim that more than 100% is impossible. Let’s put that statement to the test.
Here’s an optional question that may push your score up to 42 (105%).
Assume the door is connected to a low latency interrupt pin. Explain how you would
improve the security of the implementation (see requirement 3) by using an interrupt
handler for the door. What code do you need? How do you cooperate with the remaining
system? (2p)
When you are completely done with all assignments you right-click the desktop and select
“Finish exam”. Click OK when asked to confirm, your files are saved even if the session is
not. You get to a “relogin” page and should select “Quit” and confirm that. When you are
back at the normal blue login screen you can leave.
5 (6)
TDDI11.2012-05-31.08-12
State machine drawing template sheet
Write state names in circle. Write action(s) on line(s) below circle. Draw transitions and state
condition for each transition as needed. You do not have to use all circles. You may add
additional states. You may ask for a new template.
Inputs to this state machine:______________________________________________
Outputs to this state machine:_____________________________________________
Period this state machine run at:___________________________________________
6 (6)
Download