2014年9月27日土曜日

Slave FIFOs メモ書き⑤

page.233「15.5.3 PINFLAGSxx」について、


「Table 15-4. FIFO Flag Pin Functions」より、

FLAGA=PF, FLAGB=FF, FLAGC=EF, FLAGD=EP2PF
(Actual FIFO is selected by FIFOADR[0,1] pins)


ここで、page.103「9.2.4 FIFO Flag Pins (FLAGA, FLAGB, FLAGC, FLAGD)」より、

Four pins — FLAGA, FLAGB, FLAGC, and FLAGD (see
Figure 9-7) — report the status of the EZ-USB’s FIFOs; in
addition to the usual ‘FIFO full’ and ‘FIFO empty’ signals,
there is also a signal which indicates that a FIFO has filled to
a user-programmable level. The external master typically
monitors the ‘empty’ flag (EF) of OUT endpoints and the full
(FF) flag of IN endpoints; the programmable level flag (PF)
is equally useful for either type of endpoint (it can, for
instance, give advance warning that an OUT endpoint is
almost empty or that an IN endpoint is almost full).

empty flag (EF)
full flag      (FF)
programmable level flag (PF)

Slave FIFOs メモ書き④

「15.5.10 REVCTL
Chip Revision Control Register」について。



Note DYN_OUT and ENH_PKT default to ‘0’ on a hard reset. Cypress highly recommends setting both bits to ‘1’.

デフォルトではDYN_OUT と ENH_PKTは両方とも0だが、
Cypressは両方とも1にする事を強く勧める。



1 DYN_OUT
 Disable Auto-Arming at the 0-1 transition of AUTOOUT.

0
 The core automatically arms the endpoints when AUTOOUT is switched from ‘0’ to ‘1’.
 This means that firmware must reset the endpoint
 (and risk losing endpoint data) when switching
between Auto-Out mode and Manual-Out mode.

1
 The core disables auto-arming of the endpoints when AUTOOUT transitions from ‘0’ to ‘1’.
This feature allows CPU intervention when switching between AUTO and Manual mode
without having to reset the endpoint.

Note
 When DYN_OUT = 1 and AUTOOUT = 1, the CPU is responsible for ‘priming the pump’ by initially arming the endpoints (OUTPKTEND w/SKIP = 1 to pass packets to host).


0 ENH_PKT
 Enhanced Packet Handling.

0 The CPU can neither source OUT packets nor skip IN packets; it has only the following capabilities.
OUT packets: Skip or Commit
IN packets: Commit or Edit/Source

1 The CPU has additional capabilities:
OUT packets: Skip, Commit, or Edit/Source
IN packets: Skip, Commit, or Edit/Source

1 DYN_OUT
 AUTOOUTが 0から 1に遷移する時、自動アーミングを無効にします。
(自動アーミングがそもそも何かが分からない……エンドポイントの切り替え?)

0
AUTOOUTが0から1へ変化した時、コア(半導体チップ?)は自動的にエンドポイントを切り替えます。
これは、Auto-Out mode と Manual-Out modeの切り替え時に、ファームウェアがエンドポイントをリセットしなければならない事を意味します。(そして、エンドポイントのデータを失う危険性を負います。)

1
AUTOOUTが0から1へ変化した時、コア(半導体チップ?)は自動的にエンドポイントを切り替え。
ることができない。
この特徴はオート・モードからマニュアル・モードへの切り替え時に、
エンドポイントをリセットする事無く、CPUが介入する事を可能にする。

注意
DYN_OUT = 1 かつ AUTOOUT = 1の場合、CPUは‘priming the pump’に対して、
エンドポイントを初期化する最初に使用する(切り替える)エンドポイントを(OUTPKTEND w/SKIP = 1 にして、パケットがホストに渡されるようにする)
責任を負う。


--------------
0 ENH_PKT
 強化されたパケットの処理方法

0
CPUはOUTパケットを参照する事も、INパケットを通過させる事もできない。
それは、唯一以下の様な機能を持つ。

OUTパケット:通過か修正
INパケット:修正、編集/参照

(――――何が違うのかが分からない……)


1
CPUは追加の機能を持ちます。

OUTパケット:通過、修正、編集/参照
INパケット:通過、修正、編集/参照



「15.6.16 INPKTEND
Force IN Packet End Register」について、





「15.6.17 OUTPKTEND
Force OUT Packet End Register」について、


7 SKIP
 Skip Packet.
When ENH_PKT (REVCTL.0) is set to ‘1’, setting this bit to a ‘1’ causes the OUT packet to be
skipped. Clearing this bit to ‘0’ automatically dispatches an OUT buffer.

3:0 EP[3:0]
 Endpoint Number.
Replaces the function of EPxBCL.7=1 (Skip). This feature is for OUT transfers. By writing the desired
endpoint number (2, 4, 6, or 8), EZ-USB logic automatically skips or commits an OUT packet
(depends on the SKIP bit settings).
Note This register has no effect if REVCTL.0 = 0.

7 SKIP
パケットをスキップする。
ENH_PKT (REVCTL.0) が1かつ、このビット(SKIP(OUTPKTEND.7))が1の時、
「OUT packet」(複数ではなく、単数、と考えていいのか?)はスキップされる。
このビットは自動的に0にクリアされ、an OUT bufferは、停止?、する


3:0 EP[3:0]
エンドポイントの番号。
EPxBCL.7=1(スキップ)の機能を置き換えます。
 この機能は、OUT転送のためのものです。
希望するエンドポイントの番号 (2, 4, 6, or 8) を書き込む事により、
 EZ-USB のハードウェアは自動的に、パケットを、スキップまたは、渡します。
(SKIP Bitの設定に依ります。)

注意
このビットは、「REVCTL.0 = 0」の場合、効果を発揮しません。
今回は
http://www.nahitech.com/nahitafu/fpgavhdl/fpgacfg/fpgacfg.html
あたりのSlave Serial Modeでコンフィギュレーションする。

FPGAで、コンフィギュレーションのモードを設定するM0,M1,M2は、

「Spartan-3ジェネレーション コンフィギュレーション ガイド Spartan-3A、Spatran-3E、および Spartan-3 FPGA ファミリ」

より、HSWAPがLowの場合は、
内部でプルアップされているので、
1なら解放しておいても問題ない。(page.47参照)
ただし、今回DWマガジンの付録ではHighとなっているので、
大人しく(4.7kΩで)プルアップしておく。

0ならGNDに落とす。



EZ-USBからの接続は、330Ωの抵抗を直列に接続しておく。
……ところで、Slave Serial Modeは3.3Vなのか2.5Vなのかどちらなのだろうか?
XAPP453参照。らしい。

XAPP453のpage.9を見ると、
M0,M1,M2は、2.5Vに直接接続されている。……なんだ、それでいいのか。
EZ-USBからの接続は、56Ωの抵抗を直列に接続している……のかな?
DINだけは3.3V駆動なのか?抵抗が接続されていない。

page.2にDINについて、3.3Vとは書いていないが、
少なくとも2.5Vには横線が引いてあるので違うのだろう。

たぶんこれで大丈夫?かな?OK

http://www.cqpub.co.jp/dwm/contents/0124/dwm012400660.pdf

あたりによると、
VCCINT:コア電源(1.2V)
VCCCAUX:補助電源(2.5V)
VCCO:I/O電源(3.3V)

付録雑誌の回路図を見ても確かにそのように接続されていた。

結局、

PROG:2.5Vなので、56Ωの抵抗を直列に接続(75Ωで代用)
CCLK:2.5Vなので、56Ωの抵抗を直列に接続(75Ωで代用)
DATA:3.3Vなので、直接接続
DONE:330Ωで2.5Vにプルアップしてから接続

M0,M1,M2は2.5Vに直接接続。

といった感じの接続になる。
FPGA参考図書

FPGAボードで学ぶ組み込みシステム開発入門[Xilinx編]
小林優[著]
低価格FPGAボードで体験する
ハードウェア&ソフトウェア設計
AUTOPTRLを用いると、
XAUTODAT1にPCからのデータが受信されて、
XAUTODAT2に書き込む事でPCに送信される。

AUTOPTRSETUPを使用すると、EP□BCH、EP□BCLにサイズを書き込まなくても、自動的に送信される。たぶん。





EP1OUTCFG
EP1INCFG

EP2CFG
EP4CFG
EP6CFG
EP8CFG
の設定については、「EZ-USB(R) Technical Reference Manual.pdf」で、
■「8.4 How the CPU Configures the Endpoints」(page.88)にレジスタの意味。
■「15.6 Endpoint Configuration」の「15.6.1 EP1OUTCFG」(page.233)~(page.236)辺りにレジスタの定義。
をそれぞれ参照すると良い。



バッファの分け方については
「1.17 EZ-USB Endpoint Buffers」(page.30)



AUTOPTRSETUPについて、
「EZ-USB(R) Technical Reference Manual.pdf」の(page.215)より、

The AUTOPTRSETUP register is configured as follows:
■ Set APTRnINC=0 to freeze the address pointer, APTRnINC=1 to automatically increment it for every read or write of an
XAUTODATn register. This bit defaults to ‘1’, enabling the auto increment feature.
■ To enable the autopointer, set APTREN=1. Enabling the Autopointers has one side-effect: any code access (an instruction
fetch, for instance) from addresses 0xE67B and 0xE67C return the AUTODATA values, rather than the code-memory values
at these two addresses. This introduces a two-byte ‘hole’ in the code memory.
The firmware then writes a 16 bit address to AUTOPTRHn/Ln. Then, for every read or write of an XAUTODATn register, the
address pointer automatically increments (if APTRnINC=1).

要するに、XAUTODATnへリードorライトする毎に、自動的に、データの格納されたバッファのポインタがインクリメントされる。
ところで、サンプルで

  // enable dual autopointer feature
  AUTOPTRSETUP |= 0x01;

となっているのは、「|=」(ビット和代入)していて、もともと、APTRnINCはデフォルトの設定が1なので、

AUTOPTRSETUP = 0x07;

とするのと同じ。



「EZ-USB(R) Development Kit User Guide.pdf」のコメントより、

APTR1H = MSB( &EP2FIFOBUF ); // Initializing the first data pointer
APTR1L = LSB( &EP2FIFOBUF );

APTRnH,APTRLは、data pointerの始めの開始位置を指定するときに使うらしい。


「C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.0\Firmware\Bulkext」
のBulkextの「bulkext.c」を書き直しただけだと、「EP1」がホストで認識されない問題について、

「C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.0\Firmware\EP_Interrupts」
のサンプルプログラムでは、ホストで認識された。

そこで、「bulkext.c」の内容を「EP_Interrupts.c」に書き換えて、コンパイルしたところ、
またも失敗する。

ファイル比較ソフトで両者のファイルの違いを比較したところ、
「dscr.a51」ファイルで違いが見られた。
(なお、ファイルの比較には「DF.txt」というファイル比較ソフトを用いた。)
このファイルでは

      db   4               ;; Number of end points


      db   6               ;; Number of end points

や、その他に、EP1に関する部分について違いが見られた。

そこで、「dscr.a51」を入れ替えた所、ホストで認識できるようになった。


この if文 "if (!(USBCS & bmRENUM))" をコメントアウトして FWをビルドして やれば、ダウンロード(CPUリセット)の度、毎回 ReNumerationされるようになるので 「ミミックUSB FX2」 もうまく動くようになります。

http://www.geocities.jp/altshibabou/win/ezusb_tip3sub.html
より。











DCMの使い方。

http://japan.xilinx.com/support/documentation/user_guides/j_ug331.pdf

のpage.71と、page.64の

周波数合成の出力CLKIN を分数値 M/D (M = {2..32}、D = {1..32}) で逓倍
• CLKFX
• CLKFX180

辺りを参照。

Spartan3E DCMからクロックが出てこない
の記事は、なりかねないので、注意しておこう。

MCP4726の使い方メモ。



がた老AVR研究所
によると、


 EEPROMの使い道はまだ良くわからない。判然とはしないが、電源断を含む運転を想定していて、前の値を保持しているだけのようだ。

この辺りは私も手を出す予定はないのでパスしよう。


ディバイスのアドレスは出荷時に固定で、あとからは換えられない。

D/Aコンバータを増やすたびにFPGAのIOを消費するかと思ったが、
恐らくその心配はなさそうだ。(I2Cだし……)

と、思ったのだが、秋月のDIP版の説明書が、マニュアルの必要部分を要約していて、
どうやらアドレスは全て
「ICアドレス:‘1100000’(7ビットアドレス) 」で固定らしい。
良く見ると「http://akizukidenshi.com/catalog/g/gI-07611/」の説明にも書いてあった。
最悪だ。
この説明はマニュアルのpage.46
ICの型番でアドレスが決まっている。
「http://www.chip1stop.com/」に「MCP4726A0T-E/XX」以外の型番を発見。



 データシートには具体例があるので、数値入力12ビットをアナログ化する手順だけなら間題ない。1ブロックを27ビットとし、頭1バイトをI2Cのマスター書き込み宣言、続いてデータバイト2バイトを送る。それぞれのバイトのあとにACKビットが1ビットづつ付くので計27ビット分を送ると、ディバイスはアナログ電圧をラッチする。



I2Cのクロックは、625μsのサンプリング期間に27ビットが送り終える速さにしなければならない。ビットレートを100khz程度で、30ビット->300μsで送れるようクロックを調整する。



そもそもの、I2Cについては、
電子工作の実験室」の「I2Cモジュールの使い方」(http://www.picfun.com/i2cframe.html)の
I2Cの接続構成とプルアップ抵抗
I2Cの基本データフォーマット

CCS Cコンパイラ実用プログラミングテク」の「11. I2Cの使い方(旧)」を参考にする。



あとはマニュアルのpage.50からのタイミングを見れば大体なんとかなりそうだと分かった。

ただ、プルアップ抵抗の値が心配なのと、クロスストレッチって、これショートしてませんか?
まあ、クロスストレッチに関してはその部分のタイミングが掛かれていないので、考えなくても大丈夫かな?

データシートのpage64によると、プルアップは

R1 and R2:
5 kΩ - 10 kΩ for fSCL = 100 kHz to 400 kHz
~700Ω for fSCL = 3.4 MHz



出力電圧は電源電圧に対して12Bit分に分割されると考えて合っているのだろうか?
……まあ、やってみれば分かる事か。




型番メモ。

秋月電子
MCP4726A0T-E/CH
2個入り180円(1個90円)


「http://www.chip1stop.com/」

「MCP4726A0T-E/CH」
1個135円~
「MCP4726A0T-E/MAY」
1個200円~


「MCP4726A1T-E/CH」
1個135円~


「MCP4726A2T-E/CH」
1個135円~


「MCP4726A3T-E/CH」
1個135円~

今回は6個使う予定なので、数百円高くなるが、秋月に無い型番はこちらで調達しようと思う。
Clockは共有できるので、クロック以外の6ピンが2ピンに削減できる予定。




page.8より

SCL pin Frequency

Standard mode 0 100 kHz Cb = 400 pF, 2.7V - 5.5V
Fast mode 0 400 kHz Cb = 400 pF, 2.7V - 5.5V
High-Speed 1.7 0 1.7 MHz Cb = 400 pF, 4.5V - 5.5V
High-Speed 3.4 0 3.4 MHz Cb = 100 pF, 4.5V - 5.5V

要するに、3.3Vの場合、通信速度は、400kHzまでらしい。



page.2の表より、Vrefやゲインと抵抗を操作できる。
ゲインはGで、
抵抗はPDで操作する。
PDについては、page.40の表より、

TABLE 4-2: POWER-DOWN BITS AND
OUTPUT RESISTIVE LOAD

PD1 PD0 Function
0 0 Normal operation
0 1 1 kΩ resistor to ground
1 0 125 kΩ resistor to ground
1 1 640 kΩ resistor to ground

今回は{PD1,PD2}={0,0}とする。

VrefやGはpage.51~55までの操作(など?)で変更できるが、
今回はデフォルトのままで使う。








SDRAMのメモ

http://pdf.datasheetarchive.com/indexerfiles/Datasheet-093/DSA0072064.pdf
を参考にしてSDRAMのコントローラを作る。

実装例は
http://www.hmwr-lsi.co.jp/fpga/fpga_10.htm

実際に使うSDRAMは、
http://akizukidenshi.com/catalog/g/gI-08265/
SDRAM EDS1216AGTA-75-E



CS(ChipSelect)に関係なく、readやwriteしていない時は、DQ(データバス)はHi-Z

ただし、

page.34

備考 初期化シーケンス中は、出力がハイ・インピーダンス状態であることを保証するため,CKE とDQM を
ハイレベルの状態に保持することを推奨します。

->FPGAのIOが足りないので無理。
大丈夫だと祈って諦める。


page.38

例 2)バースト長:フル・ページ(512)の場合
1 回のコマンド入力により,フル・ページ分のデータを連続して入出力します。
このとき,入出力データはラップ・アラウンド動作をするため,データの入出力を止める場合,バース
ト・ストップ・コマンド,リード/ライト・コマンド,プリチャージ・コマンドを用いて止める必要があ
ります。


なお,バースト長をフル・ページに設定した場合,オート・プリチャージ付きリード/ライト・コマン
ドを入力しないでください。





page.35~
4.1 モード・レジスタ設定

バースト長の設定:フルページ

ラップ・タイプの設定:シーケンシャル

/CAS レーテンシの設定:「CL=3」
SDRAM EDS1216AGTA-75-Eのpage.7の「System clock cycle time」より、
「CL=3」(CL : /CAS Latency)の場合、型番が「75」なので、
Clockは「7.5ns==133.333MHz」まで対応できる。

オプション:それぞれのデータシートの「mode」の項目を参照する。
今回の場合だと、SDRAM EDS1216AGTA-75-Eのpage.21に書いてある。

今回はフルページなので、A3のBT=0(シーケンシャル)でしか、{A2,A1,A0}={1,1,1}
のFullPageに対応していない事が分かるので注意。


第 7 章基本動作モード
page.59



リフレッシュサイクルについて、

http://documentation.renesas.com/doc/products/mpumcu/apn/rjj06b0867_sh7730ap.pdf
のpage.16について、

SDRAM の仕様で,64 ms (tREF) 期間内に4096 回 (Ref_Cyc) リフレッシュを行う必要がある

と言う意味らしい。

これは今回使うSDRAM EDS1216AGTA-75-Eのpage.7にも、それらしき記述がある。



2.5.3 リフレッシュサイクル
(1) SDRAM に対してリフレッシュを実施する間隔時間 (tREF) を設定します。
(2) オートリフレッシュサイクルのウェイトサイクル (Trc) を設定します。
本設定において,SH7730 と使用するSDRAM のバスタイミングを満たしていることを確認します。
• SDRAM のtREF (リフレッシュ間隔時間)
tREF(max) ≥ tcyc × CKS × RTCOR × Ref_Cyc
* SDRAM の仕様で,64 ms (tREF) 期間内に4096 回 (Ref_Cyc) リフレッシュを行う必要があるた
め,上記の計算式を満たす必要があります。【参考】の結果より,tREF (64 ms) ≥ 60.9 ms となる
ため条件は満たしています。
【参考】
Tcyc = 15 ns, CKS = 16, RTCOR = 62, Ref_Cyc = 4096 とすると,
リフレッシュカウンタのクロック周期: tcyc × CKS = 240 (ns)
1 回当たりのリフレッシュ間隔時間: tcyc × CKS × RTCOR = 14.9 (μs)*
4096 回のリフレッシュ間隔時間: tcyc × CKS × RTCOR × Ref_Cyc = 60.9 (ms)
【注】 バスサイクル実行中にリフレッシュ要求が発生した場合は,リフレッシュの実行はバスサイ
クルの完了まで待たされます。このようなリフレッシュするタイミングが遅れる場合を考慮
して,本設定例では,RTCOR の設定に余裕を持たせています。
• SDRAM のtRC (リフレッシュサイクル時)
tRC(min) ≤ (tcyc × Trc) + (Tr) ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ (図9)
* Tr = Trc = tcyc

上記のルネサスの例では、64msの間隔に対して60.9msに設定しており、
約5.09%の余裕を持っている。
この例に倣い、今回は5%の余裕を持って計算する。














Slave FIFOs メモ書き③

レジスタの設定についてのメモ。


「15.6.3 EPxCFG」について、


---------------

1:0 BUF[1:0] Buffering Type/Amount.

00 Quad
01 Invalid
10 Double
11 Triple

Note
The Valid bit is ignored
when buffer space is allocated by the EZ-USB
(for example, BUF[1:0] takes precedence over the Valid bit).

When you are not using all of the endpoints in the endpoint configuration,
disable the unused endpoints by writing a zero into the “valid” bit of
the corresponding EPxCFG register without disturbing the default state of the other bits in the register.

For example, if the endpoint configuration 11 (see 1.17 EZ-USB Endpoint Buffers on page 30), which uses only endpoints 2 and 8, must be
used, configure the endpoints as follows.
EP2CFG = 0xDB;
SYNCDELAY;
EP8CFG = 0x92;
SYNCDELAY;
EP4CFG &= 0x7F;
SYNCDELAY;
EP6CFG &=0x7F;
SYNCDELAY;

バッファスペースが EZ-USB によって割り当てられている時、
VALID(EPxCFGの 7Bit目の事)は無視されます。
(例えば、 BUF[1:0]  ( 今説明している、EPxCFGの 0番目と 1番目のビット ) は、
VALIDよりも優先されます。)

//要するに、512Byteのバッファ4つをEP2に割り当て、
//同様に、512Byteのバッファ4つをEP6に割り当てる時、
//合計のメモリ容量は4kByteまでしかないので、
//(EP2+EP4+EP6+EP8<=4kByte、4キロバイト以下でなければいけないので、)
//EP2とEP4を組み合わせて512kByte*4==2kByte確保する事になる。
//その時、EP4 の VALID は、BUF[1:0]が優先されるため無効となる。

全てのエンドポイントを使用しない場合は、
対応するEPxCFGレジスタのデフォルトの設定が悪さをしないように、
“valid” bitに0を書き込むことで、エンドポイントを無効にする。

例えば、
(1.17 EZ-USB Endpoint Buffers on page 30)の
「 the endpoint configuration 11 」の設定をしたい場合、
エンドポイント2と8は以下の様に設定される。
EP2CFG = 0xDB;
SYNCDELAY;
EP8CFG = 0x92;
SYNCDELAY;
EP4CFG &= 0x7F;
SYNCDELAY;
EP6CFG &=0x7F;
SYNCDELAY;





















---------------
---------------
---------------

Slave FIFOs メモ書き②

レジスタの設定についてのメモ。


「15.6.4 EPxFIFOCFG」について、

---------------

6 INFM1 IN Full Minus One.
When a FIFO configuration register’s ‘INEARLY’ or INFM bit is set to ‘1’, the FIFO flags for that endpoint
become valid one sample earlier than when the FULL condition occurs. These bits take effect
only when the FIFOs are operating synchronously—according to an internally or externally supplied
clock. Having the FIFO flag indications a clock early simplifies some synchronous interfaces (applies
only to IN endpoints).

INEARLYかINFM のいずれかのビットが1にセットされている時、
FULL になるよりも一サンプル早くフラグが有効になる。

これらのビット(INEARLYとINFM )は、
同期モードの場合だけ(内部あるいは外部から供給されているクロックに従って)効果を表す。

一クロック早く結果を示すフラグは、いくつかの同期転送のインターフェースを簡素化します。

(INエンドポイントのみに適用されます。)


---------------

5 OEP1

 OUT Empty Plus One.
When a FIFO configuration register’s ‘OUTEARLY’ or OEP1 bit is set to ‘1’, the FIFO flags for that
end point become valid one sample earlier than when the EMPTY condition occurs. These bits take
effect only when the FIFOS are operating synchronously—according to an internally or externally
supplied clock. Having the FIFO flag indications a clock early simplifies some synchronous interfaces
(applies only to OUT endpoints).

OUTEARLYかOEP1のいずれかのビットが1にセットされている時、
EMPTYになるよりも一サンプル早くフラグが有効になる。

これらのビット(OUTEARLYとOEP1)は、
同期モードの場合だけ(内部あるいは外部から供給されているクロックに従って)効果を表す。

一クロック早く結果を示すフラグは、いくつかの同期転送のインターフェースを簡素化します。

(OUTエンドポイントのみに適用されます。)


---------------

4 AUTOOUT

 Instantaneous Connection to Endpoint FIFO. This bit applies only to OUT endpoints.

0 As soon as a buffer fills with USB data, an endpoint interrupt is asserted. The connection of
the buffer to the endpoint FIFO is under control of the firmware, rather than automatically
being connected. Using this method, the firmware can inspect the data in OUT packets, and
based on what it finds, choose to include that packet in the endpoint FIFO or not. The firmware
can even modify the packet data, and then commit it to the endpoint FIFO. Refer to
Enhanced Packet Handling in section Chip Revision Control Register on page 231.

1 As soon as a buffer fills with USB data, the buffer is automatically and instantaneously committed
to the endpoint FIFO bypassing the CPU. The endpoint FIFO flags and buffer counts
immediately indicate the change in FIFO status. Refer to the description of the DYN_OUT
bit in section Chip Revision Control Register on page 231.

The SKIP bit (in the EPxBCL registers) chooses between skipping and committing packet data. Refer
to OUTPKTEND in section Force OUT Packet End Register on page 255.

0:バッファが一杯になったら、ファームウェアに割り込みでコントロールが渡される?
1:バッファが一杯になったら、CPUバイパスして(迂回して)勝手にPCへFIFOへ送信する?


---------------

3 AUTOIN

 Auto Commit to SIE. This bit applies only to IN endpoints.
EZ-USB has EPxAUTOINLEN registers that allow the firmware to configure endpoints to sizes
smaller than the physical memory sizes used to implement the endpoint buffers (512 or 1024 bytes).
For example, suppose the firmware configures the EP2 buffer to be 1024 bytes (this must match the
wMaxPacketSize value in the endpoint descriptor), and then sets up EP2 as a 760 byte endpoint by
setting EP2AUTOINLEN=760. This makes EP2 appear to be a 760 byte endpoint to the USB host,
even though EP2's physical buffer is 1024 bytes.

0 Each packet has to initially be manually committed to SIE, (prime the pump). See section
Chip Revision Control Register on page 231.

1 EZ-USB automatically packetizes and dispatches IN packets according to the packet length
value it finds in the EPxAUTOINLEN registers. In this example, the GPIF (or an external
master, if the EZ-USB is in Slave FIFO mode) could load the EP2 buffer with 950 bytes,
which the EZ-USB logic would then automatically send as two packets, of 760 and 190
bytes. Refer to Enhanced Packet Handling in section Chip Revision Control Register on
page 231.

0
パケットのサイズを始めに定義する必要があるって事?

1
エンドポイントを本来よりも小さい大きさに見せかける事ができる。
例えばEP2について、EPxAUTOINLENを760Byteに設定すると、
950Byteのデータは760Byteと190Byteのパケットに分割されて、自動的ホスト(PC)側に送信される。

//……1パケット目の760Byteは兎も角、2パケット目の190Byteは、
//書き込みが終了した事を合図に送信されるのかな?


---------------

2 ZEROLENIN

 Enable Zero length IN Packets.
0 Zero length packets are sent on PKTEND.
1 A zero length packet is sent when PKTEND is activated and there are no bytes in the current
packet.

//良く分からなかった。
0:長さ0のパケットはPKTENDに?送られる。(長さ0のパケットはPCに送られる、って事では無くて?)(あるいは、長さ0だと送信されないのか?)

こちらは「packets」なので、複数のデータが送られるって事?

1:PKTENDが有効ならば、長さ0のパケットは(PCに?)送信される。そして現在のパケットにはデータが無い???(エンドポイントにデータが無い、で良いのか???)

こちらは「packet」なので、単数(一つ)のデータが送られるって事?

//どちらにせよ、長さ0のパケットがPCに送信されるとは考えずらいので、???
//……つまり、つまり、意味が分からない……。


---------------

0 WORDWIDE

 Select Byte/Word FIFOs on PORTB/D Pins.
This bit selects byte or word FIFOS on the PORTB and PORTD pins. The WORD bit applies ‘for
IFCFG =11 or 10’.
The OR of all four WORDWIDE bits is what causes PORTD to be PORTD or FD[15:8]. The individual
WORDWIDE bits indicate how data is to be passed for each individual endpoint.

0 WORDWIDE
Select Byte/Word FIFOs on PORTB/D Pins.
FIFOでのビット幅の選択(8bitOR16bit)
0:Byte幅(8bit)
1:WORD幅(16bit)
「IFCFG =11」にして、「Slave FIFO Interface (external master)」を選択している必要がある。


---------------

Slave FIFOs メモ書き①

「EZ-USB(R) Technical Reference Manual.pdf」
の(page.99~)「9.Slave FIFOs」について、


The FIFOADR[1:0] pins select which of the four FIFOs is
connected to the FD bus and is being controlled by the
external master.

FIFOADR[1:0] pins:(FPGA->EZ_USB_FX2LP)
接続先の4つのFIFO(エンドポイント?)を選択する。





In asynchronous mode (IFCONFIG.3 = 1), SLRD and SLWR
are read and write strobes; in synchronous mode
(IFCONFIG.3 = 0), SLRD and SLWR are enables for the
IFCLK clock pin.

IFCLK clock pin:(FPGA<->EZ_USB_FX2LP)(双方向)
信号の同期を取るクロックを出力するピン???

http://optimize.ath.cx/cusb_spa3/index.html」に説明があった。

•非同期転送モードよりは同期転送モードがはるかに高速
•IFCLKは外部クロックを使用するより、内部クロックを使用したほうがタイミング的に楽になる
•エンドポイントの切り替え(FIFOアドレスの変更)はタイミング的にかなりのペナルティーになる

らしい。
良く分からないが、page.102「9.2.3 Interface Clock」を見た感じだと、

今回は発振器を付けないので、EZ_USB_FX2LPでCLKOEのフラグを立てることで、
CLKOUT端子から出力したクロックでFPGAを駆動し、
さらに、FIFOについては、FPGAからのクロックで駆動する。って感じかな。
確かにタイミングは楽になりそうだ。
→良く考えれば、これだとFPGA->EZ_USB_FX2LPへの転送は兎も角、
EZ_USB_FX2LP->FPGA向きの転送はタイミングを揃える必要がある(とは言っても48MHzで問題になるとは思わない……と信じている)。
→しかし、クロックが外部であれば、クロックを止める事もできるだろうから、
デバックはやり易いと思われる。
→まあ、それなら非同期転送でも同じだけれど……。

「Figure 9-6. IFCLK Configuration」の説明で、IFCL Kレジスタを設定すればいい。

オプティマイズの設定は同期では無く非同期だった。



The FIFO Data (FD) bus, FD[x:0], can be either 8- or 16-bits
wide. The width is selected via each FIFO’s WORDWIDE
bit, (EPxFIFOCFG.0):
■ WORDWIDE = 0: 8-bit mode. FD[7:0] replaces Port B.
See Figure 9-4.
■ WORDWIDE = 1: 16-bit mode. FD[15:8] replaces Port D
and FD[7:0] replaces Port B. See Figure 9-5. FD[7:0] is
the LSB of the word, and FD[15:8] is the MSB of the
word.

8-bit mode. FD[7:0] replaces Port B.
16-bit mode. FD[15:8] replaces Port D and FD[7:0] replaces Port B.
(FPGA<->EZ_USB_FX2LP)(双方向)




「9.2.4 FIFO Flag Pins (FLAGA, FLAGB,FLAGC, FLAGD)」より、

Flag pins configured for Indexed mode report the status of
the FIFO currently selected by the FIFOADR[1:0] pins.
When configured for Indexed mode, FLAGA reports the programmable
level status, FLAGB reports the ‘full’ status, and
FLAGC reports the ‘empty’ status.

FLAGA : the programmable level status
FLAGB : the ‘full’ status
FLAGC : the ‘empty’ status.

(EZ_USB_FX2LP->FPGA)

フラグは自分で決めるんだったっけ?(下記)




同じく
「9.2.4 FIFO Flag Pins (FLAGA, FLAGB,FLAGC, FLAGD)」より、
Flag pins configured for Fixed mode report one of the three
conditions for a specific FIFO, regardless of the state of the
FIFOADR[1:0] pins. The condition and FIFO are userselectable.
For example, FLAGA could be configured to
report FIFO2’s ‘empty’ status, FLAGB to report FIFO4’s
‘empty’ status, FLAGC to report FIFO4’s ‘programmable
level’ status, and FLAGD to report FIFO6’s ‘full’ status.

FLAGの意味を自分で設定できる……って事???
(EZ_USB_FX2LP->FPGA)


The polarity of the ‘empty’ and ‘full’ flag pins defaults to
active-low but may be inverted via the FIFOPINPOLAR register.


On a hard reset, the FIFO flags are configured for Indexed
operation.

デフォルトでは「Indexed operation」らしい。




「9.2.5 Control Pins (SLOE, SLRD,SLWR, PKTEND, FIFOADR[1:0])」について、


--------------

In synchronous mode (IFCONFIG.3 = 0), the FIFO pointer is
incremented on each rising edge of IFCLK while SLRD is
asserted. In asynchronous mode (IFCONFIG.3 = 1), the
FIFO pointer is incremented on each asserted-to-deasserted
transition of SLRD.

SLRD:Slave Read:(FPGA->EZ_USB_FX2LP)
同期転送の場合、
クロックが立ち上がった時、SLRDがLの場合、
データのポインタがインクリメントされ、
次の(あるいは最初の?)データがEZ_USB_FX2LPから出力される。???

データをFPGAに読み込む時、SLRDをLにする。???
「SLRD is asserted」ってLでいいのかな?

非同期転送の場合、
SLRDがL->Hを繰り返すごとにインクリメントされる。

--------------

The SLOE pin enables the FD outputs. In synchronous
mode, when SLOE is asserted, this causes the FD bus to be
driven with the data that the FIFO pointer is currently pointing
to. The data is pre-fetched and is output only when
SLOE is asserted. In asynchronous mode, the data is not
pre-fetched, and SLRD must be asserted when SLOE is
asserted for the FD bus to be driven with the data that the
FIFO pointer is currently pointing to. SLOE has no other
function besides enabling the FD bus to be in a driven state.
By default, SLOE and SLRD are active-low; their polarities
can be changed via the FIFOPINPOLAR register.

SLOE:Slave Output Enable:(FPGA->EZ_USB_FX2LP)
EZ_USB_FX2LPに対して、FD(FIFO Data)へのデータの出力を許可する。
(FD(FIFO Data)は双方向なので、注意して制御しないと、ショートする可能性がある。)


--------------

Slave Write — SLWR
In synchronous mode (IFCONFIG.3 = 0), data on the FD bus
is written to the FIFO (and the FIFO pointer is incremented)
on each rising edge of IFCLK while SLWR is asserted. In
asynchronous mode (IFCONFIG.3 = 1), data on the FD bus
is written to the FIFO (and the FIFO pointer is incremented)
on each asserted-to-deasserted transition of SLWR.
By default, SLWR is active-low; its polarity can be changed
via the FIFOPINPOLAR register.

SLWR:Slave Write:(FPGA->EZ_USB_FX2LP)
クロックが立ち上がった時、SLWRがLの場合、
データがEZ_USB_FX2LPに書き込まれる。


--------------

FIFOADR[1:0]:
The FIFOADR[1:0] pins select which of the four FIFOs is
connected to the FD bus (and, if the FIFO flags are operating
in Indexed mode, they select which FIFO’s flags are presented
on the FLAGx pins):


Table 9-2. FIFO Selection via FIFOADR[1:0]
+--------------------------+
|FIFOADR[1:0]  |  Selected FIFO|
+------------+-------------+
|         00          |    EP2               |
|         01          |      EP4             |
|         10          |      EP6             |
|         11          |      EP8             |
+--------------------------+

FIFOADR[1:0]:FIFO address:(FPGA->EZ_USB_FX2LP)
FPGAが接続する先のエンドポイントを選択する。


--------------

PKTEND
An external master asserts the PKTEND pin to commit an IN
packet to USB regardless of the packet’s length. PKTEND is
usually used when the master wishes to send a ‘short’
packet (for example, a packet smaller than the size specified
in the EPxAUTOINLENH:L registers).

For example: Assume that EP4AUTOINLENH:L is set to the
default of 512 bytes. If AUTOIN = 1, the external master can
stream data to FIFO4 continuously, and (absent any bottlenecks
in the data path) the EZ-USB automatically commits a
packet to USB whenever the FIFO fills with 512 bytes. If the
master wants to send a stream of data whose length is not a
multiple of 512, the last packet is not be automatically committed
to USB because it is smaller than 512 bytes. To commit
that last packet, the master can do one of two things: It
can pad the packet with dummy data in order to make it
exactly 512 bytes long, or it can write the short packet to the
FIFO, then pulse the PKTEND pin.

PKTEND:Packet End:(FPGA->EZ_USB_FX2LP)
FPGAからEZ_USB_FX2LPにデータを書き込む時、
FIFOに512Byte(the EPxAUTOINLENH:L registersのサイズなので、設定によっては512Byteとはならないと考えられる。)溜まると自動的にPCへ転送されるが、
512Byte以下(the EPxAUTOINLENH:L registersのサイズ以下のサイズ)のデータを転送したい場合は、
PKTENDをLにすれば良い。


……
逆に、PC->EZ_USB_FX2LP->FPGA
に「the EPxAUTOINLENH:L registers」のサイズ以下のサイズ
のデータを転送したい場合は……どうなるのだろうか?


--------------
引き続きPKTENDについて。

Note The PKTEND pin must not be asserted unless a
buffer is available, even if only a zero-length packet is being
committed. The ‘full’ flag may be used to determine whether
a buffer is available.

例え0の長さのパケットが約束されているとしても、
バッファが利用可能でない時にPKTEND pinをLにしてはいけない。
‘full’フラグによってバッファが利用可能かどうか判断できる。

(おそらく0でも1でも10でも512でも64でもバッファが利用可能でなければダメって事かな。)


--------------

Note In synchronous mode, there is no specific timing
requirement for PKTEND assertion with respect to SLWR
assertion. PKTEND can be asserted anytime. In asynchronous
mode, SLWR and PKTEND should not be pulsed at
the same time. PKTEND should be asserted after SLWR
has been deasserted for the minimum deasserted pulse
width. In both modes, FIFOADR[1:0] should be held constant
during the PKTEND pin assertion.

同期転送では、PKTENDとSLWRのタイミングの問題で注意する点は無い。
非同期転送では、PKTENDとSLWRは同時にパルスさせてはいけない。
PKTENDは、SLWRがdeasserted(Lにして再びHに)された後で、
assert(Lにする事)する必要がある。
また、どちらのモードでも、PKTENDがLの間は、FIFOADR[1:0]を一定に保つ必要がある。




「9.2.6 Slave FIFO Chip Select」(page.104)について。

SLCS:The Slave FIFO Chip Select:(FPGA->EZ_USB_FX2LP)


The Slave FIFO Chip Select (SLCS#) pin is an alternate
function of pin PA7; it is enabled via the PORTACFG.6 bit
(see section 13.4.1 Port A Alternate Functions on
page 185).

The SLCS# pin allows external logic to effectively remove
the EZ-USB from the FIFO Data bus, in order to, for example,
share that bus among multiple slave devices. For applications
that do not need to share the FD bus among multiple
slave devices, the SLCS# pin can be tied to GND to permanently
select the EZ-USB slave FIFO interface. This configuration
is assumed for the interface and timing examples that
follow.

While the SLCS# pin is pulled high by external logic, the EZUSB
floats its FD[x:0] pins and ignores the SLOE, SLRD,
SLWR, and PKTEND pins.

SLCSは、pin PA7の選択できる機能の内の一つ。
PORTACFG.6 bitによって有効にできる。

SLCSを使う事によって、複数のデバイスで
「FD[x:0]、SLOE、SLRD、SLWR、PKTEND」
を共有させる事ができる。

//(例えば一つのFPGAに複数のスレーブのEZ_USB_FX2LPが接続されている場合、
//FPGAがどちらのEZ_USB_FX2LPと通信するかを選択する事ができる。)

そのようなバスを共有する必要の無いアプリケーションでは無い場合は、
SLCSは永続的にGNDに接続する事ができる。

SLCSがhighの間は、EZ_USB_FX2LPは、FD[x:0] pinsをハイ・インピーダンスに設定し、
SLOE、SLRD、SLWR、PKTENDの信号を無視する。


--------------
(see section 13.4.1 Port A Alternate Functions on page 185)
の部分について。


Table 13-1. Register Bits that Select Port A Alternate Functions
~中略~
[1] Although the SLCS alternate function is selected by bit 6 of PORTACFG, that function does not appear on pin PA6. Instead, the SLCS function appears
on pin PA7 (see Table 13-2).

SLCSを有効にするのはPORTACFGの6bit目だが、実際のピンはPA7なので注意。



Table 13-2. Port A Alternate Function Configuration
PA.0:INT0                   <-FIFO以外で使えそう(ただし割り込み端子)
PA.1:INT1                   <-FIFO以外で使えそう(ただし割り込み端子)
PA.2:SLOE
PA.3:WU2                   [1]<-FIFO以外で使えそう?
PA.4:FIFOADR0
PA.5:FIFOADR1
PA.6:PKTEND
PA.7:FLAGD  [2]  /SLCS     [3]<-???

[1] When PA.3 is configured for alternate function WU2, it continues to function as a general purpose input pin as well. See section 6.4.1 WU2 Pin on page 81
for more information.
[2] Although PA.7’s alternate function FLAGD is selected via the PORTACFG register, the state of the FLAGD output is undefined unless IFCFG1:0 = 11.
[3] FLAGD takes priority over SLCS if PORTACFG.6 and PORTACFG.7 are both set to ‘1’.

[1]
WU2を設定している場合は、汎用入力端子としても使える。

[2]
PA.7をFLAGDに設定するにはPORTACFGだけでなく、「IFCFG1:0 = 11」を指定する必要がある。
つまり、
PORTACFG = 0x80 | ( PORTACFG & 0x3F );
//あるいは他に設定しないのであれば単純に、「PORTACFG=0x80;」
//
//あるいは注意書き[3]を前提にするのであれば
//「PORTACFG |= 0x80;」
//で問題ない。

IFCONFIG = 0x03;
となる。

[3]
PORTACFG.6 と PORTACFG.7 が共に 1 にセットされている場合は、
FLAGD が SLCS よりも優先される。
--------------
上記のSLCSについて、指定しなければおそらく、SLCSが常にGNDに設置されているのと同じ条件になると考えられる。




FD[x:0] pinsがハイ・インピーダンスになっているタイミングは、
恐らくタイミングチャートに「Z」と書かれている期間。(Hi-Zの略だと思う。たぶん。)




http://optimize.ath.cx/FX2_USB/fifo.htm
に各フラグの意味が、簡単にだが説明されている……。





レジスタのメモ書きは以上。以下より書き込み及び読み込みのタイミングについて考える。


page.105~
「9.2.7 Implementing Synchronous Slave FIFO Writes」






page.107~
「9.2.8 Implementing Synchronous Slave FIFO Reads」