File: emit_jed.c

package info (click to toggle)
iverilog 12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,148 kB
  • sloc: cpp: 109,972; ansic: 62,713; yacc: 10,216; sh: 3,470; vhdl: 3,246; perl: 1,814; makefile: 1,774; python: 78; csh: 2
file content (128 lines) | stat: -rw-r--r-- 3,370 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form 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 program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

# include "config.h"

# include  "priv.h"
# include  <stdio.h>
# include  <stdlib.h>
# include  <assert.h>
# include  "ivl_alloc.h"

static void draw_macrocell_modes(FILE*jfd)
{
      unsigned idx;
      unsigned cfuses;
      unsigned mode, mcnt;

      for (idx = 0 ;  idx < pins ;  idx += 1) {
	    char*str;
	    unsigned ffirst, flast, tmp;
	    struct pal_bind_s*cur = bind_pin + idx;
	    if (cur->sop == 0)
		  continue;

	    cfuses = pal_sop_cfuses(cur->sop);
	    mcnt = 1 << pal_sop_cfuses(cur->sop);
	    mode = 0;
	    for (mode = 0 ;  mode < mcnt ;  mode += 1) {

		  pal_sop_set_mode(cur->sop, mode);
		  if (cur->reg && !pal_sop_is_register(cur->sop))
			continue;

		  if (!cur->reg && pal_sop_is_register(cur->sop))
			continue;

		  if (cur->sop_inv && !pal_sop_is_invert(cur->sop))
			continue;

		  if (!cur->sop_inv && pal_sop_is_invert(cur->sop))
			continue;

		  break;
	    }

	    assert(mode < mcnt);

	    ffirst = pal_sop_cfuse(cur->sop, 0);
	    flast  = pal_sop_cfuse(cur->sop, 0);
	    for (tmp = 1 ;  tmp < cfuses ;  tmp += 1) {
		  unsigned f = pal_sop_cfuse(cur->sop, tmp);
		  if (f < ffirst)
			ffirst = f;
		  if (f > flast)
			flast = f;
	    }
	    assert(flast == (ffirst + cfuses - 1));

	    str = malloc(cfuses+1);
	    str[cfuses] = 0;
	    for (tmp = 0 ;  tmp < cfuses ;  tmp += 1) {
		  if (mode & (1 << (cfuses-tmp-1)))
			str[pal_sop_cfuse(cur->sop, tmp)-ffirst] = '1';
		  else
			str[pal_sop_cfuse(cur->sop, tmp)-ffirst] = '0';
	    }


	    fprintf(jfd, "L%05u %s* Note: ", ffirst, str);
	    if (cur->nexus)
		  fprintf(jfd, "%s ", ivl_nexus_name(cur->nexus));

	    { int pin = pal_sop_pin(cur->sop);
	      if (pin > 0)
		    fprintf(jfd, "pin %d: ", pin);
	    }
	    if (pal_sop_is_register(cur->sop))
		  fprintf(jfd, "<registered");
	    else
		  fprintf(jfd, "<unregistered");

	    if (pal_sop_is_invert(cur->sop))
		  fprintf(jfd, ", invert");

	    fprintf(jfd, "> *\n");

	    free(str);
      }
}

int emit_jedec(const char*path)
{
      FILE*jfd;

      jfd = fopen(path, "w");
      if (jfd == 0) {
	    fprintf(stderr, "unable to open ``%s'' for output.\n", path);
	    return -1;
      }

      fprintf(jfd, "\002This file created by Icarus Verilog/PAL\n");
      fprintf(jfd, "*\n");

      fprintf(jfd, "QF%u*  Number of fuses*\n", pal_fuses(pal));
      fprintf(jfd, "F0*  Note: Default fuse set to 0*\n");
      fprintf(jfd, "G0*  Note: Security fuse NOT blown.*\n");

      draw_macrocell_modes(jfd);

      fclose(jfd);
      return 0;
}