娇小w搡bbbb搡bbb,《第一次の人妻》,中国成熟妇女毛茸茸,边啃奶头边躁狠狠躁视频免费观看

Android JNI用于驅(qū)動測試

發(fā)布者:清晨微風(fēng)最新更新時間:2024-11-07 來源: cnblogs關(guān)鍵字:Android  JNI  S3C6410 手機看文章 掃描二維碼
隨時隨地手機看文章

硬件平臺:S3C6410


操作系統(tǒng):Ubuntu、windows


板子系統(tǒng):Android


開發(fā)工具:jdk。ndk,eclipse


本次測試從linux內(nèi)核模塊編譯開始。以S3C6410的pwm驅(qū)動為例。


pwm_6410.c:


#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include


#define DEVICE_NAME  'pwm'


static struct semaphore lock;


static void PWM_Set_Freq( unsigned long freq )

{

unsigned long tcon;

unsigned long tcnt;

unsigned long tcfg1;

unsigned long tcfg0;

unsigned long pclk;

unsigned tmp;

struct clk *clk_p;


    printk ('Freq is %d',freq);

tmp = readl(S3C64XX_GPFCON);//PWM GPF15

    tmp &= ~(0x3U << 30);// Timer1

    tmp |=  (0x2U << 30);

writel(tmp, S3C64XX_GPFCON);

tcon  = __raw_readl(S3C_TCON);

tcfg1 = __raw_readl(S3C_TCFG1);

tcfg0 = __raw_readl(S3C_TCFG0);

tcfg0 &= ~S3C_TCFG_PRESCALER0_MASK;

tcfg0 |= (50 - 1); 

    tcfg1 &= ~S3C_TCFG1_MUX1_MASK;

    tcfg1 |= S3C_TCFG1_MUX1_DIV16;

__raw_writel(tcfg1, S3C_TCFG1);

__raw_writel(tcfg0, S3C_TCFG0);

clk_p = clk_get(NULL, 'pclk');

pclk  = clk_get_rate(clk_p);

tcnt  = (pclk/50/16)/freq;

__raw_writel(tcnt, S3C_TCNTB(1));

__raw_writel(tcnt/2, S3C_TCMPB(1));

tcon &= ~(0xf << 8);

tcon |= (0xb << 8);

__raw_writel(tcon, S3C_TCON);

tcon &= ~(2 << 8);

__raw_writel(tcon, S3C_TCON);

}


void PWM_Stop( void )

{

unsigned tmp;

tmp = readl(S3C64XX_GPFCON);

tmp &= ~(0x3U << 30);// set GPF15

writel(tmp, S3C64XX_GPFCON);

}


static int s3c64xx_pwm_open(struct inode *inode, struct file *file)

{

if (!down_trylock(&lock))

return 0;

else

return -EBUSY;

}


static int s3c64xx_pwm_close(struct inode *inode, struct file *file)

{

up(&lock);

return 0;

}


static long s3c64xx_pwm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)

{

switch (cmd) 

{

case 1:

if (arg == 0)

return -EINVAL;

PWM_Set_Freq(arg);

break;


case 0:

PWM_Stop();

break;

}

return 0;

}



static struct file_operations dev_fops = {

    .owner = THIS_MODULE,

    .open = s3c64xx_pwm_open,

    .release = s3c64xx_pwm_close, 

    .unlocked_ioctl = s3c64xx_pwm_ioctl,

};


static struct miscdevice misc = {

    .minor = MISC_DYNAMIC_MINOR,

    .name  = DEVICE_NAME,

    .fops  = &dev_fops,

};


static int __init dev_init(void)

{

int ret;

init_MUTEX(&lock);

ret = misc_register(&misc);

printk (DEVICE_NAME'tinitializedn');

    return ret;

}


static void __exit dev_exit(void)

{

misc_deregister(&misc);

}


MODULE_LICENSE('GPL');

module_init(dev_init);

module_exit(dev_exit);

Makefile加入:

obj-$(CONFIG_PWM_S3C6410)        += pwm_6410.o

Kconfig加入:

config PWM_S3C6410

tristate 'pwm'

depends on CPU_S3C6410

make menuconfig配置內(nèi)核后編譯內(nèi)核


make zImage后啟動Android系統(tǒng)

ls /dev會看到名稱為pwm的設(shè)備驅(qū)動


驅(qū)動已經(jīng)載入好。這時候就要編寫Android下的測試程序。JNI是Java Native Interface的縮寫。即Java本地調(diào)用,它同意java代碼和其它語言寫的代碼進行交互。寫測試程序時使用JNI方式實現(xiàn)。


eclipse建立一個新的應(yīng)用project。取名為pwm,包名為com.example.pwm


默認生成的java代碼:PwmActivity.java


package com.example.pwm;


import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;


public class PwmActivity extends Activity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_pwm);

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.activity_pwm, menu);

return true;

}

}

加入本地方法:

package com.example.pwm;


import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;


public class PwmActivity extends Activity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_pwm);

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.activity_pwm, menu);

return true;

}

       public static native int pwm_set_freq(int i, int j);

static {  

System.loadLibrary('pwm');  // 加入 C/C++動態(tài)庫導(dǎo)入方法  

}

}

編輯res/layout下activity_pwm.xml


加入button控件


            android:id='@+id/pwm_on'

        android:layout_width='wrap_content'

        android:layout_height='wrap_content'

        android:layout_above='@+id/textView1'

        android:layout_alignLeft='@+id/textView1'

        android:layout_marginBottom='39dp'

        android:onClick='onPwmOnClicked'

        android:text='@string/pwm' />

編輯res/values下strings.xml

加入


pwm

PwmActivity.java中加入:

    public void onPwmOnClicked(View v){

    pwm_set_freq(1,200);

    }

PwmActivity.java:

package com.example.pwm;


import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;


public class PwmActivity extends Activity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_pwm);

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.activity_pwm, menu);

return true;

}

        public void onPwmOnClicked(View v){

            pwm_set_freq(1,200); //按下按鍵就輸出波形

        }

public static native int pwm_set_freq(int i, int j);

static {  

System.loadLibrary('pwm');  // 加入 C/C++動態(tài)庫導(dǎo)入方法  ,這個庫須要使用NDK工具編譯生成。


}  

}


上述步驟就緒后,編譯project,再將該project復(fù)制到Ubuntu下

project文件夾下創(chuàng)建jni文件夾:

使用javah命令生成jni頭文件

注意冒號后沒有空格


生成的頭文件:

com_example_pwm_PwmActivity.h:


/* DO NOT EDIT THIS FILE - it is machine generated */

#include

/* Header for class com_example_pwm_PwmActivity */


#ifndef _Included_com_example_pwm_PwmActivity

#define _Included_com_example_pwm_PwmActivity

#ifdef __cplusplus

