Blogs

Advantages And Disadvantages of Embedded Systems

Advantages And Disadvantages of Embedded Systems

During embedded systems training in Bangalore, Many student ask us what is the advantages and disadvantages of embedded systems. At Professional Training Institute campus had once open seminars for around 2 hours on these topics. Here I summarize the outcome of the seminar so that everyone gets benefited from learning.

Development Cycle

Embedded system is having a well-defined development cycle, this cycle starts from the requirement gathering, product specification, product design, unit testing, validation, the release of the product. Mainly this cycle includes development I.e. coding and unit testing. In the embedded system, we need to consider the capability of the embedded system, power requirement, target cost, etc.

During design, if the company is having similar expertise then it will help in development. In embedded company can develop a re-usable component. This component can be hardware or firmware or testing plans or review points etc. This type of reusable component help during the next development time. All the learning can be helpful in the next development cycle.

The disadvantage is if the developer made one mistake and we are using the same reusable component may be hardware design or firmware code, then the same code will be reflected in all products, wherever that component is re-used. So the re-usable component must to well tested and trusted.

Time of Development

Normally development time in embedded systems is higher. As embedded devices are meant to run independently throughout life. Due to this independent nature of the embedded device, during development time products need to test thoroughly for all possible conditions. Such due to long and regress testing, we can get many errors. Most of the errors are related to Firmware or connection-related, which are solved with less time. But sometimes we can Error which can lead to a long hardware modification development cycle.
So the time of development for a good quality product is always a constraint. This can be put into a disadvantage bucket. But over some time when companies develop the more and more maturity over embedded hardware, then this development reduce significantly and can be considered Advantage, as within a short period many (1-2 week) company can develop a new product. So the development time entirely depends upon developer knowledge and capabilities.

Cost

The product cost of the embedded system is always a key factor to discuss, it is having both advantages and disadvantages. Consider the very competitive market many products are available in the same segment, that time we can’t huge profit margin. We need to keep our price is also in the same segment, there is a possibility that we may not able to make much profit. Consider if our BOM (total cost of the component, PCB, Box) cost is 90$, but in the market same product is available at the price of 100$ then we also need to put a similar cost. In some cases, if our product having some special feature then we can charge an extra amount.
On the other hand, if our product is only in the segment and we are not having any direct competitor then the same product we can sell at 1000$, depends upon usability users are easily able to purchase our product. But in most of the cases, Embedded product cost is having 100% profit the margin which gives very attractive towards embedded system design.

Production

Once we have certified and tested embedded products with us then, the production of the embedded product is an easy and simple process. But production is always having the constraint of time, which means we need to finish production in less time. We can easily reproduce the same product at a low cost. When we go for production even the cost of the product further reduce due to the bulk quantity of production.
Production of the embedded device is a having advantage, one famous product can give a lot of profit to the company and it is having a huge margin. So this is a great advantage of an embedded system. On the other hand, some time in production if some wrong or default component is used then a whole lot of production gets failed, this can lead to heavy loss to the company, and the company should be ready to bear such losses. This is one of the losses of embedded system production.

Life of Product

For every embedded system we need to give some kinds of warranty, some time this warranty leads to huge profit or a huge loss. Profit or loss depends upon how good is our product.
Consider we are making a shaving device, and all our competitor is giving one year warranty, we can give a 2-year warranty and make our price higher. But this is only possible when we are having confidence in our product. Our product should be lost for more then 2 years, if not then it will be a huge loss for the organization.

Here is I will cover one very technical point, consider an EEPROM (Electrical Erasable Programmable Read-Only Memory). EEPROM is always having a limited write cycle. Consider EEPROM is having a 100000 write cycle. If we give a warranty of 2 years then in one day we will only be allowed to write in EEPROM =100000/2*365 =136 times.
It means if are giving a 2-year warranty of our product and EEPROM we are using to save some data into it, then in a day, we should not write more then 136 times. If by mistake our software is writing more then 136 times then the EEPROM of our product will not be lost for 2 years and we may need to replace our product with a warranty. So this life of the product is having a lot of advantages and disadvantages of an embedded system world.

Operations in Filed and Maintenance:

Once we sold our product, our customers will come back to us only when we give service to them after-sales. While making products we need to consider the servicing and maintenance accepts also. Nowadays many devices are coming with firmware update over the air. Firmware update over the air will save a lot of time to visit service engineers to the actual site and do it manually.
So if the embedded product is having good features like an Auto diagnosis of error, Reporting possible error in advance to the server, isolating failed component, firmware update then we will have very
little maintenance cost and it will increase the trust of our customers as well. But for other product service engineers need to visit the actual product location that may increase the cost of maintenance.

We are a Professional Training Institute highly focused on embedded system training and giving more importance to hands-on embedded system training. We believe the learning by doing it has a great advantage. We are having expertise in Embedded system training, Linux internals, Linux device driver, Embedded Linux. You can visit us for more information on www.ptinstitute.in

Characteristics Of Embedded Systems

Characteristics Of Embedded Systems

With the knowledge I gain over 18 years in Industrial exposure, I am sharing my understanding of the embedded system with you. If anyone of you want to gain deeper knowledge in the embedded system then I will suggest you go through the practical and hands-on training in an embedded systems institute which makes you an embedded professional.
Here I want to share with you the characteristic of the embedded system, it will help you understand the embedded system better and deeper.
Here is I listed 10 important points which will tell you the characteristic of the embedded system, and how beautiful embedded system is. Here I want to tell you there are many – more characteristic are available which can be further explored.

1) Embedded Product Design for Infinite Life

Yes, I am not joking, all embedded products are designed to infinite life periods. In every embedded system, we are having
While (1)
{
// infinite loop
}
The meaning of this loop is embedded firmware will work forever. It means an embedded device is designed to be run for always/forever. Although the life of hardware is limited and after some time hardware is started degrading its performance while software (firmware) keeps working with full potential.

2) Self-Reset

Normally embedded device is developed to work in autonomous mode, it means no human will be available near to them. The example of such type of application is Energy meters, temperature monitor units, remote monitoring units, Windmill controllers. Consider in such type of embedded device if we got some error and firmware stops working then humans can’t reach there and reset the device.

In such a case normally we are using a time called watchdog timer, this timer help to reset the whole system if the system stuck some unwanted location. Actually during normal operation devices are keeps feeding the watchdog timer, so watchdog timer keeps running, but if our firmware stuck some unwanted loop then the firmware will not able to reset the watchdog timer. In this case, the watchdog timer will reset the whole system and try to recover the system automatically.

3) Real-time Processing Capability

Embedded system comes with real-time processing capabilities, it means the as soon as the signal is available will be processed and action will be taken accordingly. In some of the real-time application, timing is very critical. Let’s see some of the examples of real-time applications. Detecting rash driving on highways, war field spying robots, Health monitoring systems, etc. You can see in all of the above examples time is very critical, the embedded device needs to process the signal in almost real-time. Even a single mistake will ruin the purpose of the device. But fortunately, embedded systems are capable to process signals in real-time and take action faster.

4) Embedded Having Face Mask for User

This points only developer can understand while working in the embedded system we are having many things/data/signals which we are not showing to the user as it is. We as a developer having some other data with us, but to the user, we show some other thing. Normally to the user, we show in the human-readable format. This human-readable format gives clarity in operation and understanding of the machine, while actually, we may have very complex data with us.
Just for example if we want to display 1 on 7-segment display then actual we are writing 0x06 on the port to display one. So now you can see with this simple example that for 1 to display we are showing 0x06. This feature gives liberty to the developer that we can layout our world the ways we want.

5) Learn Once Use Lifetimes

This is a very beautiful feature of an embedded system, you just need to learn once and you can use that knowledge for the rest of your life. I will explain this in detail consider if you are working in JAVA/C#/JaveScript/etc any high-level programming language then with 6-12 months. you will get a new version of language itself or altogether a new language. So it means you need to keep learning continuously and upgrade your knowledge. But in the embedded system we are having a facility that if once we learn practically then you can use that knowledge as it is for the rest of your life. Here in Professional Training Institute, we focus on practical and hands-on training in the embedded systems, that gives stable carrier to our student.

6) Having Capability to Match Real Lifetime

In many embedded applications, we are having a requirement to take action on exactly 10:00 AM or 6:00 PM, etc. So it means any delay in time will lead to missing the purpose of the device itself. In such an application, we need to generate or maintain time inside of embedded devices such that this time matches exactly the same as real-world time.

In most of the applications, we are using RTC chip – real-time clock to do this activity, but in some embedded applications using internal timer we are calculating time, in such an embedded device we need to write very optimize code so that we can calculate real-time from firmware. Calculating time with firmware is fun.

7) Software Behaviour

Software behavior is always the same but hardware can change its behavior. The behavior of embedded firmware will always same, it means the ways firmware is working the first time then next time and every time firmware will work the same ways. So as an embedded developer we should be always confident behavior of embedded firmware. But hardware can change its behavior, over a period of time hardware degraded. Due to the degraded hardware, we face behavior changes. As a human being whenever any program occurs we directly doubt our work, but as per my experience, the most common cause of the error is a connection/wring/environment, etc. Which means neither hardware nor software is giving problems.

8) Encryption Algorithm Make Embedded Safe From Hackers

Embedded system is porn to hacking, in much critical application hacker are trying to theft data. In the current world, data is costlier than gold. But fortunately, in the embedded system we are having encryption algorithms like (SHA, DES, AES, MD5, etc.). By using Encryption algorithm users are able to save the embedded system from hackers. The above algorithm is very hard to hack, and almost zero practical hacking attempts got succeed till now.

9) Detection and Reporting of Hardware and Software Failure

This is a very advanced feature in new embedded systems. We are able to detect the possible error in hardware or software based on the past learning of machine. Here I will give one example, EEPROM is having a limited write cycle, so while writing software we can limit and count our EEPROM write. So even before it occurs our device is safe. Still consider we can save some know signature bytes in the memory like 0xAA5500AA on some know location. Periodically read and verify the signature bytes, it will let firmware know that EEPROM is in good condition and is able to save data. We are having many other methods like ti-redundancy check, in this methods, we save our data into three locations, and before using read all three and compare at-least two data should match, then only we consider data is valid. Almost all computers are having a power-on self-test, in this computer try to detect hardware availability as well and normal functionality. Similar functionality is implemented in an embedded system as well.

10) ASIC Help to Reduce Hardware and Software

Now a day we are having special IC for the special purpose of work, it is called as ASIC – application-specific integrated chip. The advance of ASIC is it helps to reduce the hardware and software. Most of the work of hardware and software will be converted into IC format and companies creating special ICs. such as ICs is having many advantages like

  • Reduce cost
  • Small in size
  • Fast development
  • Less chance of copying the data.

Here I had listed some of the characteristics of the embedded system, we at professional training institute focus on practical and hands-on embedded system training in Bangalore. We are having an embedded system training institute in Bangalore, we also provide training in Linux device driver and Embedded Linux. Contact us for more details.

What Is Deep Learning

What is Deep Learning

What is deep learning, nowadays many students want to know about it? Deep learning is another branch of the embedded system, in embedded system data collected by the sensor is in the core of the algorithm. Before starting deep learning is will be advantages to embedded system training in Bangalore, it will help you to get understanding and collecting sensor data.

Deep learning is part of a big family of machine learning, here we mainly focus on deep learning. With deep learning, the algorithm computer is capable of learning like a brain. In simple words, when we are child our brain learning by touching, smelling, tasting, and feeling. Similar ways computers also capable to learn slowly one by one, step by step using a deep algorithm like a neural network. Using a neural network computer is capable to extract complicate concepts and relationships of data.

In deep learning computer use data like picture, sound, video, text, and established complex the relationship among these data, this learning computer remember and uses in the next algorithm. In deep learning, we are having many more data sets, which is used for learning to teach computers. Using deep algorithm computers take the complex decision and use these decisions for the next algorithm. In deep learning, we need to focus on speed, scalability, and flexibility.

Speed:

We have to design a deep learning algorithm so that computers are capable of learning quickly. In order to learn faster computers need many more CPUs and GPUs to solve complex matrix. Using high-speed CPUs and GPUs user can speed up computer deep learning.

Scalability:

Consider the case when we have written the algorithm to lean COVID-19 spread in the world, soon after the deep learning algorithm computer can able to tell how COVID-19 going to spread in the future, we continuously need to feed new data so that we get correct prediction in advance.

Flexibility:

During algorithm many, we may need to use much software that required very high computation power. So we need to choose a deep learning algorithm that is best suited for our algorithm.

Now we will see what is the use of deep learning and where we are using deep learning. Nowadays across the world, many companies are working in deep learning.

Computer Vision:

In the application of computer vision, face recognition is most widely used. Although there are millions of applications of computer vision, like production control, quality inspection, autonomous driving cars, etc. In computer vision, We take input from a camera, sound, heat and proximity data, using all input computer vision is created which is capable to detect the face of human, or quality inspection at a faster rate, or drive a car automatically.

Speech Recognition:

Speech recognition is another important application of deep learning. On every smartphone. We are having voice command using google voice, Amazon Alexa, Microsoft Cortana, Apple Siri are the major name among many more which can recognize input voice, take action on them and analyze for future use.

Dealing With Malware:

Deep learning can help a lot in malware analysis and protect computer users. In new world malware attach are a very severe effect. Nowadays malware can theft user data and it use for many scams.

Network Traffic Analysis:

Deep learning is very useful for our country, much tarriest organization are using the internet for communication among their team, using deep learning communication can track and used for security purposes.

User Behavior Analysis:

When a customer is visiting the shopping mall, he is keep seeing many products and then chose few, while another customer is just directly going and buying a product. These varying behavior can we understand properly using IoT and embedded systems. With deep learning we will able to predict the product customer is going to buy, these deep learning can help to suggest the product user is interested in buying.

Here in Professional Training Institute, we are mainly focusing on embedded system training, Linux device driver, Embedded Linux, and IOT training. Our teaching method is completely practical and hands-on. We are a best-embedded system training institute in Bangalore.

