]> rtime.felk.cvut.cz Git - arc.git/blob - common/ramlog.c
Initial ARM port
[arc.git] / common / ramlog.c
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15 \r
16 #include <stdio.h>\r
17 #include <stdarg.h>
18 #include "simple_printf.h"\r
19 \r
20
21 #ifndef CFG_RAMLOG_SIZE\r
22 #define CFG_RAMLOG_SIZE  2000
23 #endif\r
24 \r
25 static unsigned char ramlog[CFG_RAMLOG_SIZE] __attribute__ ((section (".ramlog")));\r
26 static unsigned ramlog_curr __attribute__ ((section (".ramlog")));\r
27 static unsigned ramlog_session __attribute__ ((section (".ramlog")));\r
28 \r
29 static FILE *ramlogFile = 0;\r
30 \r
31 \r
32 void ramlog_chr( char c ) {\r
33   ramlog[ramlog_curr++] = c;\r
34   if( ramlog_curr >= CFG_RAMLOG_SIZE ) {\r
35           ramlog_curr = 0;\r
36   }\r
37 }\r
38 \r
39 void ramlog_puts( char *str ) {\r
40 \r
41   while(*str!=0) {\r
42         ramlog_chr(*str++);\r
43   }\r
44   ramlog_chr('\n');\r
45 }\r
46 \r
47 void ramlog_printf( const char *format, ... ) {\r
48 \r
49         // Fast and ugly ramlog support.\r
50         volatile int rv;\r
51         va_list args;\r
52         va_start(args,format);\r
53 \r
54         rv = vfprintf(ramlogFile,format, args);\r
55         va_end(args);\r
56 }\r
57 \r
58 void ramlog_init()\r
59 {\r
60         char buf[32];\r
61     if( ramlog_curr>CFG_RAMLOG_SIZE)\r
62     {\r
63       ramlog_curr = 0;\r
64       ramlog_session = 0;\r
65     }\r
66 \r
67     ramlogFile = fopen("ramlog","a");\r
68 \r
69     ramlog_session++;\r
70 \r
71     simple_sprintf(buf, "Session (%d)\n", ramlog_session);\r
72     ramlog_puts(buf);\r
73 }\r