Advertisement
Sothian

ProbaMailBoxa

Nov 16th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.12 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.  
  27. struct interrupt_data {
  28.     volatile int* leds_addr;
  29.     volatile int* sliders_addr;
  30.     volatile int* hex_addr;
  31. };
  32. /* Przełączniki */
  33. #define  SW0 0x00000001
  34. #define  SW1 0x00000002
  35. #define  SW2 0x00000004
  36. #define  SW3 0x00000008
  37. #define  SW4 0x00000010
  38. #define  SW5 0x00000020
  39. #define  SW6 0x00000040
  40. #define  SW7 0x00000080
  41. #define  SW8 0x00000100
  42. #define  SW9 0x00000200
  43. #define  SW10 0x00000400
  44. #define  SW11 0x00000800
  45. #define  SW12 0x00001000
  46. #define  SW13 0x00002000
  47. #define  SW14 0x00004000
  48. #define  SW15 0x00008000
  49. #define  SW16 0x00010000
  50. #define  SW17 0x00020000
  51.  
  52. /* PushButtony */
  53. #define  KEY1 0x00000002
  54. #define  KEY2 0x00000004
  55. #define  KEY3 0x00000008
  56.  
  57. /* Ledy */
  58. #define  LED0 0x00000001
  59. #define  LED1 0x00000002
  60. #define  LED2 0x00000004
  61. #define  LED3 0x00000008
  62. #define  LED4 0x00000010
  63. #define  LED5 0x00000020
  64. #define  LED6 0x00000040
  65. #define  LED7 0x00000080
  66. #define  LED8 0x00000100
  67. #define  LED9 0x00000200
  68. #define  LED10 0x00000400
  69. #define  LED11 0x00000800
  70. #define  LED12 0x00001000
  71. #define  LED13 0x00002000
  72. #define  LED14 0x00004000
  73. #define  LED15 0x00008000
  74. #define  LED16 0x00010000
  75. #define  LED17 0x00020000
  76.  
  77. /* Segmenty HEX */
  78. #define  SEGA 1
  79. #define  SEGB 2
  80. #define  SEGC 4
  81. #define  SEGD 8
  82. #define  SEGE 16
  83. #define  SEGF 32
  84. #define  SEGG 64
  85.  
  86. /* Litery i cyfry z hex 7 segmentowych */
  87. #define HEX0 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF)
  88. #define HEX1 (SEGB|SEGC)
  89. #define HEX2 (SEGA|SEGB|SEGG|SEGE|SEGD)
  90. #define HEX3 (SEGA|SEGB|SEGC|SEGD|SEGG)
  91. #define HEX4 (SEGF|SEGG|SEGB|SEGC)
  92. #define HEX5 (SEGA|SEGF|SEGG|SEGC|SEGD)
  93. #define HEX6 (SEGA|SEGF|SEGG|SEGC|SEGD|SEGE)
  94. #define HEX7 (SEGA|SEGB|SEGC)
  95. #define HEX8 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG)
  96. #define HEX9 (SEGA|SEGB|SEGC|SEGD|SEGF|SEGG)
  97. #define HEXE (SEGA|SEGF|SEGG|SEGE|SEGD)
  98. #define HEXr (SEGE|SEGG)
  99. #define HEXA (SEGA|SEGB|SEGC|SEGE|SEGF|SEGG)
  100. #define HEXF (SEGA|SEGE|SEGF|SEGG)
  101. #define HEXC (SEGA|SEGE|SEGF|SEGD)
  102. #define HEXD (SEGB|SEGC|SEGD|SEGE|SEGG)
  103.  
  104. typedef enum POZIOM_TEMP {
  105.     POZIOM_0 = 0,
  106.     POZIOM_1 = 2,
  107.     POZIOM_2 = 4,
  108.     POZIOM_3 = 8,
  109.     POZIOM_4 = 16,
  110.     POZIOM_5 = 32,
  111.     POZIOM_6 = 64,
  112.     POZIOM_7 = 128,
  113.     POZIOM_8 = 256,
  114.     POZIOM_9 = 512,
  115.     POZIOM_10 = 1024,
  116.  
  117. } TEMP;
  118.  
  119. #define TASK_STACKSIZE 2048;
  120. OS_STK task1_stk[TASK_STACKSIZE];
  121. OS_STK task2_stk[TASK_STACKSIZE];
  122. OS_STK task3_stk[TASK_STACKSIZE];
  123. OS_STK task4_stk[TASK_STACKSIZE];
  124. OS_STK task5_stk[TASK_STACKSIZE];
  125. OS_STK task6_stk[TASK_STACKSIZE];
  126. OS_STK task7_stk[TASK_STACKSIZE];
  127.  
  128. OS_EVENT *SWBox1;
  129.  
  130. /* Definition of Task Priorities */
  131.  
  132. #define TASK1_PRIORITY 1;
  133. #define TASK2_PRIORITY 2;
  134. #define TASK3_PRIORITY 3;
  135. #define TASK4_PRIORITY 4;
  136. #define TASK5_PRIORITY 5;
  137. #define TASK6_PRIORITY 6;
  138. #define TASK7_PRIORITY 7;
  139.  
  140. void VGA_text (int, int, char *);
  141.  
  142. /* Prints "Hello World" and sleeps for three seconds */
  143. void task1(void* pdata) {
  144.     while (1) {
  145.         printf("Hello from task 1\n");
  146.         int sw;
  147.         sw = IORD(SW_SLIDERS_BASE, 0);
  148.         sw = sw & (SW0 | SW1 | SW2 | SW3 | SW4 | SW5 | SW6);
  149.  
  150.         printf("Slider = %d\n", sw);
  151.         OSMboxPostOpt(SWBox1, &sw, OS_POST_OPT_BROADCAST);
  152.  
  153.         if (sw == 0) {
  154.             IOWR(HEX_3_BASE, 0, 0);
  155.             IOWR(LEDS_RED_BASE, 0, 0);
  156.         } else if (sw != SW0 && sw != SW1 && sw != SW2 && sw != SW3 && sw != SW4
  157.                 && sw != SW5 && sw != SW6 && sw < 128) {
  158.             IOWR(HEX_3_BASE, 0, ((HEXE<<16) | (HEXr<<8) | HEXr));
  159.             IOWR(LEDS_RED_BASE, 0, LED17);
  160.         }
  161.         if (sw == SW0) {
  162.             IOWR(HEX_3_BASE, 0, HEX1);
  163.             IOWR(LEDS_RED_BASE, 0, LED0);
  164.         }
  165.  
  166.         OSTimeDlyHMSM(0, 0, 0, 10);
  167.     }
  168. }
  169.  
  170. /* Prints "Hello World" and sleeps for three seconds */
  171. void task2(void* pdata) {
  172.     while (1) {
  173.         INT8U err;
  174.         printf("Hello from task 2\n");
  175.         int *sw;
  176.  
  177.         sw = OSMboxPend(SWBox1, 0, &err);
  178.  
  179.         printf("T=%d\n", *sw);
  180.         if (*sw == SW1) {
  181.             IOWR(HEX_3_BASE, 0, HEX2);
  182.             IOWR(LEDS_RED_BASE, 0, LED1);
  183.         }
  184.         OSTimeDlyHMSM(0, 0, 0, 10);
  185.     }
  186. }
  187.  
  188. void task3(void* pdata) {
  189.     while (1) {
  190.         INT8U err;
  191.         printf("Hello from task 3\n");
  192.         int *sw;
  193.  
  194.         sw = OSMboxPend(SWBox1, 0, &err);
  195.  
  196.         printf("T=%d\n", *sw);
  197.         if (*sw == SW2) {
  198.             IOWR(HEX_3_BASE, 0, HEX3);
  199.             IOWR(LEDS_RED_BASE, 0, LED2);
  200.         }
  201.         OSTimeDlyHMSM(0, 0, 0, 10);
  202.     }
  203. }
  204. void task4(void* pdata) {
  205.     while (1) {
  206.         INT8U err;
  207.         printf("Hello from task 4\n");
  208.         int *sw;
  209.  
  210.         sw = OSMboxPend(SWBox1, 0, &err);
  211.  
  212.         printf("T=%d\n", *sw);
  213.         if (*sw == SW3) {
  214.             IOWR(HEX_3_BASE, 0, HEX4);
  215.             IOWR(LEDS_RED_BASE, 0, LED3);
  216.         }
  217.         OSTimeDlyHMSM(0, 0, 0, 10);
  218.     }
  219. }
  220. void task5(void* pdata) {
  221.     while (1) {
  222.         INT8U err;
  223.         printf("Hello from task 5\n");
  224.         int *sw;
  225.  
  226.         sw = OSMboxPend(SWBox1, 0, &err);
  227.  
  228.         printf("T=%d\n", *sw);
  229.         if (*sw == SW4) {
  230.             IOWR(HEX_3_BASE, 0, HEX5);
  231.             IOWR(LEDS_RED_BASE, 0, LED4);
  232.         }
  233.         OSTimeDlyHMSM(0, 0, 0, 10);
  234.     }
  235. }
  236. void task6(void* pdata) {
  237.     while (1) {
  238.         INT8U err;
  239.         printf("Hello from task 6\n");
  240.         int *sw;
  241.  
  242.         sw = OSMboxPend(SWBox1, 0, &err);
  243.  
  244.         printf("T=%d\n", *sw);
  245.         if (*sw == SW5) {
  246.             IOWR(HEX_3_BASE, 0, HEX6);
  247.             IOWR(LEDS_RED_BASE, 0, LED5);
  248.         }
  249.         OSTimeDlyHMSM(0, 0, 0, 10);
  250.     }
  251. }
  252. void task7(void* pdata) {
  253.     while (1) {
  254.         INT8U err;
  255.         printf("Hello from task 7\n");
  256.         int *sw;
  257.  
  258.         sw = OSMboxPend(SWBox1, 0, &err);
  259.  
  260.         printf("T=%d\n", *sw);
  261.         if (*sw == SW5) {
  262.             IOWR(HEX_3_BASE, 0, HEX7);
  263.             IOWR(LEDS_RED_BASE, 0, LED6);
  264.         }
  265.         OSTimeDlyHMSM(0, 0, 0, 10);
  266.     }
  267. }
  268.  
  269. // IOWR(HEX_3_BASE, 0, ((HEX9<<8)| HEX0));
  270.  
  271.  
  272. /* The main function creates two task and starts multi-tasking */
  273. int main(void) {
  274.  
  275.     SWBox1 = OSMboxCreate((void*) 0);
  276.  
  277.     OSTaskCreateExt(task1,
  278.     NULL, (void *) &task1_stk[TASK_STACKSIZE - 1],
  279.     TASK1_PRIORITY,
  280.     TASK1_PRIORITY, task1_stk,
  281.     TASK_STACKSIZE,
  282.     NULL, 0);
  283.  
  284.     OSTaskCreateExt(task2,
  285.     NULL, (void *) &task2_stk[TASK_STACKSIZE - 1],
  286.     TASK2_PRIORITY,
  287.     TASK2_PRIORITY, task2_stk,
  288.     TASK_STACKSIZE,
  289.     NULL, 0);
  290.  
  291.     OSTaskCreateExt(task3,
  292.     NULL, (void *) &task3_stk[TASK_STACKSIZE - 1],
  293.     TASK3_PRIORITY,
  294.     TASK3_PRIORITY, task3_stk,
  295.     TASK_STACKSIZE,
  296.     NULL, 0);
  297.  
  298.     OSTaskCreateExt(task4,
  299.     NULL, (void *) &task4_stk[TASK_STACKSIZE - 1],
  300.     TASK4_PRIORITY,
  301.     TASK4_PRIORITY, task4_stk,
  302.     TASK_STACKSIZE,
  303.     NULL, 0);
  304.  
  305.     OSTaskCreateExt(task5,
  306.     NULL, (void *) &task5_stk[TASK_STACKSIZE - 1],
  307.     TASK5_PRIORITY,
  308.     TASK5_PRIORITY, task5_stk,
  309.     TASK_STACKSIZE,
  310.     NULL, 0);
  311.  
  312.     OSTaskCreateExt(task6,
  313.     NULL, (void *) &task6_stk[TASK_STACKSIZE - 1],
  314.     TASK6_PRIORITY,
  315.     TASK6_PRIORITY, task6_stk,
  316.     TASK_STACKSIZE,
  317.     NULL, 0);
  318.  
  319.     OSTaskCreateExt(task7,
  320.     NULL, (void *) &task7_stk[TASK_STACKSIZE - 1],
  321.     TASK7_PRIORITY,
  322.     TASK7_PRIORITY, task7_stk,
  323.     TASK_STACKSIZE,
  324.     NULL, 0);
  325.  
  326.     OSStart();
  327.  
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement