dump.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. *
  11. * www.optixx.org
  12. *
  13. *
  14. * Version: 1.0
  15. * Created: 07/21/2009 03:32:16 PM
  16. * Author: david@optixx.org
  17. *
  18. * =====================================================================================
  19. */
  20. #include <stdlib.h>
  21. #include <stdint.h>
  22. #include "debug.h"
  23. #include "info.h"
  24. #include "uart.h"
  25. #include "sram.h"
  26. #include "dump.h"
  27. extern FILE uart_stdout;
  28. void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
  29. {
  30. uint16_t i, j;
  31. uint16_t sum = 0;
  32. uint8_t clear = 0;
  33. for (i = 0; i < len; i += 16) {
  34. sum = 0;
  35. for (j = 0; j < 16; j++) {
  36. sum += packet[i + j];
  37. }
  38. if (!sum) {
  39. clear = 1;
  40. continue;
  41. }
  42. if (clear) {
  43. info_P(PSTR("*\n"));
  44. clear = 0;
  45. }
  46. info_P(PSTR("%08lx:"), addr + i);
  47. for (j = 0; j < 16; j++) {
  48. info_P(PSTR(" %02x"), packet[i + j]);
  49. }
  50. info_P(PSTR(" |"));
  51. for (j = 0; j < 16; j++) {
  52. if (packet[i + j] >= 33 && packet[i + j] <= 126)
  53. info_P(PSTR("%c"), packet[i + j]);
  54. else
  55. info_P(PSTR("."));
  56. }
  57. info_P(PSTR("|\n"));
  58. }
  59. }
  60. void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
  61. {
  62. uint32_t addr;
  63. uint8_t byte;
  64. sram_bulk_read_start(bottom_addr);
  65. for (addr = bottom_addr; addr < top_addr; addr++) {
  66. if (addr % 0x10 == 0)
  67. info_P(PSTR("\n%08lx:"), addr);
  68. byte = sram_bulk_read();
  69. sram_bulk_read_next();
  70. info_P(PSTR(" %02x"), byte);
  71. }
  72. info_P(PSTR("\n"));
  73. sram_bulk_read_end();
  74. }