Sunday, December 11, 2011

Automotive Embedded Questions





















Embedded C, Control Area Network (CAN), CANAlyzer and CANoe Interview Questions:


Hello All, I hope these questions will help you on understanding Embedded C, CAN, CANAlyzer and CANoe

Enjoy
Yours Rasmi Ranjan Nayak............ The Ultimate Power of RAY Beyond Your Imagination

My Great Web page
Embedded C:
1.  How C program works?
Ans:
#include<stdio.h>
#define x 1      // http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html
main()
{
int i;
i = 0;
i = i + x;
printf("The value of i is %d \n", i);
Printf("Hello");                          // Run time error (Linking error), Think
}
Before compilation, preprocessor comes into picture, and the value of X gets replaced by 1 before actual compilation starts.
Then compiler looks for main() and starts compiling, and checks for the syntax format.
Then when we run the program the linking comes into picture, compiler links the functions and all called within the file, are really exists in the library or not?
If everything is Okay then program runs successfully...
Manythigs I have skipped (Where variable gets stored and all) and I briefed  some overall idea.

Refer http://www.howstuffworks.com/c.htm
2.What is the output of printf("%d")?
Ans:
main(){printf("%d");}
Output will be a Garbage.
3. Calloc vs Malloc
Ans:-
There are two differences.
First, is in the number of arguments. Malloc() takes a single argument (memory required in bytes), while calloc() needs two arguments.
Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.
  • calloc() allocates a memory area, the length will be the product of its parameters. calloc fills the memory with ZERO's and returns a pointer to first byte. If it fails to locate enough space it returns a NULL pointer.


Syntax: ptr_var=(cast_type *)calloc(no_of_blocks , size_of_each_block); 
i.e. ptr_var=(type *)calloc(n,s);
  • malloc() allocates a single block of memory of REQUSTED SIZE and returns a pointer to first byte. If it fails to locate requsted amount of memory it returns a null pointer.


Syntax: ptr_var=(cast_type *)malloc(Size_in_bytes);

                4. Struct vs union
Think and Try
I just wanted to add make/add a point here, In Union:-
union u{
int x;
char y;
}
u.x = 0;
u.y = 1.;
printf("The value of u.x will be ? ") //Think before you scroll Down or look down
The o/p of x will be garbage.
                5.  #define vs #include
Try yourself
                6.  #define vs typedef; Explain


typedefs can correctly encode pointer types.where as #DEFINES are just replacements done by the preprocessor.
For example,
typedef char *String_t;
  1. #define String_d char *
  2. String_t s1, s2; String_d s3, s4;
s1, s2, and s3 are all declared as char *, but s4 is declared as a char, which is probably not the intention.
http://www.oualline.com/style/c06.html
                7. #define vs enum; Which one is better? And Why?
Ans: Click the below link for better understnding
Coming to the question:- Which one is better and why?
It depends on the programmer.
If there is only few changes needed then #define is the best solution.
But if there are lots of changes need to be done then the solution is enum.
e.g,
#define x 1 // if tomorrow you are changing the value of x from 1 to 2 then #define is effective
similarly if there are many #defines like
#define X1 1
#define X2 2
.
.
.
#define Xn n
In this case we can use enum, to reduce the complexity.
enum {X1, X2....Xn};
Now the question is if X10 value changed from 10 to 50 but the rest of the sequence are unchanged then how to tackle? Think !!!
                8.Compilation How to reduce a final size of executable?

Ans:
Size of the final execuatable can be reduced using dynamic linking for libraries.
                9. What does static variable and function mean?
void func() {
        static int x = 0; // x is initialized only once across three calls of func()
        printf("%d, ", x); // outputs the value of x
        x = x + 1;
fun();
}
 O/p:- 0,1,2,3,.....
Because the scope of static variable is always to that particular function/file(incase of Global declaration).
It gets stored in Data Segment
The default value of static variable is always Zero, It (Default value or user-defined value) gets initialized at the run time.And it get initialized only once.
In this above example the value of x is initialized to Zero.
When next time fun() call happens, the variable x does not get initialized again.
Static Function:-
in file 1.c                    In file 2.c
main()                         static void fun(); void fun1();
{ fun(); fun1();}              void fun{ printf("It is a static fun") ;}
    void fun1{printf("It is not a static fun");}
Try to compile and see what happens, That (The warning or error) is your answer.
/*undefined reference to `Func' */ //Ans:: the fun() is local to file 2.c and can't get accessed by main().
*****
Local Variables are stored in Stack.
Register variables are stored in Register.
Global & static variables are stored in data segment.
The memory created dynamically are stored in Heap
And the C program instructions get stored in code segment
and the extern variables also stored in data segment.
*****
                10.  Can a static variable accessed from outside of the file?
Ans: See Qestion number 9.
                11.  Macro vs inline; Explain each of them; and which one is better why?
12.  What are different storage classes? Why register is used?
13.  Const vs static vs #define
14. What is the difference between strings and character arrays?
15.  Difference between const char* p and char const* p
16.  **p vs &*p vs *&p
17.What is hashing?
18.  memmove vs memcpy vs memset
19. How free() works?
20.  Can a variable be both const and volatile? Explain Volatile
21. Can include files be nested?
22.What is NULL pointer? Why it is required?
23.  Is NULL = = 0?
24.  What is static memory allocation and dynamic memory allocation?
25. How you do dynamic memory allocation?
26.  Is realloc() uses the same memory location which was used by malloc()?
27.  Describe different types of pointers?
28.  How are pointer variables initialized?
29.  Difference between arrays and pointers?
30.  Is using exit() the same as using return?
31. declaring a variable vs defining a variable
32. lvalue vs rvalue
33.  Differentiate between an internal static and external static variable?
34. string vs array?
35.  Call by value vs call by reference
36.What are advantages and disadvantages of external storage class?
37.Describe void pointer
38. Typecast when to use and when not to use?
39. Switch vs if; which one is better? Why?
40.  Linker vs linkage?
41.  Function vs built-in function
42.  Why should I prototype a function?
43.  Array vs Linked list
44.  Write a code for String reverse, strlen, etc
45.  Explain C memory
46. Little endian vs big endian? Why it is required? Which one is better? How the conversion happens? White a pseudo code for hton() and ntoh()
47.  How can you make sure that 3rd bit (Say 8-bits given to you) is set or not?
48. How do you set/reset a particular bit?
49. Write the T-table of X-OR
50.  What is code optimization?
51.  How code optimization does not happen when it comes to VOLATILE? Explain
52.  Const to Pointer vs Pointer to Const
53. Difference between Static and Dynamic Library
54. Write a function which takes few arguments and displays the arguments
e.g fun(int arg1, int arg2, int arg3); // May be infinite numbers of arguments
o/p will be value of agr1, arg2, arg3....
Ans:
Use logic of printf()
Refer http://en.wikipedia.org/wiki/Stdarg.h

55. 
How to write and read data from an address location in C language?
Ans:
Method -1 
Assume it's 8 bits:

char * address = (char *)3000; // address is a pointer to address 3000
char val;

*address = 36; // write 36 to 8 bit location at address

val = *address; // read 8 bit value from address
Method - 2
char *ptr; //u can take any datatype
ptr = 0x0000000a; //"0x0000000a" is hexadecimal adrr. bit

*ptr = 'a'; //here u put data "i had put a"

same as u can read it by

char d,*ptr;
'"
" // as it is above
'"
d = *ptr; // u`r value read from ptr is store in d

http://in.answers.yahoo.com/question/index?qid=20091118002501AAYTcjU

56. What is segmentation fault?

57. volatile vs const volatile, Explain


