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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_xirq/] [main.c] - Diff between revs 62 and 64

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 62 Rev 64
Line 58... Line 58...
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Main function
 * Main function
 *
 *
 * @note This program requires the WDT and the UART to be synthesized.
 * @note This program requires the XIRQ and the UART to be synthesized.
 *
 *
 * @return 0 if execution was successful
 * @return 0 if execution was successful
 **************************************************************************/
 **************************************************************************/
int main() {
int main() {
 
 
Line 97... Line 97...
    return 1;
    return 1;
  }
  }
 
 
 
 
  // install handler functions for XIRQ channel 0,1,2,3. note that these functions are "normal" functions!
  // install handler functions for XIRQ channel 0,1,2,3. note that these functions are "normal" functions!
  // (details: these are "third-level" interrupt handler)
  // (details: these are "third-level" interrupt handlers)
 
  // neorv32_xirq_install() also enables the specified XIRQ channel and clears any pending interrupts
  err_cnt = 0;
  err_cnt = 0;
  err_cnt += neorv32_xirq_install(0, xirq_handler_ch0); // handler function for channel 0
  err_cnt += neorv32_xirq_install(0, xirq_handler_ch0); // handler function for channel 0
  err_cnt += neorv32_xirq_install(1, xirq_handler_ch1); // handler function for channel 1
  err_cnt += neorv32_xirq_install(1, xirq_handler_ch1); // handler function for channel 1
  err_cnt += neorv32_xirq_install(2, xirq_handler_ch2); // handler function for channel 2
  err_cnt += neorv32_xirq_install(2, xirq_handler_ch2); // handler function for channel 2
  err_cnt += neorv32_xirq_install(3, xirq_handler_ch3); // handler function for channel 3
  err_cnt += neorv32_xirq_install(3, xirq_handler_ch3); // handler function for channel 3
Line 119... Line 120...
 
 
  // enable global interrupts
  // enable global interrupts
  neorv32_cpu_eint();
  neorv32_cpu_eint();
 
 
 
 
  // now we are ready to got!
 
  // the code below assumes the XIRQ inputs are connected to the processor's GPIO output port
  // the code below assumes the XIRQ inputs are connected to the processor's GPIO output port
  // so we can trigger the IRQs from software; if you have connected the XIRQs to buttons you
  // so we can trigger the IRQs from software; if you have connected the XIRQs to buttons you
  // can remove the code below (note the trigger configuration using the XIRQ generics!)
  // can remove the code below (note the trigger configuration using the XIRQ generics!)
  {
  {
    // trigger XIRQs 3:0 at once
    // trigger XIRQs 3:0 at once
    // assumes xirq_i <= gpio.output(31:0)
    // assumes xirq_i(31:0) <= gpio.output(31:0)
 
 
    // due to the prioritization this will execute
    // due to the prioritization this will execute
    // -> xirq_handler_ch0
    // -> xirq_handler_ch0
    // -> xirq_handler_ch1
    // -> xirq_handler_ch1
    // -> xirq_handler_ch2
    // -> xirq_handler_ch2
Line 140... Line 140...
 
 
 
 
  // --- wait for interrupts ---
  // --- wait for interrupts ---
  // All incoming XIRQ interrupt requests are "prioritized" in this example. The XIRQ FIRQ handler
  // All incoming XIRQ interrupt requests are "prioritized" in this example. The XIRQ FIRQ handler
  // reads the ID of the interrupt with the highest priority from the XIRQ controller ("source" register) and calls the according
  // reads the ID of the interrupt with the highest priority from the XIRQ controller ("source" register) and calls the according
  // handler function.
  // handler function (installed via neorv32_xirq_install();).
  // Non-prioritized handling of interrupts (or custom prioritization) can be implemented by manually reading the
  // Non-prioritized handling of interrupts (or custom prioritization) can be implemented by manually reading the
  // XIRQ controller's "pending" register. It is up to the software to define which pending IRQ should be served.
  // XIRQ controller's "pending" register. Then it is up to the software to define which pending IRQ should be served first.
  while(1);
  while(1);
 
 
 
 
  // just as an example: to disable certain XIRQ interrupt channels, we can
  // just as an example: to disable certain XIRQ interrupt channels, we can
  // un-install the according handler. this will also clear a pending interrupt for that channel
  // un-install the according handler. this will also clear a pending interrupt for that channel
  neorv32_xirq_uninstall(0); // disable XIRQ channel 0 and remove associated handler
  neorv32_xirq_uninstall(0); // disable XIRQ channel 0 and remove associated handler
  neorv32_xirq_uninstall(1); // disable XIRQ channel 1 and remove associated handler
  neorv32_xirq_uninstall(1); // disable XIRQ channel 1 and remove associated handler
  neorv32_xirq_uninstall(2); // disable XIRQ channel 2 and remove associated handler
  neorv32_xirq_uninstall(2); // disable XIRQ channel 2 and remove associated handler
  neorv32_xirq_uninstall(3); // disable XIRQ channel 3 and remove associated handler
  neorv32_xirq_uninstall(3); // disable XIRQ channel 3 and remove associated handler
 
 
 
  // you can also manually clear pending interrupts
 
  neorv32_xirq_clear_pending(0); // clear pending interrupt of channel 0
 
 
 
  // manually enable and disable XIRQ channels
 
  neorv32_xirq_channel_enable(0); // enable channel 0
 
  neorv32_xirq_channel_disable(0); // disable channel 0
 
 
 
  // globally enable/disable XIRQ CPU interrupt
 
  // this will not affect the XIR configuration / pending interrupts
 
  neorv32_xirq_global_enable();
 
  neorv32_xirq_global_disable();
 
 
  return 0;
  return 0;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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