CPE/EE 323 Introduction to Embedded Computer Systems
Homework III
__ / __ / __ / ____
Problem #1 (40 points) Consider the following C program.
1 / #include "io430.h"2 / #include "stdio.h"
3
4 / int main(void) {
5 / // Stop watchdog timer to prevent time out reset
6 / WDTCTL = WDTPW + WDTHOLD;
7 / int x = 5; // an integer x
8 / int *p_x; // a pointer to int
9 / int y1; // an integer y1 (uninitialized)
10 / long int y2, y3; // long integers y2, y3
11 / long int *p_y2; // a pointer to long integer
12 / char mya[10] = "Hello!"; // character array
13 / char *p_mya; // pointer to character
14
15 / p_x = &x; // p_x points to x
16 / *p_x = 7;
17 / *p_x = *p_x + 2;
18 / y1 = 10 + x; // new value to y1
19 / y2 = -1;
20 / p_y2 = &y2; // pointer p_y2 points to y2
21 / *p_y2 = y2 + 3;
22 / y3 = 10 + *p_y2;
23 / p_mya = mya; // p_mya points to array mya
24 / p_mya = p_mya + 3;
25 / *p_mya = 'L';
26
27 / // display addresses and variables in terminal i/o
28 / printf("a.x=%x, x=%x\n", &x, x);
29 / printf("a.p_x=%x, p_x=%x\n", &p_x, p_x);
30 / printf("a.y1=%x, y1=%x\n", &y1, y1);
31 / printf("a.y2=%x, y2=%lx\n", &y2, y2);
32 / printf("a.y3=%x, y3=%lx\n", &y3, y3);
33 / printf("a.p_y2=%x, p_y2=%x\n", &p_y2, p_y2);
34 / printf("a.mya=%x, mya=%s\n", &mya, mya);
35 / printf("a.p_mya=%x, p_mya=%x\n", &p_mya, p_mya);
36 / return 0;
37 / }
A. (20 points). Illustrate the content of the stack at the moment (i) before the statement in line 15 is executed and (ii) before the statement in line 27 is executed. Use the comments fields to indicate the individual variables.
Orig. TOS / Memory[15:0] hex / Comments / Orig. TOS / Memory[15:0] hex / Comments
OTOS-2 / OTOS-2
OTOS-4 / OTOS-4
B. (20 points). For each statement from line 15 to line 25 show its assembly language implementation.
p_x = &x;
*p_x = 7;
*p_x = *p_x + 2;
y1 = 10 + x;
y2 = -1;
p_y2 = &y2;
*p_y2 = y2 + 3;
y3 = 10 + *p_y2;
p_mya = mya;
p_mya = p_mya + 3;
*p_mya = 'L';
Problem #2 (30 points) Microcontroller MSP430 is using 32KHz crystal connected to LFXT1 Oscillator, 8MHz crystal connected to XT2 Oscillator, and 3V power supply. See Appendix (pages 8-10) for necessary information.
Datasheet specifications:
fRsel+1 / fRsel = 1.65,
fDCO+1 / fDCO = 1.12,
DCOR: use internal Rosc
Set the following modes of operation (If the bit can be either 0 or 1, put X):
A. (5 points) processor clock (MCLK) to 8MHz, ACLK to 8KHz, SMCLK to 750 KHz.
BCSCTL1: 0x_____
XT2Off XTS DIVA.1 DIVA.0 XT5V Rsel2 Rsel1 Rsel0
BCSCTL2: 0x_____
SELM.1 SELM.0 DIVM.1 DIVM.0 SELS DIVS.1 DIVS.0 DCOR
DCOCTL: 0x_____
DCO.2 DCO.1 DCO.0 MOD.4 MOD.3 MOD.2 MOD.1 MOD.0
B. (5 points) processor clock to 840KHz, SMCLK to 420KHz, and ACLK to 32KHz.
BCSCTL1: 0x_____
XT2Off XTS DIVA.1 DIVA.0 XT5V Rsel2 Rsel1 Rsel0
BCSCTL2: 0x_____
SELM.1 SELM.0 DIVM.1 DIVM.0 SELS DIVS.1 DIVS.0 DCOR
DCOCTL: 0x_____
DCO.2 DCO.1 DCO.0 MOD.4 MOD.3 MOD.2 MOD.1 MOD.0
C. (5 points) processor clock to 2MHz, ACLK to 32 KHz, SMCLK to 1MHz.
BCSCTL1: 0x_____
XT2Off XTS DIVA.1 DIVA.0 XT5V Rsel2 Rsel1 Rsel0
BCSCTL2: 0x_____
SELM.1 SELM.0 DIVM.1 DIVM.0 SELS DIVS.1 DIVS.0 DCOR
DCOCTL: 0x_____
DCO.2 DCO.1 DCO.0 MOD.4 MOD.3 MOD.2 MOD.1 MOD.0
D. (5 points) processor clock and SMCLK to 787 KHz and ACLK to 32KHz.
BCSCTL1: 0x_____
XT2Off XTS DIVA.1 DIVA.0 XT5V Rsel2 Rsel1 Rsel0
BCSCTL2: 0x_____
SELM.1 SELM.0 DIVM.1 DIVM.0 SELS DIVS.1 DIVS.0 DCOR
DCOCTL: 0x_____
DCO.2 DCO.1 DCO.0 MOD.4 MOD.3 MOD.2 MOD.1 MOD.0
E. (10 points) What should be the value of MOD if MCLK needs to be set to 1.5MHz for the system that doesn’t use external oscillators (uses only DCO)? Give values for Rsel, DCO, and MOD. Show how you came up with the result. [Hint: use the formula T=((32-MOD)*TDCO + MOD*TDCO+1)/32]
Problem #3 (30 points) Interrupts
A. (15 points) Let us assume a P2.2 port pin is configured as interrupt request input. Describe all steps involved in handling an interrupt request, from the moment a request is received (rising edge detected on P2.2) until the return from the corresponding interrupt handling routine. Be precise, and describe what is done in hardware and what is done in software.
B. (5 points) What is interrupt nesting? Describe how the MSP430 deals with interrupt nesting.
C. (5 points) What is interrupt selective masking? Describe how the MSP430 deals with selective masking.
D. (5 points) How do we enter and exit low-power modes in the MSP430? Be specific.
Appendix