source: rtems/tools/cpu/nios2/output.c @ e8cf7b5

4.104.115
Last change on this file since e8cf7b5 was 5f5f681, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/10/09 at 07:20:06

Whitespace removal.

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[037e1639]1/*
2 *  Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 *
8 *  $Id$
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "ptf.h"
16#include "devices.h"
17#include "output.h"
18
19typedef struct
20{
21  FILE *file;
22  device_desc *dev;
23  char *def_name;
24  char *orig_value;
25  clock_desc *clocks;
26  device_desc *devices;
27}
28out_desc;
29
30int is_not_connected(struct ptf_item *pi)
31{
32  if(pi->item[0] == NULL) return 0;
33  if(pi->item[0]->name == NULL) return 0;
34
35  if(strcmp(pi->item[0]->name, "SLAVE") == 0)
36  {
37    struct ptf *t;
38    struct ptf_item ti;
39    t = ptf_find(pi->item[0]->sub, &ti, item, "N2G_Selected", "1");
40
41    if(t == NULL) return 1;
42  };
43
44  return 0;
45}
46
47void fwrite_devhead_def(struct ptf_item *pi, void *arg)
48{
49  out_desc *dinfo = arg;
50
51  if(pi != NULL) if(is_not_connected(pi)) return;
52
53  fprintf(dinfo->file, "#define %s_%s %s\n",
54    dinfo->dev->cfgname, dinfo->def_name, dinfo->orig_value);
55}
56
57void fwrite_devhead_line(struct ptf_item *pi, void *arg)
58{
59  out_desc *dinfo = arg;
60
61  if(is_not_connected(pi)) return;
62
63  if(strncmp(dinfo->orig_value, "N2G_", 4)==0)
64  {
65    if(strncmp(dinfo->orig_value, "N2G_CLOCKREF_", 13)==0)
66    {
67      clock_desc *c;
68      for(c = dinfo->clocks; c; c=c->next)
69      {
70        if(strcmp(c->name, pi->item[pi->level]->value) == 0)
71        {
72          fprintf(dinfo->file, "#define %s_%s %s\n",
73            dinfo->dev->cfgname, dinfo->orig_value + 13, c->cfgname);
74          break;
75        };
76      };
77    }
78    else if(strncmp(dinfo->orig_value, "N2G_DEVICEREF_", 14)==0)
79    {
80      device_desc *d;
81      for(d = dinfo->devices; d; d=d->next)
82      {
83        if(strcmp(d->ptf->value, pi->item[pi->level]->value) == 0)
84        {
85          fprintf(dinfo->file, "#define %s_%s %s\n",
86            dinfo->dev->cfgname, dinfo->orig_value + 14, d->cfgname);
87          break;
88        };
89      };
90    }
91  }
92  else
93  {
[5f5f681]94    fprintf(dinfo->file, "#define %s_%s %s\n",
[037e1639]95      dinfo->dev->cfgname, dinfo->orig_value,
96      pi->item[pi->level]->value);
97  };
98}
99
100void fwrite_device_header(struct ptf_item *pi, void *arg)
101{
102  struct ptf *f;
103  struct ptf_item fi;
104  out_desc *dinfo = arg;
105
106  /* This is called for every matching CLASS section in the
107     configuration. The following loop iterates through all
108     items in the CLASS section regardless of their nesting level */
109
110  f = ptf_find(pi->item[pi->level]->sub, &fi, item, 0, 0);
111
[5f5f681]112  while(f != NULL)
[037e1639]113  {
114    dinfo->orig_value = f->value;
115    if(f->name && strncmp(f->name, "N2G_DEFINE_", 11)==0)
116    {
117      dinfo->def_name = f->name + 11;
118      if(fi.level >= 2)
119      {
120        fi.level--; /* match only the enclosing section */
121        ptf_match(dinfo->dev->ptf->sub, &fi, fwrite_devhead_def, dinfo);
122        fi.level++;
123      }
124      else
125      {
126        fwrite_devhead_def( 0, dinfo );
127      };
128    }
129    else
130    {
131      f->value = 0; /* Match ANY value */
132      ptf_match(dinfo->dev->ptf->sub, &fi, fwrite_devhead_line, dinfo);
133      f->value = dinfo->orig_value;
134    };
135    f = ptf_next(&fi, item, 0, 0);
136  };
137}
138
139void fwrite_value(struct ptf_item *pi, void *arg)
140{
141  FILE *file = arg;
142  fputs(pi->item[pi->level]->value, file);
143}
144
145void fwrite_header_file( FILE *file, struct ptf *cfg, device_desc *devices, clock_desc *clocks)
146{
147  struct ptf *p;
148  struct ptf_item pi;
149
150  struct ptf aclass = { section, "CLASS", 0, 0, 0 };
151  struct ptf_item matchaclass = { 1, &aclass };
152
[16fd5a9]153  struct ptf bspsect = { section, "BSPHEADER", 0, 0, 0 };
154  struct ptf leadtext = { item, "LEADTEXT", 0, 0, 0 };
155  struct ptf_item matchleadtext = { 2, &bspsect, &leadtext };
[037e1639]156
157  struct ptf epilog = { item, "EPILOG", 0, 0, 0 };
[16fd5a9]158  struct ptf_item matchepilog = { 2, &bspsect, &epilog };
[037e1639]159
160  out_desc dinfo;
161
162  dinfo.file    = file;
163  dinfo.clocks  = clocks;
164  dinfo.devices = devices;
165
[16fd5a9]166  ptf_match(cfg, &matchleadtext, fwrite_value, file);
[037e1639]167
168  if(clocks)
169  {
170    clock_desc *cs;
171    for(cs = clocks; cs; cs = cs->next)
172    {
173      fprintf(file, "#define %s_FREQ %luu\n", cs->cfgname, cs->freq);
174    };
175  };
176
177  if(devices)
178  {
179    for(dinfo.dev = devices; dinfo.dev; dinfo.dev=dinfo.dev->next)
180    {
[16fd5a9]181      /* fprintf(file, "\n#define SOPC_HAS_%s 1\n", dinfo.dev->cfgname); */
[037e1639]182
183      p = ptf_find(dinfo.dev->ptf, &pi, item, "class", 0);
184      if(p)
185      {
186        aclass.value = p->value;
187        ptf_match(cfg, &matchaclass, fwrite_device_header, &dinfo);
188      };
189    };
190  };
191
192  ptf_match(cfg, &matchepilog, fwrite_value, file);
193}
194
[5f5f681]195
Note: See TracBrowser for help on using the repository browser.