上传文件至「/」

更新毫秒计数
This commit is contained in:
2026-04-22 14:01:40 +08:00
parent dda997df24
commit 9ee6d96eff
3 changed files with 361 additions and 0 deletions

163
Custom_MS.cs Normal file
View File

@@ -0,0 +1,163 @@
//
// UART 外设实现
// 基于 UART 规格,包含完整的 FIFO、中断和调制解调器控制功能
//
using System;
using System.Collections.Generic;
using Antmicro.Renode.Core;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Bus;
using Antmicro.Renode.Peripherals.UART;
using Antmicro.Renode.Utilities;
using Antmicro.Renode.Time;
namespace Antmicro.Renode.Peripherals.CustomPeripherals
{
/// <summary>
/// 毫秒计数器
/// </summary>
public class Custom_MS : IDoubleWordPeripheral, IKnownSize
{
private readonly IMachine machine;
public Custom_MS(IMachine machine)
{
this.machine = machine;
// 初始化寄存器
DefineRegisters();
Reset();
this.Log(LogLevel.Info, "Custom_MS initialized");
// 启动后台计时任务
// StartCountingTask();
}
public void Reset()
{
ms_cnt = 0; // 毫秒计数
rstr = 0x00; // 复位/使能寄存器
startTime = machine.ElapsedVirtualTime; //记录启动时间
this.Log(LogLevel.Info, "Custom_MS reset, startTime={0}", startTime.TimeElapsed);
}
void get_msCnt()
{
TimeStamp currentTime = machine.ElapsedVirtualTime;
TimeInterval timeDifference = currentTime.TimeElapsed - startTime.TimeElapsed;
double timeDiffMs = timeDifference.TotalMilliseconds;
// ms_cnt = (ushort)(timeDiffMs % 1000);
ms_cnt = (ushort)timeDiffMs;
this.Log(LogLevel.Info, "Custom_MS currentTime={0}", currentTime.TimeElapsed);
this.Log(LogLevel.Info, "Custom_MS timeDiffMs={0}", timeDiffMs);
}
private void DefineRegisters()
{
// 寄存器访问通过 ReadDoubleWord/WriteDoubleWord 实现
}
// ========================================
// IBusPeripheral 接口实现
// ========================================
public uint ReadDoubleWord(long offset)
{
return ReadRegisters(offset);
}
public void WriteDoubleWord(long offset, uint value)
{
WriteRegisters(offset, value);
}
// ========================================
// 自定义
// ========================================
public uint ReadRegisters(long offset)
{
uint value = 0;
switch (offset)
{
case (long)Registers.CNT_REG: // 毫秒延迟计时
get_msCnt();
value = (uint)ms_cnt;
this.Log(LogLevel.Info, "Read CNT_REG: {0}", value);
break;
case (long)Registers.RSTR_REG: // 复位/使能,暂无读操作
value = (uint)(rstr & 0xFF);
this.Log(LogLevel.Info, "Read RSTR_REG: 0x{0}", value);
break;
default:
this.Log(LogLevel.Warning, "Read to unknown offset: 0x{0:X}", offset);
break;
}
return value;
}
public void WriteRegisters(long offset, uint value)
{
switch (offset)
{
case (long)Registers.RSTR_REG: // 复位/使能,暂无读操作
rstr = (byte)(value & 0xFF);
this.Log(LogLevel.Info, "Write RSTR_REG: 0x{0:X2}", rstr);
if ((rstr & 0XFF) == RSTR_RES)
{
Reset();
}
break;
default:
this.Log(LogLevel.Warning, "Write to unknown offset: 0x{0:X}", offset);
break;
}
}
public long Size => 0x80; //uart地址长度总空间
// ========================================
// 寄存器定义
// ========================================
private enum Registers : long
{
CNT_REG = 0x00, // 毫秒延迟计时
RSTR_REG = 0x7C // 复位/使能 0x55复位清零其他使能
}
// RSTR 复位/使能寄存器
private const byte RSTR_RES = 0x55; // 0x55复位清零其他使能
// ========================================
// 私有字段
// ========================================
private TimeStamp startTime; // 记录累加器启动时间
// 寄存器
private ushort ms_cnt; // FIFO状态寄存器
private byte rstr; // 复位/使能
}
}

136
generated_yyq.repl Normal file
View File

