summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/maximus/src/maximus_pbdma.c
blob: 0da9e496e3dec44dbf6498e7c12a88fad078b0ab (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
161
162
163
164
165
166
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/maximus/src/maximus_pbdma.c
 * \brief   HAL Phy PB DMA functions for Maximus.
 * \ingroup hal_phy_maximus
 */

#include "common/std.h"
#include "hal/phy/maximus/inc/maximus_phy_ctx.h"
#include "mac/common/defs.h" // for 'MAC_MAX_PB_PER_MPDU'
#include <errno.h>


/**
 * set errno to:
 * - EINVAL if ctx or first_pb are null,
 * or if arguments are out-of-range or incoherent
 */
void
phy_pbdma_start (phy_t *ctx, bool bypass_aes, const u32 nek[4], uint nb_total,
                 uint nb_ready, uint nb_pb_it, phy_pb_t *first_pb,
                 phy_chandata_t *first_chandata, bool now)
{
    dbg_assert_ptr(ctx);
    dbg_assert(MAC_MAX_PB_PER_MPDU >= nb_total);
    dbg_assert(nb_total >= nb_ready);
    dbg_assert(nb_total >= nb_pb_it);
    dbg_assert_ptr(first_pb);
    if (first_chandata)
    {
        dbg_assert_ptr(first_chandata);
        dbg_assert((PHY_CHANDATA_TYPE_NO_MEMORY_READ < first_chandata->conf.type) && (PHY_CHANDATA_TYPE_NRJ_SYMBOL >= first_chandata->conf.type));
    }
    MAXIMUS_PHY_TRACE (PBDMA_START, my_station.current_tick_tck, bypass_aes,
                       nb_total, nb_ready, nb_pb_it,
                       first_chandata ? true : false, now);
    if ((NULL == ctx)
        || (MAC_MAX_PB_PER_MPDU < nb_total)
        || (nb_total < nb_ready)
        || (nb_total < nb_pb_it)
        || (NULL == first_pb))
    {
        errno = EINVAL;
        station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                    "%s: errno = %d", __FUNCTION__, errno);
    }
    else
    {
        ctx->pbdma.bypass_aes = bypass_aes;
        if (!bypass_aes)
        {
          memcpy(ctx->pbdma.nek, nek, 4*sizeof(u32));
        }
        else
        {
          memset(ctx->pbdma.nek, '\0', 4*sizeof(u32));
        }
        ctx->pbdma.nb_total = nb_total;
        ctx->pbdma.nb_ready = nb_ready;
        ctx->pbdma.nb_pb_it = nb_pb_it;
        ctx->pbdma.first_pb = first_pb;
        ctx->pbdma.first_chandata = first_chandata;
        ctx->pbdma.chandata_transfer = first_chandata ? true : false;
        // reset current PB descriptor in case of Rx
        ctx->pbdma.current_pb = &ctx->pbdma.first_pb->pb_rx;
    }    
}


/**
 * set errno to:
 * - EINVAL if ctx is null, or if arguments are incoherent
 */
void
phy_pbdma_update (phy_t *ctx, uint nb_ready, uint nb_pb_it)
{
    dbg_assert_ptr(ctx);
    dbg_assert(nb_ready >= ctx->pbdma.nb_ready);
    dbg_assert(nb_pb_it <= ctx->pbdma.nb_total);
    dbg_assert(nb_ready <= ctx->pbdma.nb_total);
    MAXIMUS_PHY_TRACE (PBDMA_UPDATE, nb_ready, nb_pb_it);
    if ((NULL == ctx)
        || (nb_ready < ctx->pbdma.nb_ready)
        || (nb_pb_it > ctx->pbdma.nb_total)
        || (nb_ready > ctx->pbdma.nb_total))
    {
        errno = EINVAL;
        station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                    "%s: errno = %d", __FUNCTION__, errno);
    }
    else
    {
        ctx->pbdma.nb_ready = nb_ready;
        ctx->pbdma.nb_pb_it = nb_pb_it;
    }
}


/**
 * set errno to: 
 * - EINVAL if ctx is null
 */
phy_pb_t *
phy_pbdma_get_tail (phy_t *ctx)
{
    phy_pb_t * tail = NULL;
    
    dbg_assert_ptr(ctx);
    if (NULL == ctx)
    {
        errno = EINVAL;
        station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                    "%s: errno = %d", __FUNCTION__, errno);
    }
    else
    {
        // PHY context current PB points to the last valid received PB
        tail = PARENT_OF(phy_pb_t, pb_rx, ctx->pbdma.current_pb);
    }
    
    return tail;
}


/**
 * set errno to:
 * - EINVAL if ctx or first_chandata are null,
 * or if first_chandata->type equals 0
 */
void
phy_pbdma_start_chandata (phy_t *ctx, phy_chandata_t *first_chandata)
{
    dbg_assert_ptr(ctx);
    dbg_assert_ptr(first_chandata);
    dbg_assert((PHY_CHANDATA_TYPE_NO_MEMORY_READ < first_chandata->conf.type) && (PHY_CHANDATA_TYPE_NRJ_SYMBOL >= first_chandata->conf.type));
    MAXIMUS_PHY_TRACE (PBDMA_START_CHANDATA);
    if ((NULL == ctx)
        || (NULL == first_chandata)
        || (PHY_CHANDATA_TYPE_NO_MEMORY_READ >= first_chandata->conf.type) || (PHY_CHANDATA_TYPE_NRJ_SYMBOL < first_chandata->conf.type))
    {
        errno = EINVAL;
        station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                    "%s: errno = %d", __FUNCTION__, errno);
    }
    else
    {
        ctx->pbdma.first_chandata = first_chandata;

        // set chandata transfer
        ctx->pbdma.chandata_transfer = true;
    }
}


volatile const u32 *
phy_pbdma_get_crc_bitmap (phy_t *ctx)
{
    return ctx->pbdma.crc_bitmap;
}