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 SW6 0x00000040
- #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 H_NULL 0x00000000
- #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;
- };
- int state;
- static void handle_sliders_interrupt(struct interrupt_data * data){
- sw = IORD(SW_SLIDERS_BASE, 0);
- switch(state){
- case 0:
- if ((sw & SW1) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW6))) {
- state = 1;
- IOWR(data->leds, 0, LED0);
- IOWR(data->hex, 0, ONE);
- }else if ((sw & SW2) && !(sw & (SW1 | SW3 | SW4 | SW5 | SW6))) {
- state = 2;
- IOWR(data->leds, 0, LED1);
- IOWR(data->hex, 0, TWO);
- }else if ((sw & SW3) && !(sw & (SW2 | SW1 | SW4 | SW5 | SW6))) {
- state = 3;
- IOWR(data->leds, 0, LED2);
- IOWR(data->hex, 0, THREE);
- }else if ((sw & SW4) && !(sw & (SW2 | SW3 | SW1 | SW5 | SW6))) {
- state = 4;
- IOWR(data->leds, 0, LED3);
- IOWR(data->hex, 0, FOUR);
- }else if ((sw & SW5) && !(sw & (SW2 | SW3 | SW4 | SW1 | SW6))) {
- state = 5;
- IOWR(data->leds, 0, LED4);
- IOWR(data->hex, 0, FIVE);
- }else if ((sw & SW6) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW1))) {
- state = 6;
- IOWR(data->leds, 0, LED5);
- IOWR(data->hex, 0, SIX);
- }
- break;
- case 1: case 2:
- case 3: case 4:
- case 5: case 6:
- if(sw == 0){
- state = 0;
- IOWR(data->leds, 0, L_NULL);
- IOWR(data->hex, 0, H_NULL);
- }
- else{
- state = 7;
- IOWR(data->leds, 0, LED6);
- IOWR(data->hex, 0, CHAR_R);
- IOWR(data->hex, 1, CHAR_R);
- IOWR(data->hex, 2, CHAR_E);
- }
- case 7:
- if ((sw & SW1) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW6))) {
- state = 1;
- IOWR(data->leds, 0, LED0);
- IOWR(data->hex, 0, ONE);
- }else if ((sw & SW2) && !(sw & (SW1 | SW3 | SW4 | SW5 | SW6))) {
- state = 2;
- IOWR(data->leds, 0, LED1);
- IOWR(data->hex, 0, TWO);
- }else if ((sw & SW3) && !(sw & (SW2 | SW1 | SW4 | SW5 | SW6))) {
- state = 3;
- IOWR(data->leds, 0, LED2);
- IOWR(data->hex, 0, THREE);
- }else if ((sw & SW4) && !(sw & (SW2 | SW3 | SW1 | SW5 | SW6))) {
- state = 4;
- IOWR(data->leds, 0, LED3);
- IOWR(data->hex, 0, FOUR);
- }else if ((sw & SW5) && !(sw & (SW2 | SW3 | SW4 | SW1 | SW6))) {
- state = 5;
- IOWR(data->leds, 0, LED4);
- IOWR(data->hex, 0, FIVE);
- }else if ((sw & SW6) && !(sw & (SW2 | SW3 | SW4 | SW5 | SW1))) {
- state = 6;
- IOWR(data->leds, 0, LED5);
- IOWR(data->hex, 0, SIX);
- }else {
- //state = 7;
- IOWR(data->leds, 0, LED6);
- IOWR(data->hex, 0, CHAR_R);
- IOWR(data->hex, 1, CHAR_R);
- IOWR(data->hex, 2, CHAR_E);
- }
- break;
- }
- /*
- if ((sw & SW6) && !(SW & (SW1 | SW2 | SW3 | SW4 | SW5))) {
- IOWR(data->leds, 0, LED0);
- IOWR(data->hex, 0, ONE);
- }else if ((sw & SW1) && !(sw & (SW6 | SW2 | SW3 | SW4 | SW5))) {
- IOWR(data->leds, 0, LED1);
- IOWR(data->hex, 0, TWO);
- }else if ((sw & SW2) && !(sw & (SW1 | SW6 | SW3 | SW4 | SW5))) {
- IOWR(data->leds, 0, LED2);
- IOWR(data->hex, 0, THREE);
- }else if ((sw & SW3) && !(sw & (SW1 | SW2 | SW6 | SW4 | SW5))) {
- IOWR(data->leds, 0, LED3);
- IOWR(data->hex, 0, FOUR);
- }else if ((sw & SW4) && !(sw & (SW1 | SW2 | SW3 | SW6 | SW5))) {
- IOWR(data->leds, 0, LED4);
- IOWR(data->hex, 0, FIVE);
- }else if ((sw & SW5) && !(sw & (SW1 | SW2 | SW3 | SW4 | SW6))) {
- IOWR(data->leds, 0, LED5);
- IOWR(data->hex, 0, SIX);
- }else if (!(sw & (SW6 | SW1 | SW2 | SW3 | SW4 | SW5))){
- IOWR(data->leds, 0, L_NULL);
- IOWR(data->hex, 0, 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);
- }
- */
- }
- int main(){
- 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;
- state = 0;
- // SW 6543210
- IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0b1111111);
- 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