runtime_accessor:Encapsulate the operations of the hardware component drivers and buses, then provide to hwproxy to access the hardware resources

Encapsulate the operations of the hardware component drivers and buses, then provide to hwproxy to access the hardware resources

Branch3Tags11
FilesLast commitLast update
1 month ago
3 months ago
3 months ago
10 days ago
3 months ago
10 days ago
10 days ago
3 months ago
19 days ago
3 months ago
3 months ago
10 days ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago

runtime_accessor

支持将外围器件(如PCA9555, EEPROM,Lm75等)的接口库独立代码仓,支持组件化交付。

1. 功能简介


基于libsoc_adapter提供的用户态驱动接口,将针对外围器件(如PCA9555, EEPROM,Lm75等)和总线(如I2c、Hisport、LocalBus等)的操作进一步封装,供hwproxy组件使用。

graph LR
    subgraph 驱动库
        runtime_accessor
        libsoc_adapter
    end

    subgraph 框架应用
        hwproxy
    end

    libsoc_adapter-->runtime_accessor
    runtime_accessor-->hwproxy

2. 关键特性


将针对外围器件(如PCA9555, EEPROM,Lm75等)和总线(如I2c、Hisport、LocalBus等)的操作进一步封装,供hwproxy组件使用,支持组件化交付

3. 对外接口


3.1 器件和总线操作接口


器件操作接口分为

  1. driver
    • 代码位置:runtime_accessor/src/lualib/driver
    • 说明:封装了各个器件(例如lm75)的读写接口
  2. mux:
    • 代码位置:runtime_accessor/src/lualib/mux
    • 说明:封装了多路复用Mux器件(例如pca9545)的打开和关闭通道接口
  3. protocol
    • 代码位置:runtime_accessor/src/lualib/protocol
    • 说明:封装了协议包装接口(例如smc)

总线接口

  1. stream
    • 代码位置:runtime_accessor/src/lualib/stream
    • 说明:封装了总线(例如I2c、Hisport)读写接口

类图

classDiagram
    class Dispatch {
        +scanners: object<Scanner>
        +run()
    }

    class Scanner {
        +bus: object<Bus>
        +chips: table<Chip>
    }

    class Chip {
        +l_chip: object<Chip>
        +r_chips: table<Chip>
        +accessors: object<Accessor>
        +position: int
        +driver: object<Driver>
        +protocol: object<Protocol>
        +mux: object<Mux>
    }

    class Bus {
        +name: string
        +id: int
        +write()
        +read()
    }

    class Stream
    <<interface>> Stream
    Stream : +read()
    Stream : +write()

    class Localbus {
        +read()
        +write()
    }

    class I2c {
        +read()
        +write()
    }

    class Accessor {
        +name: string
        +offset: int
        +size: int
        +mask: int
        +type: int
        +resources: object<Resource>
    }

    class Resource {
        +uri: string
        +property:string
        +period: int
        +priority: int
    }

    class DataWindow
    <<interface>> DataWindow
    DataWindow : +calcu()

    class Uniform {
        +calcu()
    }

    class Merge {
        +calcu()
    }

    Dispatch "n" o-- "1" Scanner
    Scanner "n" o-- "1" Chip

    Stream <|.. Localbus : Realization
    Stream <|.. I2c : Realization

    Bus "1" *-- "1" Stream
    Scanner "1" o-- "1" Bus

    Resource "n" --o "1" Accessor
    Chip "1" o-- "n" Accessor

    DataWindow <|.. Uniform : Realization
    DataWindow <|.. Merge : Realization

    Chip "1" o-- "1" DataWindow

    class Mux
    <<interface>> Mux
    Mux : +open_channel()
    Mux : +close_channel()

    class Pca9545 {
        +open_channel()
        +close_channel()
    }

    class Pca9544 {
        +open_channel()
        +close_channel()
    }

    class Driver    {
        +host_bus: object<Bus>
        +own_ship: object<Chip>
        +read()
        +write()
    }
    <<interface>> Driver

    class Lm75 {
        +read()
        +write()
    }

    class Eeprom {
        +read()
        +write()
    }

    class Protocol
    <<interface>> Protocol
    Protocol : +wrap()

    class Smc {
        +wrap()
    }

    Mux <|.. Pca9545 : Realization
    Mux <|.. Pca9544 : Realization
    Driver <|.. Lm75 : Realization
    Driver <|.. Eeprom : Realization
    Protocol <|.. Smc : Realization

    Chip "1" o-- "1" Mux
    Chip "1" *-- "1" Driver
    Chip "1" o-- "1" Protocol

3.2 如何新增器件操作接口

如需新增器件操作接口,可参考runtime_accessor/src/lualib/driver/lm75.lua:

-- 1. 在runtime_accessor/src/lualib/driver新增lua文件,并定义新的器件类

---@class lm75
---@field read function
---@field write function
local lm75 = class(driver)

-- 2. 实现读接口
function lm75:read(input)

-- 3. driver对象(runtime_accessor/src/lualib/driver/base.lua)会进行协议包装,最终调用前级总线的读方法
function Driver:read(input)

4. 架构设计

4.1 核心组件

组件 文件 职责
driver src/lualib/driver/*.lua 器件驱动封装(lm75, eeprom, pca9555等)
mux src/lualib/mux/*.lua 多路复用器驱动(pca9545, pca9544等)
protocol src/lualib/protocol/*.lua 协议包装(smc等)
stream src/lualib/stream/*.lua 总线接口(i2c, hisport, localbus等)
base src/lualib/driver/base.lua 驱动基类

4.2 目录结构

runtime_accessor/
├── src/lualib/
│   ├── driver/       # 器件驱动(lm75, eeprom, cpld等)
│   ├── mux/          # 多路复用器驱动
│   ├── protocol/     # 协议封装
│   └── stream/       # 总线接口(I2C, Hisport, LocalBus等)
└── gen/              # 自动生成代码

5. 贡献

欢迎提交 Issue 和 Pull Request。

详细的贡献规范请参阅 openUBMC 社区贡献指南。

6. 许可协议

runtime_accessor 采用 Mulan PSL v2 开源协议。

详情请参阅:http://license.coscl.org.cn/MulanPSL2

7. 支持

此开源项目非华为产品,仅提供有限支持。

如果有任何问题、建议、或者发现任何 bug,请在 Issues 页面提交一个新的 Issue。详细的描述可以帮助我们快速理解并解决问题。

也欢迎通过邮件方式与我们进行交流。community@public.openubmc.cn

Introduction

Encapsulate the operations of the hardware component drivers and buses, then provide to hwproxy to access the hardware resources

Customize your domain