Shop OBEX P1 Docs P2 Docs Learn Events
Hi, I'm confused about FullDuplexSerial code... — Parallax Forums

Hi, I'm confused about FullDuplexSerial code...

Hi everyone, I am trying to understand the FullDuplexSerial Assembly code and while I am studying it I am becoming confused at one point. Please disregard that I am asking a stupid question: what is the VAR tx_buffer[64] & rx_buffer[64] declaration? Is this a buffer area in Hub's Ram shared by Cog's Ram between Spin and Assembly to store what is being transmitted and received by Prop chip? What is VAR Long rx_head declaration for? For example, tx_buffer[rx_head], why rx_head is the number of tx_buffer array elements? Isn't rx_head a start bit in UART?

Please some one help me out!

[img][/img]

Comments

  • Heater.Heater. Posts: 21,230
    hans90,
    Isn't rx_head a start bit in UART?
    No. As far as I recall there are circular buffers for bytes being transmitted and received.

    Start and stop bits of each byte transmitted, or received on the line is a different thing.

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2017-02-21 20:58
    The array variables tx_buffer and rx_buffer are where characters slated for transmission and characters already received but not processed are stored. This allows the actual hardware transmission and reception to occur asynchronously with the user's program. IOW, characters can be stored in the buffer for transmission, with control returning immediately to the user's program; and characters can be received in the background and stored for later retrieval by the user's program.

    The _head and _tail variables are pointers into those buffers. For the receive buffer, they keep track of where the next unread character is stored and where the last character received is stored. For the transmit buffer, they keep track of where the last character from the user's program is stored and where the next character to be transmitted is stored.

    The buffers operate in circular fashion. Once a character is stored or retrieved from the end of the buffer, the appropriate pointer cycles back to the beginning of the buffer. The repeat until statement you've shown waits until there's room in the transmit buffer for a new character from the user's program.

    -PHil
  • hans90hans90 Posts: 29
    edited 2017-02-23 04:34
    Hello PHill,

    Thanks very much for the reply on ring buffer!
    My question is what does the program use to print things? I tried to understand the code where it prints things. It seems to me it uses method PUB tx(txbyte) to print but I think tx_buffer[tx_head] := txbyte only moves strings into the ring buffer without printing it. In the following assembly code I don't really find a specific instruction that prints things. Did I miss anything in assembly that prints? I'm confused...
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2017-02-23 05:00
    hans90 wrote:
    It seems to me it uses method PUB tx(txbyte) to print but I think tx_buffer[tx_head] := txbyte only moves strings into the ring buffer without printing it.
    That's correct. The object has another cog running that reads characters out of the ring buffer for transmission.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    The other cog runs pasm code that takes characters from the input ring buffer and transmits them by bit-banging the TX pin, and receives characters by receive bit-assembling them and placing them into the receive ring buffer. This pasm code simulates a full duplex uart.

    It is not necessary to understand the pasm code running in the other cog. FDX will work reliably at least up to 115,200 baud.
Sign In or Register to comment.