Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <io.h>
- #include <system.h>
- #include "alt_types.h"
- #include "altera_up_avalon_parallel_port.h"
- #include "sys/alt_irq.h"
- #include "sys/alt_timestamp.h"
- #include <unistd.h>
- #include <sys/alt_alarm.h>
- #include "includes.h"
- #include <stdbool.h>
- typedef enum POZIOM_TEMP{
- POZIOM_0 = 0,
- POZIOM_1 = 2,
- POZIOM_2 = 4,
- POZIOM_3 = 8,
- POZIOM_4 = 16,
- POZIOM_5 = 32,
- POZIOM_6 = 64,
- POZIOM_7 = 128,
- POZIOM_8 = 256,
- POZIOM_9 = 512,
- POZIOM_10 = 1024,
- }TEMP;
- struct room{
- int rooms[6];
- bool error;
- };
- #define SW17 0x00000001
- #define SW16 0x00000002
- #define SW15 0x00000004
- #define SW14 0x00000008
- #define SW13 0x00000010
- #define SW12 0x00000020
- #define SW11 0x00000040
- #define SW10 0x00000080
- #define SW9 0x00000100
- #define SW8 0x00000200
- #define SW7 0x00000400
- #define SW6 0x00000800
- #define SW5 0x00001000
- #define SW4 0x00002000
- #define SW3 0x00004000
- #define SW2 0x00008000
- #define SW1 0x00010000
- #define SW0 0x00020000
- #define KEY1 0x00000002
- #define KEY2 0x00000004
- #define KEY3 0x00000008
- #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
- #define LED10 0x00000400
- #define LED11 0x00000800
- #define LED12 0x00001000
- #define LED13 0x00002000
- #define LED14 0x00004000
- #define LED15 0x00008000
- #define LED16 0x00010000
- #define LED17 0x00020000
- #define SEGA 0x01
- #define SEGB 0x02
- #define SEGC 0x04
- #define SEGD 0x08
- #define SEGE 0x10
- #define SEGF 0x20
- #define SEGG 0x40
- #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 SEGB | SEGC | SEGF | SEGG
- #define FIVE SEGA | SEGC | SEGD | SEGF | SEGG
- #define SIX SEGA | SEGC | SEGD | SEGE | SEGF | SEGG
- #define SEVEN SEGA | SEGB | SEGC
- #define EIGHT SEGA | SEGB | SEGC | SEGD | SEGE | SEGF | SEGG
- #define NINE SEGA | SEGB| SEGC | SEGD | SEGF | SEGG
- #define R SEGE | SEGG
- #define E SEGA | SEGD | SEGE | SEGF | SEGG
- #define NIC SEGG
- #define SW_BASE_ADDRESS 0x1010f0
- #define KEY_BASE_ADDRESS 0x1010e0
- #define LEDG_BASE_ADDRESS 0x101130
- #define LEDR_BASE_ADDRESS 0x101120
- #define HEX3_BASE_ADDRESS 0x101110
- #define HEX7_BASE_ADDRESS 0x101100
- #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];
- OS_STK task7_stk[TASK_STACKSIZE];
- OS_STK task8_stk[TASK_STACKSIZE];
- OS_EVENT *SWBox1;
- #define TASK1_PRIORITY 1
- #define TASK2_PRIORITY 2 //leds
- #define TASK3_PRIORITY 3 //r1
- #define TASK4_PRIORITY 4 //r2
- #define TASK5_PRIORITY 5 //r3
- #define TASK6_PRIORITY 6 //r4
- #define TASK7_PRIORITY 7 //r5
- #define TASK8_PRIORITY 8 //errory
- #define SEGA 0x01
- #define SEGB 0x02
- #define SEGC 0x04
- #define SEGD 0x08
- #define SEGE 0x10
- #define SEGF 0x20
- #define SEGG 0x40
- void light_hex(int address, int stat, int shift)
- {
- switch (stat) {
- case 0:
- IOWR(address, 0, ((ZERO) << shift));
- break;
- case 1:
- IOWR(address, 0, ((ONE) << shift));
- break;
- case 2:
- IOWR(address, 0, ((TWO) << shift));
- break;
- case 3:
- IOWR(address, 0, ((THREE) << shift));
- break;
- case 4:
- IOWR(address, 0, ((FOUR) << shift));
- break;
- case 5:
- IOWR(address, 0, ((FIVE) << shift));
- break;
- case 6:
- IOWR(address, 0, ((SIX) << shift));
- break;
- case 7:
- IOWR(address, 0, ((SEVEN) << shift));
- break;
- case 8:
- IOWR(address, 0, ((EIGHT) << shift));
- break;
- case 9:
- IOWR(address, 0, ((NINE) << shift));
- break;
- case 50:
- IOWR(address, 0, ((NIC) << shift));
- break;
- case 100:
- IOWR(address, 0, ((R) << shift));
- break;
- case 1000:
- IOWR(address, 0, ((E) << shift));
- break;
- default:
- break;
- }
- }
- void task1(void* pdata)
- {
- int f[10];
- int state,i,direction;
- for (i = 0; i<10; i++)
- f[i] = 0;
- struct room r;
- r.error = false;
- for (i = 0; i < 6; i++)
- r.rooms[i]=0;
- while (1)
- {
- if (IORD(SW_BASE_ADDRESS, 0) == 0)
- {
- for (i = 0; i <10; i++)
- f[i] = 1;
- r.error = false;
- }
- if (IORD(KEY_BASE_ADDRESS, 0) & KEY3)
- direction = 1;
- else
- direction = 0;
- if (direction == 1)
- {
- switch (state)
- {
- case 32: //cd1
- if (f[0] == 1)
- {
- if (r.rooms[1] == 0)
- {
- r.error=true;
- }
- else
- {
- r.rooms[1]--;
- r.rooms[5]++;
- }
- f[0] = 0;
- }
- break;
- case 64: //cd2
- if (f[1] == 1)
- {
- r.rooms[1]++;
- f[1] = 0;
- }
- break;
- case 128: //cd3
- if (f[2] == 1)
- {
- r.rooms[1]++;
- f[2] = 0;
- }
- break;
- case 256: //cd4
- if (f[3] == 1)
- {
- r.rooms[5]++;
- f[3] = 0;
- }
- break;
- case 512: //cd5
- if (f[4] == 1)
- {
- r.rooms[5]++;
- f[4] = 0;
- }
- break;
- case 1024: //cd6
- if (f[5] == 1)
- {
- if (r.rooms[1] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[1]--;
- r.rooms[4]++;
- }
- f[5] = 0;
- }
- break;
- case 2048: //cd7
- if (f[6] == 1)
- {
- r.rooms[4]++;
- f[6] = 0;
- }
- break;
- case 4096: //cd8
- if (f[7] == 1)
- {
- r.rooms[4]++;
- f[7] = 0;
- }
- break;
- case 8192: //cd9
- if (f[8] == 1)
- {
- if (r.rooms[2] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[2]--;
- r.rooms[3]++;
- }
- f[8] = 0;
- }
- break;
- case 16384: //cd10
- if (f[9] == 1)
- {
- if (r.rooms[2] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[2]--;
- r.rooms[4]++;
- }
- f[9] = 0;
- }
- break;
- default:
- break;
- }
- }
- else
- {
- switch (state)
- {
- case 32: //cd1
- if (f[0] == 1)
- {
- if (r.rooms[5] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[5]--;
- r.rooms[1]++;
- }
- f[0] = 0;
- }
- break;
- case 64: //cd2
- if (f[1] == 1)
- {
- if (r.rooms[1] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[1]--;
- }
- f[1] = 0;
- }
- break;
- case 128: //cd3
- if (f[2] == 1)
- {
- if (r.rooms[1] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[1]--;
- }
- f[2] = 0;
- }
- break;
- case 256: //cd4
- if (f[3] == 1)
- {
- if (r.rooms[5] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[5]--;
- }
- f[3] = 0;
- }
- break;
- case 512: //cd5
- if (f[4] == 1)
- {
- if (r.rooms[5] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[5]--;
- }
- f[4] = 0;
- }
- break;
- case 1024: //cd6
- if (f[5] == 1)
- {
- if (r.rooms[4] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[4]--;
- r.rooms[1]++;
- }
- f[5] = 0;
- }
- break;
- case 2048: //cd7
- if (f[6] == 1)
- {
- if (r.rooms[4] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[4]--;
- }
- f[6] = 0;
- }
- break;
- case 4096: //cd8
- if (f[7] == 1)
- {
- if (r.rooms[4] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[4]--;
- }
- f[7] = 0;
- }
- break;
- case 8192: //cd9
- if (f[8] == 1)
- {
- if (r.rooms[3] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[3]--;
- r.rooms[2]++;
- }
- f[8] = 0;
- }
- break;
- case 16384: //cd10
- if (f[9] == 1)
- {
- if (r.rooms[4] == 0)
- {
- r.error = true;
- }
- else
- {
- r.rooms[4]--;
- r.rooms[2]++;
- }
- f[9] = 0;
- }
- break;
- default:
- break;
- }
- }
- OSMboxPostOpt(SWBox1, r.rooms, OS_POST_OPT_BROADCAST);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task2(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room_led;
- int *rooms;
- rooms = OSMboxPend(SWBox1, 0, &err);
- int leds_to_light = 0;
- if(rooms[1] > 0)
- leds_to_light += LED1;
- if(rooms[2] > 0)
- leds_to_light += LED2;
- if(rooms[3] > 0)
- leds_to_light += LED3;
- if(rooms[4] > 0)
- leds_to_light += LED4;
- if(rooms[5] > 0)
- leds_to_light += LED5;
- IOWR(LEDG_BASE_ADDRESS, 0, leds_to_light);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task3(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room1;
- room1 = OSMboxPend(SWBox1, 0, &err);
- light_hex(HEX3_BASE_ADDRESS, room1->rooms[1], 0);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task4(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room2;
- room2 = OSMboxPend(SWBox1, 0, &err);
- light_hex(HEX3_BASE_ADDRESS, room2->rooms[2], 8);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task5(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room3;
- room3 = OSMboxPend(SWBox1, 0, &err);
- light_hex(HEX3_BASE_ADDRESS, room3->rooms[3], 16);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task6(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room4;
- room4 = OSMboxPend(SWBox1, 0, &err);
- light_hex(HEX3_BASE_ADDRESS, room4->rooms[4], 24);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task7(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room5;
- room5 = OSMboxPend(SWBox1, 0, &err);
- light_hex(HEX7_BASE_ADDRESS, room5->rooms[5], 0);
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- void task8(void* pdata)
- {
- while (1)
- {
- INT8U err;
- struct room *room_error;
- room_error = OSMboxPend(SWBox1, 0, &err);
- if(room_error->error == true)
- {
- IOWR(LEDR_BASE_ADDRESS, 0, LED1);
- light_hex(HEX7_BASE_ADDRESS, 100, 8);
- light_hex(HEX7_BASE_ADDRESS, 100, 16);
- light_hex(HEX7_BASE_ADDRESS, 1000, 24);
- }
- OSTimeDlyHMSM(0, 0, 0, 10);
- }
- }
- 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 *)&task6_stk[TASK_STACKSIZE-1],
- TASK6_PRIORITY,
- TASK6_PRIORITY,
- task6_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task7,
- NULL,
- (void *)&task7_stk[TASK_STACKSIZE-1],
- TASK7_PRIORITY,
- TASK7_PRIORITY,
- task7_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSTaskCreateExt(task8,
- NULL,
- (void *)&task8_stk[TASK_STACKSIZE-1],
- TASK8_PRIORITY,
- TASK8_PRIORITY,
- task8_stk,
- TASK_STACKSIZE,
- NULL,
- 0);
- OSStart();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement