summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/maximus/src/maximus_tmdma.c
blob: 237f3940b0c56a88c255ebcad87be04a9eb87d53 (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
/* 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 errno to:
 * - EINVAL if ctx or tonemask are null
 */
void
phy_set_tonemask (phy_t *ctx, u32 *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);
        }
    }
}


/**
 * set errno to:
 * - EINVAL if ctx or tonemap are null,
 * or if arguments are out-of-range or incorrect
 */
void
phy_set_tonemap (phy_t *ctx, blk_t *tonemap)
{
    uint tonemap_index = 0;
    /* 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);
    }
}