网页浏览总次数

2012年2月20日星期一

Embedded System interview Question

1. What are static variables?


Static variable in a function only remain one copy of itself.
Static variable in a module can be used by any function in the module
Static function can only be called in its class


2. What are volatile variables?
Volatile variables may change its value unexpectedly in the program.
The program will check its value every time, it tries to use it.
If a variable is not volatile, the program may keep a copy of the var in its cache.


3. What do you mean by const keyword ?
A constant variable is a read only variable. You cant change its value else where except initialization.


4. What is interrupt latency?
Interrupt latency is the time between the generation of interrupt and the time for interrupt handler to process it.


5. How you can optimize it?
We may use polling and message passing for interrupt to handle interrupt immediately.


6. What is size of character, integer, integer pointer, character pointer?
The size of character is 1 byte, integer is 4 bytes.
Character pointer is platform dependent, in a 32 bits system it's 4 bytes.


7. What is NULL pointer and what is its use?
When a pointer points to nothing


8.What is void pointer and what is its use?
If a function is defined like: int func (void *a);
It can take any type of pointer


9.What is ISR?
ISR is interrupt service routine which is a short routine used to handle interrupt.


10. What is return type of ISR?
ISR does not return anything, it does not have parameter.


11.Can we use any function inside ISR?
If a function could be reentrant, then we could use it. Since during the ISR, another interrupt may occur. If the interrupts are turned off, then I think we could call other functions.


12. Can we use printf inside ISR?
Generally we dont want to use printf, since it's not valid for reentrant, also ISR is supposed to be short, but printf takes too much time.


13. Can we put breakpoint inside ISR?
Yes, we can.  But I think we can only set breakpoint in emulator where hardware is emulated. Since during the process of ISR, it will occupy the CPU resource.


14. How to decide whether given processor is using little endian format or big endian format ?
 Little endian means store the least significant bit in smaller address.
To test it we can do this:
int a=1;
if(*(char *)&a==1){// convert int to char which is only 1 byte, so if it still has value, the value is store in //smaller addr
   printf("Little endian");
}
15.What is Top half & bottom half of a kernel?
 When handling interrupt, we divide the routine into two halves, top half will responde quickly, and call bottom half which will continue to handle the interrupt.


16.Difference between RISC and CISC processor.

17.What is RTOS?It's real time operating system.


18.What is the difference between hard real-time and soft real-time OS?Hard real-time system has strict limit on the deadline, while soft real-time OS has comparably loose requirement


19.What type of scheduling is there in RTOS?There are many types: static and dynamic.
Earliest deadline first, round robin etc


20.What is priority inversion?
It means a task with lower priority will run in front of the task with higher priority in some circumstances.


22.How many types of IPC mechanism you know?
Share memory, procedure call, semaphore, message passing


23. What is semaphore?


24. What is spin lock?
It's like busy waiting, it will check condition continuously in a while loop until the condition is met. This is resource wasting.


25.What is difference between binary semaphore and mutex?Binary semaphore only has two state its upper limit is 1. Mutex has higher limit up to a point, but the lower is the same binary semaphore which is 0.


26.What is virtual memoryWith virtual memory, the program will view the memory as if it has the whole memory space. It's indirect access, the OS will keep a mapping which maps virtual memory address to physical memory address.


27.What is kernel paging?
Ideally, kernel will put all its routine inside the memory, so that they could be fetched quickly which they are called. But sometimes the memory does not have enough space, so the kernel will swap part of the services to hard drive, and fetches them if they are needed.


28. Can structures be passed to the functions by value?
Yes, structures can be passed by value.


29.Why cannot arrays be passed by values to functions?
The array name represents the first element in the array.


30.Advantages and disadvantages of using macro and inline functions?
Macro does not have type checking. Inline function is replaced to the entire function by the complier.


31.What happens when recursion functions are declared inline?It depends some complier will expand it up to a limit, others will simply not expand it.


32.#define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives
preprocessor warning. Why?
cat(cat(1,2),3) will be replaced to 1##2##3, ## could only concatenate two arguments.


33.Can you have constant volatile variable? Yes, you can have a volatile pointer
34.++*ip increments what? it increments what ip points to 35.Operations involving unsigned and signed — unsigned will be converted to signed 36.malloc(sizeof(0)) will return — valid pointer
37.main() {fork();fork();fork();printf("hello world"); } — will print 8 times.
38.Array of pts to functions — void (*fptr[10])()

Array of pointer to functions is useful, when function with similar functionality, but different parameters could be stored in an array and called like element in the array. 
39.Which way of writing infinite loops is more efficient than others? there are 3ways. 
while(1) ; for(;;); Go to
I think go to is the most efficient

40.How to know whether system uses big endian or little endian format and how to convert among them?


41.What is forward reference w.r.t. pointers in c?
Forward reference means a reference is used before its declaration.
There are only two cases:
structure and goto statement 

42.How is generic list manipulation function written which accepts elements of any kind? 





43.What is the difference between embedded systems and the system in which RTOS is running? 
RTOS requires much more constraint on the time and scheduling


44.How can you define a structure with bit field members?



45.How do you write a function which takes 2 arguments - a byte and a field in the byte and

returns the value of the field in that byte?

We can move the number using shift operator (>>)



46.Which parameters decide the size of data type for a processor ? 


47.What is job of preprocessor, compiler, assembler and linker ?


48.What is the difference between static linking and dynamic linking ? 


49.How to implement a WD timer in software ? 







1 条评论: