3.2. sample_vin 使用说明

3.2.1. get_vin_data

3.2.1.1. 功能概述

get_vin_data 完成 Camera Sensor 、 MIPI CSI 和 SIF 模块初始化,实现从 vin 模块获取视频数据功能,支持从 VIN 模块获取 Raw 或者 YUV 格式图像。

软件架构说明

image-20250110-172641.png

代码位置目录结构

  • 代码位置 app/samples/platform_samples/sample_vin/get_vin_data

  • 目录结构

sample_vin/
└── get_vin_data
    ├── get_vin_data.c
    └── Makefile

API 流程说明

image-20250110-165856.png

3.2.1.2. 编译部署

编译

  • 进入 get_vin_data 目录,执行 make 编译

  • 输出产物是 get_vin_data 源码目录get_vin_data

  • 详细程序编译方式查阅 编译方法 章节

程序部署

刷写系统软件镜像后 , 本 sample 的可执行文件位于板端 : /app/platform_samples/sample_vin/get_vin_data

3.2.1.3. 运行

程序运行方法

  • 执行程序 ./get_vin_data -h 可以获得帮助信息;

  • 执行程序 ./get_vin_data -s 3,以 sc230ai-30fps 为例;

  • 执行程序 ./get_vin_data -s 3 -f 15, 指定 Sensor Index 的同时配置目标为 15;

  • 执行程序即可进入交互模式,详见3.2.3.3.小节运行效果内容。

    注意:示例通过 SIF 硬件实现功能(间接实现改变 sensor 帧率),并且支持初始化阶段运行阶段配置参数:

    1. 命令行-f 参数:展示初始化阶段设置参数;

    2. 交互模式-s 参数:展示运行阶段动态设置参数。

程序参数选项说明

Usage: get_vin_data [OPTIONS]
Options:
  -s <sensor_index>      Specify sensor index
  -m <sensor_mode>       Specify sensor mode of camera_config_t, support 'm' and 's'
                m: Master
                s: Slave
                The default value is determined by the configuration in vp_sensor
  -e <extern_param>          Specify extension parameters through a JSON file
  -f <target_fps>        Specify target output FPS (0 = disable, sensor native)
  -h                     Show this help message
index: 0  sensor_name: sc1330t                  config_file:linear_1280x960_raw10_30fps_1lane.c
index: 1  sensor_name: irs2875-tof              config_file:linear_208x1413_raw12_15fps_2lane.c
index: 2  sensor_name: sc230ai-10fps            config_file:linear_1920x1080_raw10_10fps_1lane.c
index: 3  sensor_name: sc230ai-30fps            config_file:linear_1920x1080_raw10_30fps_1lane.c
index: 4  sensor_name: sc230ai-dol2-30fps       config_file:dol2_1920x1080_raw10_30fps_2lane.c
index: 5  sensor_name: sc132gs-1280p            config_file:linear_1088x1280_raw10_60fps_1lane.c
index: 6  sensor_name: sc132gs-hdr-2lane        config_file:hdr_1088x1280_raw10_30fps_2lane.c
index: 7  sensor_name: sc035hgs                 config_file:linear_640x480_raw10_30fps_1lane.c
index: 8  sensor_name: sc035hgs_mono            config_file:linear_mono_640x480_raw10_30fps_1lane.c
index: 9  sensor_name: ov5640                   config_file:linear_1920x1080_raw10_30fps_2lane.c
index: 10  sensor_name: f37                     config_file:linear_1920x1080_raw10_30fps_1lane.c
index: 11  sensor_name: imx415-30fps-2lane      config_file:linear_3840x2160_raw10_30fps_2lane.c
index: 12  sensor_name: imx415-30fps-4lane      config_file:linear_3840x2160_raw10_30fps_4lane.c
index: 13  sensor_name: sc202cs-1600x1200       config_file:linear_1600x1200_raw10_30fps_1lane.c
index: 14  sensor_name: irs2381c-tof            config_file:linear_224x1903_raw12_5fps_2lane.c
index: 15  sensor_name: sc035hgs-vc0            config_file:linear_640x480_raw10_30fps_2lane_vc0.c
index: 16  sensor_name: sc035hgs-vc1            config_file:linear_640x480_raw10_30fps_2lane_vc1.c
index: 17  sensor_name: sc231ai-30fps           config_file:linear_1920x1080_raw10_30fps_2lane.c
index: 18  sensor_name: imx586-30fps-4lane      config_file:linear_3840x2160_raw10_30fps_4lane.c
index: 19  sensor_name: os08c10-30fps-2lane     config_file:linear_3840x2160_raw12_30fps_2lane.c
index: 20  sensor_name: ar0233-30fps            config_file:linear_1920x1080_raw12_30fps_2lane.c
index: 21  sensor_name: ar0820std-30fps         config_file:linear_3840x2160_yuv422_30fps_4lane.c
index: 22  sensor_name: sc1336                  config_file:linear_1280x720_raw10_15fps_2lane.c
index: 23  sensor_name: dummy                   config_file:dummy_sensor.c
index: 24  sensor_name: ar0233-30fps            config_file:ar0233_linear_1920x1080_raw12_30fps_2lane_vc0.c
index: 25  sensor_name: ar0233-30fps            config_file:ar0233_linear_1920x1080_raw12_30fps_2lane_vc1.c
index: 26  sensor_name: ov9782-200fps-2lane     config_file:linear_640x360_raw10_200fps_2lane.c
index: 27  sensor_name: ov9782-120fps-2lane     config_file:linear_1280x720_raw10_120fps_2lane.c
index: 28  sensor_name: imx219-640x480-30fps    config_file:linear_640x480_raw10_30fps_2lane.c
index: 29  sensor_name: imx219-1632x1232-30fps  config_file:linear_1632x1232_raw10_30fps_2lane.c
index: 30  sensor_name: imx219-1920x1080-30fps  config_file:linear_1920x1080_raw10_30fps_2lane.c
index: 31  sensor_name: imx219-3264x2464-15fps  config_file:linear_3264x2464_raw10_15fps_2lane.c
index: 32  sensor_name: imx219-3264x2464-21fps  config_file:linear_3264x2464_raw10_21fps_2lane.c
index: 33  sensor_name: ov5647-640x480-60fps    config_file:linear_640x480_raw10_60fps_2lane.c
index: 34  sensor_name: ov5647-1280x960-30fps   config_file:linear_1280x960_raw10_30fps_2lane.c
index: 35  sensor_name: ov5647-1920x1080-30fps  config_file:linear_1920x1080_raw10_30fps_2lane.c
index: 36  sensor_name: ov5647-2592x1944-15fps  config_file:linear_2592x1944_raw10_15fps_2lane.c
index: 37  sensor_name: imx678-30fps-4lane      config_file:linear_3840x2160_raw12_30fps_4lane.c
index: 38  sensor_name: imx678-30fps-4lane-dol2 config_file:dol2_3840x2160_raw12_30fps_4lane.c
index: 39  sensor_name: imx477-1280x960-120fps  config_file:linear_1280x960_raw10_120fps_2lane.c
index: 40  sensor_name: imx477-1920x1080-50fps  config_file:linear_1920x1080_raw12_50fps_2lane.c
index: 41  sensor_name: imx477-2016x1520-21fps  config_file:linear_2016x1520_raw12_21fps_2lane.c
index: 42  sensor_name: imx477-4000x3000-10fps  config_file:linear_4000x3000_raw12_10fps_2lane.c
index: 43  sensor_name: ov50h40-30fps-4lane     config_file:linear_4096x3072_raw10_30fps_4lane.c
index: 44  sensor_name: ox05b1s                 config_file:linear_2592x1944_raw10_30fps_4lane.c
index: 45  sensor_name: ox05b1s_2lane           config_file:linear_2592x1944_raw10_10fps_2lane.c
index: 46  sensor_name: imx415-60fps-4lane      config_file:linear_3840x2160_raw10_60fps_4lane.c
index: 47  sensor_name: sc850sl-30fps           config_file:linear_3840x2160_raw10_30fps_4lane.c
index: 48  sensor_name: shw3g-30fps             config_file:linear_2064x1552_raw12_30fps_4lane.c
index: 49  sensor_name: shw3g-30fps_vc1         config_file:linear_2064x1552_raw12_30fps_4lane_vc1.c
index: 50  sensor_name: sc235hai-30fps          config_file:linear_1920x1080_raw10_30fps_2lane.c
index: 51  sensor_name: cv4006-60fps-2lane      config_file:linear_1280x720_raw10_60fps_2lane.c
index: 52  sensor_name: ov50h40-30fps-4lane     config_file:linear_3840x2160_raw10_30fps_4lane.c
index: 53  sensor_name: ov50h40-30fps-4lane     config_file:linear_4096x3072_raw14_30fps_4lane.c
index: 54  sensor_name: sc132gs-slave-right     config_file:linear_1088x1280_raw10_30fps_slave_1lane_right.c
index: 55  sensor_name: sc132gs-slave-left      config_file:linear_1088x1280_raw10_30fps_slave_1lane_left.c
index: 56  sensor_name: sc132gsstd_vc0          config_file:linear_1088x1280_raw10_10fps_1lane_vc0.c
index: 57  sensor_name: sc132gsstd_vc1          config_file:linear_1088x1280_raw10_10fps_1lane_vc1.c
index: 58  sensor_name: sc132gsstd_vc2          config_file:linear_1088x1280_raw10_10fps_1lane_vc2.c
index: 59  sensor_name: sc132gsstd_vc3          config_file:linear_1088x1280_raw10_10fps_1lane_vc3.c
index: 60  sensor_name: imx415-30fps-4lane-dol2 config_file:dol2_3840x2160_raw10_30fps_4lane.c
index: 61  sensor_name: isx031-30fps-vc0        config_file:isx031_linear_1920x1536_yuv422_30fps_4lane_vc0.c
index: 62  sensor_name: isx031-30fps-vc1        config_file:isx031_linear_1920x1536_yuv422_30fps_4lane_vc1.c
index: 63  sensor_name: isx031-30fps-vc2        config_file:isx031_linear_1920x1536_yuv422_30fps_4lane_vc2.c
index: 64  sensor_name: isx031-30fps-vc3        config_file:isx031_linear_1920x1536_yuv422_30fps_4lane_vc3.c

选项:

  • s <sensor_index>: 指定使用的 camera sensor 索引,可多次指定(最多 4 个 sensor)。

  • m <sensor_mode>: 指定 camera sensor 配置传感器模式。

  • e <extern_param>: 指定 Json 格式文件,在 camera sensor 点亮阶段用于快速更改参数, 详细get_vin_data 源码目录如下文件: sensor_param_sample1.json sensor_param_sample2.json sensor_param_sample3.json

  • f <target_fps>: 指定目标输出率,通过 SIF 硬件实现。不配置保持默认率。可配置目标范围是 1 到默认率。比如默认为30fps,则取值范围为 1 至 30。

  • h: 显示帮助信息。

当前支持传感器以及对应配置文件列表:

Index Sensor Name Configuration File
0 sc1330t linear_1280x960_raw10_30fps_1lane.c
1 irs2875-tof linear_208x1413_raw12_15fps_2lane.c
2 sc230ai-10fps linear_1920x1080_raw10_10fps_1lane.c
3 sc230ai-30fps linear_1920x1080_raw10_30fps_1lane.c
4 sc230ai-dol2-30fps dol2_1920x1080_raw10_30fps_2lane.c
5 sc132gs-1280p linear_1088x1280_raw10_60fps_1lane.c
6 sc132gs-hdr-2lane hdr_1088x1280_raw10_30fps_2lane.c
7 sc035hgs linear_640x480_raw10_30fps_1lane.c
8 sc035hgs_mono linear_mono_640x480_raw10_30fps_1lane.c
9 ov5640 linear_1920x1080_raw10_30fps_2lane.c
10 f37 linear_1920x1080_raw10_30fps_1lane.c
11 imx415-30fps-2lane linear_3840x2160_raw10_30fps_2lane.c
12 imx415-30fps-4lane linear_3840x2160_raw10_30fps_4lane.c
13 sc202cs-1600x1200 linear_1600x1200_raw10_30fps_1lane.c
14 irs2381c-tof linear_224x1903_raw12_5fps_2lane.c
15 sc035hgs-vc0 linear_640x480_raw10_30fps_2lane_vc0.c
16 sc035hgs-vc1 linear_640x480_raw10_30fps_2lane_vc1.c
17 sc231ai-30fps linear_1920x1080_raw10_30fps_2lane.c
18 imx586-30fps-4lane linear_3840x2160_raw10_30fps_4lane.c
19 os08c10-30fps-2lane linear_3840x2160_raw12_30fps_2lane.c
20 ar0233-30fps linear_1920x1080_raw12_30fps_2lane.c
21 ar0820std-30fps linear_3840x2160_yuv422_30fps_4lane.c
22 sc1336 linear_1280x720_raw10_15fps_2lane.c
23 dummy dummy_sensor.c
24 ar0233-30fps ar0233_linear_1920x1080_raw12_30fps_2lane_vc0.c
25 ar0233-30fps ar0233_linear_1920x1080_raw12_30fps_2lane_vc1.c
26 ov9782-200fps-2lane linear_640x360_raw10_200fps_2lane.c
27 ov9782-120fps-2lane linear_1280x720_raw10_120fps_2lane.c
28 imx219-640x480-30fps linear_640x480_raw10_30fps_2lane.c
29 imx219-1632x1232-30fps linear_1632x1232_raw10_30fps_2lane.c
30 imx219-1920x1080-30fps linear_1920x1080_raw10_30fps_2lane.c
31 imx219-3264x2464-15fps linear_3264x2464_raw10_15fps_2lane.c
32 imx219-3264x2464-21fps linear_3264x2464_raw10_21fps_2lane.c
33 ov5647-640x480-60fps linear_640x480_raw10_60fps_2lane.c
34 ov5647-1280x960-30fps linear_1280x960_raw10_30fps_2lane.c
35 ov5647-1920x1080-30fps linear_1920x1080_raw10_30fps_2lane.c
36 ov5647-2592x1944-15fps linear_2592x1944_raw10_15fps_2lane.c
37 imx678-30fps-4lane linear_3840x2160_raw12_30fps_4lane.c
38 imx678-30fps-4lane-dol2 dol2_3840x2160_raw12_30fps_4lane.c
39 imx477-1280x960-120fps linear_1280x960_raw10_120fps_2lane.c
40 imx477-1920x1080-50fps linear_1920x1080_raw12_50fps_2lane.c
41 imx477-2016x1520-21fps linear_2016x1520_raw12_21fps_2lane.c
42 imx477-4000x3000-10fps linear_4000x3000_raw12_10fps_2lane.c
43 ov50h40-30fps-4lane linear_4096x3072_raw10_30fps_4lane.c
44 ox05b1s linear_2592x1944_raw10_30fps_4lane.c
45 ox05b1s_2lane linear_2592x1944_raw10_10fps_2lane.c
46 imx415-60fps-4lane linear_3840x2160_raw10_60fps_4lane.c
47 sc850sl-30fps linear_3840x2160_raw10_30fps_4lane.c
48 shw3g-30fps linear_2064x1552_raw12_30fps_4lane.c
49 shw3g-30fps_vc1 linear_2064x1552_raw12_30fps_4lane_vc1.c
50 sc235hai-30fps linear_1920x1080_raw10_30fps_2lane.c
51 cv4006-60fps-2lane linear_1280x720_raw10_60fps_2lane.c
52 ov50h40-30fps-4lane linear_3840x2160_raw10_30fps_4lane.c
53 ov50h40-30fps-4lane linear_4096x3072_raw14_30fps_4lane.c
54 sc132gs-slave-right linear_1088x1280_raw10_30fps_slave_1lane_right.c
55 sc132gs-slave-left linear_1088x1280_raw10_30fps_slave_1lane_left.c
56 sc132gsstd_vc0 linear_1088x1280_raw10_10fps_1lane_vc0.c
57 sc132gsstd_vc1 linear_1088x1280_raw10_10fps_1lane_vc1.c
58 sc132gsstd_vc2 linear_1088x1280_raw10_10fps_1lane_vc2.c
59 sc132gsstd_vc3 linear_1088x1280_raw10_10fps_1lane_vc3.c
60 imx415-30fps-4lane-dol2 dol2_3840x2160_raw10_30fps_4lane.c
61 isx031-30fps-vc0 isx031_linear_1920x1536_yuv422_30fps_4lane_vc0.c
62 isx031-30fps-vc1 isx031_linear_1920x1536_yuv422_30fps_4lane_vc1.c
63 isx031-30fps-vc2 isx031_linear_1920x1536_yuv422_30fps_4lane_vc2.c
64 isx031-30fps-vc3 isx031_linear_1920x1536_yuv422_30fps_4lane_vc3.c

运行效果

单 sensor 模式
  1. 根据提示选择当前连接开发板的 Sensor 名,以 sc230ai-30fps 为例,执行 ./get_vin_data -s 3

  2. 通过 -f <fps> 指定目标输出率,例如 ./get_vin_data -s 3 -f 15 以 15fps 输出。

  3. 执行命令自动加载 sc230ai-30fps 配置文件linear_1920x1080_raw10_30fps_1lane.c对 Camera Sensor、MIPI CSI 和 SIF 模块完成初始化。

  4. 初始化完成后,系统进入用户交互模式,提示符显示各 sensor 的简称当前输出率,例如 Command [sc230ai:30fps]:

执行命令:

cd sample_vin/get_vin_data
chmod +x get_vin_data
./get_vin_data -s 3

运行日志:

  • g: 获取一帧图像,支持输入多个 g 来连续获取图像,例如:输入 gggg ​会获取4张图像。

Using index:3  sensor_name:sc230ai-30fps  config_file:linear_1920x1080_raw10_30fps_1lane.c
mipi mclk is configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@0 i2c bus: 4 mipi rx phy: 0
INFO: Found sensor_name:sc230ai-30fps on mipi rx csi 0, i2c addr 0x30, config_file:linear_1920x1080_raw10_30fps_1lane.c
Not config sensor mode, so use default mode.


***************  Command Lists  ***************
 g      -- get single frame
 l      -- get a set frames
 s      -- set target FPS
 f      -- check frame rate and compare with configured fps
 q      -- quit
 h      -- print help message

Command [sc230ai:30fps]: g
Dumping RAW data: handle 34661, resolution: 1920x1080 (stride: 3840), size: 4147200, frame id: 0, timestamp: 320230295485
Dump image to file(handle_34661_chn0_vc0_1920x1080_stride_3840_frameid_0_ts_320230295485.raw), size(4147200) succeeded
  • l: 连续获取 12 帧图像,相当于输入 12 个 g ​

Command [sc230ai:30fps]: l
Dumping RAW data: handle 34661, resolution: 1920x1080 (stride: 3840), size: 4147200, frame id: 1, timestamp: 46024435294737
Dump image to file(handle_34661_chn0_vc0_1920x1080_stride_3840_frameid_1_ts_46024435294737.raw), size(4147200) succeeded
... ( 省略,总共 Dump 12  ) ...
Dumping RAW data: handle 34661, resolution: 1920x1080 (stride: 3840), size: 4147200, frame id: 424, timestamp: 46038535296244
Dump image to file(handle_34661_chn0_vc0_1920x1080_stride_3840_frameid_424_ts_46038535296244.raw), size(4147200) succeeded
  • f: 计算打印实际率,并判断配置是否正确

Command [sc230ai:30fps]: f

======================== Frame Rate Check =======================
Sensor sc230ai-30fps: Target FPS = 30fps
Statistics (timestamp): Average FPS = 30.25
First frame_id = 130, Last frame_id = 281, Frame count = 152
First timestamp = 116917846862208, Last timestamp = 116922871251586
Sensor sc230ai-30fps: Frame rate check: Success
=================== Frame Rate Check Complete ===================
  • q: 退出程序​

Command: q
quit
多 sensor 模式

-s 参数多次指定,最同时打开 4 个 sensor。-f 作用其前最近-s,每个 sensor 可独立指定率,例如 ./get_vin_data -s 2 -f 5 -s 60 -f 15 将 sensor 2 设为 5fps、sensor 60 设为 15fps。

以下./get_vin_data -s 2 -s 60启动日志,每个 sensor 独立完成 CSI 探测初始化:

Using index:2  sensor_name:sc230ai-10fps  config_file:linear_1920x1080_raw10_10fps_1lane.c
mipi mclk is configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@2 i2c bus: 2 mipi rx phy: 2
INFO: Found sensor_name:sc230ai-10fps on mipi rx csi 2, i2c addr 0x30, config_file:linear_1920x1080_raw10_10fps_1lane.c
Using index:60  sensor_name:imx415-30fps-4lane-dol2  config_file:dol2_3840x2160_raw10_30fps_4lane.c
mipi mclk is configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@0 i2c bus: 4 mipi rx phy: 0
INFO: Found sensor_name:imx415-30fps-4lane-dol2 on mipi rx csi 0, i2c addr 0x1a, config_file:dol2_3840x2160_raw10_30fps_4lane.c
Not config sensor mode, so use default mode.

***************  Command Lists  ***************
 g      -- get single frame
 l      -- get a set frames
 f      -- check frame rate and compare with configured fps
 s      -- set target FPS
 q      -- quit
 h      -- print help message
Command [sc230ai:10fps, imx415:30fps]:
  • g: 对所有 sensor 各获取一帧

Command [sc230ai:10fps, imx415:30fps]: g
Dumping RAW data: handle 34661, resolution: 1920x1080 (stride: 3840), size: 4147200, frame id: 500, timestamp: 36387692251350
Dump image to file(handle_34661_chn0_vc0_1920x1080_stride_3840_frameid_500_ts_36387692251350.raw), size(4147200) succeeded
Dumping RAW data: handle 100197, resolution: 3840x2160 (stride: 7680), size: 16588800, frame id: 1631, timestamp: 36392514268144
Dump image to file(handle_100197_chn0_vc0_3840x2160_stride_7680_frameid_1631_ts_36392514268144.raw), size(16588800) succeeded
  • l: 对所有 sensor 各连续获取 12 帧

Command [sc230ai:10fps, imx415:30fps]: l
Dumping RAW data: handle 34661, resolution: 1920x1080 (stride: 3840), size: 4147200, frame id: 504, timestamp: 36388092014976
Dump image to file(handle_34661_chn0_vc0_1920x1080_stride_3840_frameid_504_ts_36388092014976.raw), size(4147200) succeeded
Dumping RAW data: handle 100197, resolution: 3840x2160 (stride: 7680), size: 16588800, frame id: 1633, timestamp: 36392580945394
Dump image to file(handle_100197_chn0_vc0_3840x2160_stride_7680_frameid_1633_ts_36392580945394.raw), size(16588800) succeeded
... ( 省略,每个 sensor  Dump 12  ) ...
  • f: 对所有 sensor 逐帧检查,sensor 之间--- 分隔

Command [sc230ai:10fps, imx415:30fps]: f

======================== Frame Rate Check =======================
Sensor sc230ai-10fps: Target FPS = 10fps
Statistics (timestamp): Average FPS = 10.20
First frame_id = 191, Last frame_id = 242, Frame count = 52
First timestamp = 117070885035740, Last timestamp = 117075982024326
Sensor sc230ai-10fps: Frame rate check: Success
=================== Frame Rate Check Complete ===================

======================== Frame Rate Check =======================
Sensor imx415-30fps-4lane-dol2: Target FPS = 30fps
Statistics (timestamp): Average FPS = 30.20
First frame_id = 714, Last frame_id = 864, Frame count = 151
First timestamp = 117076018166701, Last timestamp = 117081018969245
Sensor imx415-30fps-4lane-dol2: Frame rate check: Success
=================== Frame Rate Check Complete ===================
  • s: 多 sensor 模式下先输入 sensor 索引,再输入目标

Command [sc230ai:10fps, imx415:30fps]: s

Enter sensor index (0..1): 0
Enter target FPS (0 = disable skip, restore native): 7
[FPS] Sensor[sc230ai] 10 -> 7 fps
Use 'f' to check frame rate
Command [sc230ai:7fps, imx415:30fps]: s

Enter sensor index (0..1): 1
Enter target FPS (0 = disable skip, restore native): 15
[FPS] Sensor[imx415] 30 -> 15 fps
Use 'f' to check frame rate

运行效果说明

执行程序获取如 handle_34661_chn0_vc0_1920x1080_stride_3840_frameid_424_ts_46038535296244.raw 命名格式的 Raw 图像。

参考 Hobot player 静态图片章节浏览图像,图像参数配置说明如下:

  • 浏览 RAW 图

按照如下所示步骤配置选项,其中 file config 里面关注 pic_type 、 raw_type 、 pix_length 、 width 和 height 的配置, sc1330t 配置为( PIC_RAW、 UNPACKET_RAW、 RAW_MIPI_BIT_10 , 1920 , 1080 )

image-20250110-195428.png

3.2.1.4. 常见问题

1. 显示 No Camera Sensor found

  • 原因分析:

    1. 开发板实际连接 camera 型号./get_vin_data -s 指定的 camera 不匹配。

    2. FPC 线缆接触不良、接口松动导致测试异常。

  • 解决方法:

    1. 确保实际连接的 camera 和./get_vin_data -s 指定的 camera 匹配。

    2. 检查 FPC 线缆连接,确保接口稳定连接。

3.2.2. time_synchronization

3.2.2.1. 功能概述

time_synchronization ⽤于演⽰ camera 与其他外设进⾏时间同步功能

  1. camera 的时间通过 SIF 模块设置的,通过结构hbn_frame_info_t 可以拿到 camera的时间

  2. hbn_frame_info_t 中有4个时间戳,描述如下:

含义 来源 受 NTP 影响
timestamps SIF frame start 中断内核时间戳,从系统启动计时 ktime_get_raw_ns()
sys_timestamps SIF frame start 中断墙上时间(Unix 纳秒) ktime_get_real_ns()
tv SIF frame start 时刻,SIF锁存硬件时间戳。 SIF IPI_TS_VSYNC 寄存器
trig_tv LPWM 上升沿时刻, SIF 锁存硬件时间 SIF IPI_TS_TRIG 寄存器

时间配置相关结构vin_node_attr.cim_attr.func参数如下:

说明
enable_frame_id 是否使能 frame_id,使能getframe 才能拿到 frame_id
time_stamp_en 是否使能 SIF 硬件时间戳,使能trig_tv/tv有值;不影响 timestamps/sys_timestamps
time_stamp_mode SIF 锁存类型,位掩码组合:0x01=VSYNC(锁存 tv)、0x02=TRIGGER(锁存 trig_tv)、0x03=两者锁存(推荐)
ts_src 触发 SIF 锁存源,1-8 对应 LPWM0/1 各 channel,需硬件触发曝光的 LPWM 连接一致

其他传感器时间同步方法:

  1. 其他传感器可以使用 ktime_get_raw_ns 或 ktime_get_real_ns 获取时间

  2. camera 选择其他传感器相同时间基准时间进行运算

注意:如果 camera 选择 LPWM 时刻时间戳,需要进行如下运算
通过 timestamps - (tv - trig_tv) 获取 以 timestamps 为基准的 曝光时刻时间

要点:

  • timestamps 是 从系统启动计时 的 raw monotonic,不受 NTP 频率调整,适合作为用户稳定同步基准。

  • sys_timestamps墙上时间,受 NTP 调整可能跳变,建议 用作同步基准,仅适合日志/审计设备对齐场景。

  • trig_tv:LPWM 触发脉冲边沿到达 SIF 时刻锁存(脉冲同时分两路:一路送 sensor 触发曝光,一路送 SIF 做时间锁存,trig_tv 标记后者到达 SIF 的时刻,不等于 sensor 实际开始曝光时刻)。

  • tv:MIPI VSYNC(帧起始信号)边沿到达 SIF 时刻锁存,SIF frame start 中断寄存器读出。

    • 两者由 AON RTC(Always-On 域硬件计数器,24M 晶振驱动)在信号边沿硬件存进寄存器;frame start 中断软件寄存器读出原始 tick,再timestamp_clk 转换tv_sec/tv_usec(精度 1 us)填入 buffer。不受 NTP 影响。

    • tv - trig_tv 即”LPWM 触发脉冲到达”到”MIPI 帧起始信号到达”的固有时延(含 sensor 曝光+读出+MIPI 传输)。

软件架构说明

screenshot-20260728-211011.png

代码位置目录结构

  • 代码位置:app/samples/platform_samples/sample_vin/time_synchronization

  • 目录结构

app/samples/platform_samples/sample_vin/time_synchronization/
└── time_synchronization
    ├── Makefile
    ├── time_synchronization.c

API 流程说明

time_synchronization 基于 VIN pipeline 实现,主要流程如下:

  1. 解析命令行参数,校验 sensor 模式(支持 -m 指定 master/slave,未指定时用 sensor 配置默认模式)。

  2. auto_fill_ts_src设备树读取 lpwm_chn,设置 ts_src/time_stamp_en/time_stamp_mode(SLAVE 模式锁存 tv+trig_tv,非 SLAVE 仅锁存 tv)。

  3. 创建 VIN pipeline(hbn_camera_create / hbn_vnode_* / hbn_vflow_*),SLAVE 模式开启 LPWM。

  4. hbn_vnode_getframe()一帧,读取四个时间戳。

  5. 打印四个时间戳值、时钟说明曝光→mipi 时延(tv - trig_tv)。

  6. hbn_vnode_releaseframe() 释放帧;退出释放 VIN 资源。

screenshot-20260728-210940.png

3.2.2.2. 编译部署

编译

  • 进入 time_synchronization 目录,执行 make 编译

  • 输出产物源码目录time_synchronization

  • 详细程序编译方式查阅 编译方法 章节

程序部署

刷写系统软件镜像后,本 sample 的可执行文件位于板端:/app/platform_samples/sample_vin/time_synchronization

sensor 索引通过 -h 参数查看列表,需选择板子实际接入的 sensor,如 sc230ai-10fps 对应索引 2。

3.2.2.3. 运行

程序运行方法

./time_synchronization -s 2 -m s

程序启动进入交互式命令菜单,按 g 抓单帧、l 连续抓 12 帧、q 退出、h 显示帮助。

程序参数选项说明

./time_synchronization [-s <index> -m <m|s>] [-h]
  • -s <index>(必填):sensor 索引,通过 -h 查看列表

  • m <m|s> (选填): sensor 模式

  • -h:显示帮助

交互命令:

命令 说明
g 抓取单帧并打印四个时间
l 连续抓取 12 帧并打印时间
q 退出程序
h 显示命令帮助

运行效果

Sensor index=2  name=sc230ai-10fps  config=linear_1920x1080_raw10_10fps_1lane.c
[INFO] RDK board_id is 0x0503, so skip csi test for index 1 and index 3
mipi mclk is not configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@0 i2c bus: 6 mipi rx phy: 0
INFO: Found sensor_name:sc230ai-10fps on mipi rx csi 0, i2c addr 0x30, config_file:linear_1920x1080_raw10_10fps_1lane.c
Sensor mode: SLAVE_M
vcon@0: lpwm_chn=4 -> ts_src=5, time_stamp_en=1, mode=0x03
csi0: no mclk configured, skip mclk attr.

***************  Command Lists  ***************
 g  -- grab one frame and print four timestamps
 l  -- grab 12 frames and print timestamps
 q  -- quit
 h  -- this help

Command: g
frame_id=0       1920x1080 stride=3840
  timestamps       = 336060994951 ns  (raw monotonic, ktime_get_raw_ns; NOT NTP-adjusted)
  sys_timestamps    = 946705156915582076 ns  (realtime, ktime_get_real_ns; wall clock, NTP-adjusted)
  trig_tv           = 342.216467 s  -> 342216467000 ns  (AON RTC, exposure trigger)
  tv                = 342.216618 s  -> 342216618000 ns  (AON RTC, frame start)
  exposure->mipi duration (tv - trig_tv)    = +151000 ns = +151.000 us
......

说明:

  • timestamps:SIF frame start 中断的 raw monotonic 时间戳(ns),从系统启动计时,不受 NTP 调整

  • sys_timestamps:SIF frame start 中断的 realtime 时间戳(ns),墙上时间,受 NTP 调整可能跳变

  • trig_tv:LPWM 触发脉冲到达 SIF 时刻锁存的 AON RTC 硬件时间戳(ns)

  • tv:MIPI VSYNC(帧起始信号)到达 SIF 时刻锁存的 AON RTC 硬件时间戳(ns)

  • exposure->mipi duration (tv - trig_tv): 即”LPWM 触发脉冲到达”到”MIPI 帧起始信号到达”的固有时延(含 sensor 曝光+读出+MIPI 传输)

3.2.2.4. 常见问题

1. trig_tv 为

  • 确认 time_stamp_en=1time_stamp_mode对应位(0x02 锁存 trig_tv、0x01 锁存 tv、0x03 两者锁存)。

  • 确认 ts_src硬件触发曝光的 LPWM 通道一致(示例自动设备树 lpwm_chn 推导,若为 0 说明设备树配置)。

  • 确认 sensor 处于 SLAVE 模式(master 模式无 LPWM 触发,trig_tv 恒为 0)。