@rfish
2016-03-13T12:37:59.000000Z
字数 7501
阅读 1529
培训
名称 | 型号 | 其他 |
---|---|---|
camera | OV9650 | 2 |
液晶 | at070th92 | 分辨率800*480,16M种颜色 |
CPU | 三星 | |
内存 | 三星 | |
闪存 | 三星 | |
操作系统 | Linux | |
应用程序 | C/C++ |
\172.24.6.8
user:yangjz
passwd:123456
嵌入式系统:linux
开发环境:安装交叉开发环境
编译:gcc c_file.c -o filename
解压:tar -jcvf filename.tar.bz2
解压在当前目录
拷贝
4.4.1.tar.bz2
到/usr/local/arm
tar xvfj 4.4.1.tar.bz2
配置环境变量
vim /rtc/bash.bashrc
export PATH= /usr/local/arm/4.4.1/bin:$PATH
在最后添加环境变量source /etc/bash.bashrc
在本shell中执行bash.bashrc测试交叉编译工具
/opt/
目录创建目录hello.c
文件arm-linux-gcc hello.c -o hello_arm
编译成arm架构的文件配置串口
名称 | 选择 |
---|---|
协议 | Serial(串口) |
端口 | 本机查看(设备管理器) |
波特率 | 115200 |
数据流 | XON/XOFF |
传输
mkpro
rx hello_arm
等待接收hello_arm
传输
->Xmodem
hello_arm
权限为777重新安装linux系统
zImage
文件系统:gec210.img
bootloader:u-boot.bin
启动过程:
第一阶段:bootloader阶段(引导内核)
第二阶段:kernel(内核)启动阶段有类似[0.0000123]
的打印信息
第三阶段:rootfs文件系统阶段(用户可以与系统交互)驱动:运行在
内核空间
应用:运行在用户空间
flash
内核
与文件系统
到开发板DRAM
nand
操作(nand erase/write)操作在bootloader交互界面:
1. PC与gec210开发板网线连接
2. pri 打印环境变量
3. 找到serverip=172.x.x.x
//我们的PC的IP(PC改为静态IP)
4. 找到ipaddr=x.x.x.x
//开发板ip
5. 找到gatewayip=x.x.x.x
//网关
#set serverip 172.24.6.100
#set ipaddr 172.23.6.101
#set gatewayip 172.24.6.1
#set netmask 255.255.255.0
#save
#ping 172.24.6.29(windows ip)
以上操作只是为了将PC的IP和板子的IP设在同一网段
tftp 目录为zImage
gec210.img
u-boot.bin
所在目录
tftp 40000000 zImage
40000000是DRAM的地址
nand erase 600000 500000
从地址0x600000开始擦除500000(5M)空间
nand write 40000000 600000 500000
从DRAM地址40000000开始的内容 写到flash从600000开始的地址,写500000(5M)大小
tftp 40000000 gec210.img
(记录下载后的大小为xxx)
nand erase e00000 0xf200000
nand write.yaffs 40000000 e00000 xxx
tftp 40000000 u-boot
nand erase 0 600000
从地址0x0开始擦除600000(6M)空间
nand write 40000000 0 600000
重启即可
按键 | 功能 | 备注 |
---|---|---|
key2 | camera on/off | EINT16(16号外部中断) |
key3 | 上一张 | EINT17 |
key4 | 下一张 | EINT18 |
key5 | 上传图片 | EINT19 |
linux-2.6.35.7-gec-v3.0-gt110.tar
/opt/gec210/bsp
/opt后的文件夹是任意命名的 tar xvfj linux-2.6.35.7-gec-v3.0-gt110.tar
cp GEC210_7INCH_CONFIG-FT5x06 .config
拷贝该文件为.config
文件 MaKefile
中194行的4.5.1
内容改成4.4.1
make uImage -j 3
问题:
"mkimage" command not found - U-Boot images will not be built
解决:不影响驱动开发
Input.c
#include<linux/kernel.h>
#include<linux/module.h>
int input_init(void)
{
printk("input sub system init\n");
return 0;
}
void input_exit(void)
{
printk("input sub system exit\n");
}
module_init(input_init);
module_exit(input_exit);
MODULE_LICENSE("GPL");
cobj-m +=Input.o
#obj是必须的前面的c表示依赖的原文件是.C文件,后面的Input是必须和我们的Input.c同名(包括大小写)。
#依赖包路径
KERN := /opt/Video-system-train/gec210/bsp/linux-2.6.35.7-gec-v3.0-gt110
all:
make modules -C $(KERN) M=`pwd`
#M后的pwd当前路径是生成文件Input.o的路径
clean:
make modules -C $(KERN) M=`pwd` clean
执行命令make
input.ko
用户空间的驱动 安装到内核控件
insmod <filename.ko>
lsmod
显示驱动,rmmod <filename>
卸载驱动(不加后缀.ko)添加一个按键中断
linux/interrupt.h
)
/*注册中断*/
int request_irq(unsigned int irq,//中断号(IRQ_EINT(16))
irq_handler_t handler,
//irq_handler_t一个函数指针的别名,指向中断后的运行的中断函数
unsigned long irqflags,//触发标记
。
。
。
)
/* 释放中断*/
free_irq(unsigned int irq,//中断号
void *dev//一般为NULL
)
内核中有输入子系统,我们需要为它创建一个驱动
开发过程:
1.定义一个struct input_dev 并且初始化
inout_dev *but_dev=input_allocate_eevice();
but_dev->evbit
2.将input_dev结构体向输入子系统注册
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/input.h>
#include <plat/irqs.h>
#include <mach/irqs.h>
static struct input_dev *button_dev;
irqreturn_t gec_handler(int irq, void *data)
{
int sn;
//提交按键触发的信号
printk("gec_handler \n");
sn = irq - IRQ_EINT(16);
input_report_key(button_dev, KEY_1+sn, 1); //在中断处理中汇报按键键值
input_report_key(button_dev, KEY_1+sn, 0);
input_sync(button_dev); //提交同步请求
return IRQ_HANDLED;
}
static int __init hello_init(void)
{
int ret,i;
printk("hello \n");
for(i=0;i<4;i++)
{
// 申请中断
ret = request_irq(IRQ_EINT(16)+i,
gec_handler,
IRQF_TRIGGER_FALLING | IRQF_DISABLED,
"gec_key",
NULL);
if(ret)
goto request_irq_err;
}
//分配空间
button_dev = input_allocate_device();
if(!button_dev)
goto input_allocate_device_err;
//初始化
button_dev->evbit[0] = BIT_MASK(EV_KEY); //支持按键事件
button_dev->keybit[BIT_WORD(KEY_1)] = BIT_MASK(KEY_1); //支持 KEY_1 按键
button_dev->keybit[BIT_WORD(KEY_2)] |= BIT_MASK(KEY_2); //支持 KEY_1 按键
button_dev->keybit[BIT_WORD(KEY_3)] |= BIT_MASK(KEY_3); //支持 KEY_1 按键
button_dev->keybit[BIT_WORD(KEY_4)] |= BIT_MASK(KEY_4); //支持 KEY_1 按键
button_dev->name = "gec_key";
button_dev->id.bustype = 0xFF;
button_dev->id.product = 0xFF;
//向系统注册设备
ret = input_register_device(button_dev);
if(ret)
goto input_register_device_err;
return 0;
request_irq_err:
printk("request_irq Failed!\n");
return -EBUSY;
input_allocate_device_err:
printk("input_allocate_device Failed!\n");
return -EFAULT;
input_register_device_err:
printk("input_register_device Failed!\n");
return -EFAULT;
}
static void __exit hello_exit(void)
{
int i;
for(i=0;i<4;i++)
free_irq(IRQ_EINT(16)+i, NULL);
input_unregister_device(button_dev);
printk("hello_exit \n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include <linux/input.h>
int main()
{
int key_fd;
int ret;
struct input_event key_value;
key_fd = open("/dev/event1",O_RDWR);
if(key_fd < 0)
{
printf("open key Failed !\n");
return -1;
}
/* debug1 */while(1){
ret = read(key_fd,&key_value,sizeof(key_value));
if(ret != sizeof(key_value))
{
printf("read key Failed !\n");
return -1;
}
if(key_value.type == EV_KEY)
{
switch(key_value.code)
{
case KEY_1:
printf("read key KEY_1 !\n");
break;
case KEY_2:
printf("read key KEY_2 !\n");
break;
case KEY_3:
printf("read key KEY_3 !\n");
break;
case KEY_4:
printf("read key KEY_4!\n");
break;
default:
printf("read key err !\n");
break;
}
}
}
close(key_fd);
return key_value.code;
}
RGB接口
其中24线,每8线对应一种颜色VD[23:16]
R
(0-255)
VD[15:8]G
VD[7:0]B
VD(video data)4线控制信号
DMA电路去DRAM取显存,改格式包装后送到LCD
framebuffer子系统1.定义一个显示结构体
2.注册驱动
3.open(fb0,权限)
4.mmap(用户与内核显存空间映射)
- 拷贝文件至ubuntu编译
- 下载到开发板
- PC打开tftp软件配置好目录
- 开发板进入文件系统
- 修改开发板IP(
ifconfig eth0 <IP address>
动态修改)
静态修改:修改配置文件/etc/init.d/rcS
ip- 测试ping通
- 开发板中输入
tftp <service ip> -g -r <filename>
- 显示图片
- 给图片和应用程序可执行权限
chmod 777 <filename>
- 执行程序
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
char lcd_buf[800*480*4];
char bmp24_buf[800*480*3];
unsigned int* fb_mem;
int main(int argc,char **argv)
{
int i,ret,x,y;
int lcd_fd,bmp_fd;
printf(" argc = %d \n",argc);
for(i=0;i<argc;i++)
printf(" argv = %s \n",argv[i]);
// 获取资源许可
lcd_fd = open("/dev/fb0", O_RDWR);
if(lcd_fd < 0)
{
printf("open LCD Failed!\n");
return -1;
}
//读取BMP 图片----> 使用文件IO API
bmp_fd = open("./helloworld.bmp", O_RDWR);
if(bmp_fd < 0)
{
printf("open BMP Failed!\n");
return -1;
}
// 跳开文件头的54B数据
lseek(bmp_fd,54,SEEK_SET);
ret = read(bmp_fd,bmp24_buf,800*480*3);
if(ret != 800*480*3)
{
printf("read 24bit BMP Failed!\n");
return -1;
}
// 方案2: a进行LCD显存映射mmap
fb_mem = (unsigned int*)mmap(NULL, 800*480*4, PROT_READ| PROT_WRITE, MAP_SHARED,lcd_fd, 0);
if(fb_mem == MAP_FAILED)
{
printf("mmap Failed!\n");
return -1;
}
sleep(1); //睡眠1s
// 方案2: b将24bit的RGB位操作依次写入映射的显存
for(i=0,y=479;y>=0;y--)
for(x=0;x<800;x++)
{
*(fb_mem+y*800+x) = bmp24_buf[i]|bmp24_buf[i+1]|bmp24_buf[i+2];
i+=3;
}
// 撤销显存映射
munmap(fb_mem, 800*480*4);
//释放资源
close(lcd_fd);
close(bmp_fd);
return 0;
}
- 在ubuntu中解压
lcd_jpg.tar.bz2
- 进入解压文件后编译
- 下载图片和程序文件到开发板
- 修改权限后执行
内部控制电路(核心A8),控制camera光电信号转换,然后将数据缓存到DRAM
V4L_V2:camera
cam_jpg
配置nfs功能:
安装nfs程序:
apt-get install nfs-kernel-server portmap
vim /etc/exports
添加
/nfs/ *(rw,sync,no_root_squash)
需要在根目录下新建/nfs/
重启nfs服务
/etc/init.d/nfs-kernel-server restart
开发板操作:
ping测试
ping xxxxx
开发板创建目录/mount/
将ubuntu的/nfs/目录挂载到开发板的/mount/:
mount -o nolock <ip address>:/nfs/ /mount/
取消挂载:
umount /mount
1.图片存储到指定目录
2.拍照后图片显示到lcd
服务器端:
发送三个重要要素:IP、port、协议
1.创建一个套接字
2.绑定地址
3.等待接收
客户端:
1.创建一个套接字
2.