STM32F1 ETHERNET

Started by tha, February 11, 2021, 08:40:30 AM

Previous topic - Next topic

tha

•    Frame check sequence: 4-byte field ที่บรรจุ the cyclic redundancy check (CRC) value. The CRC computation อยู่
      บนฐานของฟิลด์ต่อไปนี้ : source address, destination address, QTag prefix, length/type, LLC data and PAD (นั่นคือ,
      fields ทั้งหมดยกเว้น the preamble, SFD). The generating polynomial เป็นดังต่อไปนี้ :

     

The CRC value ของ a frame ถูกคำนวณดังต่อไปนี้ :
•    The first 2 bits ของ the frame ถูกเติมเต็ม
•    The n-bits of the frame เป็นสัมประสิทธิ์ของ a polynomial M(x) ของ degree (n – 1). The first bit of the destination
      address ตรงกันกับ the term และ the last bit of the data field ตรงกันกับ the term
•    M(x) ถูกคูณด้วย x32 และถูกหารด้วย G(x), ทำให้เหลือ R(x) ของ degree ≤ 31
•    ค่าสัมประสิทธิ์ของ R(x) ถูกพิจารณาเป็น a 32-bit sequence
•    The bit sequence ถูกเติมเต็มและผลลัพธ์คือ the CRC
•    The 32-bits of the CRC value ถูกใส่ใน the frame check sequence. The term ถูกส่งก่อน, the term ถูกส่งสุดท้าย



แต่ละ byte ของ the MAC frame, ยกเว้น the FCS field, ถูกส่ง low-order bit ก่อน.

An invalid MAC frame ถูกกำหนดโดยหนึ่งในเงื่อนไขต่อไปนี้ :
•    The frame length ไม่สอดคล้องกับค่าที่คาดหวังตามที่ระบุโดย the length/type field. ถ้า the length/type field บรรจุ a type
      value, ดังนั้น the frame length จะถือว่ามีความสอดคล้องกับฟิลด์นี้ (no invalid frame)
•    The frame length ไม่ใช่จำนวนเต็มของ bytes (extra bits)
•    The CRC value ที่คำนวณบน the incoming frame ไม่ตรงกับ the included FCS

tha

29.5.2 MAC frame transmission

The DMA ควบคุม transactions ทั้งหมดสำหรับ the transmit path. Ethernet frames อ่านจาก the system memory ถูกใส่ลงใน the FIFO โดย the DMA. The frames จากนั้นถูก popped out และถูกส่งถ่ายไปยัง the MAC core. เมื่อ the end-of-frame ถูกส่งถ่าย, the status ของ the transmission ถูกได้จาก the MAC core และส่งถ่ายกลับไปยัง the DMA. The Transmit FIFO มีความลึก 2 Kbyte. FIFO-fill level ถูกแสดงให้เห็นไปยัง the DMA เพื่อว่ามันสามารถเริ่มต้น a data fetch ใน required bursts จาก the system memory, โดย the AHB interface. The data จาก the AHB Master interface ถูกใส่ลงใน the FIFO.

เมื่อ the SOF ถูกตรวจพบ, the MAC ยอมรับ the data และเริ่มการส่งไปยัง the MII. The time ที่จำเป็นเพื่อส่ง the frame data ไปยัง the MII หลังจาก the application เริ่มต้น transmission ผันแปรได้, ขึ้นอยู่กับ delay factors อย่าง IFG delay, เวลาเพื่อส่ง preamble/SFD, และ any back-off delays สำหรับ Half-duplex mode. หลังจาก the EOF ถูกส่งถ่ายไปยัง the MAC core, the core เสร็จสมบูรณ์ normal transmission และจากนั้นให้ the status of transmission กลับไปยัง the DMA. ถ้า a normal collision (in Half-duplex mode) เกิดขึ้นในระหว่าง transmission, the MAC core ทำให้ the transmit status ถูกต้อง, จากนั้นยอมรับและดร็อป data ต่อไปทั้งหมดจนกระทั่ง the next SOF ถูกรับ. The same frame จะถูกส่งซ้ำจาก SOF บนการสังเกตุ a Retry request (ใน the Status) จาก the MAC. The MAC ปล่อยออก an underflow status ถ้า the data ไม่ถูกจัดให้มีอย่างต่อเนื่องในระหว่าง the transmission. ในระหว่าง the normal transfer ของ a frame, ถ้า the MAC รับ an SOF โดยไม่ได้รับ an EOF ของ the previous frame, ดังนั้น the SOF จะถูกไม่ยอมรับรู้และ the new frame ถูกพิจารณาเป็นความต่อเนื่องของ the previous frame.

tha

มีสองโหมดของการทำงานสำหรับดึง data ไปยัง the MAC core:
•    ใน Threshold mode, ทันทีที่จำนวนของ bytes ใน the FIFO ข้ามระดับขอบเขตที่กำหนดค่าไว้ (หรือเมื่อ the end-of-frame ถูก
      เขียนก่อนขอบเขตจะถูกข้าม), the data พร้อมที่จะถูก popped out และส่งต่อไปยัง the MAC core. The threshold level ถูก
      กำหนดค่าโดยใช้ the TTC bits of ETH_DMABMR.
•    ใน Store-and-forward mode, เพียงหลังจาก a complete frame ถูกเก็บใน the FIFO, the frame ถูก popped ไปยัง the
      MAC core. ถ้า the Tx FIFO size น้อยกว่า the Ethernet frame ที่จะถูกส่ง, ดังนั้น the frame ถูก popped ไปยัง the MAC
      core เมื่อ the Tx FIFO มาเป็นใกล้จะเต็ม.

The application สามารถล้าง the Transmit FIFO ของสิ่งที่อยู่ภายในทั้งหมดโดยการเซ็ต the FTF (ETH_DMAOMR register [20]) bit. บิตนี้เคลียร์ด้วยตัวเองและเริ่มต้น the FIFO ชี้ไปยัง the default state. ถ้า the FTF bit ถูกเซ็ตในระหว่าง a frame ส่งถ่ายไปยัง the MAC core, จากนั้น transfer จะถูกหยุดเนื่องจาก the FIFO ถูกพิจารณาว่าว่างเปล่า. ดังนั้น an underflow event เกิดขึ้นที่ the
MAC transmitter และ the corresponding Status word ถูกส่งต่อไปยัง the DMA.


tha

Automatic CRC and pad generation

เมื่อจำนวนของ bytes ที่รับจาก the application ตกลงต่ำกว่า 60 (DA+SA+LT+Data), ศูนย์ถูกต่อท้ายไปยัง the transmitting frame เพื่อทำให้ the data length เท่ากับ 46 bytes เพื่อตรงตาม the minimum data field requirement of IEEE 802.3. The MAC สามารถถูกโปรแกรมไม่ต่อท้ายด้วย any padding. The cyclic redundancy check (CRC) สำหรับ the frame check sequence (FCS) field ถูกคำนวณและต่อท้ายไปยัง the data ที่กำลังถูกส่ง. เมื่อ the MAC ถูกโปรแกรมไม่มีต่อท้ายด้วย the CRC value ไปยัง the end of Ethernet frames, the computed CRC จะไม่ถูกส่ง. ข้อยกเว้นของกฎนี้คือว่าเมื่อ the MAC ถูกโปรแกรมเพื่อต่อท้าย pads สำหรับ frames (DA+SA+LT+Data) ที่น้อยกว่า 60 bytes, CRC จะถูกต่อท้ายที่ the end of the padded frames.

The CRC generator จะคำนวณ the 32-bit CRC สำหรับ the FCS field ของ the Ethernet frame. การเข้ารหัสถูกกำหนดโดยพหุนามต่อไปนี้.


tha

Transmit protocol

The MAC ควบคุมการทำงานของ Ethernet frame transmission. มันดำเนินการหน้าที่ต่อไปนี้เพื่อตรงตาม the IEEE 802.3/802.3z specifications. มัน :
•    สร้าง the preamble and SFD
•    สร้าง the jam pattern in Half-duplex mode
•    ควบคุม the Jabber timeout
•    ควบคุมการไหลสำหรับ Half-duplex mode (back pressure)
•    สร้าง the transmit frame status
•    บรรจุ time stamp snapshot logic สอดคล้องกันกับ IEEE 1588