extern 'C' {

#endif

#undef com_example_pwm_PwmActivity_MODE_PRIVATE

#define com_example_pwm_PwmActivity_MODE_PRIVATE 0L

#undef com_example_pwm_PwmActivity_MODE_WORLD_READABLE

#define com_example_pwm_PwmActivity_MODE_WORLD_READABLE 1L

#undef com_example_pwm_PwmActivity_MODE_WORLD_WRITEABLE

#define com_example_pwm_PwmActivity_MODE_WORLD_WRITEABLE 2L

#undef com_example_pwm_PwmActivity_MODE_APPEND

#define com_example_pwm_PwmActivity_MODE_APPEND 32768L

#undef com_example_pwm_PwmActivity_MODE_MULTI_PROCESS

#define com_example_pwm_PwmActivity_MODE_MULTI_PROCESS 4L

#undef com_example_pwm_PwmActivity_MODE_ENABLE_WRITE_AHEAD_LOGGING

#define com_example_pwm_PwmActivity_MODE_ENABLE_WRITE_AHEAD_LOGGING 8L

#undef com_example_pwm_PwmActivity_BIND_AUTO_CREATE

#define com_example_pwm_PwmActivity_BIND_AUTO_CREATE 1L

#undef com_example_pwm_PwmActivity_BIND_DEBUG_UNBIND

#define com_example_pwm_PwmActivity_BIND_DEBUG_UNBIND 2L

#undef com_example_pwm_PwmActivity_BIND_NOT_FOREGROUND

#define com_example_pwm_PwmActivity_BIND_NOT_FOREGROUND 4L

#undef com_example_pwm_PwmActivity_BIND_ABOVE_CLIENT

#define com_example_pwm_PwmActivity_BIND_ABOVE_CLIENT 8L

#undef com_example_pwm_PwmActivity_BIND_ALLOW_OOM_MANAGEMENT

#define com_example_pwm_PwmActivity_BIND_ALLOW_OOM_MANAGEMENT 16L

#undef com_example_pwm_PwmActivity_BIND_WAIVE_PRIORITY

#define com_example_pwm_PwmActivity_BIND_WAIVE_PRIORITY 32L

#undef com_example_pwm_PwmActivity_BIND_IMPORTANT

#define com_example_pwm_PwmActivity_BIND_IMPORTANT 64L

#undef com_example_pwm_PwmActivity_BIND_ADJUST_WITH_ACTIVITY

#define com_example_pwm_PwmActivity_BIND_ADJUST_WITH_ACTIVITY 128L

#undef com_example_pwm_PwmActivity_CONTEXT_INCLUDE_CODE

#define com_example_pwm_PwmActivity_CONTEXT_INCLUDE_CODE 1L

#undef com_example_pwm_PwmActivity_CONTEXT_IGNORE_SECURITY

#define com_example_pwm_PwmActivity_CONTEXT_IGNORE_SECURITY 2L

#undef com_example_pwm_PwmActivity_CONTEXT_RESTRICTED

#define com_example_pwm_PwmActivity_CONTEXT_RESTRICTED 4L

#undef com_example_pwm_PwmActivity_RESULT_CANCELED

#define com_example_pwm_PwmActivity_RESULT_CANCELED 0L

#undef com_example_pwm_PwmActivity_RESULT_OK

#define com_example_pwm_PwmActivity_RESULT_OK -1L

#undef com_example_pwm_PwmActivity_RESULT_FIRST_USER

#define com_example_pwm_PwmActivity_RESULT_FIRST_USER 1L

#undef com_example_pwm_PwmActivity_DEFAULT_KEYS_DISABLE

#define com_example_pwm_PwmActivity_DEFAULT_KEYS_DISABLE 0L

#undef com_example_pwm_PwmActivity_DEFAULT_KEYS_DIALER

#define com_example_pwm_PwmActivity_DEFAULT_KEYS_DIALER 1L

#undef com_example_pwm_PwmActivity_DEFAULT_KEYS_SHORTCUT

#define com_example_pwm_PwmActivity_DEFAULT_KEYS_SHORTCUT 2L

#undef com_example_pwm_PwmActivity_DEFAULT_KEYS_SEARCH_LOCAL

#define com_example_pwm_PwmActivity_DEFAULT_KEYS_SEARCH_LOCAL 3L

#undef com_example_pwm_PwmActivity_DEFAULT_KEYS_SEARCH_GLOBAL

#define com_example_pwm_PwmActivity_DEFAULT_KEYS_SEARCH_GLOBAL 4L

/*

 * Class:     com_example_pwm_PwmActivity

 * Method:    pwm_set_freq

 * Signature: (II)I

 */

JNIEXPORT jint JNICALL Java_com_example_pwm_PwmActivity_pwm_1set_1freq

  (JNIEnv *, jclass, jint, jint);


#ifdef __cplusplus

}

#endif

#endif

將頭文件復(fù)制到j(luò)ni文件夾下,jni文件夾下創(chuàng)建pwm.c:


#include  

#include  

#include  

[1] [2]
關(guān)鍵字:Android  JNI  S3C6410 引用地址:Android JNI用于驅(qū)動測試

上一篇:QT在嵌入式系統(tǒng)中顯示中文的方法
下一篇:LED 將為我閃爍: 控制發(fā)光二級管

小廣播
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦

最新單片機文章

 
EEWorld訂閱號

 
EEWorld服務(wù)號

 
汽車開發(fā)圈

 
機器人開發(fā)圈

電子工程世界版權(quán)所有 京ICP證060456號 京ICP備10001474號-1 電信業(yè)務(wù)審批[2006]字第258號函 京公網(wǎng)安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
主站蜘蛛池模板: 阜城县| 宜阳县| 庆安县| 筠连县| 溆浦县| 威宁| 仪陇县| 仁布县| 桐柏县| 开远市| 如皋市| 赤峰市| 泰来县| 从化市| 潮州市| 民权县| 汉中市| 敦煌市| 弋阳县| 邯郸县| 桃源县| 泰宁县| 太仓市| 金秀| 河南省| 泸州市| 贵定县| 汾阳市| 通州市| 太湖县| 那坡县| 承德市| 兰坪| 兰州市| 衡阳市| 诸暨市| 武胜县| 奉贤区| 罗城| 桐城市| 莱芜市|