Edit online

Demo

5 Jul 2024
Read time: 1 minute(s)
以下 demo 实现 VE 驱动基本调用流程,具体可参考 mpp 代码,路径为 base/ve/ve.c
//* 1. 打开 VE 驱动
int fd = open("/dev/aic_ve", O_RDWR);

//* 2. 获取 ve 寄存器空间大小
struct ve_info info = {0};
ioctl(fd, IOC_VE_GET_INFO, &info);

//* 3. 映射寄存器地址空间
unsigned long reg_base = (unsigned long)mmap(NULL,
                info.reg_size,
                PROT_READ | PROT_WRITE, MAP_SHARED,
                fd,
                0);

//* 4. 获取 VE 权限
ioctl(fd, IOC_VE_GET_CLIENT);

//* 5. 配置寄存器(省略)
...

//* 6. 等 VE 中断
struct wait_info wt_info;
wt_info.wait_time = VE_TIMEOUT;
int ret = ioctl(fd, IOC_VE_WAIT, &wt_info);
if(ret < 0) {
    // 中断超时,VE 硬件复位
    ioctl(fd, IOC_VE_RESET);
}

//* 7. 释放 VE 权限
ioctl(fd, IOC_VE_PUT_CLIENT);