]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/esd/common/xilinx_jtag/lenval.c
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 /*******************************************************/
26 /* abstract: This file contains routines for using */
27 /* the lenVal data structure. */
28 /*******************************************************/
31 #include <asm/processor.h>
37 /*****************************************************************************
39 * Description: Extract the long value from the lenval array.
40 * Parameters: plvValue - ptr to lenval.
41 * Returns: long - the extracted value.
42 *****************************************************************************/
43 long value( lenVal
* plvValue
)
45 long lValue
; /* result to hold the accumulated result */
49 for ( sIndex
= 0; sIndex
< plvValue
->len
; ++sIndex
)
51 lValue
<<= 8; /* shift the accumulated result */
52 lValue
|= plvValue
->val
[ sIndex
]; /* get the last byte first */
58 /*****************************************************************************
59 * Function: initLenVal
60 * Description: Initialize the lenval array with the given value.
61 * Assumes lValue is less than 256.
62 * Parameters: plv - ptr to lenval.
63 * lValue - the value to set.
65 *****************************************************************************/
66 void initLenVal( lenVal
* plv
,
70 plv
->val
[0] = (unsigned char)lValue
;
73 /*****************************************************************************
74 * Function: EqualLenVal
75 * Description: Compare two lenval arrays with an optional mask.
76 * Parameters: plvTdoExpected - ptr to lenval #1.
77 * plvTdoCaptured - ptr to lenval #2.
78 * plvTdoMask - optional ptr to mask (=0 if no mask).
79 * Returns: short - 0 = mismatch; 1 = equal.
80 *****************************************************************************/
81 short EqualLenVal( lenVal
* plvTdoExpected
,
82 lenVal
* plvTdoCaptured
,
87 unsigned char ucByteVal1
;
88 unsigned char ucByteVal2
;
89 unsigned char ucByteMask
;
92 sIndex
= plvTdoExpected
->len
;
94 while ( sEqual
&& sIndex
-- )
96 ucByteVal1
= plvTdoExpected
->val
[ sIndex
];
97 ucByteVal2
= plvTdoCaptured
->val
[ sIndex
];
100 ucByteMask
= plvTdoMask
->val
[ sIndex
];
101 ucByteVal1
&= ucByteMask
;
102 ucByteVal2
&= ucByteMask
;
104 if ( ucByteVal1
!= ucByteVal2
)
114 /*****************************************************************************
116 * Description: return the (byte, bit) of lv (reading from left to right).
117 * Parameters: plv - ptr to lenval.
118 * iByte - the byte to get the bit from.
119 * iBit - the bit number (0=msb)
120 * Returns: short - the bit value.
121 *****************************************************************************/
122 short RetBit( lenVal
* plv
,
126 /* assert( ( iByte >= 0 ) && ( iByte < plv->len ) ); */
127 /* assert( ( iBit >= 0 ) && ( iBit < 8 ) ); */
128 return( (short)( ( plv
->val
[ iByte
] >> ( 7 - iBit
) ) & 0x1 ) );
131 /*****************************************************************************
133 * Description: set the (byte, bit) of lv equal to val
134 * Example: SetBit("00000000",byte, 1) equals "01000000".
135 * Parameters: plv - ptr to lenval.
136 * iByte - the byte to get the bit from.
137 * iBit - the bit number (0=msb).
138 * sVal - the bit value to set.
140 *****************************************************************************/
141 void SetBit( lenVal
* plv
,
146 unsigned char ucByteVal
;
147 unsigned char ucBitMask
;
149 ucBitMask
= (unsigned char)(1 << ( 7 - iBit
));
150 ucByteVal
= (unsigned char)(plv
->val
[ iByte
] & (~ucBitMask
));
154 ucByteVal
|= ucBitMask
;
156 plv
->val
[ iByte
] = ucByteVal
;
159 /*****************************************************************************
161 * Description: add val1 to val2 and store in resVal;
162 * assumes val1 and val2 are of equal length.
163 * Parameters: plvResVal - ptr to result.
164 * plvVal1 - ptr of addendum.
165 * plvVal2 - ptr of addendum.
167 *****************************************************************************/
168 void addVal( lenVal
* plvResVal
,
172 unsigned char ucCarry
;
173 unsigned short usSum
;
174 unsigned short usVal1
;
175 unsigned short usVal2
;
178 plvResVal
->len
= plvVal1
->len
; /* set up length of result */
180 /* start at least significant bit and add bytes */
182 sIndex
= plvVal1
->len
;
185 usVal1
= plvVal1
->val
[ sIndex
]; /* i'th byte of val1 */
186 usVal2
= plvVal2
->val
[ sIndex
]; /* i'th byte of val2 */
188 /* add the two bytes plus carry from previous addition */
189 usSum
= (unsigned short)( usVal1
+ usVal2
+ ucCarry
);
191 /* set up carry for next byte */
192 ucCarry
= (unsigned char)( ( usSum
> 255 ) ? 1 : 0 );
194 /* set the i'th byte of the result */
195 plvResVal
->val
[ sIndex
] = (unsigned char)usSum
;
199 /*****************************************************************************
201 * Description: read from XSVF numBytes bytes of data into x.
202 * Parameters: plv - ptr to lenval in which to put the bytes read.
203 * sNumBytes - the number of bytes to read.
205 *****************************************************************************/
206 void readVal( lenVal
* plv
,
209 unsigned char* pucVal
;
211 plv
->len
= sNumBytes
; /* set the length of the lenVal */
212 for ( pucVal
= plv
->val
; sNumBytes
; --sNumBytes
, ++pucVal
)
214 /* read a byte of data into the lenVal */