NDK Java Native Interface 1 NDK Java Native

  • Slides: 44
Download presentation
NDK / Java Native Interface 자바 네이티브 인터페이스 -1 -

NDK / Java Native Interface 자바 네이티브 인터페이스 -1 -

NDK / Java Native Interface § Android NDK § § § A toolset that

NDK / Java Native Interface § Android NDK § § § A toolset that lets you embed in your apps native source code C, C++(recently supported December 2010) and assembly(? ) It is supported on android cupcake(1. 5)+ -5 - Huins. R&D Center 5

NDK / Java Native Interface § NDK 설치 - jni 파일을 컴파일하여 so파일로 컴파일

NDK / Java Native Interface § NDK 설치 - jni 파일을 컴파일하여 so파일로 컴파일 하는 툴과 예제를 포함한 개발 킷 § NDK 다운로드 § § android-ndk-r 9 b-linux-x 86. tar. bz 2 다운로드 from http: //developer. android. com/tools/sdk/ndk/index. html or http: //web. donga. ac. kr/jwjo or [CD]/android_tools/linux/ndk_linux_x 86_x 64/android-ndk-r 8 -linux-x 86. tar NDK 복사 및 설치 # tar jxvf android-ndk-r 9 b-linux-x 86. tar. bz 2 -C /work/mydroid NDK 패스 설정 # cd /root # vim. bashrc … … # NDK Path export PATH=/work/mydroid/android-ndk-r 8 b: $PATH -7 - Huins. R&D Center 7

NDK / Java Native Interface § JNI 테스트 - JNI 가 정상 설치되었는지 테스트

NDK / Java Native Interface § JNI 테스트 - JNI 가 정상 설치되었는지 테스트 § Hello JNI 디렉터리로 이동 # cd /work/mydroid/android-ndk-r 9 b/samples/hello-jni § 패키지에 포함된 경로 # cd /work/mydroid/android-ndk-r 9 b/samples/hello-jni # ls Android. Manifest. xml default. properties jni libs obj res src tests # ls. /jni Android. mk hello-jni. c # ndk-build -8 - Huins. R&D Center 8

NDK / Java Native Interface § Hello Jni 소스 분석 § Hello-jni. java native

NDK / Java Native Interface § Hello Jni 소스 분석 § Hello-jni. java native 키워드를 붙여 선언부만 작성함. public native String string. From. JNI (); 네이티브 라이브러리에 구현 부가 있음 public class Hello. Jni extends Activity { @Override public void on. Create(Bundle saved. Instance. State ){ super. on. Create(saved. Instance. State); Text. View tv = new Text. View(this); tv. set. Text( string. From. JNI() ); 네이티브 라이브러리 함수도 보통의 자 set. Content. View(tv); 바 메소드와 같은 방식으로 사용한다. } public native String string. From. JNI(); public native String unimplemented. String. From. JNI(); static { 클래스가 로딩될 때 호출됨. System. load. Library("hello-jni"); hello-jni라는 이름의 네이티브 라이브러리를 } 로딩. ‘lib’와 ‘. so’는 생략한다. } § hello-jni. c jstring Java_com_example_hellojni_Hello. Jni_string. From. JNI( JNIEnv* env, jobject thiz ) { return (*env)->New. String. UTF(env, "Hello from JNI !"); } 리턴 타입 접두사 패키지 - 10 - 클래스 Huins. R&D Center 함수 공통 파라메타 10

NDK / Java Native Interface § Android. mk - GNU Makefile의 일부 - Static

NDK / Java Native Interface § Android. mk - GNU Makefile의 일부 - Static library와 Shared library를 생성 - Static library는 Shared library를 생성하기 위해 사용 LOCAL_PATH 는 현재 파일의 경로를 주기 위해 사 용 ‘my-dir’은 현재 디렉터리 경로를 반환 빌드 시스템에서 제공하는 LOCAL_PATH를 제외하 고 LOCAL_XXX를 Clear함(undefine) LOCAL_PATH : = $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE : = hello-jni LOCAL_SRC_FILES : = hello-jni. c LOCAL_LDLIBS : = -L$(SYSROOT)/usr/lib -llog include $(BUILD_SHARED_LIBRARY) Shard library를 생성 LOCAL_XXX 변수에서 제공하는 정보를 수집하고 목 록의 소스로 부터 shared library를 빌드하는 방법을 결정 모듈의 이름의 정의. 유일하고 중간에 공백이 있어서 는 안된다. 모듈로 빌드될 C와 C++ 소스파일의 목록 추가적인 linker flag의 목록 include $(BUILD_SHARED_LIBRARY) lib$(LOCAL_MODULES). so include $(BUILD_STATIC_LIBRARY) lib$(LOCAL_MODULE). a - 11 - Huins. R&D Center 11

NDK / Java Native Interface § Shared library의 명명 규칙 1. ‘lib’prefix<name>’. so’suffix의 형식

NDK / Java Native Interface § Shared library의 명명 규칙 1. ‘lib’prefix<name>’. so’suffix의 형식 2. <name>이 ‘hello-jni’라면, 최종 파일은 ‘libhello-jni. so’ § 생성된 라이브러리 위치 Shared library는 프로젝트의 적절한 경로에 복사되고, 최종 ‘. apk’파일에 포함 최종 파일은 projectlibsarmeabi 의 경로에 libhello-jni. so파일로 생성 - 12 - Huins. R&D Center 12

NDK / Java Native Interface § 디바이스 드라이버와 어플리케이션간의 통신 - 15 - Huins.

NDK / Java Native Interface § 디바이스 드라이버와 어플리케이션간의 통신 - 15 - Huins. R&D Center 15

NDK / Java Native Interface § 커널 모듈 § § 모듈은 리눅스 시스템이 부팅된

NDK / Java Native Interface § 커널 모듈 § § 모듈은 리눅스 시스템이 부팅된 후 동적으로 load, unload 할 수 있는 커널의 구성 요소 시스템을 재부팅 하지 않고, 일부를 교체할 수 있다 리눅스를 구성하는 많은 모듈들은 의존성이 있을 수 있다. 커널을 등록시킬 때에는 insmod 명령을 이용하고 내릴 때는 rmmod 명령을 이용한다. /* This program is modue example AUTH : Huins, Inc MENT : Test Only */ #include <linux/kernel. h> #include <linux/module. h> #include <linux/init. h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("Huins"); static int module_begin(void) { printk(KERN_ALERT "Hello module, Achro 4210!!n"); return 0; } static void module_end(void) { printk(KERN_ALERT "Goodbye module, Achro 4210!!n"); } module_init(module_begin); module_exit(module_end); - 16 - Huins. R&D Center 16

NDK / Java Native Interface § LED 드라이버 § 회로 Exynos 4210 CPU -

NDK / Java Native Interface § LED 드라이버 § 회로 Exynos 4210 CPU - 17 - Huins. R&D Center 17

NDK / Java Native Interface § LED 드라이버 § § 회로 설명 - CPU의

NDK / Java Native Interface § LED 드라이버 § § 회로 설명 - CPU의 GPIO핀과 LED가 연결되어있음 - LED에는 VDD를 통해 전원이 공급되고 있음 - CPU의 핀이 LOW(0)가 되면 LED가 점등. 연번 순서 PIN NAME CPU/IO 1 LED 0 SPI_1. MOSI GPB 7 2 LED 1 SPI_1. MISO GPB 6 3 LED 2 SPI_1. NSS GPB 5 4 LED 3 SPI_1. CLK GPB 4 LED Driver Souce /* LED Ioremap Control FILE : led_driver. c */ // 헤더 선언부 #define LED_MAJOR 240 // 디바이스 드라이버의 주번호 #define LED_MINOR 0 // 디바이스 드라이버의 부번호 #define LED_NAME "led_driver" // 디바이스 드라이버의 이름 #define LED_GPBCON 0 x 11400040 // GPBCON 레지스터의 물리주소 #define LED_GPBDAT 0 x 11400044 // GPBDAT 레지스터의 물리주소 int led_open(struct inode *, struct file *); int led_release(struct inode *, struct file *); ssize_t led_write(struct file *, const char *, size_t, loff_t *); - 18 - Huins. R&D Center 18

