硬件平臺: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控件
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦
- 迅為IMX6ULL開發(fā)板交叉編譯器的安裝和使用
- 迅為-i.MX6ULL 開發(fā)板-移植OpenCv3.4.1-搭建編譯環(huán)境
- 嵌入式學(xué)習(xí)篇丨迅為4412開發(fā)板Android4.4系統(tǒng)編譯
- Linux系統(tǒng)編程篇丨迅為IMX6ULL-對應(yīng)視頻講解
- 嵌入式學(xué)習(xí)丨4412開發(fā)板-uboot源碼-匯編-源碼分析(一)嵌入式學(xué)習(xí)丨4412開發(fā)板-uboot源碼-匯
- 迅為IMX6ULL開發(fā)板-主頻和時鐘配置例程(二)
- 迅為IMX6ULL開發(fā)板-主頻和時鐘配置例程
- 迅為IMX6ULL開發(fā)板安裝VMware Tool工具
- i.MX6ULL終結(jié)者Debian文件系統(tǒng)的構(gòu)建i.MX6ULL 移植Debian文件系統(tǒng)
- 適用于 R41Z-TA-R R41Z 模塊螺紋 + 藍牙 4.2 LE 的 DC-DC 升壓模式應(yīng)用
- QorIQ LX2160A開發(fā)板
- THEVAL3502,基于 THL3502 24 通道 LED 驅(qū)動器的評估板,帶有 LVDS 接口
- 用于 DDR 電源的 LTC3634MPUFD 雙路 3A 單片式降壓穩(wěn)壓器的典型應(yīng)用電路
- TWR-KW21D256、TWR-KW2x 開發(fā)平臺連接測試應(yīng)用演示,使用 MKW21D256V Kinetis KW20 MCU
- STEVAL-ISA084V1,使用 ST1S40、4 A 峰值、800 kHz 固定頻率 PWM 同步降壓轉(zhuǎn)換器的演示板
- LTC3835EGN-1 高效 5V、5A 降壓轉(zhuǎn)換器的典型應(yīng)用電路
- LTC3226EUD 鋰離子備用電源的典型應(yīng)用電路
- 使用 Microchip Technology 的 U690B 的參考設(shè)計
- NCV33074DR2G快速建立逆變器的典型應(yīng)用
- 中國發(fā)布HDMI和DisplayPort替代方案:GPMI接口來了
- 三星進軍 AI 機器人領(lǐng)域,Ballie 本周公開亮相
- 消息稱美光即日起針對存儲模組產(chǎn)品向美國客戶征收“關(guān)稅附加費”
- 迅為IMX6ULL開發(fā)板交叉編譯器的安裝和使用
- 迅為-i.MX6ULL 開發(fā)板-移植OpenCv3.4.1-搭建編譯環(huán)境
- BOE(京東方)董事長提議回購公司股份 堅定看好資本市場長期價值
- 英飛凌宣布收購Marvell的汽車以太網(wǎng)業(yè)務(wù)
- 強強聯(lián)合!兆易創(chuàng)新與納微半導(dǎo)體達成戰(zhàn)略合作
- 德州儀器模擬設(shè)計 | 運算放大器基本穩(wěn)定性概述
- 人形機器人新王者崛起:Figure估值直逼2900億,中國軍團能否迎頭趕上?
- STM32F103_TIM3輸出PWM波實現(xiàn)全彩呼吸燈
- 三星:7nm LPP天下無敵 臺積電:試產(chǎn)了5nm
- STM32實戰(zhàn) 2.矩陣鍵盤通過串口3輸出
- stm32中pwm頻率和占空比設(shè)置
- 浩亭聯(lián)手TE Connectivity推動確立SPE基礎(chǔ)設(shè)施解決方案
- 國網(wǎng)公司召開源網(wǎng)荷儲多元協(xié)調(diào)泛在調(diào)度控制現(xiàn)場推進會
- 華中電網(wǎng)實現(xiàn)儲能電站省間資源配置
- 全國產(chǎn)化干式套管在宜賓換流站掛網(wǎng)試運行
- 國網(wǎng)河北電力電動汽車充電量同比翻一番
- 國網(wǎng)湖南信通公司率先取得泛在電力物聯(lián)網(wǎng)省級重點實驗室認證