hello.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include "io.h"
  4. #include "console.h"
  5. void die(void)
  6. {
  7. while (1)
  8. ;
  9. }
  10. #define SDRAM_ADDR 0x40000000
  11. #define SDRAM_SIZE (32 << 20)
  12. static void write_check(volatile uint32_t *p, uint32_t v)
  13. {
  14. uint32_t rb;
  15. *p = v;
  16. rb = *p;
  17. if (v != rb)
  18. con_printf("\r%p : read %08x wrote %08x\r\n", p, rb, v);
  19. }
  20. static void test_sdram(void)
  21. {
  22. uint32_t * const sdram_start = (uint32_t *)SDRAM_ADDR;
  23. uint32_t * const sdram_end = (uint32_t *)(SDRAM_ADDR + SDRAM_SIZE);
  24. volatile uint32_t *p;
  25. con_printf("Testing SDRAM from %p to %p...\r\n", sdram_start, sdram_end);
  26. for (p = sdram_start ; p < sdram_end ; p++) {
  27. uint32_t a = (uint32_t)p;
  28. if (!(a & 0xffff))
  29. con_printf("\r%p ", p);
  30. write_check(p, 0);
  31. write_check(p, ~0);
  32. write_check(p, ~a);
  33. write_check(p, a);
  34. }
  35. con_puts("\rReading back to check for aliases...\r\n");
  36. for (p = sdram_start ; p < sdram_end ; p++) {
  37. uint32_t a = (uint32_t)p;
  38. uint32_t v = *p;
  39. if (!(a & 0xffff))
  40. con_printf("\r%p ", p);
  41. #if 0
  42. if (v != a)
  43. con_printf("\r%p : read %08x expected %08x\r\n", p, v, a);
  44. #endif
  45. }
  46. con_puts("\rSDRAM test complete\r\n");
  47. }
  48. void main(void)
  49. {
  50. static const char hello[] = "\r\n\nHello, World!\r\n";
  51. uint8_t led = 0;
  52. unsigned int loops = 0;
  53. con_set_baudrate(115200);
  54. set_led(led = 0);
  55. con_puts(hello);
  56. while ( 1 ) {
  57. test_sdram();
  58. led = (led << 1) | ((~led >> 2) & 1);
  59. set_led(led);
  60. udelay(400000);
  61. loops++;
  62. con_printf("Loops: %u\r\n\n", loops);
  63. }
  64. die();
  65. }