All about Process in Linux/Unix – Developer Perspective

PROCESS:

In Linux every thing we sees executing or taking some action will be by the process. Processes carry out tasks within the operating system. For definition ” Any program in execution is called process”.  A program is a set of machine code instructions and data stored in an executable area of memory.

Processes are separate tasks each with their own rights and responsibilities. Each individual process runs in its own address space and not interacting with another process except through secure, kernel managed mechanisms.

LINUX PROCESS:-

An instance of a program is called a Process. In simple terms, any command that you give to terminal on your Linux machine starts a new process. Having multiple processes for the same program is possible. A process itself not a process, until it comes info execution.

In a Linux system no process is independent of any other process. Every process in the system, except the initial process has a parent process. New processes are not created, they are copied, or cloned from previous processes.

Types of Process:-

  • Foreground Process: A foreground process is any command or task you run directly and wait for it complete. They run on the screen and need input from the user.

A foreground Process begins by typing a command at prompt. For example, list of files in current directory

>ls
  • Background Processes: In Linux, a background process is nothing but process running independently. They run in the background and usually do not need user input.

For example

  • Antivirus in your computer, normally it is running in background.

 

Basic command for Linux process:-

ps:

The ps command is used to provide information about the currently running process, including their process identification number(PID).

The basic syntax of ps is

>ps

When ps is used without any option, which display default  information of process currently running on the system .

The four items are labeled PID,TTY,TIME,CMD

PID-  Process identification number.

TTY- TTY is the name of console or terminal shows currently console.

TIME- Time is the amount of CPU, time in minutes and seconds that the process has been running.

CMD- Cmd is the name of the command that launched the process.

 

 

 

 

ps –e:-

ps –e command is used for list of all process running on the system in a single shot

>ps –e
  • –e show all process not just those belonging to user.

 

 

 

 

 

 

 

 

 

 

 

 

pstree:-

pstree is a command that shows the running processes as a tree fromat. It  is  used as a alternative to the ps command.

The basic syntax of the pstree is

>pstree

pstree command is similar to the ps command, but instead of listing the running processes ,it shows in a tree format.

 

 

 

 

 

 

 

 

 

 

bg:-

Linux treats everything as file, even the processes as files under /proc directories. The processes are basically program in execution, they also called jobs

The bg command is the processes that have been stopped by some interrupt signal can be continued background with bg command

Syntax for bg command

  • ./output &

 

 

 

fg:-

The  fg command  is like bg command Except that instead of sending a command in the background it runs them in foreground and occupies the current terminal and wait for process to exit.

top:-

In Linux, top is a command used to display processor activity of your linux , this command shows the  information of the system and the list of processes  which are currently running in the Linux

 

 

 

 

 

 

 

 

 

 

 

 

  • PID:Shows task’s unique process id.
  • PR: Stands for priority of the task.
  • SHR:Represents the amount of shared memory used by a task.
  • VIRT:Total virtual memory used by the task.
  • USER:User name of owner of task.
  • %CPU: Represents the CPU usage.
  • TIME+:CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
  • SHR:Represents the Shared Memory size (kb) used by a task.
  • NI:Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
  • %MEM: Shows the Memory usage of task.

 

Kill

kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process which terminates the process.

 

EXAMPLES

> kill -9 -1        Kill all processes you can kill.

> kill -l 11         Translate number 11 into a signal name.

> kill -L             List the available signal choices in a nice table.

> kill 3453         Send the default signal, SIGTERM, to all those processes.

 

Now we will learn the Process with the developer prospective, here user can write C program using any editor wish and compile code using GCC.

Process  Identification:-

In Linux, User can be running various programs in the system, each running program must be unique identified by the kernel and program id identified by its own process is called “PID”, therefore process can be further categorized into

  • Parent process.
  • Child process.

Parent process-Parent process is processes that create other processes during run-time.

In command prompt, Command to get the parent process identity.

Header file need to include for getpid():

  • Sys/types.h
  • unistd.h
getppid()

Child process-Child process are created by the parent process by cone of it ,it will be behaves same as parent.

In command prompt, Command to get the child process identity.

Header file need to include for getppid():

  • Sys/types.h
  • unistd.h
getpid()

 

Now our first steps is to create process, fork is the system call which is used to create process. read on and follow –

Frok():-

Fork is a way to create new processes, fork() operation create a separate processes as a copy of itself then, the copy called the “child process”.

The child process has an exact copy of  the parent process. After the fork, both processes not only run the same program

The child has its own unique process ID and this PID not match the ID of any existing process

The child parent process ID is the same as the parent’s process ID.

Return value:

On success, the PID of the child is returned in the parent, and “0” is returned in the child. On failure, “-1” is returned in the parent, no child process is created and errno is set appropriately.

 

Header file need to include for fork:

 

unistd.h

 

 

 

 

 

 

 

 

 

 

 

Sleep():-

In Linux, Sleep() I s causes the calling thread to sleep either until of real-time specified in seconds have to elapsed .

Steps for sleep():-

Step 1– write a source code for sleep(), as shown in below image.

Step 2– Search for PID in all current running processes, by giving command ps.

Step 3-Enter in /proc and search that Pid by using ls command.

Step 4– Enter the Pid proc type cat status for the process states. Now you should be in /proc/pidof_yourprocess. Steps shown below.

$cd /proc <┘

$ls <┘

$cd  /proc/pid <┘

$cat status <┘

Now see the status of process, it will show process is sleeping.

 

 

 

 

 

 

 

 

 

 

 

 

 

Now check the status of process, that is sleeping.

 

 

 

 

 

 

 

 

 

wait system call

wait()  blocks the calling process until one of its child processes exits or a signal is received. After child process terminates, parent continues its execution after wait system call instruction.

Header files for wait:

  • sys/wait.h

 

 

 

 

 

 

 

 

 

 

Exec System calls family:-

 

  • Exec family of function or system call replace current process with new process.
  • There are various function used in the Exec  like
    • Execl
    • Exclp
    • Execle
    • Execve
    • Execvp
    • Execvpe

Header file need to include is

unistd.h

Example for execlp:-

 

 

 

 

 

 

 

 

Orphan process:-

Orphan processes are those processes that are still running even though their parent process has terminated or finished. A process can be orphaned intentionally or unintentionally.

An intentionally orphaned process runs in the background without any manual support. This is usually done to start an indefinitely running service or to complete a long-running job without user attention.

An unintentionally orphaned process is created when its parent process crashes or terminates. Unintentional orphan processes can be avoided using the process group mechanism.

Zombie process

Zombie processes usually occur for child processes, as the parent process still needs to read its child’s exit or crashes . Once this is done using the wait system call, the zombie process is eliminated from the process . This is known as the zombie process.

Professional Training Institute is the top embedded training institute in Bangalore, where student can learn the practical embedded system, we believe in hands on knowledge of subject such that student are not only getting the practical knowledge but also getting experience in embedded system development. All our students are able to get placed in top companies with the knowledge they gain in our institute. come and explore the possibilities, of amazing knowledge you can gain.

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.

INTERFACING LCD 16*2 WITH 8051

INTERFACING LCD 16*2 WITH 8051

SUMMERY:

Connecting LCD 16*2 display to the 8051 microcontroller in 8 bitration method and also passing two commands.

COMPONENTS RECQURIED:

o 8051 Microcontroller
o 16*2 LCD Display
o Switch
o Binary Wires
o Power Supply

PIN DIAGRAM:

 

 

 

 

 

 

 

 

 

SOURCE CODE:


#include 
# define lcd P0 
sbit rs=P1^0; 
sbit e=P1^1; 
sbit b=P1^2; 

void dealy50ms(int a); 
void intial(char b); 
void delay1s(unsigned char c); 
void write1(); 
void write2(); 
void write3(); 
void write4(); 
void button() 
{
	int k=1; 
	while(k==1)
	{ 
		if(b==0)
		{ 
			intial(0x01); 
			k=0; 
		}
	}
} 

void display(char *d); 

int main() 
{ 
	b=1; 
	while(1)
	{ 
		intial(0x38); 
		intial(0x0c); 
		intial(0x01); 
		intial(0x80); 
		write1(); 
		intial(0xc0); 
		write2(); 
		button(); 
		intial(0x80); 
		write3(); 
		intial(0xc0); 
		write4(); 
	} 
} 

void display(char *d)
{ 
	for(*d;d!=NULL;d++)
	{ 
		lcd=*d;
		rs=1; 
		e=1; 
		delay1s(1); 
		e=0;
	}
} 
void write1()
{ 
	display("Done LCD16*2 ");
}

void write2() 
{
	display(" SUCESS ");
}

void write3() 
{
	display("Thank");
}

void write4()
{
	display("YOU");
}

void intial(char b) 
{
	lcd=b;
	rs=0;
	e=1;
	dealy50ms(2);
	e=0; 
} 

void dealy50ms(int a) 
{
	inti=0; 
	for(i; i < a ; i++) 
	{
		TMOD=0x01;
		TH0=0xff; 
		TL0=0xfc;
		TR0=1; 
		while(!TF0);
		TF0=0;
		TR0=0; 
	}
}

void delay1s(unsigned char c)
{
	int i,j;
	for(i=0;i < c;i++)
	{
		for(j=0;j<20;j++) 
		{
			TMOD=0x01; 
			TH0=0xff; 
			TL0=0xfc; 
			TR0=1;
			while(!TF0);
			TF0=0;
			TR0=0;
		}
	}
}

EXPLIANATION:

Now we will go through code and understand how LCD is working. Any C programalways start with main function. In our code main function contains.


int main()
{ 
	b=1; 
	while(1)
	{ 
		intial(0x38); 
		intial(0x0c); 
		intial(0x01); 
		intial(0x80); 
		write1(); 
		intial(0xc0); 
		write2(); 
		button(); 
		intial(0x80); 
		write3(); 
		intial(0xc0); 
		write4(); 
		} 
	}
}
Main function is started
intial(0x38); command 0x38
intial(0x0c);Passing 0x0C value for Display ON, Cursor OFF
intial(0x01);Passing 0x01 value for Clear the screen
intial(0x80);Passing 0x80 value for Force curser to the 1st line in first position
Write1();Calling write1 function to pass the “Done LCD 16*2 ” string to display function

Next how to send the commands through intial function to LCD


void intial(char b) 
{ 
	lcd=b; 
	rs=0; 
	e=1; 
	dealy50ms(2); 
	e=0; 
}
In Intial function, Passing the command from Microcontroller P0 to LCD through parallel communication from Microcontroller(P0.0-P0.7) to LCD(D0-D7). “rs” register pin used to set 1 or 0 is used to sending commands. “e” enable pin used to given value to LCD as making high to low.
Professional Training Institute is highly focus on practical embedded system training in Bangalore, Above post is writtern by our student Joy and Prathavi. We wish bright carrer ahead to both of them.

Next is interfacing button to the LCD to send different string data

 


void button()
{ 
	int k=1; 
	while(k==1)
	{ 
		if(b==0)
		{
			intial(0x01); 
			k=0; 
		} 
	}
}
In button function, Run the while part to check every time the value of k. b is connected to the switch when it pressed it becomes zero, It is initially high condition(1). Passing the value 0x01 to clear the screen. Once button is clicked the value of “k” changed to 0 to exit the while loop.

Next to pass the string value to the LCD through display function

 


void display(char *d)
{ 
	for(*d;*d!=NULL;d++) 
	{ 
		lcd=*d; 
		rs=1; 
		e=1; 
		delay1s(1); 
		e=0; 
	} 
}
Display function getting the string’s first address. rs is the register pin used to intimate the LCD as it is a data not a command. e is a enable pin used to given value to LCD as making high to low.

Next delay function for 50ms

 


void dealy50ms(int a)
{
	inti=0; 
	for(i;i<a;i++)
		{
			TMOD=0x01;
			TH0=0xff; 
			TL0=0xfc; 
			TR0=1; 
			while(!TF0); 
			TF0=0; 
			TR0=0; 
			} 
		}
}
Here is the delay function for 50ms you maximize the value through passing number to make higher, this is done trough using Timer concept

Next is the delay for 1s

 


void delay1s(unsigned char c)
{ 
	inti,j; 
	for(i=0;i<c;i++) 
	{ 
		for(j=0;j<20;j++) 
		{ 
			TMOD=0x01; 
			TH0=0xff; 
			TL0=0xfc; 
			TR0=1; 
			while(!TF0); 
			TF0=0; 
			TR0=0; 
		} 
	} 
}
Here is the same but used delay function for 1s you maximize the value through passing number to make higher, this is done through using Timer concept

From above the program it is written for 8 bitration of 16*2 LCD display for 2 commands. Here I used common initialisation command for all 16*2 LCD display which is in intial( ); and the strings are written in write1..4( ) functions and the display commands of working procedures also written in the display( ) function and also two different delays are represented as 50ms and 1s in delay50ms( ) and delay1s( ) function which is written in timer concept.
Professoinal Training Institute is focus in Practical embedded system training in Bangalore. This post is written by our student Joy and Prathavi, based on their executed experiments during training. we wish then for their bright career ahead.

Alternet Working Source Code:


#include 
#define Display_Port P0
// Selecting a display port P0 
sbit RS = P1^0; 
// Selecting Resistor Selection 
Port P1.0 
sbit EN = P1^1; 
// Port P1.1 for Enable Pin 
sbit button = P1^2; 
void delay_ms(int d);
// Function Prototype to generate mili second delay 
void lcd_data(char display_data); 
// Function Prototype to send information on LCD display 
void lcd_int(); 
// Function Prototype to initilization of Basics LCD Commands 
void lcd_command(char command); 
// Function Prototype to send commands on LCD Port 
/* .................Begining of Main Function .....................*/ 

void main() 
{ 
	inti=0; 
	int j=0; 
	int k=0; 
	int l=0; 
	int check = 1; 
	unsigned char a[9]="EMBEDDED"; 
	unsigned char b[8]="DESIGN"; 
	unsigned char c[6]="THANK"; 
	unsigned char d[4]="YOU"; 
	button =1; 
	lcd_int(); 

// LCD Initilization 
// button = 1; 

	while( a[i] != '\0' )
	{
		lcd_data(a[i]);
		i++;
		delay_ms(50);
	} 
	lcd_command(0xC0); // Command to Move Cursor to next line 
	while(b[j] != '\0') 
	{
	lcd_data(b[j]);
	j++; 
	delay_ms(50);
	}
	lcd_command(0x0C); // Command to set Display ON Curser OFF 
	//delay_ms(2000); // Delay for 2sec 
	while(check==1)
	{ 
		if(button == 0)
		{
			lcd_command(0x01); // Command To clear screen 
			check = 0; 
		} 
	} 
	while(c[k]!='\0') 
	{ 
		lcd_data(c[k]);
		k++;
		delay_ms(50); 
	}
	delay_ms(20); 
	lcd_command(0xC0); // Move cursor to nest line 
	while(d[l]!='\0') 
	{ 
		lcd_data(d[l]); 
		l++; 
		delay_ms(50); 
	} 
	while(1);
} 
/*................. END of Main Function .........................*/ 

/*................. Delay Sub Routile............................*/ 
void delay_ms(int d) 
{
	inti,j; 
	for(i=0; i<d; i++)
	for(j=0; j<1257; j++); 
}
/*.....Sub Routine to send information over LCD...............*/ 

void lcd_data(char display_data)
{
	Display_Port = display_data; 
	RS = 1; 
	EN = 1; 
	delay_ms(1); 
	EN = 0; 
} 

/*....... Sub Routine to send Commands over LCD Display.............*/ 


void lcd_command(char command) 
{ 
	Display_Port = command; 
	RS = 0; 
	EN = 1; 
	delay_ms(1); 
	EN = 0; 
} 
/*........... Sub Routine to initilize the Commands............*/ 
void lcd_int()
{
	lcd_command(0x38); 
	delay_ms(10); 
	lcd_command(0x0F); 
	delay_ms(10); 
	lcd_command(0x01); 
	delay_ms(10); 
	lcd_command(0x80);
	delay_ms(10); 
}

Interview Q and A 9

Interview Q and A 9



Ques 1. How to know the given controller is little endian or big endian ?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    unsigned int x=0xaa55;
    unsigned char *p=&x;
if(*p == 0x55)
{
    printf("\n Little endian");
    printf("%x = %x\n",p, *p);
    printf("%x = %x\n",(p+1),*(p+1));
}
else
    printf("\n Big endian");
    return 0;
}


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=5;
    {
      int a=9;
      printf("\n %d",a);
    }
    printf(" %d",a);
    return 0;
}

Ans. 9 5


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=5;
    {
      a=9;
      printf("\n %d",a);
    }
    printf(" %d",a);
    return 0;
}

ans :  9 9



Ques 4. What is the difference between General purpose os and RTOS ?

RTOS :
  Rtos scheduling is based on priority
  Resopnse time is predictable
  kernel is preemptive or upto maximum degree
  priority inversion is a major issue
  it has less memory

Ex: Free RTOS, vxworks, RT linux, PSOS, VRTX, Lynx

General Purpose OS:
  GPOS scheduling  can be adjusted dynamically for optimized throuhput.
  Resopnse time is not predictable
  kernel is non preemptive or upto maximum degree
  priority inverson is unnoticed.
  it is having large memory.
 Ex: Microsoft windows, Redhat Linux, Apple MacOS


Ques 5. explain the meaning of below declaration?

const int PI, int const PI, const int *p,  int * const p, const int *const p;

const int PI : PI is a integer constant.
int const PI : PI is a integer constant.
const int *p:  p is a pointer to constant integer, data present in p is constant and ponter is not constant.
int * const p: pointer p is constant and data is not constant.
const int * const p: both pointer p and data are constant. 


Ques 6. what are the bitwise operators and its types?

bitwise operators are as mentioned below:

| bitwise or operator   
& bitwise and operator
~ bitwise 1's complement operator
^ bitwise xor operator
<< bitwise left shift operator
>> bitwise right shift operator.


Ques 7. which operator is suitable for checking perticular bit is set or not?
 >> and & operators.


Ques 8. what is the output for the below code?
int main()
{
    int a=3;
    int x=-15;

    a+x > 5? puts("a+x > 5 "): puts("a+x < 5");

    return 0;
}


ans: a+x < 5


Ques 9. write a program to swap two numbers without using third variable?

swap(int *p, int *q)
{
  *p=*p+*q;
  *q= *p-*q;
  *p=*p-*q;
}


Ques 10. write a program to pass array as argument to a function?

fun(int p[])
{
  int i=0;
  for(; i<3; i++)
  printf(" = %d \n", p[i]);

}

int main()
{
    int a[3] ={2,3,4};
    fun(a);
    return 0;
}


Ques 11. what is ohms law?
ohms law states that the current through the conductor is directly proportional to the voltage across
the two points of the conductor with resistance is constant.


Ques 12. what is the difference between call by value and call by reference ?
	call by value means we are passing copy of the original arguments to the formal arguments of the function.
             here the value changed in the formal arguments will not affect the original arguments 
	call by referece means we are passing the address of the arguments to the formal arguments of the function.
             here the value changed in the formal arguments will affect the original arguments.

Ques 13. what is the output for the below code if integer size is 4 bytes?

int main()
{
	int x=-1;
	printf("%x ", (x>>1));
	return 0;
}

ans : ffffffff


Ques 14. what is the equivalent pointer expression for the array element arr[i][j][k][m]?

ans:     *(*(*(*(arr+i)+j)+k)+m)


Ques 15. what is the output for the below code?

int main()
{
	int *p, **q, ***r;
	int x=9;
        p=&x;
	q=&p;
	r= &q;
	printf("%d %d %d", *p, **q, ***r);
	return 0;
}

ans: 9 9 9



Ques 16. what is the requirement of infinite loop in embedded system?

	Since embedded system has to continuously work and respond to the inputs, and some other jobs in loop. 
to make the system to run continuously for long time it has to be kept in infinite loop. 
Otherwise it will run only once and stops.



Ques 17: explain about ALU?
 ALU is present in the microprocessors  and microcontrollers. it will do the arithmetic and logic operations
 that is required to be done on instructions. The cpu is powerful if the design of the ALU good. It consumes
 more power and it releases more heat. This is why faster cpus consume more power releases more heat.

Interview Q & A 8

Interview Q & A 8



1. write a code for removing repeated digits in a number?
ex : number = 45678678 here the digits 6,7,8 has to be removed.



2. write a code to search the largest element in the array of your choice?



3. write a program to convert the integer string to number using atoi function.?


4. write a source code to find the sum of 1/3+1/5+1/7+ ....+1/n using recursive function?


5. write a code for linked list print function in reverse order?


6. what is the difference between address of variable and address of ponter variable, 
   explain using an example?


7. write a source code for insert a char/word/substring into a string?


8. can we return multiple values from the function explain with an example?


9.  what is the output for the below code?
	static int k= 8;
	int main()
	{
		if(-k)
		printf("%d", k);
		printf("error");
	}


10. what are the errors in the below source code?

int add();
int main()
{
	printf("function ",add());
}

int add()
{
	int x=5,y=4,z;
	z=x+y;
	printf("%d",z);
}


11. explain for the below code, the memory allocated is safe or not?

struct person
{
char per_name[10];
int per_age;
};
int main()
{
struct person *per;
per=(struct per*)malloc(sizeof(struct person));
free(per);
return 0;
}


12. explain the memory is safe for the below mentioned code?

struct person *per;
per=(struct person*)malloc(sizeof(struct person)*100);
char pername[] = "ptinstitute.in" ;
per = *pername;
free(per);
return 0;


13 what is the output for the below code explain?

char *name="ptinstitute.in";
char  name1[]="ptinstitute.in";
printf("%d %d ",strlen(name),strlen(name[]));
printf(" %d %d",sizeof(name++),sizeof(name[0]));


14. what is the output for the below program explain?
int main()
{
	int x=4,y=2,p,q,r;
	p=x||y;
	q=p&&x;
	r=p^q;
printf("%c %x %d",p,q,r);
return 0;
}


15. what is the output for the below code explain?

int main()
{
int p=4;
for( ;p++;printf("%d",p))
{
printf("ptinstitute.in");
}
return 0;
}

16. what is the output for the below program?

int main()
{
static int m=3;
main();
printf("%d",m++);
return 0;
}


answers:

10.  no errors. 
     output: 9 function

11. safe, because memory is allocated to pointer per.

12. here memory allocated to per , 
    then per = *pername         //it stores the 'p' in the per variable.
    we copying the ascii value of p to pointer p which gives runtime error.
    the allocated memory is not freed, so memory leakage happened here.

13. the prototype of strlen is
       size_t strlen ( const char * str );
    we need to pass the address of the string to find the length.
    in the program we passing strlen with name[], we are passing without index.
    we suppose to pass the address of the string. that is why it gives compile time error.
14. ascii character for 1, 1 0

15. it gives an lengthy loop, in the for loop we incrementing p++ in condition checking position,
    p++ doing continuously and the loop stops after p=0.

16 It gives an runtime error like stack over flow issue.
   here we are not exiting the recursive function main, it is calling continuously main recusively.



En-Query

    Your Name*
    Subject*
    Phone Number*
    Email Address*

    Message*

    PTInstitute