summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/hal/phy/src/bridgedma.c1
-rw-r--r--cesar/test_general/hard/bridgedma/Makefile8
-rw-r--r--cesar/test_general/hard/bridgedma/src/bridgedma-tx-one-frame.c313
-rw-r--r--cesar/test_general/hard/bridgedma/src/bridgedma-tx-test.c42
-rw-r--r--cesar/test_general/hard/bridgedma/src/bridgedma.c41
-rw-r--r--cesar/test_general/hard/bridgedma/src/bridgedma_init.c77
6 files changed, 408 insertions, 74 deletions
diff --git a/cesar/hal/phy/src/bridgedma.c b/cesar/hal/phy/src/bridgedma.c
index 7bdda4677e..aa2093024f 100644
--- a/cesar/hal/phy/src/bridgedma.c
+++ b/cesar/hal/phy/src/bridgedma.c
@@ -90,6 +90,7 @@ phy_bridgedma_init (void *user_data, phy_bridgedma_cb_t bridgedma_cb,
phy_bridgedma_global.user_data = user_data;
phy_bridgedma_global.bridgedma_cb = bridgedma_cb;
phy_bridgedma_global.deferred_cb = deferred_cb;
+ phy_bridgedma_global.status.stop = true;
/* register ISR et DSR to eCos */
cyg_interrupt_create(PHY_BRIDGEDMA_END_INTERRUPT,
diff --git a/cesar/test_general/hard/bridgedma/Makefile b/cesar/test_general/hard/bridgedma/Makefile
index e32bf59db6..799e71150e 100644
--- a/cesar/test_general/hard/bridgedma/Makefile
+++ b/cesar/test_general/hard/bridgedma/Makefile
@@ -3,7 +3,10 @@ BASE = ../../..
ECOS = y
TARGET = sparc
-TARGET_PROGRAMS = bridgedma-it bridgedma-tx
+TARGET_PROGRAMS = bridgedma_init bridgedma-it bridgedma-tx bridgedma_tx_one_frame
+
+bridgedma_init_SOURCES = bridgedma_init.c
+bridgedma_init_MODULES = lib hal/phy
bridgedma-tx_SOURCES = bridgedma-tx-test.c
bridgedma-tx_MODULES = lib hal/phy
@@ -11,6 +14,9 @@ bridgedma-tx_MODULES = lib hal/phy
bridgedma-it_SOURCES = bridgedma-it.c
bridgedma-it_MODULES = lib hal/phy
+bridgedma_tx_one_frame_SOURCES = bridgedma-tx-one-frame.c
+bridgedma_tx_one_frame_MODULES = lib hal/phy
+
include $(BASE)/common/make/top.mk
all: $(TARGET_PROGRAMS:%=obj/%.lst) $(TARGET_PROGRAMS:%=obj/%.hex)
diff --git a/cesar/test_general/hard/bridgedma/src/bridgedma-tx-one-frame.c b/cesar/test_general/hard/bridgedma/src/bridgedma-tx-one-frame.c
new file mode 100644
index 0000000000..5943b7e333
--- /dev/null
+++ b/cesar/test_general/hard/bridgedma/src/bridgedma-tx-one-frame.c
@@ -0,0 +1,313 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bridgedma-tx-one-frame.c
+ * \brief Request the fragmentation of only a Frame.
+ * \ingroup hal_phy
+ *
+ */
+#include "common/std.h"
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/hal/hal_arch.h>
+
+#include "common/defs/ethernet.h"
+
+#include "lib/test.h"
+#include "lib/list.h"
+#include "lib/read_word.h"
+#include "lib/bitstream.h"
+#include "mac/common/pb.h"
+
+#include "hal/phy/inc/bridgedma.h"
+#include "hal/phy/inc/bridgedma_regs.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <cyg/infra/diag.h>
+#include "hal/arch/arch.h"
+
+#define TEST_BRIDGEDMA_PB_NB 5
+#define TEST_BRIDGEDMA_JOB_OFFSET 128
+
+cyg_thread my_test_thread;
+cyg_handle_t my_test_thread_handle;
+u8 my_test_thread_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
+
+static test_t test;
+static uint it_recv = false;
+static phy_bridgedma_job_t job1;
+static u8 frame_buffer [2048];
+static pb_t *pb_first;
+static pb_t *pb_last;
+
+
+void
+bridgedma_verify_registers (void)
+{
+#ifdef __sparc__
+ arch_reorder_barrier ();
+ // Verify the register corresponding to the MF header1.
+ volatile uint *job_header_3210 = (uint *) PHY_BRIDGEDMA_JOB_HEADER_3210;
+ volatile uint *job_header_7654 = (uint *) PHY_BRIDGEDMA_JOB_HEADER_7654;
+
+ volatile uint *control = (uint *) PHY_BRIDGEDMA_CONTROL;
+ volatile uint *job_len = (uint *) PHY_BRIDGEDMA_JOB_LENGTH;
+ arch_reorder_barrier ();
+
+ diag_printf ("JOB HEADER BRIDGEDMA_3210 : %x\n", *job_header_3210);
+ diag_printf ("JOB HEADER BRIDGEDMA_7654 : %x\n", *job_header_7654);
+ diag_printf ("Control : %x\n", *control);
+ diag_printf ("Job length : %x\n", *job_len);
+#endif
+}
+
+
+/* WARNING: callback are not possible to test inside UNIT TEST */
+bool _bridgedma_segmentation_cb(void *data, u32 status)
+{
+ it_recv = true;
+
+ cyg_thread_resume (my_test_thread_handle);
+ return true;
+}
+
+/* WARNING: callback are not possible to test inside UNIT TEST */
+void _bridgedma_deffered_cb(void *data)
+{
+}
+
+void bridgedma_segmentation_test_case(void)
+{
+ uint i;
+ uint ats;
+ pb_t *pb_current;
+ phy_bridgedma_t *bridgedma_ctx;
+
+ test_case_begin(test, "segmentation");
+
+
+ pb_first = (pb_t*) blk_alloc_desc_range(TEST_BRIDGEDMA_PB_NB, (blk_t **) &pb_last);
+ pb_last->next = NULL;
+
+ pb_current = pb_first;
+ for (i = 0; i < TEST_BRIDGEDMA_PB_NB; i++)
+ {
+ pb_current->header.ssn = i;
+ pb_current = pb_current->next;
+ }
+
+ ats = 0x12345678;
+
+ /************************************************************************
+ * simple segmentation with 3 mac frames into 5 PBs
+ * 1st mac frame: len=1518, offset=128, ATS, ICV into 1st to 4th PB
+ * 2nd mac frame: len=64, ATS, ICV into 4th PB
+ * 3nd mac frame: len=466, ATS, ICV, padding into 4th to 5th PB
+ ***********************************************************************/
+
+ memset(&job1, '\0', sizeof(job1));
+ job1.next = NULL;
+ job1.data_addr = frame_buffer;
+ job1.header_len = 6;
+ job1.data_len = ETH_PACKET_MAX_SIZE;
+ job1.first_pb_desc = (blk_t *)pb_first;
+ job1.first_pb_offset = TEST_BRIDGEDMA_JOB_OFFSET;
+ job1.segment_len = 512;
+ job1.direction = 0;
+ job1.crc_reset = 1;
+ job1.crc_store = 1;
+ job1.job_it = 1;
+ job1.eth_buffer_mask = 0x1fffff0; /* 2048 bytes mask */
+ /* Payload + ATS */
+ job1.mf_header1 = (((job1.data_len + 4 - 1) << 2) | 0x02) | (ats << 16);
+ job1.mf_header2 = (ats >> 16);
+
+ bridgedma_ctx = phy_bridgedma_init(NULL, _bridgedma_segmentation_cb,
+ _bridgedma_deffered_cb);
+
+ cyg_thread_delay (1);
+
+ phy_bridgedma_start (bridgedma_ctx, &job1, &job1);
+}
+
+void
+bridgedma_verify_it_reception (void)
+{
+ diag_printf ("Interruption received : %d\n", it_recv);
+}
+
+void
+bridgedma_segmentation_verify_test_case (void)
+{
+ uint payload_cnt;
+ pb_t *pb_current;
+ phy_bridgedma_job_t *job_current;
+
+ uint i;
+ uint length;
+ uint pb_offset;
+ uint qte_pb;
+ uint frame_offset;
+ bool cont;
+
+
+ test_begin(test, "segmentation of a frame")
+ {
+ for (i = 0, pb_current = pb_first; pb_current; pb_current =
+ pb_current->next, i++)
+ {
+ test_fail_if (pb_current->header.ssn != i, "Wong sequence");
+ }
+
+ diag_printf ("length job1 in PB : %x\n", read_u32_from_word
+ (((pb_t *)job1.first_pb_desc)->data + 128));
+
+ /* check pb content */
+ /* check 1st mac frame into PB */
+ payload_cnt = 0;
+
+ pb_offset = TEST_BRIDGEDMA_JOB_OFFSET;
+ job_current = &job1;
+ frame_offset = 0;
+ for (pb_current = pb_first, i = 0; i < 3; i++, job_current =
+ job_current->next)
+ {
+ cont = true;
+ length = 1 + (read_u16_from_word (pb_current->data + pb_offset) >> 2);
+
+ // To get the payload length, the frame length is 10
+ // bytes greater.
+ length -= 4;
+
+ diag_printf ("Length read in pb : %d\n", length);
+ diag_printf ("Length read in pb : %x\n", length);
+ diag_printf ("pb ssn : %d\n", ((pb_t *)pb_current)->header.ssn);
+ diag_printf ("pb offset : %d\n", pb_offset);
+ test_fail_unless (length == job_current->data_len,
+ "Data length is wrong.");
+
+ // Copy the data of the current pb.
+
+ // Jump directly to the start of the payload.
+ pb_offset += 6;
+ if (length + pb_offset > BLK_SIZE)
+ {
+ test_fail_unless (
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data + pb_offset,
+ BLK_SIZE - pb_offset),
+ "data corrupted");
+
+ frame_offset += BLK_SIZE - pb_offset;
+ length -= BLK_SIZE - pb_offset;
+ }
+ else
+ {
+ test_fail_unless (
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data + pb_offset,
+ length),
+ "data corrupted");
+
+ frame_offset += length;
+ cont = false;
+ }
+
+
+ if (cont)
+ {
+ // Add 10 to the length to use the complete MF length
+ // (ATS + MFH + ICV), the ATS and MFH are already include in the
+ // pb_offset.
+ for (qte_pb = (pb_offset + length + 4) / BLK_SIZE + 1;
+ qte_pb;
+ qte_pb --)
+ {
+ pb_current = pb_current->next;
+
+ if (length > BLK_SIZE)
+ {
+ test_fail_unless(
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data ,
+ BLK_SIZE),
+ "data corrupted");
+
+ length -= BLK_SIZE;
+ frame_offset += BLK_SIZE;
+ }
+ else
+ {
+ test_fail_unless(
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data ,
+ length),
+ "data corrupted");
+
+ frame_offset += length;
+ }
+ }
+ }
+
+ // The futur offset is length + 4 cause of the ICV of the MF.
+ // The ATS and the MFH has already been jumped above in the
+ // pb_offset.
+ pb_offset = (pb_offset + job_current->data_len + 4) % BLK_SIZE;
+ }
+ } test_end;
+
+ blk_release_desc_range((blk_t *)pb_first, (blk_t *) pb_last);
+}
+
+
+void
+test_thread_process (cyg_addrword_t data)
+{
+ bridgedma_segmentation_test_case ();
+ bridgedma_verify_registers ();
+ if (it_recv == false)
+ {
+ diag_printf ("gonna sleep\n");
+ cyg_thread_suspend (my_test_thread_handle);
+ }
+ bridgedma_verify_it_reception ();
+
+ bridgedma_segmentation_verify_test_case ();
+
+ diag_printf ("Test ENDED\n");
+ test_result (test);
+#ifndef __sparc__
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+#endif
+}
+
+int
+main (void)
+{
+ test_t test;
+ uint i;
+
+ test_init (test, 0, NULL);
+
+ for (i = 0; i < 2048; i++)
+ frame_buffer[i] = i;
+
+ // Create the thread.
+ cyg_thread_create( 9,
+ &test_thread_process,
+ (cyg_addrword_t) &test,
+ "TEST_THREAD",
+ my_test_thread_stack,
+ CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &my_test_thread_handle,
+ &my_test_thread);
+ cyg_thread_resume (my_test_thread_handle);
+
+ return 0;
+}
diff --git a/cesar/test_general/hard/bridgedma/src/bridgedma-tx-test.c b/cesar/test_general/hard/bridgedma/src/bridgedma-tx-test.c
index e94e58c3d9..4a66214a09 100644
--- a/cesar/test_general/hard/bridgedma/src/bridgedma-tx-test.c
+++ b/cesar/test_general/hard/bridgedma/src/bridgedma-tx-test.c
@@ -44,7 +44,7 @@ phy_bridgedma_job_t *job_current;
phy_bridgedma_job_t job1, job2, job3;
phy_bridgedma_t *bridgedma_ctx;
-u8 frame_buffer [2048] __attribute__((aligned(2048)));
+u8 frame_buffer [2048];
crc_t crc_ctx;
blk_t *pb_first, *pb_last, *pb_current;
u32 mf_header;
@@ -82,32 +82,6 @@ void _bridgedma_deffered_cb(void *data)
{
}
-void bridgedma_init_test_case(test_t t)
-{
- int user_data;
-
- test_case_begin(t, "init");
-
- test_begin(t, "init")
- {
- bridgedma_ctx = NULL;
- bridgedma_ctx = phy_bridgedma_init(&user_data, _bridgedma_segmentation_cb, _bridgedma_deffered_cb);
-
-
- test_fail_if (bridgedma_ctx == NULL);
- test_fail_if (bridgedma_ctx->job_first != NULL);
- test_fail_if (bridgedma_ctx->job_current != NULL);
- test_fail_if (bridgedma_ctx->job_last != NULL);
- test_fail_if (bridgedma_ctx->user_data != &user_data);
- test_fail_if (bridgedma_ctx->bridgedma_cb != _bridgedma_segmentation_cb);
- test_fail_if (bridgedma_ctx->deferred_cb != _bridgedma_deffered_cb);
- test_fail_if (bridgedma_ctx->status.running);
- test_fail_if (bridgedma_ctx->status.stop != false);
- }
- test_end;
- return;
-}
-
void bridgedma_segmentation_test_case(test_t t)
{
uint i;
@@ -206,6 +180,7 @@ void bridgedma_segmentation_test_case(test_t t)
void
bridgedma_verify_registers (void)
{
+#ifndef __sparc__
// Verify the register corresponding to the MF header1.
volatile uint *job_header_3210 = (uint *) PHY_BRIDGEDMA_JOB_HEADER_3210;
volatile uint *job_header_7654 = (uint *) PHY_BRIDGEDMA_JOB_HEADER_7654;
@@ -217,6 +192,7 @@ bridgedma_verify_registers (void)
diag_printf ("JOB HEADER BRIDGEDMA_7654 : %x\n", *job_header_7654);
diag_printf ("Control : %x\n", *control);
diag_printf ("Job length : %x\n", *job_len);
+#endif
}
void
@@ -350,19 +326,21 @@ test_thread_process (cyg_addrword_t data)
test = (test_t *) data;
- bridgedma_init_test_case (*test);
-
bridgedma_segmentation_test_case (*test);
/* Just to test. */
diag_printf ("Job 1 header : %x\n", job1.mf_header1);
- //diag_printf ("Job 2 header : %x\n", job2.mf_header1);
- //diag_printf ("Job 3 header : %x\n", job3.mf_header1);
+ diag_printf ("Job 2 header : %x\n", job2.mf_header1);
+ diag_printf ("Job 3 header : %x\n", job3.mf_header1);
diag_printf ("The test thread is now sleeping until the bridgedma ends");
- cyg_thread_suspend (my_test_thread_handle);
+ while (job_current != NULL)
+ {
+ cyg_thread_suspend (my_test_thread_handle);
+ }
+
/* */
bridgedma_verify_registers ();
diff --git a/cesar/test_general/hard/bridgedma/src/bridgedma.c b/cesar/test_general/hard/bridgedma/src/bridgedma.c
deleted file mode 100644
index bb1bf5a9f9..0000000000
--- a/cesar/test_general/hard/bridgedma/src/bridgedma.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file src/bridgedma.c
- * \brief « brief description »
- * \ingroup « module »
- *
- * « long description »
- */
-#include "common/std.h"
-#include "lib/test.h"
-
-#include "hal/phy/bridgedma.h"
-#include "hal/phy/inc/bridgedma.h"
-
-bool
-test_bridgedma (void *user, u32 status_word)
-{
- return true;
-}
-
-void
-test_phy_deffered (void *user)
-{
-}
-
-int
-main (void)
-{
- phy_bridgedma_t *bridge;
-
- bridge = phy_bridgedma_init (NULL, test_bridgedma, test_phy_deffered);
- return 0;
-}
-
-
diff --git a/cesar/test_general/hard/bridgedma/src/bridgedma_init.c b/cesar/test_general/hard/bridgedma/src/bridgedma_init.c
new file mode 100644
index 0000000000..48b695dc7a
--- /dev/null
+++ b/cesar/test_general/hard/bridgedma/src/bridgedma_init.c
@@ -0,0 +1,77 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bridgedma.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/test.h"
+
+#include "hal/phy/bridgedma.h"
+#include "hal/phy/inc/bridgedma.h"
+
+/* WARNING: callback are not possible to test inside UNIT TEST */
+bool
+_bridgedma_isr_cb(void *data, u32 status)
+{
+ return true;
+}
+
+/* WARNING: callback are not possible to test inside UNIT TEST */
+void
+_bridgedma_dsr_cb (void *toto)
+{
+}
+
+void bridgedma_init_test_case(test_t t)
+{
+ phy_bridgedma_t *bridgedma_ctx;
+
+ test_case_begin(t, "init");
+
+ test_begin(t, "init")
+ {
+ bridgedma_ctx = NULL;
+ bridgedma_ctx = phy_bridgedma_init(NULL, _bridgedma_isr_cb,
+ _bridgedma_dsr_cb);
+
+
+ test_fail_if (bridgedma_ctx == NULL);
+ test_fail_if (bridgedma_ctx->job_first != NULL);
+ test_fail_if (bridgedma_ctx->job_current != NULL);
+ test_fail_if (bridgedma_ctx->job_last != NULL);
+ test_fail_if (bridgedma_ctx->user_data != NULL);
+ test_fail_if (bridgedma_ctx->bridgedma_cb != _bridgedma_isr_cb);
+ test_fail_if (bridgedma_ctx->deferred_cb != _bridgedma_dsr_cb);
+ test_fail_if (bridgedma_ctx->status.running != false);
+ test_fail_if (bridgedma_ctx->status.stop != true);
+ }
+ test_end;
+ return;
+}
+
+
+int
+main (void)
+{
+ test_t test;
+
+ test_init (test, 0, NULL);
+
+ bridgedma_init_test_case(test);
+
+ test_result (test);
+
+#ifndef __sparc__
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+#endif
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}