SLAU132V October 2004 – February 2020
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.
#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));
lowlev.c (in the lib/src subdirectory of the compiler installation)
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.
_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 function returns one of the following values:
0 | if successful |
-1 | on failure |
Example 2 does the following:
Example 2 illustrates adding and using a device for C I/O: