C programes

How Are Data Structures Useful In Embedded Systems?

How are data structures useful in embedded systems

Data Structures in Embedded Systems

This is a very common question my student is asking when we are data structure class for them. When a student joins embedded system training in our institute the data structure is not required an embedded system.
So we thought to write details description of where the data structure is used in the embedded world, so it will help another student across the world who can’t join embedded system training in Bangalore, India.
In the embedded system we are processing a large amount of data from Sensors/devices like ADC, accelerometer/gyro meter, data logger. Normally these data come to the microcontroller using UART, IIC, SPI, or Internal reading of registers like in case of internal ADC register. You can read our post which is talking about many types of sensors in an embedded system.

Most of the time data is updated in the microsecond or millisecond. It means a lot of data, so defiantly we have to save these data in the data structure. First, we will see what mechanism available in C language to save data, and then we will go through the real-time examples which type of data is saved into which type of data structure practically.

Different Data Structure in C

Data structures are arrays, structure, union, files, queues, stack, Linked lists, binary trees etc.

Arrays

To store a single data we use variables. To store a large number of data of the same data type we use arrays. The array is a collection of the same data type variable. In array, memory is allocated continuously.

Arrays can be a single dimension or multi-dimensions.
The size of the array is declared while declaring the array data type. It means we can’t change the size of the array run time. Here are the examples of Array
ex: int arr[5]; if starting address of arr is 0x7890, here we consider integer is 4 bytes long, then the array will be saved following ways.

Address of arr[0] is 0x7890
Address of arr[1] is 0x7894
Address of arr[2] is 0x7898
Address of arr[3] is 0x789c
Address of arr[4] is 0x78a0

Practical Example:

int AdcValue[100]: Read ADC value and save it into an array. Data will be read and save into an array.
float Temperature [50]: Here we are saving the temperature of the wheel and saving it into an array. We will take an average of all 50 elements and then find the average.
char UserName[40][20]: Here save 40 user name into an array, each size is 20 bytes long maximum.

Structure:

The structure is a group of different or same data type elements. In structure, we can have a float, int, char, etc data types grouped together. The memory allocated to structure elements is continuous, the first element occupies the memory address equal to the structure address, and next it stores the second element in memory.

Example:

struct Sen
{
char ch;
float receiveddata;
short count;
} senvar;

Here the sizeof structure senvar is 12 bytes, but if we calculate individual variable sizes than it becomes 1+4+2= 7 bytes. This is because the 32 bit systems stores the data in 32 bit aligned. First, if it stores character then if it stores float 4-byte size, then it would not store the data next to the character since if it stores then 4 bytes not stored in one 4 byte sequence. 3 bytes stored in one row and 1 byte in another row.

Example:
structure start address 0xffff5560
char ch stored at 0xffff5560
flaot receiveddata stored at 0xffff5564
short count stroed at 0xffff5568

So to save the memory while declaring the data in a structure we keep the elements aligned to 4 bytes size all integers, floats at one place then characters and short integers another place.
using structure packing instruction to the compiler we pack the data nest to each other for GCC compiler with code blocks you can use #pragma pack(1) to pack the structure.

Structure with bitfields:

To store the data in bit or bitfield of a memory we use structure fields.
In microcontroller we use registers, to access the bitfields of the register we can use structure/union bitfields.

Example:
struct reg{
unsigned int bit1:1;
unsigned int bit2:1;
unsigned int bitfield1:4;
unsigned int bitfield2:7;
unsigned int bitfield3:9;
unsigned int bitfield4:5;
unsigned int bitfield4:5;
} controlreg1;
here the bit1 is the bit name, 1 is the size of the bit
here the bitfield1 is the bitfield name, 4 is the size of the bitfield, etc.

Union:

The union also can be used to store the variables of different data types. Here all the data stored in the same memory location, the size of the union is equal to the biggest variable data it is holding.
we can also use the union to access both the register and bitfields.
Example: for example, we can define the structure in a union to access both register and
bitfields.
union {
unsigned int reg32;
struct {
unsigned int b1:6;
unsigned int b2:4;
unsigned int b3:6;
unsigned int b4:8;
unsigned int b5:8;
};
}reg2;

Practical Example:

typedef struct
wpan_endpoint_table_entry_t
{
/// Endpoint ID, 0 to 254 255 (0xFF) is used as an end-of-//table marker.
uint8_t endpoint;
/// This endpoint’s profile ID. See WPAN_PROFILE_* macros //for
some known profile ids
uint16_t profile_id;
/// Function to receive all frames for invalid clusters, or //clusters
with a \c handler.
wpan_ep_handler_fn handler;
/// Structure used to track transactions and conversations on
//ZDO/ZDP and
struct wpan_ep_state_t FAR *ep_state;
/// This endpoint’s device ID.
uint16_t device_id;
//Lower 4 bits are used, upper 4 are reserved and should 0
uint8_t device_version;
const wpan_cluster_table_entry_t *cluster_table;
} wpan_endpoint_table_entry_t;

Stack:

The stack is a first in Last out FILO concept. It is like we put the books one above the other than picking it from the top one after the other. we will be storing the data to stack by push() operation and data retrieving are done by pop() function.

Example program to create a stack structure:

The stack is normally used in the embedded system to saved the return of function and local variables.

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 2
struct Stack
{
int data;
struct Stack *next;
}*top;
typedef struct Stack stack;
int count =0;
int main()
{
push(20);
push(10);
disp();
pop();
pop();
pop();
free(top);
return 0;
}

void push(int d)
{
stack *newdata;
if(++count > MAXSIZE)
{
printf(“\n stack is full”);
return 0;
}
newdata= (stack *)malloc(sizeof(stack));
newdata->data = d;
newdata->next=top;
top=newdata;
}
void pop()
{
if(–count == -1)
{
printf(“\n stack is empty”);
return 0;
}
printf(“\ndata popped is = %d”, top->data);
top=top->next;
}

disp()
{
stack *ptr;
for(ptr=top; ptr; ptr=ptr->next)
printf(“\n%d “, ptr->data);
}

Queue Structure:

Queue structure is the FIFO concept first in first out data type. It is similar to the queue of a people standing to collect the ticket in front of a counter. Here the first person standing in front of the queue takes the ticket first, and the next person takes the ticket next.it goes on. In Queue data structure also the first data stored will be read back first and the last data stored will be read last.

Here Is The Practical Example Of A Queue

1. Declare A Queue

/* Declare a variable of type xQueueHandle. This is used to store the queue * that is accessed by all three tasks. */
static xQueueHandle gCellMesgQueue;
/* The queue is created to hold a maximum of 3 structures of type TaskMesg. */
gCellMesgQueue = xQueueCreate( 16, sizeof( TaskMesg ) );

2. Update queue when we received a message

And This is how we put message into queue
if(gCellTaskStarted)
{
cellTaskMesg.id = id;
cellTaskMesg.data = data;
xStatus = xQueueSendToBackFromISR( gCellMesgQueue, &cellTaskMesg,
&xHigherPriorityTaskWoken );
Once we received message into ISR we can update queue. This activity is asynchronous and whenever message received then we update into queue.

3. Continuously check the available message into a queue and take action

for( ;; )
{
if( uxQueueMessagesWaiting( gCellMesgQueue ) == 16 )
{
}
xStatus = xQueueReceive( gCellMesgQueue, &recvCellTaskMesg, 10
/*portMAX_DELAY*/ );
if( xStatus == pdPASS )
{
/* Data was successfully received from the queue, print out the received
* value and the source of the value. Based on received message id take
* action*/
switch( recvCellTaskMesg.id)
{
case E_CELL_TASK_MESG_ID_CELL_RX_BUF_RDY:
//vPrintStringAndNumber( “From Sender 1 = “, recvCellTaskMesg.id );
// for testing we can print message id and check.
CellTaskProcessRxBuf();
break;
case MESG_ID_CELL_STATE_TMR_EVT:

CellStateTimeout();
break;
case MESG_ID_CELL_MDM_RESET:
CellCommand_CmdReset(1);
……….
………
Like this based on message id we can take different action.

Linked Lists:

Arrays use the fixed memory and it allocates memory during compile time.
Linked lists are the data structures, the memory for these is allocated during run time means while the program is running.
Here how much data we want that much memory only we are going to allocate.
No memory is wasted. Extra memory is not allocated.
There are two types of linked lists, one is a singly linked list and another is a doubly-linked list.

Singly Linked List:

The singly-linked list means data is stored in the structural element and one pointer is pointing to the next data structure. Like this, the data structure nodes will be added and the size of the list increases.

Data Structures in embedded system, Singly Linked List:

Doubley Linked List:

Data is stored in data structure and it is having two pointers. One pointer pointing to the next element and the other pointer pointing to the previous element. We traverse the list in both directions one is starting to end called forward direction and the other is an end to start called reverse direction.

Doubley linkted list, data structure

Here is a practical example of link-list in embedded system

if (Alarm_list->Counter > 1) {
for(i = 0;i < Alarm_list->Counter-1;i++) {
for(j = 1;j < Alarm_list->Counter;j++) {
if (Alarm_list->plog[j].uStamp > Alarm_list ->blog[i].uStamp) {
u32SortTick = Alarm_list ->blog[i].uStamp;
u32SortCode = Alarm_list ->blog[i].u16EvtCode;
Alarm_list ->plog[i].uStamp = Alarm_list ->blog[j].uStamp;
Alarm_list ->plog[i].u16EvtCode = Alarm_list ->blog[j].u16EvtCode;
Alarm_list ->plog[j].uStamp = u32SortTick;
Alarm_list ->plog[j].u16EvtCode = u32SortCode;
}
}
}

Here Alarm_list is the list, as and when we get some alarm we make new node and update the information into the list, on the other side of code we are continuously monitoring the list, and if an alarm is generated for any of the thread then we process at a centralized location.

Binary Trees:

The data structure is arranged like a tree. The first node is called the root and the next it will connect to elements one is left and the other is right. A node above it is called the parent node and below the above node is called child nodes. The nodes at the end of the tree are called leaves of the tree.

Normally binary tree is used to sorting the data, more frequently is used where continuously data is coming and going, and always we need to present into sorting. Here we have shown many data structures, which are frequently used embedded systems. In this document, we are shown particle and real-time example code which I had written during my professional career. You can consider the following points while choosing data types in your projects.

Array:

When similar data type needs to save multiple numbers, like ADC value, temperature data, per minute motor revolution count, etc.

Structure

When we need multiple data type need to save and maintain. For example, if we read voltage, current, power factor time, etc. Another example is Task status, last action status, the command sent, the last response received, etc.

Structure Bit filed

In embedded bit filed is widely used, like consider we are updating Bit filed data bitwise also the possibility of data update on full integer. Like
Typedef volatile
struct
_ARM_I2C_STAT
US {
uint32_t busy : 1; ///< Busy flag
uint32_t mode : 1; ///< Mode: 0=Slave, 1=Master
uint32_t direction : 1; ///< Direction: 0=Transmitter,
1=Receiver
uint32_t general_call : 1; ///< General Call indication
(cleared on start of next Slave operation)
uint32_t arbitration_lost : 1; ///< Master lost arbitration
(cleared on start of next Master operation)
uint32_t bus_error : 1; ///< Bus error detected (cleared
on start of next Master/Slave operation)
uint32_t reserved : 26;
} ARM_I2C_STATUS;

Nested Union and Structure

Consider we have to read data from EEPROM byte by byte serially and saved them such a way that while using we want to use in a group of 4,4 bytes. In this case, we can make data structure which is nested with union and structure, as shown below
structure meter_Data{
unsigned int Voltage[2];
unsinged int Current[2];
char Hour;
char Min;
char Sec;
char Day;
};
union read_memory{
unsinged char readbytes[20];
structure meter_Data myMeter;
};
Now union read_memory can be used to read data one by one and while using we can use them as a group of 4 bytes which is an integer or as one byte which is character.

Binary Tree

The binary tree is used when the number of data is entering and leaving, Tree and we need to present always data into sorted order.

Here is a Professional Training Institute which is famous for practical embedded training, we focus on Data structure in practical ways. Our training methods are one on one which leads us to focus on each and every student and give them a complete practical training on C and Data structure. So if you are looking for embedded systems training in Bangalore then come and meet us once to explore in detail. We provide job oriented embedded system training and help our students until their job.

Why C Is The Preferred Language For Embedded Systems

Why C Is The Preferred Language For Embedded Systems

Hello Friends,
I believe you wonder why C language is the preferred language for the embedded system, so here is the step by step analysis for you.

History Of C Programming

Before we enter into C language, let’s go through the history of computation. In around 1949 first computational electronic delay storage automatic calculator was incorporated with an assembler. So assembly language started gaining uses. Assembly language was based on mnemonics. In the year 1953 John W Backus and its team proposed a new language to its senior at IBM, and come up with one language that was based on assembly language but more user-friendly. This language was FORTON, the name derived from Formula Translation.

This language gain lot of popularity, used in many computational an intensive application like computational physics, numeric chemistry, weather prediction, crystallography, etc.

Now it was a time of 1969-70 when Dennis Ritchie and Ken Thompson we working in Bell labs. Ken was having a lot of ideas to improve paging, segmentation, process switch, etc. but to develop all those he was having the option to either improve the compiler of FORTON and make it strong or develop from the beginning. Both of then choose later option and started with some basic language available at that time.

Within 2 years of core working UNIX took a shape and the language C come into existence. The good part is C language is its compiler is written into a similar language like C, which is an amazing feature of C language.

Importance Of C in Embedded System

So now you can understand C language comes into existence with the motive to work develops operating system UNIX. C language is not a perfect language, it has many drawbacks like run-time checking, a lake of expectation handling, etc, but the perfect language is not yet created. Now C language is around 50 years old language, having a very very strong presence in the world of embedded systems, system programming, System programming. So for sure another next 50 years, C language will maintain its popularity and even increase. Now we start a discussion on why C language is the preferred language for embedded system development. As in this topic, we want to analyze why C has preferred the language in embedded systems, so we should know what embedded system is and what his limitation is. An embedded system is a normally small electronic device that is meant for a single purpose. As it is a small device then it is having the following limitation.

1) Low Memory Size

Normally microcontroller is coming in the smaller size, they are having a memory as low as 128 bytes. Inbuilt memory varies based on controller to controller. So the programming language should be such that which generates optimized code and occupied less memory footprint.
After C99 standard introduces, many optimization techniques and keywords are included in C language. The word “volatile” is directly dedicated to optimization.
Now a day new compiler is having the capability to generate so optimized code that even manually writing may not be possible.

2) Low Computational Power

Since the varying range of the controller, there is a possibility that for many small applications we may have less computational power. In C language has the capability to generate optimized code so that it consumes less power. Although the power required directly depends upon microcontroller internal architecture.

3) Uncontrolled And Infinite Life

Embedded application run for infinite time in the program, so code written into it should be thoroughly tested and validate so that it will work for life long. Thanks to the debugging environment available in C language, we can run the application in the acceleration mode and validate the application into debug mode to predict the lifelong behavior.

4) Mass Production Of Device

Since the embedded device is normally produced in term of million, so the language should support for automation and real-time support so that calibration, production testing, sales is possible easily. Even sometimes we also need to update firmware OTA – over the air.

So C language is supporting all possible ways in the embedded system.

What C Language Offer To Embedded System

Readability

C language syntax is easy to understand and it medium-level language. It is having the capability to interact with high-level languages like JAVA and C# and at the same time, C language is having the capability to interact with low-level Assembly language. Since C language is a procedure-oriented language, it helps to write modular code, which is highly readable. Embedded application code is written once then the main task is to maintain them throughout the product life, fix the bug, control version, testing, and validation. For all the above points we need to have code should be readable.

Portability

In the embedded system we need to write the code in one controller and release the product. Now suppose the controller used in obsolete and no more available for production. In this case, we need to move our source code to the new microcontroller, if the language is not supporting portability then we may need to start product development again. C language is highly capable to have portable code. Even more than 90% (on an average) code is capable to have portable and can be directly used into another controller, the available cross compiler takes care of many interoperable issues and as user prospect porting from one controller to other is not a very difficult task.

Simplicity

C language is easy to learn, it is having English like a keyword that is more relevant to the use case. Like keyword if, while, switch case, address, etc. all these keywords and similarly used in the English language also with almost similar use. Since C language is module language, once the student understands how to use the individual component then it will be very easy to use that module anywhere in programming. For example, once the student understands how to use, for loop in C language then it will be used as it is many places during programming.

Maintainability

There are many source control software and website are available that help to maintain source code, the main CVS, PVCS, Git-hub, etc. In the C language also there are many compile-time directives that help to maintain the source code version. The main compile-time keywords are #if, #else, #elif, #endif, #define etc. Using the above keyword, the user can do version control to make a good working code.

Scalable

C language is scalable to the extent that Linux is a million lines of code is written into C language. On average every day around 20-30 thousand lines of code are added into Linux OS itself. So C language is scalable up to the extent thought become limits.

Reliability

C language generates reliable code, its reliability making him use for Aerospace, avionics, defense, mission-critical application, nuclear plants, automobile products.

In the embedded system all most all the time we need to consider the following points during development.

1) Processor Independent

We should able to write code which will work on all processor.

2) Portability

The code should be easy to portable from one microcontroller to another.

3) Bit Manipulation

Usably in the embedded system, we are using bits and IO operation very frequently. Language should support this.

4) Memory Management

5) Code Optimization Possibility

6) Built-in Library Function

C is having many library functions available which can be used during application/system development.

Conclusion

Now being many years giving embedded systems training in Bangalore, At Professional Training Institute, We had come to ways across that C language is one of the most preferred languages in the embedded system. No language can replace C in the coming 20-30 years. It is having many bright career scope in the coming future. As many companies are coming for recruitment to us and asking for proficiency in C language only. Even during the embedded system training course, We focus mainly on C language gives the student to learn the C language up to 3 months. So let’s gear up and make your career into an embedded system, for that you must have an expert level of understanding in C level.

Best wishes for the coming future…

TWO DIMENSIONAL ARRAY

We have introduced array as if we want to save a hundred values then its difficult to declare variables, so we used array .now if we want hundred such arrays then we can have two-dimensional arrays .so an array of arrays is known as 2d array.

1.1 PROGRAM TO CHECK WHETHER THE TWO(3*3) MATRIXES ARE EQUAL OR NOT

DESCRIPTION:

