SSL_Class_B_Tests.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*******************************************************************************
  2. Class B Implementation Test File
  3. Summary:
  4. This file contains the test program for the
  5. the Class B Safety Software on PIC18 MCUs.
  6. ********************************************************************************
  7. File: SSL_Demo2.c
  8. Processor: PIC18
  9. Compiler: Microchip MPLAB® C18 v3.41 or higher
  10. Author: Reiling
  11. Created on 11. Juli 2012, 10:58
  12. ******************************************************************************/
  13. #include "SSL_Class_B_Tests.h"
  14. #pragma romdata CRCID=0x2000
  15. rom const uint16_t crc_Result_CONST = 0x97B9; /* FLASH CRC result constant */
  16. #pragma romdata
  17. /*******************************************************************************
  18. * Main SSL Demo
  19. ******************************************************************************/
  20. uint16_t SSL_Class_B_Tests( void )
  21. {
  22. uint16_t testFlags = 0;
  23. uint16_t crc_Result = 0; // CRC values FLASH
  24. /************************ CPU REGISTER TEST ***********************************/
  25. if(SSL_CPU_RegisterTest() == CPU_REGISTER_TEST_PASS)
  26. {
  27. // the CPU registers don't have stuck bits
  28. testFlags |= CPURegister_TestResult;
  29. }
  30. else
  31. {
  32. testFlags &= ~CPURegister_TestResult;
  33. }
  34. /*********************** PROGRAM COUNTER TEST *********************************/
  35. if (SSL_PCtest() == PROGRAM_COUNTER_TEST_PASS)
  36. {
  37. // the PC register does not have stuck bits
  38. testFlags |= ProgramCounter_TestResult;
  39. }
  40. else
  41. {
  42. testFlags &= ~ProgramCounter_TestResult;
  43. }
  44. /**************************** RAM TESTS ***************************************/
  45. /********************** Checker Board RAM test ********************************/
  46. // Note that this test is not destructive. It has to NOT overlap the stack space!
  47. if (SSL_RAMtest_CheckerBoard( ) == CB_TEST_PASS)
  48. {
  49. // the test succeeded and we are confident that the RAM area can be used
  50. testFlags |= CheckerboardRam_TestResult;
  51. }
  52. else
  53. {
  54. testFlags &= ~CheckerboardRam_TestResult;
  55. }
  56. /********************** Checker Board Stack test ********************************/
  57. // Note that this test is not destructive. It test Stack and Heap RAM!
  58. if (SSL_STACKtest_CheckerBoard( ) == CB_TEST_PASS)
  59. {
  60. // the test succeeded and we are confident that the RAM area can be used
  61. testFlags |= CheckerboardRam_TestResult;
  62. }
  63. else
  64. {
  65. testFlags &= ~CheckerboardRam_TestResult;
  66. }
  67. /************************ March B RAM Test ************************************/
  68. if (SSL_RAMtest_MarchB() == MARCHB_RAM_TEST_PASS)
  69. {
  70. // the test succeeded and we can go ahead and use the allocated memory
  71. testFlags |= MarchBRam_TestResult;
  72. }
  73. else
  74. {
  75. testFlags &= ~MarchBRam_TestResult;
  76. }
  77. /************************ March C RAM Test ************************************/
  78. if (SSL_RAMtest_MarchC() == MARCHC_RAM_TEST_PASS)
  79. {
  80. testFlags |= MarchCRam_TestResult;
  81. }
  82. else
  83. {
  84. testFlags &= ~MarchCRam_TestResult;
  85. }
  86. /************************ MarchC Minus RAM test *******************************/
  87. if (SSL_RAMtest_MarchCMinus() == MARCHCminus_RAM_TEST_PASS)
  88. {
  89. // if both tests succeeded we can go ahead and use the allocated memory
  90. testFlags |= MarchCMinusRam_TestResult;
  91. }
  92. else
  93. {
  94. testFlags &= ~MarchCMinusRam_TestResult;
  95. }
  96. /*************************** FLASH CRC TEST ***********************************/
  97. // This function can be called periodically and the generated checksum can be
  98. // compared with the reference checksum. Reference must be generated after
  99. // compile and written into "crc_Result_CONST". See above.
  100. crc_Result = SSL_FLASHtest_CRC( );
  101. // make sure that the periodic check is equal to the reference one
  102. if ( crc_Result == crc_Result_CONST)
  103. {
  104. testFlags |= Flash_TestResult;
  105. // we are confident that the data programmed in Flash
  106. // has not been altered in any way
  107. }
  108. else
  109. {
  110. testFlags &= ~Flash_TestResult;
  111. }
  112. return testFlags;
  113. }