summaryrefslogtreecommitdiff
path: root/cesar/station/src/station.c
blob: d09a51d7ea676d4859455c269a24b276460bb1cb (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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cesar.c
 * \brief   main level of cesar software.
 * \ingroup cesar
 */
#include "common/std.h"
#include "common/module.h"

#include "lib/trace.h"
#include "lib/stats.h"

#include "mac/common/ntb.h"
#include "station/station.h"

#if MODULE_INCLUDED (hal_leon)
#  include "config/leon/fatal/button.h"
#  include "hal/leon/fatal_button.h"
#endif

#if MODULE_INCLUDED (hal_trace)
#  include "hal/trace/trace.h"
#  include "config/hal/trace/cpu.h"
#endif

#include "lib/seq_check.h"

#include "lib/init.h"

/** Static declaration. */
static cesar_t cesar;

/**
 * \brief CESAR application software entry-point function.
 */
cesar_t *
cesar_init (void)
{
    u32 seed = 0;
    trace_init ();

#if MODULE_INCLUDED (hal_trace)
    hal_trace_init ();
#endif

#if MODULE_INCLUDED (hal_leon) && CONFIG_LEON_FATAL_BUTTON
    leon_fatal_button_init ();
#endif

    lib_stats_init ();

    lib_seq_check_config_init ();

    /* Initialise the mac store. */
    cesar.mac_store  = mac_store_init ();

    /* Initialise the MAC config. */
    mac_config_init (&cesar.mac_config);

    /* Get the Seed from the Hal PHY. */
    seed = phy_seed ();
    cesar.mac_config.seed = seed;

    /* Initialise the PBproc. */
    cesar.pbproc = pbproc_init (&cesar.mac_config,
                                cesar.mac_store);

    /* Initialise the mac ntb. */
    mac_ntb_init (&cesar.mac_config);

    /* Initialise the SAR. */
    cesar.sar = sar_init (cesar.mac_store, cesar.pbproc,
                          pbproc_get_ca(cesar.pbproc), seed);

    /* Initialise the CL. */
    cesar.cl = cl_init (cesar.mac_store, cesar.sar,
                        &cesar.mac_config);

    /* Initialise the HLE. */
    cesar.hle = hle_init (cesar.cl);

    /* Initialise the interface. */
    cesar.interface = interface_init(cesar.hle,
                                     cesar.cl,
                                     cesar.sar,
                                     &cesar.mac_config);

    /* Initialise the hal timer. */
    cesar.hal_timer = hal_timer_init ();

    /* Initialise the ACLF. */
    cesar.bsu_aclf = bsu_aclf_init (pbproc_get_phy(cesar.pbproc),
                                    &cesar.mac_config);

    /* Initialise the bsu. */
    cesar.bsu = bsu_init (cesar.bsu_aclf, &cesar.mac_config,
                          pbproc_get_phy (cesar.pbproc),
                          cesar.mac_store, pbproc_get_ca (cesar.pbproc),
                          cesar.sar, cesar.hal_timer, cesar.pbproc);
    /* Initialize the CE in RX. */
    cesar.ce_rx = ce_rx_init (cesar.mac_store, cesar.sar, cesar.pbproc,
                              &cesar.mac_config);
    /* Initialise the CP. */
    cesar.cp = cp_init (cesar.bsu, cesar.bsu_aclf, &cesar.mac_config,
                        cesar.interface, cesar.hal_timer, cesar.pbproc,
                        cesar.mac_store, cesar.sar, cesar.cl, cesar.ce_rx,
                        seed);

    // start HLE...
    hle_activate(cesar.hle, true);

    init_exec (INIT_LIST_CE);

    return &cesar;
}


void
cesar_uninit (cesar_t *ctx)
{
    dbg_assert (ctx);

    sar_cleanup (ctx->sar);

    cp_uninit (ctx->cp);
    interface_uninit(ctx->interface);
    hle_uninit (ctx->hle);
    cl_uninit (ctx->cl);
    sar_uninit (ctx->sar);
    pbproc_uninit (ctx->pbproc);
    ce_rx_uninit (ctx->ce_rx);
    bsu_uninit (cesar.bsu);
    mac_store_uninit (ctx->mac_store);
    hal_timer_uninit (cesar.hal_timer);

    lib_stats_uninit ();
    trace_uninit ();
}