Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * "Hello World" example.
- *
- * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
- * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
- * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
- * device in your system's hardware.
- * The memory footprint of this hosted application is ~69 kbytes by default
- * using the standard reference design.
- *
- * For a reduced footprint version of this template, and an explanation of how
- * to reduce the memory footprint for a given application, see the
- * "small_hello_world" template.
- *
- */
- #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 <unistd.h>
- // sw_sliders
- #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
- // pushbuttons
- #define KEY1 0x00000002
- #define KEY2 0x00000004
- #define KEY3 0x00000008
- #define KEY4 0x00000010
- // leds
- #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
- // hex
- #define SEGA 0x00001
- #define SEGB 0x00002
- #define SEGC 0x00004
- #define SEGD 0x00008
- #define SEGE 0x00010
- #define SEGF 0x00020
- #define SEGG 0x00040
- // hex - numbers
- #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 SEGF | SEGG | SEGC | SEGB
- #define FIVE SEGA | SEGC | SEGD | SEGG | SEGF
- #define SIX SEGA | SEGC | SEGD | SEGE | SEGF | SEGG
- #define SEVEN SEGA | SEGB | SEGC
- #define EIGHT SEGA | SEGB | SEGC | SEGD | SEGE | SEGF | SEGG
- #define E SEGA | SEGD | SEGE | SEGF | SEGG
- #define R SEGE | SEGG
- struct interrupt_data
- {
- int volatile leds_addr;
- int volatile sw_addr;
- int volatile pb_addr;
- };
- static void handle_sliders_interrupt(struct interrupt_data *data)
- {
- int sw = IORD(data->sw_addr, 0);
- int state=0;
- if(IORD(data->sw_addr,0)&SW0){
- state+=1;
- }
- if(IORD(data->sw_addr,0)&SW1){
- state+=2;
- }
- if(IORD(data->sw_addr,0)&SW2){
- state+=4;
- }
- if(IORD(data->sw_addr,0)&SW3){
- state+=8;
- }
- if(IORD(data->sw_addr,0)&SW4){
- state+=16;
- }
- if(IORD(data->sw_addr,0)&SW5){
- state+=32;
- }
- if(IORD(data->sw_addr,0)&SW6){
- state+=64;
- }
- if(state==1 || state==2 || state==4 || state==8 || state==16 || state==32 || state==64){
- switch(state) {
- case 0:
- IOWR(data->leds_addr,0,0);
- break;
- case 1:
- IOWR(data->leds_addr,0, LED0);
- break;
- case 2:
- IOWR(data->leds_addr,0, LED1);
- break;
- case 4:
- IOWR(data->leds_addr,0, LED2);
- break;
- case 8:
- IOWR(data->leds_addr,0, LED3);
- break;
- case 16:
- IOWR(data->leds_addr,0, LED4);
- break;
- case 32:
- IOWR(data->leds_addr,0, LED5);
- break;
- default:
- IOWR(data->leds_addr, 0, 0);
- break;
- }
- }
- else if(state==0){
- IOWR(data->leds_addr,0,0);
- }
- else{
- IOWR(data->leds_addr,0,LED9);
- }
- }
- int main()
- {
- int *leds = (int*) (0x41040);
- int *sw = (int*) (0x41030);
- int *pb = (int*) (0x41020);
- struct interrupt_data data;
- data.leds_addr = leds;
- data.pb_addr = pb;
- data.sw_addr = sw;
- IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0xFF);
- alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID,SW_SLIDERS_IRQ, handle_sliders_interrupt, &data, 0x0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement