source: rtems/tools/cpu/nios2/nios2gen.c @ 037e1639

4.104.114.84.95
Last change on this file since 037e1639 was 037e1639, checked in by Joel Sherrill <joel.sherrill@…>, on 08/09/06 at 21:05:32

2006-08-09 Kolja Waschk <waschk@…>

  • configure.ac: New port to Altera NIOS II.
  • nios2/.cvsignore, nios2/Makefile.am, nios2/README, nios2/bridges.c, nios2/bridges.h, nios2/clocks.c, nios2/clocks.h, nios2/configure.ac, nios2/devices.c, nios2/devices.h, nios2/nios2gen.c, nios2/output.c, nios2/output.h, nios2/ptf.c, nios2/ptf.h: New files.
  • Property mode set to 100644
File size: 5.6 KB
Line 
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 "bridges.h"
17#include "clocks.h"
18#include "devices.h"
19#include "output.h"
20
21/********************************************************/
22
23void store_ptf_parent(struct ptf_item *pi, void *arg)
24{
25  struct ptf *p = pi->item[pi->level-1];
26  *(struct ptf **)arg = p;
27}
28
29/********************************************************/
30
31void store_ptf_ptr(struct ptf_item *pi, void *arg)
32{
33  struct ptf *p = pi->item[pi->level];
34  *(struct ptf **)arg = p;
35}
36
37/********************************************************/
38
39void printf_ptf_value(struct ptf_item *pi, void *arg)
40{
41  struct ptf *p = pi->item[pi->level];
42  printf(*(char **)arg, p->value);
43}
44
45/********************************************************/
46
47void read_include_file(struct ptf_item *pi, void *arg)
48{
49    struct ptf *inc, *next;
50    struct ptf *p = pi->item[pi->level];
51
52    inc = ptf_parse_file(p->value);
53
54    if(inc == NULL)
55    {
56        fprintf(stderr, "Warning: couldn't parse included '%s'.\n", p->value);
57        return;
58    };
59
60    printf("Successfully read included PTF file %s.\n", p->value);
61
62    next = p->next;
63    for(p->next = inc; p->next != NULL; p = p->next);
64    p->next = next;
65}
66
67void usage()
68{
69        fprintf(stderr,
70"Please specify the name of a nios2gen PTF file that describes where to\n"
71"find the system description PTF from SOPC Builder on the command line.\n");
72}
73
74/********************************************************/
75
76int main(int argc, char *argv[])
77{
78    struct ptf *sopc, *cfg, *p, *cpu;
79    struct ptf_item pi;
80    device_desc *devices;
81    bus_bridge_pair *bridges;
82    clock_desc *clocks;
83
84    if (argc<2)
85    {
86        usage();
87        return -1;
88    };
89
90    cfg = ptf_parse_file(argv[1]);
91    if(cfg == NULL)
92    {
93        fprintf(stderr, "Couldn't parse '%s'.\n", argv[1]);
94        return -1;
95    };
96
97    printf("Successfully read config PTF file %s.\n", argv[1]);
98
99    /********************************************************/
100
101    {
102      struct ptf include_item = { item, "INCLUDE", 0, 0, 0 };
103      struct ptf_item inc_file_spec = { 1, &include_item };
104      ptf_match(cfg, &inc_file_spec, read_include_file, NULL);
105    }
106
107    /********************************************************/
108   
109    {
110      struct ptf *p;
111      struct ptf sopc_ptf_item = { item, "SOPC_PTF", 0, 0, 0 };
112      struct ptf_item sopc_ptf_spec = { 1, &sopc_ptf_item };
113      ptf_match(cfg, &sopc_ptf_spec, store_ptf_ptr, &p);
114
115      if(p == NULL)
116      {
117          fprintf(stderr, "Missing 'SOPC_PTF' filename in %s!\n", argv[1]);
118          return -1;
119      };
120
121      sopc = ptf_parse_file(p->value);
122      if(sopc == NULL)
123      {
124          fprintf(stderr, "Could not parse SOPC_PTF '%s'.\n", p->value);
125          return -1;
126      };
127
128      printf("Successfully read SOPC PTF file %s.\n", p->value);
129    };
130
131    /********************************************************/
132    /* Find CPU */
133
134    printf("Looking for usable CPUs...\n");
135
136    {
137      struct ptf modules         = { section, "MODULES", 0, 0, 0 };
138      struct ptf cpu_def         = { item, "CPU", 0, 0, 0 };
139      struct ptf_item cpu_spec   = { 2, &modules, &cpu_def };
140
141      ptf_match(cfg, &cpu_spec, store_ptf_ptr, &cpu);
142    };
143
144    {
145      int cpu_count;
146      struct ptf system          = { section, "SYSTEM", 0, 0, 0 };
147      struct ptf module          = { section, "MODULE", 0, 0, 0 };
148      struct ptf nios2_cpu_class = { item, "class", "altera_nios2", 0, 0 };
149      struct ptf_item class_spec = { 3, &system, &module, &nios2_cpu_class };
150
151      if(cpu) if(cpu->value) class_spec.item[1]->value = cpu->value;
152
153      cpu_count = ptf_match(sopc, &class_spec, store_ptf_parent, &cpu);
154
155      if(cpu_count > 1)
156      {
157        printf("There is more than one CPU. Please specify the one\n");
158        printf("you want to use with this BSP in your config file.\n");
159        printf("The available CPUs are named as follows:\n");
160        ptf_match(sopc, &class_spec, printf_ptf_value, "  %s\n");
161        return -1; 
162      };
163
164      if(cpu_count == 0)
165      {
166        printf("There is no NIOS2 cpu in the system.\n");
167        return -1; 
168      }
169    };
170
171    printf("Using NIOS II CPU '%s'.\n", cpu->value);
172    printf("Only modules mastered by this CPU are considered now.\n");
173
174    /********************************************************/
175    /* Find clocks */
176
177    printf("Looking for clock definitions...\n");
178
179    clocks = find_clocks(sopc, cfg);
180
181    if(clocks)
182    {
183      clock_desc *cs;
184      for(cs = clocks; cs; cs = cs->next)
185      {
186        printf("Found clock: %s (%lu Hz)\n", cs->name, cs->freq);
187      };
188    }
189    else
190    {
191      printf("No clocks present.\n");
192    };
193
194    /********************************************************/
195    /* Find Bridges */
196
197    printf("Looking for bus bridges...\n");
198
199    bridges = find_bridges(sopc);
200
201    if(bridges)
202    {
203      bus_bridge_pair *bbp;
204      for(bbp = bridges; bbp; bbp=bbp->next)
205      {
206        printf("Found bridge: %s\n", bbp->mastered_by);
207        printf("               \\_%s\n", bbp->bridges_to);
208      };
209    }
210    else
211    {
212      printf("No bridges present.\n");
213    };
214
215    /********************************************************/
216    /* Find other devices available to the selected CPU */
217
218    devices = find_devices(sopc, cfg, cpu, bridges);
219
220    fwrite_header_file(stdout, cfg, devices, clocks);
221
222    // ptf_printf(stdout, ptf, "");
223    // ptf_printf(stdout, cfg, "");
224
225    return 0;
226}
227
228/* vi:ts=4:
229 */
230
231
Note: See TracBrowser for help on using the repository browser.