Author Topic: Non-blocking serial read-function?  (Read 3628 times)

0 Members and 1 Guest are viewing this topic.

Offline compu

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 275
  • Rating: +63/-3
    • View Profile
Non-blocking serial read-function?
« on: July 27, 2011, 06:19:26 am »
I have a small question about Nspire C:
Is there a non-blocking function to check if data is available for reading at the serial port?

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Non-blocking serial read-function?
« Reply #1 on: July 30, 2011, 02:59:32 am »
You will have to use direct I/O access. It's not different than doing it from a computer: http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#90020000_-_Serial_UART

Here is a code snippet that was once used in Ndless, equivalent to puts():

Code: [Select]
void ut_puts(const char *str) {
volatile unsigned *line_status_reg = (unsigned*)0x90020014;
volatile unsigned *xmit_holding_reg = (unsigned*)0x90020000;
while(*str) {
while(!(*line_status_reg & 0b100000)); // wait for empty xmit holding reg
*xmit_holding_reg = *str++;
}
}
Ndless.me with the finest TI-Nspire programs

Offline compu

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 275
  • Rating: +63/-3
    • View Profile
Re: Non-blocking serial read-function?
« Reply #2 on: July 30, 2011, 06:20:26 am »
Thank you! :)