summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/src/trace.c
blob: 6f8377aa27417769de2ea8529a0bf14805d7786b (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/src/trace.c
 * \brief   Define PHY trace events.
 * \ingroup hal_phy
 */
#include "common/std.h"

#include "inc/context.h"
#include "inc/regs.h"

#include <stdio.h>

#define PHY_TRACE_EVENT(id, format, args...) \
    TRACE_EVENT (PHY_TRACE_ ## id, format, ## args)

/**
 * Format CSMA register.
 * \see trace_format_t.
 */
static int
phy_trace_format_csma (char *text, uint text_size, int data)
{
    char *t = text;
    int r;
    u32 reg = data;
    /* CAP. */
    r = snprintf (t, text_size, "%us%um%u",
                  BF_GET (PHY_PRATIC_CSMA__MPDU_CAP, reg),
                  BF_GET (PHY_PRATIC_CSMA__SENT_CAP, reg),
                  BF_GET (PHY_PRATIC_CSMA__MEDIUM_CAP, reg)
                  );
    if (r + 4 >= (int) text_size)
        return -1;
    t += r;
    if (reg & BF_MASK (PHY_PRATIC_CSMA__FALSE_ALARM))
        *t++ = 'f';
    if (reg & BF_MASK (PHY_PRATIC_CSMA__TX_PRIORITY_LOST))
        *t++ = 'P';
    if (reg & BF_MASK (PHY_PRATIC_CSMA__TX_WHILE_RX))
        *t++ = 'R';
    if (reg & BF_MASK (PHY_PRATIC_CSMA__TX_CANCEL_DUE_TO_FALSE_ALARM))
        *t++ = 'F';
    return t - text;
}

/**
 * Format combo parameters.
 * \see trace_format_t.
 */
static int
phy_trace_format_combo_params (char *text, uint text_size, int data)
{
    int r;
    u32 reg = data;
    /* CAP. */
    r = snprintf (text, text_size, "mod=%d fecrate=%d pb_size=%d",
                  BF_GET (PHY_COMBO_PARAMS__MOD, reg),
                  BF_GET (PHY_COMBO_PARAMS__FECRATE, reg),
                  BF_GET (PHY_COMBO_PARAMS__PB_SIZE, reg)
                  );
    if (r >= (int) text_size)
        return -1;
    return r;
}

void
phy_trace_init (phy_t *ctx)
{
    static trace_namespace_t namespace;
    static const trace_event_id_t event_ids[] =
    {
        PHY_TRACE_EVENT (INIT, "init"),
        PHY_TRACE_EVENT (SET_TONEMASK, "set tonemask carrier_nb=%u"),
        PHY_TRACE_EVENT (UNINIT, "uninit"),
        PHY_TRACE_EVENT (RESET, "reset"),
        PHY_TRACE_EVENT (ISR_EXIT, "isr exit", TIMESTAMP),
        PHY_TRACE_EVENT (CLOCK_SET_NUMERATOR,
                         "clock set numerator %u"),
        PHY_TRACE_EVENT (SET_TONEMAP, "set tonemap %x"),
        PHY_TRACE_EVENT (DATE_WARNING, "date warning %d", TIMESTAMP),
        PHY_TRACE_EVENT (TX_FC10, "tx fc10 %x"),
        PHY_TRACE_EVENT (TX_PARAM, "tx param mode=%u %P gil=%u"),
        PHY_TRACE_EVENT (TX_PARAM_SHORT, "tx param short mode=%u"),
        PHY_TRACE_EVENT (TX_PARAM_SOUND,
                         "tx sound mode=%u nb_pb=%u %P gil=%u"),
        PHY_TRACE_EVENT (TX_FRAME,
                         "tx frame date=%x want_conf=%b "
                         "stop_on_prp_lost=%b fc=%x", TIMESTAMP),
        PHY_TRACE_EVENT (TX_PREPARE,
                         "tx prepare", TIMESTAMP),
        PHY_TRACE_EVENT (TX_CANCEL, "tx cancel"),
        PHY_TRACE_EVENT (TX_END, "tx end", TIMESTAMP),
        PHY_TRACE_EVENT (TX_CONGESTION, "tx congestion", TIMESTAMP),
        PHY_TRACE_EVENT (RX_PARAM, "rx param mode=%u"),
        PHY_TRACE_EVENT (RX_ACTIVATE,
                         "rx activate date=%x flag=%b"),
        PHY_TRACE_EVENT (RX_ACTIVATE_NOW,
                         "rx activate now flag=%b", TIMESTAMP),
        PHY_TRACE_EVENT (RX_PREPARE,
                         "rx prepare %P gil=%u symb_nb=%u", TIMESTAMP),
        PHY_TRACE_EVENT (RX_PREPARE_SHORT,
                         "rx prepare short", TIMESTAMP),
        PHY_TRACE_EVENT (RX_PREPARE_SOUND,
                         "rx sound nb_pb=%u %P gil=%u symb_nb=%u", TIMESTAMP),
        PHY_TRACE_EVENT (EXTRA_TIMER_PROGRAM,
                         "extra timer program %x"),
        PHY_TRACE_EVENT (EXTRA_TIMER_CANCEL, "extra timer cancel"),
        PHY_TRACE_EVENT (ACCESS_CONF_CB, "access conf cb eff=%x", TIMESTAMP),
        PHY_TRACE_EVENT (RX_FC_CB, "rx fc cb rx_date=%x", TIMESTAMP),
        PHY_TRACE_EVENT (TX_FALSE_ALARM_CB, "tx false alarm cb", TIMESTAMP),
        PHY_TRACE_EVENT (DEFERRED_CB, "deferred cb", TIMESTAMP),
        PHY_TRACE_EVENT (EXTRA_TIMER_CB, "extra timer cb eff=%x", TIMESTAMP),
        PHY_TRACE_EVENT (PBDMA_START_ON_RESYS,
                         "pbdma start on resys", TIMESTAMP),

        PHY_TRACE_EVENT (ACCESS_BACKOFF_START,
                         "access backoff start date=%x cap=%u", TIMESTAMP),
        PHY_TRACE_EVENT (ACCESS_BACKOFF_UPDATE,
                         "access backoff update cap=%u"),
        PHY_TRACE_EVENT (ACCESS_BACKOFF_PRP_WON,
                         "access backoff prp won %C"),
        PHY_TRACE_EVENT (ACCESS_TIMER_PROGRAM,
                         "access timer program date=%x"),
        PHY_TRACE_EVENT (ACCESS_TIMER_UPDATE,
                         "access timer update date=%x"),
        PHY_TRACE_EVENT (ACCESS_TIMER_CANCEL, "access timer cancel"),
        PHY_TRACE_EVENT (ACCESS_CB, "access cb eff=%x", TIMESTAMP),

        PHY_TRACE_EVENT (PBDMA_START, "pbdma start bypass_aes=%b "
                         "nb_total=%u nb_ready=%u nb_pb_it=%u chandata=%b "
                         "now=%b", TIMESTAMP),
        PHY_TRACE_EVENT (PBDMA_UPDATE, "pbdma update nb_ready=%u "
                         "nb_pb_it=%u"),
        PHY_TRACE_EVENT (PBDMA_START_CHANDATA,
                         "pbdma start chandata"),
        PHY_TRACE_EVENT (PBDMA_CB, "pbdma cb %x", TIMESTAMP),
        PHY_TRACE_EVENT (PBDMA_ERROR, "pbdma error %x", TIMESTAMP),
    };
    dbg_assert (ctx);
    trace_namespace_init (&namespace, event_ids, COUNT (event_ids));
    trace_namespace_register_format (&namespace, 'C', phy_trace_format_csma);
    trace_namespace_register_format (&namespace, 'P',
                                     phy_trace_format_combo_params);
    trace_buffer_add (&ctx->trace, "phy", 8, 16, true, &namespace);
}

void
phy_trace_uninit (phy_t *ctx)
{
    dbg_assert (ctx);
    trace_buffer_remove (&ctx->trace);
}