Tuesday, May 4, 2021

100 Embedded interview questions

 https://aticleworld.com/embedded-c-interview-questions-2/

Sunday, April 25, 2021

Constant pointer vs Pointer to constant

 const int* ptr;

is a pointer to constant (content). You are allowed to modify the pointer. e.g. ptr = NULL, ptr++, but modification of the content is not possible.


int * const ptr;

Is a constant pointer. The opposite is possible. You are not allowed to modify the pointer, but you are allowed to modify what it points to e.g. *ptr += 5.

Fun with array pointers and function pointers

1-D and 2-D array pointers.   

// Pointer to an integer

int *p; 

// Pointer to an array of 5 integers

int (*ptr)[5];

// Pointer to an array of 5x2 

int (*ptr1)[5][2];

int arr[5];

int arr1[5][2];

    // Points to 0th element of the arr.

    p = arr;

    // Points to the whole array arr.

    ptr = &arr;

// Points to the while 5x2 array

ptr1 = &arry1;   

==========

Function Pointers


void fun(int a)

{

    printf("Value of a is %d\n", a);

}

  

int main()

{

    // fun_ptr is a pointer to function fun() 

    void (*fun_ptr)(int) = &fun;    

//  OR

void (*fun_ptr)(int) = fun;

  

    /* The above line is equivalent of following two

       void (*fun_ptr)(int);

       fun_ptr = &fun; 

    */

  

    // Invoking fun() using fun_ptr

    (*fun_ptr)(10);

//OR

fun_ptr(10);

    return 0;

}

Saturday, April 24, 2021

Video Formats and chroma sub-sampling

 color space system.

-> RGB

-> YCbCR  (YPbPr in analog system)

-> HSB hue satuaration brightness

-> CMYK

=================

4:2:2 (Horizontal sub sampling) 8 bytes used for 4 pixel.

Y   Y  Y  Y

cb     cb

cr     cr

4:1:1 (Horizontal sub sampling)  6 bytes used for 4 pixel.

Y   Y  Y  Y

cb     

cr     

4:2:0 (Horizontal + Vertical sub sampling) 6 bytes used for 4 pixel.

y    Y

cb, 

cr,

y    y

================

YUV formats (8 bits only)

1) Planner

-> All Y would be in one array/plane, then all U would be in one array/plane and then V would be in once array/plane

-> Here all 3 array can be at different offset in single buffer also. 

I420, I422

-> reversed planners 

YV12 is exactly like I420, but the order of the U and V planes is reversed

2) Semi Planner

-> Semi planar formats have two planes instead of three, one plane for luminance, and one plane for both chrominance components. 

-> NV12, NV16

-> reveresed semi planners

-> NV21, NV61

3)Packed formats

In packed formats, you usually have only one plane. (This is something like RGB)

( packet formats cannot normally deal with vertical sub-sampling.)  

UYVY or Y422

YUY2 or V422 (reversed format)

Thursday, April 15, 2021

Gstreamer and OMX-IL state

 Gstreamer state handling


NULL -> Default state. NO resources are allocated in this state.

READY -> Element has allocated its all global resources. Element open the devices allocate the buffers. But stream is still not openened. NO stream specific allocation.

PAUSED -> Elemened has openned the stream but its actively processing stream. Audio/Video o/p pushed into buffers and queued to play it right after state change. Video sink element display first frame and paused.

Playing -> same as paused except clock is running and data is being processing  


OMX-IL state

Loaded: 

WaitingForResources

IDLE

Executiting

paused 

Saturday, March 27, 2021

Communication method between user space and kernel space and how those are implemented

 There are couple of well known methods to communicate from user space to kernel space.

  • Virtual file system like  /proc, /sys, configfs, /debugfs
  • Standard system call like read(),write(), open(), close(), fork()
  • ioctl for char drivers. With copy_to_user and copy_from_user
  • netlink socket
  • Use udev and uevent based event mechanisim from kernel space to user space.  Read more https://stackoverflow.com/a/23149574/775964
  • Sending signal from kernal space to user space thread. Full example at https://embetronicx.com/tutorials/linux/device-drivers/sending-signal-from-linux-device-driver-to-user-space/
  • Using common memory which can be used by user space/kernel space both like ION memory or DMABuf  read more here https://lwn.net/Articles/480055

Monday, November 23, 2020

Things to know about inline function

Below are some good points about inline function to keep in mind.

  1. Usage of inlne funcation , May increase function size so that it may not fit on the cache, causing lots of cahce miss.
  2. You can not use static variable in Inline funcation. If you use them then compiler will not treat this as inline funcation.
  3. You can not use recursion with inline funcation
  4. If funcation return value depends on any used loop, swicth or goto statement in your funcation then compiler will not treat this as inline funcation
Using inline will help, Just to save execuatation time by avoiding call/stack of funcation

inline funcation are good than macro becuase, macro does not perform any type checking/usual error checking while compilation.  

Macro are like find and replace while preprocessing steps.