[关闭]
@rfish 2016-03-13T12:37:59.000000Z 字数 7501 阅读 1529

YF培训

培训


1.前言


2.第一天(搭平台)

名称 型号 其他
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解压在当前目录


3.第二天(更新系统)

名称 选择
协议 Serial(串口)
端口 本机查看(设备管理器)
波特率 115200
数据流 XON/XOFF

启动过程:
第一阶段:bootloader阶段(引导内核)
第二阶段:kernel(内核)启动阶段有类似[0.0000123]的打印信息
第三阶段:rootfs文件系统阶段(用户可以与系统交互)

驱动:运行在内核空间
应用:运行在用户空间

操作在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 zImage40000000是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

问题:
"mkimage" command not found - U-Boot images will not be built
解决:不影响驱动开发


4.第三天(驱动)

  1. #include<linux/kernel.h>
  2. #include<linux/module.h>
  3. int input_init(void)
  4. {
  5. printk("input sub system init\n");
  6. return 0
  7. }
  8. void input_exit(void)
  9. {
  10. printk("input sub system exit\n");
  11. }
  12. module_init(input_init);
  13. module_exit(input_exit);
  14. MODULE_LICENSE("GPL");
  1. cobj-m +=Input.o
  2. #obj是必须的前面的c表示依赖的原文件是.C文件,后面的Input是必须和我们的Input.c同名(包括大小写)。
  3. #依赖包路径
  4. KERN := /opt/Video-system-train/gec210/bsp/linux-2.6.35.7-gec-v3.0-gt110
  5. all:
  6. make modules -C $(KERN) M=`pwd`
  7. #M后的pwd当前路径是生成文件Input.o的路径
  8. clean:
  9. make modules -C $(KERN) M=`pwd` clean
  1. /*注册中断*/
  2. int request_irq(unsigned int irq,//中断号(IRQ_EINT(16))
  3. irq_handler_t handler
  4. //irq_handler_t一个函数指针的别名,指向中断后的运行的中断函数
  5. unsigned long irqflags//触发标记
  6. )
  7. /* 释放中断*/
  8. free_irqunsigned int irq//中断号
  9. void *dev//一般为NULL

内核中有输入子系统,我们需要为它创建一个驱动
开发过程:
1.定义一个struct input_dev 并且初始化
inout_dev *but_dev=input_allocate_eevice();
but_dev->evbit
2.将input_dev结构体向输入子系统注册

  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include <linux/module.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/input.h>
  6. #include <plat/irqs.h>
  7. #include <mach/irqs.h>
  8. static struct input_dev *button_dev;
  9. irqreturn_t gec_handler(int irq, void *data)
  10. {
  11. int sn;
  12. //提交按键触发的信号
  13. printk("gec_handler \n");
  14. sn = irq - IRQ_EINT(16);
  15. input_report_key(button_dev, KEY_1+sn, 1); //在中断处理中汇报按键键值
  16. input_report_key(button_dev, KEY_1+sn, 0);
  17. input_sync(button_dev); //提交同步请求
  18. return IRQ_HANDLED;
  19. }
  20. static int __init hello_init(void)
  21. {
  22. int ret,i;
  23. printk("hello \n");
  24. for(i=0;i<4;i++)
  25. {
  26. // 申请中断
  27. ret = request_irq(IRQ_EINT(16)+i,
  28. gec_handler,
  29. IRQF_TRIGGER_FALLING | IRQF_DISABLED,
  30. "gec_key",
  31. NULL);
  32. if(ret)
  33. goto request_irq_err;
  34. }
  35. //分配空间
  36. button_dev = input_allocate_device();
  37. if(!button_dev)
  38. goto input_allocate_device_err;
  39. //初始化
  40. button_dev->evbit[0] = BIT_MASK(EV_KEY); //支持按键事件
  41. button_dev->keybit[BIT_WORD(KEY_1)] = BIT_MASK(KEY_1); //支持 KEY_1 按键
  42. button_dev->keybit[BIT_WORD(KEY_2)] |= BIT_MASK(KEY_2); //支持 KEY_1 按键
  43. button_dev->keybit[BIT_WORD(KEY_3)] |= BIT_MASK(KEY_3); //支持 KEY_1 按键
  44. button_dev->keybit[BIT_WORD(KEY_4)] |= BIT_MASK(KEY_4); //支持 KEY_1 按键
  45. button_dev->name = "gec_key";
  46. button_dev->id.bustype = 0xFF;
  47. button_dev->id.product = 0xFF;
  48. //向系统注册设备
  49. ret = input_register_device(button_dev);
  50. if(ret)
  51. goto input_register_device_err;
  52. return 0;
  53. request_irq_err:
  54. printk("request_irq Failed!\n");
  55. return -EBUSY;
  56. input_allocate_device_err:
  57. printk("input_allocate_device Failed!\n");
  58. return -EFAULT;
  59. input_register_device_err:
  60. printk("input_register_device Failed!\n");
  61. return -EFAULT;
  62. }
  63. static void __exit hello_exit(void)
  64. {
  65. int i;
  66. for(i=0;i<4;i++)
  67. free_irq(IRQ_EINT(16)+i, NULL);
  68. input_unregister_device(button_dev);
  69. printk("hello_exit \n");
  70. }
  71. module_init(hello_init);
  72. module_exit(hello_exit);
  73. MODULE_LICENSE("GPL");
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <stdio.h>
  7. #include <linux/input.h>
  8. int main()
  9. {
  10. int key_fd;
  11. int ret;
  12. struct input_event key_value;
  13. key_fd = open("/dev/event1",O_RDWR);
  14. if(key_fd < 0)
  15. {
  16. printf("open key Failed !\n");
  17. return -1;
  18. }
  19. /* debug1 */while(1){
  20. ret = read(key_fd,&key_value,sizeof(key_value));
  21. if(ret != sizeof(key_value))
  22. {
  23. printf("read key Failed !\n");
  24. return -1;
  25. }
  26. if(key_value.type == EV_KEY)
  27. {
  28. switch(key_value.code)
  29. {
  30. case KEY_1:
  31. printf("read key KEY_1 !\n");
  32. break;
  33. case KEY_2:
  34. printf("read key KEY_2 !\n");
  35. break;
  36. case KEY_3:
  37. printf("read key KEY_3 !\n");
  38. break;
  39. case KEY_4:
  40. printf("read key KEY_4!\n");
  41. break;
  42. default:
  43. printf("read key err !\n");
  44. break;
  45. }
  46. }
  47. }
  48. close(key_fd);
  49. return key_value.code;
  50. }

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(用户与内核显存空间映射)


5.第四天(显示图片)

  • 拷贝文件至ubuntu编译
  • 下载到开发板
    • PC打开tftp软件配置好目录
    • 开发板进入文件系统
    • 修改开发板IP(ifconfig eth0 <IP address> 动态修改)
      静态修改:修改配置文件 /etc/init.d/rcS ip
    • 测试ping通
    • 开发板中输入tftp <service ip> -g -r <filename>
  • 显示图片
    • 图片应用程序可执行权限chmod 777 <filename>
    • 执行程序
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <sys/mman.h>
  7. #include <string.h>
  8. char lcd_buf[800*480*4];
  9. char bmp24_buf[800*480*3];
  10. unsigned int* fb_mem;
  11. int main(int argc,char **argv)
  12. {
  13. int i,ret,x,y;
  14. int lcd_fd,bmp_fd;
  15. printf(" argc = %d \n",argc);
  16. for(i=0;i<argc;i++)
  17. printf(" argv = %s \n",argv[i]);
  18. // 获取资源许可
  19. lcd_fd = open("/dev/fb0", O_RDWR);
  20. if(lcd_fd < 0)
  21. {
  22. printf("open LCD Failed!\n");
  23. return -1;
  24. }
  25. //读取BMP 图片----> 使用文件IO API
  26. bmp_fd = open("./helloworld.bmp", O_RDWR);
  27. if(bmp_fd < 0)
  28. {
  29. printf("open BMP Failed!\n");
  30. return -1;
  31. }
  32. // 跳开文件头的54B数据
  33. lseek(bmp_fd,54,SEEK_SET);
  34. ret = read(bmp_fd,bmp24_buf,800*480*3);
  35. if(ret != 800*480*3)
  36. {
  37. printf("read 24bit BMP Failed!\n");
  38. return -1;
  39. }
  40. // 方案2: a进行LCD显存映射mmap
  41. fb_mem = (unsigned int*)mmap(NULL, 800*480*4, PROT_READ| PROT_WRITE, MAP_SHARED,lcd_fd, 0);
  42. if(fb_mem == MAP_FAILED)
  43. {
  44. printf("mmap Failed!\n");
  45. return -1;
  46. }
  47. sleep(1); //睡眠1s
  48. // 方案2: b将24bit的RGB位操作依次写入映射的显存
  49. for(i=0,y=479;y>=0;y--)
  50. for(x=0;x<800;x++)
  51. {
  52. *(fb_mem+y*800+x) = bmp24_buf[i]|bmp24_buf[i+1]|bmp24_buf[i+2];
  53. i+=3;
  54. }
  55. // 撤销显存映射
  56. munmap(fb_mem, 800*480*4);
  57. //释放资源
  58. close(lcd_fd);
  59. close(bmp_fd);
  60. return 0;
  61. }
  • 在ubuntu中解压lcd_jpg.tar.bz2
    • 进入解压文件后编译
    • 下载图片和程序文件到开发板
    • 修改权限后执行

6.第五天(camera)

内部控制电路(核心A8),控制camera光电信号转换,然后将数据缓存到DRAM

Created with Raphaël 2.1.2CameraCameraHWHWkernel(V4L_V2)kernel(V4L_V2)user appuser appI^2c

V4L_V2:camera

配置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.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注