Android from hardware to application: Step by Step 2 -- run the C program to test the hardware driver

Source: Internet
Author: User

Android from hardware to application: Step by Step 2 -- run the C program to test the hardware driver

Compile a C program to quickly test the hardware driver:

Create the driver_test folder in the external Folder under the root directory of the Android source code:

Cd external

Mkdir driver_test

Cd driver_test

Create Android. mk:

 

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_MODULE := driver_testLOCAL_SRC_FILES := driver_test.cinclude $(BUILD_EXECUTABLE)
Create driver_test.c:

 

 

#include 
 
    #include 
  
     #include 
   
            int main(int argc, char *argv[])  {      int  fd;      int  val=0;        fd=open(/dev/AdrIO,O_RDWR);            if(fd<0)      {          printf(open device failed !);          exit(1);      }      else      {          printf(open success ! );      }              write(fd,argv[1],1);                close(fd);      return 0;  }  
   
  
 
Go back to the Android source code root directory: make driver_test

 

An error may be prompted at first:

 

Host c ++: libhost <= build/libs/host/pseudo dolocalize. cpp/bin/bash: g ++: Command not found

Make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/pseudo localize. o] Error 127

Solution:

Sudo-I
Aptitude install g ++

Sudo apt-get install build-essential

After installation, run make driver_test.

The final compilation is complete:

 

Install: out/target/product/generic/system/lib/libm.soInstall: out/target/product/generic/system/bin/driver_test
Copy out/target/product/generic/system/bin/driver_test to the AM335X file system and start Android

 

Run:

./Driver_test 1 (D1 on at this moment)

 

./Driver_test 0 (D1 off at this time)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.