What is an Embedded system? Describe Embedded C.
In simple words, the Embedded system can be referred to as customizing hardware with customizing the software. Embedded systems are controller-based which is embedded with software to perform specific tasks.
Embedded C is an extended version of C language which is used to develop microcontroller-based systems.
What are little endian and big endian types of storage? How can you identify which type of allocation a system follows?
Big-endian and little-endian are two formats to store multibyte data types into the computer’s memory. Big-endian format and little-endian format. In Big-endian format, MSB(most significant byte) gets memory first and LSB (least significant byte) in last.
In the case of little-endian format the LSB byte gets memory first and MSB byte in last.
Suppose an integer having value 0x12345678.
In the case of big-endian 0x12 gets stored first in memory, then 0x34, then 0x56 and in the last 0x78.
In the case of little-endian 0x78 gets stored first in memory, then 0x56, then 0x34 and in the last 0x12.
|Big Endian Format|
|Little Endian Format|
Write a C program to identify little and big endian.
int main ()
unsigned int x = 0x12345678;
char *c = (char*) &x;
if (*c == 0x78)
printf (“Architecture is little endian. \n“);
What is ISR(Interrupt Service Routine)?
ISR refers to the Interrupt service routine. Whenever an interrupt occurs, the controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine. This process is also known as an interrupt handler.
What is a Qualifier in C?
Qualifiers are the keywords which are used to modify the values of variables. There are two types of the qualifier in C.
Const qualifier used with a variable when we want to make variable to unchangeable. If you will try to change, the compiler will give you an error.
Variable qualified with volatility prevents the compiler to optimize that variable. The values of the variable can be changed by code outside the scope of the current code at any time. The system always reads the current value of a volatile object from the memory location rather than keeping its value in a temporary register.
What is a ‘volatile’ variable, can a variable be both constant and volatile, can a pointer be volatile?
Consider the following example:
volatile int x;
When the compiler finds the variable qualified with the volatile qualifier, it clearly comes to know to the compiler that it will not be involved in any change related to the variable. The value of this variable can be changed anytime by any external source.
A single variable can be const as well as volatile. Example
int volatile *const y;
y is a constant pointer to a volatile integer.
Yes, volatile pointers are possible in c.
int *volatile value;
What is interrupt latency? How to reduce interrupt latency?
Whenever a microcontroller receives any interrupt, first it completes currently executing the instruction , then provides service to interrupt and again continues the executing instruction from the same position where the controller skipped.
So, it takes some time to microcontroller to provide service to interrupt. The amount of time(Number of cycle) taken by microcontroller to start servicing to interrupt known as interrupt latency.
Interrupt latency can be minimized by writing short ISR routine and by not delaying interrupts for more time.
Can we use any function inside the ISR?
Yes, we can but doing so will increase interrupt latency. That’s why it is not recommended as in many cases latency should be as small as possible and using a function inside the ISR will also decrease performance.
What are storage classes?
Storage classes used to classify variable as per their scope (visibility) and lifetime. Default value and storing value place also different to each other. There are four types of storage classes.
|Auto||Local||Within the function||Garbage value|
|register||Local||Within the function||Garbage value|
|Static||Local||Till the end of the program||Zero|
|extern||Global||Till the end of the program||Zero|
Note: Only register variables get memory in a CPU register (if CPU register has vacant memory). Other three variables get memory in RAM memory locations.
What is use of static keyword?
Static keyword can be used with variable as well as functions. The life of static variable lasts till the end of the programs and scope is local(Visible within the function only). Still static variable holds their value after they are out of their scope.
static int count = 0;
printf(“%d “, increment());
printf(“%d “, increment());
Output: 1 2
Function with static within any source file can accessible to only that source file.By using static we make function local only to source file within it is defined.
What is use of register storage class?
In register storage class CPU registers are used to store values.
for example. If you want to store variable which will be frequently required then you can store it in the register like in case of loops. However it is not guaranteed that variable will get store in register.
It is like a request to CPU to allow the variable to store in CPU’s register.
If CPU has vacant register to store variable ,it permits otherwise ignore the request and variable gets allocated in ram memory.
Note: We cannot obtain the address of a register variable using pointers.
What is Synchronous and asynchronous data transmission?
Serial data communication has two types.
Synchronous data transmission
Synchronous transmission needs a clock signal between the source and target to let the target know of the new byte.synchronous transmission data is transmitted in the form of data bundles. So data rate of it very high.
Asynchronous data transmission
Asynchronous transmission has no need of clock signal between the source and target. It sends start and stop bit to start and stop the transmission. It send single-byte data at a time so data rate of it is not much good.
Synchronous vs. Asynchronous Transmission
- In synchronous mode, data is transmitted in the bundle but in asynchronous mode, data is transmitted byte by byte.
- Synchronous required a clock signal between the source and destination to acknowledge the destination about information while in asynchronous clock signal is not required.
- Data transfer rate of synchronous is faster compared to asynchronous .
- Synchronous mode has lower overhead compared to asynchronous transmission.
What is Baud Rate? How it differs from Bit Rate?
In data communication, data are transferred along with signal. The number of the signal transferred per second is known is Baud rate. Bite rate is a number of bits (data) transferred per second. As a single signal may contain more than 1 bit while transferring the data. The relation between the two is given below.
Bit rate = baud rate x the number of bit per baud
What is memory leak ? How we can avoid it?
The memory leak is a condition where the programmer allocates memory in the heap area by using dynamic memory allocation and forget two deallocate. So, it is recommended to use the free() function to deallocate memory which is allocated by dynamic memory allocation once the use of memory location is not further needed.
How to set, clear and toggle a single bit of variable?
The value represents the initial variable and position represents the position of bit in a variable.
Setting a Bit:
Value |= (1 << position)
Clearing a Bit:
Value &= ~ (1<<position)
Toggling a Bit:
Value ^= (1 << position)
What is Dynamic Memory Allocation(DMA)? What is the difference between malloc() and malloc()?
Dynamic memory allocation (DMA) is the process of allocating memory for variables at run time of the program. This kind of allocation allocates memory in the heap area of memory.
malloc function takes one argument at calling but calloc takes two arguments. Also, memory allocated by calloc is initialized with zero.
These functions always return pointer of type void which can be cast into a pointer of any form.
Syntax: For 5 element of int type variable. ptr is int type pointer.
ptr = (int *) malloc (5*sizeof(int))
ptr = (int*) calloc (5, sizeof(int))
What are void pointers in C?
Void pointer also known as generic pointers. There is no data type associated with these, so these can be typed cast to any type.
What is a dangling pointer?
A pointer pointing to deleted or deallocated memory location is known as dangling pointer. To try to access this type of pointer causes undefined behavior or segmentation fault.
What is a wild pointer?
An uninitialized pointer is known as a wild pointer. When we declare any pointer without giving any address, it shows an arbitrary memory location. As we assign it a memory location, it is not a wild pointer anymore.
int* ptr; //Wild pointer
ptr = &a; //Not more wild pointer
Explain the meaning of these pointers?
- int *ptr;
- cons int * ptr;
- int * const ptr;
- const int *const ptr;
It is a pointer to a variable. We can change the value pointer pointing to and also the value of ptr.
const int * ptr
It is a pointer to a constant. It can be also declared as int const *ptr. We can change the pointer to point other variable but we can not change the value of it by using the pointer.
int * const ptr
It is a constant pointer to a variable. We can change the value of the variable by using pointer but we can not change the pointer to point other variables.
const int *const ptr
It is a constant pointer to a constant variable. Neither we can change the pointer to point other variable nor we can change the value using the pointer.