Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocketchip学习笔记3:如何添加设备(加速器),挂载流程:cake pattern 解析 #25

Open
meton-robean opened this issue Nov 30, 2019 · 7 comments

Comments

@meton-robean
Copy link
Owner

meton-robean commented Nov 30, 2019

概述

拓展rocketchip时,经常需要将我们编写的设备或者加速器挂载到rocket的总线上,这个过程包含了:

  • module的编写

  • module封装成trait

  • 将我们的traits混入rocket system变成一个整体(其实是编写module层面的TopWIthModule的配置class)

  • 进一步生成rocket层面的顶层配置类

  • 将配置class实例化后添加到rocket的默认配置之上

这就是rocket的一种可拓展的模块化配置 编程模式,叫做cake pattern

  • 下面以挂载一个pwm外设模块为例:

https://chipyard.readthedocs.io/en/dev/Customization/Adding-An-Accelerator.html#mmio-peripheral
这个例子详细讲解了cake pattern,值得参考学习

Repository owner locked and limited conversation to collaborators Nov 30, 2019
@meton-robean
Copy link
Owner Author

meton-robean commented Nov 30, 2019

1.module的编写

image

  • 将我们实现的PWMModule(这里没展示实现代码)用TLRegisterRouter封装起来,这样PWMTL就相当于一个外设模块(自动实现了tilelink,并且是作为client node)

@meton-robean
Copy link
Owner Author

meton-robean commented Nov 30, 2019

2.module封装成trait

Selection_004
Selection_005

  • trait一般成对实现,命名上很有规律。

  • 其中HasPeripheryPWMTL将我们的外设module和pbus连接了

  • HasPeripheryPWMTLModuleImp定义了外设的一个输出(具体做什么要看你设备的需要了)

@meton-robean
Copy link
Owner Author

meton-robean commented Nov 30, 2019

3.将我们的traits混入rocket system变成一个整体

Selection_006

  • 也是成对出现

  • 前一步的trait混入这两个类

  • 其实是编写module层面的TopWIthModule的配置class,实例化后是一个封装了的lazy module

@meton-robean
Copy link
Owner Author

meton-robean commented Nov 30, 2019

4.进一步生成rocket层面的顶层配置类

Selection_007

  • 这次是rocket层面的配置类编写(封装累加了上一步的东西,像蛋糕一样)

  • 这里利用case模板匹配,这里的case本质上是偏函数(scala语法),这样做是为了在最顶层,也就是下一步可以自由的进行参数化配置(改一次参数配置,就可以通过隐式参数的方式传给下一级,直到最底层module,而不用到处改参数)

@meton-robean
Copy link
Owner Author

5.将配置class实例化后添加到rocket的默认配置之上

Selection_008

  • 这是cake中的最顶层配置了

  • 当然这里没有在最顶层进行参数话设置,这个例子简单不需要。另一个例子,DMA例子:【链接】里面就在最顶层进行了参数配置:
    image

@meton-robean
Copy link
Owner Author

@meton-robean
Copy link
Owner Author

cake pattern更多资料

wiki:https://github.com/Intensivate/learning-journey/wiki/Cake-Pattern

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant