This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Flash file system: fwrite not working

Hello,
fwrite is not writing to the file when implementing my own fputc to display debug messages on lcd and fwrite is writing on lcd not in file and without fputc fwrite is working fine.fwrite is calling fputc rather than _sys_write.
please help i am new here....thanxx..

fputc
int fputc(int c, FILE *f)

{ unsigned char lcd_i; char tempch = c;

if (c == 0x0a) { for (lcd_i=disp_count%21;lcd_i<21;lcd_i++) { if (DISPLAY_LINES == 5) { disp_char_5line(' ');

} else if(DISPLAY_LINES == 8) { disp_char_8line(' ');

} else disp_char_8line(' ');

} } else if(c == 0x0d) { disp_count = disp_count - (disp_count%21);

} else if (c == 0x08) { disp_count--; if (DISPLAY_LINES == 5) { disp_char_5line(' '); } else if(DISPLAY_LINES == 8) { disp_char_8line(' ');

} else disp_char_8line(' '); disp_count--;

} else{ if(DISPLAY_LINES==5) { disp_char_5line(c); } else if (DISPLAY_LINES== 8) { disp_char_8line(c); } else disp_char_8line(c);

} return c;

}
--------------------------------------------------------------------------
Retarget.c
#include <stdio.h>
#include <string.h>
//#include <rt_misc.h>
#include <rt_sys.h>
#include <File_Config.h>
//#include "display.h"

#pragma import(__use_no_semihosting_swi)

/* The following macro definitions may be used to translate this file:

STDIO - use standard Input/Output device (default is NOT used) */

/* Standard IO device handles. */
#define STDIN 0x8001
#define STDOUT 0x8002
#define STDERR 0x8003

/* Standard IO device name defines. */
const char __stdin_name[] = "STDIN";
const char __stdout_name[] = "STDOUT";
const char __stderr_name[] = "STDERR";

struct __FILE { int handle; /* Add whatever you need here */ };
//FILE __stdout;
//FILE __stdin;

#ifdef STDIO extern int sendchar (int c); extern int getkey (void); #endif

/*--------------------------- _ttywrch --------------------------------------*/

void _ttywrch (int ch) {
#ifdef STDIO sendchar(ch); #endif
}

/*--------------------------- _sys_open -------------------------------------*/

FILEHANDLE _sys_open (const char *name, int openmode) { /* Register standard Input Output devices. */ if (strcmp(name, "STDIN") == 0) { return (STDIN); } if (strcmp(name, "STDOUT") == 0) { return (STDOUT); } if (strcmp(name, "STDERR") == 0) { return (STDERR); } return (__sys_open (name, openmode));
}

/*--------------------------- _sys_close ------------------------------------*/

int _sys_close (FILEHANDLE fh) { if (fh > 0x8000) { return (0); } return (__sys_close (fh));
}

/*--------------------------- _sys_write ------------------------------------*/

int _sys_write (FILEHANDLE fh, const U8 *buf, U32 len, int mode) { //FILEHANDLE fh
#ifdef STDIO if (fh == STDOUT) { /* Standard Output device. */ for ( ; len; len--) { sendchar(*buf++);

} return (0); }
#endif if (fh > 0x8000) { return (-1); } return (__sys_write (fh, buf, len)); }

/*--------------------------- _sys_read -------------------------------------*/

int _sys_read (FILEHANDLE fh, U8 *buf, U32 len, int mode) {
#ifdef STDIO if (fh == STDIN) { /* Standard Input device. */ for ( ; len; len--) { *buf++ = getkey (); } return (0); }
#endif if (fh > 0x8000) { return (-1); } return (__sys_read (fh, buf, len));
}

/*--------------------------- _sys_istty ------------------------------------*/

int _sys_istty (FILEHANDLE fh) { if (fh > 0x8000) { return (1); } return (0);

}

/*--------------------------- _sys_seek -------------------------------------*/

int _sys_seek (FILEHANDLE fh, long pos) { if (fh > 0x8000) { return (-1); } return (__sys_seek (fh, pos));
}

/*--------------------------- _sys_ensure -----------------------------------*/

int _sys_ensure (FILEHANDLE fh) { if (fh > 0x8000) { return (-1); } return (__sys_ensure (fh));
}

/*--------------------------- _sys_flen -------------------------------------*/

long _sys_flen (FILEHANDLE fh) { if (fh > 0x8000) { return (0); } return (__sys_flen (fh));
}

/*--------------------------- _sys_tmpnam -----------------------------------*/

int _sys_tmpnam (char *name, int sig, unsigned maxlen) { return (1);
}

/*--------------------------- _sys_command_string ---------------------------*/

char *_sys_command_string (char *cmd, int len) { return (cmd);
}

/*--------------------------- _sys_exit -------------------------------------*/

void _sys_exit (int return_code) { /* Endless loop. */ while (1);
}

/*---------------------------------------------------------------------------- * end of file *---------------------------------------------------------------------------*/