@@ -0,0 +1,136 @@
// Simple platform with LEON_Control_Regs_SIMPLE
sysbus:
Endianess: Endianess.BigEndian
//cpu: CPU.Sparc @ sysbus
cpu: CPU.Sparc @ sysbus
cpuType: "leon3"
rom: Memory.MappedMemory @ sysbus 0x00000000
size: 0x20000
ddr: Memory.MappedMemory @ sysbus 0x40000000
size: 0x20000000
sdram: Memory.MappedMemory @ sysbus 0x60000000
size: 0x10000000
ahbInfo: Bus.GaislerAHBPlugAndPlayInfo @ sysbus <0xfffff000, +0xfff>
apbController: Bus.GaislerAPBController @ sysbus <0x800ff000, +0xfff>
// Use simplified LEON Control Regs
//leonRegs: Miscellaneous.LEON_Control_Regs_SIMPLE @ sysbus 0x80000000
// MIC at the address VxWorks expects (0x80000090)
// Note: GaislerMIC needs a range, so we use <base, +size> syntax
//mic: IRQControllers.GaislerMIC @ sysbus <0x80000090, +0x10>
// 0 -> cpu@0 | cpu@1 | cpu@2
// 0 -> cpu@0
mic: IRQControllers.GaislerMIC @ sysbus <0x80000200, +0x100>
0 -> cpu@0 | cpu@1 | cpu@2
//ioRegs: Miscellaneous.Simple_IO_Regs @ sysbus 0x800000A0
// TimeSliceIRQ -> mic@4
uart: UART.GaislerAPBUART @ sysbus <0x80000100, +0x100>
-> mic@2
timer: Timers.Gaisler_GPTimer @ sysbus 0x80000300
// 0 -> mic@8
0 -> mic@8
numberOfTimers: 2
separateInterrupts: false
frequency: 50000000
eth: Network.GaislerEth @ sysbus 0x80000B00
-> mic@12
gpio: GPIOPort.Gaisler_GPIO @ sysbus 0x80000800
numberOfConnections: 16
numberOfInterrupts: 1
rtc: Timers.Custom_RTC_R17V1 @sysbus 0x20800D80
lc3233IntCtrl:IRQControllers.LC3233_InterruptController @sysbus 0x80020000
4 -> mic@4
5 -> mic@5
10 -> mic@10
8 -> mic@8
13 -> mic@13
lc3233Timer:Timers.LC3233_TaskTimer @ sysbus 0x80000000
IRQ -> lc3233IntCtrl@4
can_a:CustomPeripherals.SJA1000_CAN @sysbus 0xC0000000
IRQ -> lc3233IntCtrl@10
can_b:CustomPeripherals.SJA1000_CAN @sysbus 0xD0000000
IRQ -> lc3233IntCtrl@5
//TimerTrigger:Timers.TaskTimer @ sysbus 0x80002000
// IRQ -> lc3233IntCtrl@4
adc0: ADUADC0.ADU0 @ sysbus 0x21800000
adc1: ADUADC1.ADU1 @ sysbus 0x21800800
adc2: ADUADC2.ADU2 @ sysbus 0x21801000
adc3: ADUADC3.ADU3 @ sysbus 0x21C00000
adc4: ADUADC4.ADU4 @ sysbus 0x21C00800
adc5: ADUADC5.ADU5 @ sysbus 0x21C01000
oc1: ThermalOC1.ThermalOC1 @ sysbus 0x22000000
oc2: ThermalOC2.ThermalOC2 @ sysbus 0x22400000
oc_SIU1:OCModule.OC_LIMSIU64 @ sysbus 0x21400000
oc_SIU2:OCModule_1.OC_LIMSIU64_1 @ sysbus 0x21400020
uart0: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800000 //光纤陀螺A
uart1: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800080 //光纤陀螺B
uart2: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800100 //陀螺C
uart3: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800180 //激光探测仪
uart4: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800200 //暂无
uart5: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800280 //暂无
uart6: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800300 //陀螺A
uart7: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800380 //陀螺B
uart8: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800400 //陀螺C
uart9: CustomPeripherals.UART_771_RUHW_2CFG3 @ sysbus 0x20800480 //星敏B,A3
uart10: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800500 //星敏C
uart11: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800580 //天气效应1-Jcydrl
uart12: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800600 //天气效应3-Jcydr2
uart13: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800680 //天气效应3-Jcydr3
uart14: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800700 //智能载荷1未使用
uart15: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800780 //智能载荷2未使用
uart16: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800800 //MHI预留1
uart17: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800880 //MHI预留2
uart18: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800900 //亚角秒星敏2
uart19: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800980 //亚角秒星敏1
uart20: CustomPeripherals.UART_771_RUHW_2CFG3 @ sysbus 0x20800A00 //亚角秒星敏接收/ 工程遥测主 gcyc[0] ,A3
uart21: CustomPeripherals.UART_771_RUHW_2CFG3 @ sysbus 0x20800A80 //星敏B接收2/工程遥测备 gcyc[1] ,A3
uart22: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800B00 //复接重构主
uart23: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800B80 //复接重构备
uart24: CustomPeripherals.UART_771_RUHW_2CFG4 @ sysbus 0x20800C00 //地测串口, A4
IRQ -> lc3233IntCtrl@8
uart25: CustomPeripherals.UART_771_RUHW_2CFG1 @ sysbus 0x20800C80 //GPS串口
uart26: CustomPeripherals.UART_771_RUHW_2CFG2 @ sysbus 0x20C00000 //高速通信, A2
uart27: CustomPeripherals.UART_771_RUHW_2CFG5 @ sysbus 0x20800E80 //USB-A遥控, A5
uart28: CustomPeripherals.UART_771_RUHW_2CFG5 @ sysbus 0x20800F00 //USB-B遥控, A5
uart29: CustomPeripherals.UART_771_RUHW_2CFG5 @ sysbus 0x20800F80 //高速通信机遥控, A5
uart30: CustomPeripherals.UART_771_RUHW_2CFG6 @ sysbus 0x20800E00 //遥测, A6
IRQ -> lc3233IntCtrl@13
//timer1: Timers1.TimeSlice_Timer_v2.cs @ sysbus 0x80000000
// txInterrupt -> mic@2
time_ms: CustomPeripherals.Custom_MS @ sysbus 0x20801500
// 毫秒计数器, Custom_MS

