solutions.txt Jun 20 2012 14:29 Page 1 Page 2

advertisement
Jun 20 2012 14:29
solutions.txt
Page 1
Jun 20 2012 14:29
solutions.txt
Page 2
TDDI11 2012−05−31 Solution proposal. Several "overkill" answers.
Upg3 3p
Upg1 3p
a)
Single functioned. It often solves only one task.
Complex functionality. The task is often complex to solve.
Reactive. It reacts to sensor events and sets actuators in response.
Real−time. It may have a deadline on how fast to produce the response.
Controls it’s environment. The sensors and actuators is controlled.
b)
A rocket stabilizer.
Only function is to steer rocket straight up.
It’s a vary complicated task involving accurate calculations of position as well as o
rientation.
It has to react to changes, like wind, that take the rocket off course.
It has to react within some precalculated time, or it’s too late to steer straight (o
nce the rocket tilt too much it can’t be steered back, or start to break apart).
It controls it’s environment (the rocket thrusters).
All embedded systems do not have to have all characteristics, but most have several.
Upg2 5p
a)
Common non−functional requirements set on the system is
* performance
* unit cost
+ physical size (or weight)
+ power consumption (battery time)
− durability
− flexibility
− quality
− reliability
− safety
− user−friendliness
− stability
~ correctness
~ development time (time−to−market)
~ maintainability
~ non−recurrent engineering cost
* was given and do not score.
− is a bit too generic and nonspecific to be really good answers without further elab
oration, perhaps some special "quality", like "robust to physical strain", or some sp
ecific "user−friendliness" like "possible to control by feeling the shape of the cont
rols, without actually looking"
~ is also aiming towards the development process
b)
A semaphore is a functional unit that counts free resources of some kind. Threads can
call it to consume (or "lock") a resource, and to produce (or "unlock" a resource. I
f no resources is available in the semaphore when a thread try to consume it will for
ce the thread to stop and wait until one resource is available. It is commonly used t
o enforce mutual exclusion among critical code sections, for example when writing a p
acket to a serial port (serial port is then one resource). It the thread writing the
packet is interrupted halfway an someone else use the serial port the packet will be
corrupted or incomplete. By always (in all threads) lock a resource before using the
serial port, and unlock when packet is sent, threads will be forced to wait until the
serial port is free (no−one write to it).
c)
A memory map described how various hardware devices are connected to the memory bus a
nd how it uses the memory addresses. It give the programmer a clue of which addresses
that are reserved and how to use them.
a)
Assumption: Low byte of the 2−byte word is on low address.
mov
mov
add
mov
reg1
reg2
reg1
[C+0]
[A+0] ;; must dereference address with []
[B+0]
reg2 ;; do not use adc, that will add in a random carry
reg1
mov
mov
adc
mov
reg1
reg2
reg1
[C+1]
[A+1] ;; must add 1 to get to high byte
[B+1]
reg2 ;; use adc, it will add in carry from previous add
reg1
Use only what are in the specification.
Other instructions are not mentioned in the assignment.
b)
Any B > 0 will result in overflow if A == 2^16−1 (0xFFFF).
Any 16−bit overflow can be determined by checking the carry flag generated by the las
t addition (adc).
Upg4 4p
a)
Optimization is best done when the application tested and works correct, but is deter
mined to be to slow or too memory intense, or too power hungry.
b)
Two things enough to score.
We can optimize for high speed (often require more memory)
We can optimize for low binary application size (may sacrifice speed)
We can optimize for low runtime memory consumption (may sacrifice speed)
We can optimize power consumption (may affect both speed and response time)
c)
To optimize for speed:
− Turn on compiler optimization. Easy thing with almost no negative.
− Determine the slow part of program and write hand−crafted assembly for that part. V
ery time consuming and error−prone. Both (time and error) is very costly.
Upg5 4p
a)
To organize the work effectively and to ensure a high quality output of the work effo
rt. The process help by defining the important steps to perform, and their order, hel
ps to prioritize and divide the work, helps to find problems early, helps to manage d
ocumentation and communication, and helps to collect experiences in order to improve
in future projects.
b)
If I am asked to do an application relatively unknown to my project team and no speci
fic time limit. Successive refinement helps to learn the application area step by ste
p. first focusing on the most important product core and based on the first prototype
expanding to more advance models with experiences from the prototype "in store".
c)
If my project team need to do a product we have previous knowledge of, and have a har
d close time limit successive refinement may be too slow or uncalled for, there may b
e time for only one iteration. We may be better off with a model suited to a known pr
oduct domain (waterfall?) or a model saving time (hw/sw−codesign?).
d)
Spiral model, Waterfall model, Hardware/Software codesign
1
Jun 20 2012 14:29
solutions.txt
Upg6 14p (See /home/TDDI11/lab/skel/microwave/ for skeleton files)
//
//
//
//
Each pint below in solutions rated according to:
− not fulfilled
~ intermediate
+ fulfilled
// Upg6a)
//***0p
// + updates all positions (ready handled ok)
// + no complete enumeration of hard coded cases x2
// + clear bits ok
// + set bits ok
// + masks ok
// Upg6b)
//***0p
// Upg6c)
//***0p
// + door must be opened
// + time must be set
// + countdown works correct
// + beeps for one second when done
// + pause when opened
// + clear quality state machine drawing
// + outputs set in all states
// + clear quality implementation
// & 3F both off, 7F beep off, BF wave off
// | 80 beep on, 40 wave on, C0 both on
// Upg6d)
//***0p
// + SET_TIME have 200ms period
// + HEAT have 50ms period
// + all three modules called in good order
// + pointless counter removed (or made good use of)
a)
/* The second best solution (what can be better?)
* − Use bit−manipulation from lab1
* − Use polling from lab3
* − Use Time calculation skills from lab4
*/
void set_display(int value)
{
int pos;
byte out = B;
for ( pos = 3; pos >= 0; −−pos)
{
out = (out & 0xC0) | (pos << 4) | (value % 10);
value /= 10;
while ( ! READY )
;
READY = 0;
B = out;
Page 3
Jun 20 2012 14:29
solutions.txt
Page 4
/* Simple solution to set one position (some reduced points) */
void set_display(int value, int pos)
{
byte out = (B & 0xC0) | (pos << 4) | (value & 0x0F);
while ( ! READY )
;
READY = 0;
B = out;
}
/* Simple solution to set one position (more reduced points) */
void set_display_low_second(int value)
{
while ( ! READY )
;
READY = 0;
B &= 0xC0; // clear bits
B |= 0x30; // set position 3
value &= 0x0F;
B |= value;
}
b)
/* Solution according to specification */
void seconds_to_display(int seconds)
{
set_display(seconds / 60 * 100 + seconds % 60);
}
/* Simple solution (reduced points) */
void seconds_to_display(int seconds)
{
int min = seconds / 60;
int sec = seconds % 60;
set_display_low_second(sec % 10);
set_display_high_second(sec / 10);
set_display_low_minute(min % 10);
set_display_high_minute(min / 10);
}
c)
/* Actual solution code not given here. Many state machines
* possible. Points given from drawing alone.
* − Use given example state machine and knowledge from lab6
* − Exercise: implement a good state−machine.
*/
d)
−
−
−
−
−
Timer period should be 50ms to meet requirement 3
Set_Time is called first (so Heat can see set time immediately)
Set_Time is called only when (count%4 == 0) to get 200ms
Heat is called next (so set_display will show countdown immediately)
set_display is called last
}
}
2
Jun 20 2012 14:29
solutions.txt
Page 5
Upg7 7p
a)
It is a Mealy machine due to "clock" output being set depending on both the current s
tate and the inputs.
b)
Yes, it’s a problem:
It is never a good idea for two different code modules to write to a common shared va
riable (unless a special protocol for the updates is established). It becomes hard to
know the value of the global, and the value become indeterministic − it may depend o
n the calling order of individual functions. If the code later is made multi−threaded
the problems become worse with possible synchronization errors where one update may
overwrite the other, causing the display to show junk.
No, it’s not a problem.
The two functions that use clock are called from a single thread in sequential order.
The updates can not interfere with each other. The specification of each state machi
ne clearly specifies that clock is output of each state machine to avoid any future c
onfusion.
c)
The machine should detect also key releases to avoid detecting a press twice. By runn
ing the machine more often chances to miss a press is reduced (but chances to detect
several increased if key releases is not sensed). Detecting releases removed the adva
ntage to be able to hold the button pressed to increase many times fast. Also possibl
e to connect button to interrupt pin and configure to sense presses. Interrupt handle
r is called once per press if button is properly debounced.
d)
100kHz clock generates and 8−bit counter. Generates interrupt every 256 ticks by defa
ult. That’s every 2560 micro second, or every 2.56ms. 50ms / 2.56ms is 19.53125, so w
e need to count 19.53125 interrupts. Thats not an exact number.
Reset counter to 6 on each interrupt to get interrupt every 250 tick or 2.5ms and cou
nt 20 interrupts to get an exact measurement. Other configurations is possible.
e)
Figure two is correct since READY is pulled low before update of B in both cases.
Optional question 2p
Let the interrupt handler for the new door interrupt turn off the microwave beam imme
diately to meet the safety requirement (req 3). The Heat state machine can now be run
at a more convenient 1 second interval. The interrupt handler should arrange for the
Heat state machine to be called again as soon as the handler is done (let the timer
period elapse for example). This is needed to avoid a fatal mistake: assume the door
interrupt interrupts the Heat state machine just before it will turn on microwave bea
ms on B output. Heat will then turn on beams again just after the interrupt and leave
it on for a full second (with door open!). Other solutions to this problem exists. O
ther pitfalls exists.
3
Download