aboutsummaryrefslogtreecommitdiff
path: root/projects/board-test/fmc-probe.c
blob: 38897aba3b1f0f0f3a037c16cb02e1dcdadc390f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Read all registers from the FPGA. In some cases, this will be garbage;
 * in other cases, it will be the core name and version strings.
 */

#include "stm-init.h"
#include "stm-led.h"
#include "stm-fmc.h"
#include "stm-uart.h"

#define CORE_SIZE               (0x100)
#define SEGMENT_SIZE            (0x40 * CORE_SIZE)
#define SEGMENT_OFFSET_GLOBALS  (0 * SEGMENT_SIZE)
#define SEGMENT_OFFSET_HASHES   (1 * SEGMENT_SIZE)
#define BOARD_ADDR_BASE         (SEGMENT_OFFSET_GLOBALS + (0 * CORE_SIZE))
#define COMM_ADDR_BASE          (SEGMENT_OFFSET_GLOBALS + (1 * CORE_SIZE))
#define SHA1_ADDR_BASE          (SEGMENT_OFFSET_HASHES + (0 * CORE_SIZE))
#define SHA256_ADDR_BASE        (SEGMENT_OFFSET_HASHES + (1 * CORE_SIZE))
#define SHA512_ADDR_BASE        (SEGMENT_OFFSET_HASHES + (2 * CORE_SIZE))

static uint32_t read0(uint32_t addr)
{
    uint32_t data;

    fmc_read_32(addr, &data);

    return data;
}

int main(void)
{
  stm_init();
  led_on(LED_GREEN);

  for (uint32_t addr = 0; addr < 0x00080000; addr += 4) {
      uint32_t data = read0(addr);
      if (data != 0) {
	  uart_send_hex(addr, 8);
	  uart_send_string(": ");
	  uart_send_hex(data, 8);
    uart_send_char(' ');
    for (int i = 24; i >= 0; i -= 8) {
	uint8_t c = (data >> i) & 0xff;
	if (c < 0x20 || c > 0x7e)
	    uart_send_char('.');
	else
	    uart_send_char(c);
    }
	  uart_send_string("\r\n");
      }
  }
  uart_send_string("Done.\r\n");

  return 0;
}