misc: Point to correct simavr include dirs
[simavr] / simavr / sim / sim_vcd_file.h
1 /*
2         sim_vcd_file.c
3
4         Implements a Value Change Dump file outout to generate
5         traces & curves and display them in gtkwave.
6
7         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
8
9         This file is part of simavr.
10
11         simavr is free software: you can redistribute it and/or modify
12         it under the terms of the GNU General Public License as published by
13         the Free Software Foundation, either version 3 of the License, or
14         (at your option) any later version.
15
16         simavr is distributed in the hope that it will be useful,
17         but WITHOUT ANY WARRANTY; without even the implied warranty of
18         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19         GNU General Public License for more details.
20
21         You should have received a copy of the GNU General Public License
22         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25 #ifndef __SIM_VCD_FILE_H__
26 #define __SIM_VCD_FILE_H__
27
28 #include <stdio.h>
29 #include "sim_irq.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*
36  * Value Change dump module for simavr.
37  * 
38  * This structure registers IRQ change hooks to various "source" IRQs
39  * and dumps their values (if changed) at certain intervals into the VCD file
40  */
41
42 #define AVR_VCD_MAX_SIGNALS 32
43
44 typedef struct avr_vcd_signal_t {
45         avr_irq_t       irq;            // receiving IRQ
46         char    alias;                  // vcd one character alias
47         int             size;                   // in bits
48         char    name[32];               // full human name      
49 } avr_vcd_signal_t;
50
51 typedef struct avr_vcd_log_t {
52         uint64_t        when;
53         avr_vcd_signal_t * signal;
54         uint32_t value;
55 } avr_vcd_log_t, *avr_vcd_log_p;
56
57 #define AVR_VCD_LOG_CHUNK_SIZE  (4096 / sizeof(avr_vcd_signal_t))
58
59 typedef struct avr_vcd_t {
60         struct avr_t *  avr;    // AVR we are attaching timers to..
61         
62         char filename[74];              // output filename
63         FILE * output;
64
65         int signal_count;
66         avr_vcd_signal_t        signal [AVR_VCD_MAX_SIGNALS];   
67
68         uint64_t period;
69         uint64_t start;
70
71         size_t                  logsize;
72         uint32_t                logindex;
73         avr_vcd_log_p   log;
74 } avr_vcd_t;
75
76 // initializes a new VCD trace file, and returns zero if all is well
77 int avr_vcd_init(struct avr_t * avr, 
78         const char * filename,  // filename to write
79         avr_vcd_t * vcd,                // vcd struct to initialize
80         uint32_t        period );       // file flushing period is in usec
81 void avr_vcd_close(avr_vcd_t * vcd);
82
83 // Add a trace signal to the vcd file. Must be called before avr_vcd_start()
84 int avr_vcd_add_signal(avr_vcd_t * vcd, 
85         avr_irq_t * signal_irq,
86         int signal_bit_size,
87         const char * name );
88
89 // Starts recording the signal value into the file
90 int avr_vcd_start(avr_vcd_t * vcd);
91 // stops recording signal values into the file
92 int avr_vcd_stop(avr_vcd_t * vcd);
93
94 #ifdef __cplusplus
95 };
96 #endif
97
98 #endif /* __SIM_VCD_FILE_H__ */