OpenCores
URL https://opencores.org/ocsvn/potato/potato/trunk

Subversion Repositories potato

[/] [potato/] [trunk/] [benchmarks/] [sha256/] [main.c] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 skordal
// The Potato Processor Benchmark Applications
2
// (c) Kristian Klomsten Skordal 2015 <kristian.skordal@wafflemail.net>
3
// Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4
 
5
#include <stdbool.h>
6
#include <stdint.h>
7
 
8
#include "platform.h"
9
#include "potato.h"
10
 
11
#include "gpio.h"
12
#include "sha256.h"
13
#include "timer.h"
14
#include "uart.h"
15
 
16
static int led_status = 0;
17
static volatile int hashes_per_second = 0;
18
 
19
void exception_handler(uint32_t cause, void * epc)
20
{
21
        uart_puts(IO_ADDRESS(UART_BASE), "Hashes per second: ");
22
        uart_puth(IO_ADDRESS(UART_BASE), hashes_per_second);
23
        uart_puts(IO_ADDRESS(UART_BASE), "\n\r");
24
 
25
        if(led_status == 0)
26
        {
27
                gpio_set_output(IO_ADDRESS(GPIO2_BASE), 1);
28
                led_status = 1;
29
        } else {
30
                gpio_set_output(IO_ADDRESS(GPIO2_BASE), 0);
31
                led_status = 0;
32
        }
33
 
34
        timer_reset(IO_ADDRESS(TIMER_BASE));
35
        hashes_per_second = 0;
36
}
37
 
38
int main(void)
39
{
40
        // Configure GPIOs:
41
        gpio_set_direction(IO_ADDRESS(GPIO1_BASE), 0x0000); // Switches
42
        gpio_set_direction(IO_ADDRESS(GPIO2_BASE), 0xffff); // LEDs
43
 
44
        // Set up the timer:
45
        timer_set(IO_ADDRESS(TIMER_BASE), 50000000);
46
 
47
        // Print a startup message:
48
        uart_puts(IO_ADDRESS(UART_BASE), "The Potato Processor SHA256 Benchmark\n\r\n\r");
49
 
50
        // Enable interrupts:
51
        potato_enable_irq(TIMER_IRQ);
52
        potato_enable_interrupts();
53
 
54
        struct sha256_context context;
55
 
56
        // Prepare a block for hashing:
57
        uint32_t block[16];
58
        uint8_t * block_ptr = (uint8_t *) block;
59
        block_ptr[0] = 'a';
60
        block_ptr[1] = 'b';
61
        block_ptr[2] = 'c';
62
        sha256_pad_le_block(block_ptr, 3, 3);
63
 
64
        // Repeatedly hash the same data over and over again:
65
        while(true)
66
        {
67
                uint8_t hash[32];
68
 
69
                sha256_reset(&context);
70
                sha256_hash_block(&context, block);
71
                sha256_get_hash(&context, hash);
72
                ++hashes_per_second;
73
        }
74
 
75
        return 0;
76
}
77
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.