misc: Fixed a couple of typos in comments
[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 #define AVR_VCD_LOG_SIZE        5120
44
45 typedef struct avr_vcd_signal_t {
46         avr_irq_t       irq;            // receiving IRQ
47         char    alias;                  // vcd one character alias
48         int             size;                   // in bits
49         char    name[32];               // full human name      
50 } avr_vcd_signal_t;
51
52 typedef struct avr_vcd_log_t {
53         uint64_t        when;
54         avr_vcd_signal_t * signal;
55         uint32_t value;
56 } avr_vcd_log_t;
57
58 typedef struct avr_vcd_t {
59         struct avr_t *  avr;    // AVR we are attaching timers to..
60         
61         char filename[74];              // output filename
62         FILE * output;
63
64         int signal_count;
65         avr_vcd_signal_t        signal [AVR_VCD_MAX_SIGNALS];   
66
67         uint64_t period;
68         uint64_t start;
69
70         uint32_t                logindex;
71         avr_vcd_log_t   log[AVR_VCD_LOG_SIZE];
72 } avr_vcd_t;
73
74 // initializes a new VCD trace file, and returns zero if all is well
75 int avr_vcd_init(struct avr_t * avr, 
76         const char * filename,  // filename to write
77         avr_vcd_t * vcd,                // vcd struct to initialize
78         uint32_t        period );       // file flushing period is in usec
79 void avr_vcd_close(avr_vcd_t * vcd);
80
81 // Add a trace signal to the vcd file. Must be called before avr_vcd_start()
82 int avr_vcd_add_signal(avr_vcd_t * vcd, 
83         avr_irq_t * signal_irq,
84         int signal_bit_size,
85         const char * name );
86
87 // Starts recording the signal value into the file
88 int avr_vcd_start(avr_vcd_t * vcd);
89 // stops recording signal values into the file
90 int avr_vcd_stop(avr_vcd_t * vcd);
91
92 #ifdef __cplusplus
93 };
94 #endif
95
96 #endif /* __SIM_VCD_FILE_H__ */