520 likes | 783 Views
基于 TI DM642 的视频 采集与显示. 张震国 2006-11-04. 主要内容. Video Formats DSP/BIOS EDMA Video Driver Registering the Video Driver Using the Video Driver. VIDEO. 一系列活动的视频 两种制式: PAL 和 NTSC 帧频、场频、行频 分辨率 - QCIF : 176×144 - CIF : 352×288 - 4CIF : 704×576 - D1 : 720×576. YUV 与 RGB. 两种颜色空间
E N D
基于TI DM642的视频采集与显示 张震国 2006-11-04
主要内容 • Video Formats • DSP/BIOS • EDMA • Video Driver • Registering the Video Driver • Using the Video Driver
VIDEO • 一系列活动的视频 • 两种制式:PAL和NTSC • 帧频、场频、行频 • 分辨率 -QCIF:176×144 -CIF:352×288 -4CIF:704×576 -D1:720×576
YUV与RGB • 两种颜色空间 • 通过转换公式,可以相互转换 • 使用YUV的优点 -与黑白图像兼容 -占用带宽小 -抗干扰能力强
Bytes per Frame (4:2:2) • QCIF: 176x144x2=50688 • CIF: 352x288x2=202752 • 4CIF: 704x576x2=811008 • D1:720x576x2=829440
主要内容 • Video Formats • DSP/BIOS • EDMA • Video Driver • Registering the Video Driver • Using the Video Driver
DSP/BIOS? • 一个高度优化的可扩展的实时内核 • 和CCS集成在一起 • 需要最小的内存和CPU占用 • 是TI eXpressDSP技术的一个重要组成部分 另外两个:--xdais算法标准 --TI第三方软件支持
DSP/BIOS的特点 • 模块化设计 • 库被优化设计使用最少的指令周期 • 目标板和主机之间的数据交换在idle线程中进行 • 对象可以被静态或动态创建 • 多种的线程类型供选择 • 提供多种线程间同步对象
DSP/BIOS组成 • DSP/BIOS配置工具--Configuration Tool • DSP/BIOS实时分析工具 • DSP/BIOS API接口 • DSP/BIOS 内核
Configuration Tool生成的文件 • Program.cdb:配置文件,存储在Configuration Tool中的设置。 • Programcfg.s62:Configuration Tool产生的汇编文件。 • Programcfg.h62:被Programcfg.s62包含。 • Programcfg.cmd:根据Configuration Tool的设置产生的linker文件。 • Programcfg.h:包含在Configuration Tool中创建对象的声明。 • Programcfg_c.c:根据CSL设置产生的代码。
DSP/BIOS程序启动执行顺序 • C入口函数: c_int00 • 调用BIOS_init初始化DSP/BIOS的各个模块。全局属性中的用户初始化函数在该处被调用。 • 调用main函数。 • 调用BIOS_start启动DSP/BIOS。 • 进入idle循环。
main函数 • 程序执行到main函数时,DSP/BIOS的各个模块还没有启动。所以一些函数不能在main里调用。 • main只做一些初始化的工作。 • 不是DSP/BIOS中线程的一种。
线程类型 • 硬件中断(HWI),包括CLK函数 • 软件中断(SWI),包括PRD函数 • 任务(TSK) • IDL(IDL)
HWI • 响应外部事件,拥有最高的优先级 • 使用系统栈 • 中断服务程序可以用C、汇编或者C和汇编,不需要interrupt关键字 • 当全部用C语言写时需要选择Use Dispatcher属性 • CLK函数是硬件中断类型,由Timer中断来触发
SWI • 比硬件中断的优先级低,比任务高 • 每个SWI有一个SWI_handle • 使用系统栈 • 通过API接口函数来触发 • 会被硬件中断和高优先级的SWI抢占,但不能被阻塞 • 用一个32bit的mailbox来控制SWI函数的执行次数和时机
TSK • 通过TSK模块来管理 • 每个TSK有一个TSK_handle • 比SWI的优先级低,比IDLE的优先级高 • 16个优先级 • 可以被阻塞 • 每个任务拥有自己的运行时栈 • 总是运行处于ready状态的高优先级的任务
TSK的四种状态 TSK_tick() SEM_post() TSK_create() TSK_REDAY TSK_delete() TSK_RUNNING TSK_sleep() SEM_pend() TSK_TERMINATED TSK_BLOCKED TSK_exit() TSK_delete()
The idle Loop • DSP/BIOS的background thread • 任何线程可以在任意点抢占idle loop • 只有在没有HWI、SWI、TSK可以运行的时候才执行 • 可以调用IDL_run()强制运行idle loop。每调用一次IDL_run运行一次idle loop。
实验1 • 位置: \src\07tsktest
主要内容 • Video Formats • DSP/BIOS • EDMA • Video Driver • Registering the Video Driver • Using the Video Driver
C64x中的EDMA • 具有64个通道 • 具有四个优先级队列 • 时钟频率是CPU时钟频率的1/2 • 传输可以链接 • 支持二维传输 • 仅有一个Int8中断,通过TCC来区分中断事件
触发EDMA传输的方式 • CPU-initiated EDMA • Event-initiated EDMA
EDMA的使用 • TMS320C6000 DSP Enhanced Direct Memory Access(EDMA) Controller Reference Guide.pdf
实验2 EDMA的使用 • 位置: \src\edma
主要内容 • Video Formats • DSP/BIOS • EDMA • Video Driver • Registering the Video Driver • Using the Video Driver
SDRAM TMS320DM642BlockDiagram TMS320DM642 DSP Videoport-0 L1P Cache Videoport-1 Videoport-2 C64xTMDSP Core Enhanced DMA Controller L2 Cache/Memory 256 KBytes 66MHzPCI 10/100 EthernetMAC L1D Cache McASP EMIF 64-bit wide @ 133MHz
DM642Core • 750/600/500MHz C64x DSP core -64 general-purpose registers of 32-bit world length -Eight highly independent functional units -SIMD instructions tailored for video and imaging applications • Two-level cache architecture -16Kbyte L1P & L1D cache -256Kbyte L2 cache/SRAM • 64-channel EDMA controller -Five transfer request queues with programmable priority and depth -Transfer linking and chaining -2-D transfer
DM642 Key Peripherals • Three configurable video ports • One 10/100 Mb/s Ethernet MAC • One multi-channel buffered audio serial port (McASP) • One inter-integrated circuit(I2C) Bus module • One 66MHz peripheral component interface (PCI) • One 64 bit glueless external memory interface (EMIF) • Two multi-channel buffered serial ports (McBSPs) • Three 32-bit general-purpose timers • One user-configurable 16-bit or 32-bit host-port interface(HPI16/HPI32)
Driver Basics • Separate drivers for capture & display • Only support frame based operation • Uses EDMA to move data between video port FIFO and DSP memory • EDMA link is enabled to automate the transfer no CPU intervention • EDMA transfer completion interrupts are used to synchronize with the application
Video Port Modes • Video Capture -Dual-channel capable -8/10bit ITU-R BT.656mode -16/20bit Y/C mode -8/16/20bit raw mode -scaling & chroma re-sampling(硬件上可实现) • Video Display -same as capture
Use EDMA Linking for Automated Transfer (Capture)??? EDMA Channels SRC Y DST Y Frame1 VP FIFO Y Frame2 SRC Y DST Y EDMA Reload Channels
Driver Architecture • Adopted a two-level device driver model • Top level – Class Driver , 2 layers -FVID Wrapper -GIO Class Driver • Bottom level – Mini-driver, 2 layers -IOM interface: Generic EDMA data mover -EDCinterface: External Device Control Module
Driver Block Diagram Application/Framework FVID Class Driver Wrapper Class Driver GIO Class Driver Device Driver Generic Video Port – EDMA Data Mover Mini- Driver Encoder/Decoder Specific Part of Mini-Driver Chip Support Library (CSL) Video Port/EDMA Video Codecs
Class Driver Architecture • GIO -Generic class driver API -Can be used for wide range of I/O devices -Can be extended to support specific I/Os types such as video and file system -Provides basic seriallization and synchronization capabilities of multi-threaded I/O requests -Handles device instance management • FVID -An extension of GIO -Tailored for frame video applications
GIO Classs Driver API • GIO_control: Calls the underneath mini-driver control function. • GIO_create: Create an instance of a device driver. • GIO_delete: Delete the instance of the device driver previously created. • GIO_submit: Submit an I/O request. • Basic GIO APIS do not provide adequate support for continuous video capture & display operations
FVID Wrapper API • Macros that directly mapped to GIO APIs • Three new I/O request commands are defined -FVID_ALLOC -FVID_FREE -FVID_EXCHANGE • FVID_control: directly mapped to GIO_control • FVID_create: directly mapped to GIO_create • FVID_delete: directly mapped to GIO_delete • FVID_alloc: returns a frame buffer from the driver to the application • FVID_free: returns an application owned buffer back to the driver • FVID_exchange: a combination of FVID_alloc and FVID_free
Mini-Driver Architecture • The generic EDMA data mover -DSP specific, but independent of external devices used. -Responsible for all peripheral, EDMA configuration and data movement inside the DSP. • The External Device Control (EDC) module -Responsible for configuring the external device to ensure correct data flow between the external device and the DSP’s video port. • Ensures easy portability by maximizing code reuse
Mini-Driver Top Layer • Implements the IOM interface, which should implement the following functions: -mdBindDev. Bind device to mini-driver -mdControlChan. Perform channel control commands. -mdCreateChan. Create a device channel -mdDeleteChan. Delete a channel. -mdSubmitChan. Submit a packet to a channel for processing. -mdUnBindDev. Unbind device from mini-driver • These functions are referenced in an interface table of type IOM_Fxns
Mini-Driver Interfaces • Top layer implements the IOM interface: -mdBindDev. -mdControlChan. -mdCreateChan. -mdDeleteChan. -mdSubmitChan. -mdUnBindDev. • Bottom layer implements the EDC interface: -edcControl. -edcOpen. -edcClose. • These functions are referenced in interface tables of type IOM_Fxns and EDC_Fxns respectively
用到的结构 • VPORTCAP_Params • VPORTDIS_Params • VPORT_PortParams • TVP5150_ConfParams • SAA7105_ConfParams • FVID_Frame • IOM_Packet
IOM Packets 向mini-driver提交请求的标准数据结构。 typedef struct IOM_Packet { /* frame object */ QUE_Elem link; /* queue link */ Ptr addr; /* buffer address */ Uns size; /* buffer size */ Arg misc; /* miscellaneous item */ Arg arg; /* user argument */ /* these fields are used by IOM ... */ Uns cmd; /* command for mini-driver */ Int status; /* status of command */ } IOM_Packet;
用到的函数 • FVID_create • FVID_control • FVID_alloc • FVID_exchange
Video Port Reg • TMS320C64x DSP Video Port & VCXO Interpolated Control (VIC) Port Reference Guide (Rev. A).pdf
主要内容 • Video Formats • DSP/BIOS • EDMA • Video Driver • Registering the Video Driver • Using the Video Driver
注册mini-driver 注册mini-driver需要在Configuration Tool中静态完成,遵循以下步骤: • 在User-Defined Devices上点击右键,从弹出菜单上选择Insert UDEV。 • 重命名刚才插入的对象,名字要唯一。 • 设置刚刚插入对象的属性