Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. /*
  2. * "Hello World" example.
  3. *
  4. * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
  5. * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
  6. * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
  7. * device in your system's hardware.
  8. * The memory footprint of this hosted application is ~69 kbytes by default
  9. * using the standard reference design.
  10. *
  11. * For a reduced footprint version of this template, and an explanation of how
  12. * to reduce the memory footprint for a given application, see the
  13. * "small_hello_world" template.
  14. *
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <io.h>
  19. #include <system.h>
  20. #include "alt_types.h"
  21. #include "altera_avalon_pio_regs.h"
  22. #include "sys/alt_irq.h"
  23. //#include "sys/alt_timestamp.h"
  24. #include <unistd.h>
  25. #include "definition.h"
  26.  
  27. struct interrupt_data
  28. {
  29. volatile int * leds_addr;
  30. volatile int * hex_addr;
  31. volatile int * sw_addr;
  32. };
  33.  
  34. static void handle_sliders_interrupt(struct interrupt_data * data)
  35. {
  36. int sw = IORD(data->sw_addr,0);
  37. IOWR(data->leds_addr,0,sw);
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43. volatile int *sliders = (int*) SW_SLIDERS_BASE;
  44. volatile int *leds = (int*) LEDS_BASE;
  45. struct interrupt_data data;
  46.  
  47. data.leds_addr = leds;
  48. data.sw_addr = sliders;
  49. IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE,0xf);
  50.  
  51. alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ ,handle_sliders_interrupt,&data, 0x0);
  52.  
  53.  
  54. alt_ic_irq_enable(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ);
  55.  
  56. printf("Hello from Nios II!\n");
  57.  
  58. while(1);
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement