A basic tight polling implementation would look something like this:
Similarly, we can use polling to check if the device is ready to receive data (output from the CPU). Optimistically, we can assume that the device is initially ready to receive data. In this case, the code clears the flag, sends the data, and then tight polls for the device to set the flag again, indicating it is ready to continue.
This might work most of the time, there’s a danger of losing the first piece sent if the device is not actually ready.
A more conservative option is to tight poll for the device to be ready first, then clear the flag and output the data once its ready to receive it.
Here, we assume the device is not initially ready, poll the device, wait until device is ready, and then output the data.