summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/bridgedma/src/bridge.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/bridgedma/src/bridge.c')
-rw-r--r--cesar/mac/sar/bridgedma/src/bridge.c258
1 files changed, 0 insertions, 258 deletions
diff --git a/cesar/mac/sar/bridgedma/src/bridge.c b/cesar/mac/sar/bridgedma/src/bridge.c
deleted file mode 100644
index b0fb30b368..0000000000
--- a/cesar/mac/sar/bridgedma/src/bridge.c
+++ /dev/null
@@ -1,258 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2009 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file cesar/mac/sar/bridgedma/src/bridge.c
- * \brief bridgedma functionalities for unit tests.
- * \ingroup mac_sar
- */
-#include "common/std.h"
-#include "common/defs/homeplugAV.h"
-#include "mac/sar/bridgedma/inc/bridge.h"
-#include "lib/bitstream.h"
-#include "lib/crc.h"
-#include "hal/phy/inc/bridgedma_soft.h"
-
-phy_bridgedma_t *phy_bridgedma_init (void *user_data,
- phy_bridgedma_cb_t bridgedma_cb, phy_deferred_cb_t deferred_cb)
-{
- bridge.deferred_cb = deferred_cb;
- bridge.user_data = user_data;
-
- bridge.head = NULL;
- bridge.tail = NULL;
- bridge.curr = NULL;
-
- pb_list.first = NULL;
- pb_list.last = NULL;
-
- return NULL;
-}
-
-void phy_bridgedma_start (phy_bridgedma_t *ctx,
- phy_bridgedma_job_t *job_first, phy_bridgedma_job_t *job_last)
-{
- if (bridge.head == NULL)
- {
- bridge.head = job_first;
- bridge.tail = job_last;
-
- bridge.curr = job_first;
- }
- else
- {
- bridge.tail->next = job_first;
- bridge.tail = job_last;
- }
-
- job_last->next = NULL;
- bridge_run ();
-}
-
-static void
-phy_bridgedma_change_pb (bitstream_t *stream, void *user_data)
-{
- pb_t **pb = user_data;
- dbg_assert (stream);
- dbg_assert (user_data);
- dbg_assert ((*pb)->next);
- *pb = (*pb)->next;
- bitstream_set_buffer (stream, (*pb)->data, BLK_SIZE);
-}
-
-void bridge_run (void)
-{
- phy_bridgedma_job_t *bridge_job;
-
- while (bridge.curr)
- {
- bridge_job = bridge.curr;
- dbg_assert (bridge_job->first_pb_offset < BLK_SIZE);
-
- /* TX part. */
- if (bridge_job->direction == 0)
- {
- pb_t *current = (pb_t*)bridge_job->first_pb_desc;
- bitstream_t stream;
- uint i;
- /* Store the header of the mac frame in the PB. */
- bitstream_write_init (&stream,
- current->data + bridge_job->first_pb_offset,
- BLK_SIZE - bridge_job->first_pb_offset);
- bitstream_init_buffer_cb (&stream, phy_bridgedma_change_pb,
- &current);
-
- if (bridge_job->header_len == 2)
- bitstream_write (&stream, bridge_job->mf_header1, 16);
- else
- {
- bitstream_write (&stream, bridge_job->mf_header1, 32);
- bitstream_write (&stream, bridge_job->mf_header2, 16);
- }
-
- for (i = 0; i < bridge_job->data_len; i++)
- bitstream_write (&stream, bridge_job->data_addr[i], 8);
-
- /* Compute the CRC and store it. */
- crc_t crc_ctx;
- u32 enc_tab[256];
- u32 crc;
-
- crc_ctx.width = 32;
- crc_ctx.generator = HPAV_CRC32_GENERATOR;
- crc_ctx.init = HPAV_CRC32_INIT;
- crc_ctx.refin = true;
- crc_ctx.refout = true;
- crc_ctx.xorout = 0xffffffff;
- crc_ctx.reg_init = 0;
- crc_ctx.table.t32 = enc_tab;
- crc_init(&crc_ctx);
-
- crc = crc_compute_begin (&crc_ctx);
- crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc,
- bridge_job->data_addr,
- bridge_job->data_len);
- crc = crc_compute_end (&crc_ctx, crc);
- bitstream_write (&stream, crc, 32);
- }
- /* RX part. */
- else
- {
- pb_t *current = (pb_t*)bridge_job->first_pb_desc;
- bitstream_t stream;
- uint i;
- uint header1;
- uint header2 = 0;
- /* Read the data from the PB. */
- bitstream_read_init (&stream,
- current->data,
- BLK_SIZE - bridge_job->first_pb_offset);
- bitstream_init_buffer_cb (&stream, phy_bridgedma_change_pb,
- &current);
-
- if (bridge_job->header_len == 2)
- header1 = bitstream_read (&stream, 16);
- else
- {
- header1 = bitstream_read (&stream, 32);
- header2 = bitstream_read (&stream, 16);
- }
-
- for (i = 0; i < bridge_job->data_len; i++)
- bridge_job->data_addr[i] = bitstream_read (&stream, 8);
-
- /* Compute the CRC and store it. */
- crc_t crc_ctx;
- u32 enc_tab[256];
- u32 crc;
-
- crc_ctx.width = 32;
- crc_ctx.generator = HPAV_CRC32_GENERATOR;
- crc_ctx.init = HPAV_CRC32_INIT;
- crc_ctx.refin = true;
- crc_ctx.refout = true;
- crc_ctx.xorout = 0xffffffff;
- crc_ctx.reg_init = 0;
- crc_ctx.table.t32 = enc_tab;
- crc_init(&crc_ctx);
-
- crc = crc_compute_begin (&crc_ctx);
- crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc,
- bridge_job->data_addr,
- bridge_job->data_len);
- crc = crc_compute_end (&crc_ctx, crc);
- if (crc == bitstream_read (&stream, 32))
- bridge_job->crc_error = 1;
- }
-
- bridge.curr = bridge.head->next;
- if (bridge.head)
- {
- bridge.head = bridge.head->next;
- }
-
- if (bridge_job->job_it)
- (*bridge.deferred_cb) (bridge.user_data);
- }
-}
-
-u16 mix_up_pbs (pb_t **first, pb_t **last)
-{
- pb_t *list[100];
- u16 size;
- pb_t *head;
- pb_t *tmp;
- lib_rnd_t rnd_ctx1;
- lib_rnd_t rnd_ctx2;
- int i;
- u16 slot1;
- u16 slot2;
-
- lib_rnd_init (&rnd_ctx1, 123456);
- lib_rnd_init (&rnd_ctx2, 234567);
-
- //count the quantity of PBs.
- for (size = 0, head = pb_list.first; head != NULL; head = head->next,
- size++)
- {
- list[size] = head;
- }
- list[size] = NULL;
-
- // randomize the list
- for (i = 0; i < size; i++)
- {
- slot1 = lib_rnd32 (&rnd_ctx1) % size;
- slot2 = lib_rnd32 (&rnd_ctx2) % size;
-
- tmp = list[slot1];
- list[slot1] = list[slot2];
- list[slot2] = tmp;
- }
-
- //Chain the PB list
- for (i = 0; i < size - 1; i++)
- {
- list[i]->next = list[i+1];
- }
-
- *first = list[0];
- *last = list[size - 1];
- list[size - 1]->next = NULL;
-
- return size;
-}
-
-/**
- * Reset and uninitialise the Bridge DMA.
- * \param ctx Bridge DMA context
- */
-void
-phy_bridgedma_uninit (phy_bridgedma_t *ctx)
-{
-}
-
-/**
- * Get the current job descriptor from the bridgedma.
- * \param ctx the Bridge DMA context.
- * \return the address of the current job descriptor beeing processed by the
- * bridge DMA.
- *
- * It corresponds to the current job which is being processed by the
- * bridgedma when the Interruption arrived.
- */
-phy_bridgedma_job_t *
-phy_bridgedma_current_job (phy_bridgedma_t *ctx)
-{
- return bridge.head;
-}
-
-bool
-phy_bridgedma_status (phy_bridgedma_t *ctx)
-{
- return false;
-}