Spring 2021
Spring 2021
FACULTY OF ENGINEERING
Computer and Systems Engineering Department
Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. Maximum Marks: 60 Marks 1 / 12
�ﻌﻠﻴﻤﺎت هﺎﻣﺔ
.ﺣﻴﺎزة اﻟﺘﻴﻠﻔﻮن ا�حﻤﻮل ﻣﻔﺘﻮﺣﺎ داﺧﻞ �جﻨﺔ اﻷﻣﺘﺤﺎن �ﻌﺘ�� ﺣﺎﻟﺔ ﻏﺶ �ﺴﺘﻮﺟﺐ اﻟﻌﻘﺎب و�ذا �ﺎن ﺿﺮورى اﻟﺪﺧﻮل ﺑﺎ�حﻤﻮل ﻓﻴﻮﺿﻊ ﻣﻐﻠﻖ �� ا�حﻘﺎﺋﺐ •
Power: mark Exam Model as A .ﻻ �ﺴﻤﺢ ﺑﺪﺧﻮل ﺳﻤﺎﻋﺔ اﻷذن أو اﻟﺒﻠﻮﺗﻮث •
Comp & Comm: mark Exam Model as B .ﻻ�ﺴﻤﺢ ﺑﺪﺧﻮل أي ﻛﺘﺐ أو ﻣﻼزم أو أوراق داﺧﻞ اﻟ�جﻨﺔ وا�خﺎﻟﻔﺔ �ﻌﺘ�� ﺣﺎﻟﺔ ﻏﺶ •
For each of the following 60 multiple choice questions (MCQs), select ONLY the ONE correct answer. Mark
your choice on the answer bubble sheet. .............................................. [The 60 MCQs are equal in weight]
1. How many general-purpose registers do ARM Cortex-M processors have?
A) 10 B) 11 C) 13 D) 15
2. Which register is used to point to the next instruction to be fetched in ARM Cortex-M processors?
A) R13 B) R14 C) R15 D) R16
3. Which register is used to store the return address in ARM Cortex-M processors?
A) R13 B) R14 C) R15 D) R16
4. Which register is the stack pointer in ARM Cortex-M processors?
A) R13 B) R14 C) R15 D) R16
5. Which PSR flag in ARM Cortex-M processors indicates a negative result?
A) Z flag B) N flag C) C flag D) V flag
6. Which PSR flag in ARM Cortex-M processors indicates an unsigned overflow?
A) Z flag B) N flag C) C flag D) V flag
7. Which PSR flag in ARM Cortex-M processors indicates a signed overflow?
A) Z flag B) N flag C) C flag D) V flag
8. Which PSR flag in ARM Cortex-M processors indicates a zero result?
A) Z flag B) N flag C) C flag D) V flag
9. What is the size of the Flash ROM in the TM4C microcontroller?
A) 32 KB B) 64 KB C) 128 KB D) 256 KB
10. Which bus is connected to the Data RAM in ARM Cortex-M processors?
A) Advanced High-perf Bus (AHB) B) DCode bus C) ICode bus D) System bus
11. Which bus(s) is(are) connected to the Instructions Flash ROM in ARM Cortex-M processors?
A) DCode bus B) ICode bus C) System bus D) Answers (A) and (B)
12. A serial communication channel that does not have a clock signal is said to be
A) Asynchronous B) Parallel C) Synchronous D) UART
13. The letter A in UART stands for
A) Accumulator B) ASCII C) Asymmetric D) Asynchronous
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 2 / 12
PROG1 Q14—Q24
#define L_PIN 0x01U // PF0 is connected to Lower-Level (L) sensor
1
#define ALARM_LED_PIN <CONST1> // PF1 is connected to ALARM LED (Red)
2 #define P_PIN <CONST2> // PF2 is connected to water pump
3 #define ON_LED_PIN <CONST3> // PF3 is connected to ON LED (Green)
#define U_PIN 0x10U // PF4 is connected to Upper-Level (U) sensor
#define COUNTER_TH 100000 // Threshold counter value
#define PUMP_OFF 0
#define PUMP_ON 1
#define PUMP_ALARM 2
#define ON 1
#define OFF 0
void Controller_Init(void);
void Set_PIN(unsigned char, unsigned char);
4
unsigned char Get_PIN(unsigned char);
int main(void){
unsigned char old_L, old_U; current_L, current_U, state;
unsigned long on_state_counter;
Controller_Init();
state=PUMP_OFF;
on_state_counter=0;
for(;;){
current_L=Get_PIN(L_PIN); current_U=Get_PIN(U_PIN);
if (state==PUMP_OFF){
5 if (<C1>) state=PUMP_ON;
6 Set_PIN(P_PIN,V1); Set_PIN(ON_LED_PIN,V2); Set_PIN(ALARM_LED_PIN,V3);
7 } else if(state==PUMP_ON){
8 if (<C2>) state=PUMP_OFF;
9 if (<C3>){state=PUMP_ALARM; on_state_counter=0;}
10 if(!current_L) on_state_counter+=1;
11 Set_PIN(P_PIN,V4); Set_PIN(ON_LED_PIN,V5); Set_PIN(ALARM_LED_PIN,V6);
} else if(state==PUMP_ALARM){
12
on_state_counter+=1;
13 if (<C4>){state=PUMP_ON; on_state_counter=0;}
14 Set_PIN(P_PIN,V7); Set_PIN(ON_LED_PIN,V8); Set_PIN(ALARM_LED_PIN,V9);
}
old_L=current_L; old_U=current_U;
15
}
}
16 void Controller_Init(void){
SYSCTL_RCGCGPIO_R |= 0x00000020; // Activate PORTF
while((SYSCTL_PRGPIO_R&0x00000020)==0);
17
GPIO_PORTF_DIR_R = 0x0E; GPIO_PORTF_PUR_R = 0x11; GPIO_PORTF_DEN_R = 0x1F;
}
18 unsigned char Get_PIN(unsigned char PIN){
<S1>
19
}
20 void Set_PIN(unsigned char PIN, unsigned char value){
if (value) GPIO_PORTF_DATA_R |= PIN;
21 else GPIO_PORTF_DATA_R &= ~PIN;
}
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 4 / 12
PROG2 Q25—Q32
void UART_Init(void);
1
void UART_OutChar(char data){
2 while((UART0_FR_R&0x0020) != 0);
UART0_DR_R = data;
}
3 int main(void){
UART_Init();
for(;;){
4 UART_OutChar(<C1>);
}
5
}
void UART_Init(void){
SYSCTL_RCGCUART_R |= 0x00000001;
SYSCTL_RCGCGPIO_R |= 0x00000001;
6
UART0_CTL_R &=!0x00000001;
UART0_IBRD_R=43;
UART0_FBRD_R=26;
7 UART0_LCRH_R=0x00000070;
8 UART0_CTL_R=0x00000301;
9 GPIO_PORTA_AFSEL_R |= 0x03;
10 GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R &0xFFFFFF00)+0X0000011;
11 GPIO_PORTA_DEN_R |= 0x03;
12 GPIO_PORTA_AMSEL_R &= ~0x03;
13 }
25. In PROG2, if bus clock frequency is 80 MHz, the approximate baud rate, in bits per second, is
A) 4,600 B) 9,600 C) 19,200 D) 115,200
26. In PROG2, if <C1> in line 4 is set to 0x55 and noting that the UART is configured to handle 8-bit data with
no parity and one stop bit, the approximate frequency, in Hz, of the signal generated on serial output is
A) 9,600 B) 28,800 C) 57,600 D) 115,200
27. In PROG2, if <C1> in line 4 is set to 0xF0 and noting that the UART is configured to handle 8-bit data with
no parity and one stop bit, the approximate frequency, in Hz, of the signal generated on serial output is
A) 57,600 B) 11,520 C) 115,200 D) 1,152,000
28. In PROG2, the functionality of line 2 is to wait until
A) a new input is available B) receive buffer is not empty C) RXFE is 0 D) TXFF is 0
29. In PROG2, the functionality of line 2 can be described as
A) busy-waiting B) echoing C) inspection D) reviewing
30. In PROG2, the UART is configured to use one stop bit in
A) Line 7 B) Line 8 C) Line 9 D) Line 10
31. In PROG2, the UART is enabled in
A) Line 7 B) Line 8 C) Line 9 D) Line 10
32. In PROG2, the UART is configured to have no parity in
A) Line 7 B) Line 8 C) Line 9 D) Line 10
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 5 / 12
Q33—Q38: The following figure illustrates the linear relationship between the input wave to a servo motor
and the angle the motor rotates to. The servo motor controller runs PROG3 below on a TM4C
microcontroller. Some statements in PROG3 are not in the right order.
PROG3 Q33—Q38
#define MOTOR_PIN 0x02U
#define ON 1
1
#define OFF 0
#define PERIOD_MS 20 // Period of the input wave to the servo motor
void Controller_Init(void);
void delay_ms(<T1> v);
void Set_PIN(unsigned char, unsigned char);
float angle_2_time(unsigned char);
unsigned char Angles_Array []={00,45,90,180};
2
int main(void){
int i;
<T1> delay_time; unsigned char angle;
Controller_Init();
for(;;){
for (i=0;i<4;i++){
3 delay_time=PERIOD_MS-delay_time; delay_ms(delay_time);
4 delay_time=angle_2_time(angle); delay_ms(delay_time);
5 Set_PIN(MOTOR_PIN,OFF);
6 angle=Angles_Array[i];
7 Set_PIN(MOTOR_PIN,ON);
}
8 }
}
9 <T1> angle_2_time(unsigned char angle){
10 return (<E1>);
11 }
12 void delay_ms(<T1> v){
13 unsigned long i=0;
14 unsigned long d=v*(<S1>);
while(i<d) i++;
15
}
void Set_PIN(unsigned char PIN, unsigned char val){
if (val) GPIO_PORTF_DATA_R |= PIN;
else GPIO_PORTF_DATA_R &= ~PIN;
}
void Controller_Init(void){
16 SYSCTL_RCGCGPIO_R |= 0x00000020; // Activate PORTF
while((SYSCTL_PRGPIO_R&0x00000020)==0);
GPIO_PORTF_DIR_R=0x0E; // PF0 and PF4 as input and PF3-1 as output
GPIO_PORTF_PUR_R=0x11; // Enable pull-up on PF0 and PF4
GPIO_PORTF_DEN_R=0x1F; // Enable digital I/O on PF4-0
}
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 6 / 12
33. In PROG3, line 10, equation <E1> (used to convert an angle to input pulse duration in ms) should be
A) 1-angle*(1.0/180) B) 1+angle*(2.0/360) C) 1+angle*(1/180) D) 1+angle*(2.0/180)
34. In PROG3, if the input pulse duration is 1.75 ms, the angle the motor will rotate to will be
A) -135o B) -67.5o C) 67.5o D) 135o
35. In PROG3, block lines 2 and lines 9 and 12, datatype <T1> should best be set to
A) int B) unsigned int C) long D) float
36. In PROG3, if the controller uses a 16-MHz clock, function delay_ms(1.0) is called to insert a 1-ms delay,
and a single loop iteration at line 15 takes 5 cycles, integer value <S1> in line 14 should be
A) 80 B) 800 C) 1600 D) 3200
37. In PROG3, assume that <S1> is set as in the previous question and that the loop at line 15 is changed so
that a single iteration takes 6 cycles instead of 5. If function delay_ms(1.5) is called to produce a 1.5-ms
pulse to have the motor rotate 90o, the actual angle the motor will rotate to will be
A) 36o B) 91o C) 95o D) 144o
38. In PROG3, the correct order for lines 3—7 should be
A) 6-7-3-5-4 B) 6-7-4-5-3 C) 7-6-4-5-3 D) 6-5-4-7-3
Q39—Q44: Four TM4C microcontrollers are
connected in a ring using UART, as shown in the figure
to the right. The transmitter line of one
microcontroller is connected to the receiver line of its
neighbor to form a ring. Each microcontroller defines
a unique address for itself using two dip switches
connected to PF0 (least bit) and PF4. Exchanged
messages consist of 3 characters; first character
defines the sender address; second one defines the
receiver address; and the third defines the receiver
LED state to set to. As an example, if microcontroller
0 wants to switch on the LED on microcontroller 2,
the message will be “021” and to switch it off, the
message should be “020”. When receiving a message, a microcontroller checks the second character, if it
matches its address, then the microcontroller should apply the received setting to its LED; otherwise, the
microcontroller forwards the message to its neighbor. If a message comes back to its sender that means that
the receiver address does not match any microcontroller on the ring and that message should be dropped.
PROG4 (on the next page) is running on each microcontroller. In PROG4, each microcontroller tries to switch
its LED ON through the ring connection. Some statements in PROG4 are not in the right order.
39. In PROG4, line 2, expression <E1> (used to get the microcontroller own address should be
A) A0+A1 B) A0*2+A1 C) A0*2+A1*4 D) A0+A1*2
40. In PROG4, lines 3 and 6, <X> should be
A) 0 B) '0' C) 1 D) '1'
41. In PROG4, line 5, assuming that <X> is set as in the previous question, condition <C1> should be
A) RecAdd==myAdd+<X> B) RecAdd!=myAdd+<X> C) TranAdd==myAdd+<X> D) TranAdd!=myAdd+<X>
42. In PROG4, line 8, assuming that <X> is set as in the previous question, condition <C2> should be
A) RecAdd==myAdd+<X> B) RecAdd!=myAdd+<X> C) TranAdd==myAdd+<X> D) TranAdd!=myAdd+<X>
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 7 / 12
Q45—Q50: A display is connected to a microcontroller running PROG8 to display all UART output.
PROG8: Q45—Q50 .ﺳﺆال ﻣﺨﺼﺺ ﻟﻄﻠبﺔ ﻗﺴﻢ ﺣﺎﺳبﺎت وﻃﻠبﺔ ﻗﺴﻢ إﺗﺼﺎﻻت ﻓﻘﻂ
void Controller_Init(void);
void UART_Init(void); // Configure UART0
void UART_OutChar(char); // Send a char on UART0
void EnableInterrupts(void); // Enable interrupts
int main(void){
Controller_Init(); UART_Init();
1
UART_OutChar('A');
for(;;);
UART_OutChar('C');
}
void GPIOF_Handler(void){
UART_OutChar('B');
GPIO_PORTF_ICR_R=0x10;
2
}
void Controller_Init(void){
SYSCTL_RCGCGPIO_R |= 0x00000020; // Activate PORTF
while((SYSCTL_PRGPIO_R&0x00000020) == 0){};
SYSCTL_RCGCGPIO_R |= 0x00000020; // Activate clock for PORTF
GPIO_PORTF_DIR_R &= ~0x10; // Make PF4 a built-in button
GPIO_PORTF_DEN_R |= 0x10; // Enable digital I/O on PF4
3 GPIO_PORTF_PUR_R |= 0x10; // Enable weak pull-up on PF4
GPIO_PORTF_IS_R &= ~0x10; // PF4 is edge-sensitive
GPIO_PORTF_IBE_R &= ~0x10; // PF4 is not both edges
GPIO_PORTF_IEV_R &= ~0x10; // PF4 falling edge event
GPIO_PORTF_ICR_R = 0x10; // Clear flag4
GPIO_PORTF_IM_R |= 0x10; // Enable ARM interrupt on PF4
NVIC_PRI7_R=(NVIC_PRI7_R&0xFF00FFFF)|0x00A00000; // Priority 5
4 NVIC_EN0_R=0x40000000; // Enable interrupt 30 in NVIC
EnableInterrupts(); // Enable interrupts
5
}
45. In PROG8, the message displayed, if no action occurs on PF4 after resetting the microcontroller is
A) A B) AC C) ACB D) ABC
46. In PROG8, the message displayed, if PF4 is changed from zero to one after resetting the microcontroller is
A) A B) AB C) ACB D) ABC
47. In PROG8, the message displayed, if PF4 is changed from one to zero after resetting the microcontroller is
A) A B) AB C) ACB D) ABC
48. In PROG8, the message displayed, if PF4 is changed from one to zero then from zero to one again after
resetting the microcontroller is
A) A B) AB C) ACB D) ABC
49. In PROG8, assume line 2 is removed, the message displayed, if PF4 is changed from one to zero then
from zero to one again after resetting the microcontroller is
A) A B) AB C) ABB D) ABBBBBBB …to infinity
50. In PROG8, assume line 4 is removed, the message displayed, if PF4 is changed from one to zero then
from zero to one again after resetting the microcontroller is
A) A B) AB C) ABB D) ABBBBBBB …to infinity
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 11 / 12
PROG9 Q51—Q56 .ﺳﺆال ﻣﺨﺼﺺ ﻟﻄﻠبﺔ ﻗﺴﻢ ﺣﺎﺳبﺎت وﻃﻠبﺔ ﻗﺴﻢ إﺗﺼﺎﻻت ﻓﻘﻂ
AREA WRITE_variables, DATA, READWRITE
a space 4
b space 4
1
s_size equ 12
s_b space s_size ; Stack base address
AREA MYCODE, CODE, READONLY
2 ldr sp, =s_b
3 add sp, #s_size
4 ldr r0, =a
5 mov r4, #3
6 str r4, [r0]
7 ldr r1, =b
8 mov r4, #5
9 str r4, [r1]
10 ldr r2, [r0]
11 ldr r3, [r1]
12 add r2, #1
13 add r3, #1
14 bl func
15 b stop
func
16
push {r2-r3}
17 ldr r2, [r0]
18 ldr r3, [r1]
19 str r2, [r1]
20 str r3, [r0]
21 pop {r2-r3}
bx lr
22 stop
END
51. In PROG9, the value of r2 at the end of the program is
A) 2 B) 3 C) 4 D) 5
52. In PROG9, the value of r3 at the end of the program is
A) 2 B) 4 C) 5 D) 6
53. In PROG9, the content of variable a in memory before calling function func is
A) 3 B) 4 C) 5 D) 6
54. In PROG9, the content of variable a in memory after calling function func is
A) 1 B) 3 C) 4 D) 5
55. In PROG9, function func is used to
A) Swap the contents of registers r2 and r3 B) Swap the contents of registers r0 and r1
C) Swap the contents of variables a and b in memory D) Swap the contents of registers r0 and r2
56. In PROG9, the value of SP after line 19 is
A) s_b-8 B) s_b+20 C) s_b+4 D) s_b+8
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer and Systems Engineering Department, Junior Electrical Engineering (Computer & Electronics & Power)
Spring 2021 Course Code: CSE 211 Time Allowed: 2 Hrs.
INTRODUCTION TO EMBEDDED SYSTEMS
The Exam Consists of 60 Questions in 12 Pages. 12 / 12
PROG10 Q57—Q60 .ﺳﺆال ﻣﺨﺼﺺ ﻟﻄﻠبﺔ ﻗﺴﻢ ﺣﺎﺳبﺎت وﻃﻠبﺔ ﻗﺴﻢ إﺗﺼﺎﻻت ﻓﻘﻂ
AREA READ_variables, DATA, READONLY
A DCD 5
1 AREA WRITE_variables, DATA, READWRITE
Z DCD 0
AREA MYCODE, CODE, READONLY
2 LDR r0, =A
3 LDR r1, [r0]
4 MOV r2, #1
5 CMP r1, #0
6 BLE LOC2
LOC1
7
MUL r3, r2, r1
8 MOV r2, r3
9 SUB r1, r1, #1
10 CMP r1, #0
11 BLE LOC2
12 B LOC1
LOC2
13
LDR r4, =Z
STR r2, [r4]
14
END
57. In PROG10, the value of r1 after the first execution of line 9 is
A) 0 B) 4 C) 5 D) 24
58. In PROG10, the value of r3 after the second execution of line 7 is
A) 0 B) 1 C) 4 D) 20
59. In PROG10, the value of r1 after the execution of line 13 is
A) 0 B) 1 C) 4 D) 5
60. In PROG10, the value of r2 after the execution of line 14 is
A) 100 B) 120 C) 130 D) 150
END of Exam