SSL_FLASH_CRC.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**********************************************************************
  2. * © 2010 Microchip Technology Inc.
  3. *
  4. * FileName: SSL_EEPROMTest_CRC16.c
  5. * Dependencies: Header (.h) files if applicable, see below
  6. * Processor: PIC18
  7. * Compiler: C18 v3.41
  8. *
  9. * SOFTWARE LICENSE AGREEMENT:
  10. * Microchip Technology Inc. (“Microchip”) licenses this software to you
  11. * solely for use with Microchip PIC® microcontroller
  12. * products. The software is owned by Microchip and is protected under
  13. * applicable copyright laws. All rights reserved.
  14. *
  15. * SOFTWARE IS PROVIDED “AS IS.” MICROCHIP EXPRESSLY DISCLAIMS ANY
  16. * WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
  17. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  18. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
  19. * BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
  20. * DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
  21. * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
  22. * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
  23. * ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
  24. *
  25. * REVISION HISTORY:
  26. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. * Author Date Comments on this revision
  28. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. * CT 09/15/2008 Initial Revision
  30. * Mike Cahill 11/11/10 Updated for HI-TECH v9.80
  31. * MVL 02/22/2011 Updated with HI-TECH v9.81
  32. * VR 07/11/2012 Downgrade to C18 v3.41
  33. *
  34. * Version 1.03
  35. *
  36. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. * ADDITIONAL NOTES:
  38. *
  39. **********************************************************************/
  40. #include "SSL_FLASH_CRC.h"
  41. uint16_t crc_Result = 0;
  42. uint16_t partialCRC_Result = 0;
  43. uint16_t tempCRC = 0;
  44. uint8_t Buffer;
  45. uint8_t rom *data_F = 0;
  46. uint16_t volatile startAddress = FLASH_STARTADDRESS;
  47. uint16_t volatile endAddress = FLASH_ENDADDRESS;
  48. /*******************************************************************************
  49. * Description:
  50. * The " SSL_8bits_EEPROMtest_CRC16 " function Calculates
  51. * the CRC of the data starting fromnAddress
  52. * "EEPROM_STARTADDRESS" to "EEPROM_ENDADDRESS". This function
  53. * \returns the final CRC Value.
  54. * CRC-16 is used as a divisor.
  55. *
  56. * CRC-16 = 1 1000 0000 0000 0101= 8005(hex)
  57. * Input: startAddress : start Address from which the CRC needs to be calculated
  58. * endAddress : This address indicates the Final address upto which the CRC is calculated
  59. * Return Values:
  60. crc_Result : Returns the final CRC result.
  61. *
  62. *******************************************************************************/
  63. uint16_t SSL_FLASHtest_CRC( void )
  64. {
  65. uint16_t i;
  66. for(i=startAddress; i<endAddress ; i++)
  67. {
  68. partialCRC_Result=0;
  69. Buffer = *(data_F+i);
  70. //Buffer=Read_b_eep(i);
  71. FLASH_CRC_Checksum();
  72. crc_Result= crc_Result + partialCRC_Result;
  73. }
  74. return crc_Result;
  75. }
  76. /*******************************************************************************
  77. * Description : Calculates the Partial Checksum for FLASH_BYTES
  78. *****************************************************************************/
  79. void FLASH_CRC_Checksum()
  80. {
  81. uint16_t i;
  82. tempCRC=0;
  83. for(i=8u; i>0u; i--)
  84. {
  85. if ( (Buffer ^ (tempCRC)) & 0x80 )
  86. {
  87. (tempCRC) = ((tempCRC)<< 1) ^ EEPROM_GEN_POLY ;
  88. }
  89. else
  90. {
  91. (tempCRC) <<= 1 ;
  92. }
  93. Buffer <<= 1 ;
  94. }
  95. partialCRC_Result= partialCRC_Result+tempCRC;
  96. }