summaryrefslogtreecommitdiff
path: root/hal/phy/maximus/src/maximus_tmdma.c
blob: af9677b54342a8b92be4c498b2e38c98c3114aa4 (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/maximus/src/maximus_tmdma.c
 * \brief   HAL Phy Tone Map DMA functions for Maximus.
 * \ingroup hal_phy_maximus
 */

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

/**
 * Set the tone mask and its related parameters.
 * \param  ctx  phy context
 * \param  tonemask  tonemask block descriptor
 * \param  carrier_nb  number of active carriers in the given tone mask
 * set errno to:
 * - EINVAL if ctx or tonemask are null
 *
 * This also set ROBO modes parameters, HP1.0 mask and other tone mask related
 * registers.
 */
void
phy_set_tonemask (phy_t *ctx, u8 *tonemask, uint carrier_nb)
{
    /* Set the carrier_nb value of PHY context.
     * Copy tonemask contents into PHY context. */

    dbg_assert_ptr(ctx);
    dbg_assert_ptr(tonemask);
    if ((NULL == ctx)
        || (NULL == tonemask))
    {
        errno = EINVAL;
        station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                    "%s: errno = %d", __FUNCTION__, errno);
    }
    else
    {
        MAXIMUS_PHY_TRACE (SET_TONEMASK, carrier_nb);

        // set number of carriers
        ctx->tmdma.carrier_nb = carrier_nb;

        // copy tonemask (1 bit per carrier)
        memcpy(ctx->tmdma.tonemask, tonemask, (PHY_CARRIER_NB+7)/8);
        
        /* Send carrier_nb and tonemask to Maximus. */
        if (0 != maximus_phy_send_tonemask(ctx))
        {
            station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                        "%s: errno = %d", __FUNCTION__, errno);
            dbg_assert_print(false, "errno = %d because TONEMASK message has not been correctly sent", errno);
        }
    }
}


/**
 * Transfer tone map to hardware using the TM DMA.
 * \param  ctx  phy context
 * \param  tonemap_index  tonemap index where to store tonemap
 * \param  tonemap  tonemap blocks first descriptor
 * set errno to:
 * - EINVAL if ctx or tonemap are null, or if arguments are out-of-range or incorrect
 *
 * The tonemap uses two blocks.
 */
void
phy_set_tonemap (phy_t *ctx, uint tonemap_index, blk_t *tonemap)
{
    /* Set the tonemap_index value of PHY context.
     * Copy tonemap contents into PHY context. */

    dbg_assert_ptr(ctx);
    dbg_assert(TONEMAP_INDEX_NB > tonemap_index);
    dbg_assert_ptr(tonemap);
    dbg_assert_ptr(tonemap->next);
    dbg_assert_ptr(tonemap->data);
    dbg_assert(NULL == tonemap->next->next);
    dbg_assert_ptr(tonemap->next->data);
    if ((NULL == ctx)
        || (TONEMAP_INDEX_NB <= tonemap_index)
        || (NULL == tonemap)
        || (NULL == tonemap->next) // tonemap uses two blocks
        || (NULL == tonemap->data)
        || (NULL != tonemap->next->next) // tonemap uses two blocks
        || (NULL == tonemap->next->data))
    {
        errno = EINVAL;
        station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
                    "%s: errno = %d", __FUNCTION__, errno);
    }
    else
    {
        MAXIMUS_PHY_TRACE (SET_TONEMAP, tonemap_index, tonemap);

        // copy tonemap
        memcpy(ctx->tmdma.tonemap[tonemap_index]->data, tonemap->data, MAC_PB520_BYTES);
        memcpy(ctx->tmdma.tonemap[tonemap_index]->next->data, tonemap->next->data, (PHY_CARRIER_NB+1)/2-MAC_PB520_BYTES);
    }
}