summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/maximus/src/maximus_tmdma.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/phy/maximus/src/maximus_tmdma.c')
-rw-r--r--cesar/hal/phy/maximus/src/maximus_tmdma.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/cesar/hal/phy/maximus/src/maximus_tmdma.c b/cesar/hal/phy/maximus/src/maximus_tmdma.c
new file mode 100644
index 0000000000..af9677b543
--- /dev/null
+++ b/cesar/hal/phy/maximus/src/maximus_tmdma.c
@@ -0,0 +1,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);
+ }
+}
+