NDK / Java Native Interface § LED Driver Souce if(result <0) { printk(KERN_WARNING"Can't get

NDK / Java Native Interface § LED Driver Souce if(result <0) { printk(KERN_WARNING"Can't get any major!n"); return result; } led_data = ioremap(LED_GPBDAT, 0 x 01); if(led_data==NULL) { printk("ioremap failed!n"); return -1; } led_ctrl = ioremap(LED_GPBCON, 0 x 04); if(led_ctrl==NULL) { printk("ioremap failed!n"); return -1; } else { get_ctrl_io=inl((unsigned int)led_ctrl); get_ctrl_io|=(0 x 11110000); outl(get_ctrl_io, (unsigned int)led_ctrl); } outb(0 x. F 0, (unsigned int)led_data); return 0; } static int led_usage = 0; static unsigned char *led_data; static unsigned int *led_ctrl; static struct file_operations led_fops = {. open = led_open, . write = led_write, . release = led_release, }; int led_open(struct inode *minode, struct file *mfile) { if(led_usage != 0) return -EBUSY; led_usage = 1; return 0; } int led_release(struct inode *minode, struct file *mfile) { led_usage = 0; return 0; } ssize_t led_write(struct file *inode, const char *gdata, size_t length, loff_t *off_what) { const char *tmp = gdata; unsigned short led_buff=0; outb (led_buff, (unsigned int)led_data); return length; } void __exit led_exit(void) { outb(0 x. F 0, (unsigned int)led_data); iounmap(led_ctrl); unregister_chrdev(LED_MAJOR, LED_NAME); } int __init led_init(void) { int result; unsigned int get_ctrl_io=0; result = register_chrdev(LED_MAJOR, LED_NAME, &led_fops); module_init(led_init); module_exit(led_exit); MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("Huins HSH"); - 19 - Huins. R&D Center 19

Internal Device Driver § Led Driver § File Operation struct static struct file_operations led_fops

Internal Device Driver § Led Driver § File Operation struct static struct file_operations led_fops = {. open. write. release = led_open, = led_write, = led_release, }; § led_open() int led_open(struct inode *minode, struct file *mfile) { if(led_usage != 0) return -EBUSY; led_usage = 1; return 0; } § led_release() int led_release(struct inode *minode, struct file *mfile) { led_usage = 0; return 0; } - 20 - Huins. R&D Center 20

Internal Device Driver § led_write() ssize_t led_write(struct file *inode, const char *gdata, size_t length,

Internal Device Driver § led_write() ssize_t led_write(struct file *inode, const char *gdata, size_t length, loff_t *off_what) { const char *tmp = gdata; unsigned short led_buff=0; if (copy_from_user(&led_buff, tmp, length)) return -EFAULT; outb (led_buff, (unsigned int)led_data); return length; } § led_release() void __exit led_exit(void) { outb(0 x. F 0, (unsigned int)led_data); iounmap(led_ctrl); unregister_chrdev(LED_MAJOR, LED_NAME); printk("Removed LED modulen"); } - 21 - Huins. R&D Center 21

Internal Device Driver § led_init() int __init led_init(void) { int result; unsigned int get_ctrl_io=0;

Internal Device Driver § led_init() int __init led_init(void) { int result; unsigned int get_ctrl_io=0; result = register_chrdev(LED_MAJOR, LED_NAME, &led_fops); if(result <0) { printk(KERN_WARNING"Can't get any major!n"); return result; } led_data = ioremap(LED_GPBDAT, 0 x 01); if(led_data==NULL) [ // 오류 처리 } led_ctrl = ioremap(LED_GPBCON, 0 x 04); if(led_ctrl==NULL) { // 오류 처리 } else { get_ctrl_io=inl((unsigned int)led_ctrl); get_ctrl_io|=(0 x 11110000); outl(get_ctrl_io, (unsigned int)led_ctrl); } printk("init module, /dev/led_driver major : %dn", LED_MAJOR); outb(0 x. F 0, (unsigned int)led_data); return 0; } - 22 - Huins. R&D Center 22

Internal Device Driver § Test Application /* … (생략) … int main(int argc, char

Internal Device Driver § Test Application /* … (생략) … int main(int argc, char **argv) { unsigned char val[] = {0 x 70, 0 x. B 0, 0 x. D 0, 0 x. E 0, 0 x 00, 0 x. F 0}; if(argc != 2) { // 실행 어규먼트를 받았는지 체크 및 오류처리 led_fd = open("/dev/led_device", O_RDWR); } // 디바이스를 오픈. if (led_fd<0) { // 만약 디바이스가 정상적으로 오픈되지 않으면 오류 처리후 종료 } get_number=atoi(argv[1]); // 받은 인자를 숫자로 바꾼다. if(get_number>0||get_number<9) // 숫자가 0~9 까지에 포함되는지 확인. write(led_fd, &val[get_number], sizeof(unsigned char)); else printf("Invalid Value : 0 thru 9"); // 포함되지 않으면, 메시지를 출력. close(led_fd); // 장치를 닫아줌. return 0; // 프로그램을 종료. } - 23 - Huins. R&D Center 23

NDK / Java Native Interface § LED Driver 컴파일 스크립트 (Makefile) # vim Makefile

NDK / Java Native Interface § LED Driver 컴파일 스크립트 (Makefile) # vim Makefile # This is simple Makefile obj-m : = led_driver. o # led_driver. c를 컴파일하여 led_driver. ko파일을 만든다. CC : = arm-linux-gcc # 어플리케이션 컴파일 시 사용할 컴파일러 KDIR : = /work/achro 4210/kernel # 커널 소스가 풀려있는 디렉터리 PWD : = $(shell pwd) # 현재 디렉터리 환경 변수를 가져옴 FILE : = test_led # 응용 프로그램 파일이름 all: driver # make만 입력했을 때 실행되는 전체 부분 driver : # make driver를 입력했을 때 실행되는 부분 $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules install : # make install을 입력했을 때 실행되는 부분 cp -a led_driver. ko /nfsroot clean: # make clean을 입력했을 때 실행되는 부분 rm -rf *. ko rm -rf *. mod. * rm -rf *. o rm -rf $(FILE) rm -rf modules. order rm -rf Module. symvers - 24 - Huins. R&D Center 24

NDK / Java Native Interface § LED Driver 컴파일 - 컴파일이 완료되면 led_driver. ko

NDK / Java Native Interface § LED Driver 컴파일 - 컴파일이 완료되면 led_driver. ko 파일이 생성된다. # make § Led_driver. ko 파일을 보드로 전송 # adb push led_driver. ko / § 안드로이드에서 led를 제어할 수 있도록 장치 노드를 생성 - adb를 이용하여 shell을 사용한다. # adb shell <-- PC 명령창(Target Board 명령창을 연다) # mknod /dev/gpio c 246 0 <-- Target Board 명령창 # insmod /led_driver. ko <--- Target Board 명령창 # exit <--- Target Board 명령창(Target Board의 명령창을 빠져나간다. ) - 25 - Huins. R&D Center 25

NDK / Java Native Interface § Led. JNI Example § Project 생성 - 27

NDK / Java Native Interface § Led. JNI Example § Project 생성 - 27 - Huins. R&D Center 27

NDK / Java Native Interface § UI 작성 (main. xml) <? xml version="1. 0"

NDK / Java Native Interface § UI 작성 (main. xml) <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android= "http: //schemas. android. com/apk/res/android" android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent" > <Radio. Button android: text="4" android: id="@+id/RB 04" android: layout_width="wrap_content" android: layout_height="wrap_content"> </Radio. Button> <Text. View android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello"/> <Radio. Button android: text="5" android: id="@+id/RB 05" android: layout_width="wrap_content" android: layout_height="wrap_content"> </Radio. Button> <Radio. Group android: id="@+id/Radio. Group 01" android: layout_width="wrap_content" android: layout_height="wrap_content" android: orientation="horizontal"> <Radio. Button android: text="6" android: id="@+id/RB 06" android: layout_width="wrap_content android: layout_height="wrap_content"> </Radio. Button> <Radio. Button android: text="1" android: id="@+id/RB 01" android: layout_width="wrap_content" android: layout_height="wrap_content"></Radio. Button> <Radio. Button android: text="7" android: id="@+id/RB 07" android: layout_width="wrap_content" android: layout_height="wrap_content"> </Radio. Button> <Radio. Button android: text="2" android: id="@+id/RB 02" android: layout_width="wrap_content" android: layout_height="wrap_content"> </Radio. Button> <Radio. Button android: text="3" android: id="@+id/RB 03" android: layout_width="wrap_content" android: layout_height="wrap_content"> </Radio. Button> <Radio. Button android: text="8" android: id="@+id/RB 08" android: layout_width="wrap_content" android: layout_height="wrap_content"> </Radio. Button> </Radio. Group> - 28 - Huins. R&D Center 28

NDK / Java Native Interface § 제어 소스 (Led. Jni. Example. Activity. java. xml)

NDK / Java Native Interface § 제어 소스 (Led. Jni. Example. Activity. java. xml) package achro 4. huins. ex 1; import android. app. Activity; import android. os. Bundle; import android. widget. Radio. Group; public class Led. Jni. Example. Activity extends Activity implements Radio. Group. On. Checked. Change. Listener { Radio. Group m. Radio. Group; @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); Receive. Led. Value(2); // LED 3 break ; case R. id. RB 04 : Receive. Led. Value(3); // LED 4 break ; case R. id. RB 05 : Receive. Led. Value(4); // ALL ON break ; case R. id. RB 06 : Receive. Led. Value(5); // ALL OFF break ; } } m. Radio. Group = (Radio. Group)find. View. By. Id(R. id. Radio. Group 01); m. Radio. Group. set. On. Checked. Change. Listener(this); public native String Recieve. Led. Value(int x); } @Override public void on. Checked. Changed(Radio. Group group, int checked. Id) { switch(checked. Id) { case R. id. RB 01 : Receive. Led. Value(0); // LED 1 break ; case R. id. RB 02 : Receive. Led. Value(1); // LED 2 break ; case R. id. RB 03 : static { System. load. Library("led-jni"); } } - 29 - Huins. R&D Center 29

NDK / Java Native Interface § JNI 컴파일 스크립트 및 JNI 코드 작성 (Led.

NDK / Java Native Interface § JNI 컴파일 스크립트 및 JNI 코드 작성 (Led. Jni. Example. Activity. java. xml) LOCAL_PATH : = $(call my-dir) #include <string. h> #include <jni. h> #include <android/log. h> #include <fcntl. h> include $(CLEAR_VARS) LOCAL_MODULE : = led-JNI LOCAL_SRC_FILES : = led-JNI. c LOCAL_LDLIBS : = -L$(SYSROOT)/usr/lib -llog void led_main (int x) { int fd = -1; unsigned char val[ ] = {0 x 70, 0 x. B 0, 0 x. D 0, 0 x. E 0, 0 x 00, 0 x. F 0}; include $(BUILD_SHARED_LIBRARY) fd = open("/dev/led_driver", O_RDWR); if (fd < 0) { __android_log_print(ANDROID_LOG_INFO, "Device Open Error", "Driver = %d", x); } else { __android_log_print(ANDROID_LOG_INFO, "Device Open Success", "Driver = %d", x); write (fd, &val[x], sizeof(unsigned char)); } close(fd); jstring Java_com_huins_led. JNI_Led. JNI_Recieve. Led. Value( JNIEnv* env, jobject thiz, jint val) <1> <2> <3> <4> <5> <6> < 7> <1> jstring : 리턴 타입으로서 자바 언어의 String에 해당한다. ex) jbyte -> byte, jshort -> short, jint -> int, void -> void, jobject -> 자바객체 등 <2> Java : 접두사 <3> com_huins_led. JNI : 패키지명 <4> Led. JNI : 클래스명 <5> Recieve. Led. Value : 함수명 } <6> JNIEnv *, Jobject thiz : 공통 파라메타 <7> jint val : 함수에 전달할 파라메타 jstring Java_achro 4_huins_ex 1_Led. Jni. Example. Activity_Receive. Led. Val ue( JNIEnv* env, jobject thiz, jint val ) { __android_log_print(ANDROID_LOG_INFO, "Led. Jni. Example", "led value = %d", val); led_main(val); } - 30 - Huins. R&D Center 30

NDK / Java Native Interface § 작성된 JNI 소스 컴파일 - 작성된 jni 소스가

NDK / Java Native Interface § 작성된 JNI 소스 컴파일 - 작성된 jni 소스가 있는 디렉터리로 이동하여 컴파일 # ndk-build § 생성된 라이브러리 확인 # ls. . /libs/armeabi § 경과 확인 # adb shell # insmod led_driver. ko # mknod /dev/led_driver c 240 0 - 31 - Huins. R&D Center 31

NDK / Java Native Interface § 프로그램 실행 - 메뉴 > RUN 을 선택하여

NDK / Java Native Interface § 프로그램 실행 - 메뉴 > RUN 을 선택하여 Achro-4210에 전송하고 실행 # ndk-build - 32 - Huins. R&D Center 32

Internal Device Control Application § 안드로이드와 리눅스에서 디바이스를 제어하기 위한 전체 경로 - 33

Internal Device Control Application § 안드로이드와 리눅스에서 디바이스를 제어하기 위한 전체 경로 - 33 - Huins. R&D Center

NDK / Java Native Interface § 7 -Segment Driver § LED 회로 분석 LED

NDK / Java Native Interface § 7 -Segment Driver § LED 회로 분석 LED 회로 구성 핀 연결 CPU I/O - 34 - Huins. R&D Center 34

NDK / Java Native Interface § 회로 정리 § § § 7 Segment(이하 FND)를

NDK / Java Native Interface § 회로 정리 § § § 7 Segment(이하 FND)를 제어하기 위해서는 CPU의 GPIO를 이용하여 제어 FND에 공급되는 전원은 ANODE FND_A ~ FND_DP의 핀이 0(Low)이 되어야 FND의 각 요소가 점등 FND Digit 선택 연번 순서 PIN NAME CPU/IO 계산값 1 FND 1 LCD_B_VD 15 GPE 3_1 0 x 02 2 FND 2 LCD_B_VD 16 GPE 3_2 0 x 04 3 FND 3 LCD_B_VD 18 GPE 3_4 0 x 10 4 FND 4 LCD_B_VD 21 GPE 3_7 0 x 80 연번 순서 PIN NAME CPU/IO 1 FND A GPS_GPIO_7 GPL 2_7 2 FND B GPS_GPIO_6 GPL 2_6 3 FND C GPS_GPIO_5 GPL 2_5 4 FND D GPS_GPIO_4 GPL 2_4 5 FND E GPS_GPIO_3 GPL 2_3 6 FND F GPS_GPIO_2 GPL 2_2 7 FND G GPS_GPIO_1 GPL 2_1 8 FND DP GPS_GPIO_0 GPL 2_0 각 FND의 구성 핀 - 35 - Huins. R&D Center 35

NDK / Java Native Interface § FND 점등 위치 § 숫자테이블 FND 숫자 레지스터

NDK / Java Native Interface § FND 점등 위치 § 숫자테이블 FND 숫자 레지스터 값 점등 위치 계산값 A B C D E F G P 0 ABCDEF 0 0 0 1 1 0 x 02 1 BC 1 0 0 1 1 1 0 x 9 F 2 ABDGE 0 0 1 0 1 0 x 25 3 ABCDG 0 0 1 1 0 x 0 D 4 BCFG 1 0 0 1 0 x 99 5 ACDFG 0 1 0 x 49 6 CDEFG 1 1 0 0 0 1 0 x. C 1 7 ABC 0 0 0 1 1 1 0 x 1 F 8 ABCDEFG 0 0 0 0 1 0 x 01 9 ABCDFG 0 0 1 0 x 09 P 1 1 1 1 0 0 x. FE 1 1 1 1 0 x. FF DP BLANK - 36 - Huins. R&D Center 36

Internal Device Driver § FND Driver § fnd_driver. c § 장치관련 선언부 및 사용할

Internal Device Driver § FND Driver § fnd_driver. c § 장치관련 선언부 및 사용할 레지스터 주소 설정 // … 생략) … #include <linux/module. h> #include <linux/fs. h> #include <linux/init. h> #include <linux/version. h> #define FND_MAJOR 241 // fnd device minor number #define FND_MINOR 0 // fnd device minor number #define FND_NAME "fnd_device" // fnd device name #define FND_GPL 2 CON 0 x 11000100 // Pin Configuration #define FND_GPL 2 DAT 0 x 11000104 // Pin Data § File Operation Structure static struct. open. write. release }; file_operations fnd_fops = { = fnd_open, = fnd_write, = fnd_release, - 37 - Huins. R&D Center 37

NDK / Java Native Interface § fnd_open() int fnd_open(struct inode *minode, struct file *mfile)

NDK / Java Native Interface § fnd_open() int fnd_open(struct inode *minode, struct file *mfile) { if(fnd_usage != 0) return -EBUSY; fnd_usage = 1; return 0; } § fnd_release() int fnd_release(struct inode *minode, struct file *mfile) { fnd_usage = 0; return 0; } - 38 - Huins. R&D Center 38

NDK / Java Native Interface § fnd_write() ssize_t fnd_write(struct file *inode, const short *gdata,

NDK / Java Native Interface § fnd_write() ssize_t fnd_write(struct file *inode, const short *gdata, size_t length, loff_t *off_what) { //. . . 생략 if (copy_from_user(&fnd_buff, tmp, length)) return -EFAULT; printk("DATA : %dn", fnd_buff); outw (fnd_buff, (unsigned int)fnd_data); return length; } - 39 - Huins. R&D Center 39

NDK / Java Native Interface § fnd_init(void) int __init fnd_init(void) { int result; result

NDK / Java Native Interface § fnd_init(void) int __init fnd_init(void) { int result; result = register_chrdev(FND_MAJOR, FND_NAME, &fnd_fops); if(result <0) { //. . . (오류처리). . . } fnd_data = ioremap(FND_GPL 2 DAT, 0 x 01); if(fnd_data==NULL) { //. . . (오류처리). . . } fnd_ctrl = ioremap(FND_GPL 2 CON, 0 x 04); fnd_ctrl 2 = ioremap(FND_GPE 3 CON, 0 x 04); if(fnd_ctrl==NULL) { //. . . (오류처리). . . } else { outl(0 x 1111, (unsigned int)fnd_ctrl); outl(0 x 10010110, (unsigned int)fnd_ctrl 2); } printk("init module, /dev/fnd_driver major : %dn", FND_MAJOR); outb(0 x. FF, (unsigned int)fnd_data); return 0; } - 40 - Huins. R&D Center 40

NDK / Java Native Interface § 모듈 관련 등록 수행 함수 및 라이선스 지정

NDK / Java Native Interface § 모듈 관련 등록 수행 함수 및 라이선스 지정 module_init(fnd_init); module_exit(fnd_exit); MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("Huins HSH"); - 41 - Huins. R&D Center 41

NDK / Java Native Interface // … 생략 … #define FND 0 0 x

NDK / Java Native Interface // … 생략 … #define FND 0 0 x 00 #define FND 1 0 x 01 // … 생략 … #define FND 8 0 x 08 #define FND 9 0 x 09 #define FNDP 0 x 0 A // DP #define FNDA 0 x 0 B // ALL #define FNDX 0 x 0 C // ALL OFF int main(int argc, char **argv) { int fnd_fd; // …생략… if(argc != 3) { // 장치를 열수 없을 때 오류처리 } fnd_fd = open("/dev/fnd_device", O_WRONLY); if (fnd_fd<0) { // 장치를 열수 없는 경우 } get_fndnumber=(char)atoi(argv[1]); switch(get_fndnumber) { case 0 : set_fndvalue = 0 x 96; break; // … 생략 … case 4 : set_fndvalue = 0 x 80; break; } - 42 - Huins. R&D Center 42