1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
17 * A very simple ramlog.
\r
20 * - Prints to a ram space in section ".ramlog"
\r
21 * - The size is configurable using CFG_RAMLOG_SIZE (default is 1000)
\r
22 * - The ramlog section should not be cleared by the linkfile if one wants
\r
23 * to have a ramlog that survives reset.
\r
26 * Assumes some c-lib support:
\r
27 * - The clib support should be able to open a file called "ramlog".
\r
28 * - Printing to that file will print to the ramlog.
\r
32 * The ramlog uses a very simple header.
\r
35 * +----+----+----+----+
\r
37 * +----+----+----+----+
\r
40 * Byte 1 is a counter that incremented for each time the ramlog is started.
\r
41 * Byte 2 is not defined yet.
\r
44 * 01 is used since it's control sign and not a printable char.
\r
46 * STRATEGY FOR SESSION
\r
48 * 1. The ramlog is empty, ie the header is not there at first position
\r
49 * 2. The header is in first poistion
\r
50 * - look for the next?
\r
51 * - Use saved inforation?
\r
62 #ifndef CFG_RAMLOG_SIZE
\r
63 #define CFG_RAMLOG_SIZE 2000
\r
66 #define RAMLOG_MAGIC 1
\r
69 SECTION_RAMLOG static unsigned char ramlog[CFG_RAMLOG_SIZE];
\r
70 #if defined(CFG_RAMLOG_SESSION)
\r
71 SECTION_RAMLOG static unsigned ramlog_curr;
\r
72 SECTION_RAMLOG static unsigned ramlog_session;
\r
74 static unsigned ramlog_curr = 0;
\r
77 #define RAMLOG_FILENO (FILE *)3
\r
81 * Print a char to the ramlog
\r
84 void ramlog_chr( char c ) {
\r
85 ramlog[ramlog_curr++] = c;
\r
86 if( ramlog_curr >= CFG_RAMLOG_SIZE ) {
\r
92 * Print a string to the ramlog
\r
95 void ramlog_puts( char *str ) {
\r
104 * Formatted print for the ramlog.
\r
106 * @param format The format string.
\r
108 void ramlog_printf( const char *format, ... ) {
\r
110 // Fast and ugly ramlog support.
\r
113 va_start(args,format);
\r
115 rv = vfprintf(RAMLOG_FILENO, format, args);
\r
121 * Initialize the ramlog. Must be called before any other ramlog functions.
\r
126 #if defined(CFG_RAMLOG_SESSION)
\r
128 /* Check for existing session */
\r
129 if( (ramlog[0] != RAMLOG_MAGIC) || (ramlog[3] != RAMLOG_MAGIC) ) {
\r
131 ramlog_session = 0;
\r
133 /* Search the ramlog */
\r
136 simple_sprintf(buf, "Session (%d)\n", ramlog_session);
\r