summaryrefslogtreecommitdiff
path: root/hal/phy/maximus/src/maximus_tmdma.c
blob: 1d610ffbaf3f5025ab0c22818cdedb456ec973bd (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
/* 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 <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
 *
 * 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;
    }
    else
    {
        // set number of carriers
        ctx->tm_dma.carrier_nb = carrier_nb;
        
        // copy tonemask (1 bit per carrier)
        memcpy(ctx->tm_dma.tonemask, tonemask, carrier_nb/8);
    }
}


/**
 * 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
 *
 * 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(PHY_TONEMAP_MAX_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)
        || (PHY_TONEMAP_MAX_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;
    }
    else
    {
        if (PHY_MOD_TM == ctx->tm_dma.mod) // else tonemap is not used
        {
            // set tonemap index used for next Tx
            ctx->tm_dma.tonemap_index = tonemap_index;
            
            // copy tonemap
            memcpy(ctx->tm_dma.tonemap[tonemap_index]->data, tonemap->data, PHY_PB_MAX_SIZE);
            memcpy(ctx->tm_dma.tonemap[tonemap_index]->next->data, tonemap->next->data, ctx->tm_dma.carrier_nb/2-PHY_PB_MAX_SIZE);
        }
    }
}