summaryrefslogtreecommitdiff
path: root/package/ifxmips_adsl/src/cmvread.c
blob: 7e5eecd0f6e253635f93b069d89179a8b1af01d0 (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
209
210
211
212
213
214
215
216
/*
 *   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 2 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, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */
//-----------------------------------------------------------------------
//Description:	
// read the CMV register under Linux for Amazon
//-----------------------------------------------------------------------
//Author:	Joe.Lin@infineon.com
//Created:	31-December-2004
//-----------------------------------------------------------------------
/* History
 * Last changed on:
 *  000002:tc.chen 2005/06/10 add get_adsl_rate and ifx_makeCMV api
 * Last changed by: 
 *
*/

#define _IFXMIPS_ADSL_APP
//#define DEBUG
#define u32 unsigned int
#define u16 unsigned short
#define u8  unsigned char
#define IFXMIPS_MEI_DEV  "/dev/ifxmips/mei"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
#include <asm/ifxmips/ifxmips_mei_app.h>
#include <asm/ifxmips/ifxmips_mei_ioctl.h>
#include <asm/ifxmips/ifxmips_mei.h>

#ifdef IFX_MULTILIB_UTIL 
#define main	cmvread_main
#define	display_version	cmvread_display_version
#endif

/*============================definitions======================*/
#define OPTN 5
#define CNFG 8
#define CNTL 1
#define STAT 2
#define RATE 6
#define PLAM 7
#define INFO 3
#define TEST 4

typedef unsigned short UINT16;
typedef unsigned long UINT32;



/*=============================================================*/


/*=============================global variables================*/
int c=0;
int input_flag=0;
int digit_optind=0;
FILE* script_file;
void (*func)()=NULL;
int fd;

UINT16 var16[8];
UINT32 var32[8];
UINT16 Message[16];

/*=============================================================*/

int ifx_makeCMV(unsigned char opcode, unsigned char group, unsigned short address, unsigned short index, int size, unsigned short * data, unsigned short *Message, int msg_len)
{
        if (msg_len < 16*2)
                return -1;
        memset(Message, 0, 16*2);
        Message[0]= (opcode<<4) + (size&0xf);
        if(opcode == H2D_DEBUG_WRITE_DM)
                Message[1]= (group&0x7f);
        else
                Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
        Message[2]= address;
        Message[3]= index;
        if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
                memcpy(Message+4, data, size*2);

        return 0;
}

void display_version()
{
   printf("adsl cmv reader version1.0\nby Joe Lin \nJoe.Lin@infineon.com\n");
   return;
}


void cmvreader_help()
{
    printf("Usage:cmvread [options] [group name][address][index][size] ...\n");
    printf("options:\n");
    printf("	-h --help            Display help information\n");       
    printf("	-v --version         Display version information\n");
    printf("group name:			--group name of CMV to read\n");
    printf("	OPTN --Read CMV Group 5 \n");
    printf("	CNFG --Read CMV Group 8 \n");
    printf("	CNTL --Read CMV Group 1 \n"); 
    printf("	STAT --Read CMV Group 2 \n");  
    printf("	RATE --Read CMV Group 6 \n");  
    printf("	PLAM --Read CMV Group 7 \n");  
    printf("	INFO --Read CMV Group 3 \n");  
    printf("	TEST --REad CMV Group 4 \n");  
    printf("address --address value of CMV to read\n"); 
    printf("index --index value of CMV to read\n");     
    printf("size  --number of words(16bits) to read \n");        
   
    
 
    return;
}

int main (int argc, char** argv) {
     
	UINT16 Message[16]; //000002:tc.chen
  	char *endptr; 
        int group=0,address,index,size;

 	if (argc < 2)
	{
	  cmvreader_help();
	  return;
	}
 
 	if (strstr(argv[1], "-h") != NULL){
 	  cmvreader_help();
	  return;
 	}
 
  	if (strstr(argv[1], "-v") != NULL){
 	  display_version();
	  return;
 	}
 
        fd=open(IFXMIPS_MEI_DEV, O_RDWR);
        if(fd<0){
                printf("\n\n autoboot open device fail\n");
                return -1;
        }
        
	if((strcmp(argv[1],"optn")==0)||(strcmp(argv[1],"OPTN")==0))
	group=OPTN;
	else if((strcmp(argv[1],"cnfg")==0)||(strcmp(argv[1],"CNFG")==0))
	group=CNFG;
	else if((strcmp(argv[1],"cntl")==0)||(strcmp(argv[1],"CNTL")==0))
	group=CNTL;
	else if((strcmp(argv[1],"stat")==0)||(strcmp(argv[1],"STAT")==0))
	group=STAT;
	else if((strcmp(argv[1],"rate")==0)||(strcmp(argv[1],"RATE")==0))
	group=RATE;
	else if((strcmp(argv[1],"plam")==0)||(strcmp(argv[1],"PLAM")==0))
	group=PLAM;
	else if((strcmp(argv[1],"info")==0)||(strcmp(argv[1],"INFO")==0))
	group=INFO;
	else if((strcmp(argv[1],"test")==0)||(strcmp(argv[1],"TEST")==0))
	group=TEST;
	else 
	 {
	   printf("wrong group type!\nplease slect group:OPTN CNFG CNTL STAT RATE PLAM INFO TEST \n");
                close(fd);
                exit(0);
	 }
	 
	address = strtoul(argv[2], &endptr, 0);
	index = strtoul(argv[3], &endptr, 0);
	size = strtoul(argv[4], &endptr, 0);
        //makeCMV(H2D_CMV_READ, group, address, index, size, NULL);
        ifx_makeCMV(H2D_CMV_READ, group, address, index, size, NULL,Message,sizeof(Message));
        if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
                printf("cr read %d %d %d fail",group,address,index);
                close(fd);
                exit(0);
        }

	int i;
	for (i=0;i<size;i++) printf ("0x%X\n",Message[i+4]);
	
        
//	return Message[4];
        
        
        
   
	close(fd);
 	return 0;	     
}