Advertisement
Litigare

Untitled

Jun 17th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "includes.h"
  3. #include <system.h>
  4. #include <io.h>
  5.  
  6. //        sw_sliders
  7. #define  SW0 0x00000001
  8. #define  SW1 0x00000002
  9. #define  SW2 0x00000004
  10. #define  SW3 0x00000008
  11. #define  SW4 0x00000010
  12. #define  SW5 0x00000020
  13. #define  SW6 0x00000040
  14. //      leds
  15. #define  LED0 0x00000001
  16. #define  LED1 0x00000002
  17. #define  LED2 0x00000004
  18. #define  LED3 0x00000008
  19. #define  LED4 0x00000010
  20. #define  LED5 0x00000020
  21. #define  LED6 0x00000040
  22. #define  LED7 0x00000080
  23. #define  LED8 0x00000100
  24. #define  LED9 0x00000200
  25. //      hex
  26. #define  SEGA 0x00001
  27. #define  SEGB 0x00002
  28. #define  SEGC 0x00004
  29. #define  SEGD 0x00008
  30. #define  SEGE 0x00010
  31. #define  SEGF 0x00020
  32. #define  SEGG 0x00040
  33. //     hex - numbers
  34. #define ZERO SEGA | SEGB | SEGC | SEGD |SEGE | SEGF
  35. #define ONE  SEGB | SEGC
  36. #define TWO  SEGA | SEGB | SEGG | SEGE | SEGD
  37. #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
  38. #define FOUR SEGG | SEGF | SEGB | SEGC
  39. #define FIVE SEGA | SEGE | SEGG | SEGC | SEGD
  40. #define E  SEGA | SEGD | SEGE | SEGF | SEGG
  41. #define R  SEGE | SEGG
  42.  
  43. /* Definition of Task Stacks */
  44. #define   TASK_STACKSIZE       2048
  45. OS_STK    task1_stk[TASK_STACKSIZE];
  46. OS_STK    task2_stk[TASK_STACKSIZE];
  47. OS_STK    task3_stk[TASK_STACKSIZE];
  48. OS_STK    task4_stk[TASK_STACKSIZE];
  49. OS_STK    task5_stk[TASK_STACKSIZE];
  50. OS_STK    task6_stk[TASK_STACKSIZE];
  51.  
  52. /* Definition of Task Priorities */
  53.  
  54. #define TASK1_PRIORITY      1 // taski musza miec rozne priorytety wszystko wygaszone
  55. #define TASK2_PRIORITY      2 // 1 Czerwone 1 tramwaj stoi 2 zielione 2 tramwaj jedzie
  56. #define TASK3_PRIORITY      3 // 1 Czerwone zolte 1 tramwaj stoi 2 zolte 2 tramwaj jedzie
  57. #define TASK4_PRIORITY      4 // 1 zielone 1 tramwaj jedzie 2 czerwone 2 tramwaj stoi
  58. #define TASK5_PRIORITY      5 // 1 zolte 1 tramwaj jedzie 2 czerwone zolte 2 tramwaj stoi
  59. #define TASK6_PRIORITY      6 // awaria skrzyzowania zolte tramwaj obydwa zapalone.
  60.  
  61.  
  62. OS_EVENT *SWBox1;
  63.  
  64. /* Prints "Hello World" and sleeps for three seconds */
  65. void task1(void* pdata)
  66. {
  67.   while (1)
  68.   {
  69.       int sw;
  70.       sw= IORD(SW_SLIDERS_BASE, 0);
  71.  
  72.       switch(sw){
  73.          case 0:
  74.              for(int i=0; i<6 ; i++){
  75.                  IOWR(HEX_BASE, i, 0x0); }
  76.                  IOWR(LEDS_BASE, 0, 0x0);
  77.                  IOWR(LEDS_BASE, 0, 0xfff);
  78.              break;
  79.       case 1:
  80.           break;
  81.       case 2:
  82.               break;
  83.       case 4:
  84.               break;
  85.       case 8:
  86.               break;
  87.       case 16:
  88.                   break;
  89.       default:
  90.           if(sw > 32){
  91.               break;
  92.           }
  93.                   IOWR(HEX_BASE, 2, E);
  94.                   IOWR(HEX_BASE, 1, R);
  95.                   IOWR(HEX_BASE, 0, R);
  96.  
  97.   }
  98.  
  99.  
  100.       OSMboxPostOpt(SWBox1, &sw, OS_POST_OPT_BROADCAST);
  101.       OSTimeDlyHMSM(0, 0, 0, 10);
  102.   }
  103. }
  104. /* Prints "Hello World" and sleeps for three seconds */
  105. void task2(void* pdata)
  106. {while (1)
  107.         {
  108.       INT8U err;
  109.       int *num;
  110.       num = OSMboxPend(SWBox1, 0, &err);
  111.       printf("T2 =  \t [ %d ]\n", *num);
  112.  
  113.       switch(*num){
  114.      case 1: // 1 Czerwone 1 tramwaj stoi 2 zielione 2 tramwaj jedzie
  115.                               IOWR(LEDS_BASE, 0, LED0); // 1 CZ
  116.                               IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
  117.                               IOWR(LEDS_BASE, 0, LED7);// 2 Ziel
  118.  
  119.                      break;}
  120.  
  121.       OSTimeDlyHMSM(0, 0, 0, 10);
  122.   }
  123. }
  124.  
  125.  
  126.   void task3(void* pdata)
  127.   {while (1)
  128.         {
  129.       INT8U err;
  130.       int *num;
  131.       num = OSMboxPend(SWBox1, 0, &err);
  132.       printf("T3 = \t\t [ %d ]\n", *num);
  133.  
  134.       switch(*num){
  135.     case 2: // 1 Czerwone zolte 1 tramwaj stoi 2 zolte 2 tramwaj jedzie
  136.                       IOWR(LEDS_BASE, 0, LED0); // 1 CZ zol
  137.                       IOWR(LEDS_BASE, 0, LED1); // 1 CZ zol
  138.                       IOWR(LEDS_BASE, 0, LED6);// 2 Zolte
  139.                       IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
  140.  
  141.  
  142.                              break;}
  143.  
  144.               OSTimeDlyHMSM(0, 0, 0, 10);
  145.           }
  146.         }
  147.  
  148.  
  149.   void task4(void* pdata)
  150.   {
  151.       while (1)
  152.         {
  153.       INT8U err;
  154.       int *num;
  155.       num = OSMboxPend(SWBox1, 0, &err);
  156.       printf("T4 =  \t [ %d ]\n", *num);
  157.  
  158.      switch(*num){
  159.      case 4: // 1 zielone 1 tramwaj jedzie 2 czerwone 2 tramwaj stoi
  160.                       IOWR(LEDS_BASE, 0, LED2); // 1 ziel
  161.                       IOWR(LEDS_BASE, 0, LED5);// 2 cz
  162.                       IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
  163.                      break;}
  164.  
  165.       OSTimeDlyHMSM(0, 0, 0, 10);
  166.    }
  167.  }
  168.  
  169.  
  170.   void task5(void* pdata)
  171.   {
  172.  
  173.       while (1)
  174.         {
  175.       INT8U err;
  176.       int *num;
  177.       num = OSMboxPend(SWBox1, 0, &err);
  178.      //  printf("T5 =  \t [ %d ]\n", *num);
  179.  
  180.      switch(*num){
  181.         case 8:// 1 zolte 1 tramwaj jedzie 2 czerwone zolte 2 tramwaj stoi
  182.                           IOWR(LEDS_BASE, 0, LED1); // 1 zolte
  183.                           IOWR(LEDS_BASE, 0, LED5);// 2 Zolte
  184.                           IOWR(LEDS_BASE, 0, LED6);// 2 Zolte
  185.                           IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
  186.                              break;}
  187.  
  188.               OSTimeDlyHMSM(0, 0, 0, 10);
  189.           }
  190.         }
  191.  
  192.  
  193.   void task6(void* pdata)
  194.   {
  195.  
  196.       INT8U err;
  197.       int *num;
  198.       num = OSMboxPend(SWBox1, 0, &err);
  199.      //  printf("T5 =  \t [ %d ]\n", *num);
  200.  
  201.      switch(*num){
  202.          case 16: // awaria skrzyzowania zolte tramwaj obydwa zapalone.
  203.              IOWR(SHAREDMEMORY_BASE, 0, 6);
  204.  
  205.                                          break;}
  206.  
  207.                           OSTimeDlyHMSM(0, 0, 0, 10);
  208.  
  209.                     }
  210.  
  211.  
  212.  
  213. /* The main function creates two task and starts multi-tasking */
  214. int main(void)
  215. {
  216.     SWBox1 =OSMboxCreate((void*)0);
  217.  
  218.   OSTaskCreateExt(task1,
  219.                   NULL,
  220.                   (void *)&task1_stk[TASK_STACKSIZE-1],
  221.                   TASK1_PRIORITY,
  222.                   TASK1_PRIORITY,
  223.                   task1_stk,
  224.                   TASK_STACKSIZE,
  225.                   NULL,
  226.                   0);
  227.              
  228.                
  229.   OSTaskCreateExt(task2,
  230.                   NULL,
  231.                   (void *)&task2_stk[TASK_STACKSIZE-1],
  232.                   TASK2_PRIORITY,
  233.                   TASK2_PRIORITY,
  234.                   task2_stk,
  235.                   TASK_STACKSIZE,
  236.                   NULL,
  237.                   0);
  238.  
  239.   OSTaskCreateExt(task3,
  240.                   NULL,
  241.                   (void *)&task3_stk[TASK_STACKSIZE-1],
  242.                   TASK3_PRIORITY,
  243.                   TASK3_PRIORITY,
  244.                   task3_stk,
  245.                   TASK_STACKSIZE,
  246.                   NULL,
  247.                   0);
  248.  
  249.   OSTaskCreateExt(task4,
  250.                    NULL,
  251.                    (void *)&task4_stk[TASK_STACKSIZE-1],
  252.                    TASK4_PRIORITY,
  253.                    TASK4_PRIORITY,
  254.                    task4_stk,
  255.                    TASK_STACKSIZE,
  256.                    NULL,
  257.                    0);
  258.  
  259.   OSTaskCreateExt(task5,
  260.                    NULL,
  261.                    (void *)&task5_stk[TASK_STACKSIZE-1],
  262.                    TASK5_PRIORITY,
  263.                    TASK5_PRIORITY,
  264.                    task5_stk,
  265.                    TASK_STACKSIZE,
  266.                    NULL,
  267.                    0);
  268.   OSTaskCreateExt(task6,
  269.                     NULL,
  270.                     (void *)&task5_stk[TASK_STACKSIZE-1],
  271.                     TASK6_PRIORITY,
  272.                     TASK6_PRIORITY,
  273.                     task6_stk,
  274.                     TASK_STACKSIZE,
  275.                     NULL,
  276.                     0);
  277.   OSStart(); // start taskow
  278.   return 0;
  279. }
  280.  
  281. /******************************************************************************
  282. *                                                                             *
  283. * License Agreement                                                           *
  284. *                                                                             *
  285. * Copyright (c) 2004 Altera Corporation, San Jose, California, USA.           *
  286. * All rights reserved.                                                        *
  287. *                                                                             *
  288. * Permission is hereby granted, free of charge, to any person obtaining a     *
  289. * copy of this software and associated documentation files (the "Software"),  *
  290. * to deal in the Software without restriction, including without limitation   *
  291. * the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
  292. * and/or sell copies of the Software, and to permit persons to whom the       *
  293. * Software is furnished to do so, subject to the following conditions:        *
  294. *                                                                             *
  295. * The above copyright notice and this permission notice shall be included in  *
  296. * all copies or substantial portions of the Software.                         *
  297. *                                                                             *
  298. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
  299. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
  300. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  301. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
  302. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
  303. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
  304. * DEALINGS IN THE SOFTWARE.                                                   *
  305. *                                                                             *
  306. * This agreement shall be governed in all respects by the laws of the State   *
  307. * of California and by the laws of the United States of America.              *
  308. * Altera does not recommend, suggest or require that this reference design    *
  309. * file be used in conjunction or combination with any other product.          *
  310. ******************************************************************************/
  311.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement