00001
00006 #include "uffs/uffs_public.h"
00007 #include <stdio.h>
00008 #include <stdarg.h>
00009 #include <string.h>
00010
00011 #ifndef LINUX
00012 #define LINUX
00013 #endif
00014
00015 #if defined(WIN32) | defined(LINUX)
00016 #define ENABLE_DEBUG
00017
00018 #endif
00019
00020 #if defined(WIN32) | defined(LINUX)
00021
00022
00023 #ifdef OUTPUT_TOFILE
00024 #define DEBUG_LOGFILE "c:\\nlscan\\log.txt"
00025 #endif
00026
00027 void uffs_Perror( int level, const char *errFmt, ...)
00028 {
00029
00030 #ifdef ENABLE_DEBUG
00031 if (level >= UFFS_DBG_LEVEL) {
00032
00033 char buf[1024] = "";
00034 #ifdef OUTPUT_TOFILE
00035 FILE *fp = NULL;
00036 #endif
00037
00038 va_list arg;
00039
00040 if( strlen(errFmt) > 800 ) {
00041
00042 printf("uffs_Perror buffer is not enough !\r\n");
00043 return;
00044 }
00045
00046 va_start(arg, errFmt);
00047 vsprintf(buf, errFmt, arg);
00048 va_end(arg);
00049
00050 #ifdef OUTPUT_TOFILE
00051 fp = fopen(DEBUG_LOGFILE, "a+b");
00052 if(fp) {
00053 fwrite(buf, 1, strlen(buf), fp);
00054 fclose(fp);
00055 }
00056 #else
00057 printf(buf);
00058 #endif
00059 }
00060 #endif //ENABLE_DEBUG
00061 }
00062
00063 #else
00064
00065
00066
00067 #include <uBase.h>
00068 #include <mm_snprintf.h>
00069
00070 static void uffs_vTrace(const char *lpszFormat, va_list args)
00071 {
00072
00073 int nBuf;
00074 char buf[512];
00075 UART_PARAM param;
00076
00077 nBuf = vsnprintf(buf, sizeof(buf), lpszFormat, args);
00078
00079 UartOpen(COM1);
00080 UartGetParam(COM1, ¶m);
00081 param.baudrate = 115200;
00082 param.data = 8;
00083 param.parity = NOPARITY;
00084 param.stop = ONESTOPBIT;
00085 UartSetParam(COM1, ¶m);
00086 UartWrite(COM1, buf, nBuf, TIMEOUT_INFINITE);
00087 UartClose(COM1);
00088 }
00089
00090 void uffs_Perror( int level, const char *errFmt, ...)
00091 {
00092 #ifdef ENABLE_DEBUG
00093 if (level >= UFFS_DBG_LEVEL) {
00094 va_list args;
00095 va_start(args, errFmt);
00096 uffs_vTrace(errFmt, args);
00097 va_end(args);
00098 }
00099 #endif //ENABLE_DEBUG
00100
00101 }
00102
00103 #endif
00104