Renode:通过插件(plugin)导入自定义外设

Renode:通过插件(plugin)导入自定义外设

Renode 的 include 命令可以动态加载 .cs 文件,使用这个特性可以导入自定义外设,可以自行编写 Renode 安装包未包含的外设,然后通过 include 命令导入就可以使用了。

https://blog.csdn.net/zoomdy/article/details/95492804
zoomdy at 163 dot com

编写自定义外设

用 C# 编写自定义外设模拟器,这要按照一定的规则,可以参考 renode/src/Infrastructure/src/Emulator/Peripherals/Peripherals/ 目录下的 C# 源文件编写。

// STM32_UART2.cs
using System;
using Antmicro.Renode.Core;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Bus;
using System.Collections.Generic;
using Antmicro.Migrant;
using Antmicro.Renode.Core.Structure.Registers;

namespace Antmicro.Renode.Peripherals.UART
{
    [AllowedTranslations(AllowedTranslation.WordToDoubleWord | AllowedTranslation.ByteToDoubleWord)]
    public class STM32_UART2 : STM32_UART
    {
        public STM32_UART2(Machine machine, uint frequency = 8000000) : base(machine)
        {
            this.frequency = frequency;
        }



        public override void Reset()
        {
            base.Reset();
            // receiveFifo.Clear();
            this.Log(LogLevel.Warning, "Reseting...");
        }

        private readonly uint frequency;
    }
}

在 Monitor 中导入自定义外设 cs 文件

include @STM32_UART2.cs

在平台定义文件中引用自定义外设

编辑 test-plugin.repl 文件,引用 STM32_UART2,然后在 Monitor 中引入对应的 repl 文件。

// test-plugin.repl
fscmBank1: Memory.MappedMemory @ sysbus 0x60000000
    size: 0x10000000

sram: Memory.MappedMemory @ sysbus 0x20000000
    size: 0x00040000

flash: Memory.MappedMemory @ sysbus 0x08000000
    size: 0x200000

uart1: UART.STM32_UART @ sysbus <0x40011000, +0x100>
    -> nvic@37

uart2: UART.STM32_UART @ sysbus <0x40004400, +0x100>
    -> nvic@38

uart3: UART.STM32_UART2 @ sysbus <0x40004500, +0x100>
    -> nvic@38
   
nvic: IRQControllers.NVIC @ sysbus 0xE000E000
    systickFrequency: 72000000
    IRQ -> cpu@0

cpu: CPU.CortexM @ sysbus
    cpuType: "cortex-m4"
    nvic: nvic

创建 machine

创建 machine 并引入使用了自定义外设的平台定义文件。

mach create 
machine LoadPlatformDescription @test-plugin.repl

查看自定义外设

使用 peripherals 命令查看外设,最后的 uart3 是自定义外设。

(machine-0) peripherals 
Available peripherals:
  sysbus (SystemBus)
  │   
  ├── cpu (CortexM)
  │     Slot: 0
  │       
  ├── flash (MappedMemory)
  │     <0x08000000, 0x081FFFFF>
  │       
  ├── fscmBank1 (MappedMemory)
  │     <0x60000000, 0x6FFFFFFF>
  │       
  ├── nvic (NVIC)
  │     <0xE000E000, 0xE000EFFF>
  │       
  ├── sram (MappedMemory)
  │     <0x20000000, 0x2003FFFF>
  │       
  ├── uart1 (STM32_UART)
  │     <0x40011000, 0x400110FF>
  │       
  ├── uart2 (STM32_UART)
  │     <0x40004400, 0x400044FF>
  │       
  └── uart3 (STM32_UART2)
        <0x40004500, 0x400045FF>

执行自定义外设的操作

调用 uart3 的 Reset 操作,可以看到日志窗口输出正是自定义外设源文件中编写的那样。

(machine-0) sysbus.uart3 Reset

日志窗口输出

16:59:03.4677 [WARNING] uart3: Reseting.

可能发生的错误

执行 include 命令时可能会发生错误:

Error running mcs: Cannot find the specified file

如果是 renode-1.11.0.linux-portable ,这个版本没有包含编译环境,因此报告这个错误,这个版本需要安装 mono 开发环境才可以 include *.cs
换成 renode-1.12.0.linux-portable 就可以了,这个版本包含了编译环境了。
1.12.0 的发行日志是这么描述的:

ad hoc C# compilation now uses the same, bundled compiler on all OSes, also allowing for compilation in the portable Linux package.
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释下面代码功能#include<iostream> #include<cstring> #include<cmath> using namespace std; int Node[50]; int number; int Calculate(char x)//计算偏移 { if(x>=97&&x<=122) return 0; switch(x) { case '!': case '^': case '(': case ')': return 1; case '|': case '-': return 2; case '<': return 3; default: return 1; } } int CalculateOut(string &Word,int n,int m)//输出||、->、<->,等等 { int i; if(m!=0) { for(i=1; i<m; i++)cout<<Word[n+i]; if(Word[i+n]!='\0') cout<<" "; } } int Input(string &Word)//输出数据 { int m,i,tag,q; number=0; for(i=0; Word[i]!='\0'; ) { q=i; if(Word[i]==' ') { i++; continue; } cout<<Word[i]; tag=Calculate(Word[i]); CalculateOut(Word,i,tag); i+=tag;//偏移 if(!tag)//数字计数 { Node[Word[q]-97]++; number++; if(Word[i+1]!='\0') cout<<" "; i++; } } cout<<endl; return number; } int Bin(int n,int m) { int bin[10000]; int a,b,i=0; do { a=n%2; n/=2; bin[i++]=a; } while(n>0); for(n=0; n<m-i; n++) { cout<<"0 "; } for(n=i-1; n>=0; n--) { cout<<bin[n]; if(n) cout<<" "; } } int Outnumber(int n) { int i,m=1; for(i=1; i<n; i++) { m=m*2+1; } for(i=m; i>=0; i--) { Bin(i,n); cout<<endl; } } void CoutNode() { int i,temp=0; for(i=0; i<50; i++) { if(temp==0&&Node[i]!=0) { cout.put(97+i); temp++; } else if(Node[i]!=0) { cout<<" "; cout.put(97+i); temp++; } } number=temp; cout<<endl; } int ReNode()//初始化 { for(int i=0; i<110; i++) Node[i]=0; } int Turn(char Map[400],string &Word) { int n,i; for(i=0,n=0;i<=strlen(Map);i++) { if(Map[i]!=' ') { Word[n]=Map[i]; n++; } } Word[n]='\0'; } int main() { int n,i; string Word; char Map[400]; while(gets(Map)!=NULL)//输入 { ReNode(); Turn(Map,Word); Input(Word); CoutNode(); Outnumber(number); } // Bin(2); }
06-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值