SSL_Demo2.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_Demo.h"
  14. /*******************************************************************************
  15. Pragmas
  16. ******************************************************************************/
  17. #pragma config XINST = OFF
  18. #pragma config FOSC = HS1
  19. #pragma config WDTEN = OFF //OFF // SWDTDIS
  20. #pragma config WDTPS = 256 // WD TimeOut 1024ms
  21. #pragma config SOSCSEL = DIG // Port C, Pin 0 & 1 => Digital
  22. #pragma config PLLCFG = ON
  23. #pragma romdata CRCID=0x1000
  24. rom const uint16_t crc_Result_CONST = 0x5a83; /* EE-Prom CRC result constant */
  25. #pragma romdata
  26. /*******************************************************************************
  27. * Main SSL Demo
  28. ******************************************************************************/
  29. void main( void )
  30. {
  31. TESTFLAG testFlag = {0,0,0,0,0,0,0};
  32. uint16_t crc_Result = 0; // CRC values FLASH
  33. /************************ CPU REGISTER TEST ***********************************/
  34. if (SSL_CPU_RegisterTest()==CPU_REGISTER_TEST_PASS)
  35. {
  36. // the CPU registers don't have stuck bits
  37. testFlag.cpuRegister_TestResult = 1;
  38. }
  39. else
  40. {
  41. testFlag.cpuRegister_TestResult = 0;
  42. }
  43. /*********************** PROGRAM COUNTER TEST *********************************/
  44. if (SSL_PCtest()==PROGRAM_COUNTER_TEST_PASS)
  45. {
  46. // the PC register does not have stuck bits
  47. testFlag.programCounter_TestResult = 1;
  48. }
  49. else
  50. {
  51. testFlag.programCounter_TestResult = 0;
  52. }
  53. /**************************** RAM TESTS ***************************************/
  54. /********************** Checker Board RAM test ********************************/
  55. // Note that this test is not destructive. It has to NOT overlap the stack space!
  56. if (SSL_RAMtest_CheckerBoard( )==CB_TEST_PASS)
  57. {
  58. // the test succeeded and we are confident that the RAM area can be used
  59. testFlag.checkerboardRam_TestResult = 1;
  60. }
  61. else
  62. {
  63. testFlag.checkerboardRam_TestResult = 0;
  64. }
  65. /************************ March B RAM Test ************************************/
  66. if (SSL_RAMtest_MarchB() ==MARCHB_RAM_TEST_PASS)
  67. {
  68. // the test succeeded and we can go ahead and use the allocated memory
  69. testFlag.marchBRam_TestResult = 1;
  70. }
  71. else
  72. {
  73. testFlag.marchBRam_TestResult = 0;
  74. }
  75. /************************ March C RAM Test ************************************/
  76. if (SSL_RAMtest_MarchC() == MARCHC_RAM_TEST_PASS)
  77. {
  78. testFlag.marchCRam_TestResult = 1;
  79. }
  80. else
  81. {
  82. testFlag.marchCRam_TestResult = 0;
  83. }
  84. /************************ MarchC Minus RAM test *******************************/
  85. if (SSL_RAMtest_MarchCMinus() == MARCHCminus_RAM_TEST_PASS)
  86. {
  87. // if both tests succeeded we can go ahead and use the allocated memory
  88. testFlag.marchCMinusRam_TestResult = 1;
  89. }
  90. else
  91. {
  92. testFlag.marchCMinusRam_TestResult = 0;
  93. }
  94. /*************************** FLASH CRC TEST ***********************************/
  95. // This function can be called periodically and the generated checksum can be
  96. // compared with the reference checksum. Reference must be generated after
  97. // compile and written into "crc_Result_CONST". See above.
  98. crc_Result = SSL_FLASHtest_CRC( );
  99. // make sure that the periodic check is equal to the reference one
  100. if ( crc_Result==crc_Result_CONST)
  101. {
  102. testFlag.flash_TestResult=1;
  103. // we are confident that the data programmed in Flash
  104. // has not been altered in any way
  105. }
  106. else
  107. {
  108. testFlag.flash_TestResult=0;
  109. }
  110. }