PC蜂鸣器音乐
有了“使用procfs”、“I/O映射之I/O端口”、“内核读写磁盘文件”这三篇文章的基础后,我们将其结合,实现如下功能的实例: 1.打开传入的音乐谱文件(通过procfs接口); 2.读取音乐谱文件(以“频率”、“延时”、“频率”、“延时”、……这样的格式保存); 3.解析读取的文件; 4.将解析的数据传送去操作8254,让PC蜂鸣器弹奏文件对应的音乐。 好了,基础的内容看开头提及的文章,接下来上代码: #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/proc_fs.h> #include <asm/uaccess.h> #include <linux/timex.h> #ifndef MAX_PATH #define MAX_PATH 256 #endif #define PACKAGE_SIZE 512 extern void msleep(unsigned int msecs); struct proc_dir_entry * slam_dir = NULL; struct proc_dir_entry * slam_entry = NULL; static char * dir_name = "slam_song"; static char * entry_name = "path"; static void beep(unsigned int freq, unsigned int delay) { unsigned int count; if (freq) count = PIT_TICK_RATE / freq; else count = 20; outb_p(0xB6, 0x43); outb_p(count & 0xff, 0x42); outb((count >> 8) & 0xff, 0x42); ...