sysinfo.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include <arm/NXP/LPC17xx/LPC17xx.h>
  2. #include <arm/bits.h>
  3. #include <string.h>
  4. #include "config.h"
  5. #include "diskio.h"
  6. #include "ff.h"
  7. #include "timer.h"
  8. #include "uart.h"
  9. #include "fileops.h"
  10. #include "memory.h"
  11. #include "snes.h"
  12. #include "fpga.h"
  13. #include "fpga_spi.h"
  14. #include "cic.h"
  15. #include "sdnative.h"
  16. #include "sysinfo.h"
  17. static uint32_t sd_tacc_max, sd_tacc_avg;
  18. void sysinfo_loop()
  19. {
  20. sd_tacc_max = 0;
  21. sd_tacc_avg = 0;
  22. while ( sram_readbyte( SRAM_CMD_ADDR ) != 0x00 )
  23. {
  24. write_sysinfo();
  25. delay_ms( 100 );
  26. }
  27. }
  28. void write_sysinfo()
  29. {
  30. uint32_t sram_addr = SRAM_SYSINFO_ADDR;
  31. char linebuf[40];
  32. int len;
  33. int sd_ok = 0;
  34. uint8_t *sd_cid = sdn_getcid();
  35. uint32_t sd_tacc_max_int = sd_tacc_max / 1000;
  36. uint32_t sd_tacc_max_frac = sd_tacc_max - ( sd_tacc_max_int * 1000 );
  37. uint32_t sd_tacc_avg_int = sd_tacc_avg / 1000;
  38. uint32_t sd_tacc_avg_frac = sd_tacc_avg - ( sd_tacc_avg_int * 1000 );
  39. uint16_t numfiles = sram_readshort( SRAM_DB_ADDR + 12 );
  40. uint16_t numdirs = sram_readshort( SRAM_DB_ADDR + 14 );
  41. int32_t sysclk = get_snes_sysclk();
  42. len = snprintf( linebuf, sizeof( linebuf ), "Firmware version: %s", CONFIG_VERSION );
  43. sram_writeblock( linebuf, sram_addr, 40 );
  44. sram_memset( sram_addr + len, 40 - len, 0x20 );
  45. sram_addr += 40;
  46. len = snprintf( linebuf, sizeof( linebuf ), " " );
  47. sram_writeblock( linebuf, sram_addr, 40 );
  48. sram_memset( sram_addr + len, 40 - len, 0x20 );
  49. sram_addr += 40;
  50. if ( disk_state == DISK_REMOVED )
  51. {
  52. sd_tacc_max = 0;
  53. sd_tacc_avg = 0;
  54. len = snprintf( linebuf, sizeof( linebuf ), " " );
  55. sram_writeblock( linebuf, sram_addr, 40 );
  56. sram_memset( sram_addr + len, 40 - len, 0x20 );
  57. sram_addr += 40;
  58. len = snprintf( linebuf, sizeof( linebuf ), " *** SD Card removed *** " );
  59. sram_writeblock( linebuf, sram_addr, 40 );
  60. sram_memset( sram_addr + len, 40 - len, 0x20 );
  61. sram_addr += 40;
  62. len = snprintf( linebuf, sizeof( linebuf ), " " );
  63. sram_writeblock( linebuf, sram_addr, 40 );
  64. sram_memset( sram_addr + len, 40 - len, 0x20 );
  65. sram_addr += 40;
  66. len = snprintf( linebuf, sizeof( linebuf ), " " );
  67. sram_writeblock( linebuf, sram_addr, 40 );
  68. sram_memset( sram_addr + len, 40 - len, 0x20 );
  69. sram_addr += 40;
  70. sd_ok = 0;
  71. }
  72. else
  73. {
  74. len = snprintf( linebuf, sizeof( linebuf ), "SD Maker/OEM: 0x%02x, \"%c%c\"", sd_cid[1], sd_cid[2], sd_cid[3] );
  75. sram_writeblock( linebuf, sram_addr, 40 );
  76. sram_memset( sram_addr + len, 40 - len, 0x20 );
  77. sram_addr += 40;
  78. len = snprintf( linebuf, sizeof( linebuf ), "SD Product Name: \"%c%c%c%c%c\", Rev. %d.%d", sd_cid[4], sd_cid[5],
  79. sd_cid[6], sd_cid[7], sd_cid[8], sd_cid[9] >> 4, sd_cid[9] & 15 );
  80. sram_writeblock( linebuf, sram_addr, 40 );
  81. sram_memset( sram_addr + len, 40 - len, 0x20 );
  82. sram_addr += 40;
  83. len = snprintf( linebuf, sizeof( linebuf ), "SD Serial No.: %02x%02x%02x%02x, Mfd. %d/%02d", sd_cid[10], sd_cid[11],
  84. sd_cid[12], sd_cid[13], 2000 + ( ( sd_cid[14] & 15 ) << 4 ) + ( sd_cid[15] >> 4 ), sd_cid[15] & 15 );
  85. sram_writeblock( linebuf, sram_addr, 40 );
  86. sram_memset( sram_addr + len, 40 - len, 0x20 );
  87. sram_addr += 40;
  88. if ( sd_tacc_max )
  89. {
  90. len = snprintf( linebuf, sizeof( linebuf ), "SD acc. time: %ld.%03ld / %ld.%03ld ms avg/max", sd_tacc_avg_int,
  91. sd_tacc_avg_frac, sd_tacc_max_int, sd_tacc_max_frac );
  92. }
  93. else
  94. {
  95. len = snprintf( linebuf, sizeof( linebuf ), "SD acc. time: measuring... " );
  96. }
  97. sram_writeblock( linebuf, sram_addr, 40 );
  98. sram_memset( sram_addr + len, 40 - len, 0x20 );
  99. sram_addr += 40;
  100. sd_ok = 1;
  101. }
  102. len = snprintf( linebuf, sizeof( linebuf ), " " );
  103. sram_writeblock( linebuf, sram_addr, 40 );
  104. sram_memset( sram_addr + len, 40 - len, 0x20 );
  105. sram_addr += 40;
  106. len = snprintf( linebuf, sizeof( linebuf ), "CIC state: %s", get_cic_statefriendlyname( get_cic_state() ) );
  107. sram_writeblock( linebuf, sram_addr, 40 );
  108. sram_memset( sram_addr + len, 40 - len, 0x20 );
  109. sram_addr += 40;
  110. if ( sysclk == -1 )
  111. {
  112. len = snprintf( linebuf, sizeof( linebuf ), "SNES master clock: measuring..." );
  113. }
  114. else
  115. {
  116. len = snprintf( linebuf, sizeof( linebuf ), "SNES master clock: %ldHz ", get_snes_sysclk() );
  117. }
  118. sram_writeblock( linebuf, sram_addr, 40 );
  119. sram_memset( sram_addr + len, 40 - len, 0x20 );
  120. sram_addr += 40;
  121. len = snprintf( linebuf, sizeof( linebuf ), " " );
  122. sram_writeblock( linebuf, sram_addr, 40 );
  123. sram_memset( sram_addr + len, 40 - len, 0x20 );
  124. sram_addr += 40;
  125. len = snprintf( linebuf, sizeof( linebuf ), "Database: %d files, %d dirs", numfiles, numdirs );
  126. sram_writeblock( linebuf, sram_addr, 40 );
  127. sram_memset( sram_addr + len, 40 - len, 0x20 );
  128. sram_addr += 40;
  129. len = snprintf( linebuf, sizeof( linebuf ), " " );
  130. sram_writeblock( linebuf, sram_addr, 40 );
  131. sram_memset( sram_addr + len, 40 - len, 0x20 );
  132. sram_addr += 40;
  133. len = snprintf( linebuf, sizeof( linebuf ), " " );
  134. sram_writeblock( linebuf, sram_addr, 40 );
  135. sram_memset( sram_addr + len, 40 - len, 0x20 );
  136. sram_hexdump( SRAM_SYSINFO_ADDR, 13 * 40 );
  137. if ( sysclk != -1 && sd_ok )
  138. {
  139. sdn_gettacc( &sd_tacc_max, &sd_tacc_avg );
  140. }
  141. }