1 /* $Id: xversion.c,v 1.1 2006/12/13 14:23:34 imanuilov Exp $ */
2 /******************************************************************************
4 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
5 * AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
6 * SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,
7 * OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
8 * APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
9 * THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
10 * AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
11 * FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY
12 * WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
13 * IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
14 * REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
15 * INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16 * FOR A PARTICULAR PURPOSE.
18 * (c) Copyright 2002 Xilinx Inc.
19 * All rights reserved.
21 ******************************************************************************/
22 /*****************************************************************************/
27 * This file contains the implementation of the XVersion component. This
28 * component represents a version ID. It is encapsulated within a component
29 * so that it's type and implementation can change without affecting users of
32 * The version is formatted as X.YYZ where X = 0 - 9, Y = 00 - 99, Z = a - z
33 * X is the major revision, YY is the minor revision, and Z is the
34 * compatability revision.
36 * Packed versions are also utilized for the configuration ROM such that
37 * memory is minimized. A packed version consumes only 16 bits and is
38 * formatted as follows.
41 * Revision Range Bit Positions
43 * Major Revision 0 - 9 Bits 15 - 12
44 * Minor Revision 0 - 99 Bits 11 - 5
45 * Compatability Revision a - z Bits 4 - 0
47 * MODIFICATION HISTORY:
49 * Ver Who Date Changes
50 * ----- ---- -------- -------------------------------------------------------
51 * 1.00a xd 11/03/04 Improved support for doxygen.
54 ******************************************************************************/
57 /***************************** Include Files *********************************/
59 #include "xbasic_types.h"
62 /************************** Constant Definitions *****************************/
64 /* the following constants define the masks and shift values to allow the
65 * revisions to be packed and unpacked, a packed version is packed into a 16
66 * bit value in the following format, XXXXYYYYYYYZZZZZ, where XXXX is the
67 * major revision, YYYYYYY is the minor revision, and ZZZZZ is the compatability
70 #define XVE_MAJOR_SHIFT_VALUE 12
71 #define XVE_MINOR_ONLY_MASK 0x0FE0
72 #define XVE_MINOR_SHIFT_VALUE 5
73 #define XVE_COMP_ONLY_MASK 0x001F
75 /* the following constants define the specific characters of a version string
76 * for each character of the revision, a version string is in the following
77 * format, "X.YYZ" where X is the major revision (0 - 9), YY is the minor
78 * revision (00 - 99), and Z is the compatability revision (a - z)
80 #define XVE_MAJOR_CHAR 0 /* major revision 0 - 9 */
81 #define XVE_MINOR_TENS_CHAR 2 /* minor revision tens 0 - 9 */
82 #define XVE_MINOR_ONES_CHAR 3 /* minor revision ones 0 - 9 */
83 #define XVE_COMP_CHAR 4 /* compatability revision a - z */
84 #define XVE_END_STRING_CHAR 5
86 /**************************** Type Definitions *******************************/
89 /***************** Macros (Inline Functions) Definitions *********************/
92 /************************** Function Prototypes ******************************/
94 static u32
IsVersionStringValid(s8
*StringPtr
);
96 /*****************************************************************************/
99 * Unpacks a packed version into the specified version. Versions are packed
100 * into the configuration ROM to reduce the amount storage. A packed version
101 * is a binary format as oppossed to a non-packed version which is implemented
104 * @param InstancePtr points to the version to unpack the packed version into.
105 * @param PackedVersion contains the packed version to unpack.
111 ******************************************************************************/
112 void XVersion_UnPack(XVersion
* InstancePtr
, u16 PackedVersion
)
114 /* not implemented yet since CROM related */
117 /*****************************************************************************/
120 * Packs a version into the specified packed version. Versions are packed into
121 * the configuration ROM to reduce the amount storage.
123 * @param InstancePtr points to the version to pack.
124 * @param PackedVersionPtr points to the packed version which will receive
125 * the new packed version.
129 * A status, XST_SUCCESS, indicating the packing was accomplished
130 * successfully, or an error, XST_INVALID_VERSION, indicating the specified
131 * input version was not valid such that the pack did not occur
133 * The packed version pointed to by PackedVersionPtr is modified with the new
134 * packed version if the status indicates success.
140 ******************************************************************************/
141 int XVersion_Pack(XVersion
* InstancePtr
, u16
*PackedVersionPtr
)
143 /* not implemented yet since CROM related */
148 /*****************************************************************************/
151 * Determines if two versions are equal.
153 * @param InstancePtr points to the first version to be compared.
154 * @param VersionPtr points to a second version to be compared.
158 * TRUE if the versions are equal, FALSE otherwise.
164 ******************************************************************************/
165 u32
XVersion_IsEqual(XVersion
* InstancePtr
, XVersion
* VersionPtr
)
167 u8
*Version1
= (u8
*) InstancePtr
;
168 u8
*Version2
= (u8
*) VersionPtr
;
171 /* assert to verify input arguments */
173 XASSERT_NONVOID(InstancePtr
!= NULL
);
174 XASSERT_NONVOID(VersionPtr
!= NULL
);
176 /* check each byte of the versions to see if they are the same,
177 * return at any point a byte differs between them
179 for (Index
= 0; Index
< sizeof(XVersion
); Index
++) {
180 if (Version1
[Index
] != Version2
[Index
]) {
185 /* No byte was found to be different between the versions, so indicate
186 * the versions are equal
191 /*****************************************************************************/
194 * Converts a version to a null terminated string.
196 * @param InstancePtr points to the version to convert.
197 * @param StringPtr points to the string which will be the result of the
198 * conversion. This does not need to point to a null terminated
199 * string as an input, but must point to storage which is an adequate
200 * amount to hold the result string.
204 * The null terminated string is inserted at the location pointed to by
205 * StringPtr if the status indicates success.
209 * It is necessary for the caller to have already allocated the storage to
210 * contain the string. The amount of memory necessary for the string is
211 * specified in the version header file.
213 ******************************************************************************/
214 void XVersion_ToString(XVersion
* InstancePtr
, s8
*StringPtr
)
216 /* assert to verify input arguments */
218 XASSERT_VOID(InstancePtr
!= NULL
);
219 XASSERT_VOID(StringPtr
!= NULL
);
221 /* since version is implemented as a string, just copy the specified
222 * input into the specified output
224 XVersion_Copy(InstancePtr
, (XVersion
*) StringPtr
);
227 /*****************************************************************************/
230 * Initializes a version from a null terminated string. Since the string may not
231 * be a format which is compatible with the version, an error could occur.
233 * @param InstancePtr points to the version which is to be initialized.
234 * @param StringPtr points to a null terminated string which will be
235 * converted to a version. The format of the string must match the
236 * version string format which is X.YYX where X = 0 - 9, YY = 00 - 99,
241 * A status, XST_SUCCESS, indicating the conversion was accomplished
242 * successfully, or XST_INVALID_VERSION indicating the version string format
249 ******************************************************************************/
250 int XVersion_FromString(XVersion
* InstancePtr
, s8
*StringPtr
)
252 /* assert to verify input arguments */
254 XASSERT_NONVOID(InstancePtr
!= NULL
);
255 XASSERT_NONVOID(StringPtr
!= NULL
);
257 /* if the version string specified is not valid, return an error */
259 if (!IsVersionStringValid(StringPtr
)) {
260 return XST_INVALID_VERSION
;
263 /* copy the specified string into the specified version and indicate the
264 * conversion was successful
266 XVersion_Copy((XVersion
*) StringPtr
, InstancePtr
);
271 /*****************************************************************************/
274 * Copies the contents of a version to another version.
276 * @param InstancePtr points to the version which is the source of data for
277 * the copy operation.
278 * @param VersionPtr points to another version which is the destination of
279 * the copy operation.
289 ******************************************************************************/
290 void XVersion_Copy(XVersion
* InstancePtr
, XVersion
* VersionPtr
)
292 u8
*Source
= (u8
*) InstancePtr
;
293 u8
*Destination
= (u8
*) VersionPtr
;
296 /* assert to verify input arguments */
298 XASSERT_VOID(InstancePtr
!= NULL
);
299 XASSERT_VOID(VersionPtr
!= NULL
);
301 /* copy each byte of the source version to the destination version */
303 for (Index
= 0; Index
< sizeof(XVersion
); Index
++) {
304 Destination
[Index
] = Source
[Index
];
308 /*****************************************************************************/
311 * Determines if the specified version is valid.
313 * @param StringPtr points to the string to be validated.
317 * TRUE if the version string is a valid format, FALSE otherwise.
323 ******************************************************************************/
324 static u32
IsVersionStringValid(s8
*StringPtr
)
326 /* if the input string is not a valid format, "X.YYZ" where X = 0 - 9,
327 * YY = 00 - 99, and Z = a - z, then indicate it's not valid
329 if ((StringPtr
[XVE_MAJOR_CHAR
] < '0') ||
330 (StringPtr
[XVE_MAJOR_CHAR
] > '9') ||
331 (StringPtr
[XVE_MINOR_TENS_CHAR
] < '0') ||
332 (StringPtr
[XVE_MINOR_TENS_CHAR
] > '9') ||
333 (StringPtr
[XVE_MINOR_ONES_CHAR
] < '0') ||
334 (StringPtr
[XVE_MINOR_ONES_CHAR
] > '9') ||
335 (StringPtr
[XVE_COMP_CHAR
] < 'a') ||
336 (StringPtr
[XVE_COMP_CHAR
] > 'z')) {