Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*************************************************************************
- * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
- * All rights reserved. All use of this software and documentation is *
- * subject to the License Agreement located at the end of this file below.*
- **************************************************************************
- * Description: *
- * The following is a simple hello world program running MicroC/OS-II.The *
- * purpose of the design is to be a very simple application that just *
- * demonstrates MicroC/OS-II running on NIOS II.The design doesn't account*
- * for issues such as checking system call return codes. etc. *
- * *
- * Requirements: *
- * -Supported Example Hardware Platforms *
- * Standard *
- * Full Featured *
- * Low Cost *
- * -Supported Development Boards *
- * Nios II Development Board, Stratix II Edition *
- * Nios Development Board, Stratix Professional Edition *
- * Nios Development Board, Stratix Edition *
- * Nios Development Board, Cyclone Edition *
- * -System Library Settings *
- * RTOS Type - MicroC/OS-II *
- * Periodic System Timer *
- * -Know Issues *
- * If this design is run on the ISS, terminal output will take several*
- * minutes per iteration. *
- **************************************************************************/
- #include <stdio.h>
- #include "includes.h"
- #include <system.h>
- #include <io.h>
- // sw_sliders
- #define SW0 0x00000001
- #define SW1 0x00000002
- #define SW2 0x00000004
- #define SW3 0x00000008
- #define SW4 0x00000010
- #define SW5 0x00000020
- #define SW6 0x00000040
- // leds
- #define LED0 0x00000001
- #define LED1 0x00000002
- #define LED2 0x00000004
- #define LED3 0x00000008
- #define LED4 0x00000010
- #define LED5 0x00000020
- #define LED6 0x00000040
- #define LED7 0x00000080
- #define LED8 0x00000100
- #define LED9 0x00000200
- // hex
- #define SEGA 0x00001
- #define SEGB 0x00002
- #define SEGC 0x00004
- #define SEGD 0x00008
- #define SEGE 0x00010
- #define SEGF 0x00020
- #define SEGG 0x00040
- // hex - numbers
- #define ZERO SEGA | SEGB | SEGC | SEGD |SEGE | SEGF
- #define ONE SEGB | SEGC
- #define TWO SEGA | SEGB | SEGG | SEGE | SEGD
- #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
- #define FOUR SEGG | SEGF | SEGB | SEGC
- #define FIVE SEGA | SEGE | SEGG | SEGC | SEGD
- #define E SEGA | SEGD | SEGE | SEGF | SEGG
- #define R SEGE | SEGG
- /* Definition of Task Stacks */
- #define TASK_STACKSIZE 2048
- OS_STK task1_stk[TASK_STACKSIZE];
- OS_STK task2_stk[TASK_STACKSIZE];
- OS_STK task3_stk[TASK_STACKSIZE];
- OS_STK task4_stk[TASK_STACKSIZE];
- OS_STK task5_stk[TASK_STACKSIZE];
- OS_STK task6_stk[TASK_STACKSIZE];
- /* Definition of Task Priorities */
- #define TASK1_PRIORITY 1 // taski musza miec rozne priorytety wszystko wygaszone
- #define TASK2_PRIORITY 2 // 1 Czerwone 1 tramwaj stoi 2 zielione 2 tramwaj jedzie
- #define TASK3_PRIORITY 3 // 1 Czerwone zolte 1 tramwaj stoi 2 zolte 2 tramwaj jedzie
- #define TASK4_PRIORITY 4 // 1 zielone 1 tramwaj jedzie 2 czerwone 2 tramwaj stoi
- #define TASK5_PRIORITY 5 // 1 zolte 1 tramwaj jedzie 2 czerwone zolte 2 tramwaj stoi
- #define TASK6_PRIORITY 6 // awaria skrzyzowania zolte tramwaj obydwa zapalone.
- OS_EVENT *SWBox1;
- /* Prints "Hello World" and sleeps for three seconds */
- void task1(void* pdata)
- {
- while (1)
- {
- int sw;
- sw= IORD(SW_SLIDERS_BASE, 0);
- switch(sw){
- case 0:
- for(int i=0; i<6 ; i++){
- IOWR(HEX_BASE, i, 0x0); }
- IOWR(LEDS_BASE, 0, 0x0);
- IOWR(LEDS_BASE, 0, 0xfff);
- break;
- case 1:
- break;
- case 2:
- break;
- case 4:
- break;
- case 8:
- break;
- case 16:
- break;
- default:
- if(sw > 32){
- break;
- }
- IOWR(HEX_BASE, 2, E);
- IOWR(HEX_BASE, 1, R);
- IOWR(HEX_BASE, 0, R);
- }
- OSMboxPostOpt(SWBox1, &sw, OS_POST_OPT_BROADCAST);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- /* Prints "Hello World" and sleeps for three seconds */
- void task2(void* pdata)
- {while (1)
- {
- INT8U err;
- int *num;
- num = OSMboxPend(SWBox1, 0, &err);
- printf("T2 = \t [ %d ]\n", *num);
- switch(*num){
- case 1: // 1 Czerwone 1 tramwaj stoi 2 zielione 2 tramwaj jedzie
- IOWR(LEDS_BASE, 0, LED0); // 1 CZ
- IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
- IOWR(LEDS_BASE, 0, LED7);// 2 Ziel
- break;}
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task3(void* pdata)
- {while (1)
- {
- INT8U err;
- int *num;
- num = OSMboxPend(SWBox1, 0, &err);
- printf("T3 = \t\t [ %d ]\n", *num);
- switch(*num){
- case 2: // 1 Czerwone zolte 1 tramwaj stoi 2 zolte 2 tramwaj jedzie
- IOWR(LEDS_BASE, 0, LED0); // 1 CZ zol
- IOWR(LEDS_BASE, 0, LED1); // 1 CZ zol
- IOWR(LEDS_BASE, 0, LED6);// 2 Zolte
- IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
- break;}
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task4(void* pdata)
- {
- while (1)
- {
- INT8U err;
- int *num;
- num = OSMboxPend(SWBox1, 0, &err);
- printf("T4 = \t [ %d ]\n", *num);
- switch(*num){
- case 4: // 1 zielone 1 tramwaj jedzie 2 czerwone 2 tramwaj stoi
- IOWR(LEDS_BASE, 0, LED2); // 1 ziel
- IOWR(LEDS_BASE, 0, LED5);// 2 cz
- IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
- break;}
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task5(void* pdata)
- {
- while (1)
- {
- INT8U err;
- int *num;
- num = OSMboxPend(SWBox1, 0, &err);
- // printf("T5 = \t [ %d ]\n", *num);
- switch(*num){
- case 8:// 1 zolte 1 tramwaj jedzie 2 czerwone zolte 2 tramwaj stoi
- IOWR(LEDS_BASE, 0, LED1); // 1 zolte
- IOWR(LEDS_BASE, 0, LED5);// 2 Zolte
- IOWR(LEDS_BASE, 0, LED6);// 2 Zolte
- IOWR(SKRZYZOWANIE_0_BASE, 0, 0); // -- LED1(3): ON LED2(4): OFF LED3(8): OFF LED4(9): ON
- break;}
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task6(void* pdata)
- {
- int i=0;
- while (1)
- {
- INT8U err;
- int *num;
- num = OSMboxPend(SWBox1, 0, &err);
- // printf("T5 = \t [ %d ]\n", *num);
- switch(*num){
- case 16: // awaria skrzyzowania zolte tramwaj obydwa zapalone.
- while(1){
- if(i % 2 == 0){
- IOWR(LEDS_BASE, 0, LED1); // 1 zolte
- IOWR(LEDS_BASE, 0, LED6);// 2 Zolte
- IOWR(SKRZYZOWANIE_0_BASE, 0, 4); // -- LED1(3): ON LED2(4): on LED3(8): on LED4(9): ON
- for(int k=0; k<50000000 ; k++){ // opoznienie procesore 2 mhz o 1 sek
- }
- }
- else{
- IOWR(LEDS_BASE, 0, 0x0);
- IOWR(SKRZYZOWANIE_0_BASE, 0, 3);// -- LED1(3): off LED2(4): off LED3(8): off LED4(9): off
- for(int k=0; k<50000000 ; k++){ // opoznienie procesore 2 mhz o 1 sek
- }
- }
- i++;
- }
- break;}
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- /* The main function creates two task and starts multi-tasking */
- int main(void)
- {
- SWBox1 =OSMboxCreate((void*)0);
- OSTaskCreateExt(task1,
- NULL,
- (void *)&task1_stk[TASK_STACKSIZE-1],
- TASK1_PRIORITY,
- TASK1_PRIORITY,
- task1_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task2,
- NULL,
- (void *)&task2_stk[TASK_STACKSIZE-1],
- TASK2_PRIORITY,
- TASK2_PRIORITY,
- task2_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task3,
- NULL,
- (void *)&task3_stk[TASK_STACKSIZE-1],
- TASK3_PRIORITY,
- TASK3_PRIORITY,
- task3_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task4,
- NULL,
- (void *)&task4_stk[TASK_STACKSIZE-1],
- TASK4_PRIORITY,
- TASK4_PRIORITY,
- task4_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task5,
- NULL,
- (void *)&task5_stk[TASK_STACKSIZE-1],
- TASK5_PRIORITY,
- TASK5_PRIORITY,
- task5_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task6,
- NULL,
- (void *)&task5_stk[TASK_STACKSIZE-1],
- TASK6_PRIORITY,
- TASK6_PRIORITY,
- task6_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSStart(); // start taskow
- return 0;
- }
- /******************************************************************************
- * *
- * License Agreement *
- * *
- * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
- * All rights reserved. *
- * *
- * Permission is hereby granted, free of charge, to any person obtaining a *
- * copy of this software and associated documentation files (the "Software"), *
- * to deal in the Software without restriction, including without limitation *
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
- * and/or sell copies of the Software, and to permit persons to whom the *
- * Software is furnished to do so, subject to the following conditions: *
- * *
- * The above copyright notice and this permission notice shall be included in *
- * all copies or substantial portions of the Software. *
- * *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
- * DEALINGS IN THE SOFTWARE. *
- * *
- * This agreement shall be governed in all respects by the laws of the State *
- * of California and by the laws of the United States of America. *
- * Altera does not recommend, suggest or require that this reference design *
- * file be used in conjunction or combination with any other product. *
- ******************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement