The C++ libraries depend on the C library for target-specific support. There are no target dependencies in the C++ libraries. To retarget your C++ streamed I/O, we recommend that you retarget the “_sys_xxxx” driver level functions. These are the functions used by the C and C++ library and are responsible for target specific I/O. The default implementation uses Semihosting to handle I/O on the host machine. The RVDS Compiler and Libraries Guide discusses which functions have to be re-implemented. A summary is shown below: _sys_open() _sys_close() _sys_read() _sys_write() _sys_ensure() _sys_flen() _sys_seek() _sys_istty() _sys_tmpnam() _sys_exit() _ttywrch() For an example file (retarget.c), used for redirecting C++ streamed I/O to an UART (connected to e.g. a Terminal Emulator), click here. To retarget standard input/output functionality, low level library functions such as fgetc() and fputc()can be re-implemented instead. In ADS 1.2 and RVDS 3.x, only functions such as fgetc() and fputc() need to be reimplemented. With RVDS 2.x an additional library function (used by cin) '__fread_bytes_avail()' must also be reimplemented. The default version of '__fread_bytes_avail()' fills a buffer by calling fgetc() until either the buffer is filled or EOF is encountered. Since the retargeted version of fgetc() in the example code simply returns characters from a UART (and never returns EOF), __fread_bytes_avail() must be re-implemented to read a single character by calling fgetc(): #ifdef __cplusplus extern "C" #endif size_t __fread_bytes_avail(void *buf, size_t nbytes, FILE *stream) /* Read a single character into buf[] using fgetc() */ { *(char *)buf = (char)fgetc(stream); return 1; } This function should be added to 'retarget.c' in the Application Note 107 code /RVCT 'emb_sw_dev' example. For ADS users, general retargeting of I/O functions is described in Application Note 107 , "Embedded Software Development". Download
|