Advertisement
Litigare

Untitled

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