Advertisement
Sothian

Lab10_sw

Dec 18th, 2019
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.37 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. #include <stdio.h>
  17. #include <io.h>
  18. #include <system.h>
  19. #include "sys/alt_irq.h"
  20. #include <unistd.h>
  21. #include "sys/alt_alarm.h"
  22. #include "includes.h"
  23. #include "altera_up_avalon_parallel_port.h"
  24. #include "sys/alt_timestamp.h"
  25. #include "alt_types.h"
  26. #include <altera_avalon_mutex.h>
  27.  
  28. #define SHARED_MEMORY_BASE 0x81000
  29.  
  30. struct interrupt_data {
  31.     volatile int* leds_addr;
  32.     volatile int* sliders_addr;
  33.     volatile int* hex_addr;
  34. };
  35. /* Przełączniki */
  36. #define  SW0 0x00000001
  37. #define  SW1 0x00000002
  38. #define  SW2 0x00000004
  39. #define  SW3 0x00000008
  40. #define  SW4 0x00000010
  41. #define  SW5 0x00000020
  42. #define  SW6 0x00000040
  43. #define  SW7 0x00000080
  44. #define  SW8 0x00000100
  45. #define  SW9 0x00000200
  46. #define  SW10 0x00000400
  47. #define  SW11 0x00000800
  48. #define  SW12 0x00001000
  49. #define  SW13 0x00002000
  50. #define  SW14 0x00004000
  51. #define  SW15 0x00008000
  52. #define  SW16 0x00010000
  53. #define  SW17 0x00020000
  54.  
  55. /* PushButtony */
  56. #define  KEY1 0x00000002
  57. #define  KEY2 0x00000004
  58. #define  KEY3 0x00000008
  59.  
  60. /* Ledy */
  61. #define  LED0 0x00000001
  62. #define  LED1 0x00000002
  63. #define  LED2 0x00000004
  64. #define  LED3 0x00000008
  65. #define  LED4 0x00000010
  66. #define  LED5 0x00000020
  67. #define  LED6 0x00000040
  68. #define  LED7 0x00000080
  69. #define  LED8 0x00000100
  70. #define  LED9 0x00000200
  71. #define  LED10 0x00000400
  72. #define  LED11 0x00000800
  73. #define  LED12 0x00001000
  74. #define  LED13 0x00002000
  75. #define  LED14 0x00004000
  76. #define  LED15 0x00008000
  77. #define  LED16 0x00010000
  78. #define  LED17 0x00020000
  79.  
  80. /* Segmenty HEX */
  81. #define  SEGA 1
  82. #define  SEGB 2
  83. #define  SEGC 4
  84. #define  SEGD 8
  85. #define  SEGE 16
  86. #define  SEGF 32
  87. #define  SEGG 64
  88.  
  89. /* Litery i cyfry z hex 7 segmentowych */
  90. #define HEX0 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF)
  91. #define HEX1 (SEGB|SEGC)
  92. #define HEX2 (SEGA|SEGB|SEGG|SEGE|SEGD)
  93. #define HEX3 (SEGA|SEGB|SEGC|SEGD|SEGG)
  94. #define HEX4 (SEGF|SEGG|SEGB|SEGC)
  95. #define HEX5 (SEGA|SEGF|SEGG|SEGC|SEGD)
  96. #define HEX6 (SEGA|SEGF|SEGG|SEGC|SEGD|SEGE)
  97. #define HEX7 (SEGA|SEGB|SEGC)
  98. #define HEX8 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG)
  99. #define HEX9 (SEGA|SEGB|SEGC|SEGD|SEGF|SEGG)
  100. #define HEXE (SEGA|SEGF|SEGG|SEGE|SEGD)
  101. #define HEXr (SEGE|SEGG)
  102. #define HEXA (SEGA|SEGB|SEGC|SEGE|SEGF|SEGG)
  103. #define HEXF (SEGA|SEGE|SEGF|SEGG)
  104. #define HEXC (SEGA|SEGE|SEGF|SEGD)
  105. #define HEXD (SEGB|SEGC|SEGD|SEGE|SEGG)
  106.  
  107. typedef enum POZIOM_TEMP {
  108.     POZIOM_0 = 0,
  109.     POZIOM_1 = 2,
  110.     POZIOM_2 = 4,
  111.     POZIOM_3 = 8,
  112.     POZIOM_4 = 16,
  113.     POZIOM_5 = 32,
  114.     POZIOM_6 = 64,
  115.     POZIOM_7 = 128,
  116.     POZIOM_8 = 256,
  117.     POZIOM_9 = 512,
  118.     POZIOM_10 = 1024,
  119.  
  120. } TEMP;
  121.  
  122. #define TASK_STACKSIZE 1024
  123. OS_STK task1_stk[TASK_STACKSIZE];
  124. OS_STK task2_stk[TASK_STACKSIZE];
  125. OS_STK task3_stk[TASK_STACKSIZE];
  126. OS_STK task4_stk[TASK_STACKSIZE];
  127. OS_STK task5_stk[TASK_STACKSIZE];
  128. OS_STK task6_stk[TASK_STACKSIZE];
  129. OS_STK task7_stk[TASK_STACKSIZE];
  130.  
  131. OS_EVENT *SWBox1;
  132.  
  133. /* Definition of Task Priorities */
  134. // alt_up_parallel_port_dev *uchwytLEDR;
  135. #define TASK1_PRIORITY 1
  136. #define TASK2_PRIORITY 2
  137. #define TASK3_PRIORITY 3
  138. #define TASK4_PRIORITY 4
  139. #define TASK5_PRIORITY 5
  140. #define TASK6_PRIORITY 6
  141. #define TASK7_PRIORITY 7
  142.  
  143. void VGA_text(int, int, char *);
  144.  
  145. int lastState = 0;
  146. int startNicks = 0;
  147. int startTimeHex = 0;
  148.  
  149. static alt_alarm alarmerror;
  150.  
  151. static int shouldError = 0;
  152.  
  153. alt_u32 writeERROR(void* context) {
  154.     printf("OK_ERR\n");
  155.     if (shouldError == 0) {
  156.         IOWR(LEDS_RED_BASE, 0, LED17);
  157.         shouldError = 1;
  158.         return alt_ticks_per_second() * 2;
  159.     } else {
  160.         shouldError = 0;
  161.         return 0;
  162.     }
  163. }
  164.  
  165. /* Prints "Hello World" and sleeps for three seconds */
  166. void task1(void* pdata) {
  167.     alt_mutex_dev *mutex = altera_avalon_mutex_open("/dev/mutex");
  168.     while (1) {
  169.         //printf("Hello from task 1\n");
  170.         int sw;
  171.         sw = IORD(SW_SLIDERS_BASE, 0);
  172.  
  173.         altera_avalon_mutex_lock(mutex, 1);
  174.         IOWR(SHARED_MEMORY_BASE, 0, sw);
  175.         altera_avalon_mutex_unlock( mutex );
  176.  
  177.         sw = sw & (SW0 | SW1 | SW2 | SW3 | SW4 | SW5 | SW6);
  178.  
  179.         // Odliczanie czasu
  180.         if (sw != lastState) {
  181.             startNicks = alt_nticks();
  182.             //startTimeHex = alt_timestamp();
  183.             //printf("%d \n", startTimeHex);
  184.             //printf("%d \n", startNicks);
  185.         }
  186.  
  187.         //printf("Slider = %d\n", sw);
  188.         OSMboxPostOpt(SWBox1, &sw, OS_POST_OPT_BROADCAST);
  189.  
  190.         if (sw == 0) {
  191.             // Odliczanie czasu
  192.             if (sw != lastState) {
  193.                 startNicks = alt_nticks();
  194.             }
  195.             // Hex bez opoznienia
  196.             IOWR(HEX_3_BASE, 0, 0);
  197.             IOWR(LEDS_RED_BASE, 0, 0);
  198.             IOWR(LAB8_0_BASE, 0, 0);
  199.  
  200.             // Diody z opoznieneim
  201.             if (((alt_nticks() - startNicks) >= (2 * alt_ticks_per_second()))) {
  202.                 IOWR(LEDS_RED_BASE, 0, 0);
  203.                 IOWR(LAB8_0_BASE, 0, 0);
  204.             }
  205.  
  206.         } else if (sw != SW0 && sw != SW1 && sw != SW2 && sw != SW3 && sw != SW4
  207.                 && sw != SW5 && sw != SW6 && sw < 128) {
  208.             if (sw != lastState) {
  209.                 // Hex bez opoznienia
  210.                 IOWR(LEDS_RED_BASE, 0, 0);
  211.                 IOWR(HEX_3_BASE, 0, ((HEXE<<16) | (HEXr<<8) | HEXr));
  212.                 IOWR(LAB8_0_BASE, 0, 5);
  213.                 shouldError = 0;
  214.                 // Ledy funkcja z opoznieniem
  215.                 alt_alarm_start(&alarmerror, alt_ticks_per_second(), writeERROR,
  216.                         sw);
  217.             }
  218.         }
  219.         if (sw == SW0 && shouldError == 0) {
  220.             int subSw;
  221.             subSw = IORD(SW_SLIDERS_BASE, 0);
  222.             subSw = subSw & (SW7 | SW8);
  223.  
  224.  
  225.             IOWR(HEX_3_BASE, 0, HEX1);
  226.             IOWR(LEDS_RED_BASE, 0, LED0);
  227.             IOWR(LAB8_0_BASE, 0, 0);
  228.  
  229.             if ((subSw & SW7) && (subSw & SW8)) {
  230.                 IOWR(HEX_3_BASE, 0, ((HEXE<<16) | (HEXr<<8) | HEXr));
  231.                 IOWR(LEDS_RED_BASE, 0, 0);
  232.                 IOWR(LEDS_RED_BASE, 0, LED17);
  233.                 OSTimeDlyHMSM(0, 0, 1, 0);
  234.             } else if (subSw == SW7) {
  235.                 IOWR(LEDS_RED_BASE, 0, LED0 | LED7);
  236.                 IOWR(HEX_3_BASE, 0, (HEXA<<8) | HEX1);
  237.                 OSTimeDlyHMSM(0, 0, 1, 0);
  238.             } else if (subSw == SW8) {
  239.                 IOWR(LEDS_RED_BASE, 0, LED0 | LED8);
  240.                 IOWR(HEX_3_BASE, 0, (HEXF<<8) | HEX1);
  241.                 OSTimeDlyHMSM(0, 0, 1, 0);
  242.             }
  243.         }
  244.         OSTimeDlyHMSM(0, 0, 1, 0);
  245.         lastState = sw;
  246.     }
  247. }
  248.  
  249. /* Prints "Hello World" and sleeps for three seconds */
  250. void task2(void* pdata) {
  251.     while (1) {
  252.         INT8U err;
  253.         //printf("Hello from task 2\n");
  254.         int *sw;
  255.         sw = OSMboxPend(SWBox1, 0, &err);
  256.  
  257.         if (err == OS_NO_ERR) {
  258.             //printf("T=%d\n", *sw);
  259.             if (*sw == SW1) {
  260.                 IOWR(LAB8_0_BASE, 0, 2);
  261.                 IOWR(LEDS_RED_BASE, 0, 0);
  262.                 IOWR(HEX_3_BASE, 0, 0);
  263.                 //OSTimeDlyHMSM(0, 0, 1, 0);
  264.             }
  265.             OSTimeDlyHMSM(0, 0, 1, 0);
  266.         } else if (err == OS_TIMEOUT) {
  267.             printf("Timeout\n");
  268.             OSTimeDlyHMSM(0, 0, 1, 0);
  269.         }
  270.  
  271.     }
  272. }
  273.  
  274. void task3(void* pdata) {
  275.     while (1) {
  276.         INT8U err;
  277.         //printf("Hello from task 3\n");
  278.         int *sw;
  279.         sw = OSMboxPend(SWBox1, 0, &err);
  280.  
  281.         if (err == OS_NO_ERR) {
  282.             //printf("T=%d\n", *sw);
  283.             if (*sw == SW2) {
  284.                 /*
  285.                 IOWR(HEX_3_BASE, 0, HEX3);
  286.                 IOWR(LEDS_RED_BASE, 0, LED2);
  287.                 //OSTimeDlyHMSM(0, 0, 1, 0);
  288.                  * */
  289.             }
  290.             OSTimeDlyHMSM(0, 0, 1, 0);
  291.         } else if (err == OS_TIMEOUT) {
  292.             printf("Timeout\n");
  293.             OSTimeDlyHMSM(0, 0, 1, 0);
  294.         }
  295.     }
  296. }
  297.  
  298. void task4(void* pdata) {
  299.     while (1) {
  300.         INT8U err;
  301.         //printf("Hello from task 4\n");
  302.         int *sw;
  303.         sw = OSMboxPend(SWBox1, 0, &err);
  304.  
  305.         if (err == OS_NO_ERR) {
  306.             //printf("T=%d\n", *sw);
  307.             if (*sw == SW3) {
  308.                 int subSw;
  309.                 subSw = IORD(SW_SLIDERS_BASE, 0);
  310.                 subSw = subSw & (SW9 | SW10 | SW11 | SW12);
  311.  
  312.                 IOWR(HEX_3_BASE, 0, HEX4);
  313.                 IOWR(LEDS_RED_BASE, 0, LED3);
  314.  
  315.                 if (((subSw & SW9) && (subSw & SW10))
  316.                         || ((subSw & SW9) && (subSw & SW11))
  317.                         || ((subSw & SW9) && (subSw & SW12))
  318.                         || ((subSw & SW10) && (subSw & SW11))
  319.                         || ((subSw & SW10) && (subSw & SW12))
  320.                         || ((subSw & SW11) && (subSw & SW12))) {
  321.                     IOWR(LEDS_RED_BASE, 0, LED17);
  322.                     IOWR(HEX_3_BASE, 0, ((HEXE<<24) | (HEXr<<16) | (HEXr<<8)));
  323.                     OSTimeDlyHMSM(0, 0, 1, 0);
  324.                 } else if (subSw == SW9) {
  325.                     IOWR(LEDS_RED_BASE, 0, LED9 | LED3);
  326.                     IOWR(HEX_3_BASE, 0, ((HEXC<<16)| (HEX1 <<8) | HEX4));
  327.                     OSTimeDlyHMSM(0, 0, 1, 0);
  328.                 } else if (subSw == SW10) {
  329.                     IOWR(LEDS_RED_BASE, 0, LED10 | LED3);
  330.                     IOWR(HEX_3_BASE, 0, ((HEXC<<16)| (HEX2 <<8) | HEX4));
  331.                     OSTimeDlyHMSM(0, 0, 1, 0);
  332.                 } else if (subSw == SW11) {
  333.                     IOWR(LEDS_RED_BASE, 0, LED11 | LED3);
  334.                     IOWR(HEX_3_BASE, 0, ((HEXD<<16)| (HEX1 <<8) | HEX4));
  335.                     OSTimeDlyHMSM(0, 0, 1, 0);
  336.                 } else if (subSw == SW12) {
  337.                     IOWR(LEDS_RED_BASE, 0, LED12 | LED3);
  338.                     IOWR(HEX_3_BASE, 0, ((HEXD<<16)| (HEX2 <<8) | HEX4));
  339.                     OSTimeDlyHMSM(0, 0, 1, 0);
  340.                 }
  341.  
  342.                 //OSTimeDlyHMSM(0, 0, 1, 0);
  343.             }
  344.             OSTimeDlyHMSM(0, 0, 1, 0);
  345.         } else if (err == OS_TIMEOUT) {
  346.             printf("Timeout\n");
  347.             OSTimeDlyHMSM(0, 0, 1, 0);
  348.         }
  349.     }
  350. }
  351. void task5(void* pdata) {
  352.     while (1) {
  353.         INT8U err;
  354.         //printf("Hello from task 5\n");
  355.         int *sw;
  356.         sw = OSMboxPend(SWBox1, 0, &err);
  357.  
  358.         if (err == OS_NO_ERR) {
  359.             //printf("T=%d\n", *sw);
  360.             if (*sw == SW4) {
  361.                 IOWR(HEX_3_BASE, 0, HEX5);
  362.                 IOWR(LEDS_RED_BASE, 0, LED4);
  363.                 //OSTimeDlyHMSM(0, 0, 1, 0);
  364.             }
  365.             OSTimeDlyHMSM(0, 0, 1, 0);
  366.         } else if (err == OS_TIMEOUT) {
  367.             printf("Timeout\n");
  368.             OSTimeDlyHMSM(0, 0, 1, 0);
  369.         }
  370.     }
  371. }
  372. void task6(void* pdata) {
  373.     while (1) {
  374.         INT8U err;
  375.         //printf("Hello from task 6\n");
  376.         int *sw;
  377.         sw = OSMboxPend(SWBox1, 0, &err);
  378.  
  379.         if (err == OS_NO_ERR) {
  380.             //printf("T=%d\n", *sw);
  381.             if (*sw == SW5) {
  382.                 IOWR(HEX_3_BASE, 0, HEX6);
  383.                 IOWR(LEDS_RED_BASE, 0, LED5);
  384.                 //OSTimeDlyHMSM(0, 0, 1, 0);
  385.             }
  386.             OSTimeDlyHMSM(0, 0, 1, 0);
  387.         } else if (err == OS_TIMEOUT) {
  388.             printf("Timeout\n");
  389.             OSTimeDlyHMSM(0, 0, 1, 0);
  390.         }
  391.     }
  392. }
  393. void task7(void* pdata) {
  394.     while (1) {
  395.         INT8U err;
  396.         //printf("Hello from task 7\n");
  397.         int *sw;
  398.         sw = OSMboxPend(SWBox1, 0, &err);
  399.  
  400.         if (err == OS_NO_ERR) {
  401.             //printf("T=%d\n", *sw);
  402.             if (*sw == SW6) {
  403.                 IOWR(HEX_3_BASE, 0, HEX7);
  404.                 IOWR(LEDS_RED_BASE, 0, LED6);
  405.                 //OSTimeDlyHMSM(0, 0, 1, 0);
  406.             }
  407.             OSTimeDlyHMSM(0, 0, 1, 0);
  408.         } else if (err == OS_TIMEOUT) {
  409.             printf("Timeout\n");
  410.             OSTimeDlyHMSM(0, 0, 1, 0);
  411.         }
  412.     }
  413. }
  414.  
  415. // IOWR(HEX_3_BASE, 0, ((HEX9<<8)| HEX0));
  416.  
  417. /* The main function creates two task and starts multi-tasking */
  418. int main(void) {
  419.  
  420.     SWBox1 = OSMboxCreate((void*) 0);
  421.     //alt_timestamp_start();
  422.  
  423.     OSTaskCreateExt(task1,
  424.     NULL, (void *) &task1_stk[TASK_STACKSIZE - 1],
  425.     TASK1_PRIORITY,
  426.     TASK1_PRIORITY, task1_stk,
  427.     TASK_STACKSIZE,
  428.     NULL, 0);
  429.  
  430.     OSTaskCreateExt(task2,
  431.     NULL, (void *) &task2_stk[TASK_STACKSIZE - 1],
  432.     TASK2_PRIORITY,
  433.     TASK2_PRIORITY, task2_stk,
  434.     TASK_STACKSIZE,
  435.     NULL, 0);
  436.  
  437.     OSTaskCreateExt(task3,
  438.     NULL, (void *) &task3_stk[TASK_STACKSIZE - 1],
  439.     TASK3_PRIORITY,
  440.     TASK3_PRIORITY, task3_stk,
  441.     TASK_STACKSIZE,
  442.     NULL, 0);
  443.  
  444.     OSTaskCreateExt(task4,
  445.     NULL, (void *) &task4_stk[TASK_STACKSIZE - 1],
  446.     TASK4_PRIORITY,
  447.     TASK4_PRIORITY, task4_stk,
  448.     TASK_STACKSIZE,
  449.     NULL, 0);
  450.  
  451.     OSTaskCreateExt(task5,
  452.     NULL, (void *) &task5_stk[TASK_STACKSIZE - 1],
  453.     TASK5_PRIORITY,
  454.     TASK5_PRIORITY, task5_stk,
  455.     TASK_STACKSIZE,
  456.     NULL, 0);
  457.  
  458.     OSTaskCreateExt(task6,
  459.     NULL, (void *) &task6_stk[TASK_STACKSIZE - 1],
  460.     TASK6_PRIORITY,
  461.     TASK6_PRIORITY, task6_stk,
  462.     TASK_STACKSIZE,
  463.     NULL, 0);
  464.  
  465.     OSTaskCreateExt(task7,
  466.     NULL, (void *) &task7_stk[TASK_STACKSIZE - 1],
  467.     TASK7_PRIORITY,
  468.     TASK7_PRIORITY, task7_stk,
  469.     TASK_STACKSIZE,
  470.     NULL, 0);
  471.  
  472.     OSStart();
  473.  
  474. }
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489. /*
  490.  * "Hello World" example.
  491.  *
  492.  * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
  493.  * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
  494.  * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
  495.  * device in your system's hardware.
  496.  * The memory footprint of this hosted application is ~69 kbytes by default
  497.  * using the standard reference design.
  498.  *
  499.  * For a reduced footprint version of this template, and an explanation of how
  500.  * to reduce the memory footprint for a given application, see the
  501.  * "small_hello_world" template.
  502.  *
  503.  */
  504.  
  505. #include <stdio.h>
  506. #include <io.h>
  507. #include <system.h>
  508. #include <altera_avalon_mutex.h>
  509.  
  510. /* Przełączniki */
  511. #define  SW0 0x00000001
  512. #define  SW1 0x00000002
  513. #define  SW2 0x00000004
  514. #define  SW3 0x00000008
  515. #define  SW4 0x00000010
  516. #define  SW5 0x00000020
  517. #define  SW6 0x00000040
  518. #define  SW7 0x00000080
  519. #define  SW8 0x00000100
  520. #define  SW9 0x00000200
  521. #define  SW10 0x00000400
  522. #define  SW11 0x00000800
  523. #define  SW12 0x00001000
  524. #define  SW13 0x00002000
  525. #define  SW14 0x00004000
  526. #define  SW15 0x00008000
  527. #define  SW16 0x00010000
  528. #define  SW17 0x00020000
  529.  
  530. /* Ledy */
  531. #define  LED0 0x00000001
  532. #define  LED1 0x00000002
  533. #define  LED2 0x00000004
  534. #define  LED3 0x00000008
  535. #define  LED4 0x00000010
  536. #define  LED5 0x00000020
  537. #define  LED6 0x00000040
  538. #define  LED7 0x00000080
  539. #define  LED8 0x00000100
  540. #define  LED9 0x00000200
  541. #define  LED10 0x00000400
  542. #define  LED11 0x00000800
  543. #define  LED12 0x00001000
  544. #define  LED13 0x00002000
  545. #define  LED14 0x00004000
  546. #define  LED15 0x00008000
  547. #define  LED16 0x00010000
  548. #define  LED17 0x00020000
  549.  
  550. /* Litery i cyfry z hex 7 segmentowych */
  551. #define HEX0 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF)
  552. #define HEX1 (SEGB|SEGC)
  553. #define HEX2 (SEGA|SEGB|SEGG|SEGE|SEGD)
  554. #define HEX3 (SEGA|SEGB|SEGC|SEGD|SEGG)
  555. #define HEX4 (SEGF|SEGG|SEGB|SEGC)
  556. #define HEX5 (SEGA|SEGF|SEGG|SEGC|SEGD)
  557. #define HEX6 (SEGA|SEGF|SEGG|SEGC|SEGD|SEGE)
  558. #define HEX7 (SEGA|SEGB|SEGC)
  559. #define HEX8 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG)
  560. #define HEX9 (SEGA|SEGB|SEGC|SEGD|SEGF|SEGG)
  561. #define HEXE (SEGA|SEGF|SEGG|SEGE|SEGD)
  562. #define HEXr (SEGE|SEGG)
  563. #define HEXA (SEGA|SEGB|SEGC|SEGE|SEGF|SEGG)
  564. #define HEXF (SEGA|SEGE|SEGF|SEGG)
  565. #define HEXC (SEGA|SEGE|SEGF|SEGD)
  566. #define HEXD (SEGB|SEGC|SEGD|SEGE|SEGG)
  567.  
  568. /* Segmenty HEX */
  569. #define  SEGA 1
  570. #define  SEGB 2
  571. #define  SEGC 4
  572. #define  SEGD 8
  573. #define  SEGE 16
  574. #define  SEGF 32
  575. #define  SEGG 64
  576.  
  577. int main() {
  578.     alt_mutex_dev* mutex = altera_avalon_mutex_open("/dev/mutex");
  579.     int x;
  580.  
  581.     while (1) {
  582.  
  583.         altera_avalon_mutex_lock(mutex, 1);
  584.         x = IORD(SHARED_MEMORY_BASE, 0);
  585.         altera_avalon_mutex_unlock(mutex);
  586.  
  587.         IOWR(LEDS_RED_BASE, 0, x);
  588.  
  589.         if(x == SW2) {
  590.             IOWR(HEX_3_BASE, 0, HEX3);
  591.         }
  592.     }
  593.  
  594.     return 0;
  595.  
  596. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement