cybtldr_parse.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*******************************************************************************
  2. * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved.
  3. * You may use this file only in accordance with the license, terms, conditions,
  4. * disclaimers, and limitations in the end user license agreement accompanying
  5. * the software package with which this file was provided.
  6. ********************************************************************************/
  7. #ifndef __CYBTLDR_PARSE_H__
  8. #define __CYBTLDR_PARSE_H__
  9. #include "cybtldr_utils.h"
  10. /* Maximum number of bytes to allocate for a single row. */
  11. /* NB: Rows should have a max of 592 chars (2-arrayID, 4-rowNum, 4-len, 576-data, 2-checksum, 4-newline) */
  12. #define MAX_BUFFER_SIZE 768
  13. /*******************************************************************************
  14. * Function Name: CyBtldr_FromHex
  15. ********************************************************************************
  16. * Summary:
  17. * Converts the provided ASCII char into its hexadecimal numerical equivilant.
  18. *
  19. * Parameters:
  20. * value - the ASCII char to convert into a number
  21. *
  22. * Returns:
  23. * The hexadecimal numerical equivilant of the provided ASCII char. If the
  24. * provided char is not a valid ASCII char, it will return 0.
  25. *
  26. *******************************************************************************/
  27. unsigned char CyBtldr_FromHex(char value);
  28. /*******************************************************************************
  29. * Function Name: CyBtldr_FromAscii
  30. ********************************************************************************
  31. * Summary:
  32. * Converts the provided ASCII array into its hexadecimal numerical equivilant.
  33. *
  34. * Parameters:
  35. * bufSize - The length of the buffer to convert
  36. * buffer - The buffer of ASCII characters to convert
  37. * rowSize - The number of bytes of equivilant hex data generated
  38. * rowData - The hex data generated for the buffer
  39. *
  40. * Returns:
  41. * CYRET_SUCCESS - The buffer was converted successfully
  42. * CYRET_ERR_LENGTH - The buffer does not have an even number of chars
  43. *
  44. *******************************************************************************/
  45. int CyBtldr_FromAscii(unsigned int bufSize, unsigned char* buffer, unsigned short* rowSize, unsigned char* rowData);
  46. /*******************************************************************************
  47. * Function Name: CyBtldr_ReadLine
  48. ********************************************************************************
  49. * Summary:
  50. * Reads a single line from the open data file. This function will remove
  51. * any Windows, Linux, or Unix line endings from the data.
  52. *
  53. * Parameters:
  54. * size - The number of bytes of data read from the line and stored in buffer
  55. * file - The preallocated buffer, with MAX_BUFFER_SIZE bytes, to store the
  56. * read data in.
  57. *
  58. * Returns:
  59. * CYRET_SUCCESS - The file was opened successfully.
  60. * CYRET_ERR_FILE - An error occurred opening the provided file.
  61. * CYRET_ERR_EOF - The end of the file has been reached
  62. *
  63. *******************************************************************************/
  64. EXTERN int CyBtldr_ReadLine(unsigned int* size, char* buffer);
  65. /*******************************************************************************
  66. * Function Name: CyBtldr_OpenDataFile
  67. ********************************************************************************
  68. * Summary:
  69. * Opens the provided file for reading. Once open, it is expected that the
  70. * first call will be to ParseHeader() to read the first line of data. After
  71. * that, successive calls to ParseRowData() are possible to read each line
  72. * of data, one at a time, from the file. Once all data has been read from
  73. * the file, a call to CloseDataFile() should be made to release resources.
  74. *
  75. * Parameters:
  76. * file - The full canonical path to the *.cyacd file to open
  77. *
  78. * Returns:
  79. * CYRET_SUCCESS - The file was opened successfully.
  80. * CYRET_ERR_FILE - An error occurred opening the provided file.
  81. *
  82. *******************************************************************************/
  83. EXTERN int CyBtldr_OpenDataFile(const char* file);
  84. /*******************************************************************************
  85. * Function Name: CyBtldr_ParseHeader
  86. ********************************************************************************
  87. * Summary:
  88. * Parses the hader information from the *.cyacd file. The header information
  89. * is stored as the first line, so this method should only be called once,
  90. * and only immediatly after calling OpenDataFile and reading the first line.
  91. *
  92. * Parameters:
  93. * bufSize - The number of bytes contained within buffer
  94. * buffer - The buffer containing the header data to parse
  95. * siliconId - The silicon ID that the provided *.cyacd file is for
  96. * siliconRev - The silicon Revision that the provided *.cyacd file is for
  97. * chksum - The type of checksum to use for packet integrety check
  98. *
  99. * Returns:
  100. * CYRET_SUCCESS - The file was opened successfully.
  101. * CYRET_ERR_LENGTH - The line does not contain enough data
  102. *
  103. *******************************************************************************/
  104. EXTERN int CyBtldr_ParseHeader(unsigned int bufSize, unsigned char* buffer, unsigned long* siliconId, unsigned char* siliconRev, unsigned char* chksum);
  105. /*******************************************************************************
  106. * Function Name: CyBtldr_ParseRowData
  107. ********************************************************************************
  108. * Summary:
  109. * Parses the contents of the provided buffer which is expected to contain
  110. * the row data from the *.cyacd file. This is expected to be called multiple
  111. * times. Once for each row of the *.cyacd file, excluding the header row.
  112. *
  113. * Parameters:
  114. * bufSize - The number of bytes contained within buffer
  115. * buffer - The buffer containing the row data to parse
  116. * arrayId - The flash array that the row of data belongs in
  117. * rowNum - The flash row number that the data corresponds to
  118. * rowData - The preallocated buffer to store the flash row data
  119. * size - The number of bytes of rowData
  120. * checksum - The checksum value for the entire row (rowNum, size, rowData)
  121. *
  122. * Returns:
  123. * CYRET_SUCCESS - The file was opened successfully.
  124. * CYRET_ERR_LENGTH - The line does not contain enough data
  125. * CYRET_ERR_DATA - The line does not contain a full row of data
  126. * CYRET_ERR_CMD - The line does not start with the cmd identifier ':'
  127. *
  128. *******************************************************************************/
  129. EXTERN int CyBtldr_ParseRowData(unsigned int bufSize, unsigned char* buffer, unsigned char* arrayId, unsigned short* rowNum, unsigned char* rowData, unsigned short* size, unsigned char* checksum);
  130. /*******************************************************************************
  131. * Function Name: CyBtldr_CloseDataFile
  132. ********************************************************************************
  133. * Summary:
  134. * Closes the data file pointer.
  135. *
  136. * Parameters:
  137. * void.
  138. *
  139. * Returns:
  140. * CYRET_SUCCESS - The file was opened successfully.
  141. * CYRET_ERR_FILE - An error occured opening the provided file.
  142. *
  143. *******************************************************************************/
  144. EXTERN int CyBtldr_CloseDataFile(void);
  145. #endif