Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit cbe0cfa

Browse files
committed
usb camera
1 parent 5bb3979 commit cbe0cfa

11 files changed

+586
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
NO.|文件名称|摘要
1010
:--:|:--|:--
11+
0013| [开机自动发IP信息邮件](docs/0013_开机自动发IP信息邮件.md) | Python3自动发邮件
12+
0012| [dtparam_dtoverlay_DTS动态设备树](docs/0012_dtparam_dtoverlay_DTS动态设备树.md) | 分析dtparam/dtoverlay本质,为什么能够动态改变设备与驱动的match
13+
0011| [SoC设备树DTS分析](docs/0011_SoC设备树DTS分析.md) | 怎么分析芯片设备树
14+
0010| [Tmux_Vim_Ctags_Cscope代码分析](docs/0010_Tmux_Vim_Ctags_Cscope代码分析.md) | 在Linux命令行如何阅读代码?
15+
0009| [USB摄像头搭建IP网络摄像头](docs/0009_USB摄像头搭建IP网络摄像头.md) | 使用USB Camera搭建IP Camera,理解IP Camera工作原理
1116
0008| [USB摄像头分析udev加载驱动原理](docs/0008_USB摄像头分析udev加载驱动原理.md) | 使用USB Camera分析udev加载驱动原理,理解udev工作原理
1217
0007| [Systemd进程启动](docs/0007_Systemd进程启动.md) | 分析Linux系统进程何启动起来
1318
0006| [搭建samba服务端](docs/0006_搭建samba服务端.md) | 像访问普通文件夹一样访问树莓派文件系统
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# USB摄像头搭建IP网络摄像头
2+
3+
使用USB Camera搭建IP Camera,理解IP Camera工作原理
4+
5+
## 参考文档
6+
7+
* [利用flask将opencv实时视频流输出到浏览器](https://www.cnblogs.com/arkenstone/p/7159615.html)
8+
* [使用 multipart/x-mixed-replace 实现 http 实时视频流](https://segmentfault.com/a/1190000018563132)
9+
10+
## 简述
11+
12+
从USB摄像头获取视频帧(一张图片),将视频帧传输到客户端(浏览器),这里有很多成熟的传输技术,包括:HLS、RTSP、RTMP等。这些技术有一定的复杂性,各自有其适用场景,如果业务场景对实时性、性能没有太高要求,那显得有点牛刀杀鸡了。我们选择http的multipart类型,这是一个简单的方案,我们主要是理解架构:
13+
14+
![0009_USB_Camera_to_IP_WebCamera.png](images/0009_USB_Camera_to_IP_WebCamera.png)
15+
16+
## IP Camera实践
17+
18+
* cat /etc/pip.conf
19+
```
20+
[global]
21+
timeout = 600
22+
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
23+
extra-index-url = https://pypi.tuna.tsinghua.edu.cn/simple
24+
```
25+
* sudo pip3 install flask
26+
* Flask是一个使用Python编写的轻量级Web应用程序框架。
27+
* sudo apt-get install cmake
28+
* sudo pip3 install opencv-python
29+
* 安装时间挺长,挺住,编译源代码的时候好像只用了一个核,所以很慢,我这边安装了差不多一个半小时;
30+
* 可以通过top命令查看情况
31+
* https://github.com/LowLevelOfLogic/RaspberryPi/tree/IP_Camera
32+
* [OpenCV人脸识别模型haarcascade_frontalface_alt.xml,模型来自这里](https://github.com/TimeIvyace/OpenCV-PCA-KNN-SVM_face_recognition)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Tmux Vim Ctags Cscope代码分析
2+
3+
在Linux命令行如何阅读代码?
4+
5+
## 参考文档
6+
7+
* http://cscope.sourceforge.net/cscope_maps.vim
8+
* [How to let cscope use absolute path in cscope.out file?](https://stackoverrun.com/cn/q/450057)
9+
10+
## Tmux分屏
11+
12+
* cat ~/.tmux.conf
13+
```
14+
set -g default-terminal "screen-256color"
15+
set -g history-limit 10000
16+
17+
# Easy config reload
18+
bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
19+
bind C-a source-file ~/.tmux/layout/mylayout \; display-message "tmux.conf reloaded"
20+
21+
# Use Alt-arrow keys to switch panes
22+
unbind-key j
23+
bind-key j select-pane -D
24+
unbind-key k
25+
bind-key k select-pane -U
26+
unbind-key h
27+
bind-key h select-pane -L
28+
unbind-key l
29+
bind-key l select-pane -R
30+
31+
unbind '"'
32+
bind - splitw -v -c '#{pane_current_path}' # 垂直方向新增面板,默认进入当前目录
33+
unbind %
34+
bind | splitw -h -c '#{pane_current_path}' # 水平方向新增面板,默认进入当前目录
35+
```
36+
37+
## Vim Ctags
38+
39+
* sudo apt-get install vim universal-ctags
40+
* make ARCH=arm tags
41+
* 要等得挺久才行
42+
* cat ~/.vimrc
43+
```
44+
set mouse-=a
45+
46+
syntax on
47+
set hlsearch
48+
hi Search ctermbg=white
49+
hi Search ctermfg=black
50+
51+
set tabstop=4
52+
set shiftwidth=4
53+
"set expandtab
54+
55+
set tags+=/home/pi/zengjf/linux-rpi-5.4.y/tags
56+
```
57+
58+
## Vim Cscope
59+
60+
* sudo apt-get install cscope
61+
* make ARCH=arm cscope
62+
* ls cscope*
63+
* cat ~/.vimrc
64+
```
65+
set mouse-=a
66+
syntax on
67+
set hlsearch
68+
hi Search ctermbg=white
69+
hi Search ctermfg=black
70+
71+
set tags+=/home/pi/zengjf/linux-rpi-5.4.y/tags
72+
73+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
74+
" cscope setting
75+
76+
if has("cscope")
77+
set csprg=/usr/bin/cscope
78+
set csto=1
79+
set cst
80+
set nocsverb
81+
" add any database in current directory
82+
" if filereadable("cscope.out")
83+
" cs add cscope.out
84+
" endif
85+
cs add /home/pi/zengjf/helloworld/cscope.out /home/pi/zengjf/helloworld
86+
cs add /home/pi/zengjf/linux-rpi-5.4.y/cscope.out /home/pi/zengjf/linux-rpi-5.4.y
87+
set csverb
88+
endif
89+
90+
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
91+
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
92+
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
93+
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
94+
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
95+
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
96+
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
97+
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
98+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
99+
```
100+
* s: 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
101+
* g: 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
102+
* d: 查找本函数调用的函数
103+
* c: 查找调用本函数的函数
104+
* t: 查找指定的字符串
105+
* e: 查找egrep模式,相当于egrep功能,但查找速度快多了
106+
* f: 查找并打开文件,类似vim的find功能
107+
* i: 查找包含本文件的文

docs/0011_SoC设备树DTS分析.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# SoC设备树DTS分析
2+
3+
怎么分析芯片设备树
4+
5+
## 配置bash环境变量
6+
7+
* tail ~/.bashrc
8+
```
9+
# ...省略
10+
11+
LINUX_SRC=/home/pi/zengjf/linux-rpi-5.4.y
12+
alias kernel="cd ${LINUX_SRC}"
13+
alias dts="cd ${LINUX_SRC}/arch/arm/boot/dts"
14+
```
15+
* 便于代码目录跳转
16+
17+
## SoC Datasheet
18+
19+
* [Raspberry Pi 4 B Datasheets](https://www.raspberrypi.org/documentation/hardware/raspberrypi/datasheets.md)
20+
* [rpi_DATA_2711_1p0.pdf](refers/datasheet/rpi_DATA_2711_1p0.pdf)
21+
22+
# GPIO UART I2C DTS分析
23+
24+
* arch/arm/boot/dts/bcm2711-rpi-4-b.dts
25+
```
26+
* arch/arm/boot/dts # dts目录
27+
* bcm2711-rpi-4-b.dts # 一般是产品的名字称,包含整个产品控制器的描述
28+
* #include "bcm2711.dtsi" # 一般是芯片的名称,包含基本芯片的控制器的基本描述
29+
* #include "bcm283x.dtsi" # 芯片是在原来芯片基础上设计的,继承原先的基础配置
30+
* gpio # pin脚复用配置
31+
* uart0 ~ 1
32+
* i2c0if
33+
* i2c1
34+
* uart2 ~ 5
35+
* i2c3 ~ 6
36+
```
37+
* Chapter 3. BSC
38+
* i2c
39+
* Chapter 5. General Purpose I/O (GPIO)
40+
* gpio
41+
* Chapter 11. UART
42+
* uart
43+
44+
## DTS如何关联Driver
45+
46+
* arch/arm/boot/dts/bcm2711-rpi-4-b.dts
47+
```
48+
* arch/arm/boot/dts # dts目录
49+
* bcm2711-rpi-4-b.dts # dts文件
50+
* i2c3: i2c@7e205600 # i2c3控制器
51+
* compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; # 控制器与驱动match字段
52+
* cd drivers/i2c # 查找i2c驱动目录
53+
* ack brcm,bcm2711-i2c # 查找match字段
54+
* busses/i2c-bcm2835.c # 驱动文件
55+
* { .compatible = "brcm,bcm2711-i2c" }, # 驱动match字段
56+
```
57+
* of: Open Firmware
58+
59+
## Device Driver match
60+
61+
* 打印probe内核调用栈:
62+
```diff
63+
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
64+
index 9f4f496..792f20e 100644
65+
--- a/drivers/i2c/busses/i2c-bcm2835.c
66+
+++ b/drivers/i2c/busses/i2c-bcm2835.c
67+
@@ -517,6 +517,8 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
68+
struct clk *mclk;
69+
u32 bus_clk_rate;
70+
71+
+ dump_stack();
72+
+
73+
i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
74+
if (!i2c_dev)
75+
return -ENOMEM;
76+
```
77+
* KERNEL=kernel7l
78+
* make -j4 zImage modules dtbs
79+
```
80+
CALL scripts/atomic/check-atomics.sh
81+
CALL scripts/checksyscalls.sh
82+
CHK include/generated/compile.h
83+
CC [M] drivers/i2c/busses/i2c-bcm2835.o
84+
Kernel: arch/arm/boot/Image is ready
85+
Building modules, stage 2.
86+
MODPOST 1626 modules
87+
Kernel: arch/arm/boot/zImage is ready
88+
CC [M] drivers/i2c/busses/i2c-bcm2835.mod.o
89+
LD [M] drivers/i2c/busses/i2c-bcm2835.ko
90+
```
91+
* uname -a
92+
```
93+
Linux raspberrypi 5.4.83-v7l #1 SMP Wed Feb 10 09:33:55 GMT 2021 armv7l GNU/Linux
94+
```
95+
* sudo cp drivers/i2c/busses/i2c-bcm2835.ko /lib/modules/5.4.83-v7l/kernel/drivers/i2c/busses/i2c-bcm2835.ko
96+
* sudo raspi-config
97+
* i2c
98+
* vim /boot/config.txt
99+
* dtparam=i2c_arm=on
100+
* dmesg
101+
```
102+
...省略
103+
[ 287.688821] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/i2c@7e804000/status
104+
[ 287.730053] CPU: 1 PID: 787 Comm: systemd-udevd Tainted: G C 5.4.83-v7l #1
105+
[ 287.730060] Hardware name: BCM2711
106+
[ 287.730063] Backtrace:
107+
[ 287.730080] [<c020dfb0>] (dump_backtrace) from [<c020e330>] (show_stack+0x20/0x24)
108+
[ 287.730086] r7:ffffffff r6:00000000 r5:a0000013 r4:c129fab0
109+
[ 287.730095] [<c020e310>] (show_stack) from [<c0a76c34>] (dump_stack+0xd8/0x11c)
110+
[ 287.730113] [<c0a76b5c>] (dump_stack) from [<bf36a9b4>] (bcm2835_i2c_probe+0x34/0x388 [i2c_bcm2835])
111+
[ 287.730118] r10:00000000 r9:00000023 r8:c1204fc8 r7:d6a05e00 r6:d6a05e10 r5:00000000
112+
[ 287.730122] r4:d6a05e10 r3:cbd15570
113+
[ 287.730133] [<bf36a980>] (bcm2835_i2c_probe [i2c_bcm2835]) from [<c07969ec>] (platform_drv_probe+0x58/0xa8)
114+
[ 287.730138] r9:00000023 r8:bf36c014 r7:00000000 r6:bf36c014 r5:00000000 r4:d6a05e10
115+
[ 287.730145] [<c0796994>] (platform_drv_probe) from [<c07949c0>] (really_probe+0x1f0/0x354)
116+
[ 287.730150] r7:00000000 r6:c13616b4 r5:d6a05e10 r4:c13616b0
117+
[ 287.730156] [<c07947d0>] (really_probe) from [<c0794d1c>] (driver_probe_device+0x70/0x184)
118+
[ 287.730161] r10:c1204fc8 r9:d5a8ff30 r8:bf36c080 r7:c0795028 r6:bf36c014 r5:bf36c014
119+
[ 287.730164] r4:d6a05e10 r3:00000000
120+
[ 287.730171] [<c0794cac>] (driver_probe_device) from [<c0795020>] (device_driver_attach+0x68/0x70)
121+
[ 287.730176] r9:d5a8ff30 r8:bf36c080 r7:c0795028 r6:bf36c014 r5:00000000 r4:d6a05e10
122+
[ 287.730182] [<c0794fb8>] (device_driver_attach) from [<c0795090>] (__driver_attach+0x68/0xdc)
123+
[ 287.730187] r7:c0795028 r6:d6a05e10 r5:bf36c014 r4:00000000
124+
[ 287.730193] [<c0795028>] (__driver_attach) from [<c07929c8>] (bus_for_each_dev+0x84/0xc4)
125+
[ 287.730197] r7:c0795028 r6:bf36c014 r5:c1204fc8 r4:d5943db4
126+
[ 287.730203] [<c0792944>] (bus_for_each_dev) from [<c0794218>] (driver_attach+0x2c/0x30)
127+
[ 287.730207] r7:00000000 r6:d736ae80 r5:c12713b8 r4:bf36c014
128+
[ 287.730214] [<c07941ec>] (driver_attach) from [<c0793c30>] (bus_add_driver+0x1c8/0x1e8)
129+
[ 287.730220] [<c0793a68>] (bus_add_driver) from [<c079574c>] (driver_register+0x84/0x118)
130+
[ 287.730224] r7:00000000 r6:d60a2d00 r5:bf077000 r4:bf36c014
131+
[ 287.730231] [<c07956c8>] (driver_register) from [<c0796940>] (__platform_driver_register+0x50/0x58)
132+
[ 287.730234] r5:bf077000 r4:c1204fc8
133+
[ 287.730244] [<c07968f0>] (__platform_driver_register) from [<bf077028>] (bcm2835_i2c_driver_init+0x28/0x1000 [i2c_bcm2835])
134+
[ 287.730252] [<bf077000>] (bcm2835_i2c_driver_init [i2c_bcm2835]) from [<c02030c4>] (do_one_initcall+0x50/0x25c)
135+
[ 287.730260] [<c0203074>] (do_one_initcall) from [<c02c28fc>] (do_init_module+0x70/0x264)
136+
[ 287.730265] r8:bf36c080 r7:d60a2d40 r6:d60a2d00 r5:d60a2740 r4:bf36c080
137+
[ 287.730271] [<c02c288c>] (do_init_module) from [<c02c4f58>] (load_module+0x236c/0x2670)
138+
[ 287.730274] r6:d60a2d00 r5:00000002 r4:00000002
139+
[ 287.730280] [<c02c2bec>] (load_module) from [<c02c54c0>] (sys_finit_module+0xd4/0xec)
140+
[ 287.730285] r10:0000017b r9:d5a8e000 r8:c02011c4 r7:00000006 r6:b6e2f8e0 r5:00000000
141+
[ 287.730288] r4:c1204fc8
142+
[ 287.730294] [<c02c53ec>] (sys_finit_module) from [<c02011a4>] (__sys_trace_return+0x0/0x1c)
143+
[ 287.730298] Exception stack(0xd5a8ffa8 to 0xd5a8fff0)
144+
[ 287.730303] ffa0: fdfcc000 00e13b90 00000006 b6e2f8e0 00000000 b6e303f4
145+
[ 287.730308] ffc0: fdfcc000 00e13b90 00000000 0000017b 00e1ee40 0049b1dc 00e49ca0 00000000
146+
[ 287.730312] ffe0: bebbd228 bebbd218 b6e269d8 b6f16af0
147+
[ 287.730316] r7:0000017b r6:00000000 r5:00e13b90 r4:fdfcc000
148+
```

0 commit comments

Comments
 (0)