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

Subversion Repositories potato

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

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 20 skordal
// Handle an exception/interrupt.
20
// Arguments:
21
// - cause: exception cause, see potato.h for values
22
// - epc: exception return address
23
// - regbase: base of the stored context, can be used for printing all
24
//            registers with regbase[0] = x1 and upwards.
25
void exception_handler(uint32_t cause, void * epc, void * regbase)
26 13 skordal
{
27 20 skordal
        if(cause == (CAUSE_IRQ_BASE + 5)) // Timer interrupt
28
        {
29
                uart_puts(IO_ADDRESS(UART_BASE), "Hashes per second: ");
30
                uart_puth(IO_ADDRESS(UART_BASE), hashes_per_second);
31
                uart_puts(IO_ADDRESS(UART_BASE), "\n\r");
32 13 skordal
 
33 20 skordal
                if(led_status == 0)
34
                {
35
                        gpio_set_output(IO_ADDRESS(GPIO2_BASE), 1);
36
                        led_status = 1;
37
                } else {
38
                        gpio_set_output(IO_ADDRESS(GPIO2_BASE), 0);
39
                        led_status = 0;
40
                }
41
 
42
                hashes_per_second = 0;
43
                timer_reset(IO_ADDRESS(TIMER_BASE));
44 13 skordal
        } else {
45 20 skordal
                uart_puts(IO_ADDRESS(UART_BASE), "Unhandled exception!\n\r");
46
                uart_puts(IO_ADDRESS(UART_BASE), "Cause: ");
47
                uart_puth(IO_ADDRESS(UART_BASE), cause);
48
                uart_puts(IO_ADDRESS(UART_BASE), "\n\r");
49
                uart_puts(IO_ADDRESS(UART_BASE), "EPC: ");
50
                uart_puth(IO_ADDRESS(UART_BASE), (uint32_t) epc);
51
                uart_puts(IO_ADDRESS(UART_BASE), "\n\r");
52
 
53
                while(1) asm volatile("nop\n");
54 13 skordal
        }
55
}
56
 
57
int main(void)
58
{
59
        // Configure GPIOs:
60
        gpio_set_direction(IO_ADDRESS(GPIO1_BASE), 0x0000); // Switches
61
        gpio_set_direction(IO_ADDRESS(GPIO2_BASE), 0xffff); // LEDs
62
 
63
        // Set up the timer:
64 20 skordal
        timer_set(IO_ADDRESS(TIMER_BASE), SYSTEM_CLK_FREQ);
65 13 skordal
 
66
        // Print a startup message:
67
        uart_puts(IO_ADDRESS(UART_BASE), "The Potato Processor SHA256 Benchmark\n\r\n\r");
68
 
69
        // Enable interrupts:
70
        potato_enable_irq(TIMER_IRQ);
71
        potato_enable_interrupts();
72
 
73
        struct sha256_context context;
74
 
75
        // Prepare a block for hashing:
76
        uint32_t block[16];
77
        uint8_t * block_ptr = (uint8_t *) block;
78
        block_ptr[0] = 'a';
79
        block_ptr[1] = 'b';
80
        block_ptr[2] = 'c';
81
        sha256_pad_le_block(block_ptr, 3, 3);
82
 
83
        // Repeatedly hash the same data over and over again:
84
        while(true)
85
        {
86
                uint8_t hash[32];
87
 
88
                sha256_reset(&context);
89
                sha256_hash_block(&context, block);
90
                sha256_get_hash(&context, hash);
91
                ++hashes_per_second;
92
        }
93
 
94
        return 0;
95
}
96
 

powered by: WebSVN 2.1.0

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