SSL_MarchBRamTest.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**********************************************************************
  2. * © 2010 Microchip Technology Inc.
  3. *
  4. * FileName: SSL_MarchBRamTest.c
  5. * Dependencies: Header (.h) files if applicable, see below
  6. * Processor: PIC16FXXX
  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 08/15/2008 First release of source file
  30. * Mike Cahill 11/11/2010 Updated for HI-TECH v9.80
  31. * MVL 02/22/2011 Modified for HI-TECH v9.80 & v9.81
  32. * VR 07/11/2012 Downgrade to C18 v3.41
  33. *
  34. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. * ADDITIONAL NOTES:
  36. *
  37. **********************************************************************/
  38. #include "SSL_Class_B_Tests.h"
  39. #pragma idata RAMFIX3=0xE20
  40. uint8_t *data = (uint8_t *)MARCHB_RAM_START_ADDRESS;
  41. uint16_t i=0;
  42. /*******************************************************************
  43. * Description : This function implements the March B test. It is a complete and irredundant test
  44. * capable of detecting stuck-at faults , linked coupling Idempotent faults or Inversion Coupling
  45. * faults. This test is of complexity 17n( Where n is the number of bits).
  46. * Input:
  47. * *data : pointer to an array declared in user memory
  48. * MAX_MEM : value indicating the number of bytes to test
  49. * Return Values:
  50. * MARCHB_RAM_TEST_FAIL : return value = 0
  51. * MARCHB_RAM_TEST_PASS : return value = 1
  52. *
  53. *******************************************************************/
  54. unsigned char SSL_RAMtest_MarchB( void )
  55. {
  56. volatile uint8_t testResult;
  57. //***********************************************
  58. for(i=0;i<=(MAX_MEM_B-1);i++)
  59. {
  60. data[i]=0x00;
  61. }
  62. //***********************************************
  63. for(i=0;i<=(MAX_MEM_B-1);i++)
  64. {
  65. testResult = Rd0Wr1Rd1Wr0Rd0Wr1( );
  66. if ( !testResult)
  67. return MARCHB_RAM_TEST_FAIL;
  68. }
  69. //***********************************************
  70. for(i=0;i<=(MAX_MEM_B-1);i++)
  71. {
  72. testResult = Rd1Wr0Wr1( );
  73. if ( !testResult)
  74. return MARCHB_RAM_TEST_FAIL;
  75. }
  76. //***********************************************
  77. for(i=(MAX_MEM_B-1);i>0;i--)
  78. {
  79. testResult = Rd1Wr0Wr1Wr0( );
  80. if ( !testResult)
  81. return MARCHB_RAM_TEST_FAIL;
  82. }
  83. // do this once more time for zero
  84. testResult = Rd1Wr0Wr1Wr0 ( );
  85. if ( !testResult)
  86. return MARCHB_RAM_TEST_FAIL;
  87. //***********************************************
  88. for(i=(MAX_MEM_B-1);i>0;i--)
  89. {
  90. testResult = Rd0Wr1Wr0( );
  91. if ( !testResult)
  92. return MARCHB_RAM_TEST_FAIL;
  93. }
  94. // do this once more time for zero
  95. testResult = Rd0Wr1Wr0( );
  96. if( !testResult)
  97. return MARCHB_RAM_TEST_FAIL;
  98. //***********************************************
  99. return MARCHB_RAM_TEST_PASS;
  100. }
  101. //******************************************************************************
  102. unsigned char Rd0Wr1Rd1Wr0Rd0Wr1( void )
  103. {
  104. volatile uint8_t r;
  105. volatile uint8_t imresult;
  106. // read 0, write 1
  107. for(r=0;r<8;r++)
  108. {
  109. if((data[i] >>r) & 0x01)
  110. return MARCHB_RAM_TEST_FAIL;
  111. else
  112. {
  113. imresult = 1<<r;
  114. data[i] += imresult;
  115. }
  116. }
  117. // read 1, write 0
  118. for(r=0;r<8;r++)
  119. {
  120. if(((data[i] >>r) & 0x01) != 0x01)
  121. return MARCHB_RAM_TEST_FAIL;
  122. else
  123. {
  124. imresult = ~(1<<r);
  125. data[i] &= imresult;
  126. }
  127. }
  128. // read 0, write 1
  129. for(r=0;r<8;r++)
  130. {
  131. if((data[i] >>r) & 0x01)
  132. return MARCHB_RAM_TEST_FAIL;
  133. else
  134. {
  135. imresult = 1<<r;
  136. data[i] += imresult;
  137. }
  138. }
  139. return MARCHB_RAM_TEST_PASS;
  140. }
  141. //******************************************************************************
  142. unsigned char Rd1Wr0Wr1( void )
  143. {
  144. volatile uint8_t r;
  145. volatile uint8_t imresult;
  146. // read 1, write 0, write 1
  147. for (r=0; r<8;r++)
  148. {
  149. if ( ((data[i] >>r ) & 0x01) != 0x01)
  150. return MARCHB_RAM_TEST_FAIL;
  151. else
  152. {
  153. imresult = ~(1<<r);
  154. data[i] &= imresult;
  155. imresult = 1<<r;
  156. data[i] += imresult;
  157. }
  158. }
  159. return MARCHB_RAM_TEST_PASS;
  160. }
  161. //******************************************************************************
  162. unsigned char Rd1Wr0Wr1Wr0( void )
  163. {
  164. volatile uint8_t r;
  165. volatile uint8_t imresult;
  166. // read 1, write 0, write 1, write 0
  167. for(r=0;r<8;r++)
  168. {
  169. if(((data[i] >>r) & 0x01) != 0x01)
  170. return MARCHB_RAM_TEST_FAIL;
  171. else
  172. {
  173. imresult = ~(1<<r);
  174. data[i] &= imresult;
  175. imresult = 1<<r;
  176. data[i] += imresult;
  177. imresult = ~(1<<r);
  178. data[i] &= imresult;
  179. }
  180. }
  181. return MARCHB_RAM_TEST_PASS;
  182. }
  183. //******************************************************************************
  184. unsigned char Rd0Wr1Wr0( void )
  185. {
  186. volatile uint8_t r;
  187. volatile uint8_t imresult;
  188. // read 0, write 1, write 0
  189. for(r=0;r<8;r++)
  190. {
  191. if((data[i] >>r) & 0x01)
  192. return MARCHB_RAM_TEST_FAIL;
  193. else
  194. {
  195. imresult = 1<<r;
  196. data[i] += imresult;
  197. imresult = ~(1<<r);
  198. data[i] &= imresult;
  199. }
  200. }
  201. return MARCHB_RAM_TEST_PASS;
  202. }