Advertisement
Guest User

SW6

a guest
Nov 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "includes.h"
  3.  
  4. #include <alt_types.h>
  5. #include <altera_avalon_pio_regs.h>
  6. #include <io.h>
  7. #include <sys/alt_irq.h>
  8. #include <sys/alt_alarm.h>
  9.  
  10. #define  SW0 0x00000001
  11. #define  SW1 0x00000002
  12. #define  SW2 0x00000004
  13. #define  SW3 0x00000008
  14. #define  SW4 0x00000010
  15. #define  SW5 0x00000020
  16.  
  17. #define  LEDG0 0x00000001
  18. #define  LEDG1 0x00000002
  19. #define  LEDG2 0x00000004
  20. #define  LEDG3 0x00000008
  21. #define  LEDG4 0x00000010
  22. #define  LEDG5 0x00000020
  23.  
  24. #define  LEDR17 0x00020000
  25.  
  26. #define  SEGA 0b0000001
  27. #define  SEGB 0b0000010
  28. #define  SEGC 0b0000100
  29. #define  SEGD 0b0001000
  30. #define  SEGE 0b0010000
  31. #define  SEGF 0b0100000
  32. #define  SEGG 0b1000000
  33.  
  34. #define HEX0 0b0111111 //SEGA|SEGB|SEGC|SEGD|SEGE|SEGF;
  35. #define HEX3 0b1001111 //SEGA|SEGB|SEGC|SEGD|SEGG;
  36. #define HEX4 0b1100110 //SEGF|SEGG|SEGB|SEGC;
  37. #define HEX5 0b1101101 //SEGA|SEGF|SEGG|SEGC|SEGD;
  38. #define HEX6 0b1111101 //SEGA|SEGF|SEGG|SEGC|SEGD|SEGE;
  39. #define HEX8 0b1111111 //SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG;
  40. #define HEX9 0b1101111 //SEGA|SEGB|SEGC|SEGD|SEGF|SEGG;
  41. #define HEXE 0b1111001 //SEGA|SEGF|SEGG|SEGE|SEGD;
  42. #define HEXr 0b1010000 //SEGE|SEGG;
  43.  
  44. typedef enum POZIOM_TEMP
  45. {
  46.     POZIOM_0 = 0,
  47.     POZIOM_1 = 2,
  48.     POZIOM_2 = 4,
  49.     POZIOM_3 = 8,
  50.     POZIOM_4 = 16,
  51.     POZIOM_5 = 32,
  52.     POZIOM_6 = 64,
  53.     POZIOM_7 = 128,
  54.     POZIOM_8 = 256,
  55.     POZIOM_9 = 512,
  56.     POZIOM_10 = 1024,
  57.  
  58. } TEMP;
  59.  
  60. /* Definition of Task Stacks */
  61. #define   TASK_STACKSIZE       2048
  62. OS_STK task1_stk[TASK_STACKSIZE];
  63. OS_STK task2_stk[TASK_STACKSIZE];
  64. OS_STK task3_stk[TASK_STACKSIZE];
  65. OS_STK task4_stk[TASK_STACKSIZE];
  66. OS_STK task5_stk[TASK_STACKSIZE];
  67. OS_STK task6_stk[TASK_STACKSIZE];
  68.  
  69. /* Definition of Task Priorities */
  70.  
  71. #define TASK1_PRIORITY      1
  72. #define TASK2_PRIORITY      2
  73. #define TASK3_PRIORITY      3
  74. #define TASK4_PRIORITY      4
  75. #define TASK5_PRIORITY      5
  76. #define TASK5_PRIORITY      6
  77.  
  78. OS_EVENT *SWBox1;
  79.  
  80. /* Prints "Hello World" and sleeps for three seconds */
  81. void task1(void* pdata)
  82. {
  83.     while (1)
  84.     {
  85.         printf("Hello from task1\n");
  86.         int switches;
  87.         switches = IORD(SW_SLIDERS_BASE, 0);
  88.         int state;
  89.         state = switches & (SW0|SW1|SW2|SW3|SW4|SW5);
  90.  
  91.         printf("State = %d\n", state);
  92.         OSMboxPostOpt(SWBox1, &state, OS_POST_OPT_BROADCAST);
  93.  
  94.         if (state == 0)
  95.         {
  96.             IOWR(HEX_3_BASE, 0, 0);
  97.             IOWR(LEDS_GREEN_BASE, 0, 0);
  98.             IOWR(LEDS_RED_BASE, 0, 0);
  99.         }
  100.         else if (state != SW0 && state != SW1 && state != SW2 && state != SW3 && state != SW4 && state != SW5 && state < 64)
  101.         {
  102.             IOWR(LEDS_GREEN_BASE,0,0);
  103.             IOWR(LEDS_RED_BASE,0,LEDR17);
  104.             IOWR(HEX_3_BASE,0,((HEXE<<16) | (HEXr<<8) | HEXr));
  105.         }
  106.  
  107.         if (state == SW1)
  108.         {
  109.             IOWR(LEDS_RED_BASE,0,0);
  110.             IOWR(LEDS_GREEN_BASE,0,LEDG0);
  111.             IOWR(HEX_3_BASE,0,((HEX3<<8)| HEX0));
  112.         }
  113.  
  114.         OSTimeDlyHMSM(0, 0, 0, 10);
  115.     }
  116. }
  117. /* Prints "Hello World" and sleeps for three seconds */
  118. void task2(void* pdata)
  119. {
  120.     while (1)
  121.     {
  122.         INT8U err;
  123.         printf("Hello from task2\n");
  124.         int *state;
  125.  
  126.         state = OSMboxPend(SWBox1, 0, &err);
  127.  
  128.         printf("T=%d\n", *state);
  129.         if (*state == 2)
  130.         {
  131.             IOWR(LEDS_RED_BASE,0,0);
  132.             IOWR(LEDS_GREEN_BASE,0,LEDG1);
  133.             IOWR(HEX_3_BASE,0,((HEX3<<8)| HEX5));
  134.         }
  135.  
  136.         OSTimeDlyHMSM(0, 0, 0, 10);
  137.     }
  138. }
  139.  
  140. void task3(void* pdata)
  141. {
  142.     while (1)
  143.     {
  144.         INT8U err;
  145.         printf("Hello from task3\n");
  146.         int *state;
  147.  
  148.         state = OSMboxPend(SWBox1, 0, &err);
  149.  
  150.         printf("T=%d\n", *state);
  151.         if (*state == 4)
  152.         {
  153.             IOWR(LEDS_RED_BASE,0,0);
  154.             IOWR(LEDS_GREEN_BASE,0,LEDG2);
  155.             IOWR(HEX_3_BASE,0,((HEX4<<8)| HEX0));
  156.         }
  157.  
  158.         OSTimeDlyHMSM(0, 0, 0, 10);
  159.     }
  160. }
  161.  
  162. void task4(void* pdata)
  163. {
  164.     while (1)
  165.     {
  166.         INT8U err;
  167.         printf("Hello from task4\n");
  168.         int *state;
  169.  
  170.         state = OSMboxPend(SWBox1, 0, &err);
  171.  
  172.         printf("T=%d\n", *state);
  173.         if (*state == 8)
  174.         {
  175.             IOWR(LEDS_RED_BASE,0,0);
  176.             IOWR(LEDS_GREEN_BASE,0,LEDG3);
  177.             IOWR(HEX_3_BASE,0,((HEX6<<8)| HEX0));
  178.         }
  179.  
  180.         OSTimeDlyHMSM(0, 0, 0, 10);
  181.     }
  182. }
  183.  
  184. void task5(void* pdata)
  185. {
  186.     while (1)
  187.     {
  188.         INT8U err;
  189.         printf("Hello from task5\n");
  190.         int *state;
  191.  
  192.         state = OSMboxPend(SWBox1, 0, &err);
  193.  
  194.         printf("T=%d\n", *state);
  195.         if (*state == 16)
  196.         {
  197.             IOWR(LEDS_RED_BASE,0,0);
  198.             IOWR(LEDS_GREEN_BASE,0,LEDG4);
  199.             IOWR(HEX_3_BASE,0,((HEX8<<8)| HEX0));
  200.         }
  201.  
  202.         OSTimeDlyHMSM(0, 0, 0, 10);
  203.     }
  204. }
  205.  
  206. void task6(void* pdata)
  207. {
  208.     while (1)
  209.     {
  210.         INT8U err;
  211.         printf("Hello from task6\n");
  212.         int *state;
  213.  
  214.         state = OSMboxPend(SWBox1, 0, &err);
  215.  
  216.         printf("T=%d\n", *state);
  217.         if (*state == 32)
  218.         {
  219.             IOWR(LEDS_RED_BASE,0,0);
  220.             IOWR(LEDS_GREEN_BASE,0,LEDG5);
  221.             IOWR(HEX_3_BASE,0,((HEX9<<8)| HEX0));
  222.         }
  223.  
  224.         OSTimeDlyHMSM(0, 0, 0, 10);
  225.     }
  226. }
  227.  
  228.  
  229. /* The main function creates two task and starts multi-tasking */
  230. int main(void)
  231. {
  232.  
  233.     SWBox1 = OSMboxCreate((void*) 0);
  234.  
  235.     OSTaskCreateExt(task1,
  236.                     NULL, (void *) &task1_stk[TASK_STACKSIZE - 1],
  237.                     TASK1_PRIORITY,
  238.                     TASK1_PRIORITY, task1_stk,
  239.                     TASK_STACKSIZE,
  240.                     NULL, 0);
  241.  
  242.     OSTaskCreateExt(task2,
  243.                     NULL, (void *) &task2_stk[TASK_STACKSIZE - 1],
  244.                     TASK2_PRIORITY,
  245.                     TASK2_PRIORITY, task2_stk,
  246.                     TASK_STACKSIZE,
  247.                     NULL, 0);
  248.  
  249.     OSTaskCreateExt(task3,
  250.                     NULL, (void *) &task3_stk[TASK_STACKSIZE - 1],
  251.                     TASK3_PRIORITY,
  252.                     TASK3_PRIORITY, task3_stk,
  253.                     TASK_STACKSIZE,
  254.                     NULL, 0);
  255.  
  256.     OSTaskCreateExt(task4,
  257.                     NULL, (void *) &task4_stk[TASK_STACKSIZE - 1],
  258.                     TASK4_PRIORITY,
  259.                     TASK4_PRIORITY, task4_stk,
  260.                     TASK_STACKSIZE,
  261.                     NULL, 0);
  262.  
  263.     OSTaskCreateExt(task5,
  264.                     NULL, (void *) &task5_stk[TASK_STACKSIZE - 1],
  265.                     TASK5_PRIORITY,
  266.                     TASK5_PRIORITY, task5_stk,
  267.                     TASK_STACKSIZE,
  268.                     NULL, 0);
  269.  
  270.     OSTaskCreateExt(task6,
  271.                     NULL, (void *) &task6_stk[TASK_STACKSIZE - 1],
  272.                     TASK6_PRIORITY,
  273.                     TASK6_PRIORITY, task6_stk,
  274.                     TASK_STACKSIZE,
  275.                     NULL, 0);
  276.  
  277.     OSStart();
  278.     return 0;
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement