Merge remote-tracking branch 'upstream/master' into BranchName
|
@ -2,10 +2,4 @@
|
|||
|
||||
---
|
||||
|
||||
* [开发板](/doc/appdev/board)
|
||||
|
||||
* [开发环境](/doc/appdev/env.md)
|
||||
|
||||
* [调试工具](/doc/appdev/debug.md)
|
||||
|
||||
* [开发过程](/doc/appdev/dev.md)
|
||||
* [从零开始构建矽璓工业物联操作系统](/doc/appdev/start_from_scratch)
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# 开发板
|
||||
|
||||
---
|
||||
|
||||
## ARM
|
||||
|
||||
* [STM32F407-ST-DISCOVERY](/doc/appdev/board/stm32f407-st-discovery.md)
|
||||
|
||||
* [STM32F407ZGT6](/doc/appdev/board/stm32f407zgt6.md)
|
||||
|
||||
## RISC-V
|
||||
|
||||
* [HIFIVE1-REV-B](/doc/appdev/board/hifive1-rev.md)
|
||||
|
||||
* [MAXGO](/doc/appdev/board/maxgo.md)
|
||||
|
||||
* [KD233](/doc/appdev/board/kd233.md)
|
||||
|
||||
* [Nexys_A7-100T](/doc/appdev/board/nexys.md)
|
|
@ -1,45 +0,0 @@
|
|||
# RISC-V HIFIVE1-REV-B
|
||||
|
||||
## 综述
|
||||
<div class ="tablebox_hifive">
|
||||
<div class="hifive1-rev-b-box">
|
||||
<img src="https://images.prismic.io/sifive/ddef5160-1769-4d8a-9332-99729088aff6_hifive-rev-b-home-page-new.jpg" alt="hifive1-rev-b"/>
|
||||
</div>
|
||||
<center>HIFIVE1-REV-B</center>
|
||||
<span>XiUOS最新分支支持IFIVE1-REV-B开发板,该开发板作为一种标准的板子,支持各种上层组件和应用程序。</span>
|
||||
</div>
|
||||
|
||||
## 硬件特点
|
||||
+ Microcontroller: FE310-G002
|
||||
+ Operating Voltage: 3.3 V and 1.8 V
|
||||
+ Input Voltage: 5 V USB or 7-12 VDC Jack
|
||||
+ IO Voltage: 3.3 V
|
||||
+ Digital I/O Pins: 19
|
||||
+ PWM Pins: 9
|
||||
+ SPI Controllers/HW CS Pins: 1/3
|
||||
+ UART: 2
|
||||
+ I<sup>2</sup>C: 1
|
||||
+ Networking: WiFi/BT (off-chip)
|
||||
+ External Interrupt Pins: 19
|
||||
+ External Wakeup Pins: 1
|
||||
+ Flash Memory: 32 Mbit Off-Chip (ISSI SPI Flash)
|
||||
+ Host Interface (microUSB): Program, Debug, and Serial Communication
|
||||
+ Debug: Segger J-Link, drag/drop code download
|
||||
+ Weight: 22 g
|
||||
|
||||
### 更多信息[查看网址](https://www.sifive.com/boards/hifive1-rev-b)
|
||||
|
||||
## 支持的功能
|
||||
|
||||
## 编程与调试
|
||||
针对<u>**HIFIVE1-REV-B**</u>开发板的配置和刷新信息,详见[开发环境构建](/environment/debug.html)
|
||||
|
||||
<style>
|
||||
.hifive1-rev-b-box{
|
||||
width: 1500px;
|
||||
height: 400px;
|
||||
vertical-align: middle;
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
Before Width: | Height: | Size: 2.0 MiB |
Before Width: | Height: | Size: 131 KiB |
Before Width: | Height: | Size: 693 KiB |
|
@ -1,53 +0,0 @@
|
|||
# RISC-V KD233
|
||||
## 综述
|
||||
|
||||
<img src="./imagesrc/kd233.png" />
|
||||
|
||||
<center>
|
||||
<span>XiUOS最新分支支持KD233开发板,该开发板作为一种标准的板子,支持各种上层组件和应用程序。</span>
|
||||
</center>
|
||||
|
||||
## 硬件特点
|
||||
+ 性能
|
||||
+ 中央处理器:RISC-V Dual Core 64bit, with FPU
|
||||
+ 图像识别:QVGA@60fps/VG@30fps
|
||||
+ 语音识别:麦克风阵列(8 mics)
|
||||
+ 安全
|
||||
+ 高级加密硬件加速器(AES)
|
||||
+ 一次性只读存储器(OTP)SHA256
|
||||
+ 功耗
|
||||
+ 典型应用场景功耗 < 1W
|
||||
+ 芯片功耗 < 300mW
|
||||
+ 扩展性
|
||||
+ 操作系统:FreeRTOS
|
||||
+ 网络模型:TinyYOLOv2(after pruned)
|
||||
+ 深度学习框架:TensorFlow/Keras/Darknet
|
||||
+ 外设:FPIOA、UART、GPIO、SPI、I<sup>2</sup>C、I<sup>2</sup>S、WDT、TIMER、RTC等等
|
||||
### 更多信息
|
||||
+ [KD233](https://canaan-creative.com/product/kendryteai)
|
||||
|
||||
## 支持的功能
|
||||
| 名称 | 控制器 | 驱动描述 |
|
||||
| ---- | ---- | ---- |
|
||||
| <center>AUDIO</center> | on-chip | audio音频控制 |
|
||||
| <center>CAMERA</center> | on-chip | camera驱动控制 |
|
||||
| <center>DMA</center> | on-chip | dma驱动控制 |
|
||||
| <center>FFT</center> | on-chip | 快速傅里叶变换 |
|
||||
| <center>GPIO</center> | on-chip | gpio 输入输出控制 |
|
||||
| <center>I<sup>2</sup>C</center> | on-chip | i<sup>2</sup>c总线 |
|
||||
| <center>I<sup>2</sup>S</center> | on-chip | i<sup>2</sup>s总线 |
|
||||
| <center>KPU</center> | on-chip | kpu计算架构 |
|
||||
| <center>LCD</center> | on-chip | lcd 液晶显示器控制 |
|
||||
| <center>PLIC</center> | on-chip | 中断控制 |
|
||||
| <center>PWM</center> | on-chip | pwm驱动控制 |
|
||||
| <center>RTC</center> | on-chip | rtc实时时钟驱动控制 |
|
||||
| <center>SECURITY</center> | on-chip | 安全 |
|
||||
| <center>SPI</center> | on-chip | spi总线驱动控制 |
|
||||
| <center>SYS_CLOCK</center> | on-chip | 系统时钟控制 |
|
||||
| <center>TIMER</center> | on-chip | timer重置和计时控制 |
|
||||
| <center>UART</center> | on-chip | uart串口驱动控制 |
|
||||
| <center>VIDEO</center> | on-chip | video视频控制器驱动 |
|
||||
| <center>WATCHDOG</center> | on-chip | watchdog看门狗控制 |
|
||||
|
||||
## 编程与调试
|
||||
针对<u>**KD233**</u>开发板的配置和刷新信息,详见[开发环境构建](/environment/bianyi.html)
|
|
@ -1,46 +0,0 @@
|
|||
# RISC-V MAXGO
|
||||
## 综述
|
||||
|
||||
<center>
|
||||
<img src="./imagesrc/maxgo1.png" alt="maxgo"/>
|
||||
<p>MAXGO</p>
|
||||
</center>
|
||||
|
||||
<span>XiUOS最新分支支持MAXGO开发板,该开发板作为一种标准的板子,支持各种上层组件和应用程序。</span>
|
||||
|
||||
|
||||
## 硬件特点
|
||||
+ 性能
|
||||
+ 中央处理器:RISC-V Dual Core 64bit, with FPU
|
||||
+ 图像识别:QVGA@60fps/VG@30fps
|
||||
+ 语音识别:麦克风阵列(8 mics)
|
||||
+ 安全
|
||||
+ 高级加密硬件加速器(AES)
|
||||
+ 一次性只读存储器(OTP)SHA256
|
||||
+ 功耗
|
||||
+ 典型应用场景功耗 < 1W
|
||||
+ 芯片功耗 < 300mW
|
||||
+ 扩展性
|
||||
+ 操作系统:FreeRTOS
|
||||
+ 网络模型:TinyYOLOv2(after pruned)
|
||||
+ 深度学习框架:TensorFlow/Keras/Darknet
|
||||
+ 外设:FPIOA、UART、GPIO、SPI、I<sup>2</sup>C、I<sup>2</sup>S、WDT、TIMER、RTC等等
|
||||
### 更多信息
|
||||
+ [KD233](https://canaan-creative.com/product/kendryteai)
|
||||
|
||||
## 支持的功能
|
||||
| 名称 | 控制器 | 驱动描述 |
|
||||
| ---- | ---- | ---- |
|
||||
| <center>CAMERA</center> | on-chip | camera驱动控制 |
|
||||
| <center>DMA</center> | on-chip | dma驱动控制 |
|
||||
| <center>GPIO</center> | on-chip | gpio 输入输出控制 |
|
||||
| <center>I<sup>2</sup>C</center> | on-chip | i<sup>2</sup>c总线 |
|
||||
| <center>I<sup>2</sup>S</center> | on-chip | i<sup>2</sup>s总线 |
|
||||
| <center>LCD</center> | on-chip | lcd 液晶显示器控制 |
|
||||
| <center>PLIC</center> | on-chip | 中断控制 |
|
||||
| <center>SPI</center> | on-chip | spi总线驱动控制 |
|
||||
| <center>SYS_CLOCK</center> | on-chip | 系统时钟控制 |
|
||||
| <center>UART</center> | on-chip | uart串口驱动控制 |
|
||||
|
||||
## 编程与调试
|
||||
针对<u>**MAXGO**</u>开发板的配置和刷新信息,详见[开发环境构建](/environment/bianyi.html)
|
|
@ -1,76 +0,0 @@
|
|||
# Nexys A7-100T
|
||||
|
||||
## 综述
|
||||
|
||||
<center>
|
||||
<img src="https://reference.digilentinc.com/_media/reference/programmable-logic/nexys-a7/nexys-a7-obl-600.png">
|
||||
<br>
|
||||
<div style="color:orange; border-bottom: 1px solid #d9d9d9;
|
||||
display: inline-block;
|
||||
color: #999;
|
||||
padding: 2px;">Nexys A7</div>
|
||||
</center>
|
||||
|
||||
Nexys A7-100T 是 Digilent 多孔 RAM-based Nexys 开发板的简易替代品。搭载Xilinx®Artix™-7 FPGA芯片,Nexys 4 DDR 是一个打开即用型的数字电路开发平台,帮助使用者能够在课堂环境下实现诸多工业领域的应用,配有高容量的大型FPGA芯片(Xilinx产品编号XC7A100T-1CSG324C)并集成了USB,以太网和其它端口。Nexys 4 DDR开发板能实现从理论型组合电路到强大的嵌入式处理器的多种设计。
|
||||
## 硬件特点
|
||||
|
||||
<img src="https://s3.ax1x.com/2020/11/19/DuzSVf.jpg">
|
||||
|
||||
| 序号 | 描述 | 序号 | 描述 |
|
||||
| ---- | ---- | ---- | ---- |
|
||||
| 1 | 选择供电跳线 |13|CPU复位按键(用于软核)|
|
||||
| 2 | UART/JTAG共用USB接口 |14|FPGA 配置复位按键|
|
||||
| 3 | 外部配置跳线柱(SD/USB) |15|模拟信号Pmod端口(XADC)|
|
||||
| 4 | Pmod端口 |16|编程模式跳线柱|
|
||||
| 5 | 扩音器 |17|音频连接口|
|
||||
| 6 | 电源测试点 |18|VGA连接口|
|
||||
| 7 | 16个LED |19|FPGA编程完成LED|
|
||||
| 8 | 16个按键开关 |20|以太网连接口|
|
||||
| 9 | 8位7段数码管 |21|USB连接口|
|
||||
| 10 | 可选用与外部接线的JTAG端口 |22|(工业用)PIC24编程端口|
|
||||
| 11 | 5个按键开关 |23|电源开关|
|
||||
| 12 | 板载温度传感器 |24|电源接口|
|
||||
|
||||
|
||||
## 验证FPGA 移植linux
|
||||
|
||||
通过 lowRISC 开源项目,基于 rocket 修改的软核上运行完整的 linux。支持键盘、显示器、网卡等常见通用设备,验证了riscv软核运行linux操作系统的可行性,为XiUOS进一步支持riscv软核提供了试验基础。
|
||||
* 生成riscv软核比特流
|
||||
* 裁剪编译 linux
|
||||
* 生成伯克利 bootloader(bbl)
|
||||
* 将软核写入 flash
|
||||
* 将 bbl 和 linux 写入 microSD卡
|
||||
* JP1 位于 USB / SD 位置,JP2 位于 USB 位置,电源选择 JP3位,usb底部的开关打开DIP-SW 1,引导linux从sd卡启动
|
||||
|
||||
<center>
|
||||
<img src="https://s3.ax1x.com/2020/11/13/DSRnpj.png">
|
||||
<br>
|
||||
<div style="color:orange; border-bottom: 1px solid #d9d9d9;
|
||||
display: inline-block;
|
||||
color: #999;
|
||||
padding: 2px;">在Nexys A7-100T上基于riscv软核运行Linux</div>
|
||||
</center>
|
||||
|
||||
```bash
|
||||
Debian GUN/Linux buster/sid lowrisc tty1
|
||||
lowrisc login: xiuos
|
||||
Password:
|
||||
Last login:Thu Jan 1 01:09:48 BST 1970 on tty1
|
||||
Linux lowrisc 4.18.0-gc81ff0d #48 Thu Oct 18 16:00:24 BST 2018 riscv64
|
||||
|
||||
The programs included with the Debian GUN/linux system are free software;
|
||||
the exact distribution terms for each program are described in the
|
||||
individual files in /usr/share/doc/*/copyright.
|
||||
|
||||
Debian GUN/linux comes with ABSOLUTELY NO WARRANT, to the extent
|
||||
permitted by applicable law.
|
||||
xiuos@lowrisc:~$ cat /proc/cpuinfo
|
||||
hart : 0
|
||||
isa : rv64imafdc
|
||||
mmu : sv39
|
||||
uarch : sifive,rocket0
|
||||
|
||||
xiuos@lowrisc:~$ uname -a
|
||||
Linux lowrisc 4.18.0-gc81ff0d #48 Thu Oct 18 16:00:24 BST 2018 riscv64 GUN/linux
|
||||
xiuos@lowrisc:~$
|
||||
```
|
|
@ -1,62 +0,0 @@
|
|||
# STM32F407-ST-DISCOVERY
|
||||
## 综述
|
||||
<div class ="tablebox">
|
||||
<div class="imgbox">
|
||||
<img src="https://www.st.com/bin/ecommerce/api/image.PF252419.en.feature-description-include-personalized-no-cpn-large.jpg" />
|
||||
</div>
|
||||
<p>STM32F4DISCOVERY</p>
|
||||
<span>XiUOS最新分支支持stm32f407-st-discovery开发板,该开发板作为一种标准的板子,支持各种上层组件和应用程序。</span>
|
||||
</div>
|
||||
|
||||
## 硬件特点
|
||||
|
||||
+ STM32F407VGT6 microcontroller featuring 32-bit ARM®Cortex®-M4 with FPU core, 1-Mbyte Flash memory, 192-Kbyte RAM in an LQFP100 package
|
||||
+ On-board ST-LINK/V2 on STM32F4DISCOVERY (old reference) or ST-LINK/V2-A on STM32F407G-DISC1 (new order code)
|
||||
+ USB ST-LINK with re-enumeration capability and three different interfaces:
|
||||
<p style="text-indent:2em">1. Debug port</p>
|
||||
<p style="text-indent:2em">2. Virtual Com port (with new order code only) </p>
|
||||
<p style="text-indent:2em">3. Mass storage (with new order code only) </p>
|
||||
+ Board power supply: through USB bus or from an external 5 V supply voltage
|
||||
+ External application power supply: 3 V and 5 V
|
||||
+ LIS302DL or LIS3DSH ST MEMS 3-axis accelerometer
|
||||
+ MP45DT02 ST-MEMS audio sensor omni-directional digital microcontroller
|
||||
+ CS43L22 audio DAC with integrated class D speaker driver
|
||||
+ Eight LEDs:
|
||||
<p style="text-indent:2em">1. LD1 (red/green) for USB communication</p>
|
||||
<p style="text-indent:2em">2. LD2 (red) for 3.3 V power on </p>
|
||||
<p style="text-indent:2em">3. Four user LEDs, LD3 (orange), LD4 (green), LD5 (red) and LD6 (blue) </p>
|
||||
<p style="text-indent:2em">4. USB OTG LEDs LD7 (green) VBUS and LD8 (red) over-current </p>
|
||||
+ Two push-buttons (user and reset)
|
||||
+ USB OTG FS with micro-AB connector
|
||||
+ Extension header for all LQFP100 I/Os for quick connection to prototyping board and easy probing
|
||||
+ Comprehensive free software including a variety of examples, part of STM32CubeF4 package or STSW-STM32068 to use legacy standard libraries.
|
||||
|
||||
### 更多信息
|
||||
+ [STM32F4DISCOVERY](https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-discovery-kits/stm32f4discovery.html#)
|
||||
|
||||
## 支持的功能
|
||||
| 名称 | 控制器 | 驱动描述 |
|
||||
| ---- | ---- | ---- |
|
||||
| <center>DMA</center> | on-chip | DMA驱动控制 |
|
||||
| <center>GPIO</center> | on-chip | gpio 输入输出控制 |
|
||||
| <center>I2C</center> | on-chip | i2c 控制 |
|
||||
| <center>LCD</center> | on-chip | lcd 液晶显示器控制 |
|
||||
| <center>RTC</center> | on-chip | rtc 实时始终控制 |
|
||||
| <center>SPI</center> | on-chip | spi 总线系统控制 |
|
||||
| <center>TIMER</center> | on-chip | timer重置和计时控制 |
|
||||
| <center>UART</center> | on-chip | uart串口驱动控制 |
|
||||
| <center>USB</center> | on-chip | usb驱动控制 |
|
||||
| <center>WATCHDOG</center> | on-chip | watchdog看门口控制 |
|
||||
|
||||
## 编程与调试
|
||||
针对<u>**stm32f407-st-discovery**</u>开发板的配置和刷新信息,详见[开发环境构建](/environment/bianyi.html)
|
||||
|
||||
<style>
|
||||
.tablebox{
|
||||
width: 1500px;
|
||||
height: 400px;
|
||||
vertical-align: middle;
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
|
@ -1,84 +0,0 @@
|
|||
# STM32F407ZGT6
|
||||
## 综述
|
||||
<div class ="tablebox1">
|
||||
<img src="./imagesrc/stm32f407zgt6.png"/>
|
||||
<p>STM32F407ZET6</p>
|
||||
<span>XiUOS最新分支支持stm32f407zgt6开发板,该开发板作为一种标准的板子,支持各种上层组件和应用程序。</span>
|
||||
</div>
|
||||
|
||||
## 硬件特点
|
||||
|
||||
+ Core: Arm® 32-bit Cortex®-M4 CPU with FPU, Adaptive real-time accelerator (ART Accelerator) allowing 0-wait state execution from Flash memory, frequency up to 168 MHz, memory protection unit, 210 DMIPS/1.25 DMIPS/MHz (Dhrystone 2.1), and DSP instructions
|
||||
+ Memories
|
||||
<p style="text-indent:2em">1. Up to 1 Mbyte of Flash memory</p>
|
||||
<p style="text-indent:2em">2. Up to 192+4 Kbytes of SRAM including 64-Kbyte of CCM (core coupled memory) data RAM </p>
|
||||
<p style="text-indent:2em">3. Up to 192+4 Kbytes of SRAM including 64-Kbyte of CCM (core coupled memory) data RAM</p>
|
||||
<p style="text-indent:2em">4. 512 bytes of OTP memory</p>
|
||||
<p style="text-indent:2em">5. Flexible static memory controller supporting Compact Flash, SRAM, PSRAM, NOR and NAND memories</p>
|
||||
+ LCD parallel interface, 8080/6800 modes
|
||||
+ Clock, reset and supply management
|
||||
<p style="text-indent:2em">1. 1.8 V to 3.6 V application supply and I/Os</p>
|
||||
<p style="text-indent:2em">2. POR, PDR, PVD and BOR</p>
|
||||
<p style="text-indent:2em">3. 4-to-26 MHz crystal oscillator </p>
|
||||
<p style="text-indent:2em">4. Internal 16 MHz factory-trimmed RC (1% accuracy)</p>
|
||||
<p style="text-indent:2em">5. 32 kHz oscillator for RTC with calibration</p>
|
||||
<p style="text-indent:2em">6. Internal 32 kHz RC with calibration </p>
|
||||
+ Low-power operation
|
||||
<p style="text-indent:2em">1. Sleep, Stop and Standby modes </p>
|
||||
<p style="text-indent:2em">2. V<sub>BAT</sub> supply for RTC, 20×32 bit backup registers + optional 4 KB backup SRAM </p>
|
||||
+ 3×12-bit, 2.4 MSPS A/D converters: up to 24 channels and 7.2 MSPS in triple interleaved mode
|
||||
+ 2×12-bit D/A converters
|
||||
+ General-purpose DMA: 16-stream DMA controller with FIFOs and burst support
|
||||
+ Up to 17 timers: up to twelve 16-bit and two 32-bit timers up to 168 MHz, each with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input
|
||||
+ Debug mode
|
||||
<p style="text-indent:2em">1. Serial wire debug (SWD) & JTAG interfaces </p>
|
||||
<p style="text-indent:2em">2. Cortex-M4 Embedded Trace Macrocell™ </p>
|
||||
+ Up to 140 I/O ports with interrupt capability
|
||||
<p style="text-indent:2em">1. Up to 136 fast I/Os up to 84 MHz </p>
|
||||
<p style="text-indent:2em">2. Up to 138 5 V-tolerant I/Os </p>
|
||||
+ Up to 15 communication interfaces
|
||||
<p style="text-indent:2em">1. Up to 3 × I<sup>2</sup>C interfaces (SMBus/PMBus) </p>
|
||||
<p style="text-indent:2em">2. Up to 4 USARTs/2 UARTs (10.5 Mbit/s, ISO 7816 interface, LIN, IrDA, modem control) </p>
|
||||
<p style="text-indent:2em">3. Up to 3 SPIs (42 Mbits/s), 2 with muxed full-duplex I2S to achieve audio class accuracy via internal audio PLL or external clock </p>
|
||||
<p style="text-indent:2em">4. 2 × CAN interfaces (2.0B Active) </p>
|
||||
<p style="text-indent:2em">5. SDIO interface </p>
|
||||
+ Advanced connectivity
|
||||
<p style="text-indent:2em">1. USB 2.0 full-speed device/host/OTG controller with on-chip PHY </p>
|
||||
<p style="text-indent:2em">2. USB 2.0 high-speed/full-speed device/host/OTG controller with dedicated DMA, on-chip full-speed PHY and ULPI</p>
|
||||
<p style="text-indent:2em">3. 10/100 Ethernet MAC with dedicated DMA: supports IEEE 1588v2 hardware, MII/RMII </p>
|
||||
+ 8- to 14-bit parallel camera interface up to 54 Mbytes/s
|
||||
+ True random number generator
|
||||
+ CRC calculation unit
|
||||
+ 96-bit unique ID
|
||||
+ RTC: subsecond accuracy, hardware calendar
|
||||
|
||||
|
||||
### 更多信息
|
||||
+ [STM32F407ZET6](https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus/stm32-high-performance-mcus/stm32f4-series/stm32f407-417/stm32f407ze.html)
|
||||
|
||||
## 支持的功能
|
||||
| 名称 | 控制器 | 驱动描述 |
|
||||
| ---- | ---- | ---- |
|
||||
| <center>DMA</center> | on-chip | DMA驱动控制 |
|
||||
| <center>GPIO</center> | on-chip | gpio 输入输出控制 |
|
||||
| <center>I2C</center> | on-chip | i2c 控制 |
|
||||
| <center>LCD</center> | on-chip | lcd 液晶显示器控制 |
|
||||
| <center>RTC</center> | on-chip | rtc 实时始终控制 |
|
||||
| <center>SPI</center> | on-chip | spi 总线系统控制 |
|
||||
| <center>TIMER</center> | on-chip | timer重置和计时控制 |
|
||||
| <center>UART</center> | on-chip | uart串口驱动控制 |
|
||||
| <center>USB</center> | on-chip | usb驱动控制 |
|
||||
| <center>WATCHDOG</center> | on-chip | watchdog看门口控制 |
|
||||
|
||||
## 编程与调试
|
||||
针对<u>**stm32f407zet6**</u>开发板的配置和刷新信息,详见[开发环境构建](/environment/bianyi.html)
|
||||
|
||||
<style>
|
||||
.tablebox1{
|
||||
width: 1000px;
|
||||
height: 300px;
|
||||
vertical-align: middle;
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
|
@ -1,150 +0,0 @@
|
|||
# 系统调试
|
||||
|
||||
* [前言](#intro)
|
||||
* [Jlink调试](#jlink-debug)
|
||||
* [Ozone调试](#ozone-debug)
|
||||
* [FAQ](#faq)
|
||||
|
||||
<span id="intro"></span>
|
||||
|
||||
## 前言
|
||||
|
||||
本文档将介绍<B>XiUOS</B>使用jlink、Ozone调试软件的配置、调试过程。
|
||||
|
||||
<span id="jlink-debug"></span>
|
||||
|
||||
## Jlink调试
|
||||
|
||||
### 软件安装
|
||||
|
||||
+ jlink包安装
|
||||
|
||||
第一步,进入jlink官网[下载网址](https://www.segger.com/downloads/jlink)
|
||||
|
||||
<img src="./imagesrc/jlink_package_1.png" width="100%"/>
|
||||
|
||||
第二步,选择版本并下载安装包,此处下载的安装包版本为V6.72e,即JLink_Linux_V672e_x86_64.deb。
|
||||
|
||||
<img src="./imagesrc/jlink_package_2.png" width="100%"/>
|
||||
|
||||
第三步,安装JLink_Linux_V672e_x86_64.deb
|
||||
|
||||
```shell
|
||||
$ dpkg -i JLink_Linux_V672e_x86_64.deb
|
||||
```
|
||||
|
||||
+ openocd安装
|
||||
|
||||
第一步,进入[下载网址](https://github.com/kendryte/openocd-kendryte/releases),
|
||||
下载Unbuntu版本的openocd。<B>XiUOS</B>中下载的kendryte-openocd-0.2.3-ubuntu64.tar.gz
|
||||
|
||||
第二步,安装openocd
|
||||
|
||||
```shell
|
||||
$ sudo mv kendryte-openocd-0.2.2-ubuntu64.tar.gz /opt
|
||||
$ cd /opt
|
||||
$ sudo tar -zxvf kendryte-openocd-0.2.2-ubuntu64.tar.gz
|
||||
$ sudo apt install libusb-dev libftdi-dev libhidapi-dev
|
||||
```
|
||||
|
||||
|
||||
|
||||
第三步,openocd文件配置
|
||||
|
||||
打开配置文件,修改第三行 jlink serial 504503073的504503073为具体JLINK设备的标签。
|
||||
|
||||
```shell
|
||||
$ cd /opt/kendryte-openocd
|
||||
$ vim ctl/openocd.cfg
|
||||
```
|
||||
|
||||
<img src="./imagesrc/openocd_cfg.png" width="100%"/>
|
||||
|
||||
第四步,打开openocd软件
|
||||
|
||||
```shell
|
||||
$ cd /opt/kendryte-openocd
|
||||
$ ./bin/openocd -f ./ctl/openocd.cfg
|
||||
```
|
||||
|
||||
成功运行则显示如下的界面。
|
||||
|
||||
<img src="./imagesrc/open_openocd.png"/>
|
||||
|
||||
|
||||
### 调试程序
|
||||
|
||||
```shell
|
||||
$ riscv-none-embed-gdb XiaoShan_kd233.elf --eval-command="target remote 127.0.0.1:3333"
|
||||
```
|
||||
|
||||
运行上述命令,其中,
|
||||
+ XiaoShan_kd233.elf是编译过程生成的elf文件;
|
||||
+ 127.0.0.1表示本地IP地址,也可以制定远程地址;
|
||||
+ 3333是openocd监听的端口号;
|
||||
|
||||
成功连接openocd之后,界面如下所示,之后就可以使用load\break\continue等gdb命令进行调试了。
|
||||
|
||||
<div>
|
||||
<img src="./imagesrc/openocd_gdb.png"/>
|
||||
</div>
|
||||
|
||||
<span id="ozone-debug"></span>
|
||||
|
||||
## Ozone调试
|
||||
|
||||
第一步,从Segger官网下载Ozone,下载链接分别为[32位](https://www.segger.com/downloads/jlink/Ozone_Linux_i386.deb)、[64位](https://www.segger.com/downloads/jlink/Ozone_Linux_x86_64.deb).
|
||||
|
||||
第二步,安装deb安装包
|
||||
|
||||
|
||||
![INSTALL PROCESS](./imagesrc/ozone_install.png)
|
||||
|
||||
|
||||
|
||||
第三步,配置合适的参数
|
||||
|
||||
选择Device为STM32F407VG
|
||||
|
||||
<center>
|
||||
|
||||
![DEVICE CONFIG](./imagesrc/device_config.png)
|
||||
|
||||
</center>
|
||||
|
||||
:::tip
|
||||
注意Target Interface需修改为SWD.
|
||||
:::
|
||||
|
||||
<center>
|
||||
|
||||
![INTERFACE CONFIG](./imagesrc/interface_config.png)
|
||||
|
||||
</center>
|
||||
|
||||
选择编译后生成的elf文件
|
||||
|
||||
<img src="./imagesrc/elf_file.png" width = "100%"/>
|
||||
|
||||
提交到Ozone页面
|
||||
|
||||
![OZONE PAGE](./imagesrc/ozone_page.png)
|
||||
|
||||
点击调试后,若未设置断点,Ozone将自动在执行main函数前停止,Ozone支持设置代码和数据断点、单步调试、查看变量值等功能,是很方便的一个调试工具。
|
||||
|
||||
|
||||
|
||||
<span id="faq"></span>
|
||||
|
||||
## FAQ
|
||||
|
||||
|
||||
<style>
|
||||
.openocd_cfg{
|
||||
width: 1500px;
|
||||
height: 400px;
|
||||
vertical-align: middle;
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
|
@ -1,56 +0,0 @@
|
|||
# 开发步骤
|
||||
|
||||
## 前言
|
||||
<p style="text-indent:2em">本文档将介绍<B>XiUOS</B>分别在基于ARM和RISC-V架构的开发板上的编译、烧录和运行的过程。包括开发板选择及配置初始化、编译命令等信息。
|
||||
</p>
|
||||
|
||||
## 开发板的选择及配置初始化
|
||||
<p style="text-indent:2em">在执行编译之前,我们需要先确定<B>XiUOS</B>系统要运行在哪个开发板上,然后针对具体的开发板设置相关的配置信息。</p>
|
||||
|
||||
+ 开发板的选择
|
||||
为了查看<B>XiUOS</B>支持的开发板种类,可以执行以下命令,也可以[查看支持的开发板](/hardwaresupport/arm32/stm32f407-st-discovery.html)。
|
||||
|
||||
$ make BOARD=list
|
||||
+ 配置初始化
|
||||
+ 以stm32f407-st-discovery为例,进行开始系统参数。
|
||||
|
||||
|
||||
|
||||
|
||||
$ make BOARD=stm32f407-st-discovery menuconfig
|
||||
<img src="https://raw.githubusercontent.com/yanyannew/images/branch/stm32_menuconfig.png" />
|
||||
对应的配置信息将存放在board/stm32f407-st-discovery/xsconfig.h头文件中,文件中的选项均以<B>XS_</B>为前缀开头。
|
||||
|
||||
+ 以kd233为例,进行开始系统参数。
|
||||
|
||||
$ make BOARD=KD233 menuconfig
|
||||
|
||||
<img src="https://raw.githubusercontent.com/yanyannew/images/branch/kd233_menuconfig.png" />
|
||||
对应的配置信息将存放在board/kd233/xsconfig.h头文件中,文件中的选项均以<B>XS_</B>为前缀开头。
|
||||
|
||||
## 编译命令
|
||||
通用编译命令, 默认为BOARD=KD233
|
||||
|
||||
$ make [BOARD=<所选开发板>]
|
||||
+ 当 make 命令被执行时,它会扫描当前目录下Makefile或makefile文件找到目标以及其依赖。如果这些依赖自身也是目标,继续为这些依赖扫描Makefile 建立其依赖关系,然后编译它们。
|
||||
+ 创建build目录,目录下包含了各种目标文件、.bin、.elf等文件
|
||||
+ 目标文件,以.o结尾的文件
|
||||
+ .bin 二进制文件
|
||||
+ .elf 可执行文件
|
||||
## 烧录命令
|
||||
+ 基于ARM开发板的烧录命令
|
||||
|
||||
$ sudo st-flash write <生成的.elf文件> 0x8000000
|
||||
+ 基于RISC-V开发板的烧录命令
|
||||
|
||||
$ sudo kflash <生成的.elf文件> -t
|
||||
|
||||
## 运行界面
|
||||
+ <B>XiUOS</B>运行在ARM开发板
|
||||
|
||||
<img src="https://raw.githubusercontent.com/yanyannew/images/branch/stm32_run_gui.png" />
|
||||
|
||||
+ <B>XiUOS</B>运行在RISC-V开发板
|
||||
<img src="https://raw.githubusercontent.com/yanyannew/images/branch/riscv_run_gui.png" />
|
||||
|
||||
## FAQ
|
|
@ -1,80 +0,0 @@
|
|||
# 开发环境
|
||||
|
||||
## 前言
|
||||
本文档将介绍如何在个人pc设备上构建编译环境来编译 <B>XiUOS</B>
|
||||
操作系统, 需要注意的是, 目前 <B>XiUOS</B> 暂时只支持在Linux系统上编译。</p>
|
||||
|
||||
## 硬件安装
|
||||
* 硬件要求
|
||||
64位系统,磁盘空间大于40G。
|
||||
* linux内核下载
|
||||
因为<B>XiUOS</B>是在Ubuntu 16.04上开发与测试的(Ubuntu 18.04、20.04版本也支持),因此我们推荐您使用Ubuntu 16.04版本的系统执行编译环境搭建。
|
||||
* Ubuntu下载网址
|
||||
[here](https://ubuntu.com/download/desktop)
|
||||
|
||||
|
||||
## 依赖包安装
|
||||
|
||||
```shell
|
||||
$ sudo apt-get install gcc
|
||||
$ sudo apt-get install make
|
||||
$ sudo apt-get install libncurses5-dev
|
||||
$ sudo apt-get install openssl
|
||||
$ sudo apt-get install libssl-dev
|
||||
$ sudo apt-get install build-essential
|
||||
$ sudo apt-get install pkg-config
|
||||
$ sudo apt-get install libc6-dev
|
||||
$ sudo apt-get install bison
|
||||
$ sudo apt-get install flex
|
||||
$ sudo apt-get install libelf-dev
|
||||
$ sudo apt-get install autoconf
|
||||
$ sudo apt-get install libtool
|
||||
$ sudo apt-get install gpref
|
||||
```
|
||||
## 源码下载
|
||||
<B>XiUOS</B>的源码和相关文档介绍使用git进行集成管理,建议开发者使用git工具进行版本控制和分支管理
|
||||
|
||||
git配置执行以下命令
|
||||
```shell
|
||||
$ git config --global user.name "your name"
|
||||
$ git config --global user.email "your email"
|
||||
```
|
||||
其中,源码下载网址点击该链接[XiUOS源码网址](https://ubuntu.com/download/desktop)
|
||||
|
||||
## 工具链
|
||||
* ARM下编译需要安装<B>arm-none-eabi</B>编译工具, 安装到Ubuntu的默认路径/usr/bin/arm-none-eabi-,使用如下命令行下载
|
||||
|
||||
```shell
|
||||
$ sudo apt-get install gcc-arm-none-eabi
|
||||
```
|
||||
|
||||
* 源码下载,下载网址
|
||||
[ARM官网下载](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
|
||||
RISC-V下编译需要安装<B>riscv-none-embed-</B>编译工具, 安装到Ubuntu的默认路径/opt/
|
||||
[下载网址](https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/), 根据需求选择不同的版本
|
||||
操作方法,以xpack-riscv-none-embed-gcc-linux-x64.tar.gz为例
|
||||
|
||||
```shell
|
||||
$ tar -zxvf xpack-riscv-none-embed-gcc-linux-x64.tar.gz -C /opt/
|
||||
```
|
||||
## 烧写工具
|
||||
* ARM下烧写软件(ST-LINK)
|
||||
下载源码
|
||||
|
||||
```shell
|
||||
git clone https://github.com/texane/stlink.git
|
||||
```
|
||||
|
||||
|
||||
* RISC-V下烧写软件(KFLASH)
|
||||
|
||||
```shell
|
||||
$ sudo pip3 install kflash
|
||||
// 如果在安装工具失败,则执行一下命令
|
||||
$ sudo python -m pip install kflash
|
||||
$ sudo python3 -m pip install kflash
|
||||
$ sudo pip install kflash
|
||||
$ sudo pip2 install kflash
|
||||
```
|
||||
|
||||
## FAQ
|
Before Width: | Height: | Size: 243 KiB |
Before Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 329 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 663 KiB |
Before Width: | Height: | Size: 932 KiB |
|
@ -0,0 +1,11 @@
|
|||
# 从零开始构建矽璓工业物联操作系统
|
||||
|
||||
---
|
||||
|
||||
## 使用ARM架构的开发板
|
||||
|
||||
* [STM32F407-ST-DISCOVERY](/doc/appdev/start_from_scratch/stm32f407-st-discovery.md)
|
||||
|
||||
## 使用risc-v架构的开发板
|
||||
|
||||
* [KD233](/doc/appdev/start_from_scratch/kd233.md)
|
|
@ -0,0 +1,198 @@
|
|||
# 从零开始构建矽璓工业物联操作系统:使用risc-v架构的kd233开发板
|
||||
|
||||
[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓工业物联操作系统是一款面向工业物联场景的泛在操作系统,来自泛在操作系统研究计划。所谓泛在操作系统(UOS: Ubiquitous Operating Systems),是支持互联网时代人机物融合泛在计算应用模式的新型操作系统,是传统操作系统概念的泛化与延伸。在泛在操作系统技术体系中,不同的泛在计算设备和泛在应用场景需要符合各自特性的不同UOS,XiUOS即是面向工业物联场景的一种UOS,主要由一个极简的微型实时操作系统(RTOS)内核和其上的智能工业物联框架构成,支持工业物联网(IIoT: Industrial Internet of Things)应用。
|
||||
|
||||
## 开发环境搭建
|
||||
|
||||
### 推荐使用
|
||||
|
||||
**操作系统:** ubuntu18.04[https://ubuntu.com/download/desktop](https://ubuntu.com/download/desktop)
|
||||
更新`ubuntu 18.04`源的方法:(根据自身情况而定,可以不更改)
|
||||
第一步:打开sources.list文件
|
||||
|
||||
```bash
|
||||
sudo vim /etc/apt/sources.list
|
||||
```
|
||||
|
||||
第二步:将以下内容复制到sources.list文件
|
||||
|
||||
```
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
|
||||
```
|
||||
|
||||
第三步:更新源和系统软件
|
||||
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
```
|
||||
|
||||
**开发工具推荐使用 VSCode,VScode下载地址为:** VSCode [https://code.visualstudio.com/](https://code.visualstudio.com/),推荐下载地址为 [http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb](http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb)
|
||||
|
||||
### 依赖包安装
|
||||
|
||||
```bash
|
||||
sudo apt install build-essential pkg-config git
|
||||
sudo apt install gcc make libncurses5-dev openssl libssl-dev bison flex libelf-dev autoconf libtool gperf libc6-dev
|
||||
```
|
||||
|
||||
**源码下载:** XiUOS [https://forgeplus.trustie.net/projects/xuos/xiuos](https://forgeplus.trustie.net/projects/xuos/xiuos)
|
||||
新建一个空文件夹并进入文件夹中,并下载源码,具体命令如下:
|
||||
|
||||
```bash
|
||||
mkdir test && cd test
|
||||
git clone https://git.trustie.net/xuos/xiuos.git
|
||||
```
|
||||
|
||||
打开源码文件包可以看到以下目录:
|
||||
| 名称 | 说明 |
|
||||
| -- | -- |
|
||||
| application | 应用代码 |
|
||||
| board | 板级支持包 |
|
||||
| framework | 应用框架 |
|
||||
| fs | 文件系统 |
|
||||
| kernel | 内核源码 |
|
||||
| resources | 驱动文件 |
|
||||
| tool | 系统工具 |
|
||||
使用VScode打开代码,具体操作步骤为:在源码文件夹下打开系统终端,输入`code .`即可打开VScode开发环境,如下图所示:
|
||||
<div align= "center">
|
||||
<img src = https://img-blog.csdnimg.cn/20210429154839715.jpg width =1000>
|
||||
</div>
|
||||
|
||||
### 裁减配置工具的下载
|
||||
|
||||
裁减配置工具:
|
||||
**工具地址:** kconfig-frontends [https://forgeplus.trustie.net/projects/xuos/kconfig-frontends](https://forgeplus.trustie.net/projects/xuos/kconfig-frontends)
|
||||
|
||||
```bash
|
||||
mkdir kfrontends && cd kfrontends
|
||||
git clone https://git.trustie.net/xuos/kconfig-frontends.git
|
||||
```
|
||||
|
||||
下载源码后按以下步骤执行软件安装:
|
||||
|
||||
```bash
|
||||
cd kconfig-frontends
|
||||
./xs_build.sh
|
||||
```
|
||||
|
||||
### 编译工具链
|
||||
|
||||
ARM: arm-none-eabi(`gcc version 6.3.1`),默认安装到Ubuntu的/usr/bin/arm-none-eabi-,使用如下命令行下载
|
||||
|
||||
```bash
|
||||
sudo apt install gcc-arm-none-eabi
|
||||
```
|
||||
|
||||
# 在STM32F407-DISCOVERY上创建第一个应用 --helloworld
|
||||
|
||||
## 1. 简介
|
||||
|
||||
| 硬件 | 描述 |
|
||||
| -- | -- |
|
||||
|芯片型号| Stm32F407VGT6|
|
||||
|CPU|arm cortex-m|
|
||||
|主频| 168MHz |
|
||||
|片内SRAM| 192KB |
|
||||
|片上FLASH| 1MB |
|
||||
| 外设 | -- |
|
||||
| | ADC、DAC、USB、GPIO、UART、SPI、SDIO、RTC、CAN、DMA、MAC、I²C、WDT、Timer等 |
|
||||
|
||||
XiUOS板级驱动当前支持使用GPIO、I2C、LCD、USB、RTC、SPI、Timer、UART和WDT等。
|
||||
|
||||
## 2. 编译说明
|
||||
|
||||
### 编辑环境:`Ubuntu18.04`
|
||||
|
||||
### 编译工具链:`arm-none-eabi-gcc`
|
||||
|
||||
使用`VScode`打开工程的方法有多种,本文介绍一种快捷键,在项目目录下将`code .`输入终端即可打开目标项目
|
||||
|
||||
修改`applications`文件夹下`main.c`
|
||||
在输出函数中写入 `Hello, world!!! \n Running on stm32f407-st-discovery`完成代码编辑。
|
||||
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210428145204668.png#pic_center)
|
||||
|
||||
编译步骤:
|
||||
|
||||
1.在代码根目录下执行以下命令,生成配置文件
|
||||
|
||||
```bash
|
||||
make BOARD=stm32f407-st-discovery menuconfig
|
||||
```
|
||||
|
||||
2.在menuconfig界面配置需要关闭和开启的功能,按回车键进入下级菜单,按Y键选中需要开启的功能,按N键选中需要关闭的功能,配置结束后保存并退出
|
||||
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210426212955727.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ViaXF1aXRvdXNUZWFt,size_16,color_FFFFFF,t_70#pic_center)
|
||||
|
||||
3.继续执行以下命令,进行编译
|
||||
|
||||
```bash
|
||||
make BOARD=stm32f407-st-discovery
|
||||
```
|
||||
|
||||
4.如果编译正确无误,会产生XiUOS_stm32f407-st-discovery.elf、XiUOS_stm32f407-st-discovery.bin文件。其中XiUOS_stm32f407-st-discovery.bin需要烧写到设备中进行运行。
|
||||
|
||||
## 3. 烧写及执行
|
||||
|
||||
将 BOARD=stm32f407-st-discovery开发板SWD经 st-link 转接到USB接口,然后使用st-flash工具进行烧写bin文件。
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021042716353240.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70#pic_center)
|
||||
|
||||
### 烧写工具
|
||||
|
||||
ARM:ST-LINK(ST-LINK V2实物如图,可在购物网站搜索关键字购买)
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210427144736126.png#pic_center)
|
||||
|
||||
下载并以下执行命令以下命令安装st-link工具(本文使用v1.5.1版本),下载地址为:[http://101.36.126.201:8011/stlink.zip](http://101.36.126.201:8011/stlink.zip)
|
||||
|
||||
```bash
|
||||
sudo apt install libusb-dev
|
||||
sudo apt install libusb-1.0-0-dev
|
||||
sudo apt install cmake
|
||||
cd stlink
|
||||
make
|
||||
cd build/Release && make install DESTDIR=_install
|
||||
```
|
||||
|
||||
将生成的st-flash(在stlink/build/Release/bin文件夹下)复制到/usr/bin下就可使用了
|
||||
|
||||
代码根目录下执行st-flash工具烧录
|
||||
|
||||
```bash
|
||||
sudo st-flash write build/XiUOS_stm32f407-st-discovery.bin 0x8000000
|
||||
```
|
||||
|
||||
此外,推荐用户使用putty作为终端工具,安装命令如下:
|
||||
|
||||
```bash
|
||||
sudo apt install putty
|
||||
```
|
||||
|
||||
打开putty配置串口信息
|
||||
|
||||
```bash
|
||||
sudo puty
|
||||
```
|
||||
|
||||
选择ttyUSB0(这个端口号根据具体情况而定),配置波特率为115200。
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021042815015872.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70#pic_center)
|
||||
|
||||
注意:选择正确的终端端口号,最后可以执行以下命令,清除配置文件和编译生成的文件
|
||||
|
||||
```bash
|
||||
make BOARD=stm32f407-st-discovery distclean
|
||||
```
|
||||
|
||||
### 3.1 运行结果
|
||||
|
||||
如果编译 & 烧写无误,将会在串口终端上看到信息打印输出,(终端串口引脚为PB6、PB7)。
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210426213212239.PNG?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ViaXF1aXRvdXNUZWFt,size_16,color_FFFFFF,t_70#pic_center)
|
|
@ -0,0 +1,198 @@
|
|||
# 从零开始构建矽璓工业物联操作系统:使用ARM架构的STM32F407-discovery开发板
|
||||
|
||||
[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓工业物联操作系统是一款面向工业物联场景的泛在操作系统,来自泛在操作系统研究计划。所谓泛在操作系统(UOS: Ubiquitous Operating Systems),是支持互联网时代人机物融合泛在计算应用模式的新型操作系统,是传统操作系统概念的泛化与延伸。在泛在操作系统技术体系中,不同的泛在计算设备和泛在应用场景需要符合各自特性的不同UOS,XiUOS即是面向工业物联场景的一种UOS,主要由一个极简的微型实时操作系统(RTOS)内核和其上的智能工业物联框架构成,支持工业物联网(IIoT: Industrial Internet of Things)应用。
|
||||
|
||||
## 开发环境搭建
|
||||
|
||||
### 推荐使用
|
||||
|
||||
**操作系统:** ubuntu18.04 [https://ubuntu.com/download/desktop](https://ubuntu.com/download/desktop)
|
||||
更新`ubuntu 18.04`源的方法:(根据自身情况而定,可以不更改)
|
||||
第一步:打开sources.list文件
|
||||
|
||||
```bash
|
||||
sudo vim /etc/apt/sources.list
|
||||
```
|
||||
|
||||
第二步:将以下内容复制到sources.list文件
|
||||
|
||||
```bash
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
|
||||
```
|
||||
|
||||
第三步:更新源和系统软件
|
||||
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
```
|
||||
|
||||
**开发工具推荐使用 VSCode ,VScode下载地址为:** VSCode [https://code.visualstudio.com/](https://code.visualstudio.com/),推荐下载地址为 [http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb](http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb)
|
||||
|
||||
### 依赖包安装
|
||||
|
||||
```bash
|
||||
sudo apt install build-essential pkg-config git
|
||||
sudo apt install gcc make libncurses5-dev openssl libssl-dev bison flex libelf-dev autoconf libtool gperf libc6-dev
|
||||
```
|
||||
|
||||
**源码下载:** XiUOS [https://forgeplus.trustie.net/projects/xuos/xiuos](https://forgeplus.trustie.net/projects/xuos/xiuos)
|
||||
新建一个空文件夹并进入文件夹中,并下载源码,具体命令如下:
|
||||
|
||||
```bash
|
||||
mkdir test && cd test
|
||||
git clone https://git.trustie.net/xuos/xiuos.git
|
||||
```
|
||||
|
||||
打开源码文件包可以看到以下目录:
|
||||
| 名称 | 说明 |
|
||||
| ----------- | ---------- |
|
||||
| application | 应用代码 |
|
||||
| board | 板级支持包 |
|
||||
| framework | 应用框架 |
|
||||
| fs | 文件系统 |
|
||||
| kernel | 内核源码 |
|
||||
| resources | 驱动文件 |
|
||||
| tool | 系统工具 |
|
||||
使用VScode打开代码,具体操作步骤为:在源码文件夹下打开系统终端,输入`code .`即可打开VScode开发环境,如下图所示:
|
||||
<div align= "center">
|
||||
<img src = https://img-blog.csdnimg.cn/20210429154839715.jpg width =1000>
|
||||
</div>
|
||||
|
||||
### 裁减配置工具的下载
|
||||
|
||||
裁减配置工具:
|
||||
**工具地址:** kconfig-frontends [https://forgeplus.trustie.net/projects/xuos/kconfig-frontends](https://forgeplus.trustie.net/projects/xuos/kconfig-frontends)
|
||||
|
||||
```bash
|
||||
mkdir kfrontends && cd kfrontends
|
||||
git clone https://git.trustie.net/xuos/kconfig-frontends.git
|
||||
```
|
||||
|
||||
下载源码后按以下步骤执行软件安装:
|
||||
|
||||
```bash
|
||||
cd kconfig-frontends
|
||||
./xs_build.sh
|
||||
```
|
||||
|
||||
### 编译工具链
|
||||
|
||||
ARM: arm-none-eabi(`gcc version 6.3.1`),默认安装到Ubuntu的/usr/bin/arm-none-eabi-,使用如下命令行下载
|
||||
|
||||
```bash
|
||||
sudo apt install gcc-arm-none-eabi
|
||||
```
|
||||
|
||||
# 在STM32F407-DISCOVERY上创建第一个应用 --helloworld
|
||||
|
||||
## 1. 简介
|
||||
|
||||
| 硬件 | 描述 |
|
||||
| --------- | --------------------------------------------------------------------------- |
|
||||
| 芯片型号 | Stm32F407VGT6 |
|
||||
| CPU | arm cortex-m |
|
||||
| 主频 | 168MHz |
|
||||
| 片内SRAM | 192KB |
|
||||
| 片上FLASH | 1MB |
|
||||
| 外设 | -- |
|
||||
| | ADC、DAC、USB、GPIO、UART、SPI、SDIO、RTC、CAN、DMA、MAC、I²C、WDT、Timer等 |
|
||||
|
||||
XiUOS板级驱动当前支持使用GPIO、I2C、LCD、USB、RTC、SPI、Timer、UART和WDT等。
|
||||
|
||||
## 2. 编译说明
|
||||
|
||||
### 编辑环境:`Ubuntu18.04`
|
||||
|
||||
### 编译工具链:`arm-none-eabi-gcc`
|
||||
|
||||
使用`VScode`打开工程的方法有多种,本文介绍一种快捷键,在项目目录下将`code .`输入终端即可打开目标项目
|
||||
|
||||
修改`applications`文件夹下`main.c`
|
||||
在输出函数中写入 `Hello, world!!! \n Running on stm32f407-st-discovery`完成代码编辑。
|
||||
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210428145204668.png#pic_center)
|
||||
|
||||
编译步骤:
|
||||
|
||||
1.在代码根目录下执行以下命令,生成配置文件
|
||||
|
||||
```bash
|
||||
make BOARD=stm32f407-st-discovery menuconfig
|
||||
```
|
||||
|
||||
2.在menuconfig界面配置需要关闭和开启的功能,按回车键进入下级菜单,按Y键选中需要开启的功能,按N键选中需要关闭的功能,配置结束后保存并退出
|
||||
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210426212955727.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ViaXF1aXRvdXNUZWFt,size_16,color_FFFFFF,t_70#pic_center)
|
||||
|
||||
3.继续执行以下命令,进行编译
|
||||
|
||||
```bash
|
||||
make BOARD=stm32f407-st-discovery
|
||||
```
|
||||
|
||||
4.如果编译正确无误,会产生XiUOS_stm32f407-st-discovery.elf、XiUOS_stm32f407-st-discovery.bin文件。其中XiUOS_stm32f407-st-discovery.bin需要烧写到设备中进行运行。
|
||||
|
||||
## 3. 烧写及执行
|
||||
|
||||
将 BOARD=stm32f407-st-discovery开发板SWD经 st-link 转接到USB接口,然后使用st-flash工具进行烧写bin文件。
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021042716353240.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70#pic_center)
|
||||
|
||||
### 烧写工具
|
||||
|
||||
ARM:ST-LINK(ST-LINK V2实物如图,可在购物网站搜索关键字购买)
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210427144736126.png#pic_center)
|
||||
|
||||
下载并以下执行命令以下命令安装st-link工具(本文使用v1.5.1版本),下载地址为:[http://101.36.126.201:8011/stlink.zip](http://101.36.126.201:8011/stlink.zip)
|
||||
|
||||
```bash
|
||||
sudo apt install libusb-dev
|
||||
sudo apt install libusb-1.0-0-dev
|
||||
sudo apt install cmake
|
||||
cd stlink
|
||||
make
|
||||
cd build/Release && make install DESTDIR=_install
|
||||
```
|
||||
|
||||
将生成的st-flash(在stlink/build/Release/bin文件夹下)复制到/usr/bin下就可使用了
|
||||
|
||||
代码根目录下执行st-flash工具烧录
|
||||
|
||||
```bash
|
||||
sudo st-flash write build/XiUOS_stm32f407-st-discovery.bin 0x8000000
|
||||
```
|
||||
|
||||
此外,推荐用户使用putty作为终端工具,安装命令如下:
|
||||
|
||||
```bash
|
||||
sudo apt install putty
|
||||
```
|
||||
|
||||
打开putty配置串口信息
|
||||
|
||||
```bash
|
||||
sudo puty
|
||||
```
|
||||
|
||||
选择ttyUSB0(这个端口号根据具体情况而定),配置波特率为115200。
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021042815015872.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70#pic_center)
|
||||
|
||||
注意:选择正确的终端端口号,最后可以执行以下命令,清除配置文件和编译生成的文件
|
||||
|
||||
```bash
|
||||
make BOARD=stm32f407-st-discovery distclean
|
||||
```
|
||||
|
||||
### 3.1 运行结果
|
||||
|
||||
如果编译 & 烧写无误,将会在串口终端上看到信息打印输出,(终端串口引脚为PB6、PB7)。
|
||||
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210426213212239.PNG?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ViaXF1aXRvdXNUZWFt,size_16,color_FFFFFF,t_70#pic_center)
|
|
@ -1,458 +1,545 @@
|
|||
# 驱动模型
|
||||
|
||||
## 概述
|
||||
多数嵌入式操作系统对驱动的抽象采用以物理外设实体为中心的方式,采用驱动(driver)-设备(device)的模式开发驱动。这种抽象带来的缺陷在面对一些兼容多平台的操作系统开发驱动时尤为突出。
|
||||
多数嵌入式操作系统对驱动的抽象采用以物理外设实体为中心的方式,采用驱动(DRIVER)-设备(DEVICE)的模式开发驱动。这种抽象带来的缺陷在面对一些兼容多平台的操作系统开发驱动时尤为突出。
|
||||
|
||||
对于实时复杂的操作系统,代码的重用性非常重要,否则的话就会在操作系统内核中存在大量无意义的重复代码。尤其是驱动程序,因为驱动程序占用了操作系统代码量的绝大部分,如果不对驱动程序加以管理,任由重复的代码肆意增加,那么随着操作系统的发展,其文件数量就庞大到无法接受的地步,进而增加了驱动开发难度和周期。
|
||||
|
||||
以I2C接口的ATH10的温湿度传感器驱动为例,每种平台下都有一个主机驱动和设备驱动,主机驱动是必要的,它随着每个平台的IIC控制器不同而不同。但是对于不同平台下的同一个设备ATH10(温湿度传感器),没必要每个平台都写一个设备驱动,因为不管对于哪个架构的 SOC 来说, ATH10温湿度传感器都是一样,通过I2C接口读写数据就行了,只需要公用一个ATH10的驱动程序即可。基于上述思想,XiuOS将驱动进行分隔设计以求简化驱动的开发,采用驱动(driver)-总线(bus)-设备(device)的架构对驱动进行管理和组织。对于同一类设备,每个平台的同种外设控制器都提供一个统一的接口,即主机驱动。每个设备的话也只提供一个驱动程序(设备驱动),每个设备通过统一的 I2C接口驱动来访问,这样就可以大大简化驱动文件。
|
||||
针对这种情况,我们了解到对于嵌入式系统外设来说,不外乎几类常用的外设,如I2C外设、SPI外设、字符设备外设、块设备外设等,同一类外设使用的外设接口相同,这就意味着这类外设可以复用同一套DRIVER驱动代码和DEVICE操作代码。而对于上层应用来说,最理想的情况下是这类外设的接口控制器在不同SOC平台上可以复用,即应用程序通过统一的API接口操作外设,可以大大减少系统开发和维护工作量。
|
||||
|
||||
对于ATH10的温湿度传感器,我们只需要提供设备信息即可,比如设备连接到了哪个I2C 接口上,I2C的速度是多少等等。相当于将设备信息从设备驱动中剥离开来,驱动使用标准方法去获取到设备信息,然后根据获取到的设备信息来初始化设备。这样就相当于驱动只负责驱动,设备只负责设备,想办法将两者进行匹配即可,总线负责将驱动和设备信息链接起来。
|
||||
因此,XiUOS集成了一套BUS驱动模型,即利用一套BUS总线管理DEVICE设备和DRIVER驱动的框架,以BUS为基类,分发多种BUS子类对应一类外设,覆盖目前常使用的外设接口,如SPI_BUS、I2C_BUS、SERIAL_BUS等。以SPI_BUS总线为例,SPI_BUS总线创建后,首先会注册SPI_DRIVER驱动相关实现,之后系统接入的所有SPI_DEVICE都会注册挂载到SPI_BUS总线上,DRIVER驱动和DEVICE设备通过bus_name绑定上,实现设备和驱动相互对应的配置,这样即可实现用一套BUS数据结构管理其挂载的DEVICE设备和DRIVER驱动的目的。对于上层应用来说,通过获取SPI_BUS数据结构即可知道当前系统中挂载的SPI_DEVICE个数,利用BUS回调函数便可满足配置、数据交互需求,而不用关心具体的硬件细节,且底层新增或删减外设的操作由框架层统一管理,上层应用模块依旧可以复用,这套框架层次化管理界限清晰,驱动和应用解耦、复用功能凸显,应用层开发友好。
|
||||
|
||||
## 目录结构和框图
|
||||
* 驱动框架resources/xxx/文件目录结构
|
||||
|
||||
其中 xs_Bus 结构体被设计为可以采用类似面向对象的方法,它集合了所有总线的共有特征,为总线的基类。具体的总线以它为基类进行派生,如 xs_IIC_bus 、xs_USB_bus 、xs_SPI_bus 、xs_CAN_bus等。从而为众多不同性质的总线架构实现统一的管理架构。在应用开发的过程中只需要使用对应外设的总线实例,无需关心传感器的硬件细节,从而实现数据采样功能与底层硬件的解耦。
|
||||
| 文件名 | 描述 |
|
||||
| --- | --- |
|
||||
| bus.c | bus驱动框架实现,提供给上层应用调用 |
|
||||
| bus_xxx.c | xxx_bus子类实现,如spi_bus、i2c_bus、serial_bus等 |
|
||||
| dev_xxx.c | xxx_dev子类实现,如spi_dev、i2c_dev、serial_dev等 |
|
||||
| drv_xxx.c | xxx_drv子类实现,如spi_drv、i2c_drv、serial_drv等 |
|
||||
|
||||
xs_Device 结构体同样采用类似面向对象的方法,它集合了所有设备的共有特征,为设备的基类。平台上接入的具体设备以它为基类进行派生,如 IICHardwareDevice 、USBHardwareDevice 、SPIHardwareDevice 、CANHardwareDevice等。从而为众多不同性质的设备实现统一的管理架构。
|
||||
* 驱动框架框图(以SPI_Bus为例)
|
||||
|
||||
<img src="./imagesrc/spi_bus.png" width =100%/>
|
||||
|
||||
## 关键数据结构
|
||||
|
||||
* struct xs_Bus结构
|
||||
* struct Bus结构
|
||||
```c
|
||||
struct xs_Bus {
|
||||
char Bus_name[XS_NAME_MAX]; /* name of bus */
|
||||
enum xs_BusType type; /* type of bus */
|
||||
enum xs_BUSSTATE flag;
|
||||
list_head device;
|
||||
list_head driver;
|
||||
int (*match)(const struct xs_DeviceDriver * drv,const struct xs_Device dev);
|
||||
int (*probe)(void * bus);
|
||||
int (*remove)(void * bus);
|
||||
int (*shutdown)(void * bus);
|
||||
int (*resume)(void * bus);
|
||||
struct Bus
|
||||
{
|
||||
int8 bus_name[NAME_NUM_MAX];
|
||||
enum BusType bus_type;
|
||||
enum BusState bus_state;
|
||||
|
||||
int (bus_register)(void * bus);
|
||||
int (bus_unregister)(void * bus);
|
||||
void * private_data;
|
||||
};
|
||||
```
|
||||
Bus_name成员是一个可读的名字,用于唯一标识一个xs_Bus结构,
|
||||
type成员表示该xs_Bus为什么类型的总线,用一个枚举变量表示。
|
||||
```c
|
||||
enum xs_BusType {
|
||||
XS_IIC_BUS = 0, /* IIC */
|
||||
XS_SPI_BUS, /* SPI */
|
||||
XS_USB_BUS, /* USB */
|
||||
XS_CAN_BUS, /* CAN */
|
||||
/* ...... */
|
||||
XS_BUS_END,
|
||||
};
|
||||
```
|
||||
xs_BusType成员表示不同的总线类型,其具体定义在上文给出。
|
||||
int32 (*match)(struct Driver *driver, struct HardwareDev *device);
|
||||
|
||||
int bus_lock;
|
||||
|
||||
* enum Bus_priority枚举结构
|
||||
```c
|
||||
enum Bus_priority{
|
||||
PriorityLevelOne = 1,
|
||||
PriorityLevelTwo,
|
||||
PriorityLevelThree,
|
||||
PriorityLevelforth,
|
||||
PriorityLevelFive,
|
||||
PriorityLevelSix,
|
||||
PriorityLevelSeven
|
||||
};
|
||||
```
|
||||
Bus_priority变量表示总线优先级,数值越低优先级越高
|
||||
|
||||
|
||||
* struct xs_IIC_bus结构
|
||||
```c
|
||||
struct xs_I2CBus {
|
||||
struct xs_Bus bus; /* Basic properties of the bus */
|
||||
unsigned int speed; /* IIC communication rate*/
|
||||
};
|
||||
```
|
||||
speed成员记录I2C总线与传感器设备通信的速率
|
||||
|
||||
* struct xs_SPIBus结构
|
||||
```c
|
||||
struct xs_SPIBus {
|
||||
struct xs_Bus bus; /* Basic properties of the bus */
|
||||
enum Bus_priority priority /* Bus priority */
|
||||
unsigned char CPHA; /* SPI clock phase*/
|
||||
unsigned char CPOL; /* SPI clock polarity*/
|
||||
};
|
||||
```
|
||||
CPHA成员记录SPI总线的时钟相位,CPOL成员记录SPI总线的时钟极性
|
||||
|
||||
* struct xs_CANBus结构
|
||||
```c
|
||||
struct xs_CAN_bus {
|
||||
struct xs_Bus bus; /* Basic properties of the bus */
|
||||
enum Bus_priority priority /* Bus priority */
|
||||
unsigned int speed; /* CAN communication rate*/
|
||||
};
|
||||
```
|
||||
|
||||
* struct xs_USBBus结构
|
||||
```c
|
||||
struct xs_USB_bus {
|
||||
struct xs_Bus bus; /* Basic properties of the bus */
|
||||
enum Bus_priority priority /* Bus priority */
|
||||
unsigned int speed; /* USB communication rate*/
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
* struct xs_Device结构
|
||||
```c
|
||||
typedef struct xs_Device {
|
||||
char dev_name[XS_NAME_MAX]; /* name of device */
|
||||
enum xs_DeviceType type;
|
||||
struct mutex mut; /* Mutually Exclusive Semaphore*/
|
||||
xs_uint32 ref_count; /* the number of open */
|
||||
void * driver; /* Mounted driver*/
|
||||
struct device_ops ops; /* Device operation function set */
|
||||
struct xs_Device * prev;
|
||||
struct xs_Device * next;
|
||||
void * data;
|
||||
};
|
||||
};
|
||||
typedef struct xs_Device * xs_DevicePointer ;
|
||||
```
|
||||
|
||||
|
||||
|
||||
* struct device_ops结构
|
||||
```c
|
||||
struct device_ops{
|
||||
int (*init)(struct xs_Device * dev);
|
||||
int (*open)(struct xs_Device * dev);
|
||||
int (*close)(struct xs_Device * dev);
|
||||
int (*read)(struct xs_Device * dev, void * buf, int unm);
|
||||
int (*write)(struct xs_Device * dev, void *buf, int num);
|
||||
int (*ioctl)(struct xs_Device * dev, int cmd);
|
||||
}
|
||||
```
|
||||
device_ops包含统一的、类似文件系统的API,用于对具体外设进行实际的数据读写。如在使用一个传感器前后需要打开(open)/关闭(close)该传感器,read、write分别用与从传感器接收数据与向传感器发送数据,ioctl用于配置传感器属性(如波特率)
|
||||
|
||||
* struct xs_HardwareDev结构
|
||||
```c
|
||||
struct xs_HardwareDev{
|
||||
struct xs_Device dev;
|
||||
struct device_ops ops;
|
||||
|
||||
int (*probe)(struct xs_Device * dev);
|
||||
int (*remove)(struct xs_Device * dev);
|
||||
void (*shutdown)(struct xs_Device * dev);
|
||||
int (*suspend)(struct xs_Device * dev, int state);
|
||||
int (*resume)(struct xs_Device * dev);
|
||||
};
|
||||
```
|
||||
|
||||
* struct IICHardwareDevice结构
|
||||
```c
|
||||
struct IICHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
unsigned short IIC_addr;
|
||||
void * PrivData;
|
||||
}
|
||||
```
|
||||
|
||||
* struct SPIHardwareDevice结构
|
||||
```c
|
||||
struct SPIHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
unsigned short SPI_addr;
|
||||
void * PrivData;
|
||||
}
|
||||
```
|
||||
|
||||
* struct CANHardwareDevice结构
|
||||
```c
|
||||
struct CANHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
unsigned short CAN_addr;
|
||||
void * PrivData;
|
||||
}
|
||||
```
|
||||
|
||||
* struct USBHardwareDevice结构
|
||||
```c
|
||||
struct USBHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
unsigned short USB_addr;
|
||||
void * PrivData;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
* struct xs_DeviceDriver结构
|
||||
```c
|
||||
struct xs_DeviceDriver{
|
||||
char driver_name[XS_NAME_MAX];
|
||||
struct bus_type * bus;
|
||||
enum driver_state falg;
|
||||
struct HardwareDev *owner_haldev;
|
||||
struct Driver *owner_driver;
|
||||
|
||||
int (*add)(struct xs_DeviceDriver *dev);
|
||||
int (*remove)(struct xs_DeviceDriver *dev);
|
||||
int (*probe)(struct xs_HardwareDev *dev);
|
||||
void (*shutdown)(struct xs_HardwareDev *dev);
|
||||
struct list_drv{
|
||||
struct xs_DeviceDriver * prev;
|
||||
struct xs_DeviceDriver * next;
|
||||
void * data;
|
||||
};
|
||||
} Device_driver_head;
|
||||
```
|
||||
void *private_data;
|
||||
|
||||
/*manage the drv of the bus*/
|
||||
uint8 driver_cnt;
|
||||
uint8 bus_drvlink_flag;
|
||||
DoubleLinklistType bus_drvlink;
|
||||
|
||||
/*manage the dev of the bus*/
|
||||
uint8 haldev_cnt;
|
||||
uint8 bus_devlink_flag;
|
||||
DoubleLinklistType bus_devlink;
|
||||
|
||||
uint8 bus_cnt;
|
||||
uint8 bus_link_flag;
|
||||
DoubleLinklistType bus_link;
|
||||
};
|
||||
```
|
||||
* enum BusType枚举结构
|
||||
```c
|
||||
enum BusType
|
||||
{
|
||||
TYPE_I2C_BUS = 0,
|
||||
TYPE_SPI_BUS,
|
||||
TYPE_HWTIMER_BUS,
|
||||
TYPE_USB_BUS,
|
||||
TYPE_CAN_BUS,
|
||||
TYPE_WDT_BUS,
|
||||
TYPE_SDIO_BUS,
|
||||
TYPE_TOUCH_BUS,
|
||||
TYPE_LCD_BUS,
|
||||
TYPE_PIN_BUS,
|
||||
TYPE_RTC_BUS,
|
||||
TYPE_SERIAL_BUS,
|
||||
TYPE_BUS_END,
|
||||
};
|
||||
```
|
||||
|
||||
* enum BusState枚举结构
|
||||
```c
|
||||
enum BusState
|
||||
{
|
||||
BUS_INIT = 0,
|
||||
BUS_INSTALL,
|
||||
BUS_UNINSTALL,
|
||||
};
|
||||
```
|
||||
* struct HardwareDev结构
|
||||
```c
|
||||
struct HardwareDev
|
||||
{
|
||||
int8 dev_name[NAME_NUM_MAX];
|
||||
enum DevType dev_type;
|
||||
enum DevState dev_state;
|
||||
|
||||
const struct HalDevDone *dev_done;
|
||||
|
||||
int (*dev_recv_callback) (void *dev, x_size_t length);
|
||||
int (*dev_block_control) (struct HardwareDev *dev, struct HalDevBlockParam *block_param);
|
||||
|
||||
struct Bus *owner_bus;
|
||||
void *private_data;
|
||||
|
||||
int32 dev_sem;
|
||||
|
||||
DoubleLinklistType dev_link;
|
||||
};
|
||||
```
|
||||
* struct HalDevDone结构
|
||||
```c
|
||||
struct HalDevDone
|
||||
{
|
||||
uint32 (*open) (void *dev);
|
||||
uint32 (*close) (void *dev);
|
||||
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
|
||||
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
|
||||
};
|
||||
```
|
||||
HalDevDone包含统一的、类似文件系统的API,用于对具体外设进行实际的开关和数据读写。如在使用一个外设前后需要打开(open)/关闭(close)该外设,read、write分别用与从外设接收数据与向外设发送数据。
|
||||
* struct Driver结构
|
||||
```c
|
||||
struct Driver
|
||||
{
|
||||
int8 drv_name[NAME_NUM_MAX];
|
||||
enum DriverType driver_type;
|
||||
enum DriverState driver_state;
|
||||
|
||||
uint32 (*configure)(void *drv, struct BusConfigureInfo *configure_info);
|
||||
|
||||
struct Bus *owner_bus;
|
||||
void *private_data;
|
||||
|
||||
DoubleLinklistType driver_link;
|
||||
};
|
||||
```
|
||||
回调函数configure用于对具体外设进行实际的配置。
|
||||
|
||||
## 使用场景
|
||||
在获取i2c数据前,要匹配设备驱动,在设备驱动打开后对设备进行读写。使用完毕后,关闭设备驱动。
|
||||
在获取外设数据前,要先获取外设bus,匹配driver和device数据结构,若有需要应配置外设driver,在外设device打开后对外设进行读写,使用完毕后,关闭设备。
|
||||
|
||||
完整的使用过程示例如下:
|
||||
以SERIAL为例,完整的使用过程示例如下:
|
||||
```c
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
struct xs_I2cDevice *dev;
|
||||
int ret = EOK;
|
||||
char test_str[] = "Hello AIIT!\r\n";
|
||||
|
||||
/* find the i2c device instance */
|
||||
dev = (struct xs_I2cDevice*)xs_DeviceFind("i2c_temp",XS_IIC_BUS); //获取设备句柄
|
||||
if(dev == NULL)
|
||||
{
|
||||
xs_kprintf("find iic device error\n");
|
||||
struct Bus *bus;
|
||||
struct HardwareDev *dev;
|
||||
struct Driver *drv;
|
||||
|
||||
/* find the serial bus pointer */
|
||||
bus = BusFind(SERIAL_BUS_NAME);
|
||||
if (NONE == bus) {
|
||||
KPrintf("BusFind %s failed\n", SERIAL_BUS_NAME);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* find the serial driver pointer */
|
||||
drv = BusFindDriver(bus, SERIAL_DRV_NAME);
|
||||
if (NONE == drv) {
|
||||
KPrintf("BusFindDriver %s failed\n", SERIAL_DRV_NAME);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* find the serial device pointer */
|
||||
dev = BusFindDevice(bus, SERIAL_DEVICE_NAME);
|
||||
if (NONE == dev) {
|
||||
KPrintf("BusFindDevice %s failed\n", SERIAL_DEVICE_NAME);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* open the device instance */
|
||||
ret = xs_DeviceOpen(dev); //打开设备
|
||||
XS_ASSERT(ret == XS_EOK);
|
||||
/*step 1: init bus_driver, change struct SerialCfgParam if necessary*/
|
||||
struct SerialCfgParam serial_cfg;
|
||||
memset(&serial_cfg, 0, sizeof(struct SerialCfgParam));
|
||||
configure_info.configure_cmd = OPE_INT;
|
||||
configure_info.private_data = &serial_cfg;
|
||||
ret = BusDrvConfigure(drv, &configure_info);
|
||||
if (EOK != ret) {
|
||||
KPrintf("BusDrvConfigure OPE_INT failed error code %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* read temperature sensor data for 5 times */
|
||||
for (int i = 0; i < 5; i++)
|
||||
xs_kprintf("Current CO2 concentration is %u ppm\n", xs_DeviceRead(dev)); //读取设备数据
|
||||
xs_DeviceClose(dev); //关闭数据
|
||||
/*step 2: match serial bus_driver with bus_device*/
|
||||
bus->match(drv, dev);
|
||||
|
||||
return 0;
|
||||
/*step 3: open bus_device, configure struct SerialDevParam if necessary*/
|
||||
serial_dev_param->serial_set_mode = SIGN_OPER_INT_RX;
|
||||
serial_dev_param->serial_stream_mode = SIGN_OPER_STREAM;
|
||||
ret = BusDevOpen(dev);
|
||||
if (EOK != ret) {
|
||||
KPrintf("BusDevOpen failed error code %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*step 4: write serial data, configure struct BusBlockWriteParam*/
|
||||
struct BusBlockWriteParam write_param;
|
||||
write_param.pos = 0;
|
||||
write_param.buffer = (void *)test_str;
|
||||
write_param.size = sizeof(test_str) - 1;
|
||||
BusDevWriteData(bus_device, &write_param);
|
||||
|
||||
/*step 5: close bus_device*/
|
||||
BusDevClose(bus_device);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 函数接口
|
||||
### 设备初始化函数
|
||||
* BUS注册函数
|
||||
```c
|
||||
/**
|
||||
* This function will initialize the specified device
|
||||
*
|
||||
* @param dev the pointer of device driver structure
|
||||
*
|
||||
* @return the result
|
||||
*/
|
||||
xs_err_t xs_DeviceInit(xs_DevicePointer dev)
|
||||
{
|
||||
xs_err_t result = XS_EOK;
|
||||
|
||||
XS_ASSERT(dev != XS_NULL);
|
||||
|
||||
/*driver init*/
|
||||
if(dev->driver && dev->driver->flag & DRIVER_FLAG_MOUNTED){
|
||||
device_register(dev)
|
||||
if (!(dev->flag & DEVICE_FLAG_ACTIVATED))
|
||||
{
|
||||
result = device_init(dev);/* Macro */
|
||||
if (result != XS_EOK)
|
||||
{
|
||||
xs_kprintf("Initialize device:%s failed. The error code is %d\n",
|
||||
dev->name, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
dev->flag |= XS_DEVICE_FLAG_ACTIVATED;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
return DRIVER_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
### 设备查找函数
|
||||
|
||||
```c
|
||||
/**
|
||||
* This function finds a device driver by specified name.
|
||||
*/
|
||||
xs_DevicePointer xs_DeviceFind(const char *name)
|
||||
{
|
||||
enum xs_BusType e;
|
||||
xs_DevicePointer dev;
|
||||
for(e=0;e !=XS_BUS_END; ++e){
|
||||
if(dev = __xs_DeviceFind_by_type(name,e) && dev !=BUS_ERROR)
|
||||
return dev;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xs_DevicePointer xs_DeviceFind(const char *name,enum xs_BusType bus_type){
|
||||
return __xs_DeviceFind_by_type(name,bus_type);
|
||||
};
|
||||
|
||||
xs_DevicePointer __xs_DeviceFind_by_type(const char *name,enum xs_BusType bus_type)
|
||||
{
|
||||
struct xs_Device *device;
|
||||
struct xs_ListNode *node;
|
||||
|
||||
xs_Bus bus = get_bus_from_type(bus_type);
|
||||
if(!(bus && bus->falg = BUS_FLAG_ACTIVED))
|
||||
return BUS_ERROR;/*a point to speical area */
|
||||
|
||||
/* enter critical */
|
||||
if (xs_get_kthread_descriptor() != XS_NULL)
|
||||
xs_critical_enter();
|
||||
|
||||
/* try to find device */
|
||||
for (node = bus->device.next;
|
||||
node != &(bus->device);
|
||||
node = node->next)
|
||||
{
|
||||
device = xs_list_entry(node, struct xs_Device, list);
|
||||
if (xs_strncmp(device->name, name, XS_NAME_MAX) == 0)
|
||||
{
|
||||
/* leave critical */
|
||||
if (xs_get_kthread_descriptor() != XS_NULL)
|
||||
xs_critical_exit();
|
||||
|
||||
return (xs_DevicePointer)device;
|
||||
}
|
||||
}
|
||||
|
||||
/* leave critical */
|
||||
if (xs_get_kthread_descriptor() != XS_NULL)
|
||||
xs_critical_exit();
|
||||
|
||||
/* not found */
|
||||
return XS_NULL;
|
||||
}
|
||||
|
||||
```
|
||||
### 设备打开函数
|
||||
```c
|
||||
|
||||
/*
|
||||
* This function open a device
|
||||
* @Description: support to register bus pointer with linklist
|
||||
* @param bus - bus pointer
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
xs_err_t xs_DeviceOpen(xs_DevicePointer dev)
|
||||
int BusRegister(struct Bus *bus)
|
||||
{
|
||||
xs_err_t result = XS_EOK;
|
||||
x_err_t ret = EOK;
|
||||
NULL_PARAM_CHECK(bus);
|
||||
|
||||
XS_ASSERT(dev != XS_NULL);
|
||||
if(!(dev->bus))
|
||||
return BUS_ERROR;
|
||||
if(!(dev->driver && dev->bus->match(dev->driver,dev)))
|
||||
return DRIVER_ERROR;
|
||||
bus->match = BusMatchDrvDev;
|
||||
|
||||
/* if device is not initialized, initialize it. */
|
||||
if (!(dev->flag & DEVICE_FLAG_ACTIVATED))
|
||||
{
|
||||
xs_DeviceInit(dev);
|
||||
}
|
||||
BusLinkInit(bus);
|
||||
|
||||
/* call device_open interface */
|
||||
if (device_open != XS_NULL)
|
||||
{
|
||||
result = device_open(dev, oflag);
|
||||
dev->ref_count++;
|
||||
XS_ASSERT(dev->ref_count != 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
### 设备关闭函数
|
||||
bus->bus_lock = KMutexCreate();
|
||||
|
||||
```c
|
||||
xs_err_t xs_DeviceClose(xs_DevicePointer dev)
|
||||
{
|
||||
xs_err_t result = XS_EOK;
|
||||
DoubleLinkListInsertNodeAfter(&bus_linklist, &(bus->bus_link));
|
||||
|
||||
XS_ASSERT(dev != XS_NULL);
|
||||
|
||||
if (dev->ref_count == 0)
|
||||
return XS_ERROR;
|
||||
|
||||
dev->ref_count--;
|
||||
|
||||
if (dev->ref_count != 0)
|
||||
return XS_EOK;
|
||||
|
||||
/* call device_close interface */
|
||||
if (device_close != XS_NULL)
|
||||
{
|
||||
result = device_close(dev);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## i2c设备注册与卸载
|
||||
* BUS删除函数
|
||||
```c
|
||||
int int xs_I2cDeviceRegister(struct xs_I2cDevice *dev,const char *name, xs_uint16 flags);
|
||||
int xs_I2cDeviceunRegister(struct xs_I2cDevice *dev);
|
||||
/**
|
||||
* @Description: support to unregister bus pointer and delete its linklist node
|
||||
* @param bus - bus pointer
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
int BusUnregister(struct Bus *bus)
|
||||
{
|
||||
NULL_PARAM_CHECK(bus);
|
||||
|
||||
bus->bus_cnt--;
|
||||
|
||||
DoubleLinkListRmNode(&(bus->bus_link));
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
### xs_I2cDeviceRegister函数具体实现
|
||||
* DRIVER注册到BUS函数
|
||||
```c
|
||||
int xs_I2cDeviceRegister(struct xs_I2cDevice *dev,const char *name, xs_uint16 flags)
|
||||
/**
|
||||
* @Description: support to register driver pointer to bus pointer
|
||||
* @param bus - bus pointer
|
||||
* @param driver - driver pointer
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
int DriverRegisterToBus(struct Bus *bus, struct Driver *driver)
|
||||
{
|
||||
if(dev != NULL)
|
||||
{
|
||||
return xs_DeviceRegister(dev,name,0);
|
||||
}
|
||||
return -XS_ERROR;
|
||||
NULL_PARAM_CHECK(bus);
|
||||
NULL_PARAM_CHECK(driver);
|
||||
|
||||
driver->owner_bus = bus;
|
||||
bus->driver_cnt++;
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&bus->bus_drvlink, &(driver->driver_link));
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
xs_err_t xs_DeviceRegister(void * dev,const char *name, xs_uint16 flags)
|
||||
* DRIVER从BUS中删除函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to delete driver pointer from bus pointer
|
||||
* @param bus - bus pointer
|
||||
* @param driver - driver pointer
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
int DriverDeleteFromBus(struct Bus *bus, struct Driver *driver)
|
||||
{
|
||||
NULL_PARAM_CHECK(bus);
|
||||
NULL_PARAM_CHECK(driver);
|
||||
|
||||
if (dev == XS_NULL)
|
||||
return -XS_ERROR;
|
||||
bus->driver_cnt--;
|
||||
|
||||
if (xs_DeviceFind(name) != XS_NULL)
|
||||
return -XS_ERROR;
|
||||
DoubleLinkListRmNode(&(driver->driver_link));
|
||||
|
||||
xs_CriticalEnter();
|
||||
for (node = Device_driver_head.NodeNext;
|
||||
node != &(xiaoshan_device_head);
|
||||
node = node->NodeNext)
|
||||
free(driver);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
* DEVICE注册到BUS函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to register dev pointer to bus pointer
|
||||
* @param bus - bus pointer
|
||||
* @param device - device pointer
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
int DeviceRegisterToBus(struct Bus *bus, struct HardwareDev *device)
|
||||
{
|
||||
NULL_PARAM_CHECK(bus);
|
||||
NULL_PARAM_CHECK(device);
|
||||
|
||||
device->owner_bus = bus;
|
||||
bus->haldev_cnt++;
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&bus->bus_devlink, &(device->dev_link));
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
* DEVICE从BUS中删除函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to delete dev pointer from bus pointer
|
||||
* @param bus - bus pointer
|
||||
* @param device - device pointer
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
int DeviceDeleteFromBus(struct Bus *bus, struct HardwareDev *device)
|
||||
{
|
||||
NULL_PARAM_CHECK(bus);
|
||||
NULL_PARAM_CHECK(device);
|
||||
|
||||
bus->haldev_cnt--;
|
||||
|
||||
DoubleLinkListRmNode(&(device->dev_link));
|
||||
|
||||
free(device);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
* 查找BUS函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to find bus pointer by bus name
|
||||
* @param bus_name - bus name
|
||||
* @return successful:bus pointer,failed:NONE
|
||||
*/
|
||||
BusType BusFind(const char *bus_name)
|
||||
{
|
||||
struct Bus *bus = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &bus_linklist;
|
||||
|
||||
for (node = head->node_next; node != head; node = node->node_next)
|
||||
{
|
||||
struct xs_Device *device;
|
||||
|
||||
device = XS_DOUBLE_LINKLIST_ENTRY(node, struct xs_Device, link);
|
||||
if (device)
|
||||
{
|
||||
XS_ASSERT(device != dev);
|
||||
bus = SYS_DOUBLE_LINKLIST_ENTRY(node, struct Bus, bus_link);
|
||||
if(!strcmp(bus->bus_name, bus_name)) {
|
||||
return bus;
|
||||
}
|
||||
}
|
||||
xs_CriticalExit();
|
||||
xs_strncpy(dev->dev_string, name, XS_NAME_MAX);
|
||||
register xs_base temp = xs_DisableHwInterrupt();
|
||||
{
|
||||
xs_DoubleLinkListInsertNodeAfter(&xiaoshan_device_head, &(dev->link));
|
||||
}
|
||||
xs_EnableHwInterrupt(temp);
|
||||
dev->sign = flags;
|
||||
dev->call_cnt = 0;
|
||||
dev->status = 0;
|
||||
xs_InitWqueue(&(dev->wait_queue));
|
||||
return XS_EOK;
|
||||
|
||||
KPrintf("BusFind cannot find the %s bus.return NULL\n", bus_name);
|
||||
return NONE;
|
||||
}
|
||||
```
|
||||
|
||||
* 查找DRIVER函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to find driver pointer of certain bus by driver name
|
||||
* @param bus - bus pointer
|
||||
* @param driver_name - driver name
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
DriverType BusFindDriver(struct Bus *bus, const char *driver_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(bus);
|
||||
struct Driver *driver = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &bus->bus_drvlink;
|
||||
|
||||
for (node = head->node_next; node != head; node = node->node_next)
|
||||
{
|
||||
driver = SYS_DOUBLE_LINKLIST_ENTRY(node, struct Driver, driver_link);
|
||||
if(!strcmp(driver->drv_name, driver_name)) {
|
||||
return driver;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("BusFindDriver cannot find the %s driver.return NULL\n", driver_name);
|
||||
return NONE;
|
||||
}
|
||||
```
|
||||
|
||||
* 查找DEVICE函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to find device pointer of certain bus by device name
|
||||
* @param bus - bus pointer
|
||||
* @param device_name - device name
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
HardwareDevType BusFindDevice(struct Bus *bus, const char *device_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(bus);
|
||||
struct HardwareDev *device = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &bus->bus_devlink;
|
||||
|
||||
for (node = head->node_next; node != head; node = node->node_next)
|
||||
{
|
||||
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link);
|
||||
|
||||
if(!strcmp(device->dev_name, device_name)) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("BusFindDevice cannot find the %s device.return NULL\n", device_name);
|
||||
return NONE;
|
||||
}
|
||||
```
|
||||
|
||||
* 打开DEVICE函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to open dev
|
||||
* @param dev - dev pointer
|
||||
* @return successful:EOK,failed:ERROR
|
||||
*/
|
||||
uint32 BusDevOpen(struct HardwareDev *dev)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (dev->dev_done->open) {
|
||||
ret = dev->dev_done->open(dev);
|
||||
if(ret) {
|
||||
KPrintf("BusDevOpen error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
|
||||
* 关闭DEVICE函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to close dev
|
||||
* @param dev - dev pointer
|
||||
* @return successful:EOK,failed:ERROR
|
||||
*/
|
||||
uint32 BusDevClose(struct HardwareDev *dev)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (dev->dev_done->close) {
|
||||
ret = dev->dev_done->close(dev);
|
||||
if(ret) {
|
||||
KPrintf("BusDevClose error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
|
||||
* DEVICE写函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to write data to dev
|
||||
* @param dev - dev pointer
|
||||
* @param write_param - BusBlockWriteParam
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
uint32 BusDevWriteData(struct HardwareDev *dev, struct BusBlockWriteParam *write_param)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
|
||||
if (dev->dev_done->write) {
|
||||
return dev->dev_done->write(dev, write_param);
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
* DEVICE读函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to read data from dev
|
||||
* @param dev - dev pointer
|
||||
* @param read_param - BusBlockReadParam
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
uint32 BusDevReadData(struct HardwareDev *dev, struct BusBlockReadParam *read_param)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
|
||||
if (dev->dev_done->read) {
|
||||
return dev->dev_done->read(dev, read_param);
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
```
|
||||
|
||||
* DRIVER配置函数
|
||||
```c
|
||||
/**
|
||||
* @Description: support to configure drv, include OPE_CFG and OPE_INT
|
||||
* @param drv - drv pointer
|
||||
* @param configure_info - BusConfigureInfo
|
||||
* @return successful:EOK,failed:NONE
|
||||
*/
|
||||
uint32 BusDrvConfigure(struct Driver *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
NULL_PARAM_CHECK(configure_info);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (drv->configure) {
|
||||
ret = drv->configure(drv, configure_info);
|
||||
if(ret) {
|
||||
KPrintf("BusDrvCfg error, ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
|
|
After Width: | Height: | Size: 37 KiB |