Untitled
unknown
plain_text
2 years ago
4.2 kB
1
Indexable
/* * "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 <system.h> #include "altera_up_avalon_parallel_port.h" #include "sys/alt_irq.h" #include "definition.h" typedef enum POZIOM_TEMP{ POZIOM_0 = 0, POZIOM_1 = 1, POZIOM_2 = 2, POZIOM_3 = 4, POZIOM_4 = 8, POZIOM_5 = 16, POZIOM_6 = 32, POZIOM_7 = 64, POZIOM_8 = 128 }TEMP; int wybor_swiatla_global = 0; struct alt_up_dev { alt_up_parallel_port_dev * uchwytSW; alt_up_parallel_port_dev * uchwytLEDG; alt_up_parallel_port_dev * uchwytLEDR; alt_up_parallel_port_dev * uchwytHEX; }; void interrupt_handler(struct alt_up_dev* up_dev, alt_u32 id) { // Nie należy używać funkcji wykorzystujących przerwania (np. printf). // Należy pamiętać o wyzerowaniu źródła przerwania np. clear_edge_capture wybor_swiatla_global = alt_up_parallel_port_read_data(up_dev->uchwytSW); updateLeds(up_dev); //alt_up_parallel_port_write_data(up_dev->uchwytLEDR, wybor_swiatla); //alt_up_parallel_port_write_data(); } int main() { 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"); if (uchwytSW != NULL) { up_dev.uchwytSW = uchwytSW; } if (uchwytLEDG != NULL) { up_dev.uchwytLEDG = uchwytLEDG; } if (uchwytLEDR != NULL) { up_dev.uchwytLEDR = uchwytLEDR; } alt_irq_register(1, (void*) &up_dev, (void *) interrupt_handler); //alt_up_parallel_port_set_interrupt_mask(uchwytSW, 0xff); } void updateLeds(struct alt_up_dev* up_dev) { int wybor_swiatla = alt_up_parallel_port_read_data(up_dev->uchwytSW); if(wybor_swiatla == 1) { red(1); IOWR(HEX_7_BASE, 0, SEGB); } else if(wybor_swiatla == 2) { red_orange(1, 2); IOWR(HEX_7_BASE, 0, SEGA|SEGB); } else if(wybor_swiatla == 4) { green(4); IOWR(HEX_7_BASE, 0, SEGF); } else if(wybor_swiatla == 8) { orange(2); IOWR(HEX_7_BASE, 0, SEGA); } else { clearLeds(); IOWR(HEX_7_BASE,0 ,0); IOWR(HEX_3_BASE,0,0); } switch(wybor_swiatla){ case 0: break; case 1: //jest czerwone //case2 green(32); IOWR(HEX_7_BASE, 0, SEGE); //case3 red(64); IOWR(HEX_3_BASE, 0, SEGB); //case4 green(2048); IOWR(HEX_3_BASE, 0, SEGE); break; case 2: //jest dczerw poma //c2 orange(16); IOWR(HEX_7_BASE, 0, SEGD); //c3 red_orange(64, 128); IOWR(HEX_3_BASE, 0, SEGA|SEGB); //c4 orange(1024); IOWR(HEX_3_BASE, 0, SEGD); break; case 4: //zielone //c2 red(8); IOWR(HEX_7_BASE, 0, SEGC); //c3 green(256); IOWR(HEX_3_BASE, 0, SEGF); //c4 red(512); IOWR(HEX_3_BASE, 0, SEGC); break; case 8: //zpomarancz //c2 red_orange(8, 16); IOWR(HEX_7_BASE, 0, SEGC|SEGD); //c3 orange(128); IOWR(HEX_3_BASE, 0, SEGA); //c4 red_orange(512, 1024); IOWR(HEX_3_BASE, 0, SEGC|SEGD); break; default: IOWR(HEX_3_BASE, 0, ERROR); break; } } void red(int val) { IOWR(LEDS_RED_BASE, 0, val); } void orange(int val) { IOWR(LEDS_RED_BASE, 0, val); } void green(int val) { IOWR(LEDS_RED_BASE, 0, val); } void red_orange(int val, int val2) { IOWR(LEDS_RED_BASE, 0, val); IOWR(LEDS_RED_BASE, 0, val2); } void clearLeds() { IOWR(LEDS_RED_BASE, 0, 0); }
Editor is loading...