Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <io.h>
  3. #include <system.h>
  4. #include "alt_types.h"
  5. #include "altera_avalon_pio_regs.h"
  6. #include "sys/alt_irq.h"
  7. //#include "sys/alt_timestamp.h"
  8. #include <unistd.h>
  9. //#include "definition.h"
  10.  
  11. #define sw0 0x00000001
  12. #define sw1 0x00000002
  13. #define sw2 0x00000004
  14. #define sw3 0x00000008
  15. #define sw4 0x00000010
  16. #define sw5 0x00000020
  17.  
  18. #define L_NULL 0x00000000
  19. #define LED0 0x00000001
  20. #define LED1 0x00000002
  21. #define LED2 0x00000004
  22. #define LED3 0x00000008
  23. #define LED4 0x00000010
  24. #define LED5 0x00000020
  25. #define LED6 0x00000040
  26.  
  27. #define SEGA 0x00001
  28. #define SEGB 0x00002
  29. #define SEGC 0x00004
  30. #define SEGD 0x00008
  31. #define SEGE 0x00010
  32. #define SEGF 0x00020
  33. #define SEGG 0x00040
  34.  
  35. #define CHA SEGB | SEGC | SEGA | SEGE | SEGF | SEGG
  36. #define CHB SEGB | SEGC | SEGA | SEGD | SEGE | SEGF | SEGG
  37. #define CHC SEGA | SEGF | SEGE | SEGD
  38. #define CHD SEGA | SEGB | SEGC | SEGD | SEGE | SEGF
  39. #define CHE SEGA | SEGD | SEGE | SEGF | SEGG
  40. #define CHF SEGA | SEGF | SEGE | SEGG
  41. #define CHG SEGC | SEGA | SEGE | SEGF | SEGD
  42. #define CHH SEGF | SEGE | SEGG | SEGB | SEGC
  43. #define CHI SEGB | SEGC
  44. #define CHL SEGF | SEGE | SEGD
  45. #define CHP SEGF | SEGE | SEGA | SEGB | SEGG
  46. #define CHS SEGA | SEGF | SEGG | SEGC | SEGD
  47. #define CHO SEGA | SEGB | SEGC | SEGD | SEGE | SEGF
  48. #define CHU SEGB | SEGC | SEGE | SEGF | SEGD
  49.  
  50. #define S_CHE SEGG | SEGB | SEGA | SEGF | SEGE
  51. #define S_CHR SEGE | SEGG
  52. #define S_CHT SEGF | SEGG | SEGE | SEGD
  53. #define S_CHO SEGE | SEGG | SEGC | SEGD
  54. #define H_NULL 0x00000000
  55. #define ZERO SEGA | SEGB | SEGC | SEGD |SEGE | SEGF
  56. #define ONE SEGB | SEGC
  57. #define TWO SEGA | SEGB | SEGD | SEGE | SEGG
  58. #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
  59. #define FOUR SEGB | SEGC | SEGF | SEGG
  60. #define FIVE SEGA | SEGC | SEGD | SEGF | SEGG
  61. #define SIX SEGA | SEGC | SEGD | SEGE | SEGF | SEGG
  62. #define CHAR_E SEGA | SEGD | SEGE | SEGF | SEGG
  63. #define CHAR_R SEGE | SEGG
  64. /*
  65.  
  66. struct interrupt_data{
  67. volatile int * leds;
  68. volatile int * hex;
  69. volatile int * sw;
  70. };
  71.  
  72. static void handle_sliders_interrupt(struct interrupt_data * data){
  73.  
  74. int sw = IORD(SW_SLIDERS_BASE, 0);
  75.  
  76. if((sw & sw0) && !(sw & ( sw1 | sw2 | sw3 | sw4 | sw5))) {
  77. IOWR(data->leds, 0, LED0);
  78. IOWR(data->hex, 0, ONE);
  79. IOWR(data->hex, 1, ZERO);
  80. IOWR(data->hex, 3, CHC);
  81. IOWR(data->hex, 2, CHD);
  82. }else if ( (sw & sw1) && !(sw & (sw0 | sw2 | sw3 | sw4 | sw5))) {
  83. IOWR(data->leds, 0, LED1);
  84. IOWR(data->hex, 0, TWO);
  85. IOWR(data->hex, 1, ZERO);
  86. IOWR(data->hex, 3, CHP);
  87. IOWR(data->hex, 2, CHU);}
  88. else if ((sw & sw2) && !(sw & (sw0 | sw1 | sw3 | sw4 | sw5))) {
  89. IOWR(data->leds, 0, LED2);
  90. IOWR(data->hex, 0, THREE);
  91. IOWR(data->hex, 1, ZERO);
  92. IOWR(data->hex, 3, CHA);
  93. IOWR(data->hex, 2, CHD);
  94. }else if ((sw & sw3) && !(sw & (sw2 | sw1 | sw0 | sw4 | sw5))) {
  95. IOWR(data->leds, 0, LED3);
  96. IOWR(data->hex, 0, FOUR);
  97. IOWR(data->hex, 1, ZERO);
  98. IOWR(data->hex, 3, CHU);
  99. IOWR(data->hex, 2, CHD);
  100. }else if ((sw & sw4) && !(sw & (sw2 | sw1 | sw3 | sw0 | sw5))) {
  101. IOWR(data->leds, 0, LED4);
  102. IOWR(data->hex, 0, FIVE);
  103. IOWR(data->hex, 1, ZERO);
  104. IOWR(data->hex, 3, CHD);
  105. IOWR(data->hex, 2, CHD);
  106. }else if ((sw & sw5) && !(sw & ( sw2 | sw1 | sw3 | sw4 | sw0))) {
  107. IOWR(data->leds, 0, LED5);
  108. IOWR(data->hex, 0, SIX);
  109. IOWR(data->hex, 1, ZERO);
  110. IOWR(data->hex, 3, CHB);
  111. IOWR(data->hex, 2, CHD);
  112. }else if (!(sw & (sw0 | sw1 | sw2 | sw3 | sw4 | sw5))){
  113. IOWR(data->leds, 0, L_NULL);
  114. IOWR(data->hex, 0, H_NULL);
  115. IOWR(data->hex, 1, H_NULL);
  116. IOWR(data->hex, 2, H_NULL);
  117. IOWR(data->hex, 3, H_NULL);
  118.  
  119.  
  120. }else {
  121. IOWR(data->leds, 0, LED6);
  122. IOWR(data->hex, 0, CHAR_R);
  123. IOWR(data->hex, 1, CHAR_R);
  124. IOWR(data->hex, 2, CHAR_E);
  125. IOWR(data->hex, 3, H_NULL);
  126. }
  127. }
  128. */
  129.  
  130.  
  131. int main(){
  132.  
  133. int sw = IORD(SW_SLIDERS_BASE, 0);
  134.  
  135. while(1){
  136. sw = IORD(SW_SLIDERS_BASE, 0);
  137.  
  138. if((sw & sw0) && !(sw & ( sw1 | sw2 | sw3 | sw4 | sw5))) {
  139. IOWR(LEDS_BASE, 0, LED0);
  140. IOWR(HEX_BASE, 0, ONE);
  141. IOWR(HEX_BASE, 1, ZERO);
  142. IOWR(HEX_BASE, 3, CHC);
  143. IOWR(HEX_BASE, 2, CHD);
  144. }else if ( (sw & sw1) && !(sw & (sw0 | sw2 | sw3 | sw4 | sw5))) {
  145. IOWR(LEDS_BASE, 0, LED1);
  146. IOWR(HEX_BASE, 0, TWO);
  147. IOWR(HEX_BASE, 1, ZERO);
  148. IOWR(HEX_BASE, 3, CHP);
  149. IOWR(HEX_BASE, 2, CHU);}
  150. else if ((sw & sw2) && !(sw & (sw0 | sw1 | sw3 | sw4 | sw5))) {
  151. IOWR(LEDS_BASE, 0, LED2);
  152. IOWR(HEX_BASE, 0, THREE);
  153. IOWR(HEX_BASE, 1, ZERO);
  154. IOWR(HEX_BASE, 3, CHA);
  155. IOWR(HEX_BASE, 2, CHD);
  156. }else if ((sw & sw3) && !(sw & (sw2 | sw1 | sw0 | sw4 | sw5))) {
  157. IOWR(LEDS_BASE, 0, LED3);
  158. IOWR(HEX_BASE, 0, FOUR);
  159. IOWR(HEX_BASE, 1, ZERO);
  160. IOWR(HEX_BASE, 3, CHU);
  161. IOWR(HEX_BASE, 2, CHD);
  162. }else if ((sw & sw4) && !(sw & (sw2 | sw1 | sw3 | sw0 | sw5))) {
  163. IOWR(LEDS_BASE, 0, LED4);
  164. IOWR(HEX_BASE, 0, FIVE);
  165. IOWR(HEX_BASE, 1, ZERO);
  166. IOWR(HEX_BASE, 3, CHD);
  167. IOWR(HEX_BASE, 2, CHD);
  168. }else if ((sw & sw5) && !(sw & ( sw2 | sw1 | sw3 | sw4 | sw0))) {
  169. IOWR(LEDS_BASE, 0, LED5);
  170. IOWR(HEX_BASE, 0, SIX);
  171. IOWR(HEX_BASE, 1, ZERO);
  172. IOWR(HEX_BASE, 3, CHB);
  173. IOWR(HEX_BASE, 2, CHD);
  174. }else if (!(sw & (sw0 | sw1 | sw2 | sw3 | sw4 | sw5))){
  175. IOWR(LEDS_BASE, 0, L_NULL);
  176. IOWR(HEX_BASE, 0, H_NULL);
  177. IOWR(HEX_BASE, 1, H_NULL);
  178. IOWR(HEX_BASE, 2, H_NULL);
  179. IOWR(HEX_BASE, 3, H_NULL);
  180.  
  181.  
  182. }else {
  183. IOWR(LEDS_BASE, 0, LED6);
  184. IOWR(HEX_BASE, 0, CHAR_R);
  185. IOWR(HEX_BASE, 1, CHAR_R);
  186. IOWR(HEX_BASE, 2, CHAR_E);
  187. IOWR(HEX_BASE, 3, H_NULL);
  188. }
  189. }
  190. // IOWR(HEX_BASE, 0, 0);
  191. // IOWR(HEX_BASE, 1, 0);
  192. // IOWR(HEX_BASE, 2, 0);
  193. // IOWR(HEX_BASE, 3, 0);
  194. // IOWR(HEX_BASE, 4, 0);
  195. // IOWR(HEX_BASE, 5, 0);
  196. //
  197. // volatile int *sliders = (int*) SW_SLIDERS_BASE;
  198. // volatile int *leds = (int*) LEDS_BASE;
  199. // volatile int *hex = (int*) HEX_BASE;
  200. //
  201. // struct interrupt_data data;
  202. //
  203. // data.hex = hex;
  204. // data.leds = leds;
  205. // data.sw = sliders;
  206. //
  207. // IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0xf);
  208. //
  209. // alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ, handle_sliders_interrupt, &data, 0x0);
  210. // alt_ic_irq_enable(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ);
  211. //
  212. // while(1){}
  213.  
  214. return 0;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement