Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <io.h>
- #include <system.h>
- #include <definitions.h>
- //Nowe definicje
- #include "altera_up_avalon_parallel_port.h"
- #include "sys/alt_irq.h"
- /* Przełączniki */
- #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 SW10 0x00000400
- #define SW11 0x00000800
- #define SW12 0x00001000
- #define SW13 0x00002000
- #define SW14 0x00004000
- #define SW15 0x00008000
- #define SW16 0x00010000
- #define SW17 0x00020000
- /* PushButtony */
- #define KEY1 0x00000002
- #define KEY2 0x00000004
- #define KEY3 0x00000008
- /* Ledy */
- #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
- /* Segmenty HEX */
- #define SEGA 1
- #define SEGB 2
- #define SEGC 4
- #define SEGD 8
- #define SEGE 16
- #define SEGF 32
- #define SEGG 64
- /* Litery i cyfry z hex 7 segmentowych */
- #define HEX0 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF)
- #define HEX1 (SEGB|SEGC)
- #define HEX2 (SEGA|SEGB|SEGG|SEGE|SEGD)
- #define HEX3 (SEGA|SEGB|SEGC|SEGD|SEGG)
- #define HEX4 (SEGF|SEGG|SEGB|SEGC)
- #define HEX5 (SEGA|SEGF|SEGG|SEGC|SEGD)
- #define HEX6 (SEGA|SEGF|SEGG|SEGC|SEGD|SEGE)
- #define HEX7 (SEGA|SEGB|SEGC)
- #define HEX8 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG)
- #define HEX9 (SEGA|SEGB|SEGC|SEGD|SEGF|SEGG)
- #define HEXE (SEGA|SEGF|SEGG|SEGE|SEGD)
- #define HEXr (SEGE|SEGG)
- #define HEXA (SEGA|SEGB|SEGC|SEGE|SEGF|SEGG)
- #define HEXF (SEGA|SEGE|SEGF|SEGG)
- #define HEXC (SEGA|SEGE|SEGF|SEGD)
- #define HEXD (SEGB|SEGC|SEGD|SEGE|SEGG)
- //Struktura trzymajaca uchwyty
- struct alt_up_dev {
- alt_up_parallel_port_dev *uchwytSW;
- alt_up_parallel_port_dev *uchwytLEDR;
- alt_up_parallel_port_dev *uchwytLEDG;
- alt_up_parallel_port_dev *uchwytHEX3;
- };
- int SW0on, SW0off, SW1on, SW1off, SW2on, SW2off, SW3on, SW3off, SW4on, SW4off, SW5on, SW5off, SW6on, SW6off, SW7on, SW7off, SW8on, SW8off, SW9on, SW9off, SW10on, SW10off, SW11on, SW11off, SW12on, SW12off, SWerr, SWerrFMon, SWerrFMoff;
- const int ledOnDelay = 1;
- const int ledOffDelay = 2;
- const int hexOnDelay = 0;
- const int hexOffDelay = 3;
- const int errOffDelay = 3;
- //logika
- void interrupt_handler(struct alt_up_dev *up_dev, alt_u32 id) {
- int state = 0;
- //Odczyt switchy
- int switches = alt_up_parallel_port_read_data(up_dev->uchwytSW);
- //Sprawdzenie ktory slajder zostal wykorzystany
- state = switches & (SW0 | SW1 | SW2 | SW3 | SW4 | SW5 | SW6);
- //Ustawianie timerow:
- //0
- if ((state & SW0) && SW0on == 0) {
- SW0on = alt_nticks();
- SW0off = 0;
- }
- if (!(state & SW0) && SW0off == 0) {
- SW0off = alt_nticks();
- SW0on = 0;
- }
- //1
- if ((state & SW1) && SW1on == 0) {
- SW1on = alt_nticks();
- SW1off = 0;
- }
- if (!(state & SW1) && SW1off == 0) {
- SW1off = alt_nticks();
- SW1on = 0;
- }
- //2
- if ((state & SW2) && SW2on == 0) {
- SW2on = alt_nticks();
- SW2off = 0;
- }
- if (!(state & SW2) && SW2off == 0) {
- SW2off = alt_nticks();
- SW2on = 0;
- }
- //3
- if ((state & SW3) && SW3on == 0) {
- SW3on = alt_nticks();
- SW3off = 0;
- }
- if (!(state & SW3) && SW3off == 0) {
- SW3off = alt_nticks();
- SW3on = 0;
- }
- //4
- if ((state & SW4) && SW4on == 0) {
- SW4on = alt_nticks();
- SW4off = 0;
- }
- if (!(state & SW4) && SW4off == 0) {
- SW4off = alt_nticks();
- SW4on = 0;
- }
- //5
- if ((state & SW5) && SW5on == 0) {
- SW5on = alt_nticks();
- SW5off = 0;
- }
- if (!(state & SW5) && SW5off == 0) {
- SW5off = alt_nticks();
- SW5on = 0;
- }
- //6
- if ((state & SW6) && SW6on == 0) {
- SW6on = alt_nticks();
- SW6off = 0;
- }
- if (!(state & SW6) && SW6off == 0) {
- SW6off = alt_nticks();
- SW6on = 0;
- }
- //7
- if ((switches & SW7) && SW7on == 0) {
- SW7on = alt_nticks();
- SW7off = 0;
- }
- if (!(switches & SW7) && SW7off == 0) {
- SW7off = alt_nticks();
- SW7on = 0;
- }
- //8
- if ((switches & SW8) && SW8on == 0) {
- SW8on = alt_nticks();
- SW8off = 0;
- }
- if (!(switches & SW8) && SW8off == 0) {
- SW8off = alt_nticks();
- SW8on = 0;
- }
- //9
- if ((switches & SW9) && SW9on == 0) {
- SW9on = alt_nticks();
- SW9off = 0;
- }
- if (!(switches & SW9) && SW9off == 0) {
- SW9off = alt_nticks();
- SW9on = 0;
- }
- //10
- if ((switches & SW10) && SW10on == 0) {
- SW10on = alt_nticks();
- SW10off = 0;
- }
- if (!(switches & SW10) && SW10off == 0) {
- SW10off = alt_nticks();
- SW10on = 0;
- }
- //11
- if ((switches & SW11) && SW11on == 0) {
- SW11on = alt_nticks();
- SW11off = 0;
- }
- if (!(switches & SW11) && SW11off == 0) {
- SW11off = alt_nticks();
- SW11on = 0;
- }
- //12
- if ((switches & SW12) && SW12on == 0) {
- SW12on = alt_nticks();
- SW12off = 0;
- }
- if (!(switches & SW12) && SW12off == 0) {
- SW12off = alt_nticks();
- SW12on = 0;
- }
- switch (state) {
- case 0:
- //Wygraszenie gdy zaden switch nie jest aktywny
- if (alt_nticks() - SW0off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW0off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- if (alt_nticks() - SW1off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW1off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- if (alt_nticks() - SW2off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW2off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- if (alt_nticks() - SW3off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW3off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- if (alt_nticks() - SW4off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW4off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- if (alt_nticks() - SW5off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW5off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- if (alt_nticks() - SW6off >= ledOffDelay * alt_ticks_per_second()) {
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- if (alt_nticks() - SW6off >= hexOffDelay * alt_ticks_per_second()) {
- IOWR(HEX_3_BASE, 0, 0);
- }
- break;
- case 1:
- if (alt_nticks() - SW0on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED1);
- }
- if (alt_nticks() - SW0on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX2));
- }
- if ((switches & SW7) && (switches & SW8)) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED17);
- //alt_up_parallel_port_write_data(up_dev->uchwytHEX3, ((HEXE << 24) | (HEXr << 16) | (HEXr << 8));
- } else if (switches & SW7) {
- if (alt_nticks() - SW7on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED7);
- }
- if (alt_nticks() - SW7on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEXA << 8));
- }
- } else if (switches & SW8) {
- if (alt_nticks() - SW8on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED8);
- }
- if (alt_nticks() - SW8on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEXF << 8));
- }
- }
- break;
- case 2:
- if (alt_nticks() - SW1on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED1);
- }
- if (alt_nticks() - SW1on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX2));
- }
- break;
- case 4:
- if (alt_nticks() - SW2on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED2);
- }
- if (alt_nticks() - SW2on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX3));
- }
- break;
- case 8:
- if (alt_nticks() - SW3on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED3);
- }
- if (alt_nticks() - SW3on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX4));
- }
- if (((switches & SW9) && (switches & SW10)) ||
- ((switches & SW9) && (switches & SW11)) ||
- ((switches & SW9) && (switches & SW12)) ||
- ((switches & SW10) && (switches & SW11)) ||
- ((switches & SW10) && (switches & SW12)) ||
- ((switches & SW11) && (switches & SW12))) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED17);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, ((HEXE << 24) | (HEXr << 16) | (HEXr << 8)));
- } else if (switches & SW9) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED9);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, ((HEXC << 16) | (HEX1 << 8)));
- } else if (switches & SW10) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED10);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, ((HEXC << 16) | (HEX2 << 8)));
- } else if (switches & SW11) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED11);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, ((HEXD << 16) | (HEX1 << 8)));
- } else if (switches & SW12) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED12);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, ((HEXD << 16) | (HEX2 << 8)));
- }
- break;
- case 16:
- if (alt_nticks() - SW4on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED4);
- }
- if (alt_nticks() - SW4on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX5));
- }
- break;
- case 32:
- if (alt_nticks() - SW5on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED5);
- }
- if (alt_nticks() - SW5on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX6));
- }
- break;
- case 64:
- if (alt_nticks() - SW6on >= ledOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED6);
- }
- if (alt_nticks() - SW6on >= hexOnDelay * alt_ticks_per_second()) {
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX7));
- }
- break;
- default:
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEXE << 16) | (HEXr << 8) | HEXr);
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, 0);
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LED17);
- break;
- }
- }
- int main() {
- IOWR(LEDS_GREEN_BASE, 0, 0);
- IOWR(LEDS_RED_BASE, 0, 0);
- IOWR(HEX_3_BASE, 0, 0);
- SW0on = SW0off = SW1on = SW1off = SW2on = SW2off = SW3on = SW3off = SW4on = SW4off = SW5on = SW5off = SW6on = SW6off = SW7on = SW7off = SW8on = SW8off = SW9on = SW9off = SW10on = SW10off = SW11on = SW11off = SW12on = SW12off = SWerr = SWerrFMon = SWerrFMoff = 0;
- while (1) {
- struct alt_up_dev up_dev;
- alt_up_parallel_port_dev *uchwytSW = alt_up_parallel_port_open_dev("/dev/SW_SLIDERS");
- alt_up_parallel_port_dev *uchwytLEDR = alt_up_parallel_port_open_dev("/dev/LEDS_RED");
- alt_up_parallel_port_dev *uchwytLEDG = alt_up_parallel_port_open_dev("/dev/LEDS_GREEN");
- alt_up_parallel_port_dev *uchwytHEX3 = alt_up_parallel_port_open_dev("/dev/HEX_3");
- if (uchwytSW != NULL) {
- up_dev.uchwytSW = uchwytSW;
- }
- if (uchwytLEDG != NULL) {
- up_dev.uchwytLEDG = uchwytLEDG;
- }
- if (uchwytLEDR != NULL) {
- up_dev.uchwytLEDR = uchwytLEDR;
- }
- if (uchwytHEX3 != NULL) {
- up_dev.uchwytHEX3 = uchwytHEX3;
- }
- alt_irq_register(1, (void *) &up_dev, (void *) interrupt_handler);
- alt_up_parallel_port_set_interrupt_mask(uchwytSW, 0xff);
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement