SSL_MarchCRamTest.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**********************************************************************
  2. * © 2010 Microchip Technology Inc.
  3. *
  4. * FileName: SSL_MarchCRamTest.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 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.81 & HI-TECH v9.80
  32. * VR 07/11/2012 Downgrade to C18
  33. *
  34. * Version 1.03
  35. *
  36. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. * ADDITIONAL NOTES:
  38. *
  39. **********************************************************************/
  40. #include "SSL_Class_B_Tests.h"
  41. #pragma idata RAMFIX2=0xE10
  42. uint16_t j=0;
  43. uint8_t *dataC = (uint8_t *)MARCHC_RAM_START_ADDRESS;
  44. /*******************************************************************
  45. * Description:
  46. * This function that implements the MarchC test.
  47. * This test is a destructive test !!!
  48. * Input:
  49. * dataC[] : pointer to an array declared in user memory
  50. * MAX_MEM : value indicating the number of bytes to test
  51. * Return Values:
  52. * FAIL : return value = 0
  53. * PASS : return value = 1
  54. *
  55. *******************************************************************/
  56. uint8_t SSL_RAMtest_MarchC( void )
  57. {
  58. volatile uint8_t testResult;
  59. //***********************************************
  60. for(j=0;j<=(MAX_MEM_C-1);j++)
  61. {
  62. dataC[j]=0x00;
  63. }
  64. //***********************************************
  65. for(j=0;j<=(MAX_MEM_C-1);j++)
  66. {
  67. testResult = ReadZeroWriteOne( );
  68. if(!testResult)
  69. return MARCHC_RAM_TEST_FAIL;
  70. }
  71. //************************************************
  72. for(j=0;j<=(MAX_MEM_C-1);j++)
  73. {
  74. testResult = ReadOneWriteZero( );
  75. if(!testResult)
  76. return MARCHC_RAM_TEST_FAIL;
  77. }
  78. //************************************************
  79. for(j=0;j<=(MAX_MEM_C-1);j++)
  80. {
  81. testResult = ReadZero( );
  82. if(!testResult)
  83. return MARCHC_RAM_TEST_FAIL;
  84. }
  85. //***********************************************
  86. for(j=(MAX_MEM_C-1);j>0;j--)
  87. {
  88. testResult = ReadZeroWriteOne( );
  89. if(!testResult)
  90. return MARCHC_RAM_TEST_FAIL;
  91. }
  92. // do this once more time for zero
  93. testResult = ReadZeroWriteOne( );
  94. if(!testResult)
  95. return MARCHC_RAM_TEST_FAIL;
  96. //***********************************************
  97. for(j=(MAX_MEM_C-1);j>0;j--)
  98. {
  99. testResult = ReadOneWriteZero( );
  100. if(!testResult)
  101. return MARCHC_RAM_TEST_FAIL;
  102. }
  103. // do this once more time for zero
  104. testResult = ReadOneWriteZero( );
  105. if(!testResult)
  106. return MARCHC_RAM_TEST_FAIL;
  107. //***********************************************
  108. for(j=(MAX_MEM_C-1);j>0;j--)
  109. {
  110. testResult = ReadZero( );
  111. if(!testResult)
  112. return MARCHC_RAM_TEST_FAIL;
  113. }
  114. // do this once more time for zero
  115. testResult = ReadZero( );
  116. if(!testResult)
  117. return MARCHC_RAM_TEST_FAIL;
  118. //***********************************************
  119. return MARCHC_RAM_TEST_PASS;
  120. } // End of function
  121. /*******************************************************************
  122. * Description:
  123. * This function tests bitwise if a bit is zero and replaces it
  124. * with one.
  125. * Input:
  126. * *test_dataC : pointer to the byte to test
  127. * Return Values:
  128. * FAIL : return value = 0
  129. * PASS : return value = 1
  130. *
  131. *******************************************************************/
  132. uint8_t ReadZeroWriteOne( void )
  133. {
  134. volatile uint8_t r;
  135. volatile uint8_t imresult;
  136. for(r=0;r<8;r++)
  137. {
  138. if((dataC[j] >>r) & 0x01)
  139. {
  140. return MARCHC_RAM_TEST_FAIL;
  141. }
  142. else
  143. {
  144. imresult = 1<<r;
  145. dataC[j] += imresult;
  146. }
  147. }
  148. return MARCHC_RAM_TEST_PASS;
  149. }
  150. /******************************************************************
  151. * Description:
  152. * This function tests bitwise if a bit is one and replaces it
  153. * with zero.
  154. * Input:
  155. * *test_dataC : pointer to the byte to test
  156. * Return Values:
  157. * FAIL : return value = 0
  158. * PASS : return value = 1
  159. *
  160. ******************************************************************/
  161. uint8_t ReadOneWriteZero( void )
  162. {
  163. volatile uint8_t r;
  164. volatile uint8_t imresult;
  165. for(r=0u;r<8u;r++)
  166. {
  167. if(((dataC[j] >>r) & 0x01) != 0x01)
  168. {
  169. return MARCHC_RAM_TEST_FAIL;
  170. }
  171. else
  172. {
  173. imresult = ~(1<<r);
  174. dataC[j] &= imresult;
  175. }
  176. }
  177. return MARCHC_RAM_TEST_PASS;
  178. }
  179. /***********************************************************
  180. * Description:
  181. * This function tests bitwise if all bits are zeros .
  182. * Input:
  183. * *test_dataC : pointer to the byte to test
  184. * Return Values:
  185. * FAIL : return value = 0
  186. * PASS : return value = 1
  187. *
  188. ***********************************************************/
  189. uint8_t ReadZero( void )
  190. {
  191. volatile uint8_t r;
  192. for(r=0;r<8;r++)
  193. {
  194. if(dataC[j] != 0x00)
  195. {
  196. return MARCHC_RAM_TEST_FAIL;
  197. }
  198. }
  199. return MARCHC_RAM_TEST_PASS;
  200. }