The device Prefix

A file can be opened to a user-defined device driver by using a device prefix in the pathname. The device prefix is the device name used in the call to add_device followed by a colon. For example:

FILE *fptr = fopen("mydevice:file1", "r"); int fd = open("mydevice:file2, O_RDONLY, 0);

If no device prefix is used, the HOST device will be used to open the file.

add_device
Add Device to Device Table
Syntax for C

#include <file.h>

int add_device(char *name,
     unsigned flags,
     int (*dopen)(const char *path, unsigned flags, int llv_fd),
     int (*dclose)( int dev_fd),
     int (*dread)(intdev_fd, char *buf, unsigned count),
     int (*dwrite)(intdev_fd, const char *buf, unsigned count),
     off_t (*dlseek)(int dev_fd, off_t ioffset, int origin),
     int (*dunlink)(const char *path),
     int (*drename)(const char *old_name, const char *new_name));

Defined in

lowlev.c (in the lib/src subdirectory of the compiler installation)

Description

The add_device function adds a device record to the device table allowing that device to be used for I/O from C. The first entry in the device table is predefined to be the HOST device on which the debugger is running. The function add_device() finds the first empty position in the device table and initializes the fields of the structure that represent a device.

To open a stream on a newly added device use fopen( ) with a string of the format devicename:filename as the first argument.

  • The name is a character string denoting the device name. The name is limited to 8 characters.
  • The flags are device characteristics. The flags are as follows:
  • _SSA Denotes that the device supports only one open stream at a time

    _MSA Denotes that the device supports multiple open streams

    More flags can be added by defining them in file.h.

  • The dopen, dclose, dread, dwrite, dlseek, dunlink, and drename specifiers are function pointers to the functions in the device driver that are called by the low-level functions to perform I/O on the specified device. You must declare these functions with the interface specified in Section 9.2.2. The device driver for the HOST that the TMS320C6000 debugger is run on are included in the C I/O library.
Return Value

The function returns one of the following values:

0 if successful
-1 on failure
Example

Example 2 does the following:

  • Adds the device mydevice to the device table
  • Opens a file named test on that device and associates it with the FILE pointer fid
  • Writes the string Hello, world into the file
  • Closes the file

Example 2 illustrates adding and using a device for C I/O: