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_avalon_pio_regs.h"
- #include "sys/alt_irq.h"
- //#include "sys/alt_timestamp.h"
- #include <unistd.h>
- //#include "definition.h"
- #define sw0 0x00000001
- #define sw1 0x00000002
- #define sw2 0x00000004
- #define sw3 0x00000008
- #define sw4 0x00000010
- #define sw5 0x00000020
- #define L_NULL 0x00000000
- #define LED0 0x00000001
- #define LED1 0x00000002
- #define LED2 0x00000004
- #define LED3 0x00000008
- #define LED4 0x00000010
- #define LED5 0x00000020
- #define LED6 0x00000040
- #define SEGA 0x00001
- #define SEGB 0x00002
- #define SEGC 0x00004
- #define SEGD 0x00008
- #define SEGE 0x00010
- #define SEGF 0x00020
- #define SEGG 0x00040
- #define CHA SEGB | SEGC | SEGA | SEGE | SEGF | SEGG
- #define CHB SEGB | SEGC | SEGA | SEGD | SEGE | SEGF | SEGG
- #define CHC SEGA | SEGF | SEGE | SEGD
- #define CHD SEGA | SEGB | SEGC | SEGD | SEGE | SEGF
- #define CHE SEGA | SEGD | SEGE | SEGF | SEGG
- #define CHF SEGA | SEGF | SEGE | SEGG
- #define CHG SEGC | SEGA | SEGE | SEGF | SEGD
- #define CHH SEGF | SEGE | SEGG | SEGB | SEGC
- #define CHI SEGB | SEGC
- #define CHL SEGF | SEGE | SEGD
- #define CHP SEGF | SEGE | SEGA | SEGB | SEGG
- #define CHS SEGA | SEGF | SEGG | SEGC | SEGD
- #define CHO SEGA | SEGB | SEGC | SEGD | SEGE | SEGF
- #define CHU SEGB | SEGC | SEGE | SEGF | SEGD
- #define S_CHE SEGG | SEGB | SEGA | SEGF | SEGE
- #define S_CHR SEGE | SEGG
- #define S_CHT SEGF | SEGG | SEGE | SEGD
- #define S_CHO SEGE | SEGG | SEGC | SEGD
- #define H_NULL 0x00000000
- #define ZERO SEGA | SEGB | SEGC | SEGD |SEGE | SEGF
- #define ONE SEGB | SEGC
- #define TWO SEGA | SEGB | SEGD | SEGE | SEGG
- #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 CHAR_E SEGA | SEGD | SEGE | SEGF | SEGG
- #define CHAR_R SEGE | SEGG
- /*
- struct interrupt_data{
- volatile int * leds;
- volatile int * hex;
- volatile int * sw;
- };
- static void handle_sliders_interrupt(struct interrupt_data * data){
- int sw = IORD(SW_SLIDERS_BASE, 0);
- if((sw & sw0) && !(sw & ( sw1 | sw2 | sw3 | sw4 | sw5))) {
- IOWR(data->leds, 0, LED0);
- IOWR(data->hex, 0, ONE);
- IOWR(data->hex, 1, ZERO);
- IOWR(data->hex, 3, CHC);
- IOWR(data->hex, 2, CHD);
- }else if ( (sw & sw1) && !(sw & (sw0 | sw2 | sw3 | sw4 | sw5))) {
- IOWR(data->leds, 0, LED1);
- IOWR(data->hex, 0, TWO);
- IOWR(data->hex, 1, ZERO);
- IOWR(data->hex, 3, CHP);
- IOWR(data->hex, 2, CHU);}
- else if ((sw & sw2) && !(sw & (sw0 | sw1 | sw3 | sw4 | sw5))) {
- IOWR(data->leds, 0, LED2);
- IOWR(data->hex, 0, THREE);
- IOWR(data->hex, 1, ZERO);
- IOWR(data->hex, 3, CHA);
- IOWR(data->hex, 2, CHD);
- }else if ((sw & sw3) && !(sw & (sw2 | sw1 | sw0 | sw4 | sw5))) {
- IOWR(data->leds, 0, LED3);
- IOWR(data->hex, 0, FOUR);
- IOWR(data->hex, 1, ZERO);
- IOWR(data->hex, 3, CHU);
- IOWR(data->hex, 2, CHD);
- }else if ((sw & sw4) && !(sw & (sw2 | sw1 | sw3 | sw0 | sw5))) {
- IOWR(data->leds, 0, LED4);
- IOWR(data->hex, 0, FIVE);
- IOWR(data->hex, 1, ZERO);
- IOWR(data->hex, 3, CHD);
- IOWR(data->hex, 2, CHD);
- }else if ((sw & sw5) && !(sw & ( sw2 | sw1 | sw3 | sw4 | sw0))) {
- IOWR(data->leds, 0, LED5);
- IOWR(data->hex, 0, SIX);
- IOWR(data->hex, 1, ZERO);
- IOWR(data->hex, 3, CHB);
- IOWR(data->hex, 2, CHD);
- }else if (!(sw & (sw0 | sw1 | sw2 | sw3 | sw4 | sw5))){
- IOWR(data->leds, 0, L_NULL);
- IOWR(data->hex, 0, H_NULL);
- IOWR(data->hex, 1, H_NULL);
- IOWR(data->hex, 2, H_NULL);
- IOWR(data->hex, 3, H_NULL);
- }else {
- IOWR(data->leds, 0, LED6);
- IOWR(data->hex, 0, CHAR_R);
- IOWR(data->hex, 1, CHAR_R);
- IOWR(data->hex, 2, CHAR_E);
- IOWR(data->hex, 3, H_NULL);
- }
- }
- */
- int main(){
- int sw = IORD(SW_SLIDERS_BASE, 0);
- while(1){
- sw = IORD(SW_SLIDERS_BASE, 0);
- if((sw & sw0) && !(sw & ( sw1 | sw2 | sw3 | sw4 | sw5))) {
- IOWR(LEDS_BASE, 0, LED0);
- IOWR(HEX_BASE, 0, ONE);
- IOWR(HEX_BASE, 1, ZERO);
- IOWR(HEX_BASE, 3, CHC);
- IOWR(HEX_BASE, 2, CHD);
- }else if ( (sw & sw1) && !(sw & (sw0 | sw2 | sw3 | sw4 | sw5))) {
- IOWR(LEDS_BASE, 0, LED1);
- IOWR(HEX_BASE, 0, TWO);
- IOWR(HEX_BASE, 1, ZERO);
- IOWR(HEX_BASE, 3, CHP);
- IOWR(HEX_BASE, 2, CHU);}
- else if ((sw & sw2) && !(sw & (sw0 | sw1 | sw3 | sw4 | sw5))) {
- IOWR(LEDS_BASE, 0, LED2);
- IOWR(HEX_BASE, 0, THREE);
- IOWR(HEX_BASE, 1, ZERO);
- IOWR(HEX_BASE, 3, CHA);
- IOWR(HEX_BASE, 2, CHD);
- }else if ((sw & sw3) && !(sw & (sw2 | sw1 | sw0 | sw4 | sw5))) {
- IOWR(LEDS_BASE, 0, LED3);
- IOWR(HEX_BASE, 0, FOUR);
- IOWR(HEX_BASE, 1, ZERO);
- IOWR(HEX_BASE, 3, CHU);
- IOWR(HEX_BASE, 2, CHD);
- }else if ((sw & sw4) && !(sw & (sw2 | sw1 | sw3 | sw0 | sw5))) {
- IOWR(LEDS_BASE, 0, LED4);
- IOWR(HEX_BASE, 0, FIVE);
- IOWR(HEX_BASE, 1, ZERO);
- IOWR(HEX_BASE, 3, CHD);
- IOWR(HEX_BASE, 2, CHD);
- }else if ((sw & sw5) && !(sw & ( sw2 | sw1 | sw3 | sw4 | sw0))) {
- IOWR(LEDS_BASE, 0, LED5);
- IOWR(HEX_BASE, 0, SIX);
- IOWR(HEX_BASE, 1, ZERO);
- IOWR(HEX_BASE, 3, CHB);
- IOWR(HEX_BASE, 2, CHD);
- }else if (!(sw & (sw0 | sw1 | sw2 | sw3 | sw4 | sw5))){
- IOWR(LEDS_BASE, 0, L_NULL);
- IOWR(HEX_BASE, 0, H_NULL);
- IOWR(HEX_BASE, 1, H_NULL);
- IOWR(HEX_BASE, 2, H_NULL);
- IOWR(HEX_BASE, 3, H_NULL);
- }else {
- IOWR(LEDS_BASE, 0, LED6);
- IOWR(HEX_BASE, 0, CHAR_R);
- IOWR(HEX_BASE, 1, CHAR_R);
- IOWR(HEX_BASE, 2, CHAR_E);
- IOWR(HEX_BASE, 3, H_NULL);
- }
- }
- // IOWR(HEX_BASE, 0, 0);
- // IOWR(HEX_BASE, 1, 0);
- // IOWR(HEX_BASE, 2, 0);
- // IOWR(HEX_BASE, 3, 0);
- // IOWR(HEX_BASE, 4, 0);
- // IOWR(HEX_BASE, 5, 0);
- //
- // volatile int *sliders = (int*) SW_SLIDERS_BASE;
- // volatile int *leds = (int*) LEDS_BASE;
- // volatile int *hex = (int*) HEX_BASE;
- //
- // struct interrupt_data data;
- //
- // data.hex = hex;
- // data.leds = leds;
- // data.sw = sliders;
- //
- // IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0xf);
- //
- // alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ, handle_sliders_interrupt, &data, 0x0);
- // alt_ic_irq_enable(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ);
- //
- // while(1){}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement