Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <system.h>
- #include "includes.h"
- #include <io.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;
- #define SW0 0x00000001
- #define SW1 0x00000002
- #define SW2 0x00000004
- #define SW3 0x00000008
- #define SW4 0x00000010
- #define SW5 0x00000020
- #define SW6 0x00000040
- #define SW7 0x00000080
- #define SW8 0x00000100
- #define SW9 0x00000200
- #define LED0 0x00000001
- #define LED1 0x00000002
- #define LED2 0x00000004
- #define LED3 0x00000008
- #define LED4 0x00000010
- #define LED5 0x00000020
- #define LED9 0x00000200
- // Array of LED masks corresponding to cnt
- const int led_masks[5] = {LED1, LED2, LED3, LED4, LED5};
- // Tablica kodów dla wyświetlaczy 7-segmentowych (dla cyfr 0-9)
- const alt_u8 hex_digits[16] = {
- 0x3F, // 0
- 0x06, // 1
- 0x5B, // 2
- 0x4F, // 3
- 0x66, // 4
- 0x6D, // 5
- 0x7D, // 6
- 0x07, // 7
- 0x7F, // 8
- 0x6F, // 9
- 0x77, // A
- 0x7C, // B
- 0x39, // C
- 0x5E, // D
- 0x79, // E
- 0x71 // F
- };
- const alt_u8 error_code[5] = {
- 0x79, // E
- 0x50, // r
- 0x50, // r
- 0x5C, // o
- 0x50 // r
- };
- /* 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];
- OS_STK task7_stk[TASK_STACKSIZE];
- OS_EVENT *SWBox1;
- /* Definition of Task Priorities */
- #define TASK1_PRIORITY 1
- #define TASK2_PRIORITY 2
- #define TASK3_PRIORITY 3
- #define TASK4_PRIORITY 4
- #define TASK5_PRIORITY 5
- #define TASK6_PRIORITY 6
- #define TASK7_PRIORITY 7
- /* Prints "Hello World" and sleeps for three seconds */
- void task1(void* pdata)
- {
- INT8U err;
- int people=0;
- int *msg;
- while (1)
- {
- msg = OSMboxPend(SWBox1, 0, &err);
- if(msg==1)
- {
- IOWR(LEDS_BASE, 0, 1);
- }
- OSTimeDlyHMSM(0, 0, 1, 0);
- }
- }
- /* Prints "Hello World" and sleeps for three seconds */
- void task2(void* pdata)
- {
- INT8U err;
- int people=0;
- int *msg;
- while (1)
- {
- msg = OSMboxPend(SWBox1, 0, &err);
- if(msg==2)
- {
- IOWR(LEDS_BASE, 0, 2);
- }
- OSTimeDlyHMSM(0, 0, 3, 0);
- }
- }
- void task3(void* pdata)
- {
- INT8U err;
- int people=0;
- int *msg;
- while (1)
- {
- msg = OSMboxPend(SWBox1, 0, &err);
- if(msg==3)
- {
- IOWR(LEDS_BASE, 0, 4);
- }
- OSTimeDlyHMSM(0, 0, 5, 0);
- }
- }
- void task4(void* pdata)
- {
- INT8U err;
- int people=0;
- int *msg;
- while (1)
- {
- msg = OSMboxPend(SWBox1, 0, &err);
- if(msg==4)
- {
- IOWR(LEDS_BASE, 0, 8);
- }
- OSTimeDlyHMSM(0, 0, 7, 0);
- }
- }
- void task5(void* pdata)
- {
- INT8U err;
- int people=0;
- int *msg;
- while (1)
- {
- msg = OSMboxPend(SWBox1, 0, &err);
- if(msg==5)
- {
- IOWR(LEDS_BASE, 0, 16);
- }
- OSTimeDlyHMSM(0, 0, 9, 0);
- }
- }
- void task6(void* pdata)
- {
- int prev_switches = 0;
- int in_room=0;
- while (1)
- {
- int switches = IORD_ALTERA_AVALON_PIO_DATA(SW_SLIDERS_BASE);
- int changed = prev_switches ^ switches;
- int * msg;
- if (changed & SW0)
- {
- if (switches & SW0)
- in_room = 1; // SW0 turned on
- else
- in_room = 0; // SW0 turned off
- }
- for (int i = 1; i <= 9; i++)
- {
- int mask = 1 << i;
- int sw_changed = changed & mask;
- int sw_on = switches & mask;
- if (sw_changed && sw_on)
- {
- if (in_room)
- {
- switch (i)
- {
- //do gory i w prawo
- case 1:
- OSMboxPostOpt(SWBox1, &(int){1}, OS_POST_OPT_BROADCAST);
- OSMboxPostOpt(SWBox1, &(int){4}, OS_POST_OPT_BROADCAST);
- break;
- case 2:
- cnt[0] += 1;
- break;
- case 3:
- cnt[0] += 1;
- break;
- case 4:
- cnt[4] += 1;
- break;
- case 5:
- cnt[3] -= 1;
- break;
- case 6:
- cnt[0] -= 1;
- cnt[3] += 1;
- break;
- case 7:
- cnt[3] += 1;
- break;
- case 8:
- //cd9 bo pomijamy cd8
- cnt[2] += 1;
- cnt[1] -= 1;
- break;
- }
- }
- else
- {
- //w dol i lewo
- switch (i)
- {
- case 1:
- cnt[4] -= 1;
- cnt[0] += 1;
- break;
- case 2:
- cnt[0] -= 1;
- break;
- case 3:
- cnt[0] -= 1;
- break;
- case 4:
- cnt[4] -= 1;
- break;
- case 5:
- cnt[4] += 1;
- break;
- case 6:
- cnt[0] += 1;
- cnt[3] -= 1;
- break;
- case 7:
- cnt[3] -= 1;
- break;
- case 8:
- //cd9 bo pomijamy cd8
- cnt[2] -= 1;
- cnt[1] += 1;
- break;
- }
- }
- }
- }
- }
- }
- void task7(void* pdata)
- {
- while (1)
- {
- INT8U err;
- printf("Hello from task2\n");
- int *num;
- num = OSMboxPend(SWBox1, 0, &err);
- printf("T=%d\n", *num);
- IOWR(LEDS_BASE, 0, *num);
- OSTimeDlyHMSM(0, 0, 1, 0);
- }
- }
- /*
- *
- * while (1)
- {
- printf("Hello from task1\n");
- int sw;
- int * msg;
- sw = IORD(SW_SLIDERS_BASE, 0);
- printf("Slider = %d\n", sw);
- OSMboxPostOpt(SWBox1, &sw, OS_POST_OPT_BROADCAST);
- OSTimeDlyHMSM(0, 0, 1, 0);
- }
- */
- /* 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);
- OSStart();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement