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

Source: Internet
Author: User

Write a C program to quickly test the hardware driver:

Create the Driver_test folder in the external folder under the Android source root directory:

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 <stdio.h>  #include <stdlib.h>  #include <fcntl.h>        int main (int argc, char *argv [])  {      int  fd;      int  val=0;        Fd=open ("/dev/adrio", O_RDWR);            if (fd<0)      {          printf ("Open device failed!\n");          Exit (1);      }      else      {          printf ("Open success! \ n ");      }              Write (fd,argv[1],1);                Close (FD);      return 0;  }  
Back to Android source root: Make Driver_test

You may initially be prompted with an error:

Host C + +: Libhost <= build/libs/host/pseudolocalize.cpp/bin/bash:g++: Command not found

Make: ***[OUT/HOST/LINUX-X86/OBJ/STATIC_LIBRARIES/LIBHOST_INTERMEDIATES/PSEUDOLOCALIZE.O] Error 127

Solve:

Sudo-i
Aptitude Install g++

sudo apt-get install build-essential

After the installation is complete, do the following: Make Driver_test

Final compilation Complete:

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

Run:

./driver_test 1 (then D1)

./driver_test 0 (then D1)

Tested successfully, this method can be used to quickly test the Linux kernel driver under Android

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

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.