summaryrefslogtreecommitdiffstats
path: root/firmware/export/logdiskf.h
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2012-07-03 21:45:29 -0400
committerMichael Giacomelli <mgiacomelli@gmail.com>2012-08-07 00:53:46 +0200
commitd46b090771291c10127d0fb421ee3c9f1e8f69b1 (patch)
treeae5a6e01f6d2025294f8905a9a791c4ede3d4869 /firmware/export/logdiskf.h
parent7c31ff2fb0cc3ba40f82c3b02daf1e7ca41e1cf6 (diff)
downloadrockbox-d46b090771291c10127d0fb421ee3c9f1e8f69b1.tar.gz
rockbox-d46b090771291c10127d0fb421ee3c9f1e8f69b1.zip
Introduce logging to disk feature into rockbox.
Logs information, errors, etc to disk using the register_storage_idle_func mechanism to write to the disk when available. Currently, this is disabled in normal builds, but can be enabled by adding ROCKBOX_HAS_LOGDISKF to the config file. By default, it uses a 2KB buffer and drops text if the buffer overflows. The system includes a simple warning level mechanism that can be used to by default exclude non-serious errors from logging on release builds. Change-Id: I0a3d186a93625c7c93dae37b993a0d37e5a3a925 Reviewed-on: http://gerrit.rockbox.org/288 Reviewed-by: Jonathan Gordon <rockbox@jdgordon.info> Tested-by: Michael Giacomelli <mgiacomelli@gmail.com> Reviewed-by: Michael Giacomelli <mgiacomelli@gmail.com>
Diffstat (limited to 'firmware/export/logdiskf.h')
-rw-r--r--firmware/export/logdiskf.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/firmware/export/logdiskf.h b/firmware/export/logdiskf.h
new file mode 100644
index 0000000000..628662fdba
--- /dev/null
+++ b/firmware/export/logdiskf.h
@@ -0,0 +1,81 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2012 by Michael Giacomelli
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef LOGDISKF_H
+#define LOGDISKF_H
+#include <config.h>
+#include <stdbool.h>
+#include "gcc_extensions.h"
+#include "debug.h"
+
+#ifdef ROCKBOX_HAS_LOGDISKF
+
+void init_logdiskf(void);
+
+#ifndef __PCTOOL__
+
+/*large memory devices spin up the disk much less often*/
+#if MEMORYSIZE > 32
+ #define MAX_LOGDISKF_SIZE 8192
+#elif MEMORYSIZE > 8
+ #define MAX_LOGDISKF_SIZE 4096
+#else
+ #define MAX_LOGDISKF_SIZE 1024
+#endif
+
+extern unsigned char logdiskfbuffer[MAX_LOGDISKF_SIZE];
+extern int logfdiskindex;
+#endif /* __PCTOOL__ */
+
+
+#define LOGDISK_LEVEL 1
+
+#if LOGDISK_LEVEL > 0 /*serious errors or problems*/
+ #define ERRORF(...) _logdiskf(__func__,'E', __VA_ARGS__)
+#else
+ #define ERRORF(...)
+#endif
+
+#if LOGDISK_LEVEL > 1 /*matters of concern*/
+ #define WARNF(...) _logdiskf(__func__, 'W', __VA_ARGS__)
+#else
+ #define WARNF(...)
+#endif
+
+#if LOGDISK_LEVEL > 2 /*useful for debug only*/
+ #define NOTEF(...) _logdiskf(__func__, 'N', __VA_ARGS__)
+#else
+ #define NOTEF(...) /*TODO: rename DEBUGF later*/
+#endif
+
+/*__FILE__ would be better but is difficult to make work with the build system*/
+//#define logdiskf(...) _logdiskf(__func__, 1, __VA_ARGS__)
+
+void _logdiskf(const char* file, const char level,
+ const char *format, ...) ATTRIBUTE_PRINTF(3, 4);
+
+#else /* !ROCKBOX_HAS_LOGF */
+
+/* built without logdiskf() support enabled, replace logdiskf() by DEBUGF() */
+#define logdiskf(f,args...) DEBUGF(f"\n",##args)
+
+#endif /* !ROCKBOX_HAS_LOGDISKF */
+
+#endif /* LOGDISKF_H */