OK6410之蜂鳴器buzzer字元驅動

2021-07-22 15:33:05 字數 4151 閱讀 9013

夕陽的謝幕,隨之而出的明月,雖然剛剛回過家,但是還是想念,想念大海,想念媽媽燒的菜,也許真的是乙個人久了吧。雙休日,連個說話的人都沒有,只是自己乙個人,悶悶地看著書,寫著blog,天氣太熱,也懶得出去逛。收拾收拾心情,開始繼續ok6410吧。

昨天把led燈實現了,今天就玩個蜂鳴器吧,然後那些小的,簡單的外圍就告一段落了,接著再好好看看ldd3,linux核心等吧。打好基礎再來寫下自己之所學。

好了,開始蜂鳴器吧。還是一樣,先上驅動的**:

[html]view plain

copy

#include 

<

linux

/module.h

>

#include <

linux

/kernel.h

>

#include <

linux

/fs.h

>

#include <

linux

/init.h

>

#include <

linux

/miscdevice.h

>

#include <

linux

/delay.h

>

#include <

asm/uaccess.h

>

#include <

linux

/device.h

>

#include <

linux

/cdev.h

>

#include <

asm/irq.h

>

#include <

mach

/gpio.h

>

#include <

plat

/regs-gpio.h

>

#include <

plat

/gpio-cfg.h

>

#include <

mach

/hardware.h

>

#include <

linux

/io.h

>

#define buzzer_major 240  

int buzzer_open(struct inode *inode, struct file *filp)  

ssize_t buzzer_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)  

ssize_t buzzer_write(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)  

printk("

[math processing error]

[math processing error]

[math processing error]

[math processing error]$$$\n");  

return count;  

}  int buzzer_release(struct inode *inode, struct file *filp)  

struct file_operations my_fops

= ;  

static int buzzer_init(void)  

printk("

[math processing error]

[math processing error]$ register buzzer dev ok\n");  

return 0;  

}  static void buzzer_exit(void)  

module_license("gpl");  

module_init(buzzer_init);  

module_exit(buzzer_exit);  

和led燈一樣,蜂鳴器也是通過控制gpio口來控制的。原理圖如下:

那麼pwm_tout1對應的gpio口是那乙個呢?再看原理圖:

是gpf15,那麼就只要控制gpf15這個gpio口就好了,詳細看看他的暫存器吧

控制暫存器是31-30這兩位,因為輸出,所以設定為01就好了,具體**就是:

[html]view plain

copy

tmp= 

readl

(s3c64xx_gpfcon);  

tmp= (tmp & ~(0xc0000000) | (0x40000000)); //set the gpio output mode  

writel(tmp, s3c64xx_gpfcon);  

然後看看他的資料暫存器吧。和led一樣的。好了。

**基本和led沒啥區別。

接著就是makefile了:

[html]view plain

copy

obj-m :=

buzzer

.o  

然後建個makemod,**如下

[html]view plain

copy

make -c /home/eastmoon/work/linux2.6.28/ 

m=`pwd` modules  

然後只要source makemod就可以編譯成buzzer.ko了

好了,驅動部分搞定了,那麼接著就是要寫應用程式了

[html]view plain

copy

#include 

<

stdio.h

>

#include <

sys/types.h

>

#include <

sys/stat.h

>

#include <

fcntl.h

>

#define device "/dev/mybuzzer"  

int main(void)  

;  fd

= open

(device, o_rdwr);  

if(fd <

0)  

while(1)  

close(fd);  

return 0;  

}  

接著makefile

註冊成功。然後接著mknod裝置檔案

節點也出來了/dev/mybuzzer。就這就執行下應用程式好了

蜂鳴器也發出聲音了,ok,搞定了。這樣,ok6410,嵌入式linux也算是入了小門了。剩下的就是什麼spi啊,i2c啊,usb,那些匯流排了,有點小難度的那些。接下裡好好看看書吧還是。。。。。。

頂 0

OK6410裸機程式 hello world

上面已經解決 了幾個問題。現在我們的狀態 可以在pc ok6410 之間進行tftp傳輸,確定了一下可用的位址 空間,下面我們來說一下printf除錯 因為沒有jlink,只能用printf除錯,你也許會問,我們自己實現printf麼?答曰 不是,我們只是弄個hello world,何必那麼認真呢?...

ok6410 主機tftp 傳輸

1 開發環境 pc archlinux,minicom 或者 kermit.工具不會用的google啊,呵呵 開發板 ok6410b 256 sdram,2g nand flash 兩者之間 通訊用tftp傳輸。有人用windows下的 dnw進行傳輸,由於我沒windows,另外dnw貌似有時候有...

OK6410系列之01 模組程式設計

一 實驗環境 開發機環境 作業系統 ubuntu 9.10 交叉編譯環境 arm linux gcc 4.2.2 安裝位置 usr local arm 4.3.2 6410板子核心原始碼路徑 work linux 2.6.36.2 v1.05 目標板環境 ok6410 a linux2.6.36 二...