summaryrefslogtreecommitdiff
path: root/gdb/JTAG_download.c
blob: d3f0626906ae1ac28087abd98afd7afe6632c3a6 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* Target dependent code for ARC700, for GDB, the GNU debugger.

   Copyright 2008, 2009 Free Software Foundation, Inc.

   Contributed by ARC International (www.arc.com)

   Authors:
      Richard Stuckey <richard.stuckey@arc.com>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

/******************************************************************************/
/*                                                                            */
/* Outline:                                                                   */
/*     This module contains a test driver for the JTAG operations module of   */
/*     the ARC port of gdb.  It measures the speed at which data can be       */
/*     downloaded to the target.                                              */
/*                                                                            */
/* Usage:                                                                     */
/*           <driver>  [ -c ] [ -d ] [ -r <count> ]                           */
/*                                                                            */
/*           where -c specifies target connection & disconnection only        */
/*                 -d switches on JTAG operation debuggging                   */
/*                 -r specifies the JTAG operation retry count                */
/*                                                                            */
/******************************************************************************/

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>

#include "arc-jtag-ops.h"


/* -------------------------------------------------------------------------- */
/*                               local data                                   */
/* -------------------------------------------------------------------------- */

#define MB                       1024 * 1024
#define DATA_AREA                0x00001000
#define DATA_AREA_SIZE           1 * MB


static ARC_Byte data[DATA_AREA_SIZE];


static Boolean test = TRUE;


/* -------------------------------------------------------------------------- */
/*                               externally visible data                      */
/* -------------------------------------------------------------------------- */

/* global debug flag */
Boolean arc_debug_target;


/* -------------------------------------------------------------------------- */
/*                               local functions                              */
/* -------------------------------------------------------------------------- */

static void failed(const char* fmt, ...)
{
    va_list ap;

    printf("*** FAILED: ");
    va_start(ap, fmt);
    vprintf(fmt, ap);
    va_end(ap);
    printf("\n");

//  exit(EXIT_FAILURE);
}


static void run_test(void)
{
    unsigned int   i;
    unsigned int   bytes;
    struct timeval start_time, end_time;
    long long int  time_count;

    for (i = 0; i < DATA_AREA_SIZE; i++)
        data[i] = (ARC_Byte) i;

    gettimeofday (&start_time, NULL);

    bytes = arc_jtag_ops.memory_write_chunk(DATA_AREA, data, DATA_AREA_SIZE);

    gettimeofday (&end_time, NULL);

    if (bytes != DATA_AREA_SIZE)
        failed("memory write: %d", bytes);

    /* Compute the elapsed time in milliseconds, as a tradeoff between
       accuracy and overflow.  */
    time_count =  (end_time.tv_sec  - start_time.tv_sec)  * 1000;
    time_count += (end_time.tv_usec - start_time.tv_usec) / 1000;

    if (time_count > 0)
    {
        unsigned long rate = (bytes * 1000) / time_count;

        printf("0x%x bytes downloaded in %lld milliseconds\n", bytes, time_count);
        printf("transfer rate: %lu bytes/sec\n", rate);
    }


    gettimeofday (&start_time, NULL);

    bytes = arc_jtag_ops.memory_write_pattern(DATA_AREA, 0, DATA_AREA_SIZE);

    gettimeofday (&end_time, NULL);

    if (bytes != DATA_AREA_SIZE)
        failed("memory fill zero: %d", bytes);

    /* Compute the elapsed time in milliseconds, as a tradeoff between
       accuracy and overflow.  */
    time_count =  (end_time.tv_sec  - start_time.tv_sec)  * 1000;
    time_count += (end_time.tv_usec - start_time.tv_usec) / 1000;

    if (time_count > 0)
    {
        unsigned long rate = (bytes * 1000) / time_count;

        printf("0x%x bytes zeroed in %lld milliseconds\n", bytes, time_count);
        printf("zero rate: %lu bytes/sec\n", rate);
    }

}


static void process_options(int argc, char** argv)
{
    int c;

    while ((c = getopt (argc, argv, "dcr:")) != -1)
    {
        switch (c)
        {
            case 'd':
                arc_jtag_ops.state_machine_debug = TRUE;
                break;
            case 'r':
                arc_jtag_ops.retry_count = atoi(optarg);
                break;
            case 'c':
                test = FALSE;
                break;
            default:
                fprintf(stderr, "Usage: %s [ -d ]\n", argv[0]);
                exit(EXIT_FAILURE);
        }
    }
}


/* -------------------------------------------------------------------------- */
/*                               externally visible functions                 */
/* -------------------------------------------------------------------------- */

extern void _initialize_arc_jtag_ops(void);


int main(int argc, char** argv)
{
    Boolean opened;

    printf("Starting test of ARC JTAG download...\n");

    _initialize_arc_jtag_ops();

    process_options(argc, argv);

    opened = arc_jtag_ops.open();

    if (opened)
    {
        printf("ARC processor is connected\n");

        if (test)
            run_test();

        arc_jtag_ops.close();
    }

    printf("Finished test of ARC JTAG download\n");

    return 0;
}

/******************************************************************************/