source: rtems/tools/cpu/nios2/clocks.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.9 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.org/license/LICENSE.
7 */
8
9#include "ptf.h"
10#include "clocks.h"
11
12#include <stdlib.h>
13
14void add_clock_spec(struct ptf_item *pi, void *arg)
15{
16  clock_desc **clocks = arg;
17  clock_desc *new_clock;
18  unsigned long freq;
19
20  new_clock = (clock_desc*)malloc(sizeof(clock_desc));
21  if(new_clock == NULL) return;
22
23  new_clock->freq = strtoul(pi->item[pi->level]->value, 0, 0);
24
25  new_clock->cfgname = NULL;
26  new_clock->name = pi->item[pi->level-1]->value;
27  new_clock->next = *clocks;
28
29
30  *clocks = new_clock;
31}
32
33void set_clock_cfgname(struct ptf_item *pi, void *arg)
34{
35  clock_desc *clock = arg;
36  clock->cfgname = pi->item[pi->level]->name;
37}
38
39clock_desc *find_clocks( struct ptf *sopc, struct ptf *cfg )
40{
41    clock_desc *clocks, *reverse;
42
43    struct ptf system        = { section, "SYSTEM", 0, 0, 0 };
44    struct ptf wizargs       = { section, "WIZARD_SCRIPT_ARGUMENTS", 0, 0, 0 };
45    struct ptf all           = { section, "CLOCKS", 0, 0, 0 };
46    struct ptf clock         = { section, "CLOCK", 0, 0, 0 };
47    struct ptf freq          = { item,    "frequency", 0, 0, 0 };
48    struct ptf_item clk_spec = { 5, &system, &wizargs, &all, &clock, &freq };
49
50    struct ptf named     = { item, 0, 0, 0, 0 };
51    struct ptf_item clk_cfg = { 2, &all, &named };
52
53    clocks = NULL;
54    ptf_match(sopc, &clk_spec, add_clock_spec, &clocks);
55
56    /* Reverse the linked list and look for configured names */
57
58    reverse = NULL;
59    while(clocks)
60    {
61      clock_desc *tmp = clocks;
62      clocks = clocks->next;
63      tmp->next = reverse;
64      reverse = tmp;
65
66      named.value = tmp->name;
67      ptf_match(cfg, &clk_cfg, set_clock_cfgname, tmp);
68      if(tmp->cfgname == NULL) tmp->cfgname = ptf_defused_name(tmp->name);
69    };
70
71    return reverse;
72}
73
74
75
Note: See TracBrowser for help on using the repository browser.