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

Subversion Repositories potato

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

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

powered by: WebSVN 2.1.0

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