` RK3399开发板,搭建了最新android7.1 系统,4G DDR3内存,32G EMMC 存诸,搭配8.4寸高清IPS屏。RK3399开发板主板尺寸为:155*104mm,设计有非常丰富的接口,板载3路TTL UART,2路USB2.0接口,一路USB3.0接口,WIFI/BT二合一,HDMI OUT 、HDMI INT、Type C、4G、IR、以太网等;可扩展模块包括4G模块、Camera(1300万、500万)等应用类功能模块。
RK3399开发板为消费类电子、智能终端、MID、无线通讯、医疗设备、工业控制等行业产品的应用开发而设计,超强的视频处理能力,超高清视频输出优势,尤其适合广告机客户使用!供广大企业用户进行产品前期软硬件性能评估验证、设计参考用;也是高校、培训机构、嵌入式爱好者学习研究的最佳工具。其丰富的接口、精湛的设计,主要供广大企业用户进行产品前期软硬件性能评估验证、设计参考用;也是高校、培训机构、嵌入式爱好者学习研究首选最佳工具。
简单的字符设备驱动实验
驱动程序源代码如下:
/*CharDriver.c*/
#define _NO_VERSION
#include
#include
char kernel_version[] = UTS_RELEASE;
#define KERNEL
#include
#include
#include
#include
#include
#define SUCCESS 0
static int device_read(struct file *file, char *buf, size_t count, loff_t *f_pos);
static int device_open(struct inode *inode, struct file *file);
static void device_release(struct inode *inode, struct file *file);
struct file_operations tdd_fops = {
read: device_read, open:
device_open, release:
device_release,
};
#define DEVICE_NAME "char_dev"
static int Device_Open = 0;
unsigned int test_major = 0;
//static char Messaege[1024];
static int device_open(struct inode *inode, struct file *file){
#ifdef DEBUG
printk ("device_open(%p)
", file);
#endif
if (Device_Open)
return -EBUSY;
Device_Open++;
MOD_INC_USE_COUNT;
return SUCCESS;
}
static void device_release(struct inode *inode, struct file *fi le){
#ifdef DEBUG
printk ("device_release(%p,%p)
", inode, file);
#endif
Device_Open--;
MOD_DEC_USE_COUNT;
}
static int device_read(struct file *file, char *buf, size_t count, loff_t *f_pos){
int left;
if (verify_area(VERIFY_WRITE, buf, count) == -EFAULT)
return -EFAULT;
for (left = count; left > 0; left--){
put_user(1, buf);
buf++;
}
return count;
}
int init_module(void){
int result;
result = register_chrdev(0, "char_dev", &tdd_fops);
if (result < 0){
printk("char_dev:can't get major number
");
return result;
}
if (test_major == 0)
test_major = result;
printk ("Hello,I'm in kenel mode
");
return 0;
}
void cleanup_module(void){
printk("Hello,I'm goint to out
");
unregister_chrdev(test_major,"char_dev");
} 用下述命令进行
编译:
#gcc – O2 -DMODULE – D KERNEL -c CharDriver.c
出现下述错误:
CharDriver.c 18:Tvariable ‘fops’ has initializer but incomplete type
CharDriver.c 19:unknown field ‘read’ specified in initializer
CharDriver.c 20:unknown field ‘open’ specified in initializer
CharDriver.c 20:unknown field ‘release’ specified in initialize r
CharDriver.c 53:storage size of ‘fops’ isn’t known
原因:在用 gcc 进行编译时,默认搜索的 include 文件路径为/usr/include, 但/usr/include/linux/fs.h
中没有定义 f i le_operations 结构体(可以打开该文件看一下), file _operations 是在原代码树目录
/usr/src/linux-2.4/include 下的 linux/fs.h 中定义,而且用了#ifdef KERNEL 条件编译。因此在编
译时必须指定该目录和定义 KERNEL 。编译命令如下:
#gcc – O2 - DM ODU LE – D KE RNE L_ _ – I/ us r/s rc /li nu x-2 .4/ in clu de -c Ch arDri ve r.c
经过编译得到的文件 CharDriver.o 就是设备驱动程序,执行以下命令把它安装到系统中:
#insmod CharDriver.o
如果安装成功,用#vi /proc/devices 打开文件将看到设备 char_dev 和主设备号。如果需要卸载,可运行
#rmmod char_dev
然后就需要创建设备文件了,执行以下命令:mknod /dev/char_dev c 254 0,其中“/dev/char_dev”是
要生成的设备名及目录,选项 c 是指字符设备,254 是生成的主设备号,可用上面方法查看到,也可能是
253 或其它,从设备号设成 0 就可以。另外可以用 rm – f /dev/char_dev 将删除 mknod 命令创建的设备
文 件。可用下述测试程序源代码进行测试。
驱动的测试程序如下:
/*DriverTest.c*/
#include
#include
#include
#include
int main(int argc, char *argv[]){
int testdev;
int i;
char buf[10];
testdev = open("/dev/char_dev", O_RDWR);
if (testdev == -1){
printf("Cann't open file
");
exit(0);
}
read(testdev, buf, 10);
for (i = 0; i < 10; i++){
printf("%d
", buf);
}
close(testdev);
}
需要注意的是将驱动程序数据传给用户程序时是 pu t_u s er( 1, buf ), 而不是 p ut _us er (1, bu f,1 ); 否则会
出现错误。还有 co py_ to _us er( bu f,B uf fer ++, 1) 函数的 B uff er 是指针变量,而不是具体的数据,如果写
成 c opy _t o_use r(b uf ,1, 1) ,也会出错
深圳南山RK3399嵌入式开发板简单的字符设备驱动实验,友坚科技专注于三星、瑞芯微、飞思卡尔平台产品的研发,是三星、瑞芯微、飞思卡尔在中国最具实力的方案公司之一。公司研发、生产的平板、开发板,连续多年销量稳居第一。公司定位于中高端产品的研发,具有多年的嵌入式产品研发经验;基于A15-Exynos5260、A53_S5P6818、A9-S5P4418、A9-Exynos 4412、A8-S5PV210、ARM11-S3C6410、ARM9-S3C2416 、RK3188、RK3288、RK3399、IMX6Q等处理器,开发了系列化产品,为客户提供了全面的产品选择及专业化的量身定制MID解决方案。
`
|