Skip to main content

IAR Embedded Workbench for Arm 9.70.x

__write

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

LowLevelIOInterface.h

Description

Low-level function that writes to stdout, stderr, or a file.

C-SPY debug action

Directs stdout and stderr to the Terminal I/O window. All other files will write to the associated host file.

Default implementation

None.

Example

The code in this example uses memory-mapped I/O to write to an LCD display, whose port is assumed to be located at address 0x1000:

#include <stddef.h>
#include <LowLevelIOInterface.h>

__no_init volatile unsigned char lcdIO @ 0x1000;

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

  /* Check for the command to flush all handles */
  if (handle == -1)
  {
    return 0;
  }
  
  /* Check for stdout and stderr 
     (only necessary if FILE descriptors are enabled.) */
  if (handle != 1 && handle != 2)
  {
    return -1;
  }

  for (/* Empty */; bufSize > 0; --bufSize)
  {
    lcdIO = *buf;
    ++buf;
    ++nChars;
  }

  return nChars;
}

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

See also

Briefly about retargeting.