Skip to main content

IAR Embedded Workbench for Arm 9.70.x

__read

In this section:
Source file
arm\src\lib\file\read.c
Declared in

LowLevelIOInterface.h

Description

Low-level function that reads characters from stdin and from files.

C-SPY debug action

Directs stdin to the Terminal I/O window. All other files will read the associated host file.

Default implementation

None.

Example

The code in this example uses memory-mapped I/O to read from a keyboard, whose port is assumed to be located at address 0x1000:

#include <stddef.h>
#include <LowLevelIOInterface.h>
__no_init volatile unsigned char kbIO @ 0x1000;

size_t __read(int handle, 
              unsigned char *buf,
              size_t bufSize)
{
  size_t nChars = 0;

  /* Check for stdin 
     (only necessary if FILE descriptors are enabled) */
  if (handle != 0)
  {
    return -1;
  }

  for (/*Empty*/; bufSize > 0; --bufSize)
  {
    unsigned char c = kbIO;
    if (c == 0)
      break;

    *buf++ = c;
    ++nChars;
  }

  return nChars;
}

For information about the handles associated with the streams, see Retargeting—Adapting for your target system.

For information about the @ operator, see Controlling data and function placement in memory.

See also

Briefly about retargeting.