// Handle an exception/interrupt. // Arguments: // - cause: exception cause, see potato.h for values // - epc: exception return address // - regbase: base of the stored context, can be used for printing all // registers with regbase[0] = x1 and upwards. void exception_handler(uint32_t cause, void * epc, void * regbase) { if(cause == ((1 << CAUSE_INTERRUPT_BIT) | (CAUSE_IRQ_BASE + 5))) // Timer interrupt { uart_puts(IO_ADDRESS(UART_BASE), "Hashes per second: "); uart_puth(IO_ADDRESS(UART_BASE), hashes_per_second); uart_puts(IO_ADDRESS(UART_BASE), "\n\r"); seg7_set_value(IO_ADDRESS(SEG7_BASE), hashes_per_second); if(led_status == 0) { gpio_set_output(IO_ADDRESS(GPIO2_BASE), 1); led_status = 1; } else { gpio_set_output(IO_ADDRESS(GPIO2_BASE), 0); led_status = 0; } hashes_per_second = 0; timer_reset(IO_ADDRESS(TIMER_BASE)); } else { uart_puts(IO_ADDRESS(UART_BASE), "Unhandled exception!\n\r"); uart_puts(IO_ADDRESS(UART_BASE), "Cause: "); uart_puth(IO_ADDRESS(UART_BASE), cause); uart_puts(IO_ADDRESS(UART_BASE), "\n\r"); uart_puts(IO_ADDRESS(UART_BASE), "EPC: "); uart_puth(IO_ADDRESS(UART_BASE), (uint32_t) epc); uart_puts(IO_ADDRESS(UART_BASE), "\n\r"); while(1) asm volatile("nop\n"); } }
int main(void){ uart_init(); uart_puts_P(PSTR("\nETHERNET TEST > PROGRAM STARTED\n")); uart_puts_P(PSTR("UART initiated\n")); startSPI(); uint16_t v = socketNumberToAddress(2); uint8_t a[] = {v<<8, v|0xFF}; uart_puth(a , 2); uart_puts_P(PSTR("\n\n")); uart_putn(pgm_read_byte(var) & 0xFF); halt(); return 0; }