--- nono/vm/lance.h 2026/04/29 17:04:55 1.1.1.8 +++ nono/vm/lance.h 2026/04/29 17:05:25 1.1.1.12 @@ -4,11 +4,20 @@ // Licensed under nono-license.txt // +// +// Lance (AM7990) +// + #pragma once #include "ethernet.h" +#include "event.h" +#include "hostnet.h" +#include "message.h" #include "monitor.h" -#include "scheduler.h" + +class InterruptDevice; +class SubRAMDevice; struct AM7990 { @@ -142,14 +151,16 @@ class LanceDevice : public EthernetDevic // 受信フェーズ enum class RXPhase { - IDLE = 0, // ポーリング + STOP = 0, // (動作していない) + IDLE, // ポーリング COPY, // バッファ書き込み NEXT, // RMD 更新 MISS, // 受信ミス }; // 送信フェーズ enum class TXPhase { - IDLE = 0, // ポーリング + STOP = 0, // (動作していない) + IDLE, // ポーリング COPY, // バッファ読み込み SEND, // 送信 NEXT, // TMD 更新 @@ -157,20 +168,17 @@ class LanceDevice : public EthernetDevic public: LanceDevice(); - virtual ~LanceDevice() override; + ~LanceDevice() override; bool Init() override; - void ResetHard() override; + void ResetHard(bool poweron) override; protected: // BusIO インタフェース static const uint32 NPORT = 2; - uint64 Read(uint32 offset); - uint64 Write(uint32 offset, uint32 data); - uint64 Peek(uint32 offset); - - // パケット受信通知 (親クラスから) - void NotifyRecvPacket() override; + busdata Read(uint32 offset); + busdata Write(uint32 offset, uint32 data); + busdata Peek(uint32 offset); private: DECLARE_MONITOR_CALLBACK(MonitorUpdate); @@ -194,20 +202,22 @@ class LanceDevice : public EthernetDevic void ChangeInterrupt(); void TXIdle(Event&); - void TXCopy(Event&); + void TXCopy(); void TXSend(Event&); void TXNext(Event&); void RXIdle(Event&); - void RXCopy(Event&); + void RXCopy(); void RXNext(Event&); - void RXRecv(Event&); - void RXMiss(Event&); + void RXMiss(); // フェーズ遷移 void ChangePhase(TXPhase new_phase, uint64 time = 100_nsec); void ChangePhase(RXPhase new_phase, uint64 time = 100_nsec); + // パケット受信通知 (HostNet から EthernetDevice 経由で呼ばれる) + void RxMessage(MessageID, uint32); + const std::string BitToString(const char * const name[], uint16 bits); const std::string CSR0ToString(uint16 bits); const std::string CSR3ToString(uint16 bits); @@ -223,33 +233,40 @@ class LanceDevice : public EthernetDevic // Initialization Block uint16 initblock[12] {}; - uint64 padr {}; // PADR を下位詰めしたもの + macaddr_t padr {}; - uint32 rmd_base {}; // 受信ディスクリプタの(ZRAM での)開始アドレス + uint32 rmd_base {}; // 受信ディスクリプタの(SubRAMでの)開始アドレス int rmd_num {}; // 受信ディスクリプタ数 int rmd_cur {}; // RMD 内の現在の注目インデックス - uint32 tmd_base {}; // 送信ディスクリプタの(ZRAM での)開始アドレス + uint32 tmd_base {}; // 送信ディスクリプタの(SubRAMでの)開始アドレス int tmd_num {}; // 送信ディスクリプタ数 int tmd_cur {}; // TMD 内の現在の注目インデックス uint16 rmd1 {}; // 現在の RMD1 uint32 rmd1_ahead {}; // 次の RMD1 先読み (負なら先読みしてない状態) - RXPacket rxpacket {}; // 受信バッファ - uint16 tmd1 {}; // 現在の TMD1 uint32 tmd1_ahead {}; // 次の TMD1 先読み (負なら先読みしてない状態) - std::vector txq {}; // 送信バッファ + + NetPacket rx_packet {}; // 受信バッファ + NetPacket tx_packet {}; // 送信バッファ RXPhase rx_phase {}; // 受信フェーズ TXPhase tx_phase {}; // 送信フェーズ + // 前回の TMD 状態文字列 (デバッグ表示用) + std::string last_tmdstr {}; + + InterruptDevice *interrupt {}; + SubRAMDevice *subram {}; + // 待ち時間用イベント Event rx_event { this }; Event tx_event { this }; Monitor monitor { this }; - - // 前回の TMD 状態文字列 (デバッグ表示用) - std::string last_tmdstr {}; }; + +static inline LanceDevice *GetLanceDevice() { + return Object::GetObject(OBJ_ETHERNET(0)); +}