Advertisement
Sothian

Untitled

Oct 29th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.74 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 <unistd.h>
  24.  
  25. //        sw_sliders
  26. #define  SW0 0x00000001
  27. #define  SW1 0x00000002
  28. #define  SW2 0x00000004
  29. #define  SW3 0x00000008
  30. #define  SW4 0x00000010
  31. #define  SW5 0x00000020
  32. #define  SW6 0x00000040
  33. #define  SW7 0x00000080
  34. #define  SW8 0x00000100
  35. #define  SW9 0x00000200
  36. #define  SW10 0x00000400
  37. #define  SW11 0x00000800
  38. #define  SW12 0x00001000
  39. #define  SW13 0x00002000
  40. #define  SW14 0x00004000
  41. #define  SW15 0x00008000
  42. #define  SW16 0x00010000
  43. #define  SW17 0x00020000
  44.  
  45. //      pushbuttons
  46. #define  KEY1 0x00000002
  47. #define  KEY2 0x00000004
  48. #define  KEY3 0x00000008
  49. #define  KEY4 0x00000010
  50.  
  51. //      leds
  52. #define  LED0 0x00000001
  53. #define  LED1 0x00000002
  54. #define  LED2 0x00000004
  55. #define  LED3 0x00000008
  56. #define  LED4 0x00000010
  57. #define  LED5 0x00000020
  58. #define  LED6 0x00000040
  59. #define  LED7 0x00000080
  60. #define  LED8 0x00000100
  61. #define  LED9 0x00000200
  62. #define  LED10 0x00000400
  63. #define  LED11 0x00000800
  64. #define  LED12 0x00001000
  65. #define  LED13 0x00002000
  66. #define  LED14 0x00004000
  67. #define  LED15 0x00008000
  68. #define  LED16 0x00010000
  69. #define  LED17 0x00020000
  70.  
  71. //      hex
  72. #define  SEGA 0x00001
  73. #define  SEGB 0x00002
  74. #define  SEGC 0x00004
  75. #define  SEGD 0x00008
  76. #define  SEGE 0x00010
  77. #define  SEGF 0x00020
  78. #define  SEGG 0x00040
  79.  
  80. //     hex - numbers
  81. #define ZERO SEGA | SEGB | SEGC | SEGD |SEGE | SEGF
  82. #define ONE  SEGB | SEGC
  83. #define TWO  SEGA | SEGB | SEGG | SEGE | SEGD
  84. #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
  85. #define FOUR SEGF | SEGG | SEGC | SEGB
  86. #define FIVE SEGA | SEGC | SEGD | SEGG | SEGF
  87. #define SIX SEGA | SEGC | SEGD | SEGE | SEGF | SEGG
  88. #define SEVEN SEGA | SEGB | SEGC
  89. #define EIGHT SEGA | SEGB | SEGC | SEGD | SEGE | SEGF | SEGG
  90. #define E SEGA | SEGD | SEGE | SEGF | SEGG
  91. #define R SEGE | SEGG
  92.  
  93.  
  94. struct interrupt_data  
  95. {
  96.     int volatile leds_addr;
  97.     int volatile sw_addr;
  98.     int volatile pb_addr;
  99.     int volatile hex_addr;
  100. };
  101.  
  102.  
  103.  static void handle_sliders_interrupt(struct interrupt_data *data)
  104.  {
  105.  
  106.     int state=0;
  107.     state=IORD(data->sw_addr, 0);
  108.     state=state&(32|16|8|4|2|1);
  109.     IOWR(data->leds_addr,0,0);
  110.     IOWR(data->hex_addr,0,0);
  111.     IOWR(data->hex_addr,1,0);
  112.     IOWR(data->hex_addr,2,0);
  113.    
  114.     switch(state) {  
  115.         case 0:
  116.             break;
  117.         case 1:
  118.             IOWR(data->leds_addr,0, LED0);
  119.             IOWR(data->hex_addr,0, FIVE);
  120.             IOWR(data->hex_addr,1, TWO);
  121.             break;
  122.         case 2:
  123.             IOWR(data->leds_addr,0, LED1);
  124.             IOWR(data->hex_addr,0, FIVE);
  125.             IOWR(data->hex_addr,1, THREE);
  126.             break;
  127.         case 4:
  128.             IOWR(data->leds_addr,0, LED2);
  129.             IOWR(data->hex_addr,0, FIVE);
  130.             IOWR(data->hex_addr,1, FOUR);
  131.             break;
  132.         case 8:
  133.             IOWR(data->leds_addr,0, LED3);
  134.             IOWR(data->hex_addr,0, FIVE);
  135.             IOWR(data->hex_addr,1, FIVE);
  136.             break;
  137.         case 16:
  138.             IOWR(data->leds_addr,0, LED4);
  139.             IOWR(data->hex_addr,0, FIVE);
  140.             IOWR(data->hex_addr,1, SEVEN);
  141.             break;
  142.         case 32:
  143.             IOWR(data->leds_addr,0, LED5);
  144.             IOWR(data->hex_addr,0, FIVE);
  145.             IOWR(data->hex_addr,1, EIGHT);
  146.             break;
  147.         default:
  148.             IOWR(data->leds_addr,0,LED9);
  149.             IOWR(data->hex_addr,0, R);
  150.             IOWR(data->hex_addr,1, R);
  151.             IOWR(data->hex_addr,2, E);
  152.             break;
  153.         }
  154. }
  155.  
  156. int main()
  157. {
  158.     while(1){
  159.         struct interrupt_data data;    
  160.         int *leds = (int*) (0x41040);
  161.         int *sw = (int*) (0x41030);
  162.         int *pb = (int*) (0x41020);
  163.         int *hex = (int*) ();
  164.         data.leds_addr = leds;
  165.         data.pb_addr = pb;
  166.         data.sw_addr = sw;
  167.         data.hex_addr = hex;
  168.        
  169.         IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0xFF);
  170.         alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID,SW_SLIDERS_IRQ, handle_sliders_interrupt, &data, 0x0);
  171.     }
  172.   return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement