fpga_spn: use separate reset for DMA

This commit is contained in:
Johannes Wirth 2021-11-10 09:51:19 +01:00
parent 89ea594399
commit 446af340c8
4 changed files with 30 additions and 11 deletions

Binary file not shown.

View File

@ -13,6 +13,7 @@ typedef void (*function_ptr_t) (void);
plic_instance_t g_plic; plic_instance_t g_plic;
std::array<function_ptr_t,PLIC_NUM_INTERRUPTS> g_ext_interrupt_handlers; std::array<function_ptr_t,PLIC_NUM_INTERRUPTS> g_ext_interrupt_handlers;
bool hw_interrupt{true}; bool hw_interrupt{true};
bool dma_interrupt{true};
/*! \brief external interrupt handler /*! \brief external interrupt handler
@ -43,11 +44,7 @@ void configure_irq(size_t irq_num, function_ptr_t handler, unsigned char prio=1)
PLIC_enable_interrupt(&g_plic, irq_num); PLIC_enable_interrupt(&g_plic, irq_num);
} }
static void msi_interrupt_handler(){ void wait_for_spn_interrupt() {
hw_interrupt = false;
}
void wait_for_interrupt() {
// wait until HW is done // wait until HW is done
if(hw_interrupt) { if(hw_interrupt) {
do{ do{
@ -58,6 +55,17 @@ void wait_for_interrupt() {
hw_interrupt=true; hw_interrupt=true;
} }
void wait_for_dma_interrupt() {
// wait until HW is done
if(dma_interrupt) {
do{
asm("wfi");
asm("nop");
}while(dma_interrupt);
}
dma_interrupt=true;
}
/*!\brief initializes platform /*!\brief initializes platform
* *
*/ */
@ -77,7 +85,6 @@ void platform_init(){
clear_csr(mie, MIP_MEIP); clear_csr(mie, MIP_MEIP);
clear_csr(mie, MIP_MTIP); clear_csr(mie, MIP_MTIP);
for (auto& h:g_ext_interrupt_handlers) h=no_interrupt_handler; for (auto& h:g_ext_interrupt_handlers) h=no_interrupt_handler;
configure_irq(2, msi_interrupt_handler);
// Enable interrupts in general. // Enable interrupts in general.
set_csr(mstatus, MSTATUS_MIE); set_csr(mstatus, MSTATUS_MIE);
// Enable the Machine-External bit in MIE // Enable the Machine-External bit in MIE

View File

@ -25,10 +25,20 @@ void fpga_dma(int direction, int fpga_address, int sc_address, int num_bytes) {
dma::sc_address_reg() = sc_address; dma::sc_address_reg() = sc_address;
dma::bytes_reg() = num_bytes; dma::bytes_reg() = num_bytes;
dma::start_reg() = 1; dma::start_reg() = 1;
wait_for_interrupt(); wait_for_dma_interrupt();
dma::clear_interrupt_reg() = 1; dma::clear_interrupt_reg() = 1;
} }
static void spn_interrupt_handler(){
printf("spn_interrupt_handler\n");
hw_interrupt = false;
}
static void dma_interrupt_handler(){
printf("dma_interrupt_handler\n");
dma_interrupt = false;
}
/*! \brief main function /*! \brief main function
* *
*/ */
@ -36,10 +46,12 @@ int main() {
platform_init(); platform_init();
configure_irq(2, spn_interrupt_handler);
configure_irq(22, dma_interrupt_handler);
spn::mode_reg() = 1; spn::mode_reg() = 1;
spn::start_reg() = 1; spn::start_reg() = 1;
wait_for_interrupt(); wait_for_spn_interrupt();
spn::interrupt_reg() = 1; spn::interrupt_reg() = 1;
uint32_t readout = spn::readout_reg(); uint32_t readout = spn::readout_reg();
printf("READOUT HW:0x%x\n", readout); printf("READOUT HW:0x%x\n", readout);
@ -60,8 +72,8 @@ int main() {
printf("Result Bytes: %d\n", result_bytes); printf("Result Bytes: %d\n", result_bytes);
uint32_t step = 10000; uint32_t step = 50000;
uint32_t iterations = 5; uint32_t iterations = 2;
uint32_t in_beats = (step * sample_bytes) / axi_bytes; uint32_t in_beats = (step * sample_bytes) / axi_bytes;
@ -84,7 +96,7 @@ int main() {
for (int k = 0; k < iterations*step; k+=step) { for (int k = 0; k < iterations*step; k+=step) {
fpga_dma(1, fpga_address_in, in_addr, step * sample_bytes); fpga_dma(1, fpga_address_in, in_addr, step * sample_bytes);
run_xspn(fpga_address_in, fpga_address_out, step, in_beats, out_beats); run_xspn(fpga_address_in, fpga_address_out, step, in_beats, out_beats);
wait_for_interrupt(); wait_for_spn_interrupt();
spn::interrupt_reg() = 1; spn::interrupt_reg() = 1;
printf("XSPN finished\n"); printf("XSPN finished\n");
fpga_dma(0, fpga_address_out, out_addr, step * result_bytes); fpga_dma(0, fpga_address_out, out_addr, step * result_bytes);

Binary file not shown.