aboutsummaryrefslogtreecommitdiff
path: root/sw/test-sha256/test-sha256.c
blob: 9f7b3313030a7627b536c5a9fbfae29ec314c338 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//======================================================================
//
// test-sha256.c
// -------------
// test program for Cryptech Novena framwwork with EIM interface
// using the sha256 core.
//
//======================================================================

//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "novena-eim.h"


//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
#define SHA256_PREFIX (0x0000)
#define SHA_BASE (EIM_BASE_ADDR + SHA256_PREFIX)

#define DEMO_ADDER_BASE_ADDR (EIM_BASE_ADDR + 0x0000)
#define DEMO_ADDER_X_REG     (DEMO_ADDER_BASE_ADDR + 0)
#define DEMO_ADDER_Y_REG     (DEMO_ADDER_BASE_ADDR + 4)


//------------------------------------------------------------------------------
// Testing Parameters
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_regs() 
{
  unsigned int read_addr;
  unsigned int read_data;
  unsigned int write_addr;
  unsigned int write_data;
  unsigned int i;

//
//  for (i = 0 ; i < 0x40000 ; i += 4) {
//    read_addr = EIM_BASE_ADDR + i;
//    eim_read_32(read_addr, &read_data);
//    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
//  }

  read_addr = DEMO_ADDER_X_REG;
  eim_read_32(read_addr, &read_data);
  printf("address 0x%08x = 0x%08x\n", read_addr, read_data);

  read_addr = DEMO_ADDER_Y_REG;
  eim_read_32(read_addr, &read_data);
  printf("address 0x%08x = 0x%08x\n", read_addr, read_data);

  write_addr = DEMO_ADDER_Y_REG;
  write_data = 0xaa55aa55;
  eim_write_32(write_addr, &write_data);

  read_addr = DEMO_ADDER_Y_REG;
  eim_read_32(read_addr, &read_data);
  printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_sha256()
{
  unsigned int write_addr;
  unsigned int write_data;
  unsigned int read_addr;
  unsigned int read_data;
  int ok;
  unsigned int i;

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Try to iniate block processing and then dump 
  write_addr = SHA_BASE + 0x20;
  write_data = 0x00000001;
  eim_write_32(write_addr, &write_data);

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

}

//------------------------------------------------------------------------------
// main()
//------------------------------------------------------------------------------
int main()
{
  int ok;
  unsigned int i;

  // try to setup eim (return value should be 1)
  printf("Configuring EIM .. ");
  ok = eim_setup();
  if (ok < 1) {
    printf("ERROR\n");
    return EXIT_FAILURE;
  }
  else {
    printf("EIM Setup ok.\n");
  }

  test_sha256();

  return 0;
}

//======================================================================
// EOF test-sha256.c
//======================================================================