xversion.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /******************************************************************************
  2. *
  3. * Author: Xilinx, Inc.
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. *
  12. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
  13. * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
  14. * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
  15. * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
  16. * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
  17. * ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
  18. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
  19. * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
  20. * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
  21. * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. * FITNESS FOR A PARTICULAR PURPOSE.
  23. *
  24. *
  25. * Xilinx hardware products are not intended for use in life support
  26. * appliances, devices, or systems. Use in such applications is
  27. * expressly prohibited.
  28. *
  29. *
  30. * (c) Copyright 2002-2004 Xilinx Inc.
  31. * All rights reserved.
  32. *
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program; if not, write to the Free Software Foundation, Inc.,
  36. * 675 Mass Ave, Cambridge, MA 02139, USA.
  37. *
  38. ******************************************************************************/
  39. /*****************************************************************************
  40. *
  41. * This file contains the implementation of the XVersion component. This
  42. * component represents a version ID. It is encapsulated within a component
  43. * so that it's type and implementation can change without affecting users of
  44. * it.
  45. *
  46. * The version is formatted as X.YYZ where X = 0 - 9, Y = 00 - 99, Z = a - z
  47. * X is the major revision, YY is the minor revision, and Z is the
  48. * compatability revision.
  49. *
  50. * Packed versions are also utilized for the configuration ROM such that
  51. * memory is minimized. A packed version consumes only 16 bits and is
  52. * formatted as follows.
  53. *
  54. * <pre>
  55. * Revision Range Bit Positions
  56. *
  57. * Major Revision 0 - 9 Bits 15 - 12
  58. * Minor Revision 0 - 99 Bits 11 - 5
  59. * Compatability Revision a - z Bits 4 - 0
  60. </pre>
  61. *
  62. ******************************************************************************/
  63. /***************************** Include Files *********************************/
  64. #include "xbasic_types.h"
  65. #include "xversion.h"
  66. /************************** Constant Definitions *****************************/
  67. /* the following constants define the masks and shift values to allow the
  68. * revisions to be packed and unpacked, a packed version is packed into a 16
  69. * bit value in the following format, XXXXYYYYYYYZZZZZ, where XXXX is the
  70. * major revision, YYYYYYY is the minor revision, and ZZZZZ is the compatability
  71. * revision
  72. */
  73. #define XVE_MAJOR_SHIFT_VALUE 12
  74. #define XVE_MINOR_ONLY_MASK 0x0FE0
  75. #define XVE_MINOR_SHIFT_VALUE 5
  76. #define XVE_COMP_ONLY_MASK 0x001F
  77. /* the following constants define the specific characters of a version string
  78. * for each character of the revision, a version string is in the following
  79. * format, "X.YYZ" where X is the major revision (0 - 9), YY is the minor
  80. * revision (00 - 99), and Z is the compatability revision (a - z)
  81. */
  82. #define XVE_MAJOR_CHAR 0 /* major revision 0 - 9 */
  83. #define XVE_MINOR_TENS_CHAR 2 /* minor revision tens 0 - 9 */
  84. #define XVE_MINOR_ONES_CHAR 3 /* minor revision ones 0 - 9 */
  85. #define XVE_COMP_CHAR 4 /* compatability revision a - z */
  86. #define XVE_END_STRING_CHAR 5
  87. /**************************** Type Definitions *******************************/
  88. /***************** Macros (Inline Functions) Definitions *********************/
  89. /************************** Function Prototypes ******************************/
  90. static u32 IsVersionStringValid(s8 * StringPtr);
  91. /*****************************************************************************
  92. *
  93. * Unpacks a packed version into the specified version. Versions are packed
  94. * into the configuration ROM to reduce the amount storage. A packed version
  95. * is a binary format as oppossed to a non-packed version which is implemented
  96. * as a string.
  97. *
  98. * @param InstancePtr points to the version to unpack the packed version into.
  99. * @param PackedVersion contains the packed version to unpack.
  100. *
  101. * @return
  102. *
  103. * None.
  104. *
  105. * @note
  106. *
  107. * None.
  108. *
  109. ******************************************************************************/
  110. void
  111. XVersion_UnPack(XVersion * InstancePtr, u16 PackedVersion)
  112. {
  113. /* not implemented yet since CROM related */
  114. }
  115. /*****************************************************************************
  116. *
  117. * Packs a version into the specified packed version. Versions are packed into
  118. * the configuration ROM to reduce the amount storage.
  119. *
  120. * @param InstancePtr points to the version to pack.
  121. * @param PackedVersionPtr points to the packed version which will receive
  122. * the new packed version.
  123. *
  124. * @return
  125. *
  126. * A status, XST_SUCCESS, indicating the packing was accomplished
  127. * successfully, or an error, XST_INVALID_VERSION, indicating the specified
  128. * input version was not valid such that the pack did not occur
  129. * <br><br>
  130. * The packed version pointed to by PackedVersionPtr is modified with the new
  131. * packed version if the status indicates success.
  132. *
  133. * @note
  134. *
  135. * None.
  136. *
  137. ******************************************************************************/
  138. XStatus
  139. XVersion_Pack(XVersion * InstancePtr, u16 * PackedVersionPtr)
  140. {
  141. /* not implemented yet since CROM related */
  142. return XST_SUCCESS;
  143. }
  144. /*****************************************************************************
  145. *
  146. * Determines if two versions are equal.
  147. *
  148. * @param InstancePtr points to the first version to be compared.
  149. * @param VersionPtr points to a second version to be compared.
  150. *
  151. * @return
  152. *
  153. * TRUE if the versions are equal, FALSE otherwise.
  154. *
  155. * @note
  156. *
  157. * None.
  158. *
  159. ******************************************************************************/
  160. u32
  161. XVersion_IsEqual(XVersion * InstancePtr, XVersion * VersionPtr)
  162. {
  163. u8 *Version1 = (u8 *) InstancePtr;
  164. u8 *Version2 = (u8 *) VersionPtr;
  165. int Index;
  166. /* assert to verify input arguments */
  167. XASSERT_NONVOID(InstancePtr != NULL);
  168. XASSERT_NONVOID(VersionPtr != NULL);
  169. /* check each byte of the versions to see if they are the same,
  170. * return at any point a byte differs between them
  171. */
  172. for (Index = 0; Index < sizeof (XVersion); Index++) {
  173. if (Version1[Index] != Version2[Index]) {
  174. return FALSE;
  175. }
  176. }
  177. /* No byte was found to be different between the versions, so indicate
  178. * the versions are equal
  179. */
  180. return TRUE;
  181. }
  182. /*****************************************************************************
  183. *
  184. * Converts a version to a null terminated string.
  185. *
  186. * @param InstancePtr points to the version to convert.
  187. * @param StringPtr points to the string which will be the result of the
  188. * conversion. This does not need to point to a null terminated
  189. * string as an input, but must point to storage which is an adequate
  190. * amount to hold the result string.
  191. *
  192. * @return
  193. *
  194. * The null terminated string is inserted at the location pointed to by
  195. * StringPtr if the status indicates success.
  196. *
  197. * @note
  198. *
  199. * It is necessary for the caller to have already allocated the storage to
  200. * contain the string. The amount of memory necessary for the string is
  201. * specified in the version header file.
  202. *
  203. ******************************************************************************/
  204. void
  205. XVersion_ToString(XVersion * InstancePtr, s8 * StringPtr)
  206. {
  207. /* assert to verify input arguments */
  208. XASSERT_VOID(InstancePtr != NULL);
  209. XASSERT_VOID(StringPtr != NULL);
  210. /* since version is implemented as a string, just copy the specified
  211. * input into the specified output
  212. */
  213. XVersion_Copy(InstancePtr, (XVersion *) StringPtr);
  214. }
  215. /*****************************************************************************
  216. *
  217. * Initializes a version from a null terminated string. Since the string may not
  218. * be a format which is compatible with the version, an error could occur.
  219. *
  220. * @param InstancePtr points to the version which is to be initialized.
  221. * @param StringPtr points to a null terminated string which will be
  222. * converted to a version. The format of the string must match the
  223. * version string format which is X.YYX where X = 0 - 9, YY = 00 - 99,
  224. * Z = a - z.
  225. *
  226. * @return
  227. *
  228. * A status, XST_SUCCESS, indicating the conversion was accomplished
  229. * successfully, or XST_INVALID_VERSION indicating the version string format
  230. * was not valid.
  231. *
  232. * @note
  233. *
  234. * None.
  235. *
  236. ******************************************************************************/
  237. XStatus
  238. XVersion_FromString(XVersion * InstancePtr, s8 * StringPtr)
  239. {
  240. /* assert to verify input arguments */
  241. XASSERT_NONVOID(InstancePtr != NULL);
  242. XASSERT_NONVOID(StringPtr != NULL);
  243. /* if the version string specified is not valid, return an error */
  244. if (!IsVersionStringValid(StringPtr)) {
  245. return XST_INVALID_VERSION;
  246. }
  247. /* copy the specified string into the specified version and indicate the
  248. * conversion was successful
  249. */
  250. XVersion_Copy((XVersion *) StringPtr, InstancePtr);
  251. return XST_SUCCESS;
  252. }
  253. /*****************************************************************************
  254. *
  255. * Copies the contents of a version to another version.
  256. *
  257. * @param InstancePtr points to the version which is the source of data for
  258. * the copy operation.
  259. * @param VersionPtr points to another version which is the destination of
  260. * the copy operation.
  261. *
  262. * @return
  263. *
  264. * None.
  265. *
  266. * @note
  267. *
  268. * None.
  269. *
  270. ******************************************************************************/
  271. void
  272. XVersion_Copy(XVersion * InstancePtr, XVersion * VersionPtr)
  273. {
  274. u8 *Source = (u8 *) InstancePtr;
  275. u8 *Destination = (u8 *) VersionPtr;
  276. int Index;
  277. /* assert to verify input arguments */
  278. XASSERT_VOID(InstancePtr != NULL);
  279. XASSERT_VOID(VersionPtr != NULL);
  280. /* copy each byte of the source version to the destination version */
  281. for (Index = 0; Index < sizeof (XVersion); Index++) {
  282. Destination[Index] = Source[Index];
  283. }
  284. }
  285. /*****************************************************************************
  286. *
  287. * Determines if the specified version is valid.
  288. *
  289. * @param StringPtr points to the string to be validated.
  290. *
  291. * @return
  292. *
  293. * TRUE if the version string is a valid format, FALSE otherwise.
  294. *
  295. * @note
  296. *
  297. * None.
  298. *
  299. ******************************************************************************/
  300. static u32
  301. IsVersionStringValid(s8 * StringPtr)
  302. {
  303. /* if the input string is not a valid format, "X.YYZ" where X = 0 - 9,
  304. * YY = 00 - 99, and Z = a - z, then indicate it's not valid
  305. */
  306. if ((StringPtr[XVE_MAJOR_CHAR] < '0') ||
  307. (StringPtr[XVE_MAJOR_CHAR] > '9') ||
  308. (StringPtr[XVE_MINOR_TENS_CHAR] < '0') ||
  309. (StringPtr[XVE_MINOR_TENS_CHAR] > '9') ||
  310. (StringPtr[XVE_MINOR_ONES_CHAR] < '0') ||
  311. (StringPtr[XVE_MINOR_ONES_CHAR] > '9') ||
  312. (StringPtr[XVE_COMP_CHAR] < 'a') ||
  313. (StringPtr[XVE_COMP_CHAR] > 'z')) {
  314. return FALSE;
  315. }
  316. return TRUE;
  317. }