summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest/src/test_tx_rx.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/stationtest/src/test_tx_rx.c')
-rw-r--r--cesar/maximus/stationtest/src/test_tx_rx.c339
1 files changed, 339 insertions, 0 deletions
diff --git a/cesar/maximus/stationtest/src/test_tx_rx.c b/cesar/maximus/stationtest/src/test_tx_rx.c
new file mode 100644
index 0000000000..ddd3661f87
--- /dev/null
+++ b/cesar/maximus/stationtest/src/test_tx_rx.c
@@ -0,0 +1,339 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test_tx_rx.c
+ * \brief station executable used for the test tx rx program
+ * \ingroup
+ */
+
+#include <cyg/infra/diag.h>
+#include <cyg/kernel/kapi.h>
+#include <errno.h>
+#include "common/std.h"
+#include "host/station.h"
+#include "hal/phy/phy.h"
+#include "mac/common/defs.h"
+#include "hal/phy/maximus/inc/maximus_phy_ctx.h" // for 'phy_t'
+#include "hal/phy/maximus/inc/maximus_interrupts.h" // for 'PHY_HAL_INTERRUPT_...'
+
+extern station_ctx_t my_station;
+phy_t * ctx;
+int user_data = 123;
+
+unsigned short fc_mode = 0;
+bool short_ppdu = false;
+unsigned short mod = 0;
+unsigned short fecrate = 0;
+unsigned short pb_size = 0;
+unsigned short gil = 0;
+unsigned short pb_nb = 0;
+
+// For noise
+phy_chandata_t freq_chan[6];
+phy_chandata_t time_chan;
+u8 freq_chan_data[6][MAC_PB520_BYTES];
+u8 time_chan_data[MAC_PB520_BYTES];
+
+
+void start_pbdma (void)
+{
+ diag_write_string("=> start_pbdma\n");
+
+ int i = 0;
+ char c = 0;
+
+ static u32 iv[3];
+ static u32 nek[4];
+
+ // Test with maximum 10 PBs of 512 octets
+ int pb_length = MAC_MAX_PB_PER_MPDU;
+ static u8 pb_data[MAC_MAX_PB_PER_MPDU][MAC_PB520_BYTES];
+ static phy_pb_t pb[MAC_MAX_PB_PER_MPDU];
+
+ // Start PBDMA
+ for (i=0; i<pb_length; i++)
+ {
+ memset(&pb_data[i][0], c, MAC_PB520_BYTES);
+ pb[i].pb_rx.blk.data = &pb_data[i][0];
+ if (i != pb_length-1)
+ {
+ pb[i].pb_rx.blk.next = &pb[i+1].pb_rx.blk;
+ }
+ else
+ {
+ pb[i].pb_rx.blk.next = NULL;
+ }
+ c++;
+ }
+ for (i=0; i<3; i++)
+ {
+ iv[i] = i;
+ }
+ for (i=0; i<4; i++)
+ {
+ nek[i] = i;
+ }
+ phy_pbdma_start(ctx, true /* bypass_aes */, iv,
+ nek, (uint)pb_nb /* nb_total */, (uint)pb_nb /* nb_ready */,
+ (uint)pb_nb /* nb_pb_it */, &pb[0]);
+}
+
+
+void start_pbdma_chandata (void)
+{
+ diag_write_string("=> start_pbdma_chandata\n");
+
+ int i = 0;
+ char c = 0;
+
+ // For noise
+ int transfer_size = 128;
+ int chan_length = ((PHY_CARRIER_NB * sizeof(u16)) + ((4 * transfer_size) - 1 )) / (4 * transfer_size);
+
+ // Time noise
+ memset(time_chan_data, c, MAC_PB520_BYTES);
+ time_chan.blk.data = time_chan_data;
+ time_chan.blk.next = &freq_chan[0].blk;
+ time_chan.size = transfer_size;
+ time_chan.last = 0;
+ time_chan.type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
+ time_chan.address = 0;
+
+ // Frequency noise
+ for (i=0; i<chan_length; i++)
+ {
+ memset(&freq_chan_data[i][0], c, MAC_PB520_BYTES);
+ freq_chan[i].blk.data = &freq_chan_data[i][0];
+ if (i != chan_length-1)
+ {
+ freq_chan[i].blk.next = &freq_chan[i+1].blk;
+ freq_chan[i].last = 0;
+ }
+ else
+ {
+ freq_chan[i].blk.next = NULL;
+ freq_chan[i].last = 1;
+ }
+ freq_chan[i].size = transfer_size;
+ freq_chan[i].type = PHY_CHANDATA_TYPE_NRJ;
+ freq_chan[i].address = 0;
+ c++;
+ }
+
+ phy_pbdma_start_chandata(ctx, &time_chan);
+}
+
+
+bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av)
+{
+ diag_write_string("=> phy_rx_fc_cb\n");
+
+ // Reset IT
+ maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);
+
+ // When the FC is received, prepare RX
+ phy_rx_prepare(ctx, short_ppdu, (phy_mod_t)mod,
+ (phy_fecrate_t)fecrate, (phy_pb_size_t)pb_size, (phy_gil_t)gil,
+ 0 /* tonemap_index */, 0 /* symbol_nb */);
+
+ return true;
+}
+
+
+bool phy_access_cb (void *user)
+{
+ diag_write_string("=> phy_access_cb\n");
+
+ // Reset IT
+ maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);
+
+ return true;
+}
+
+
+bool phy_access_conf_cb (void *user)
+{
+ diag_write_string("=> phy_access_conf_cb\n");
+
+ // Reset IT
+ maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);
+
+ return true;
+}
+
+
+bool phy_pbdma_cb (void *user, u32 status_word)
+{
+ diag_write_string("=> phy_pbdma_cb\n");
+
+ // Reset IT
+ maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PBDMA);
+
+ phy_pbdma_status_t status = *((phy_pbdma_status_t*)&status_word);
+ if (status.end_rx_pb)
+ {
+ // Set TX parameters
+ phy_tx_param (ctx, ctx->control.rx_param.fc_mode, ctx->control.rx_param.short_ppdu,
+ ctx->control.rx_param.mod, ctx->control.rx_param.fecrate, ctx->control.rx_param.pb_size,
+ ctx->control.rx_param.gil, ctx->control.rx_param.tonemap_index);
+ if (0 != ctx->control.rx_param.fc_10)
+ {
+ phy_tx_fc10 (ctx, ctx->control.rx_param.fc_10);
+ }
+
+ if (!ctx->control.rx_param.short_ppdu)
+ {
+ // Start PBDMA
+ phy_pbdma_start(ctx, ctx->pbdma.bypass_aes, ctx->pbdma.iv,
+ ctx->pbdma.nek, (uint)pb_nb /* nb_total */, (uint)pb_nb /* nb_ready */,
+ (uint)pb_nb /* nb_pb_it */, ctx->pbdma.first_pb);
+ }
+
+ phy_tx_frame (ctx, (u32)my_station.current_tick_tck + PHY_FC_10_PREPARATION_DELAY_TCK,
+ false /* want_conf */, false /* stop_tx_on_prp_lost */, ctx->control.rx_param.fc_av);
+ }
+
+ return true;
+}
+
+
+bool phy_tx_false_alarm_cb (void *user)
+{
+ diag_write_string("=> phy_tx_false_alarm_cb\n");
+
+ // Reset IT
+ maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);
+
+ return true;
+}
+
+
+void phy_deferred_cb (void *user)
+{
+ diag_write_string("=> phy_deferred_cb\n");
+
+ return;
+}
+
+
+bool phy_extra_timer_cb (void *user)
+{
+ diag_write_string("=> phy_extra_timer_cb\n");
+
+ // Reset IT
+ maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);
+
+ return true;
+}
+
+
+int set_tonemask (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
+{
+ u8 tonemask[(PHY_CARRIER_NB+7)/8];
+ blk_t tonemap1;
+ blk_t tonemap2;
+ u8 tonemap1_data[MAC_PB520_BYTES];
+ u8 tonemap2_data[(PHY_CARRIER_NB+1)/2-MAC_PB520_BYTES];
+ int i = 0;
+
+ diag_write_string("=> set_tonemask\n");
+
+ // Initialize the HAL PHY
+ ctx = phy_init ((void *)&user_data, &phy_rx_fc_cb, &phy_access_cb, &phy_access_conf_cb, &phy_pbdma_cb, &phy_tx_false_alarm_cb, &phy_deferred_cb);
+
+ // Enable assertions on warnings
+ ctx->warning_assert = true;
+
+ // Set TONEMASK
+ for (i=0; i<(PHY_CARRIER_NB+7)/8; i++)
+ {
+ tonemask[i] = 0xEE;
+ }
+ phy_set_tonemask(ctx, tonemask, PHY_CARRIER_NB);
+
+ // Set TONEMAP
+ memset(tonemap1_data, 'b', MAC_PB520_BYTES*sizeof(u8));
+ memset(tonemap2_data, 'c', ((PHY_CARRIER_NB+1)/2-MAC_PB520_BYTES)*sizeof(u8));
+ tonemap2.next = NULL;
+ tonemap2.data = tonemap2_data;
+ tonemap1.next = &tonemap2;
+ tonemap1.data = tonemap1_data;
+ phy_set_tonemap(ctx, 0 /* tonemap_index */, &tonemap1);
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+
+int prepare_rx (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
+{
+ diag_write_string("=> prepare_rx\n");
+
+ /* get parameters content */
+ fcall_param_bind_short(*param, *msg, "fc_mode", &fc_mode);
+ fcall_param_bind(*param, *msg, "short_ppdu", sizeof(bool), &short_ppdu);
+ if (!short_ppdu)
+ {
+ fcall_param_bind_short(*param, *msg, "mod", &mod);
+ fcall_param_bind_short(*param, *msg, "fecrate", &fecrate);
+ fcall_param_bind_short(*param, *msg, "pb_size", &pb_size);
+ fcall_param_bind_short(*param, *msg, "gil", &gil);
+ fcall_param_bind_short(*param, *msg, "pb_nb", &pb_nb);
+ }
+
+ // Activate RX
+ phy_rx_activate(ctx, true /* now */, my_station.current_tick_tck, true /* pre_detection */);
+
+ // Set RX parameters
+ phy_rx_param(ctx, (phy_fc_mode_t)fc_mode);
+
+ if (!short_ppdu)
+ {
+ // Start PBDMA
+ start_pbdma();
+
+ // Start PBDMA chandata
+ start_pbdma_chandata();
+ }
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+
+int uninit_phy (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
+{
+ diag_write_string("=> uninit_phy\n");
+
+ // Uninitialize the HAL PHY
+ phy_uninit (ctx);
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+
+int main (void)
+{
+ station_log_set_level(&my_station, STATION_LOG_DEBUG);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+ my_station.pipe_log_fd = 1;
+
+ fcall_register(my_station.fcall, "set_tonemask", (void*)&set_tonemask, NULL);
+ fcall_register(my_station.fcall, "prepare_rx", (void*)&prepare_rx, NULL);
+ fcall_register(my_station.fcall, "uninit_phy", (void*)&uninit_phy, NULL);
+
+ return 0;
+}
+