2012 Solutions PDF
2012 Solutions PDF
2012 Solutions PDF
2012 - solutions
Monash University
Semester One Examination Period
2012
Faculty Of Engineering
During an exam, you must not have in your possession, a book, notes, paper, calculator,
pencil case, mobile phone or other material/item which has not been authorised for the exam
or specifically permitted as noted below. Any material or item on your desk, chair or person
will be deemed to be in your possession. You are reminded that possession of unauthorised
materials in an exam is a discipline offence under Monash Statute 4.1.
1. Attempt ALL questions. Candidates are asked to answer all questions in the
spaces provided in the examination paper. This paper consists of 4 questions.
2. Exam paper is printed on single sided paper. Therefore, use the reverse side of
any of these pages as scrap paper for any working or calculations that are
required in deriving your answers. THESE WORKINGS HOWEVER WILL
NOT CARRY ANY MARKS TOWARDS YOUR FINAL ANSWERS.
AUTHORISED MATERIALS
CALCULATORS o YES ü NO
OPEN BOOK o YES ü NO
SPECIFICALLY PERMITTED ITEMS o YES ü NO
Q1 Q2 Q3 Q4 Total Marks
Candidates must complete this section if required to write answers within this paper
The following program provides service for two peripheral circuits (a and b)
responding to external events.
loop:
mov r0,status_reg_a ;read contents of status_reg_a (1 T-state)
and r0,#0002h ;test bit 1 (1 T-state)
jmpa cc_NZ,service_a ;if bit set jump to service routine (2/1 T-state/s)
mov r0,status_reg_a ;read contents of status_reg_a (1 T-state)
and r0,#0002h ;test bit 1 (1 T-state)
jmpa cc_NZ,service_a ;if bit set jump to service routine (2/1 T-state/s)
mov r0,status_reg_b ;read contents of status_reg_b (1 T-state)
and r0,#0008h ;test bit 3 (1 T-state)
jmpa cc_NZ,service_b ;if bit set jump to service routine (2/1 T-state/s)
jmpa cc_UC,loop ;jump to start of polling loop (2 T-states)
Note that the T-states given for each instruction are for the purposes of this question
only. In a jump instruction the first number of T-states applies if the jump is taken,
the second if execution continues straight on.
For maximum latency, the instruction is assumed to be read at the very beginning and the input port changes slightly after
the read instruction.
mov r0, status_reg_a 1T
and r0, #0002h 1T
jmpa cc_NZ,service_a 1T
mov r0, status_reg_b 1T
and r0,#0008h 1T
jmpa cc_NZ,service_b 1T
jmpa cc_UC,loop 2T
mov r0,status_reg_a 1T
and r0,#0002h 1T
jmpa cc_NZ,service_a 2T Total: 12T
For minimum latency, the instruction is assumed to be read at the very end and the input port changes slightly before the
read instruction.
and r0, #0002h 1T
jmpa cc_NZ,service_a 2T Total: 3T
For maximum latency, the instruction is assumed to be read at the very beginning and the input port changes slightly
after the read instruction.
mov r0, status_reg_b 1T
and r0,#0008h 1T
jmpa cc_NZ,service_b 1T
jmpa cc_UC,loop 2T
mov r0,status_reg_a 1T
and r0,#0002h 1T
jmpa cc_NZ,service_a 1T
mov r0, status_reg_a 1T
and r0, #0002h 1T
jmpa cc_NZ,service_a 1T
mov r0,status_reg_b 1T
and r0,#0008h 1T
jmpa cc_NZ,service_b 2T Total:15T
For minimum latency, the instruction is assumed to be read at the very end and the input port changes slightly before
the read instruction.
and r0, #0008h 1T
jmpa cc_NZ,service_b 2T Total: 3T
write
ii) interface a light emitting diode to a microcomputer bus so that it can be switched
on or off under program control.
ii) Describe how the dual slope analogue to digital converter functions. Your
description should incorporate the equations governing its operation.
There are two phase of the operation. The switch will be connected to the unknown input voltage Vin and
it is integrated for a fixed time Ti = Ni*Tc. The resulting integrator voltage V is::
The second measurement phase involves integrating the reference voltage -Vref until the integrator output
returns to zero.
Therefore
as Nx is proportional to Vin
iii) Explain the advantages and disadvantages of the dual slope analogue to
digital converter.
Advantages: 1) The dual slop ADC are able to reject high frequency noise which acts like a low-pass filter.
2) Stable.
Disadvantages: 1) Accuracy depends on Vref and the short term stability of time measurement.
2) Relatively slow due to integrating converter.
ii) Draw a diagram showing the major components of a practical sample and
hold circuit.
The input operational amplifier will have a high input impedance so that they do not load the signal source
and a low output impedance so that the capacitor can be charged quickly during sample mode. The output
operational amplifier will have a high input impedance so that they do not discharge the capacitor quickly
during hold mode and a low output impedance to drive an external load. The feedback ensures the whole
circuit has a unity gain. The digital control will determines whether its in sample or hold mode.
With regard to sample and hold devices, explain what is meant by the following
terms:
i) acquisition time,
Acquisition time is the delay where the device changes from hold to sample until the output voltage
matches the input voltage.
OS_EVENT *sem;
while(1){
Out1 = 0;
OSTimeDly(2);
OSSemPend(sem,0,&err);
Out1 = 1;
OSTimeDly(1); /* Delay by 1 timer tick */
OSSemPost(sem);
}
}
void task2(void* pdata)
{
INT8U err;
while(1){
Out2 = 0;
OSTimeDly(1);
OSSemPend(sem,0,&err);
Out2 = 1;
OSTimeDly(1);
OSSemPost(sem);
}
}
void task3(void* pdata)
{
printf(“Ticks: Out1 Out2\n”);
while (1){
printf(“%ld: %d %d\n”, OSTimeGet(), Out1, Out2);
OSTimeDly(1);
}
}
int main(void)
{
OSTaskCreateExt(task1,
NULL,
(void *)&task1_stk[TASK_STACKSIZE-1],
TASK1_PRIORITY,
TASK1_PRIORITY,
task1_stk,
TASK_STACKSIZE,
NULL,
0);
OSTaskCreateExt(task2,
NULL,
(void *)&task2_stk[TASK_STACKSIZE-1],
TASK2_PRIORITY,
TASK2_PRIORITY,
task2_stk,
TASK_STACKSIZE,
NULL,
0);
OSTaskCreateExt(task3,
NULL,
(void *)&task3_stk[TASK_STACKSIZE-1],
TASK3_PRIORITY,
TASK3_PRIORITY,
task3_stk,
TASK_STACKSIZE,
NULL,
0);
sem = OSSemCreate(1);
OSStart();
return 0;
}
For the above C code running under the uC/OS-II real time kernel, show what output
is produced below. Assume that OSStart() is called just after time 0 and after each
system timer interrupt, the time produced by calling OSTimeGet() increments by 1.
You may assume that the execution time of a line of code is much shorter than a timer
tick. In your answer show just 12 lines of output from the printf statements.
Ticks: Out1 Out2
0: 0 0
1: 0 1
2: 1 0
3: 0 1
4: 0 0
5: 1 0
6: 0 1
7: 0 0
8: 1 0
9: 0 1
10: 0 0
……………………………………………………………………………………..
10
Repeat Question 3.1 except swap the priorities of task1 and task2 by substituting the
code after
#define TASK1_PRIORITY 2
#define TASK2_PRIORITY 1
……………………………………………………………………………………..
Explain how the uC/OS-II real time kernel measures the utilisation of a CPU when
multiple tasks are running. Your answer should outline the initialisation steps that are
performed and any assumptions, as well as the steps taken when multiple tasks are
running.
The idle task increments as integer OSIdleCtr.
Assumption: The initialization OSStatInit() must be called with just the one task running that makes this call.
OSStatInit() measures the OSIdleCtr over a period of 1 second and this is called OSIdleCtrMax. It is a maximum
since no other tasks can consume CPU cycles except the idle task during that second.
While all tasks are now running, a 2nd lowest priority task called the statistics task records the OSIdleCtr after
every second and calculates the utilisation as below. The statistic task then resets OSIdleCtr to 0 and sleeps for
another second and repeats.
The % utilisation is then [1-(OSIdleCtr/OSIdleCtrMax)]*100
Which is optimized as 100-OSIdleCtr/[OSIdleCtrMax/100] for integer arithmetic.
One additional assumption is that the utilisation is low enough to allow the statistic task to run every second.
11
……………………………………………………………………………………..
Explain how priority inversion can arise when using semaphores to protect a shared
resource in a real time system. Include an example in your answer that has at least
three tasks of different priorities and a semaphore to coordinate access to a shared
resource.
A semaphore is initialized to 1 and used as a mutex for a shared resource.
A low priority task runs and waits on the semaphore, taking the resource. Before this task can complete, it is
pre-empted by a medium priority task that is computationally intensive and does not block for a long time.
A high priority task becomes ready to run and pre-empts the medium priority task. It then requests the shared
resource by waiting on the mutex semaphore, but is blocked since the low priority task holds the resource (and
is not running). Ideally the low priority task should now run and release the resource a signal on the semaphore,
but the medium priority task runs (for a long time) instead due to its higher priority. Thus the high priority task is
effectively blocked due to a low priority task holding the resource and not able to complete.
……………………………………………………………………………………..
12
How does uC/OS-II solve the problem of priority inversion with its implementation of
a mutex?
In the above scenario, when the high priority task waits on the mutex, the uC/OS-II mutex implementation raises
the priority of the low priority task temporarily to a preset high priority. This causes the low priority task to
complete quickly in preference to the medium task and thus release the resource quickly.
The following table shows a list of periodic processes with their associated execution times
and periods in a real time system.
What is the CPU utilisation that would occur if all processes are scheduled and meet their
deadlines?
(3+4+2+4)/16 = 13/16
…………………………
What is the number of msecs that will define the minimum cycle of scheduling?
16
…………………………..
13
For a Rate Monotonic Scheduling (RMS) policy, what priorities could be allocated to each of
the processes? Use 1 for highest priority in the following table.
Show how the processes would be scheduled to meet their deadlines using RMS in the
following table. P3 priority 2 shown first then P4 priority 2 after 'or'
14
Show how the processes would be scheduled to meet their deadlines using Earliest Deadline
First (EDF) scheduling policy in the following table.
15
The following C code has been compiled into NIOS-II assembly code as shown
below:
int i, my_array[4];
i = 0;
while (i<4){
my_array[i] *= 2;
i++;
}
fp - 16 I think it should be fp - 10
………………………………………..
0x00000384
………………………………………..
16
0x00000388 to 0x00000390
………………………………………..
r2 and r4
………………………………………...