เมื่อ a new frame transmission ถูกร้องขอ, the MAC ส่งออก the preamble and SFD, ตามด้วย the data. The preamble ถูกกำหนดเป็น 7 bytes of 0b10101010 pattern, และ the SFD ถูกกำหนดเป็น 1 byte of 0b10101011 pattern. The collision window ถูกกำหนดเป็น 1 slot time (512 bit times สำหรับ 10/100 Mbit/s Ethernet). The jam pattern generation สามารถใช้ได้เฉพาะกับ Half-duplex mode, ไม่กับ Full-duplex mode.

ใน MII mode, ถ้า a collision เกิดขึ้นที่เวลาใดๆจากจุดเริ่มต้นของ the frame ไปยังจุดสิ้นสุดของ the CRC field, the MAC ส่ง a 32-bit jam pattern of 0x5555 5555 บน the MII เพื่อแจ้ง stations อื่นๆทั้งหมดว่า a collision ได้เกิดขึ้น. ถ้า the collision ถูกเห็นในระหว่าง the preamble transmission phase, the MAC เสร็จสมบูรณ์ the transmission ของ the preamble and SFD และจาก
นั้นส่ง the jam pattern.

A jabber timer ถูกค้ำจุนไว้เพื่อตัด the transmission of Ethernet frames ถ้ามากกว่า 2048 (ค่าเริ่มต้น) bytes ต้องถูกส่งถ่าย. The MAC ใช้ the deferral mechanism สำหรับ flow control (back pressure) ใน Half-duplex mode. เมื่อ the application ร้องขอเพื่อหยุด frames ที่กำลังรับ, the MAC ส่ง a JAM pattern of 32 bytes เมื่อไรก็ตามที่มันสัมผัสการรับของ a frame, โดยมีเงื่อนไขว่า
transmit flow control ถูกเปิดการใช้งาน. นี้ส่งผลให้ a collision และ the remote station backs off(ถอยหลัง). The application ร้องขอ flow control โดยการเซ็ต the BPA bit (bit 0) ใน the ETH_MACFCR register. ถ้า the application ร้องขอ a frame ที่จะถูกส่ง, จากนั้นมันถูกกำหนดเวลาและถูกส่งแม้ว่าเมื่อ back pressure ถูกทำให้ทำงาน สังเกตว่าถ้า back pressure ถูกทำให้ทำงานมาเป็นเวลานาน (และมากกว่า 16 consecutive collision events เกิดขึ้น) จากนั้น the remote stations ละทิ้งการส่งของมันเนื่องจาก collisions ที่มากเกินไป. ถ้า IEEE 1588 time stamping ถูกเปิดการใช้งานสำหรับ the transmit frame, block นี้จะจับ a snapshot ของ the system time เมื่อ the SFD ถูกใส่ไปบน the transmit MII bus.

tha

Transmit scheduler

The MAC มีหน้าที่กำหนดเวลา the frame transmission บน the MII. มันรักษา the interframe gap ระหว่าง two transmitted frames และตามด้วย the truncated binary exponential backoff algorithm สำหรับ Half-duplex mode. The MAC เปิดการใช้งาน transmission หลังจากพอใจกับ the IFG and backoff delays. มันรักษา an idle period of the configured interframe gap (IFG bits in the ETH_MACCR register) ระหว่าง any two transmitted frames. ถ้า frames ที่จะถูกส่งมาถึงเร็วกว่า the configured IFG time, the MII คอยสำหรับ the enable signal จาก the MAC ก่อนการสตาร์ท the transmission บนมัน. The MAC สตาร์ท IFG counter ของมันทันทีที่ the carrier signal ของ the MII ไปเป็นไม่ทำงาน. ที่ the end of the programmed IFG value, the MAC เปิดการใช้งาน transmission ใน Full-duplex mode. ใน Half-duplex mode และเมื่อ IFG ถูกกำหนดค่าเป็นเวลา 96 bit times, the MAC ทำตาม the rule of deference ที่ระบุใน Section 4.2.3.2.1 of the IEEE 802.3 specification. The MAC รีเซ็ต IFG counter ของมันถ้า a carrier ถูกตรวจพบในช่วงสองในสามแรก (64-bit times สำหรับ all IFG values) ของ the IFG interval. ถ้า the carrier ถูกตรวจพบในช่วงหนึ่งในสามสุดท้ายของ the IFG interval, the MAC จะดำเนินการต่อ the IFG count และเปิดการใช้งาน the transmitter หลังจาก the IFG interval. The MAC จัดให้มีใช้ the truncated binary exponential backoff algorithm เมื่อมันทำงานใน Half-duplex mode.

tha

Transmit flow control

เมื่อ the Transmit Flow Control Enable bit (TFE bit in ETH_MACFCR) ถูกเซ็ต, the MAC สร้าง Pause frames และส่งพวกมันตามความจำเป็น, ใน Full-duplex mode. The Pause frame ถูกต่อท้ายด้วย the calculated CRC, และถูกส่ง. Pause frame generation สามารถถูกเริ่มต้นในสองทาง.

A pause frame ถูกส่งอย่างใดอยางหนึ่งเมื่อ the application เซ็ต the FCB bit in the ETH_MACFCR register หรือเมื่อ the receive FIFO เต็ม (packet buffer).
•    ถ้า the application ร้องขอ flow control โดยการเซ็ต the FCB bit in ETH_MACFCR, the MAC สร้างและส่ง a single Pause
      frame. ค่าของ the pause time ใน the generated frame บรรจุ the programmed pause time value ใน
      ETH_MACFCR. เพื่อยืดขยาย the pause หรือสิ้นสุด the pause ก่อนถึง the time ที่ระบุใน the previously transmitted
      Pause frame, the application ต้องร้องขอ another Pause frame transmission หลังจากการโปรแกรม the Pause Time
      value (PT in ETH_MACFCR register) ด้วยค่าที่เหมาะสม.
•    ถ้า the application ร้องขอ flow control เมื่อ the receive FIFO เต็ม, the MAC สร้างและส่ง a Pause frame. ค่าของ the
      pause time ใน the generated frame คือ the programmed pause time value ใน ETH_MACFCR. ถ้า the receive
      FIFO ยังคงเต็มที่จำนวนที่กำหนดค่าได้ของ slot-times (PLT bits in ETH_MACFCR) ก่อน Pause time นี้จะหมด, a second
      Pause frame ถูกส่ง. กระบวนการนี้ถูกทำซ้ำตราบเท่าที่ the receive FIFO ยังคงเต็ม. ถ้าเงื่อนไขนี้ไม่พอใจมากขึ้นก่อนถึง the
      sampling time, the MAC ส่ง a Pause frame ด้วย zero pause time เพื่อแสดงให้เห็นไปยัง the remote end ว่า the
      receive buffer พร้อมรับ new data frames.

tha

Single-packet transmit operation

ลำดับทั่วไปของเหตุการณ์สำหรับ a transmit operation เป็นดังต่อไปนี้ :
1.    ถ้า the system มี data ที่จะถูกส่งถ่าย, the DMA controller จะดึงข้อมูลจาก the memory ผ่านทาง the AHB Master interface
       และสตาร์ทส่งต่อพวกมันไปยัง the FIFO. มันจะต่อเนื่องรับ the data จนกระทั่ง the end of frame ถูกส่งถ่าย.
2.    เมื่อ the threshold level ถูกข้ามหรือ a full packet of data ถูกรับลงใน the FIFO, the frame data ถูก popped และขับไปยัง
       the MAC core. The DMA จะต่อเนื่องส่งถ่าย data จาก the FIFO จนกระทั่ง a complete packet ถูกส่งถ่ายไปยัง the MAC แล้ว.
       เมื่อ completion of the frame, the DMA controller ถูกแจ้งให้ทราบโดย the status ที่มาจาก the MAC.