Friday 22 March 2013

Useful Linux Commands

Useful Linux Commands

To change owner of folder in Ubuntu:
$ sudo chown -R owner-user:owner-group folder-name
$ ls -l -> drwxr-xr-x 6 owner-user:owner-group 4096 Nov  3 16:33 folder-name

To Create symlink:
$ ln -s [Target Directory or File] ./[Shortcut]

To get uid (user id):
$ id

To Mount android emulator's sdcard.img  on Ubuntu:
$ sudo mount -o rw,uid=user_id,loop sdcard.img mount_point

To Split large file in pieces:
$ split -b 1024M large-file-name piece-file-name

To Join pieces of large file:
$ cat file1 file2 file3 > large.file OR cat file* > large.file

To upgrade Ubuntu: 
Press Alt+F2 then Type update-manager -d

To move Ubuntu buttons to right side:
$ gconf-editor -> apps/metacity/general -> button_layout -> menu:maximize,minimize,close

To download git repository:
$ git clone https://github.com/keesj/Android-HelloWorldService.git

To Open Linux share from Windows:
Type in run:-  \\linux_ip_address OR name
e.g. \\10.44.82.127\ OR \\myvostro\

To Open Windows share from linux: 
Go to Places-> Connect to Server-> Select Windows Share
Enter windows_ip_address OR name, Domain, Password
 
To Mount Windows share on Ubuntu

$ sudo mount -t cifs //windows_ip_address OR name/folder_name /mount_point -o username=window's, password=window's, domain=window's

To Open remote Desktop from Linux Machine:

$ rdesktop -g 1600x825 remote_mc_name -d domain_name

Linux Device Driver Interview Questions

Linux Device Driver Interview Questions

What is kernel panic? How it occur? How to debug and fix it?
What is trace32 simulator? How to use it?
What is debugfs? How to use it?
What is MMU? What is the role of MMU?
What are the kernel debugging tools? How to use them?
What is memory corruption? How to debug it?
What is cache corruption?
What is bit-flip?
What is useof L1 and L2 Cache memory?
(Note: L1- Faster but smaller in size and private to each cpu core
           L2- Slower but bigger in size and common to all cores)
How to disable L1 or L2 cache memory? (Note: from kernel config)
What is vmlinux? What are the modules it contain? How to build it?
What is memory scrubbling?
What is TLB (Translation lookup table)?
What is RTB, ETB, Page poisoing, slub debugging?
What is use of Signals? What is use of abort signal? Where to use it?
Describe IOMMU architecture?
What is cpu register corruption?

Wednesday 13 March 2013

program for ADC 0808 connecting Temperature sensor using 8051


/********************* ADC-0808****************************/

#include<REG51.H>                      //including the header file registers of 8051
sfr adcdata=0x90;                           //assigning adc data to port 1
sfr ldata=0x80;                  `             //assigning lcd data to port 0
sbit rs=P2^7;                                   // assining control pins to port2.5,6,7
sbit rw=P2^6;
sbit en=P2^5;

// channel selection bits of adc
sbit ch_a=P3^2;                           
sbit ch_b=P3^3;
sbit ch_c=P3^4;
  // control pins of adc
sbit ALE=P3^5;                             //address latch enble pin  
sbit EOC=P3^6;                            // end of converssion pin
sbit SC=P3^7;                                                        //select chip pin
sbit motor=P2^0;                                                  //assigning motor
sbit LED0=P2^1;                                                  //assigning led’s
sbit LED1=P2^2;
sbit LED2=P2^3;
sbit LED3=P2^4;
void cmd(unsigned char  y);                               //lcd command function           
void lcddata(unsigned char  y);                          //lcd data function
void disp_str(unsigned char  *P);                      //to display string in lcd
void delay(unsigned int k);                                //delay function
//void lcdinit(void);
unsigned char convertanddispaly(unsigned char value);
void disp_loc(unsigned char , unsigned char *);
unsigned char value,z,c,TEMP,T,LDR,L;
unsigned char adc_data(unsigned char);

/**************************convert program*************************/
// the function is used to convert the integer value to ascii value
unsigned char convertanddispaly(unsigned char value)
{
    unsigned char x,d1,d2,d3;
    x=value/10;                                            
    d1=value%10;
    d2=x%10;
    d3=x/10;
    lcddata(d3+0x30);                                //move data d3 to lcd             
    lcddata(d2+0x30);                                //move data d2 to lcd
    lcddata(d1+0x30);                               //move data d1 to lcd
    z=d1*100+d2*10+d3;
    return(z);
}

 /**********************main program start************************/

void main()
{
         adcdata=0xff;
         EOC=1;                                       // initial condition values of ADC control pin
         ALE=0;
         SC=0;
         lcdinit();                                     //initialize the lcd 
        delay(10);                                    //delay of 10
        cmd(0x01);                                 //lcd command to clear  the screen
        disp_loc(0xc0,"  ADC Project ");
        delay(100);
        cmd(0x01);
        disp_loc(0x80,"TEMP:");
        disp_loc(0x89,"LDR:");
     
        while(1)
                  {
                      TEMP=adc_data(1);
                      cmd(0x85);                               //lcd command to write in the location 85
                      T=convertanddispaly(TEMP);  //convert and display  temperature
                      delay(1);//delay of 1
                      LDR=adc_data(0);                     // the adc_data is moved to LDR
                      cmd(0x8D);                               //lcd command to write in th location 8D
                       L=convertanddispaly(LDR);    //convert and display   light
                        delay(1);
                             
                  }
}




/***********************switch cases******************************/
//The function to select the adc channel.
unsigned char adc_data(unsigned char c)
{
       switch(c)
        {
          case 0: ch_a=0; ch_b=0; ch_c=0;                // channel0 selection
                  break;

          case 1:  ch_a=1; ch_b=0; ch_c=0;               // channel1 selection
                  break;

          case 2: ch_a=0; ch_b=1; ch_c=0;                // channel2 selection
                   break;

         case 3: ch_a=1; ch_b=1; ch_c=0;                 // channel3 selection
                  break;

         case 4: ch_a=0; ch_b=0; ch_c=1;                 // channel4 selection
                  break;

         case  5: ch_a=1; ch_b=0; ch_c=1;                  // channel5 selection
                    break;

         case 6:   ch_a=0; ch_b=1; ch_c=1;                 // channel6 selection
                  break;

         default: ch_a=1; ch_b=1; ch_c=1;                  // channel7 selection
                  break;
}
delay(1);
ALE=1;
delay(1);
SC=1;
delay(1);
ALE=0;
SC=0;
while(EOC==1);                      //monitoring end of conversion bit until EOC equal to 0
delay(1);
value=adcdata;
EOC=1;
return(adcdata);
}
void disp_loc(unsigned char r, unsigned char *s)
{
         ldata=r;
         rs=0;
         rw=0;
        en=1;
        delay(2);
        en=0;
         while(*s!='\0')
         lcddata(*s++);
}

lcdinit()                                  //lcd initialize
{
cmd(0x38);                            // 2 lines and 5x7 matrix
cmd(0x0e);                            //display on, cursor blinking
cmd(0x01);                           //clear display screen
cmd(0x06);                           //increment cursor
cmd(0x80);                          //force cursor to beginning of 1st line
disp_str("welcome");
}
void cmd(unsigned char y)
{
ldata=y;
rs=0;
rw=0;
en=1;
delay(10);
en=0;
}
void lcddata(unsigned char y)
{
ldata=y;
rs=1;
rw=0;
en=1;
delay(10);
en=0;
}
void disp_str(unsigned char *P)
{
while(*P!='\0')
lcddata(*P++);
}
void delay(unsigned int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
for(j=0;j<1200;j++);
}

                                                           


program for ADC 0808 connecting Temperature


/********************* ADC-0808****************************/

#include<REG51.H>                      //including the header file registers of 8051
sfr adcdata=0x90;                           //assigning adc data to port 1
sfr ldata=0x80;                  `             //assigning lcd data to port 0
sbit rs=P2^7;                                   // assining control pins to port2.5,6,7
sbit rw=P2^6;
sbit en=P2^5;

// channel selection bits of adc
sbit ch_a=P3^2;                           
sbit ch_b=P3^3;
sbit ch_c=P3^4;
  // control pins of adc
sbit ALE=P3^5;                             //address latch enble pin  
sbit EOC=P3^6;                            // end of converssion pin
sbit SC=P3^7;                                                        //select chip pin
sbit motor=P2^0;                                                  //assigning motor
sbit LED0=P2^1;                                                  //assigning led’s
sbit LED1=P2^2;
sbit LED2=P2^3;
sbit LED3=P2^4;
void cmd(unsigned char  y);                               //lcd command function           
void lcddata(unsigned char  y);                          //lcd data function
void disp_str(unsigned char  *P);                      //to display string in lcd
void delay(unsigned int k);                                //delay function
//void lcdinit(void);
unsigned char convertanddispaly(unsigned char value);
void disp_loc(unsigned char , unsigned char *);
unsigned char value,z,c,TEMP,T,LDR,L;
unsigned char adc_data(unsigned char);

/**************************convert program*************************/
// the function is used to convert the integer value to ascii value
unsigned char convertanddispaly(unsigned char value)
{
    unsigned char x,d1,d2,d3;
    x=value/10;                                            
    d1=value%10;
    d2=x%10;
    d3=x/10;
    lcddata(d3+0x30);                                //move data d3 to lcd             
    lcddata(d2+0x30);                                //move data d2 to lcd
    lcddata(d1+0x30);                               //move data d1 to lcd
    z=d1*100+d2*10+d3;
    return(z);
}

 /**********************main program start************************/

void main()
{
         adcdata=0xff;
         EOC=1;                                       // initial condition values of ADC control pin
         ALE=0;
         SC=0;
         lcdinit();                                     //initialize the lcd 
        delay(10);                                    //delay of 10
        cmd(0x01);                                 //lcd command to clear  the screen
        disp_loc(0xc0,"  ADC Project ");
        delay(100);
        cmd(0x01);
        disp_loc(0x80,"TEMP:");
        disp_loc(0x89,"LDR:");
     
        while(1)
                  {
                      TEMP=adc_data(1);
                      cmd(0x85);                               //lcd command to write in the location 85
                      T=convertanddispaly(TEMP);  //convert and display  temperature
                      delay(1);//delay of 1
                      LDR=adc_data(0);                     // the adc_data is moved to LDR
                      cmd(0x8D);                               //lcd command to write in th location 8D
                       L=convertanddispaly(LDR);    //convert and display   light
                        delay(1);
                             
                  }
}




/***********************switch cases******************************/
//The function to select the adc channel.
unsigned char adc_data(unsigned char c)
{
       switch(c)
        {
          case 0: ch_a=0; ch_b=0; ch_c=0;                // channel0 selection
                  break;

          case 1:  ch_a=1; ch_b=0; ch_c=0;               // channel1 selection
                  break;

          case 2: ch_a=0; ch_b=1; ch_c=0;                // channel2 selection
                   break;

         case 3: ch_a=1; ch_b=1; ch_c=0;                 // channel3 selection
                  break;

         case 4: ch_a=0; ch_b=0; ch_c=1;                 // channel4 selection
                  break;

         case  5: ch_a=1; ch_b=0; ch_c=1;                  // channel5 selection
                    break;

         case 6:   ch_a=0; ch_b=1; ch_c=1;                 // channel6 selection
                  break;

         default: ch_a=1; ch_b=1; ch_c=1;                  // channel7 selection
                  break;
}
delay(1);
ALE=1;
delay(1);
SC=1;
delay(1);
ALE=0;
SC=0;
while(EOC==1);                      //monitoring end of conversion bit until EOC equal to 0
delay(1);
value=adcdata;
EOC=1;
return(adcdata);
}
void disp_loc(unsigned char r, unsigned char *s)
{
         ldata=r;
         rs=0;
         rw=0;
        en=1;
        delay(2);
        en=0;
         while(*s!='\0')
         lcddata(*s++);
}

lcdinit()                                  //lcd initialize
{
cmd(0x38);                            // 2 lines and 5x7 matrix
cmd(0x0e);                            //display on, cursor blinking
cmd(0x01);                           //clear display screen
cmd(0x06);                           //increment cursor
cmd(0x80);                          //force cursor to beginning of 1st line
disp_str("welcome");
}
void cmd(unsigned char y)
{
ldata=y;
rs=0;
rw=0;
en=1;
delay(10);
en=0;
}
void lcddata(unsigned char y)
{
ldata=y;
rs=1;
rw=0;
en=1;
delay(10);
en=0;
}
void disp_str(unsigned char *P)
{
while(*P!='\0')
lcddata(*P++);
}
void delay(unsigned int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
for(j=0;j<1200;j++);
}

                                                           


program for ADC


/********************* ADC-0808****************************/

#include<REG51.H>                      //including the header file registers of 8051
sfr adcdata=0x90;                           //assigning adc data to port 1
sfr ldata=0x80;                  `             //assigning lcd data to port 0
sbit rs=P2^7;                                   // assining control pins to port2.5,6,7
sbit rw=P2^6;
sbit en=P2^5;

// channel selection bits of adc
sbit ch_a=P3^2;                           
sbit ch_b=P3^3;
sbit ch_c=P3^4;
  // control pins of adc
sbit ALE=P3^5;                             //address latch enble pin  
sbit EOC=P3^6;                            // end of converssion pin
sbit SC=P3^7;                                                        //select chip pin
sbit motor=P2^0;                                                  //assigning motor
sbit LED0=P2^1;                                                  //assigning led’s
sbit LED1=P2^2;
sbit LED2=P2^3;
sbit LED3=P2^4;
void cmd(unsigned char  y);                               //lcd command function           
void lcddata(unsigned char  y);                          //lcd data function
void disp_str(unsigned char  *P);                      //to display string in lcd
void delay(unsigned int k);                                //delay function
//void lcdinit(void);
unsigned char convertanddispaly(unsigned char value);
void disp_loc(unsigned char , unsigned char *);
unsigned char value,z,c,TEMP,T,LDR,L;
unsigned char adc_data(unsigned char);

/**************************convert program*************************/
// the function is used to convert the integer value to ascii value
unsigned char convertanddispaly(unsigned char value)
{
    unsigned char x,d1,d2,d3;
    x=value/10;                                            
    d1=value%10;
    d2=x%10;
    d3=x/10;
    lcddata(d3+0x30);                                //move data d3 to lcd             
    lcddata(d2+0x30);                                //move data d2 to lcd
    lcddata(d1+0x30);                               //move data d1 to lcd
    z=d1*100+d2*10+d3;
    return(z);
}

 /**********************main program start************************/

void main()
{
         adcdata=0xff;
         EOC=1;                                       // initial condition values of ADC control pin
         ALE=0;
         SC=0;
         lcdinit();                                     //initialize the lcd 
        delay(10);                                    //delay of 10
        cmd(0x01);                                 //lcd command to clear  the screen
        disp_loc(0xc0,"  ADC Project ");
        delay(100);
        cmd(0x01);
        disp_loc(0x80,"TEMP:");
        disp_loc(0x89,"LDR:");
     
        while(1)
                  {
                      TEMP=adc_data(1);
                      cmd(0x85);                               //lcd command to write in the location 85
                      T=convertanddispaly(TEMP);  //convert and display  temperature
                      delay(1);//delay of 1
                      LDR=adc_data(0);                     // the adc_data is moved to LDR
                      cmd(0x8D);                               //lcd command to write in th location 8D
                       L=convertanddispaly(LDR);    //convert and display   light
                        delay(1);
                             
                  }
}




/***********************switch cases******************************/
//The function to select the adc channel.
unsigned char adc_data(unsigned char c)
{
       switch(c)
        {
          case 0: ch_a=0; ch_b=0; ch_c=0;                // channel0 selection
                  break;

          case 1:  ch_a=1; ch_b=0; ch_c=0;               // channel1 selection
                  break;

          case 2: ch_a=0; ch_b=1; ch_c=0;                // channel2 selection
                   break;

         case 3: ch_a=1; ch_b=1; ch_c=0;                 // channel3 selection
                  break;

         case 4: ch_a=0; ch_b=0; ch_c=1;                 // channel4 selection
                  break;

         case  5: ch_a=1; ch_b=0; ch_c=1;                  // channel5 selection
                    break;

         case 6:   ch_a=0; ch_b=1; ch_c=1;                 // channel6 selection
                  break;

         default: ch_a=1; ch_b=1; ch_c=1;                  // channel7 selection
                  break;
}
delay(1);
ALE=1;
delay(1);
SC=1;
delay(1);
ALE=0;
SC=0;
while(EOC==1);                      //monitoring end of conversion bit until EOC equal to 0
delay(1);
value=adcdata;
EOC=1;
return(adcdata);
}
void disp_loc(unsigned char r, unsigned char *s)
{
         ldata=r;
         rs=0;
         rw=0;
        en=1;
        delay(2);
        en=0;
         while(*s!='\0')
         lcddata(*s++);
}

lcdinit()                                  //lcd initialize
{
cmd(0x38);                            // 2 lines and 5x7 matrix
cmd(0x0e);                            //display on, cursor blinking
cmd(0x01);                           //clear display screen
cmd(0x06);                           //increment cursor
cmd(0x80);                          //force cursor to beginning of 1st line
disp_str("welcome");
}
void cmd(unsigned char y)
{
ldata=y;
rs=0;
rw=0;
en=1;
delay(10);
en=0;
}
void lcddata(unsigned char y)
{
ldata=y;
rs=1;
rw=0;
en=1;
delay(10);
en=0;
}
void disp_str(unsigned char *P)
{
while(*P!='\0')
lcddata(*P++);
}
void delay(unsigned int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
for(j=0;j<1200;j++);
}