Embedded C,RTOS interview questions with answers


Recommended Embedded RTOS books to buy:
1) What is RTOS and why do we go for it?
       RTOS sheludes execution in a timely manner,manages system resources and provides a consistent foundation for developing application code.
     Application code designed for RTOS could be ranging from simple digital stopwatch to complex aircraft navigation systems.
RTOS differs from the GPOS by
  Task scheduling : RTOS like vxWorks,neclueos, uC/OSII uses a strict scheduling algorithms (like pre-emptive scheduling) that makes the tasks meet their deadline to get the job done.
  The sheduler decides which task run when by knowing its priorities.Whereas In a GPOS, the scheduler typically uses a "fairness" policy that offers no assurances that high-priority, time-critical tasks will execute in preference to lower-priority tasks.This policy is maintained to obtain the overall output by the desktop pc or server pc.

2) What are the different types of semaphores in vxworks RTOS? Which is the fastest?
       VxWorks supports three types of semaphores.
 1) Binary 2) mutual exclusion, and 3)counting semaphores.
 Fastest : Binary semaphore.


         3. What is priority inversion ? why priority inversion occurs?
     Tasks in RTOS's communucates between them via IPC source semphores for synchornization.
     The situation priority inversion occurs when a higher priority taks is ready to run but it is waiting for a shared resource that is to be released by a lower priority task currently running .Now higher-priority task is pending on the resource and it has to wait until the lower priority task to finish.
4. What are the solutions for priority inversion ?

    1) Priority inheritance
    2) Priority ceiling

5. What is super loop ?

      Super loop is the infinite loop that runs all the time because , most of the embedded systems has no OS in it to return to application.
//Super loop example
while(true)
{
 //all other code
}

//or

for(;;)
{
}

//or

label:
//This is is tricky assembly version
goto label:


6) What is the difference between Structure and union? Where do we use union?

        When a structure is defined the compiler allocates memory for all of its member variables with necessary alignment .Whereas for unions the compiler allocates memory for the highest the union is equal to the biggest size of member from the union member variable list.union can only store information in one field at any one time.
#include <stdio.h>
struct mStruct
{
    char name[10];
    int age;
    float height;
};

union mUnion
{
    char name[15];
    int age;
    float height;
};

int main(void)
{
    union  mUnion  uTest;
    struct mStruct sTest;
    strcpy(sTest.name,"sTest");
    sTest.age    = 20;
    sTest.height = 6.1;
    strcpy(uTest.name ,"uTest");
    uTest.height = 6.0;
    uTest.age    = 20;
    printf("\n");
    printf("sizeof(uTest) = %d ,sizeof(sTest) = %d \n",sizeof(uTest),sizeof(sTest));
    printf("uTest.age = %d , uTest.height = %f , uTest.name = %s\n",uTest.age, uTest.height, uTest.name);
    printf("sTest.age = %d , sTest.height = %f , sTest.name = %s\n",sTest.age, sTest.height, sTest.name);
    printf("\n");
}
7) Convert number 2 --> 37 without using any other operator but bitwise ? 
Answer:
    int x = 2;
    printf("X before :%d\n",x);
    x = (x<<x<<x) | (x<<x<<x) |  x<<!!x | !!x ;
    printf("X After  :%d\n",x); 

 

8) Set , Get , Clear ,Toggle , Display Bits ?
// Display Every bits in a int number 
void displayBits(int data)
{
    int dataSize = 1<<sizeof(data);
    int count = 0;
    for (count = dataSize;count >= 0; count--)
    {
        printf("%d",(testBit(data,count)));
    }
}
// test a bit if it is zero or one 
int8_t testBit(int8_t value,int whichBit)
{
    int mask = 1 << whichBit;
    if (value&mask)
    {
        return TRUE;
    }
    else return FALSE;
}

// Set a bit to one 
int8_t setBit(int8_t result, int whichBit)
{
    return (result |= (1<<whichBit));
}

// toggle a bit  
int8_t toggleBit(int8_t result, int whichBit)
{
    return (result ^= (1<<whichBit));
}

/* Clear a bit to zero */
int8_t clearBit(int8_t result, int whichBit)
{
    return (result &=~ (1<<whichBit));
}

11 comments:

AdithyaG said...

Hi. How is '!' a bitwise operator?

Anonymous said...

It is logical operator , not bitwise .. good catch..

akmal niazi khan said...

This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

Love from

Interview questions answers pdf said...

MATLAB Interview Questions and Answers
http://allinterviewquestionsandanswerspdf.blogspot.in/2016/05/top-16-matlab-interview-questions-and.html

Karthika Shree said...

This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
Embedded Training in Chennai

Anonymous said...

Can someone post the output for the code for Question 6 regarding the Struct and Union. The size of struct and union values are different than expected.

Hesham Moustafa said...

for (count = dataSize;count >= 0; count--) is wrong it must be for (count = dataSize-1;count >= 0; count--) else you will get 17 bit not 16 bit for an integer. Confirmed by running the code

gowsalya said...

Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
digital marketing training in tambaram

digital marketing training in annanagar

digital marketing training in marathahalli

digital marketing training in rajajinagar

Digital Marketing online training

full stack developer training in pune

Nila shri said...

I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.

Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
Data Science training in marathahalli

sandhya kits said...

Really great blog, it's very helpful and has great knowledgeable information.
Online IT Training Videos

Office 365 Training Videos

Exchange Server Training Videos

Sap Security Training Videos

Sap MM Training Videos

sandhya kits said...

Best online training institute
Tableau Training

Teradata Training

Testing tools Training

Tibco Training