summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c
blob: 3fb731e0ff0effa42e1c7efb47bbede9b1fbe4b9 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bridgedma-init-test.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include <cyg/kernel/kapi.h>
#include <cyg/hal/hal_arch.h>

#include "common/std.h"
#include "common/defs/ethernet.h"

#include "lib/test.h"
#include "lib/list.h"
#include "lib/read_word.h"
#include "lib/bitstream.h"

#include "hal/phy/inc/bridgedma.h"
#include "hal/phy/inc/bridgedma_proto.h"

#include "mac/common/pb.h"

#include <string.h>
#include <stdio.h>
#include <cyg/infra/diag.h>

#define START_OFFSET 128

cyg_thread  my_test_thread;
cyg_handle_t my_test_thread_handle;
u8 my_test_thread_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];

phy_bridgedma_t *bridgedma_ctx;
phy_bridgedma_job_t job1;

/* WARNING: callback are not possible to test inside UNIT TEST */
bool _bridgedma_cb(void *data, u32 status)
{
}

/* WARNING: callback are not possible to test inside UNIT TEST */
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_cb, _bridgedma_deffered_cb);
        test_fail_unless(
            (bridgedma_ctx != NULL)
            && (bridgedma_ctx->job_first == NULL)
            && (bridgedma_ctx->job_current == NULL)
            && (bridgedma_ctx->job_last == NULL)            
            && (bridgedma_ctx->user_data == &user_data)
            && (bridgedma_ctx->bridgedma_cb == _bridgedma_cb)
            && (bridgedma_ctx->deferred_cb == _bridgedma_deffered_cb)
            && !bridgedma_ctx->status.running
            && bridgedma_ctx->status.stop
        );
    } test_end;
    return;
}

void
bridgedma_crc_test_case (test_t test)
{
    crc_t crc_ctx;
    unsigned long crc_current;

    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);

    memset(&job1, '\0', sizeof(job1));
    job1.next = NULL;
    job1.data_addr = frame_buffer;
    job1.header_len = 6;
    job1.data_len = MAC_FRAME_MAX_LEN;
    job1.first_pb_desc = pb_first;
    job1.first_pb_offset = START_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 */
    job1.mf_header1 = (((job1.data_len + 4 - 1) << 2) | 0x02);
    job1.mf_header2 = 0x0;


    phy_bridgedma_start(bridgedma_ctx, &job1, &job1);
}

void
test_thread_process (cyg_addrword_t data)
{
    test_t *test;

    test = (test_t *) data;
    
    bridgedma_init_test_case (*test);
    bridgedma_crc_test_case (*test);

    phy_bridgedma_uninit (bridgedma_ctx);

    test_result (*test);

#ifndef __sparc__
    HAL_PLATFORM_EXIT (test_nb_failed (*test) == 0 ? 0 : 1);
#endif
}

int
main (void)
{
    test_t test;

    test_init (test, 0, NULL);

    // 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;
}