Files
BSI-901-fpga-software/docs/csi040_ctrl_datasheet.html

243 lines
36 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSI040 控制模块 Datasheet</title>
<style>
:root { --bg:#f5f7f6; --paper:#fff; --ink:#202421; --muted:#64706a; --line:#dce3df; --accent:#0f7b78; --accent-soft:#e5f3f1; --code-bg:#1f2422; --code-ink:#eef4f0; --shadow:0 16px 34px rgba(20,32,28,.08); }
* { box-sizing:border-box; }
html { scroll-behavior:smooth; }
body { margin:0; color:var(--ink); background:var(--bg); font:15px/1.72 "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif; }
.shell { display:grid; grid-template-columns:292px minmax(0,1fr); min-height:100vh; }
aside { position:sticky; top:0; height:100vh; overflow:auto; padding:28px 22px; border-right:1px solid var(--line); background:#fbfcfb; }
.brand { padding-bottom:18px; margin-bottom:18px; border-bottom:1px solid var(--line); }
.brand-title { margin:0 0 8px; font-size:18px; line-height:1.35; font-weight:700; }
.brand-meta { margin:0; color:var(--muted); font-size:12px; line-height:1.55; }
nav a { display:block; color:#33413b; text-decoration:none; border-radius:6px; padding:5px 8px; margin:1px 0; }
nav a:hover { background:var(--accent-soft); color:var(--accent); }
.toc-l1 { font-weight:700; }
.toc-l2 { padding-left:18px; font-size:14px; }
.toc-l3 { padding-left:34px; font-size:13px; color:var(--muted); }
main { min-width:0; padding:38px 42px 72px; }
article { max-width:1120px; margin:0 auto; padding:42px 52px; background:var(--paper); border:1px solid var(--line); border-radius:10px; box-shadow:var(--shadow); }
h1,h2,h3,h4,h5,h6 { position:relative; line-height:1.32; margin:1.9em 0 .72em; color:#1c2622; }
h1 { margin-top:0; font-size:30px; padding-bottom:14px; border-bottom:2px solid var(--accent); }
h2 { font-size:23px; border-top:1px solid var(--line); padding-top:24px; }
h3 { font-size:18px; }
.anchor { position:absolute; left:-24px; color:var(--accent); opacity:0; text-decoration:none; font-weight:500; }
h1:hover .anchor,h2:hover .anchor,h3:hover .anchor { opacity:1; }
p { margin:.8em 0; }
ul { padding-left:1.35em; }
li { margin:.25em 0; }
code { font-family:Consolas,"Cascadia Mono",monospace; font-size:.92em; border-radius:4px; background:#eef2ef; padding:.12em .35em; }
pre { overflow:auto; margin:18px 0; padding:18px 20px; color:var(--code-ink); background:var(--code-bg); border-radius:8px; line-height:1.55; }
pre code { padding:0; background:transparent; color:inherit; font-size:13px; }
.table-wrap { overflow-x:auto; margin:18px 0 24px; border:1px solid var(--line); border-radius:8px; }
table { width:100%; border-collapse:collapse; min-width:640px; }
th,td { padding:10px 12px; border-bottom:1px solid var(--line); vertical-align:top; }
th { position:sticky; top:0; z-index:1; background:#edf5f3; text-align:left; font-weight:700; }
tr:nth-child(even) td { background:#fafbfa; }
tr:last-child td { border-bottom:0; }
.doc-note { margin:0 0 28px; padding:14px 16px; background:#fff8e9; border:1px solid #efd58f; border-radius:8px; color:#604600; }
.top-link { position:fixed; right:24px; bottom:22px; padding:8px 12px; border-radius:999px; background:var(--accent); color:#fff; text-decoration:none; box-shadow:0 8px 18px rgba(15,123,120,.22); font-size:13px; }
@media (max-width:980px) { .shell{display:block;} aside{position:static;height:auto;max-height:42vh;border-right:0;border-bottom:1px solid var(--line);} main{padding:22px 14px 54px;} article{padding:28px 18px;border-radius:8px;} .anchor{display:none;} h1{font-size:25px;} h2{font-size:20px;} }
@media print { body{background:#fff;font-size:12px;} .shell{display:block;} aside,.top-link{display:none;} main{padding:0;} article{max-width:none;padding:0;border:0;box-shadow:none;} h1,h2,h3{break-after:avoid;} pre,.table-wrap{break-inside:avoid;} a{color:inherit;text-decoration:none;} }
</style>
</head>
<body>
<div class="shell" id="top">
<aside>
<div class="brand">
<p class="brand-title">CSI040 控制模块 Datasheet</p>
<p class="brand-meta">&#28304;&#25991;&#20214;&#65306;docs/csi040_ctrl_datasheet.md<br>&#29983;&#25104;&#26102;&#38388;&#65306;2026-07-01 15:52:40<br>&#31163;&#32447;&#21333;&#25991;&#20214; HTML</p>
</div>
<nav aria-label="document toc">
<a class="toc-l1" href="#csi040-控制模块-datasheet">CSI040 控制模块 Datasheet</a>
<a class="toc-l2" href="#1-概述">1. 概述</a>
<a class="toc-l2" href="#2-模块框图">2. 模块框图</a>
<a class="toc-l2" href="#3-主要特性">3. 主要特性</a>
<a class="toc-l2" href="#4-参数">4. 参数</a>
<a class="toc-l3" href="#4-1-csi040-ctrl-参数">4.1 <code>csi040_ctrl</code> 参数</a>
<a class="toc-l3" href="#4-2-max-burst-bytes-说明">4.2 <code>MAX_BURST_BYTES</code> 说明</a>
<a class="toc-l2" href="#5-端口说明">5. 端口说明</a>
<a class="toc-l3" href="#5-1-时钟复位">5.1 时钟复位</a>
<a class="toc-l3" href="#5-2-bram-寄存器接口">5.2 BRAM 寄存器接口</a>
<a class="toc-l3" href="#5-3-状态输出">5.3 状态输出</a>
<a class="toc-l3" href="#5-4-asic-引脚">5.4 ASIC 引脚</a>
<a class="toc-l2" href="#6-bram-寄存器映射">6. BRAM 寄存器映射</a>
<a class="toc-l2" href="#7-寄存器位定义">7. 寄存器位定义</a>
<a class="toc-l3" href="#7-1-status-寄存器">7.1 <code>STATUS</code> 寄存器</a>
<a class="toc-l3" href="#7-2-spi-ctrl-寄存器">7.2 <code>SPI_CTRL</code> 寄存器</a>
<a class="toc-l3" href="#7-3-pin-ctrl-寄存器">7.3 <code>PIN_CTRL</code> 寄存器</a>
<a class="toc-l3" href="#7-4-seq-cmd-寄存器">7.4 <code>SEQ_CMD</code> 寄存器</a>
<a class="toc-l2" href="#8-命令行为">8. 命令行为</a>
<a class="toc-l3" href="#8-1-control">8.1 <code>CONTROL</code></a>
<a class="toc-l3" href="#8-2-ch-enable">8.2 <code>CH_ENABLE</code></a>
<a class="toc-l3" href="#8-3-通道参数写">8.3 通道参数写</a>
<a class="toc-l3" href="#8-4-direct-spi">8.4 Direct SPI</a>
<a class="toc-l2" href="#9-spi-时序规格">9. SPI 时序规格</a>
<a class="toc-l3" href="#9-1-sck-频率">9.1 SCK 频率</a>
<a class="toc-l3" href="#9-2-spi-帧格式">9.2 SPI 帧格式</a>
<a class="toc-l3" href="#9-3-spi-bit-数">9.3 SPI bit 数</a>
<a class="toc-l3" href="#9-4-传输时间估算">9.4 传输时间估算</a>
<a class="toc-l2" href="#10-软件推荐流程">10. 软件推荐流程</a>
<a class="toc-l3" href="#10-1-写普通命令">10.1 写普通命令</a>
<a class="toc-l3" href="#10-2-direct-read-示例">10.2 Direct read 示例</a>
<a class="toc-l3" href="#10-3-direct-write-示例">10.3 Direct write 示例</a>
<a class="toc-l2" href="#11-复位默认值">11. 复位默认值</a>
<a class="toc-l2" href="#12-集成注意事项">12. 集成注意事项</a>
<a class="toc-l2" href="#13-验证状态">13. 验证状态</a>
</nav>
</aside>
<main>
<article>
<p class="doc-note">&#20248;&#21270;&#29256; HTML&#65306;&#24050;&#28155;&#21152;&#20391;&#36793;&#30446;&#24405;&#12289;&#31456;&#33410;&#38170;&#28857;&#12289;&#21709;&#24212;&#24335;&#34920;&#26684;&#12289;&#25171;&#21360;&#26679;&#24335;&#21644;&#31163;&#32447; CSS&#12290;</p>
<h1 id="csi040-控制模块-datasheet"><a class="anchor" href="#csi040-控制模块-datasheet" aria-label="section link">#</a>CSI040 控制模块 Datasheet</h1>
<h2 id="1-概述"><a class="anchor" href="#1-概述" aria-label="section link">#</a>1. 概述</h2>
<p><code>csi040_ctrl</code> 是用于控制 CSI040 ASIC 的 PL 侧控制模块。模块对上层软件暴露一组 32 bit BRAM 风格寄存器,并把软件写寄存器的动作转换为 CSI040 SPI 总线访问。</p>
<p>该模块主要完成:</p>
<ul><li>CSI040 ASIC 控制寄存器写入</li><li>16 通道 enable 配置</li><li>单通道参数寄存器写入</li><li>DCS/Test 模式 key 序列写入</li><li>Direct SPI 读写</li><li>ASIC reset/trigger 引脚直接控制</li><li>SPI busy/done/error 状态反馈</li></ul>
<p>相关 RTL 文件:</p>
<ul><li><code>c64_pro.srcs/sources_1/rtl/csi040/csi040_ctrl.v</code></li><li><code>c64_pro.srcs/sources_1/rtl/csi040/csi040_spi_master.v</code></li><li><code>c64_pro.srcs/sources_1/rtl/csi040/csi040_ctrl_tb.v</code></li></ul>
<h2 id="2-模块框图"><a class="anchor" href="#2-模块框图" aria-label="section link">#</a>2. 模块框图</h2>
<pre><code class="language-text"> +------------------------------+
BRAM register | | SPI command
access --------&gt;| csi040_ctrl |----------------+
| | |
| register map / shadow regs | v
| sequence engine | +--------------------+
| busy/done/error status | | csi040_spi_master |
+------------------------------+ +---------+----------+
| | |
| | direct pins | SPI pins
v v v
asic_rst_n asic_trig asic_csn/asic_sck/asic_si/asic_so</code></pre>
<h2 id="3-主要特性"><a class="anchor" href="#3-主要特性" aria-label="section link">#</a>3. 主要特性</h2>
<div class="table-wrap"><table><thead><tr><th>项目</th><th>规格</th></tr></thead><tbody><tr><td>软件接口</td><td>32 bit BRAM 风格寄存器接口</td></tr><tr><td>BRAM 地址宽度</td><td>13 bit</td></tr><tr><td>支持写类型</td><td>仅支持 <code>bram_we == 4&#39;hF</code> 的整字写</td></tr><tr><td>支持读类型</td><td><code>bram_en == 1</code><code>bram_we == 4&#39;h0</code></td></tr><tr><td>ASIC 地址宽度</td><td>默认 16 bit</td></tr><tr><td>SPI 地址字节数</td><td>默认 2 byte</td></tr><tr><td>Direct SPI 最大 payload</td><td>默认 4 byte,由 <code>MAX_BURST_BYTES</code> 决定</td></tr><tr><td>SPI SCK 极性</td><td>idle low</td></tr><tr><td>SPI CSN 极性</td><td>active low</td></tr><tr><td>SPI 输出位序</td><td>opcode/address/data 均 MSB first 按帧发送;payload byte0 来自低 8 bit</td></tr><tr><td>忙保护</td><td>忙时写命令寄存器不会启动新命令,并置位 <code>error_busy</code></td></tr><tr><td>复位</td><td><code>rst_n</code> 异步低有效</td></tr></tbody></table></div>
<h2 id="4-参数"><a class="anchor" href="#4-参数" aria-label="section link">#</a>4. 参数</h2>
<h3 id="4-1-csi040-ctrl-参数"><a class="anchor" href="#4-1-csi040-ctrl-参数" aria-label="section link">#</a>4.1 <code>csi040_ctrl</code> 参数</h3>
<div class="table-wrap"><table><thead><tr><th>参数</th><th style="text-align:right">默认值</th><th>说明</th></tr></thead><tbody><tr><td><code>VERSION</code></td><td style="text-align:right"><code>32&#39;h04040001</code></td><td>模块版本号,读 <code>0x0000</code> 返回</td></tr><tr><td><code>SPI_CLK_DIV</code></td><td style="text-align:right"><code>50</code></td><td>SPI SCK 半周期分频,<code>f_sck = f_clk / (2 * SPI_CLK_DIV)</code></td></tr><tr><td><code>REG_ADDR_WIDTH</code></td><td style="text-align:right"><code>16</code></td><td>ASIC 寄存器地址宽度</td></tr><tr><td><code>SPI_ADDR_BYTES</code></td><td style="text-align:right"><code>2</code></td><td>SPI 帧中地址字段字节数</td></tr><tr><td><code>MAX_BURST_BYTES</code></td><td style="text-align:right"><code>4</code></td><td>Direct SPI 最大 payload 字节数</td></tr><tr><td><code>SPI_OPCODE_WRITE</code></td><td style="text-align:right"><code>8&#39;h00</code></td><td>SPI 写 opcode</td></tr><tr><td><code>SPI_OPCODE_READ</code></td><td style="text-align:right"><code>8&#39;h80</code></td><td>SPI 读 opcode</td></tr><tr><td><code>CSI_REG_CONTROL</code></td><td style="text-align:right"><code>16&#39;h0002</code></td><td>CSI040 control register 地址</td></tr><tr><td><code>CSI_REG_CH_ENABLE1</code></td><td style="text-align:right"><code>16&#39;h0007</code></td><td>channel 0-7 enable 地址</td></tr><tr><td><code>CSI_REG_CH_ENABLE2</code></td><td style="text-align:right"><code>16&#39;h0008</code></td><td>channel 8-15 enable 地址</td></tr><tr><td><code>CSI_REG_TEST_DCS_KEY</code></td><td style="text-align:right"><code>16&#39;h0009</code></td><td>DCS/Test key register 地址</td></tr><tr><td><code>CSI_CH_BASE</code></td><td style="text-align:right"><code>16&#39;h0010</code></td><td>通道寄存器基地址</td></tr><tr><td><code>CSI_CH_STRIDE</code></td><td style="text-align:right"><code>16&#39;h0010</code></td><td>通道寄存器地址步进</td></tr><tr><td><code>CSI_REG_STIM_TRIGGER</code></td><td style="text-align:right"><code>16&#39;h0110</code></td><td>stimulation trigger register 地址</td></tr><tr><td><code>CSI_REG_PART_ID</code></td><td style="text-align:right"><code>16&#39;h011D</code></td><td>part ID register 地址</td></tr><tr><td><code>CSI_REG_REVISION</code></td><td style="text-align:right"><code>16&#39;h011E</code></td><td>revision register 地址</td></tr></tbody></table></div>
<h3 id="4-2-max-burst-bytes-说明"><a class="anchor" href="#4-2-max-burst-bytes-说明" aria-label="section link">#</a>4.2 <code>MAX_BURST_BYTES</code> 说明</h3>
<p><code>MAX_BURST_BYTES</code> 同时影响以下信号宽度和行为:</p>
<div class="table-wrap"><table><thead><tr><th>位置</th><th>影响</th></tr></thead><tbody><tr><td><code>spi_cmd_wdata</code></td><td>宽度为 <code>8 * MAX_BURST_BYTES</code></td></tr><tr><td><code>spi_cmd_rdata</code></td><td>宽度为 <code>8 * MAX_BURST_BYTES</code></td></tr><tr><td>SPI master 内部 frame</td><td>最大帧长为 <code>8 * (1 + SPI_ADDR_BYTES + MAX_BURST_BYTES)</code></td></tr><tr><td>Direct SPI 长度</td><td><code>SPI_CTRL[15:8]</code> 超过 <code>MAX_BURST_BYTES</code> 时会被截断</td></tr></tbody></table></div>
<p>高层命令序列目前都只发 1 byte payload<code>MAX_BURST_BYTES</code> 主要服务于 Direct SPI burst 访问。</p>
<h2 id="5-端口说明"><a class="anchor" href="#5-端口说明" aria-label="section link">#</a>5. 端口说明</h2>
<h3 id="5-1-时钟复位"><a class="anchor" href="#5-1-时钟复位" aria-label="section link">#</a>5.1 时钟复位</h3>
<div class="table-wrap"><table><thead><tr><th>信号</th><th>方向</th><th style="text-align:right">位宽</th><th>说明</th></tr></thead><tbody><tr><td><code>clk</code></td><td>input</td><td style="text-align:right">1</td><td>主时钟,模块内部逻辑均使用此时钟</td></tr><tr><td><code>rst_n</code></td><td>input</td><td style="text-align:right">1</td><td>异步低有效复位</td></tr><tr><td><code>bram_clk</code></td><td>input</td><td style="text-align:right">1</td><td>当前 RTL 未使用,保留接口</td></tr><tr><td><code>bram_rst</code></td><td>input</td><td style="text-align:right">1</td><td>当前 RTL 未使用,保留接口</td></tr></tbody></table></div>
<p>注意:当前实现中 <code>bram_clk/bram_rst</code> 未参与逻辑,BRAM 访问必须与 <code>clk</code> 同步。</p>
<h3 id="5-2-bram-寄存器接口"><a class="anchor" href="#5-2-bram-寄存器接口" aria-label="section link">#</a>5.2 BRAM 寄存器接口</h3>
<div class="table-wrap"><table><thead><tr><th>信号</th><th>方向</th><th style="text-align:right">位宽</th><th>说明</th></tr></thead><tbody><tr><td><code>bram_addr</code></td><td>input</td><td style="text-align:right">13</td><td>BRAM 字节地址</td></tr><tr><td><code>bram_din</code></td><td>input</td><td style="text-align:right">32</td><td>写数据</td></tr><tr><td><code>bram_dout</code></td><td>output reg</td><td style="text-align:right">32</td><td>读数据</td></tr><tr><td><code>bram_en</code></td><td>input</td><td style="text-align:right">1</td><td>BRAM 访问使能</td></tr><tr><td><code>bram_we</code></td><td>input</td><td style="text-align:right">4</td><td>写 strobe;仅 <code>4&#39;hF</code> 识别为写,<code>4&#39;h0</code> 识别为读</td></tr></tbody></table></div>
<h3 id="5-3-状态输出"><a class="anchor" href="#5-3-状态输出" aria-label="section link">#</a>5.3 状态输出</h3>
<div class="table-wrap"><table><thead><tr><th>信号</th><th>方向</th><th style="text-align:right">位宽</th><th>说明</th></tr></thead><tbody><tr><td><code>busy</code></td><td>output</td><td style="text-align:right">1</td><td>模块忙。为 1 时不要写命令寄存器</td></tr><tr><td><code>spi_done</code></td><td>output</td><td style="text-align:right">1</td><td>SPI master 完成脉冲,持续 1 个 <code>clk</code></td></tr><tr><td><code>error_busy</code></td><td>output reg</td><td style="text-align:right">1</td><td>忙时启动命令产生的粘滞错误标志</td></tr></tbody></table></div>
<h3 id="5-4-asic-引脚"><a class="anchor" href="#5-4-asic-引脚" aria-label="section link">#</a>5.4 ASIC 引脚</h3>
<div class="table-wrap"><table><thead><tr><th>信号</th><th>方向</th><th style="text-align:right">位宽</th><th>说明</th></tr></thead><tbody><tr><td><code>asic_rst_n</code></td><td>output reg</td><td style="text-align:right">1</td><td>ASIC reset 引脚,软件通过 <code>PIN_CTRL[0]</code> 控制</td></tr><tr><td><code>asic_trig</code></td><td>output reg</td><td style="text-align:right">1</td><td>ASIC trig 引脚,软件通过 <code>PIN_CTRL[1]</code> 控制</td></tr><tr><td><code>asic_csn</code></td><td>output</td><td style="text-align:right">1</td><td>SPI CSN,低有效</td></tr><tr><td><code>asic_sck</code></td><td>output</td><td style="text-align:right">1</td><td>SPI SCK,空闲低</td></tr><tr><td><code>asic_si</code></td><td>output</td><td style="text-align:right">1</td><td>SPI master 输出到 ASIC</td></tr><tr><td><code>asic_so</code></td><td>input</td><td style="text-align:right">1</td><td>ASIC 输出到 SPI master</td></tr></tbody></table></div>
<h2 id="6-bram-寄存器映射"><a class="anchor" href="#6-bram-寄存器映射" aria-label="section link">#</a>6. BRAM 寄存器映射</h2>
<div class="table-wrap"><table><thead><tr><th style="text-align:right">地址</th><th>名称</th><th>访问</th><th>说明</th></tr></thead><tbody><tr><td style="text-align:right"><code>13&#39;h0000</code></td><td><code>VERSION</code></td><td>R</td><td>返回 <code>VERSION</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0004</code></td><td><code>STATUS</code></td><td>R/W1C</td><td>状态寄存器;写 bit0 清 done,写 bit1 清 error</td></tr><tr><td style="text-align:right"><code>13&#39;h0008</code></td><td><code>SPI_ADDR</code></td><td>R/W</td><td>Direct SPI 目标 ASIC 地址</td></tr><tr><td style="text-align:right"><code>13&#39;h000C</code></td><td><code>SPI_WDATA</code></td><td>R/W</td><td>Direct SPI 写数据</td></tr><tr><td style="text-align:right"><code>13&#39;h0010</code></td><td><code>SPI_CTRL</code></td><td>W</td><td>Direct SPI 启动控制</td></tr><tr><td style="text-align:right"><code>13&#39;h0014</code></td><td><code>SPI_RDATA</code></td><td>R</td><td>最近一次 SPI 读回数据</td></tr><tr><td style="text-align:right"><code>13&#39;h0018</code></td><td><code>PIN_CTRL</code></td><td>R/W</td><td>直接控制 <code>asic_rst_n/asic_trig</code></td></tr><tr><td style="text-align:right"><code>13&#39;h001C</code></td><td><code>LAST_ADDR</code></td><td>R</td><td>最近一次完成 SPI 操作的 ASIC 地址</td></tr><tr><td style="text-align:right"><code>13&#39;h0020</code></td><td><code>CONTROL</code></td><td>R/W</td><td>写 CSI040 control register</td></tr><tr><td style="text-align:right"><code>13&#39;h0024</code></td><td><code>CH_ENABLE</code></td><td>R/W</td><td>写 channel enable1/2</td></tr><tr><td style="text-align:right"><code>13&#39;h0028</code></td><td><code>TRIGGER</code></td><td>W</td><td>向 ASIC trigger register 写 <code>8&#39;hAA</code></td></tr><tr><td style="text-align:right"><code>13&#39;h002C</code></td><td><code>SEQ_CMD</code></td><td>W</td><td>特殊序列命令</td></tr><tr><td style="text-align:right"><code>13&#39;h0040</code></td><td><code>CH_INDEX</code></td><td>R/W</td><td>选择通道编号</td></tr><tr><td style="text-align:right"><code>13&#39;h0044</code></td><td><code>CH_MISC</code></td><td>W</td><td>当前通道 offset <code>0x0</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0048</code></td><td><code>CH_CUR_A</code></td><td>W</td><td>当前通道 offset <code>0x1</code></td></tr><tr><td style="text-align:right"><code>13&#39;h004C</code></td><td><code>CH_CUR_B</code></td><td>W</td><td>当前通道 offset <code>0x2</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0050</code></td><td><code>CH_CUR_C</code></td><td>W</td><td>当前通道 offset <code>0x3</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0054</code></td><td><code>CH_CUR_D</code></td><td>W</td><td>当前通道 offset <code>0x4</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0058</code></td><td><code>CH_STIM_PW</code></td><td>W</td><td>当前通道 offset <code>0x5</code></td></tr><tr><td style="text-align:right"><code>13&#39;h005C</code></td><td><code>CH_DZ0</code></td><td>W</td><td>当前通道 offset <code>0x6</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0060</code></td><td><code>CH_DZ1</code></td><td>W</td><td>当前通道 offset <code>0x7</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0064</code></td><td><code>CH_SKIP_AB</code></td><td>W</td><td>当前通道 offset <code>0x8</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0068</code></td><td><code>CH_SKIP_CD</code></td><td>W</td><td>当前通道 offset <code>0x9</code></td></tr><tr><td style="text-align:right"><code>13&#39;h006C</code></td><td><code>CH_STIM_NUM</code></td><td>W</td><td>当前通道 offset <code>0xA</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0070</code></td><td><code>CH_DZ2</code></td><td>W</td><td>当前通道 offset <code>0xB</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0074</code></td><td><code>CH_THERAPY_DELAY</code></td><td>W</td><td>当前通道 offset <code>0xC</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0078</code></td><td><code>CH_THERAPY_NUM</code></td><td>W</td><td>当前通道 offset <code>0xD</code></td></tr><tr><td style="text-align:right"><code>13&#39;h007C</code></td><td><code>CH_DZ3</code></td><td>W</td><td>当前通道 offset <code>0xE</code></td></tr><tr><td style="text-align:right"><code>13&#39;h0080</code></td><td><code>CH_MASTER_NUM</code></td><td>W</td><td>当前通道 offset <code>0xF</code></td></tr></tbody></table></div>
<h2 id="7-寄存器位定义"><a class="anchor" href="#7-寄存器位定义" aria-label="section link">#</a>7. 寄存器位定义</h2>
<h3 id="7-1-status-寄存器"><a class="anchor" href="#7-1-status-寄存器" aria-label="section link">#</a>7.1 <code>STATUS</code> 寄存器</h3>
<p><code>STATUS</code> 读回值由 RTL 拼接得到:</p>
<pre><code class="language-verilog">{16&#39;d0, seq_id, seq_step, error_busy, done_latched, spi_cmd_ready, ctrl_busy}</code></pre>
<p>赋值给 32 bit <code>bram_dout</code> 时左侧补 0。软件可按以下位使用:</p>
<div class="table-wrap"><table><thead><tr><th style="text-align:right"></th><th>名称</th><th>说明</th></tr></thead><tbody><tr><td style="text-align:right"><code>[5]</code></td><td><code>ctrl_busy</code></td><td>当前模块忙</td></tr><tr><td style="text-align:right"><code>[6]</code></td><td><code>spi_cmd_ready</code></td><td>SPI master 空闲可接收命令</td></tr><tr><td style="text-align:right"><code>[7]</code></td><td><code>done_latched</code></td><td>至少完成过一次 SPI 操作</td></tr><tr><td style="text-align:right"><code>[8]</code></td><td><code>error_busy</code></td><td>忙时写命令错误</td></tr><tr><td style="text-align:right"><code>[11:9]</code></td><td><code>seq_step</code></td><td>当前序列步骤</td></tr><tr><td style="text-align:right"><code>[15:12]</code></td><td><code>seq_id</code></td><td>当前序列编号</td></tr></tbody></table></div>
<p><code>STATUS</code> 清除粘滞位:</p>
<div class="table-wrap"><table><thead><tr><th style="text-align:right">写 bit</th><th>行为</th></tr></thead><tbody><tr><td style="text-align:right"><code>[0] = 1</code></td><td>清除 <code>done_latched</code></td></tr><tr><td style="text-align:right"><code>[1] = 1</code></td><td>清除 <code>error_busy</code></td></tr></tbody></table></div>
<h3 id="7-2-spi-ctrl-寄存器"><a class="anchor" href="#7-2-spi-ctrl-寄存器" aria-label="section link">#</a>7.2 <code>SPI_CTRL</code> 寄存器</h3>
<div class="table-wrap"><table><thead><tr><th style="text-align:right"></th><th>名称</th><th>说明</th></tr></thead><tbody><tr><td style="text-align:right"><code>[0]</code></td><td><code>direct_write</code></td><td>1Direct SPI 写;0Direct SPI 读</td></tr><tr><td style="text-align:right"><code>[15:8]</code></td><td><code>direct_len</code></td><td>payload 字节数;0 会被转换为 1</td></tr><tr><td style="text-align:right">其他</td><td>保留</td><td>当前未使用</td></tr></tbody></table></div>
<p><code>direct_len</code> 最终会在 SPI master 内限制到 <code>1..MAX_BURST_BYTES</code></p>
<h3 id="7-3-pin-ctrl-寄存器"><a class="anchor" href="#7-3-pin-ctrl-寄存器" aria-label="section link">#</a>7.3 <code>PIN_CTRL</code> 寄存器</h3>
<div class="table-wrap"><table><thead><tr><th style="text-align:right"></th><th>名称</th><th>说明</th></tr></thead><tbody><tr><td style="text-align:right"><code>[0]</code></td><td><code>asic_rst_n</code></td><td>直接驱动 ASIC reset_n</td></tr><tr><td style="text-align:right"><code>[1]</code></td><td><code>asic_trig</code></td><td>直接驱动 ASIC trig</td></tr><tr><td style="text-align:right">其他</td><td>保留</td><td>当前读回为 0</td></tr></tbody></table></div>
<h3 id="7-4-seq-cmd-寄存器"><a class="anchor" href="#7-4-seq-cmd-寄存器" aria-label="section link">#</a>7.4 <code>SEQ_CMD</code> 寄存器</h3>
<div class="table-wrap"><table><thead><tr><th style="text-align:right"></th><th>命令</th><th>SPI 行为</th></tr></thead><tbody><tr><td style="text-align:right"><code>[0]</code></td><td>DCS unlock</td><td><code>0x0009</code> 依次写 <code>55h, B3h, 0Ah</code></td></tr><tr><td style="text-align:right"><code>[1]</code></td><td>Test unlock</td><td><code>0x0009</code> 依次写 <code>AAh, 4Ch, F5h</code></td></tr><tr><td style="text-align:right"><code>[2]</code></td><td>Mode exit</td><td><code>0x0009</code><code>F9h</code></td></tr><tr><td style="text-align:right"><code>[3]</code></td><td>Control quick write</td><td>设置 <code>control_shadow = 8&#39;h10</code> 并写 <code>0x0002</code></td></tr><tr><td style="text-align:right"><code>[4]</code></td><td>Control quick write</td><td>设置 <code>control_shadow = 8&#39;h08</code> 并写 <code>0x0002</code></td></tr></tbody></table></div>
<p>若多个 bit 同时为 1,优先级从 bit0 到 bit4。</p>
<h2 id="8-命令行为"><a class="anchor" href="#8-命令行为" aria-label="section link">#</a>8. 命令行为</h2>
<h3 id="8-1-control"><a class="anchor" href="#8-1-control" aria-label="section link">#</a>8.1 <code>CONTROL</code></h3>
<p><code>BRAM_ADDR_CONTROL</code></p>
<pre><code class="language-text">control_shadow &lt;= bram_din[7:0]
SPI write addr 0x0002, data control_shadow, len 1</code></pre>
<h3 id="8-2-ch-enable"><a class="anchor" href="#8-2-ch-enable" aria-label="section link">#</a>8.2 <code>CH_ENABLE</code></h3>
<p><code>BRAM_ADDR_CH_ENABLE</code></p>
<pre><code class="language-text">ch_enable_shadow &lt;= bram_din[15:0]
step0: SPI write addr 0x0007, data ch_enable_shadow[7:0]
step1: SPI write addr 0x0008, data ch_enable_shadow[15:8]</code></pre>
<h3 id="8-3-通道参数写"><a class="anchor" href="#8-3-通道参数写" aria-label="section link">#</a>8.3 通道参数写</h3>
<p>通道参数地址计算:</p>
<pre><code class="language-text">asic_addr = CSI_CH_BASE + CH_INDEX * CSI_CH_STRIDE + channel_offset</code></pre>
<p>默认:</p>
<pre><code class="language-text">asic_addr = 0x0010 + CH_INDEX * 0x0010 + channel_offset</code></pre>
<p>示例:</p>
<pre><code class="language-text">CH_INDEX = 3
写 CH_CUR_A = 0x7F
channel_offset = 0x1
asic_addr = 0x0041</code></pre>
<h3 id="8-4-direct-spi"><a class="anchor" href="#8-4-direct-spi" aria-label="section link">#</a>8.4 Direct SPI</h3>
<p>Direct SPI 使用 <code>SPI_ADDR/SPI_WDATA/SPI_CTRL</code></p>
<pre><code class="language-text">1. 写 SPI_ADDR 设置 ASIC 地址
2. 写 SPI_WDATA 设置写数据
3. 写 SPI_CTRL 启动 direct transfer
4. 读操作完成后,从 SPI_RDATA 取数据</code></pre>
<h2 id="9-spi-时序规格"><a class="anchor" href="#9-spi-时序规格" aria-label="section link">#</a>9. SPI 时序规格</h2>
<h3 id="9-1-sck-频率"><a class="anchor" href="#9-1-sck-频率" aria-label="section link">#</a>9.1 SCK 频率</h3>
<pre><code class="language-text">f_sck = f_clk / (2 * SPI_CLK_DIV)</code></pre>
<p>示例:</p>
<div class="table-wrap"><table><thead><tr><th style="text-align:right"><code>f_clk</code></th><th style="text-align:right"><code>SPI_CLK_DIV</code></th><th style="text-align:right"><code>f_sck</code></th></tr></thead><tbody><tr><td style="text-align:right">100 MHz</td><td style="text-align:right">50</td><td style="text-align:right">1 MHz</td></tr><tr><td style="text-align:right">100 MHz</td><td style="text-align:right">25</td><td style="text-align:right">2 MHz</td></tr><tr><td style="text-align:right">100 MHz</td><td style="text-align:right">10</td><td style="text-align:right">5 MHz</td></tr><tr><td style="text-align:right">100 MHz</td><td style="text-align:right">5</td><td style="text-align:right">10 MHz</td></tr></tbody></table></div>
<h3 id="9-2-spi-帧格式"><a class="anchor" href="#9-2-spi-帧格式" aria-label="section link">#</a>9.2 SPI 帧格式</h3>
<p>默认 <code>SPI_ADDR_BYTES = 2</code></p>
<pre><code class="language-text">byte0 opcode
byte1 address high byte
byte2 address low byte
byte3.. payload byte0..N</code></pre>
<p>写 1 byte 示例:</p>
<pre><code class="language-text">opcode = 0x02
addr = 0x0002
data = 0x10
frame = 0x02_0002_10</code></pre>
<h3 id="9-3-spi-bit-数"><a class="anchor" href="#9-3-spi-bit-数" aria-label="section link">#</a>9.3 SPI bit 数</h3>
<pre><code class="language-text">frame_bits = 8 * (1 + SPI_ADDR_BYTES + payload_len)</code></pre>
<p>默认地址 2 byte 时:</p>
<div class="table-wrap"><table><thead><tr><th style="text-align:right">payload_len</th><th style="text-align:right">frame_bits</th></tr></thead><tbody><tr><td style="text-align:right">1</td><td style="text-align:right">32</td></tr><tr><td style="text-align:right">2</td><td style="text-align:right">40</td></tr><tr><td style="text-align:right">3</td><td style="text-align:right">48</td></tr><tr><td style="text-align:right">4</td><td style="text-align:right">56</td></tr></tbody></table></div>
<h3 id="9-4-传输时间估算"><a class="anchor" href="#9-4-传输时间估算" aria-label="section link">#</a>9.4 传输时间估算</h3>
<p>不计状态机少量额外周期时:</p>
<pre><code class="language-text">transfer_time ≈ frame_bits * 2 * SPI_CLK_DIV * clk_period</code></pre>
<p>100 MHz、<code>SPI_CLK_DIV = 50</code>、1 byte payload</p>
<pre><code class="language-text">frame_bits = 32
transfer_time ≈ 32 * 2 * 50 * 10 ns = 32 us</code></pre>
<h2 id="10-软件推荐流程"><a class="anchor" href="#10-软件推荐流程" aria-label="section link">#</a>10. 软件推荐流程</h2>
<h3 id="10-1-写普通命令"><a class="anchor" href="#10-1-写普通命令" aria-label="section link">#</a>10.1 写普通命令</h3>
<pre><code class="language-text">1. 轮询 STATUS[5] == 0,确认不忙
2. 写目标命令寄存器
3. 轮询 STATUS[7] == 1,确认完成
4. 写 STATUS[0] = 1,清除 done_latched
5. 若 STATUS[8] == 1,记录错误并写 STATUS[1] = 1 清除</code></pre>
<h3 id="10-2-direct-read-示例"><a class="anchor" href="#10-2-direct-read-示例" aria-label="section link">#</a>10.2 Direct read 示例</h3>
<p>读取 CSI040 Part ID</p>
<pre><code class="language-text">write SPI_ADDR = 0x0000011D
write SPI_CTRL = 0x00000100 // bit0=0 read, len=1
wait done
read SPI_RDATA[7:0]</code></pre>
<p>testbench 中 ASIC 模型返回 <code>8&#39;h28</code></p>
<h3 id="10-3-direct-write-示例"><a class="anchor" href="#10-3-direct-write-示例" aria-label="section link">#</a>10.3 Direct write 示例</h3>
<p>向 ASIC <code>0x0002</code><code>0x10</code></p>
<pre><code class="language-text">write SPI_ADDR = 0x00000002
write SPI_WDATA = 0x00000010
write SPI_CTRL = 0x00000101 // bit0=1 write, len=1
wait done</code></pre>
<h2 id="11-复位默认值"><a class="anchor" href="#11-复位默认值" aria-label="section link">#</a>11. 复位默认值</h2>
<div class="table-wrap"><table><thead><tr><th>项目</th><th style="text-align:right">复位值</th></tr></thead><tbody><tr><td><code>direct_addr</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>direct_wdata</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>direct_len</code></td><td style="text-align:right"><code>1</code></td></tr><tr><td><code>direct_write</code></td><td style="text-align:right"><code>1</code></td></tr><tr><td><code>control_shadow</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>ch_enable_shadow</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>ch_index</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>seq_id</code></td><td style="text-align:right"><code>SEQ_IDLE</code></td></tr><tr><td><code>seq_step</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>seq_active</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>error_busy</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>done_latched</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>last_rdata</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>last_addr</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>asic_rst_n</code></td><td style="text-align:right"><code>1</code></td></tr><tr><td><code>asic_trig</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>asic_csn</code></td><td style="text-align:right"><code>1</code></td></tr><tr><td><code>asic_sck</code></td><td style="text-align:right"><code>0</code></td></tr><tr><td><code>asic_si</code></td><td style="text-align:right"><code>0</code></td></tr></tbody></table></div>
<h2 id="12-集成注意事项"><a class="anchor" href="#12-集成注意事项" aria-label="section link">#</a>12. 集成注意事项</h2>
<ul><li><code>bram_clk</code><code>bram_rst</code> 当前未使用,BRAM 访问必须同步到 <code>clk</code></li><li>只支持整字写,软件侧需要保证 <code>bram_we == 4&#39;hF</code></li><li><code>busy = 1</code> 时不要写命令寄存器,否则命令被丢弃并置位 <code>error_busy</code></li><li><code>TRIGGER</code> 寄存器是通过 SPI 写 ASIC trigger register<code>PIN_CTRL[1]</code> 是直接驱动 <code>asic_trig</code> 引脚,两者不是同一个功能。</li><li><code>SPI_OPCODE_WRITE/READ</code> 需要与最终 CSI040 SPI 协议匹配。当前 testbench 使用 <code>8&#39;h02/8&#39;h03</code></li><li>若系统时钟不是 100 MHz,需要重新计算 <code>SPI_CLK_DIV</code>,保证 CSI040 SPI 时序满足要求。</li><li>Direct SPI 多字节读写最大长度由 <code>MAX_BURST_BYTES</code> 控制,默认最多 4 byte。</li></ul>
<h2 id="13-验证状态"><a class="anchor" href="#13-验证状态" aria-label="section link">#</a>13. 验证状态</h2>
<p>当前 testbench 覆盖:</p>
<div class="table-wrap"><table><thead><tr><th>测试项</th><th>期望</th></tr></thead><tbody><tr><td>CONTROL 写</td><td>SPI frame <code>0x02000210</code></td></tr><tr><td>CH_ENABLE 写</td><td>SPI frame <code>0x0200075A</code><code>0x020008A5</code></td></tr><tr><td>CH3 CUR_A 写</td><td>SPI frame <code>0x0200417F</code></td></tr><tr><td>DCS unlock</td><td>SPI frame <code>0x02000955/0x020009B3/0x0200090A</code></td></tr><tr><td>Direct read Part ID</td><td>SPI frame <code>0x03011D00</code>,读回 <code>0x28</code></td></tr></tbody></table></div>
<p>已运行:</p>
<pre><code class="language-text">xvlog: pass
xelab: pass
xsim : $finish at 10940 ns</code></pre>
</article>
</main>
</div>
<a class="top-link" href="#top">&#36820;&#22238;&#39030;&#37096;</a>
</body>
</html>