Download TMS320C6000 Optimizing Compiler v 7.4
Transcript
add_device — Add Device to Device Table
www.ti.com
Example
Example 8-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 8-2 illustrates adding and using a device for C I/O:
Example 8-2. Program for C I/O Device
#include <file.h>
#include <stdio.h>
/****************************************************************************/
/* Declarations of the user-defined device drivers
*/
/****************************************************************************/
extern int
MYDEVICE_open(const char *path, unsigned flags, int fno);
extern int
MYDEVICE_close(int fno);
extern int
MYDEVICE_read(int fno, char *buffer, unsigned count);
extern int
MYDEVICE_write(int fno, const char *buffer, unsigned count);
extern off_t MYDEVICE_lseek(int fno, off_t offset, int origin);
extern int
MYDEVICE_unlink(const char *path);
extern int
MYDEVICE_rename(const char *old_name, char *new_name);
main()
{
FILE *fid;
add_device("mydevice", _MSA, MYDEVICE_open, MYDEVICE_close, MYDEVICE_read,
MYDEVICE_write, MYDEVICE_lseek, MYDEVICE_unlink, MYDEVICE_rename);
fid = fopen("mydevice:test","w");
fprintf(fid,"Hello, world\n");
fclose(fid);
}
SPRU187U – July 2012
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
Copyright © 2012, Texas Instruments Incorporated
261