Skip to content

[BUG] Steam Buffer doesn't block when buffer contain data but less than Trigger Level #643

Closed
@cperkulator

Description

@cperkulator

Describe the bug
Blocking on a Stream Buffer only appears to work if the buffer is empty when xStreamBufferReceive is called.

Target

  • Development board: Custom
  • Instruction Set Architecture: Tricore
  • IDE and version: [e.g. Freedom Studio 4.12.0.2019-08-2]
  • Toolchain and version: [e.g. riscv64-unknown-elf-gcc-8.3.0-2019.08.0]

Host

  • Host OS: [e.g. MacOS]
  • Version: [e.g. Mojave 10.14.6]

To Reproduce

Trigger level = 2 (for simplicity)

      Reader Task:                                                                                   Writer Task/Interrupt:
      -------------                                                                                    -------------
       (Kickoff reading loop)
       xStreamBufferReceive (handle, buf_ptr, 4, portMAX_DELAY)
       blocks because no data in buffer      
                                                                                                               (Kickoff writing loop)
                                                                                                               write sample 1 into the StreamBuffer
                                                                                                               write sample 2 into the StreamBuffer
                                                                                                               trigger level reached, notify blocked reader
      unblocked 
      read 2 bytes since trigger level was 2
                                                                                                               interrupt to write sample
                                                                                                               write sample 1 into the StreamBuffer
      xStreamBufferReceive (handle, buf_ptr, 4, portMAX_DELAY)
     doesn't block because data is in the buffer
     reads 1 byte despite trigger level being 2!

Expected behavior

Trigger level = 2 (for simplicity)

      Reader Task:                                                                                   Writer Task/Interrupt:
      -------------                                                                                    -------------
       (Kickoff reading loop)
       xStreamBufferReceive (handle, buf_ptr, 4, portMAX_DELAY)
       blocks because no data in buffer      
                                                                                                               (Kickoff writing loop)
                                                                                                               write sample 1 into the StreamBuffer
                                                                                                               write sample 2 into the StreamBuffer
                                                                                                               trigger level reached, notify blocked reader
      unblocked 
      read 2 bytes since trigger level was 2
                                                                                                               interrupt to write sample
                                                                                                               write sample 1 into the StreamBuffer
      xStreamBufferReceive (handle, buf_ptr, 4, portMAX_DELAY)
     blocks because trigger level has not been reached yet
                                                                                                               write sample 2 into the StreamBuffer
                                                                                                               trigger level reached, notify blocked reader
      unblocked 
      read 2 bytes since trigger level was 2

Additional context
This code will not block when if the amount of data in the buffer is less than the trigger level.

This happens because xBytesToStoreMessageLength is 0 for a steam buffer. This if is skipped if the buffer contains any amount of data thus not putting the task to sleep even if the amount of data is less than the trigger level.

I will be submitting a PR shortly

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions