The library caller could call Poll() first, then call Read(), and the expectation is the char won't be lost. SBI doesn't have a poll call itself, so best you could do is read and stash. So you have to stash it globally. And read must use the stashed char, if it exists, before requesting more data from SBI. At that point, reading is easy to treat as continued polling - just to keep the code simple.

A

От: Gerd Hoffmann <kraxel@redhat.com>
Отправлено: Wednesday, March 1, 2023 2:13:32 AM
Кому: devel@edk2.groups.io <devel@edk2.groups.io>; Warkentin, Andrei <andrei.warkentin@intel.com>
Копия: Daniel Schaefer <git@danielschaefer.me>; Sunil V L <sunilvl@ventanamicro.com>
Тема: Re: [edk2-devel] [edk2 2/2] MdePkg: add BaseSerialPortLibRiscVSbi
 
  Hi,

> +  while ((Index < NumberOfBytes) && SerialPortPoll ()) {
> +    Buffer[Index++] = (UINT8)mLastGetChar;
> +    mLastGetChar    = -1;
> +  }

Why do you use a global variable to pass the character?  SerialPortPoll
could just return it directly ...

take care,
  Gerd