Moved drivers to subdirectory, use vectored exception model.
This commit is contained in:
parent
06cbbf0694
commit
2237b19be9
|
@ -19,5 +19,6 @@ sys_ret_t xilinx_gpio_pinmode(xilinx_gpio_handle_t *handle, uint32_t pin, uint8_
|
||||||
sys_ret_t xilinx_gpio_write(xilinx_gpio_handle_t *handle, uint32_t pin, uint8_t value);
|
sys_ret_t xilinx_gpio_write(xilinx_gpio_handle_t *handle, uint32_t pin, uint8_t value);
|
||||||
uint8_t xilinx_gpio_read(xilinx_gpio_handle_t *handle, uint32_t pin);
|
uint8_t xilinx_gpio_read(xilinx_gpio_handle_t *handle, uint32_t pin);
|
||||||
sys_ret_t xilinx_gpio_toggle(xilinx_gpio_handle_t *handle, uint32_t pin);
|
sys_ret_t xilinx_gpio_toggle(xilinx_gpio_handle_t *handle, uint32_t pin);
|
||||||
|
sys_ret_t xilinx_gpio_port_mode(xilinx_gpio_handle_t *handle, uint8_t bank, uint32_t output_mask);
|
||||||
|
sys_ret_t xilinx_gpio_port_write(xilinx_gpio_handle_t *handle, uint8_t bank, uint32_t value);
|
||||||
#endif
|
#endif
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef __SOC_PERIPHERALS_H
|
#ifndef __SOC_PERIPHERALS_H
|
||||||
#define __SOC_PERIPHERALS_H
|
#define __SOC_PERIPHERALS_H
|
||||||
|
|
||||||
#include "xilinx_uartlite.h"
|
#include "drivers/xilinx_uartlite.h"
|
||||||
#include "xilinx_gpio.h"
|
#include "drivers/xilinx_gpio.h"
|
||||||
#include "xilinx_timer.h"
|
#include "drivers/xilinx_timer.h"
|
||||||
|
|
||||||
#include "flute_system.h"
|
#include "flute_system.h"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "xilinx_gpio.h"
|
#include "drivers/xilinx_gpio.h"
|
||||||
|
|
||||||
sys_ret_t xilinx_gpio_init(xilinx_gpio_handle_t *handle) {
|
sys_ret_t xilinx_gpio_init(xilinx_gpio_handle_t *handle) {
|
||||||
handle->instance->TRI = 0xFFFFFFFF;
|
handle->instance->TRI = 0xFFFFFFFF;
|
||||||
|
@ -33,3 +33,25 @@ sys_ret_t xilinx_gpio_toggle(xilinx_gpio_handle_t *handle, uint32_t pin) {
|
||||||
handle->instance->DATA ^= (1U << pin);
|
handle->instance->DATA ^= (1U << pin);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sys_ret_t xilinx_gpio_port_mode(xilinx_gpio_handle_t *handle, uint8_t bank, uint32_t output_mask) {
|
||||||
|
if(bank == 0) {
|
||||||
|
handle->instance->TRI = ~output_mask;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
handle->instance->TRI2 = ~output_mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
sys_ret_t xilinx_gpio_port_write(xilinx_gpio_handle_t *handle, uint8_t bank, uint32_t value) {
|
||||||
|
if(bank == 0) {
|
||||||
|
handle->instance->DATA = value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
handle->instance->DATA2 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
#include "xilinx_timer.h"
|
#include "drivers/xilinx_timer.h"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "xilinx_uartlite.h"
|
#include "drivers/xilinx_uartlite.h"
|
||||||
|
|
||||||
sys_ret_t xilinx_uartlite_init(xilinx_uartlite_handle_t *handle) {
|
sys_ret_t xilinx_uartlite_init(xilinx_uartlite_handle_t *handle) {
|
||||||
handle->instance->CTRL |= 0x03; // Reset FIFO
|
handle->instance->CTRL |= 0x03; // Reset FIFO
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
#include "flute_system.h"
|
#include "flute_system.h"
|
||||||
#include "soc_peripherals.h"
|
#include "soc_peripherals.h"
|
||||||
|
|
||||||
void Timer_IRQHandler(void) {
|
__attribute__((interrupt)) void Default_IRQHandler(void) {
|
||||||
SysTick++;
|
for(;;) {
|
||||||
*(uint64_t *)(CLINT_BASE + 0x4000) = SYS_TICK_STEP;
|
//
|
||||||
*(uint64_t *)(CLINT_BASE + 0xBFF8) = 0ULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((interrupt)) void Exception_Handler(void) {
|
|
||||||
uint64_t mcause = 0;
|
|
||||||
|
|
||||||
__csrr("mcause", mcause);
|
|
||||||
|
|
||||||
switch(mcause) {
|
|
||||||
case 0x8000000000000007: // MTIME
|
|
||||||
Timer_IRQHandler();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
for(;;) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((interrupt)) void Timer_IRQHandler(void) {
|
||||||
|
SysTick++;
|
||||||
|
|
||||||
|
uint64_t *mtimecmp = (uint64_t *)(CLINT_BASE + 0x4000);
|
||||||
|
uint64_t *mtime = (uint64_t *)(CLINT_BASE + 0xBFF8);
|
||||||
|
|
||||||
|
*mtimecmp = *mtime + SYS_TICK_STEP; // Interrupt flag will be cleared by a write to MTIMECMP.
|
||||||
|
}
|
11
src/main.c
11
src/main.c
|
@ -22,13 +22,20 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
printf("System clock frequency: %luHz\r\n", SYS_CLK_FREQ);
|
printf("System clock frequency: %luHz\r\n", SYS_CLK_FREQ);
|
||||||
|
|
||||||
xilinx_gpio_pinmode(&soc_gpio, 0, 1);
|
xilinx_gpio_port_mode(&soc_gpio, 0, 0x000000FF); // All output
|
||||||
|
|
||||||
|
uint8_t led_data = 0x01;
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
System_Delay(500);
|
System_Delay(500);
|
||||||
|
|
||||||
__csrr("mcycle", csr);
|
__csrr("mcycle", csr);
|
||||||
printf("mcycle: 0x%016llx\r\n", csr);
|
printf("mcycle: 0x%016llx\r\n", csr);
|
||||||
xilinx_gpio_toggle(&soc_gpio, 0);
|
|
||||||
|
xilinx_gpio_port_write(&soc_gpio, 0, ~led_data);
|
||||||
|
|
||||||
|
led_data <<= 1U;
|
||||||
|
if(led_data == 0) led_data = 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -12,7 +12,7 @@ void System_Init(void) {
|
||||||
xilinx_gpio_pinmode(&soc_gpio, 0, 1);
|
xilinx_gpio_pinmode(&soc_gpio, 0, 1);
|
||||||
|
|
||||||
// Setup interrupt system
|
// Setup interrupt system
|
||||||
uint64_t csr = 0ULL;
|
uint64_t csr = 0x01ULL; // Enable vector'd exception handling.
|
||||||
__csrw("mtvec", csr);
|
__csrw("mtvec", csr);
|
||||||
|
|
||||||
SysTick = 0ULL;
|
SysTick = 0ULL;
|
||||||
|
|
|
@ -84,7 +84,13 @@ inf_loop:
|
||||||
.option norvc;
|
.option norvc;
|
||||||
|
|
||||||
.org 0x00
|
.org 0x00
|
||||||
jal x0, Exception_Handler
|
jal x0, Default_IRQHandler // USI
|
||||||
|
jal x0, Default_IRQHandler // SSI
|
||||||
|
jal x0, Default_IRQHandler // RFU
|
||||||
|
jal x0, Default_IRQHandler // MSI
|
||||||
|
jal x0, Default_IRQHandler // UTI
|
||||||
|
jal x0, Default_IRQHandler // STI
|
||||||
|
jal x0, Default_IRQHandler // RFU
|
||||||
|
jal x0, Timer_IRQHandler // MTI
|
||||||
.org 0x1000
|
.org 0x1000
|
||||||
jal x0, Reset_Handler
|
jal x0, Reset_Handler
|
||||||
|
|
Loading…
Reference in New Issue