Advertisement
Paczek

lab 3 stany stare

Oct 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.56 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. #define  SW6 0x00000040
  18.  
  19. #define  L_NULL 0x00000000
  20. #define  LED0 0x00000001
  21. #define  LED1 0x00000002
  22. #define  LED2 0x00000004
  23. #define  LED3 0x00000008
  24. #define  LED4 0x00000010
  25. #define  LED5 0x00000020
  26. #define  LED6 0x00000040
  27.  
  28. #define  SEGA 0x00001
  29. #define  SEGB 0x00002
  30. #define  SEGC 0x00004
  31. #define  SEGD 0x00008
  32. #define  SEGE 0x00010
  33. #define  SEGF 0x00020
  34. #define  SEGG 0x00040
  35.  
  36. #define H_NULL 0x00000000
  37. #define ONE  SEGB | SEGC
  38. #define TWO  SEGA | SEGB | SEGD | SEGE | SEGG
  39. #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
  40. #define FOUR  SEGB | SEGC | SEGF | SEGG
  41. #define FIVE  SEGA | SEGC | SEGD | SEGF | SEGG
  42. #define SIX  SEGA | SEGC | SEGD | SEGE | SEGF | SEGG
  43. #define CHAR_E SEGA | SEGD | SEGE | SEGF | SEGG
  44. #define CHAR_R SEGE | SEGG
  45.  
  46. struct interrupt_data{
  47.     volatile int* leds;
  48.     volatile int* hex;
  49.     volatile int* sw;
  50. };
  51.  
  52. int state;
  53.  
  54. static void handle_sliders_interrupt(struct interrupt_data * data){
  55.    
  56.     sw = IORD(SW_SLIDERS_BASE, 0);
  57.    
  58.     switch(state){
  59.         case 0:
  60.             if       ((sw & SW1) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW6))) {
  61.                 state = 1;
  62.                 IOWR(data->leds, 0, LED0);
  63.                 IOWR(data->hex, 0, ONE);
  64.             }else if ((sw & SW2) && !(sw & (SW1 | SW3 | SW4 | SW5 | SW6))) {
  65.                 state = 2;
  66.                 IOWR(data->leds, 0, LED1);
  67.                 IOWR(data->hex, 0, TWO);
  68.             }else if ((sw & SW3) && !(sw & (SW2 | SW1 | SW4 | SW5 | SW6))) {
  69.                 state = 3;
  70.                 IOWR(data->leds, 0, LED2);
  71.                 IOWR(data->hex, 0, THREE);
  72.             }else if ((sw & SW4) && !(sw & (SW2 | SW3 | SW1 | SW5 | SW6))) {
  73.                 state = 4;
  74.                 IOWR(data->leds, 0, LED3);
  75.                 IOWR(data->hex, 0, FOUR);
  76.             }else if ((sw & SW5) && !(sw & (SW2 | SW3 | SW4 | SW1 | SW6))) {
  77.                 state = 5;
  78.                 IOWR(data->leds, 0, LED4);
  79.                 IOWR(data->hex, 0, FIVE);
  80.             }else if ((sw & SW6) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW1))) {
  81.                 state = 6;
  82.                 IOWR(data->leds, 0, LED5);
  83.                 IOWR(data->hex, 0, SIX);
  84.             }
  85.         break;
  86.         case 1: case 2:
  87.         case 3: case 4:
  88.         case 5: case 6:
  89.             if(sw == 0){
  90.                 state = 0;
  91.                 IOWR(data->leds, 0, L_NULL);
  92.                 IOWR(data->hex, 0, H_NULL);
  93.             }
  94.             else{
  95.                 state = 7;
  96.                 IOWR(data->leds, 0, LED6);
  97.                 IOWR(data->hex, 0, CHAR_R);
  98.                 IOWR(data->hex, 1, CHAR_R);
  99.                 IOWR(data->hex, 2, CHAR_E);
  100.             }
  101.         case 7:
  102.             if       ((sw & SW1) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW6))) {
  103.                 state = 1;
  104.                 IOWR(data->leds, 0, LED0);
  105.                 IOWR(data->hex, 0, ONE);
  106.             }else if ((sw & SW2) && !(sw & (SW1 | SW3 | SW4 | SW5 | SW6))) {
  107.                 state = 2;
  108.                 IOWR(data->leds, 0, LED1);
  109.                 IOWR(data->hex, 0, TWO);
  110.             }else if ((sw & SW3) && !(sw & (SW2 | SW1 | SW4 | SW5 | SW6))) {
  111.                 state = 3;
  112.                 IOWR(data->leds, 0, LED2);
  113.                 IOWR(data->hex, 0, THREE);
  114.             }else if ((sw & SW4) && !(sw & (SW2 | SW3 | SW1 | SW5 | SW6))) {
  115.                 state = 4;
  116.                 IOWR(data->leds, 0, LED3);
  117.                 IOWR(data->hex, 0, FOUR);
  118.             }else if ((sw & SW5) && !(sw & (SW2 | SW3 | SW4 | SW1 | SW6))) {
  119.                 state = 5;
  120.                 IOWR(data->leds, 0, LED4);
  121.                 IOWR(data->hex, 0, FIVE);
  122.             }else if ((sw & SW6) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW1))) {
  123.                 state = 6;
  124.                 IOWR(data->leds, 0, LED5);
  125.                 IOWR(data->hex, 0, SIX);
  126.             }else {
  127.                 //state = 7;
  128.                 IOWR(data->leds, 0, LED6);
  129.                 IOWR(data->hex, 0, CHAR_R);
  130.                 IOWR(data->hex, 1, CHAR_R);
  131.                 IOWR(data->hex, 2, CHAR_E);
  132.             }
  133.         break;
  134.     }
  135.     /*
  136.     if       ((sw & SW6) && !(SW & (SW1 | SW2 | SW3 | SW4 | SW5))) {
  137.         IOWR(data->leds, 0, LED0);
  138.         IOWR(data->hex, 0, ONE);
  139.     }else if ((sw & SW1) && !(sw & (SW6 | SW2 | SW3 | SW4 | SW5))) {
  140.         IOWR(data->leds, 0, LED1);
  141.         IOWR(data->hex, 0, TWO);
  142.     }else if ((sw & SW2) && !(sw & (SW1 | SW6 | SW3 | SW4 | SW5))) {
  143.         IOWR(data->leds, 0, LED2);
  144.         IOWR(data->hex, 0, THREE);
  145.     }else if ((sw & SW3) && !(sw & (SW1 | SW2 | SW6 | SW4 | SW5))) {
  146.         IOWR(data->leds, 0, LED3);
  147.         IOWR(data->hex, 0, FOUR);
  148.     }else if ((sw & SW4) && !(sw & (SW1 | SW2 | SW3 | SW6 | SW5))) {
  149.         IOWR(data->leds, 0, LED4);
  150.         IOWR(data->hex, 0, FIVE);
  151.     }else if ((sw & SW5) && !(sw & (SW1 | SW2 | SW3 | SW4 | SW6))) {
  152.         IOWR(data->leds, 0, LED5);
  153.         IOWR(data->hex, 0, SIX);
  154.     }else if (!(sw & (SW6 | SW1 | SW2 | SW3 | SW4 | SW5))){
  155.         IOWR(data->leds, 0, L_NULL);
  156.         IOWR(data->hex, 0, H_NULL);
  157.     }else {
  158.         IOWR(data->leds, 0, LED6);
  159.         IOWR(data->hex, 0, CHAR_R);
  160.         IOWR(data->hex, 1, CHAR_R);
  161.         IOWR(data->hex, 2, CHAR_E);
  162.     }
  163.     */
  164. }
  165.  
  166.  
  167. int main(){
  168.     IOWR(HEX_BASE, 0, 0);
  169.     IOWR(HEX_BASE, 1, 0);
  170.     IOWR(HEX_BASE, 2, 0);
  171.     IOWR(HEX_BASE, 3, 0);
  172.     IOWR(HEX_BASE, 4, 0);
  173.     IOWR(HEX_BASE, 5, 0);
  174.  
  175.     volatile int* sliders = (int*) SW_SLIDERS_BASE;
  176.     volatile int* leds = (int*) LEDS_BASE;
  177.     volatile int* hex = (int*) HEX_BASE;
  178.    
  179.     struct interrupt_data data;
  180.    
  181.     data.hex = hex;
  182.     data.leds = leds;
  183.     data.sw = sliders;
  184.    
  185.     state = 0;
  186.    
  187.     //                                              SW 6543210
  188.     IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0b1111111);
  189.    
  190.     alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ, handle_sliders_interrupt, &data, 0x0);
  191.     alt_ic_irq_enable(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ);
  192.    
  193.     while(1){}
  194.    
  195.   return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement