Seite 1 von 1

Ringpuffer

Verfasst: Di 27. Aug 2019, 11:28
von PIC18F2550
Hallo,

hat schon ein mal jemand so etwas Programmiert?

Re: Ringpuffer

Verfasst: Di 27. Aug 2019, 13:01
von yeti
PIC18F2550 hat geschrieben:hat schon ein mal jemand so etwas Programmiert?
Sowas steckt vermutlich in jedem seriellen Objekt mit Sende-/Empfangspuffer.

***wühl***

Verfolg mal in FullDuplexSerial, was mit den Variablen rx_head, rx_tail, rx_buffer und dessen tx-Kollegen angestellt wird.

Re: Ringpuffer

Verfasst: Di 27. Aug 2019, 14:59
von PIC18F2550
Ob das alles richtig ist?
Muss mal Testen..

Code: Alles auswählen

CON
   BUFFER_LENGTH = 2048                                   'Recommended as 64 or higher, but can be 2, 4, 8, 16, 32, 64, 128 256.
   BUFFER_MASK   = BUFFER_LENGTH - 1

VAR
  long  head
  long  tail
  byte  buffer[BUFFER_LENGTH]

PUB Start
  longfill(@head, 0, 2)

PUB CharOut(a)
  repeat until (tail <> ((head + 1) & BUFFER_MASK)) ' Warten auf Platz im Buffer
  buffer[head] := a
  head := (head + 1) & BUFFER_MASK

PUB CharIn : a
  repeat while (a := Check) < 0

PRI Check : a
  a~~
  if tail <> head
    a := buffer[tail]
    tail := (tail + 1) & BUFFER_MASK

PUB Count : a
  a := head - tail
  a -= BUFFER_LENGTH*(a < 0)
Was noch rein muss ist eine Sperre da hier mindestens zwei COG's drann sind.