CS计算机代考程序代写 assembly data structure compiler Kristianstad University DT131B: Embedded Systems Programming

Kristianstad University DT131B: Embedded Systems Programming
Examiner: Dawit Mengistu Note:
• Calculators are NOT allowed. NO other help materials are allowed;
• You can write your answers in English or/and Swedish
Date: 2019.06.03
• Write your answers clearly. No points will be given for unreadable answers
• The answer to each question should start on a new page.
• Pay special attention to underlined and bold face text to understand the key points and/or focus of the questions properly.
• Use the information in the attached pages as references or data sheet wherever applicable.
• Assume ATmega328P microcontroller unless stated otherwise.
• Assume the microcontroller’s clock speed at 1MHZ and operating voltage (Vcc) of +5V, unless stated otherwise.
• This examination has three parts.
o Part1 is about general computer organization and architecture concepts. o Part2 is about C programming.
o Part 3 is about Embedded Systems programming.
• A minimum of 30 points is required to pass this examination. Part I. General Concepts
Q1. Organization and Architecture
a) What are the advantages of SRAM over DRAM?
b) Which of the answers (i) to (iv) below is correct?
The AVR architecture corresponds to a ____ address machine. i) Zero ii) One iii) Two
(5 points)
(1p) (1p)
iv) Three
Hint: refer to the attached instruction set. Motivate your answer clearly. No points
given without motivation even if your answer is correct.
c) How do you determine the size of the bus system in a microcontroller? Explain how you determine the number of bus lines for each of the following: (3p)
i) Data bus ii) Address bus iii) Control bus

Q2. CPU Organization (5 points)
Explain the use of the following CPU registers. The number of points you earn for this question depends on the clarity and detail of your answers.
Q3.
Basic C
(10 points)
a) IR (1p) b) MBR (1p) c) MAR (1p) d) What are the functions of condition registers? (2p)
Part II. C Programming
a) Do long variable names affect program execution time? Explain why or why not? (1p)
b) What values do the following expressions have? How many bytes are used to represent
2+ j % i
i=j
(++ i < 3)? !j : j i && i – 3 d) Suppose n is an int of value 1011011 in binary. What does n & ~07 do? What value does this expression have? (1p) e) Explain your understanding on text file and binary file. Give one function that writes data to a text file and one function that writes data to a binary file. (1p) f) What is a union in C? Explain its usage. (1p) g) Explain what the buffer overflow bug is and give a simple example. (1p) h) What is the general structure of a for-loop in C. Re-write it in while-do loop. (1.5p) (1.5p) expression, respectively. What value does each of the following expression have? (2p) each of them in a 32-bit system? '2' "2" 2 c) Suppose that variables i and j have values 3 and 7 before each of the following Show how you get the result. Q4. Program Reading (5 points) a) Read the following C program carefully. What are the output when the program is executed. #include
int confusion1 (int x, int y)
{
x = 2 * x + y;
return x; }
int confusion2 (int *x, int *y)
{
int tmp;
tmp = *x + 2 * *y;
return tmp; }
int main (void)
{
int x = 2, y = 5;
y = confusion1 (y, x);
x = confusion1 (y, x); printf (“%d %d\n”, x, y); y = confusion2 (&y, &x); x = confusion2 (&y, &x); printf (“%d %d\n”, x, y); return 0;
}
b) C is a concise language. Read the following C function: void func ( char *s, char *t){
while (*s++ = *t++); }
What does this function do? Give an example to call this function.
(2p)
(1p)

