]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/tools/dumpdesc.c
Merge remote branch 'origin/dpi_demo'
[keystone-rtos/netapi.git] / ti / runtime / netapi / tools / dumpdesc.c
1 /*
2  * devmem2.c: Simple program to read/write from/to any location in memory.
3  *
4  *  Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
5  *
6  *
7  * This software has been developed for the LART computing board
8  * (http://www.lart.tudelft.nl/). The development has been sponsored by
9  * the Mobile MultiMedia Communications (http://www.mmc.tudelft.nl/)
10  * and Ubiquitous Communications (http://www.ubicom.tudelft.nl/)
11  * projects.
12  *
13  * The author can be reached at:
14  *
15  *  Jan-Derk Bakker
16  *  Information and Communication Theory Group
17  *  Faculty of Information Technology and Systems
18  *  Delft University of Technology
19  *  P.O. Box 5031
20  *  2600 GA Delft
21  *  The Netherlands
22  *
23  *
24  * This program is free software; you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation; either version 2 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  * 
34  * You should have received a copy of the GNU General Public License
35  * along with this program; if not, write to the Free Software
36  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
37  *
38  */
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43 #include <string.h>
44 #include <errno.h>
45 #include <signal.h>
46 #include <fcntl.h>
47 #include <ctype.h>
48 #include <termios.h>
49 #include <sys/types.h>
50 #include <sys/mman.h>
52 //netTest_utilDumpDescr
53 void netTest_utilDumpDescr(unsigned long *p, int n)
54 {
55    printf("--------dump of descriptor %d %x\n", n, (int) p);
56    printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
57    printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
58    printf("-----------------------------\n");
59 }
61 static inline unsigned long netapi_timing_start(void)
62 {
63         volatile int vval;
64         //read clock
65         asm volatile("mrc p15, 0, %0, c9, c13, 0" :  "=r"(vval));
66         return vval;
67 }
68 static inline unsigned long netapi_timing_stop(void)
69 {
70         volatile int vval2;
71         //read clock
72         asm volatile("mrc p15, 0, %0, c9, c13, 0" :  "=r"(vval2));
73         return vval2;
74 }
76   
77 #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
78   __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
79  
80 #define MAP_SIZE 4096UL
81 #define MAP_MASK (MAP_SIZE - 1)
84 int cached = 0;
85 int test_loc = 1;
86 int sum=0;
88 int main(int argc, char **argv) {
89     int fd;
90     void *map_base, *virt_addr; 
91 #define N 50
92         unsigned long read_result[N], writeval;
93         off_t target;
94         int access_type = 'w';
95 volatile unsigned long t1;
96 volatile unsigned long t2;
97 int i;
98 int num2dump=32;
100         
101         if(argc < 2) {
102                 fprintf(stderr, "\nUsage:\t%s { address } nun ] ]\n"
103                         "\taddress : memory address to act upon\n"
104                         "\tnum    : #descriptors to be dumped (def 32)\n\n",
105                         argv[0]);
106                 exit(1);
107         }
108         target = strtoul(argv[1], 0, 0);
109         if (argc ==3) num2dump=atoi(argv[2]);
112     if((fd = open("/dev/mem", ((cached) ? (O_RDWR) : (O_RDWR | O_SYNC)))) == -1) FATAL;
113     netapi_Log("/dev/mem opened.\n"); 
114     fflush(stdout);
115     
116     /* Map one page */
117     map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
118     if(map_base == (void *) -1) FATAL;
119     netapi_Log("Memory mapped at address %p. (cached=%d)\n", map_base,cached); 
120     fflush(stdout);
121     
122     virt_addr = map_base + (target & MAP_MASK);
123 for(i=0;i<num2dump;i++)
125    long * tip= &((long *)virt_addr)[32*i];
126    netTest_utilDumpDescr(tip, i);
128     if(munmap(map_base, MAP_SIZE) == -1) FATAL;
129     close(fd);
130     return 0;