Sunteți pe pagina 1din 3

# Question 1

## a) What are embedded systems? Give two examples of an embedded system.

-definition [1M]
-two examples [1M]

b) What is the range of values that can be stored in a 16bit signed integer variable?
-values or correct formula usage [2M]

## Question 2 [CLO 1  C3]

Utilize the information in the reference manual and answer the following: [M2+1+5 / T30]

## a. What is the base address of GPIOA and GPIOB?

-GPIOA base: 0x40010800 [1M]
-GPIOB base: 0x40010C00 [1M]

## b. Calculate the register address for GPIOB_LCKR register.

-GPIOB_LCKR address: 0x40010C18 [1M]

c. Figure out how the configuration of some pins of a GPIO port can be locked. Write a
function that will lock the configuration of pins PB0, PB3, PB4 and PB9.
HINT: do not use masking in part c.
-Correct values of LCKy bits [2M]
-Writing and reading full sequence on LCKR for correct lock [2M]
-Code quality [1M]
void Pin_Lock(void)
{
unsigned int temp;
GPIOB_LCKR = 0x00010219;
GPIOB_LCKR = 0x00000219;
GPIOB_LCKR = 0x00010219;
Temp = GPIOB_LCKR;
}

## Analyze the following code and answer the questions: [M4+2 /

T12]
int main(void)
{
static char Count_a = 0, Count_b = 3;
Cyclic_Start(20);
while(1)
{
if(++Count_a >= 3)
{
Count_a = 0;
1
}
if(++Count_b >= 5)
{
Count_b = 0;
}
Cyclic_Wait();
}
return (0);
}
a. What are the periods of the Function_A and Function_B in milliseconds?
-Function_A period = 60ms [2M]
-Function_B period = 100ms [2M]

## b. Is this a time cyclic or a multi-rate cyclic system?

-Multi-rate cyclic as tasks have different periods. [2M]

## Question 4 [CLO 3  C6]

You are given a state diagram for a system. Develop the C code for this system using a switch-case
structure for a timed-cyclic executive with a cycle period of 10 ms. [M12 / T35]

Assume that you have the following functions to check for the events in the diagram:

i. uint8_t Get_Event_1_Status (void): returns 1 if the event condition is true and 0 if false.
ii. uint8_t Get_Event_2_Status (void): returns 1 if the event condition is true and 0 if false.
iii. uint8_t Get_Event_3_Status (void): returns 1 if the event condition is true and 0 if false.

## -switch case [1M]

-number of states [2M]
-Time Triggered actions [2M]
-Event Triggered actions [2M]
-Functionality [2M]
-Code Quality [3M]

2
void State_Machine_Update(void)
{
static unsigned char State_var = 0;
//State A is #0, B is #1, C is #2, D is #3
static unsigned short Count = 0;

switch(State_var)
{
case 0: //State A
if(Get_Event_1_Status() == 1)
{
State_var = 1; //go to state B
Count = 0;
}
break;
case 1: //State B
if(++Count >= 100)
{
State_var = 2; //go to state C
Count = 0;
}
if(Get_Event_2_Status() == 1)
{
State_var = 3; //go to state D
Count = 0;
}
break;
case 2: //State C
if(++Count >= 500)
{
State_var = 1; //go to state B
Count = 0;
}
break;
case 3: //State D
if(++Count >= 6000)
{
State_var = 0; //go to state A
Count = 0;
}
if(Get_Event_3_Status() == 1)
{
State_var = 1; //go to state B
Count = 0;
}
break;
default:
State_var = 0;
Count = 0;
break;
}
}