基于 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 的优点-与黑白图像兼容-占用带宽小-抗干扰能力强
4:2:0&4:2:2& 4:4:4
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_REDAY
TSK_TERMINATED
TSK_RUNNING
TSK_BLOCKED
TSK_create() TSK_tick()SEM_post()
TSK_exit()
TSK_delete()
TSK_delete()
TSK_sleep()SEM_pend()
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 Controller Block
触发 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
TMS320DM642 Block Diagram
SDRAM
64-bit wide @ 133MHz
10/100 Ethernet
MAC
C64xTM DSP Core
L2 C
ache/M
emo
ry 256 KB
ytes
En
han
ced D
MA
Co
ntro
ller
Videoport-0
Videoport-1
Videoport-2
McASP
EMIF
66MHzPCI
TMS320DM642 DSP
L1D Cache
L1P Cache
DM642 Core
• 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.656 mode
- 16/20bit Y/C mode
- 8/16/20bit raw mode
- scaling & chroma re-sampling( 硬件上可实现 )• Video Display
- same as capture
DM642 Video Port
Use EDMA Linking for Automated Transfer (Capture)???
Y
VP FIFO SRC Y
EDMA Channels
DST Y
SRC Y DST Y
EDMA Reload Channels
Frame1
Frame2
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
- EDC interface: External Device Control Module
Driver Block Diagram
Application/Framework
GIO Class Driver
Video Port/EDMA Video Codecs
Encoder/Decoder Specific Part of Mini-Driver
Chip Support Library (CSL)
Class
Driver
Mini-
Driver
Device
Driver
FVID Class Driver Wrapper
Generic Video Port – EDMA Data Mover
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 中静态完成 ,遵循以下步骤:
a)在 User-Defined Devices 上点击右键,从弹出菜单上选择 Insert UDEV 。
b)重命名刚才插入的对象,名字要唯一。c)设置刚刚插入对象的属性
主要内容• Video Formats
• DSP/BIOS
• EDMA
• Video Driver
• Registering the Video Driver
• Using the Video Driver
实验 3 :视频采集与显示• 位置: \src\Imagelab_vdp\lab_flash\
VP_loopback_P