i What are structures in embedded
system
In the context of embedded
systems, "structures" can refer to
several different things. Some
common structures in embedded
systems include:
1. Data structures: These are
specific ways of organizing
and storing data in memory,
such as arrays, linked lists,
queues, and trees. Data
structures are used to
efficiently store and retrieve
data in embedded systems.
2. Control structures: These are
structures that control the
flow of execution ina
Droaram. such as if-then-elseprogram, such as if-then-else
statements, loops, and
function calls. Control
structures are used to
implement logic and decision-
making in embedded systems.
3. Hardware structures: These
are the physical structures
that make up an embedded
system, such as
microprocessors, memory,
and peripheral devices.
Hardware structures are used
to implement the functionality
of an embedded system.
4. Software structures: These
are the logical structures that
make up an embedded
system's software, such as
tasks, threads, and processes.
Cafturare otrinturac ara icead—oOeVOO ee
Software structures are used
to organize and manage the
execution of code in
embedded systems.
5. Communication structures:
These are the structures that
allow different devices,
subsystems and components
to communicate with each
other, such as buses,
protocols and interfaces.
Overall, structures in embedded
systems are used to organize and
manage the various components
and resources of an embedded
system, in order to achieve
specific functionality and
performance goals. The choice of
structures will depend on the
specific requirements of the vspecific requirements of the
embedded system, such as
memory size, real-time
performance, and
communication requirements.a
Write a suitable program to explain the
concept of structures in embedded c
Here is an example program in C that
demonstrates the concept of
structures in embedded systems:
(in ee) erers(
SensorReading {
int temperature;
Seana Aen Rehm a ae
ia
void
printSensorReading(
SensorReading reading) {elma anest-ercel a tt-[eP ana eae le
SensorReading reading) {
printf("Temperature: %d,
Humidity: %d\n",
reading.temperature,
reading. humidity) ;
bs
int main() {
struct SensorReading
reading = {25, 60};
printSensorReading(reading) ;
return 0;In this example, we define a structure
called *SensorReading* which
represents a sensor reading from an
embedded system. The structure has
two fields, ‘temperature> and
*humidity*, which store the sensor
data. Then we define a function
*printSensorReading’ which takes
a ‘SensorReading* struct as an
argument and prints the sensor data.
In the *main* function, we create a
“SensorReading struct and initialize
it with some example data. Then we
call the ‘printSensorReading*
function to print the data.
This simple program demonstrates
how structures can be used to
organize and store dataWhat are the main components of an
embedded program. Explain with a
program
An embedded program typically consists of
several main components, which include:
1.
Main function: This is the starting point
of the program and contains the main
loop that controls the execution of the
program. The main function typically
initializes the system, sets up any
required peripherals, and then enters a
loop where it reads sensor data, performs
calculations, and controls the output
devices.
() Copy codeLpn
i
system_init();
peripherals_init();
while(1) {
sensor_data =
read_sensors()
result =
perform_calculations(sensor_data);
control_outputs(result) ;
ia-na0) amon2. Interrupt service routines (ISRs): These
are functions that are called when an
interrupt occurs. Interrupts are triggered
by external events, such as sensor
readings, button presses, or timer
expiries. ISRs are used to handle these
events and perform any necessary
actions, such as updating global
variables or controlling output devices.
Copy code
1)
void sensor_interrupt() {
e ic
sensor_data = read_sensors();
void timer_interrupt() {
control_outputs();CPSR 32 bit Bitwise Operations +
3. Data structures: These are specific ways
of organizing and storing data in memory,
such as arrays, linked lists, queues, and
trees. Data structures are used to
efficiently store and retrieve data in
embedded systems.
eo aeerel
struct
temperature;
humidity;
eda
4. Control structures: These are structures
that control the flow of execution in a
program, such as if-then-else statements,
loops, and function calls. Control
structures are used to implement logic
and decision-making inembedded ~Vand decision-making in embedded
systems.
() Copy code
if (sensor_data.temperature >
THRESHOLD) {
woe
5. Libraries and APls: These are pre-written
code that provides specific functionality,
such as communication protocols, device
drivers, and mathematical functions.
These libraries and APIs are used to
perform common tasks and reduce the
complexity of the program.
6. Memory Management: Memory
management schemes areusedto ySS
code that provides specific functionality,
such as communication protocols, device
drivers, and mathematical functions.
These libraries and APIs are used to
perform common tasks and reduce the
complexity of the program.
6. Memory Management: Memory
management schemes are used to
manage the memory usage of the
embedded system.
Overall, these are the main components of
an embedded program. The program is
written in such a way that it fits the
embedded system's constraints of low-
power, low-memory, and real-time
performance.1: | Design a embedded verilog program
whose corresponding finite state
machine represents a melay machine
Here is an example of an
embedded Verilog program that
implements a finite state
machine for a vending machine:
() Copy code
module
vending_machine( input
clk, input [3:0] state,
output reg [3:0]
next_state, input [7:0]
coin, output reg [7:0]
display);
fered a=] ol
4'bo000, WAIT_COIN =
4'b0001, DISPENSE =
4'b0010, CHANGE =4'b0010, CHANGE =
4'b0100;
reg [3:0] present_state;
always @(posedge clk)
begin
fo) 1-10
a= ae eo
end
always @(*)
begin
next_state =
present_state;
(ors 1-1 (present_state)
IDLE: begin
if (coin)
next_state = WAIT_COIN;
end
WAIT_COIN: begin
if (coin ==
8'h10)8'h10)
next_state = DISPENSE;
oa
(coin == 8'h20)
next_state = CHANGE;
end
DISPENSE: begin
next_state =
IDLE;
display =
8'h01;
end
CHANGE: begin
next_state =
IDLE;
display =
ra ae
end
endcase
end
endmoduleend
CHANGE: begin
next_state =
10>) Bo
display =
8'h02;
end
endcase
end
endmodule
This program is a Verilog
implementation of a vending
machine's finite state machine. It
has an input *clk° to trigger the
state transitionEmbedded C Program: Data Types
* When we want to declare any variables in
the program we make use of data types.
Following is the table consisting of all the
data types that are used in Keil’s Cx51
Compiler.
1719/2023 26
Data Type Bits(bytes) | Range
bit 1 | Dor | (itis the bit addressable part of RAM)
signed bit 16(2) -32768 to +32767
unsigned bit 16(2) Oto 65535
signed char a(1) -128 to +127
unsigned 8(1) Oto 255
float 32(4) #1175494E-38 to #3.402823E+38
double 32(4) 21175494E-38 to #3.4028236+38
sbit 1 Oor! (it is the bit addressable part of RAM)
str 8(1) | RAM Addresses (considering 80h to FFh)
sfrl6 16(2) | 0to 65535
19/2023Distinguish between global variables
and local variables in embedded
system
In embedded systems, the
distinction between global
variables and local variables is
similar to that in other types of
programming.
1. Global variables: These are
variables that are defined
outside of any function or
block and are accessible from
any function or block in the
program. They have a global
scope and retain their value
throughout the lifetime of the
program. Global variables are
typically used to store data
that needs to be sharedthat needs to be shared
across multiple functions or
blocks.
2. Local variables: These are
variables that are defined
inside of a function or block
and are only accessible from
that function or block. They
have a local scope and are
created and destroyed each
time the function or block is
executed. Local variables are
typically used to store data
that is used only within a
specific function or block and
does not need to be shared
with other functions or blocks.
In embedded systems, global
variables are often used to store
data that is shared acrossIn embedded systems, global
variables are often used to store
data that is shared across
different parts of the program,
such as sensor readings, system
status, or configuration settings.
They are also used to store data
that needs to be retained
between different function calls.
However, they can use up more
memory and can also lead to
unexpected behavior if not used
properly. On the other hand, local
variables are useful for storing
temporary data that is only
needed within a specific function
or block and do not require a lot
of memory. They also make the
code more readable and easier to
understand.Write a embedded C program and
identify the global and local variables
Here is an example of an
embedded C program that uses
both global and local variables:
(2) Copy code
local_counter =
global_counter++;
local_counter++;= CPSR 32 bit Bitwise Operations
global_counter++;
local_counter++;
oD
global_counter);
(
D
local_counter);
i
Of
increment_counter();
increment_counter();
return
In this example, the variable
~global_counter* is a global
variable, as it is defined outside
of anv fiinetion and is accessibleof any function and is accessible
from any function in the program.
It is initialized with the value of 0
and is incremented by 1 each
time the *increment_counter~*
function is called.
The variable *local_counter* is
a local variable, as it is defined
inside the *increment_counter~
function and is only accessible
from within that function. It is
also initialized with the value of 0
and is incremented by 1 each
time the *increment_counter~*
function is called.
When the program is run, the
~increment_counter * function is
called twice, and the values of
both the global and localcalled twice, and the values of
both the global and local
counters are printed out. You can
see that the global counter value
increases by 1 each time the
function is called and retains its
value, while the local counter is
re-initialized to 0 and increases
by 1 each time the function is
called.
It's important to note that the use
of global variables should be
minimized in embedded systems,
as they can lead to unexpected
behavior, poor performance, and
other issues.Write a embedded C program to toggle
the first four bits of port 3
Here is an example of an
embedded C program that
toggles the first four bits of port
3:
fim exe) aerorel
toggle_port3_bits()
Use volati
1 to infor
that the
unsigned
*port3 = (volatile
*port3 = (volatile
*)
*port3 A=
Of
ep)
toggle_port3_bits();
In this example, a pointer to the
memory location of port 3 is
defined as a volatile unsigned
char type, and is initialized withnnn OO OO Oe
defined as a volatile unsigned
char type, and is initialized with
the memory address of port 3.
The program enters an infinite
loop, in which the function
toggle_port3_bits() is called. This
function uses a bitwise XOR
operator to toggle the first four
bits of the port. The bitwise XOR
operator (*=) compares each bit
of the first operand to the
corresponding operand of the
second operand, and if they are
different, the corresponding
result bit is set to 1. In this case,
the first four bits of the port are
compared with the binary value
of OxOF (00001111 in binary),
which results in toggling the state
of the first four bits of the port.It's important to note that this
code uses memory-mapped |/O
and is specific to a certain
microcontroller and its memory
layout. The addresses used in
this program may not be valid for
other microcontrollers and
should be verified in the device's
documentation.Explain the process of linking and
compilation in embedded C
The process of linking and
compilation in embedded C
involves several steps:
13
Preprocessing: In this step,
the preprocessor processes
all the *#include* and
‘#define* statements in the
source code. The
preprocessor scans the
source code for any
preprocessor directives, such
as ‘#include* and
‘#define*, and replaces them
with their corresponding
values.
. Compilation: In this step, the
compiler converts thecompiler converts the
preprocessed code into
machine code. The compiler
reads the preprocessed code
and generates the machine
code that corresponds to the
instructions in the source
code. The machine code is
typically in the form of object
files, which contain the
machine code for each source
file.
. Assembly: This step is
optional but when used, the
assembler converts assembly
language code into machine
code.
. Linking: In this step, the linker
combines the object files and
any libraries that are required
hv the nroaram into a sinaleby the program into a single
executable file. The linker also
resolves any external symbols
that are referenced in the
object files and assigns
memory addresses to the
variables and functions. The
linker also resolves any
unresolved symbols and
produces a executable file.
5. Loading: This step is also
optional, but when used the
loader loads the executable
file into the target device's
memory.
Overall, the process of linking and
compilation in embedded C
involves converting the source
code into machine code that can
be executed on the taraet device.Overall, the process of linking and
compilation in embedded C
involves converting the source
code into machine code that can
be executed on the target device.
This process is typically done
using a toolchain, which is a
collection of tools, such as the
preprocessor, compiler,
assembler, and linker, that are
used to transform the source
code into machine code.