mem_tests.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * @brief Generic memory tests
  3. * Various memory tests for testing external memory integrity. Includes
  4. * inverse address, walking bit, and pattern tests.
  5. *
  6. * @note
  7. * Copyright(C) NXP Semiconductors, 2012
  8. * All rights reserved.
  9. *
  10. * @par
  11. * Software that is described herein is for illustrative purposes only
  12. * which provides customers with programming information regarding the
  13. * LPC products. This software is supplied "AS IS" without any warranties of
  14. * any kind, and NXP Semiconductors and its licensor disclaim any and
  15. * all warranties, express or implied, including all implied warranties of
  16. * merchantability, fitness for a particular purpose and non-infringement of
  17. * intellectual property rights. NXP Semiconductors assumes no responsibility
  18. * or liability for the use of the software, conveys no license or rights under any
  19. * patent, copyright, mask work right, or any other intellectual property rights in
  20. * or to any products. NXP Semiconductors reserves the right to make changes
  21. * in the software without notification. NXP Semiconductors also makes no
  22. * representation or warranty that such application will be suitable for the
  23. * specified use without further testing or modification.
  24. *
  25. * @par
  26. * Permission to use, copy, modify, and distribute this software and its
  27. * documentation is hereby granted, under NXP Semiconductors' and its
  28. * licensor's relevant copyrights in the software, without fee, provided that it
  29. * is used in conjunction with NXP Semiconductors microcontrollers. This
  30. * copyright, permission, and disclaimer notice must appear in all copies of
  31. * this code.
  32. */
  33. #include "mem_tests.h"
  34. /*****************************************************************************
  35. * Private types/enumerations/variables
  36. ****************************************************************************/
  37. /*****************************************************************************
  38. * Public types/enumerations/variables
  39. ****************************************************************************/
  40. /*****************************************************************************
  41. * Private functions
  42. ****************************************************************************/
  43. /*****************************************************************************
  44. * Public functions
  45. ****************************************************************************/
  46. /* Walking 0 memory test */
  47. bool mem_test_walking0(MEM_TEST_SETUP_T *pMemSetup)
  48. {
  49. int i = 0;
  50. uint32_t fbytes = pMemSetup->bytes, *addr = pMemSetup->start_addr;
  51. /* Must be 32-bit algined */
  52. if ((((uint32_t) addr & 0x3) != 0) || ((fbytes & 0x3) != 0)) {
  53. return false;
  54. }
  55. /* Write walking 0 pattern */
  56. while (fbytes > 0) {
  57. *addr = ~(1 << i);
  58. addr++;
  59. fbytes -= 4;
  60. i++;
  61. if (i >= 32) {
  62. i = 0;
  63. }
  64. }
  65. /* Verify walking 0 pattern */
  66. i = 0;
  67. fbytes = pMemSetup->bytes;
  68. addr = pMemSetup->start_addr;
  69. while (fbytes > 0) {
  70. if (*addr != ~(1 << i)) {
  71. pMemSetup->fail_addr = addr;
  72. pMemSetup->is_val = *addr;
  73. pMemSetup->ex_val = ~(1 << i);
  74. return false;
  75. }
  76. addr++;
  77. fbytes -= 4;
  78. i++;
  79. if (i >= 32) {
  80. i = 0;
  81. }
  82. }
  83. return true;
  84. }
  85. /* Walking 1 memory test */
  86. bool mem_test_walking1(MEM_TEST_SETUP_T *pMemSetup)
  87. {
  88. int i = 0;
  89. uint32_t fbytes = pMemSetup->bytes, *addr = pMemSetup->start_addr;
  90. /* Must be 32-bit algined */
  91. if ((((uint32_t) addr & 0x3) != 0) || ((fbytes & 0x3) != 0)) {
  92. return false;
  93. }
  94. /* Write walking 1 pattern */
  95. while (fbytes > 0) {
  96. *addr = (1 << i);
  97. addr++;
  98. fbytes -= 4;
  99. i++;
  100. if (i >= 32) {
  101. i = 0;
  102. }
  103. }
  104. /* Verify walking 1 pattern */
  105. i = 0;
  106. fbytes = pMemSetup->bytes;
  107. addr = pMemSetup->start_addr;
  108. while (fbytes > 0) {
  109. if (*addr != (1 << i)) {
  110. pMemSetup->fail_addr = addr;
  111. pMemSetup->is_val = *addr;
  112. pMemSetup->ex_val = (1 << i);
  113. return false;
  114. }
  115. addr++;
  116. fbytes -= 4;
  117. i++;
  118. if (i >= 32) {
  119. i = 0;
  120. }
  121. }
  122. return true;
  123. }
  124. /* Address memory test */
  125. bool mem_test_address(MEM_TEST_SETUP_T *pMemSetup)
  126. {
  127. uint32_t fbytes = pMemSetup->bytes, *addr = pMemSetup->start_addr;
  128. /* Must be 32-bit algined */
  129. if ((((uint32_t) addr & 0x3) != 0) || ((fbytes & 0x3) != 0)) {
  130. return false;
  131. }
  132. /* Write address for memory location */
  133. while (fbytes > 0) {
  134. *addr = (uint32_t) addr;
  135. addr++;
  136. fbytes -= 4;
  137. }
  138. /* Verify address for memory location */
  139. fbytes = pMemSetup->bytes;
  140. addr = pMemSetup->start_addr;
  141. while (fbytes > 0) {
  142. if (*addr != (uint32_t) addr) {
  143. pMemSetup->fail_addr = addr;
  144. pMemSetup->is_val = *addr;
  145. pMemSetup->ex_val = (uint32_t) addr;
  146. return false;
  147. }
  148. addr++;
  149. fbytes -= 4;
  150. }
  151. return true;
  152. }
  153. /* Inverse address memory test */
  154. bool mem_test_invaddress(MEM_TEST_SETUP_T *pMemSetup)
  155. {
  156. uint32_t fbytes = pMemSetup->bytes, *addr = pMemSetup->start_addr;
  157. /* Must be 32-bit algined */
  158. if ((((uint32_t) addr & 0x3) != 0) || ((fbytes & 0x3) != 0)) {
  159. return false;
  160. }
  161. /* Write inverse address for memory location */
  162. while (fbytes > 0) {
  163. *addr = ~(uint32_t) addr;
  164. addr++;
  165. fbytes -= 4;
  166. }
  167. /* Verify inverse address for memory location */
  168. fbytes = pMemSetup->bytes;
  169. addr = pMemSetup->start_addr;
  170. while (fbytes > 0) {
  171. if (*addr != ~(uint32_t) addr) {
  172. pMemSetup->fail_addr = addr;
  173. pMemSetup->is_val = *addr;
  174. pMemSetup->ex_val = ~(uint32_t) addr;
  175. return false;
  176. }
  177. addr++;
  178. fbytes -= 4;
  179. }
  180. return true;
  181. }
  182. /* Pattern memory test */
  183. bool mem_test_pattern(MEM_TEST_SETUP_T *pMemSetup)
  184. {
  185. uint32_t fbytes = pMemSetup->bytes, *addr = pMemSetup->start_addr;
  186. uint32_t pattern = 0x55AA55AA;
  187. /* Must be 32-bit algined */
  188. if ((((uint32_t) addr & 0x3) != 0) || ((fbytes & 0x3) != 0)) {
  189. return false;
  190. }
  191. /* Write pattern for memory location */
  192. while (fbytes > 0) {
  193. *addr = pattern;
  194. pattern = ~pattern;
  195. addr++;
  196. fbytes -= 4;
  197. }
  198. /* Verify pattern for memory location */
  199. pattern = 0x55AA55AA;
  200. fbytes = pMemSetup->bytes;
  201. addr = pMemSetup->start_addr;
  202. while (fbytes > 0) {
  203. if (*addr != pattern) {
  204. pMemSetup->fail_addr = addr;
  205. pMemSetup->is_val = *addr;
  206. pMemSetup->ex_val = pattern;
  207. return false;
  208. }
  209. pattern = ~pattern;
  210. addr++;
  211. fbytes -= 4;
  212. }
  213. return true;
  214. }
  215. /* Pattern memory test with seed and increment value */
  216. bool mem_test_pattern_seed(MEM_TEST_SETUP_T *pMemSetup, uint32_t seed, uint32_t incr)
  217. {
  218. uint32_t fbytes = pMemSetup->bytes, *addr = pMemSetup->start_addr;
  219. uint32_t pattern = seed;
  220. /* Must be 32-bit algined */
  221. if ((((uint32_t) addr & 0x3) != 0) || ((fbytes & 0x3) != 0)) {
  222. return false;
  223. }
  224. /* Write pattern for memory location */
  225. while (fbytes > 0) {
  226. *addr = pattern;
  227. pattern += incr;
  228. addr++;
  229. fbytes -= 4;
  230. }
  231. /* Verify pattern for memory location */
  232. pattern = seed;
  233. fbytes = pMemSetup->bytes;
  234. addr = pMemSetup->start_addr;
  235. while (fbytes > 0) {
  236. if (*addr != pattern) {
  237. pMemSetup->fail_addr = addr;
  238. pMemSetup->is_val = *addr;
  239. pMemSetup->ex_val = pattern;
  240. return false;
  241. }
  242. pattern += incr;
  243. addr++;
  244. fbytes -= 4;
  245. }
  246. return true;
  247. }