58. How function call happens in C? or 
How function/function call works internally?
Control Area Network:
1.   What is CAN?
2.   What is Asynchronous Serial Communication?
3.   Why CAN is reliable?
4.   How many layer it supports?
5.   What is the max speed of CAN?
6.   St. CAN vs Extd. CAN? Can they coexist on a network?
7.   If they can co-exist, which one will have priority; if not, what is the reason?
8.   Describe the process of bus arbitration in CAN?
9.   What's the difference between CSMA/CR and CSMA/CD?
10. How can we identify a specific sensor in a CAN network?
11. Data Frame vs Remote Frame; Who wins arbitration? Explain why?
12.  What is bus termination resistor value for CAN? Do they vary if we put them in each node instead of bus ends?
13. Explain Error Frame? Explain the error states (Like Passive Active and Bus-off)?
14.  What is BUS-Off? What happens when bus-off occurs?
15. What is TEC and REC?
16. How they increment and decrement?
17. What is difference between Inter frame space and overload frame?
18. What is time quanta?
19. Explain
20. How does CAN work? What are the features of CAN?
21. Why SOF is always a dominant bit?
22. Explain error detection mechanism?
23. CANALyzer vs CANoe
24. CAPL vs IG
25. IG block vs G block
26. How many nodes can be simulated in Canalyzer and Canoe?
27. Data frame vs Remote frame? Who wins when both are available in the network?
28. What is Bit-Encoding?
29. What is bit-stuffing?
30. Why bit stuff happens after 5th bit; why not after or before 4th or 6th bit?
31. What is DLC? Why is it needed?
32. CAN vs LIN?
33. CAN vs KWP vs UDS?
34. Why 7F has considered for €“ve response why not other than 7F?
35. What is tester present? Why do we need it?
36. What is security Access? Why do we need it?
37. What is CANCaseXL (if you have used it)? Explain with types?
38. If there are only two nodes on the bus, and both are transmitting same    identifier(exactly the same identifier),who will win the arbitration or what happens?
39. If there is only one node on the bus and it is transmitting messages on the bus continuously, what will happen? Is node will go into the bus-off state or what happens?
41. Is CAN full duplex? what is the significance of Extended frames other than that it can be used for generating more identifiers?
42. What is the major difference between CAN 2.0B and previous version?
43. Without CAPL,can we simulate the other ECU's CAN Messages except Test ECU in the CAN Simulation Network in CANoe tool without using IG or G blocks.
44. How many can database files are required for CAN Network simulation in CANoe tool.
45. what is the difference between CANalyzer,CANoe and CANape tools?
46. Mention the few uses of the CANoe tool?
47. what is a panel is CANoe Tool and its Use?
48. Why CAPL scripting is used in CANoe tool?
49.   Is it possible to simulate other ECU's Except Test ECU without CAPL Scripting in CANoe tool?
50. What is flow control frame?
Automotive Questions:
1. What is EBS (Electronic Braking System)? How it is different from ABS?
2. What is EBD (electronic brake force distribution)? How it helps your vehicle?
3. What is Traction Control System?
4. Are the speed/velocity of four wheels are always same?
V1 = V2 = V3 = V4?
5. What is YAW Rate?
6. What is Freeze Frame Data?
7. What is Stop-start engine system (stop-idle)? Why it is required?
8. In a traffic if Engine stops then how it turns on?
9. How the engine coolant works?



RTOS:
1. What is a Real-Time System?

2. Does the RTOS give you a flexible set of scheduling policies?

3. Does the RTOS use the dynamic object’s address as its identifier?

4. Are interrupts handled with a macro/function or do you have to write your own prologue (entry) and epilogue (exit)?

5. How does the RTOS synchronize with events? Do your event synchronization objects automatically clear with a task release or can events be missed? Can multiple tasks wait on a single event? Can a single task wait on multiple events?

6. Does the RTOS allow you to count both periodic or aperiodic ticks?

7. Can the RTOS count ticks other than time?

8. Are Timers/Alarms globally available so that they can be used by multiple tasks or are they tied to a single task? Does the RTOS allow you to define future actions to be taken when any counter reaches a predefined value?

9. Does the RTOS manage RAM with a heap that can create non-deterministic response and fragmentation?

10.Does the RTOS provide multiple data passing options?

11. Does the RTOS allow data to be passed between tasks and ISRs (or just between tasks)?

12. How does the RTOS provide exclusive access to resources? Does it use binary semaphores or mutexes?

13. Does the RTOS have a mechanism to prevent priority inversion—when a low priority task has control of a resource that is required by a higher priority task?

14. How the RTOS is coded. Is it designed for deterministic operation? Does it ensure low system overhead? Low latency? Responsive services?

15. Write a code to connect Hardware interrupt to ISR? 

16. What is priority inversion ? and What is the solution ? 

17. Explain Priority Inheritance 

18. Explain various types of Scheduling

19. Which RTOS supports Non-Preemptive scheduling ? Why other scheduling methods are supported by such Oses? 

20. RTOS vs OS

21. what is a non re-entrant code?

22. Is unix a multitasking or multiprocessing operating system? whats the difference between the two?

23. What is stack overflow and heap overflow?

24. What is a core dump?

25. Windows also has multiple processes has process priotities switches between multiple process, how RTOS is different from that?

26. what is paging, segmentation Why do we need it?

27. write a code to check wther a stack grows upwards or downwards?

28. Why do we require semaphore mutex?

29. write a small piece of code protecting a shared memory variable with a semaphore?





For RTOS Answers... Click the below link

http://www.quadros.com/resources/white-papers/questions-to-ask-when-choosing-an-rtos

http://www.freewebs.com/chinswe/rtosquestions.htm




Some more questions are coming up on RTOS, CAN and Embedded C as well. I will write my answer or understanding.
You can write your answers and your comments as well.
All comments are mostly welcomed.