First we taken the two(3*3) matrixes, afterwards we need to check that all elements inside the two matrixes are equal or not in both matrixes with respect toposition wise also, if all elements with respect to position in two matrixes are equal then prints both matrices are EQUAL otherwise prints both matrixes are not equal.
#include<stdio.h>
int main()
{
int matrix1[3][3],matrix2[3][3],i,j,count=0;
printf(“enter the elements of first 3*3 matrix\n”);
for(i=0;i<3;i++) //rows
{
for(j=0;j<3;j++)// columns
{
scanf(“%d”,&matrix1[i][j]); //input from the user
}
}
printf(“enter the elements of second 3*3 matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&matrix2[i][j]);
}
}
for(i=0;i<3;i++) //loop for checking whether two matrixes are equal or not
{
for(j=0;j<3;j++)
{
if(matrix1[i][j]!=matrix2[i][j])
{

count++;// increment the count value if the elements are not

equal
}
}
}
if(count==0)
printf(“2 matrixes are equal\n”);
else
printf(“2 matrixes are not equal\n”);
}

1.2 TO PERFORM SCALAR MULTIPLICATON OF(3*3) MATRIX

Description:

Here we can multiply any constant element with the 3*3 matrix(or any other matrix).first user ask the input for matrix along with the constant variable.
#include<stdio.h>//preprocessor directive with header file
int main()
{
int matrix[10][10],i,j,n,constant,row,col,matrix1[10][10];
printf(“enter the number of rows of the array elements\n”);
scanf(“%d”,&row);
printf(“enter the number of columns of the array elements\n”);
scanf(“%d”,&col);
printf(“enter the matrix elements\n”);
for(i=0;i<row;i++)
//for row elements
{
for(j=0;j<col;j++)
//for column elements
{
scanf(“%d”,&matrix[i][j]);
}
}
printf(“enter the constant element to multiplied with the matrix\n”);
scanf(“%d”,&constant);
for(i=0;i<row;i++)
//loop for multiplying a constant with the given matrix
{
for(j=0;j<col;j++)
{
matrix1[i][j]=constant*matrix[i][j];
}
}

printf(“the new matrix is\n”);

for(i=0;i<row;i++)
//loop for printing the multiplied matrix
{
for(j=0;j<col;j++)
{
printf(” %d”,matrix1[i][j]);
}
printf(“\n”);
}
}//end of main function

1.3 TO FIND THE SUM OF EACH ROW AND COLUMN OF A 3*3 MATRIX

DESCRIPTION:

First we have to take(3*3) matrix,then we need to find the sum of each elements of the row1,afterwards sum of each elements of row2 and then row3, similar method is needed to find the sum of each elements of columns also.afterwards print all the sums individually.
#include<stdio.h>
int main()
int matrix[3][3],i,j,sum,row=0,sum1;
printf(“enter the elements of the matrix(3*3)\n”);
for(i=0;i<3;i++)// scanning for rows
{
for(j=0;j<3;j++)// scanning for columns
{
scanf(“%d”,&matrix[i][j]);
}
}
for(i=0;i<3;i++)//loop for finding the sum of each rows and columns
{
sum=0;
sum1=0;
for(j=0;j<3;j++)
{
sum=sum+matrix[i][j];//sum is sum of each rows
sum1=sum1+matrix[j][i];//sum1 is sum of each columns
}
printf(“sum of row%d=%d\n”,row,sum);//printing sum of each rows value
printf(“sum of column%d=%d\n”,row,sum1);//printing sum of each
column value
row++;

}

}

1.4 MULTIPLICATION OF TWO 3*3 MATRIX

DESCRIPTION:

First we take the two 3*3 matrixes(or any), afterwards we need to check the rows of the first matrix is equal to the columns of the second matrix, if it is satisified then only you to process for further steps otherwise print no multiplication is possible,if it is satisified then only multiply 2 matrix.
#include<stdio.h>
int main()
{
int matrix1[3][3],matrix2[3][3],matrix3[3][3],row1,col1,row2,col2,i,j,k,mul;
printf(“enter the number of rows of the first matrix\n”);
scanf(“%d”,&row1);
printf(“enter the columns of the first matrix\n”);
scanf(“%d”,&col1);
printf(“enter the elements of the first matrix\n”);
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
scanf(“%d”,&matrix1[i][j]);
}
}
printf(“enter the number of rows of second matrix\n”);
scanf(“%d”,&row2);
printf(“enter the number of columns of second matrix\n”);
scanf(“%d”,&col2);
if(row1!=col2) //if rows of the 1st matrix not equal to second matrix exit program
otherwise continue
printf(“multiplication not possible\n”);
else
{
printf(“enter the elements of the second matrix\n”);
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
scanf(“%d”,&matrix2[i][j]);
}

}

printf(“multiplication of two matrix is\n”);
for(i=0;i<row1;i++) // matrix multiplication takes place
{
for(j=0;j<col2;j++)
{
mul=0;
for(k=0;k<col1;k++)
{
mul=mul+matrix1[i][k]*matrix2[k][j];
}
printf(” %d”,mul);
}
printf(“\n”);
}
}
}

1.5 PROGRAM TO STORE 10 NAME INTO 2D ARRAY AND PRINT THEM

DESCRIPTION:

We declare a 2 dimensional character array of required size,afterwards we need to store names, and print them.
#include<stdio.h>
int main()
{
char names[20][20];
int row,col,i,j;
printf(“enter the rows and columns of the 2d array\n”);
scanf(“%d %d”,&row,&col);
printf(“enter the names you want to print\n”);
for(i=0;i<row;i++)
{
scanf(“%s”,&names[i][0]);//user input to store names
}
for(i=0;i<row;i++)
{
printf(“%s\n”,&names[i][0]);//printing the names
}
}

1.6 PROGRAM TO SWAP THE TWO ARRAYS

DESCRIPTION:

To swap two strings in c programming we want to ask user to enter two strings and then make a temporory variable of same type and then place elements of string 1 in temp and and elements of string 2 in 1 and then temp in string 2.
#include<stdio.h>
int main()
{
char array1[10],array2[10],temp[10]=”\0″;
int len1=0,len2=0,i,j;
printf(“enter the elements of the first array\n”);
scanf(“%s”,array1);
printf(“enter the elements of the second array\n”);
scanf(“%s”,array2);
while(array1[len1]!=’\0′)//loop for calculating the length of the first array
{
len1++;
}
printf(“the length of the first array is %d\n”,len1);
while(array2[len2]!=’\0′)//loop for calacuating the length of the second array
{
len2++;
}
printf(“the length of the second array is %d\n”,len2);
for(i=0;i<len1;i++)//using temporary variable we swap the 2 given arrays and
print after the swapping process
{
temp[i]=array1[i];
}
for(i=0;i<len2;i++)
{
array1[i]=array2[i];
}
for(i=0;i<len1;i++)
{
array2[i]=temp[i];
}
for(i=0;i<len2;i++)
{
printf(“%c”,array1[i]);
}
printf(“\n”);
for(j=0;j<len1;j++)
{
printf(“%c”,array2[j]);
}
}

1.7 PROGRAM TO CHECK WHETHER THE GIVEN STRING IS PALINDROME OR NOT

DESCRIPTION:

A string is palindrome if the reverse of that string is equal to original string.firstly we need to declare a character array of some size, after we need to obtain input string from the user, and take another array and copy the reversing order of first string and comapare the both strings if it is equal print as the given string is palindrome else print the given string is not an palindrome.
#include<stdio.h>
#include<string.h>
int main()
{
char str[10],rev[10]=”\0″;
int length=0,i,j;
printf(“enter the string\n”);
scanf(“%s”,str);
while(str[length]!=’\0′)//while loop to find the length of the string till the element become
{
length++;
}
printf(“length of the string is=%d\n”,length);
for(i=length-1,j=0;i>=0,j<length;i–,j++)/*for loop for reversing a original string and store it in
another character
array*/
{
rev[i]=str[j];
}
for(i=0;i<length;i++)//comparing original string with the reversing string
{
if(rev[i]==str[i])
j=1;
else
j=0;
}
if(j==1)
printf(“palindrome\n”);
else
printf(“not an palindrome\n”);
}

1.8 PROGRAM TO INTERCHANGING THE DIGONALS OF MATRIX

DESCRIPTION:

Firstly we take the matrix (only square matrix),afterwards we need to interchange the left diagonal elements towards right and viceversa and print the result of interchanging the diagonal elements.
#include<stdio.h>
int main()
{
int a[10][10],row,column,i,j,temp;
printf(“enter the number of rows and columns of the matrix\n”);
scanf(“%d %d”,&row,&column);
printf(“enter the elements of the matrix\n”);
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<row;i++)
{
temp=a[i][i];
a[i][i]=a[i][row-i-1];
a[i][row-i-1]=temp;
}
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
printf(” %d”,a[i][j]);
}
printf(“\n”);
}
}

1.9 WRITE A PROGRAM TO PRINT UPPER TRIANGULAR MATRIX

DESCRIPTION:

we have to take one square matrix and print the upper triangular matrix only remaining the term should be zero or empty.
#include<stdio.h>
int main()
{
int matrix[3][3],row,column;
printf(“enter the (3*3) matrix elements\n”);
for(row=0;row<3;row++)
{
for(column=0;column<3;column++)
{
scanf(“%d”,&matrix[row][column]);
}
}
for(row=0;row<3;row++)
{
for(column=0;column<3;column++)
{
if(column>=row)
{
matrix[row][column]=matrix[row][column];//assign the elements as it is if column is
greater or equal,else it is 0
}
else
{
matrix[row][column]=0;
}
}
}
for(row=0;row<3;row++)
{
for(column=0;column<3;column++)
{
printf(” %d”,matrix[row][column]);
}
printf(“\n”);
}
}

1.1 PROGRAM TO READ 10 NAMES INTO 2D ARRAY AND SORT THEM BASED ON THE FIRST ELEMENT IN ALPHABETICAL ORDER

DESCRIPTION:

Firstly we can take some of names from the user input and then we have to compare first letter of each names and then use swapping technique if one letter greater than other,after completing the sorting technique, we will get strings of names in alphabetical order.
#include<stdio.h>
#include<string.h>
int main()
{
char names[10][10],temp;
int i,j,k;
printf(“enter the names(10):\n”);
for(i=0;i<10;i++)
{
scanf(“%s”,&names[i][0]);
}
for(k=0;k<10;k++)//loop for swapping until all the elements will be sorting in alphabetical order
{
for(i=0;i<10-1;i++)//swapping all the elements in the array only one time
{
if(names[i][0]>names[i+1][0])/*comparing the first letters of the names and if
greater swap else don’t swap*/
{
for(j=0;j<10;j++)
{
temp=names[i][j];
names[i][j]=names[i+1][j];//swapping
names[i+1][j]=temp;
}
}
}
}
printf(“\n”);
printf(“string name in alphabetical order\n”);//after the swapping technique print the sorted
names
for(i=0;i<10;i++)
{
printf(“%s\n”,&names[i][0]);
}
}

10 Tips to Accelerate Your Engineering Career in Embedded System

10 Tips to Accelerate Your Engineering Career in embedded system_

10 Tips to Accelerate Your Engineering Career in Embedded System

Now a days, there are many ways to build our carrier. But when it comes to ECE/EEE/EE/ student then we are having very less options. For Us we are having few top choises are VLSI/SCADA-PLC/ and Embedded system. Here VLSI is having very limited scope in India, while SCADA is not in much trand now a day, while are having one of the best and core field is Embedded system. I will discuss with you how to build your successful career in Embedded system. Before I move on I will introduce my self so that you can relies on the information which I am providing here.
I am Yogesh Kumar Sharma from founder of Professional Training Institute, having 15+ years of industrial experience in embedded development. Okay so let’s start your journey in the embedded world.
As of my past experience I will explain the 10 most important tips to accelerate your engineering career in embedded systems.

1. Practical Working Knowledge in Embedded Devices:

If we wanna to make our career in embedded system then first we need to know about all the embedded devices used in the projects development. Every companies will use different types of controllers based on project. So, we need to have some knowledge on different controllers because if we are working in any company they will give project and the requirements only and there is your job to make that complete project and you need to study which controller is suitable to that requirement. If we want to design any project we need a knowledge on embedded devices which we are using for our requirements. So, firstly, we need to learn the embedded components, the controllers, the protocols, tools, programming language etc,. you should gain some practical knowledge in embedded system, you should do some hands on experiment with the latest technologies to make them use correctly. Here in Embedded Training Institute in Bangalorewe give directly projects to the students and they gains hands on knowledge on embedded system from us.

2. Embedded Development Life Cycle:

By knowing the Embedded development life cycle will helps a lot in your career. you can only make the project by own without anyone help. Normally process is depends upon individual company but normally we follow SDLC with some changes. For complete embedded development cycle involves different steps.
First, the market team will give a requirement for their application and based on their application R&D engineer need to analyze the project for feasibility of project, technology required, past experience within organization etc.
Following are the steps normally followed in organization
a) Requirement
b) Feasibility
c) specification
d) Design
e) Implementation
f) Testing and validation

Then R&D team will start the design and implementation.
The above steps are part of SDLC – software development life cycle. After implementation complete product testing is started. once you should know the above steps.

3. Command Over C Language is Very Important:

In my life i know only C language, till now i don’t have any other requirement to learn other language. C is the programming language for embedded system. Mainly C language is working more closely hardware. it is most widely used programming in the world. While you are setting in any interview you should have complete knowledge of C language. In any embedded system interview 90% questions will come from C language. you should have control over C language. In Interview company is expecting very deep understanding of C, normally they ask higher end of C language like, function pointer, structure, union, pointer, array of structure pointer etc. In order to achieve control over interview you should go complete understanding of C language.
When you work in company, you have to design an embedded product and you need to use C language. We need to know Advance knowledge in C language. As deeper understanding you will have in C language that much good code you can write. We are the professional training institute in Bangalore, we give training in C completely hands on, it will make our student knowledge more stronger than any experience student.

4. Understanding of Hardware Component, Their Use and Datasheet Reading Skills:

As an Embedded Engineer, we need to know all the hardware components which we are used in the Embedded projects. Normally component used in Embedded is Resistance, capacitor, inductance, diode, transistor we should be aware of these components, how to use them, limitation etc. We may also need have knowledge of ICs like RTC DS1307, EEPROM – 24c04, ADC 0804, RS232, ULN2003 etc we should know what all types of ics are available and where we can use them. Although many types are ICs are available in the marketing, but we should be aware of all main ICs. When we know that how the hardware components will work and how to interface with other components then we can easily complete the projects with less help with others.
During training our student do lot of experiments with the above ic and gets hands on understanding of that. during experiment student read data sheet and use the information mentioned in that. you also must know what all are the important parameter we need to check in data sheet.

5) Debugging skills of software – Embedded firmware.

If your writing code for running hardware then if you are lucky then your code will work as it is. but in most of the case, I won’t. Firmware won’t work as it is, And if firmware not working then we have to make it work. We have to find out what is the mistake we did, for that we need debugging skills. But the difficult part is how to learn to debug, here in the Professional Training Institute we ensure that during training student face enough problems so that he/she can develop debugging skills. However, when we got an error we need to go through the ocean and solve the problem faced. We need a lot of analytical skills to overcome the possible cause of the error, to narrow down the scope of error. Still, there is a possibility that some error will solve in 10 min, some error will solve in a few days, but some may take months or years. But it will surely be having a root cause. Sometimes, we are written the firmware code correctly but we are getting errors because of there is a malfunction in the hardware circuit(we don’t know that), so with how many times if you check also you won’t found the answer for that error. Because of these, we need to have good debugging skills while working on Embedded products.

6) Unit testing, Component Testing, System Testing skills:

This is the one more skill to need to establish the embedded systems developer, it is used for testing the complete hardware products. when we make firmware we need to check that it is working or not, this is called unit testing. In unit testing, we ensure whatever functionality we had developed that has to be working correctly. if we found any bug then we need to correct them. once unit testing is done then we give our component for testing, this testing may be done by some other team.
We are having another level of testing that is called component testing- in the component testing, we ensure the individual component is working correctly. This individual component can include hardware, software. To test components we may need to give some dummy input for testing. Once the independent component is working correctly then we can go for integration testing. In this, we check full system functionality. If we found some issue then we have solved them at individual level.

7) Hardware Debugging is a Requirement While Working:

when you are working on any project many times system is not working, you have to debug and diagnose the problem. To debugging an embedded device we must know the art of debugging hardware. As an embedded engineer we should know where is the problem located, why device not working. For firmware, we are having a debugger, but hardware we are not having the debugger. we need to check signal one by one and find the problem.
You should have hands-on knowledge of the tool used to debug hardware like logic analyzer, CRO, multimeter etc. When are testing an embedded hardware part for an errors first we need to check individually and then the whole system.
The following point may help in hardware debugging
• We need to check first all the equipment are working or not individually.
• Next, we need to check the input requirements to all the devices.
• Next, we need to analyze the errors occurs and we need to check is there any short circuit or not.
• If there is an error occurs when we need to rearrange that product without any of errors.

So, we need to aware of hardware debugging also. We are professional training institutes in Bangalore and we will focus on the student’s knowledge and we will train you on Hardware debugging also. We will teach you how to build a hardware part in the project and how to rectify if any error occurs on the hardware part.

8) Component Review – Firmware Review Skills:

If we are doing any projects and we need to make that project should be run exactly. While creating any firmware code that must meet all requirements. But in many times development is done by the junior member of the team, and he may have a full understanding of the system. so there is a possibility that he may make some mistake which is working currently but later it may give some problem or may in component level it is working bust system level it will not work. This point needs to check and must be review by a senior member of the team. To check the code for its functionality is called code review. normally it is done by a senior member in the team. But you should also have the same skills so that while writing code itself you come to know what mistake is possible and you can make correct firmware

9) Master the Tools of the Trade:

When you’re doing any project on Embedded System we need to know compulsory on tools which will use to work on projects that make to accelerate a career is to master the tools of the trade. The tools which will be used to work on the Embedded projects are Keil, Proteus, Flash Magic, Mp Lab, MATLAB, Kicad, Altium Designer, Eagle, OrCad, STM32 CubeMax, Arduino, Rasbian etc., By using these tools based on controllers like Arduino is used to write firmware in Arduino and Node Mcu ESP8266 etc,. Keil is used to writing a C code or Assembly code and for compilation process. Proteus is used for a schematic of the hardware section and checking the code as well as hardware project is working or not. Flash Magic is used to dump the code into a microcontroller(8051MC, LPC21XX, etc) and Kicad, Altium Designer, Eagle, OrCad are used for Pcb designing purpose. Rasbian is used to work on the Raspberry pi Controller.
So, in every company, they will use different controllers and based on the controller we need to work on different IDE tolls. That’s why we need to know about the IDE tools, then only we can do any type of projects.

10) Documentation Skill Needed:

When your working on any project, it is necessary to make documentation also. When so many peoples are working on the same project then documentation is required. When you start designing a project then you need to make a design document, we also need to make testing documents. When some candidate is leaving the company then what activity he did all those things need to capture so that in future it can be used in case of any problem. when any customer buys our product he needs to know about how it will work and he requires manual, to operate that product. When you have completed your project and you need to submit a project for review and release, that time you need to have all document completed.

These are the 10 tips to accelerate your career in an Embedded System and you need to aware of these tips then you can service in any where in the company. And we are the Professional Training Institute in Bangalore, we will mainly focus on the embedded Course in Bangalore which will helpful their carrier and we will help you how to make individual projects also which makes you as an experienced person. So, first please join in any top embedded training institute in Bangalore that is Professional Training Institute.

If Statement

Control Statements:

There are different types of control statements. It is also called as Flow control statements i.e, we can execute the block of program based on the conditions. There are different types of Flow Control Statements. They are

Decision Statement

1. If Statement.
2. If…else and if…else…if statements
3. nested if else statement
4. switch case

Looping Statements

1. for loop
2. while loop
3. do…while loop
4. Nested loop

Jump Statements

1. Break Statement
2. Continue statement
3. goto Statement

If Statement:

If statement is used in c to control the flow of program with conditional expression. If condition is true, then the block of statement will be executed

Syntax:

if( condition)
{
statement 1; // The block of statement which would be executed
statement 2; // when condition is true, then execute this block of statements
……
……
statement n;
}
If the condition is true, then the statement inside the body of “if” only executed. If the condition is false, then the statement inside the body of “if” will be skipped.

How it works:

if statement

Flow Chart:

flow chat of control statement

Now, we can see the example with a program.
#include<stdio.h>
int main()
{
int a=5, b=8;
if(a<b) // if the condition is true then it will execute the if block statement
{ // if condition is false then it ends the program
printf(“The number a=%d is lessthan b= %d”, a,b);
}
return 0;
}

OUTPUT:

The number a=5 is lessthan b=8.
So now we discussed the If statement and the remaining flow control statements will be explain on the following documents. If you want to establish a good carrier then we need to have good knowledge on the basic language . This language is very useful to the Embedded Systems and to get more knowledge we need join in the top embedded training institutes in Bangalore and we are the Professional Training institute in Bangalore and we will focus on the good knowledge for the students.

Variable

Variable

Variable is a name that can be used to store the values or data. Here, A data type is associated with each variable. The data type of variable decides what value it can take. The data which is stored in the variables exist upto program’s execution, One’s program execution is completed then variables data also expires. The rules of naming a variables are same as that for naming identifiers.

Declaration of a variable:

we need to declare a variable before using in the program.Here, Declaration of a variable defines the name and datatype.The type and range of a value in the variable decides can store depends upon its datatype. The syntax of a variable declaration is shown below

Syntax:

int x; // Used to hold an integer.
float salary; //Used to hold a float value.
char grade; //Can hold/store a character in it.
Where the datatype may be int, char,float double etc,. Here, x is a variable of type int, salary is a
variable of type float, grade is a variable of type char.
we can also declare a more than one variable in a single declaration. For example
int x,y,z,temp;
Here, x,y,z,temp are all variables of int type.

Rules to name a variable:

* Keywords are not allowed as a variable name.
* Variable name is not allowed start with a digit or numbers.
* Variable name can consist of alphabets, digits and special symbols like underscore _.
* Blank or spaces are not allowed in variable name.
Let’s write a program in which we will use some variables :
#include <stdio.h>
int main ()
/* variable definition: */
int x, y,z; // x,y,z are the int datatype variables
/* Initialization a valve in variable */
x = 5; // 5 value is stored into the x variable
y = 2; // 2 value is stored into the y variable
/* using addition operator */
z = x + y; // the sum of two variables x and y will stored into the z variable
/* display the result */
printf(“Sum is : %d \n”, z); // displaying the z variable
return 0;

Output:

Sum is 7
Here, if we consider the program we are declaring the variables in the main program that to it has been declared before used. In the program, x,y,z are the int datatype variable and which the system will allocates the seperate memories for each variables. Later, in the program we are initialized the values to the variables I.e, x=5 and y=2. So here the value 5 is stored in the variable x memory location. Similarly, the value 2 is stored in the variable y memory location. So after performing the addition operation the sum value is stored in the z(z=5+2).
If a student is very ambitious about the career in embedded systems industry. They should have a very deep knowledge in the basics . There are lot of famous institutes for embedded systems training institutes in this field. We are the Professional training institute, in Bangalore are focusing on student’s deepest understanding in this field from its basics.

Storage Classes in C

Storage Classes in C

To describe the features of the variable we use storage classes in c programming. Storage classes are used to track the variable during the run time of the program. Storage class describes the lifetime, scope of the variable in a program.
There are four storage classes in c program. They are auto, register, static and extern.
Storage classes in C

Auto:

The variable normally declared inside block or function is of auto type i.e auto is a default storage class for all the variables which are declared inside the block or function.
The scope of auto variables are within the block or functions means Auto variables can be only accessed within the block/function they have been declared and not outside them.
{
Int a;
auto int a;
}
Above we declared two variable of the same type.

Register:

The register storage class is used to define local variables that should be stored in a register instead of RAM.
{
register int c;
}
The register should only be used for variables that require quick access such as counters. It should be noted that describing ‘register’ it does not mean that the variable will be stored in a register. It means it might be stored in a register depending on hardware and implementation restrictions.

Static Variable

The static storage class notifies the compiler to keep a local variable in existence during the lifetime of the program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables static allows them to maintain their values between function calls.
The static variable can be external or internal, its depends on the place of declaration.
#include<stdio.h>
void foo();
int main(void)
{
foo();
foo();
foo();
}
Void foo()
{
Static int x=1;
Printf(“x=%d”,)
x=x+1;
}

Output: 1,2,3.

Extern

The keyword extern is used with a variable to notify the compiler that the declaration of a variable is done somewhere else. The declaration of extern does not allocate storage for variables.
File1.c //
#include<stdio.h>
int x=3; //global declaration of variable
void foo()
{
 x++;
printf(“%d”,x);
}
File2.c
#include”file1.c”                   //including the file1
main()
{
Extern int x; // global variable from file1 is extracted so x=3.
Foo();
}
So the global variable which is declared in one file can be used in other file using the extern.

Arrays

Arrays

An array is a collection of similar data which is stored in sequential order in the memory. For example, if we save one integer variable into memory it will occupy 4 bytes. If we make another variable then it also occupies 4 bytes, but this memory of two variable may be consecutive or maybe not. This type of variable declaration method is alright until we are having less number of variables.
Once we have to handle the number of variables, it’s maybe 50, 100 then making 50 variable is very difficult.
                int a,b;
We have a solution, we can make an array of N number of the element. In the array, all variable will be saved into consecutive memory locations.

Declaration of array

datatype arrayname[sizeofarray];
Ex:int array[50];
array stored in memory.
array program example
This will reserve 50th places each of size 4 bytes int memory and the good part is all are consecutive in memory locations.
You can initialize an array in C either one by one or using a single statement as follows
marks[5]={47,48,45,44,49};
Or marks[5];
marks[0]=47;, marks[1]=48; marks[2]=45;, marks[3]=44;,marks[4]=49.
How to access this element? This is very simple,
We can access each element individually by showing their place value.
E.g. array[1], array[0], array[24] etc.
Keep remember array always starts from 0, means the first element is always array[0] and last-element is one less than the maximum number element, in our case array[49].

Let’s see the program using the array which explains the declaration, assignment and accessing the array;

#include<stdio.h>
Int main(void)
{
Int a [12]; /* a is array of 12 integers*/
Int I,j; /* I and j are integers*/
/*initializing the values to array elements a */.
for(i=0;i<12;i++)
{
a[i]=i+10; /* assigning value i+10 to ith element*/
}
/* printing the values of elements of array a*/
For(j=0;j<12;j++)
{
Printf(“a[%d]=%d”,j,a[j]);
}
Return 0;
}

Output:

a[0]=10;
a[1]=11;
a[2]=12;
a[3]=13;
a[4]=14;
a[5]=15;
a[6]=16;
a[7]=17;
a[8]=18;
a[9]=19;
a[10]=20;
a[11]=21;

Passing array to function

We can pass array elements to function in two ways. One is bypassing a single value or by passing the full array.
Passing single value to array
#include<stdio.h>
Void foo(int a)
{
printf(“a=%d”,a)
}
Int main (void)
{
Int array[]={1,2,3};
foo(array[1]); // array[1] is passed to the called function foo
Return 0;
}

Output:

a=2;

Passing Entire Array to Function

#include<stdio.h>
Int main(void)
{
Int a[5]={1,2,3,4,5};
Sum=add(a); // passing full array to called function
Printf(“sum=%d”,sum);
return 0;
}
Int add(int a[])
{
Int sum=0, i;
for(i=0;i<5;i++)
{
Sum=sum+a[i];
}
return sum;// return sum to main function.
}

Output

Sum=15;

Pointers and Function Arguments

Pointers and Function Arguments

In call by reference method for a function call, we are using pointers in function as arguments. Pointers as arguments in function are used to hold the address of variables passed from calling the function. If a function is called by reference and any change made to the reference variable will affect the original variable.

Let us consider a program for more detailed study

#include <stdio.h>
#include <stdlib.h>
int main()
{
int m = 10, n = 20;
printf(“Before swapping:\n\n”);
printf(“m = %d\n”, m);
printf(“n = %d\n\n”, n);
swap(&m, &n); //passing address of m and n to the swap function
printf(“After Swapping:\n\n”);
printf(“m = %d\n”, m);
printf(“n = %d”, n);
return 0;
}
/*
pointer ‘a’ and ‘b’ holds and
points to the address of ‘m’ and ‘n’
*/
void swap(int *a, int *b)
// pointers as the function arguments
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

Output:

Before swapping:

m=10
n=20

After swapping:

m=20
Let’s check the detailed explanation of the program. We initialized two integer variables m,n and we printed its value before swapping that is 10,20.
Now we are calling a function by passing the address of the arguments to the called function. When we are calling a function current status of the program execution will be saved in the stack and the program counter will jump to the called function. In the called function swap pointers are used as the function arguments and denoted as int *a, int *b. with these arguments, we can hold the address of the integer variables m and n. pointer variable *a have the address of m and b have the address of n.
In the called function we declared an integer variable temp. The de-referenced value of *a is assigned to temp ie, 10 De-referenced value of b is assigned to pointer a. Now a became 20 Finally value in the variable temp is assigned to *b, so b became 10 When we were assigning values to the pointers all these values were got stored directly in the memory location. The memory locations which were held by the pointers. *a have the address of m and the value 10 in the beginning so after the swapping to that memory location 20 came and overwritten the 10 Same things happened to *b.
Let’s see the picture below for the clarification.
 Also, Learn Embedded System Click Here

Conditional Operators

Conditional Operators:

Conditional operators also called ternary operators. Because it has three sets of expressions. Conditional operators return one value if the condition is true and returns another value if the condition is wrong.
The syntax of the expression and example is given below.

Syntax:

(Condition?true_value:false_value);

Example:

(a>b?a:b);
Let’s consider a program for the detailed understanding,
#include<stdio.h>
Int main()
{
Int a=10;
Int b=20;
Int c;
Printf(“The value after conditional operation is %d”,c=(a>b?a,b));
Return 0;
}

Output:

The value after conditional operation is 20
So in this program, We are initializing two integers a, b as 10 and 20 And another variable c. we are took
use of printf to print the output of conditional operator.
Conditional operator comparing the values of a and b. if a is greater than b. it will print the value of a or
b. In our example b is greater than a. so the conditional operators will print the variable b value.

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*