62
generated_yyq.resc Normal file
View File

@@ -0,0 +1,62 @@
# Renode Simulation Script - Auto Generated
# Generated: 2026-01-06 14:19:56
# Architecture: SPARC V8 / Leon3
using sysbus
# Load peripherals
include @LEON_Control_Regs_SIMPLE.cs
#include @Custom_RTC_R17V1_CORRECT_ADDR.cs
#include @Simple_IO_Regs.cs
include @LC3233_Timer_InterruptController_NO3.cs
#include @Custom_ADC_R17V1.cs
include @Custom_TLZA_Rwa.cs
include @Custom_TLZA_ADU.cs
include @Custom_TLZA_ADU1.cs
include @Custom_TLZA_ADU2.cs
include @Custom_TLZA_ADU3.cs
include @Custom_TLZA_ADU4.cs
include @Custom_TLZA_ADU5.cs
include @Custom_TLZA_OC_HDC1.cs
include @Custom_TLZA_OC_HDC2.cs
include @Custom_TLZA_OC_LMSIU64.cs
include @Custom_TLZA_OC_LMSIU64_1.cs
include @Custom_RTC_TLZA.cs
include @SJA1000_CAN.cs
#include @timer_trigger.cs
include @UART_kx12A1.cs
include @UART_kx12A2.cs
include @UART_kx12A3.cs
include @UART_kx12A4.cs
include @UART_kx12A5.cs
include @UART_kx12A6.cs
include @Custom_MS.cs
# ===== 创建机器 =====
mach create "SPARC V8_Leon3"
# ===== 加载硬件平台描述(引用 .repl 文件)=====
machine LoadPlatformDescription @generated.repl
# ===== CPU 性能配置 =====
cpu PerformanceInMips 2000
# ===== 固件加载 =====
# Load VxWorks
sysbus LoadBinary @C:/Users/PingCe/Desktop/1_simulation/KX12A_Z/vxworks_smu/default/vxWorks 0x40003000
sysbus WriteDoubleWord 0x80000240 0x90430
# ===== 调试配置 =====
machine StartGdbServer 3333 true
# ===== 仿真参数 =====
emulation SetGlobalQuantum "0.00001"
# ===== 日志配置 =====
logLevel 1
# ===== 启动命令 =====
# start