summaryrefslogtreecommitdiffstats
path: root/tools/cpu/nios2/clocks.c
blob: 5a3293ef295de97e5f179ceaad24c566d41b769f (plain)
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
/*
 *  Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */

#include "ptf.h"
#include "clocks.h"

#include <stdlib.h>

void add_clock_spec(struct ptf_item *pi, void *arg)
{
  clock_desc **clocks = arg;
  clock_desc *new_clock;
  unsigned long freq;

  new_clock = (clock_desc*)malloc(sizeof(clock_desc));
  if(new_clock == NULL) return;

  new_clock->freq = strtoul(pi->item[pi->level]->value, 0, 0);

  new_clock->cfgname = NULL;
  new_clock->name = pi->item[pi->level-1]->value;
  new_clock->next = *clocks;


  *clocks = new_clock;
}

void set_clock_cfgname(struct ptf_item *pi, void *arg)
{
  clock_desc *clock = arg;
  clock->cfgname = pi->item[pi->level]->name;
}

clock_desc *find_clocks( struct ptf *sopc, struct ptf *cfg )
{
    clock_desc *clocks, *reverse;

    struct ptf system        = { section, "SYSTEM", 0, 0, 0 };
    struct ptf wizargs       = { section, "WIZARD_SCRIPT_ARGUMENTS", 0, 0, 0 };
    struct ptf all           = { section, "CLOCKS", 0, 0, 0 };
    struct ptf clock         = { section, "CLOCK", 0, 0, 0 };
    struct ptf freq          = { item,    "frequency", 0, 0, 0 };
    struct ptf_item clk_spec = { 5, &system, &wizargs, &all, &clock, &freq };

    struct ptf named     = { item, 0, 0, 0, 0 };
    struct ptf_item clk_cfg = { 2, &all, &named };

    clocks = NULL;
    ptf_match(sopc, &clk_spec, add_clock_spec, &clocks);

    /* Reverse the linked list and look for configured names */

    reverse = NULL;
    while(clocks)
    {
      clock_desc *tmp = clocks;
      clocks = clocks->next;
      tmp->next = reverse;
      reverse = tmp;

      named.value = tmp->name;
      ptf_match(cfg, &clk_cfg, set_clock_cfgname, tmp);
      if(tmp->cfgname == NULL) tmp->cfgname = ptf_defused_name(tmp->name);
    };

    return reverse;
}