Clock.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.6 $
*
* This is the default implementation of the "clock" function of the
* standard library. It can be replaced with a system-specific
* implementation.
*
* The "clock" function should return the processor time used by the
* program from some implementation-defined start time. The value
* should be such that if divided by the macro CLOCKS_PER_SEC the
* result should yield the time in seconds.
*
* The value "(clock_t)-1" means that the processor time is not
* available.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define CLOCK_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <time.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?clock"
clock_t (clock)(void)
{
#if defined AT91SAM9260
unsigned int value, alarm;
alarm = AT91C_BASE_RTTC->RTTC_RTAR;
value = AT91C_BASE_RTTC->RTTC_RTVR;
return (clock_t) (alarm + value);
#endif
}
//_STD_END
#endif
Close.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.6 $
*
* This is a template implementation of the "__close" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__close" function should close the file corresponding to
* "handle". It should return 0 on success and nonzero on failure.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define CLOSE_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "lib.h"
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?__close"
#pragma diag_suppress = Pe826
int __close(int handle)
{
int fd = ToFD(handle);
if (fd == -1) {
return -1;
}
ClearFD(handle);
return ___close(fd);
}
//_STD_END
#endif
Lib.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define LIB_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "lib.h"
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define FD_MAX (FOPEN_MAX + 3)
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
STATIC INT FileDescriptor[FD_MAX];
void InitialLib(void)
{
int handle;
for (handle = 0; handle < FD_MAX; handle++) {
FileDescriptor[handle] = -1;
}
}
void ClearFD(int handle)
{
if (handle == _LLIO_ERROR) {
return;
}
if (handle < 0 || handle >= FD_MAX) {
return;
}
FileDescriptor[handle] = -1;
}
int ToFD(int handle)
{
if (handle == _LLIO_ERROR) {
return -1;
}
if (handle < 0 || handle >= FD_MAX) {
return -1;
}
return FileDescriptor[handle];
}
int EnoughFD(void)
{
int handle;
for (handle = 3; FileDescriptor[handle] != -1;) {
if (++handle >= FD_MAX) {
return -1;
}
}
return 0;
}
int CreateHandle(int fd)
{
int handle;
if (fd == 0 || fd == -1) {
return -1;
}
for (handle = 3; FileDescriptor[handle] != -1;) {
if (++handle >= FD_MAX) {
return -1;
}
}
FileDescriptor[handle] = fd;
return handle;
}
int RegisterStandardIO(CONST char *name, int mode)
{
int fd;
if ((fd = ___open(name, mode)) == -1) {
return -1;
}
if (FileDescriptor[0] != -1) {
___close(FileDescriptor[0]);
}
FileDescriptor[0] = fd;
FileDescriptor[1] = fd;
FileDescriptor[2] = fd;
return 0;
}
#endif
Lib.h 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#ifndef LIB_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define LIB_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
#define _LLIO_RDONLY 0x0000
#define _LLIO_WRONLY 0x0001
#define _LLIO_RDWR 0x0002
#define _LLIO_APPEND 0x0008
#define _LLIO_CREAT 0x0010
#define _LLIO_TRUNC 0x0020
#define _LLIO_TEXT 0x0040
#define _LLIO_BINARY 0x0080
#define _LLIO_ERROR 0
#define _O_RDONLY _LLIO_RDONLY /*!< Read only. */
#define _O_WRONLY _LLIO_WRONLY /*!< Write only. */
#define _O_RDWR _LLIO_RDWR /*!< Read and write. */
#define _O_APPEND _LLIO_APPEND /*!< Start writing at the end. */
#define _O_CREAT _LLIO_CREAT /*!< Create file if it does not exist. */
#define _O_TRUNC _LLIO_TRUNC /*!< Truncate file if it exists. */
#define _O_TEXT _LLIO_TEXT /*!< EOL translation. */
#define _O_BINARY _LLIO_BINARY /*!< Raw mode. */
#else
#define _O_RDONLY 0x0000 /*!< Read only. */
#define _O_WRONLY 0x0001 /*!< Write only. */
#define _O_RDWR 0x0002 /*!< Read and write. */
#define _O_APPEND 0x0008 /*!< Start writing at the end. */
#define _O_CREAT 0x0100 /*!< Create file if it does not exist. */
#define _O_TRUNC 0x0200 /*!< Truncate file if it exists. */
#define _O_TEXT 0x4000 /*!< EOL translation. */
#define _O_BINARY 0x8000 /*!< Raw mode. */
#endif
/*
* Some global definitions for ioctl commands.
*/
#define IOCTL_GETSTATUS 0x0001
#define IOCTL_SETSTATUS 0x0002
#define IOCTL_SETBUFFERMODE 0x0003
#define IOCTL_GETBUFFERMODE 0x0004
#define IOCTL_GETOUTBUFSIZE 0x0005
#define IOCTL_SETOUTBUFSIZE 0x0006
#define IOCTL_GETINBUFSIZE 0x0007
#define IOCTL_SETINBUFSIZE 0x0008
/*! \brief Flush the output buffer.
*
* Currently not provided by any known device.
*/
#define IOCTL_FLUSHOUTBUF 0x0009
/*! \brief Return the number of bytes currently available in the input buffer.
*/
#define IOCTL_GETFILESIZE 0x000A
/*! \brief Return the number of bytes currently available in the input buffer.
*/
#define IOCTL_GETOUTBUFCOUNT 0x000B
/*! \brief Return the number of bytes currently available in the output buffer.
*/
#define IOCTL_GETINBUFCOUNT 0x000C
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
#if defined(NUTOS)
int ___open(CONST char *, int);
int ___close(int);
int ___read(int, void *, unsigned int);
int ___write(int, CONST void *, unsigned int);
int ___seek(int, long, int);
long ___tell(int);
int ___ioctl(int, int, void *);
long ___filelength(int);
#else
#define ___open(name, mode) (-1)
#define ___close(fd) (0)
#define ___read(fd, buffer, count) (0)
#define ___write(fd, data, count) (0)
#define ___seek(fd, offset, origin) (-1)
#define ___tell(fd) (-1)
#define ___ioctl(fd, cmd, data) (0)
#define ___filelength(fd) (0)
#endif
#if defined(__ICCARM__)
void InitialLib(void);
void ClearFD(int);
int ToFD(int);
int EnoughFD(void);
int CreateHandle(int);
int RegisterStandardIO(CONST char *, int);
#else
#define InitialLib()
#define ClearFD(handle)
#define ToFD(handle) (-1)
#define EnoughFD() (-1)
#define CreateHandle(fd) (-1)
#define RegisterStandardIO(name, mode) (-1)
#endif
/*!
* \file io.h
*/
#define _close(fd) ___close(fd)
#define _open(name, mode) ___open(name, mode)
#define _read(fd, buffer, count) ___read(fd, buffer, count)
#define _write(fd, data, count) ___write(fd, data, count)
#define _seek(fd, offset, origin) ___seek(fd, offset, origin)
#define _tell(fd) ___tell(fd)
#define _ioctl(fd, cmd, data) ___ioctl(fd, cmd, data)
#define _filelength(fd) ___filelength(fd)
/*!
* \file stdio.h
*/
#define _fdopen(fd, mode) fdopen(CreateHandle(fd), mode)
#define _fileno(stream) ToFD(fileno(stream))
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif
Lseek.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-1999 IAR Systems. All rights reserved.
*
* $Revision: 1.6 $
*
* This is a template implementation of the "__lseek" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__lseek" function makes the next file operation (__read or
* __write) act on a new location. The parameter "whence" specifies
* how the "offset" parameter should be interpreted according to the
* following table:
*
* 0 (=SEEK_SET) - Goto location "offset".
* 1 (=SEEK_CUR) - Go "offset" bytes from the current location.
* 2 (=SEEK_END) - Go to "offset" bytes from the end.
*
* This function should return the current file position, or -1 on
* failure.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define LSEEK_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "lib.h"
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?__lseek"
#pragma diag_suppress = Pe826
long __lseek(int handle, long offset, int whence)
{
int fd = ToFD(handle);
if (fd == -1) {
return -1;
}
return ___seek(fd, offset, whence);
}
//_STD_END
#endif
NutLib.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define NUTLIB_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XNutOS.h"
#include "lib.h"
#if defined(NUTOS)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/*!
* \brief Open a file.
*
* \param name The name of a registered device, optionally followed by a
* colon and a filename.
* \param mode Operation mode. May be any of the following:
* - _O_APPEND Always write at the end.
* - _O_BINARY Raw mode.
* - _O_CREAT Create file if it does not exist.
* - _O_EXCL Open only if it does not exist.
* - _O_RDONLY Read only.
* - _O_RDWR Read and write.
* - _O_TEXT End of line translation.
* - _O_TRUNC Truncate file if it exists.
* - _O_WRONLY Write only.
*
* \return File descriptor for the opened file or -1 to indicate an error.
*/
int ___open(CONST char *name, int mode)
{
NUTDEVICE *dev;
char dev_name[9];
u_char nidx;
CONST char *nptr = name;
/*
* Extract device name.
*/
for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++) {
dev_name[nidx] = *nptr++;
}
dev_name[nidx] = 0;
/*
* Get device structure of registered device. In later releases we
* try to open a file on a root device.
*/
if ((dev = NutDeviceLookup(dev_name)) == 0) {
return -1;
}
/*
* We should check, if the mode flags are device conformant.
*/
/*
* If a device name was specified, open this device. Otherwise open
* a file on the device.
*/
if (*nptr++ != ':')
nptr = 0;
return (int) ((uptr_t) ((*dev->dev_open) (dev, nptr, mode, 0)));
}
/*!
* \brief Close a file, device or socket.
*
* The calling thread may be suspended until all buffered output data
* has been written.
*
* \param fd Descriptor of a previously opened file, device or
* connected socket.
*
* \return 0 if the file was successfully closed or -1 to indicate an error.
*/
int ___close(int fd)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
if (dev == 0) {
NUTVIRTUALDEVICE *vdv = (NUTVIRTUALDEVICE *) fp;
return (*vdv->vdv_write) (vdv, 0, 0);
}
return (*dev->dev_close) (fp);
}
/*!
* \brief Read data from a file, device or socket.
*
* \param fd Descriptor of a previously opened file, device or
* connected socket.
* \param buffer Pointer to the buffer that receives the data.
* \param count Maximum number of bytes to read.
*
* \return The number of bytes read, which may be less than the number
* of bytes specified. A return value of -1 indicates an error.
*/
int ___read(int fd, void *buffer, unsigned int count)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
if (dev == 0) {
NUTVIRTUALDEVICE *vdv = (NUTVIRTUALDEVICE *) fp;
return (*vdv->vdv_read) (fp, buffer, count);
}
return (*dev->dev_read) (fp, buffer, count);
}
/*!
* \brief Write data to a file, device or socket.
*
* \param fd Descriptor of a previously opened file, device or
* connected socket.
* \param data Pointer to data in program space to be written.
* \param count Number of bytes to write.
*
* \return The number of bytes written, which may be less than the number
* of bytes specified. A return value of -1 indicates an error.
*
* \note The write implementation of the underlying driver does not need
* to be thread-safe. Parallel writes using device usartavr will
* lead to intermixed data (if data doesn't fit into ringbuffer
* on the first try )
*/
int ___write(int fd, CONST void *data, unsigned int count)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
if (dev == 0) {
NUTVIRTUALDEVICE *vdv = (NUTVIRTUALDEVICE *) fp;
return (*vdv->vdv_write) (vdv, data, count);
}
return (*dev->dev_write) (fp, data, count);
}
/*!
* \brief Move read/write position of a file.
*
* \param fd Descriptor of a previously opened file, device or
* connected socket.
* \param offset Number of bytes from initial position.
* \param origin Initial position to seek from.
*
* \return 0 if no error occured -1 on error. errno is set
*
*/
int ___seek(int fd, long offset, int origin)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
IOCTL_ARG3 conf;
conf.arg1 = (void*) fp;
conf.arg2 = (void*) &offset;
conf.arg3 = (void*) origin;
if (dev != 0) {
if ((*dev->dev_ioctl) (dev, FS_FILE_SEEK, &conf)) {
return 0;
} else {
return -1;
}
} else {
return -1;
}
}
/*!
* \brief Return the read/write position of a stream.
*
* \param fd Descriptor of a previously opened file, device or
* connected socket.
*
* \return The current position or -1 on error.
*
*/
long ___tell(int fd)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
IOCTL_ARG3 conf;
long offset = 0;
int origin = SEEK_CUR;
conf.arg1 = (void*) fp;
conf.arg2 = (void*) &offset;
conf.arg3 = (void*) origin;
if (dev != 0) {
if ((*dev->dev_ioctl) (dev, FS_FILE_SEEK, &conf)) {
return offset;
} else {
return -1;
}
} else {
return -1;
}
}
/*!
* \brief Perform device specific control functions.
*
* Check the specific device driver for a list of supported control
* functions.
*
* \param fd Descriptor of a previously opened device or
* connected socket.
* \param cmd Requested control function.
* \param data Points to a buffer that contains any data required for
* the given control function or receives data from that
* function.
*/
int ___ioctl(int fd, int cmd, void *data)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
if (dev == 0) {
NUTVIRTUALDEVICE *vdv = (NUTVIRTUALDEVICE *) fp;
return (*vdv->vdv_ioctl) (vdv, cmd, data);
}
return (*dev->dev_ioctl) (dev, cmd, data);
}
/*!
* \brief Return the length of a file.
*
* \param fd Descriptor of a previously opened file, device or
* connected socket.
*
* \return Filelength in bytes or -1 in case of an error.
*/
long ___filelength(int fd)
{
NUTFILE *fp = (NUTFILE *) ((uptr_t) fd);
NUTDEVICE *dev = fp->nf_dev;
long l;
if (dev == 0) {
NUTVIRTUALDEVICE *vdv = (NUTVIRTUALDEVICE *) fp;
if (vdv->vdv_ioctl && vdv->vdv_ioctl(vdv, IOCTL_GETFILESIZE, &l) == 0)
return l;
else {
return -1;
}
}
if (dev->dev_size == 0) {
return -1;
}
return (*dev->dev_size) (fp);
}
#endif
Open.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.8 $
*
* This is a template implementation of the "__open" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__open" function opens the file named "filename" as specified
* by "mode". "mode" & _LLIO_RDWRMASK specifies the basic file type:
* _LLIO_RDONLY, _LLIO_WRONLY, and _LLIO_RDWR for read only, write only, and
* read write, respectively. Handle the rest of the _LLIO_xxx flags as
* described in the code below.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define OPEN_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "lib.h"
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?__open"
#pragma diag_suppress = Pe826
int __open(const char * filename, int mode)
{
if (EnoughFD() == -1) {
return -1;
}
return CreateHandle(___open(filename, mode));
}
//_STD_END
#endif
Read.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.13 $
*
* This is a template implementation of the "__read" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__read" function reads a number of bytes, at most "size" into
* the memory area pointed to by "buffer". It returns the number of
* bytes read, 0 at the end of the file, or _LLIO_ERROR if failure
* occurs.
*
* The template implementation below assumes that the application
* provides the function "MyLowLevelGetchar". It should return a
* character value, or -1 on failure.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define READ_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "lib.h"
#include <stdio.h>
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?__read"
size_t __read(int handle, unsigned char * buffer, size_t size)
{
int fd = ToFD(handle);
if (fd == -1) {
return _LLIO_ERROR;
}
return ___read(fd, buffer, size);
}
//_STD_END
#endif
Remove.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.6 $
*
* This is a template implementation of the "remove" function of the
* standard library. Replace it with a system-specific
* implementation.
*
* The "remove" function should remove the file named "filename". It
* should return 0 on success and nonzero on failure.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define REMOVE_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?remove"
#pragma diag_suppress = Pe826
int remove(const char * filename)
{
return 0;
}
//_STD_END
#endif
Rename.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-1999 IAR Systems. All rights reserved.
*
* $Revision: 1.6 $
*
* This is a template implementation of the "rename" function of the
* standard library. Replace it with a system-specific
* implementation.
*
* The "rename" function should rename file from "old" to "new". It
* should return 0 on success and nonzero on failure.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define RENAME_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?rename"
#pragma diag_suppress = Pe826
int rename(const char *old, const char *new)
{
return (-1);
}
//_STD_END
#endif
Time.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.4 $
*
* This is the default implementation of the "time" function of the
* standard library. It can be replaced with a system-specific
* implementation.
*
* The "time" function returns the current calendar time. (time_t)-1
* should be returned if the calendar time is not available. The time
* is measured in seconds since the first of January 1970.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define TIME_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <time.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
#pragma module_name = "?time"
time_t (time)(time_t *t)
{
#if defined AT91SAM9260
unsigned int alarm = AT91C_BASE_RTTC->RTTC_RTAR;
unsigned int value = AT91C_BASE_RTTC->RTTC_RTVR;
if (t)
*t = (time_t) (alarm + value);
return (time_t) (alarm + value);
#else
return 0;
#endif
}
#endif
Write.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.14 $
*
* This is a template implementation of the "__write" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__write" function should output "size" number of bytes from
* "buffer" in some application-specific way. It should return the
* number of characters written, or _LLIO_ERROR on failure.
*
* If "buffer" is zero then __write should perform flushing of
* internal buffers, if any. In this case "handle" can be -1 to
* indicate that all handles should be flushed.
*
* The template implementation below assumes that the application
* provides the function "MyLowLevelPutchar". It should return the
* character written, or -1 on failure.
*
********************/
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define WRITE_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#if defined(__ICCARM__)
#include <yfuns.h>
#endif
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "lib.h"
#include <stdio.h>
#if defined(__ICCARM__)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
//_STD_BEGIN
#pragma module_name = "?__write"
/*
* If the __write implementation uses internal buffering, uncomment
* the following line to ensure that we are called with "buffer" as 0
* (i.e. flush) when the application terminates.
*/
size_t __write(int handle, const unsigned char * buffer, size_t size)
{
int fd = ToFD(handle);
if (fd == -1) {
return _LLIO_ERROR;
}
return ___write(fd, buffer, size);
}
//_STD_END
#endif