c) Given the following C function: (2p) void myFunc( int array[], int n){
int c, d, t, i;
for (c = 1 ; c <= n - 1; c++) { d = c; while ( d > 0 && array[d-1] > array[d]) { t = array[d];
array[d] = array[d-1];
array[d-1] = t;
d–; }
for (i=0 ; i <5; i ++) printf("%d ", array[i]); printf("\n"); } } Suppose that you have the following data. How to call the above function to work with the data: int myData[ ] = { 10, 8, 7, 5, 2}; What does this function do? Q5. Data Structures (5 points) Develop a C program that manages books. Information on a book should include the followings: • Authors • Title • Number of pages • Publisher • Year of publication • Edition • Price Do the following tasks: a) Design a data structure to keep information about a book. (1p) b) Count by hand the number of bytes used to represent a book (1p) c) Develop a C function to read in a book from the keyboard (1p) d) Develop the main( ) function to allocate space for 10 books, to read in 10 books and find the cheapest and most expensive books. (2p) Part III. Embedded Systems Programming (Refer to the attached data sheets wherever needed) Q6. General Concepts (7 points) a) Your ATMega328P microcontroller has different types of memory. Explain the types of memory technologies used in the microcontroller. For each type of memory, explain how/why it is used. (2.5p) b) Discuss at least two reasons why we may use assembly programming in certain types of embedded applications. (1p) c) From implementation point of view, what is the difference between internal interrupts and external interrupts of the ATMega328P microcontroller? (1.5p) d) Integrated Development Environment tools (IDEs) such as Atmel Studio play an important role in embedded systems development. Explain the main features (functions) provided by IDEs such as Atmel Studio. (2p) Hint: Imagine that you have no IDE on your computer. What kinds of tools would you need to develop software for your microcontroller in the absence of a dedicated IDE like Atmel Studio? Q7. Programming Timers (8 points) The timer is one of the most powerful I/O units of the microcontroller. In practice, only few meaningful embedded applications are implemented without the timer. a) A microcontroller has an LED and a push button connected to it. Write a program (actual C code or C-like pseudocode) to control a blinking LED as follows: (4p) - The LED blinks continuously (ON-OFF) every 2 seconds, (2 seconds ON, 2 seconds OFF) - When the push button is pressed, blinking stops and the LED will be in the ON state forever. • Show your calculations, initialization of parameters, and your choice of values clearly. No marks given for unclear or incomplete answers. • You can choose any of the timers provided by ATMega328P datasheet. b) The above microcontroller shall be used to control a dimmer. (4p) - Initially, the dimmer gives a bright light because it is operated with an input of 4V. - When the button is pressed, the input shall be reduced to 2V so that the dimmer produces a low intensity light. • Write an actual C code or C-like pseudocode you shall use to control according to the above specifications. • Show your calculations and your choice of values clearly. No marks given for unclear or incomplete answers. Q8. Analog-to-Digital Converter (ADC) (8 points) The ADC is an essential I/O module of your microcontroller. Without it, we wouldn’t be able to record sound, read room temperature, humidity, etc. a) A microcontroller from TI (Texas instruments) has an 8-bit, 0-10V range ADC module. A musician is to use this microcontroller for recording a wind instrument clip using a microphone. • The sound of the instrument has frequency up to 5KHz. • The microphone can produce an output voltage in the range (0-10milli volts) while recording. i) Explain how you would set up the hardware including the signal conditioning circuit. Show your calculations clearly. (Use of diagrams is preferred.) (2p) ii) If the microcontroller has a storage capacity of 450KB, what is the maximum possible length of his recording? Motivate your answer. (1p) b) The musician in the problem above decides to use the ATMega328P microcontroller for his task. i) How does his decision affect your answers in (a) above? (1p) ii) You are requested to write an interrupt based code for this task (on ATMega). Show your implementation approach clearly. (4p) Note: • You may write actual C code or use C-like pseudocode and apply actual settings/parameters on the datasheet provided (attached). • The number of points you earn for this question depends on the readability, and level of detail you provide. Q9. Embedded software optimization Needless to say, optimization is a very important aspect in embedded systems software development. a) In your opinion, what are the main goals of code optimization? b) What is compiler optimization? How does it work? (7 points) (2p) (2p) c) Discuss at least three (3) ways or techniques you can apply to optimize your embedded software. (3p)