ecctest.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. indent: Standard input:27: Warning:old style assignment ambiguity in "=*". Assuming "= *"
  2. #ifdef ECC_TEST
  3. static inline void ecc_off (void)
  4. {
  5. *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) &= ~0x00200000;
  6. }
  7. static inline void ecc_on (void)
  8. {
  9. *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) |= 0x00200000;
  10. }
  11. static int putshex (const char *buf, int len)
  12. {
  13. int i;
  14. for (i = 0; i < len; i++) {
  15. printf ("%02x", buf[i]);
  16. }
  17. return 0;
  18. }
  19. static int char_memcpy (void *d, const void *s, int len)
  20. {
  21. int i;
  22. char *cd = d;
  23. const char *cs = s;
  24. for (i = 0; i < len; i++) {
  25. *(cd++) = *(cs++);
  26. }
  27. return 0;
  28. }
  29. static int memory_test (char *buf)
  30. {
  31. const char src[][16] = {
  32. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  33. {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  34. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  35. {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
  36. 0x02, 0x02, 0x02, 0x02, 0x02, 0x02},
  37. {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  38. 0x04, 0x04, 0x04, 0x04, 0x04, 0x04},
  39. {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  40. 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
  41. {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  42. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
  43. {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  44. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20},
  45. {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
  46. 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
  47. {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  48. 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
  49. {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  50. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55},
  51. {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  52. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa},
  53. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  54. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
  55. };
  56. const int foo[] = { 0 };
  57. int i, j, a;
  58. printf ("\ntest @ %d %p\n", foo[0], buf);
  59. for (i = 0; i < 12; i++) {
  60. for (a = 0; a < 8; a++) {
  61. const char *s = src[i] + a;
  62. int align = (unsigned) (s) & 0x7;
  63. /* ecc_off(); */
  64. memcpy (buf, s, 8);
  65. /* ecc_on(); */
  66. putshex (s, 8);
  67. if (memcmp (buf, s, 8)) {
  68. putc ('\n');
  69. putshex (buf, 8);
  70. printf (" [FAIL] (%p) align=%d\n", s, align);
  71. for (j = 0; j < 8; j++) {
  72. s[j] == buf[j] ? puts (" ") :
  73. printf ("%02x",
  74. (s[j]) ^ (buf[j]));
  75. }
  76. putc ('\n');
  77. } else {
  78. printf (" [PASS] (%p) align=%d\n", s, align);
  79. }
  80. /* ecc_off(); */
  81. char_memcpy (buf, s, 8);
  82. /* ecc_on(); */
  83. putshex (s, 8);
  84. if (memcmp (buf, s, 8)) {
  85. putc ('\n');
  86. putshex (buf, 8);
  87. printf (" [FAIL] (%p) align=%d\n", s, align);
  88. for (j = 0; j < 8; j++) {
  89. s[j] == buf[j] ? puts (" ") :
  90. printf ("%02x",
  91. (s[j]) ^ (buf[j]));
  92. }
  93. putc ('\n');
  94. } else {
  95. printf (" [PASS] (%p) align=%d\n", s, align);
  96. }
  97. }
  98. }
  99. return 0;
  100. }
  101. #endif