Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include "system.h"
- #include "sys/alt_irq.h"
- #include "altera_avalon_pio_regs.h"
- #include "stdio.h"
- #include <io.h>
- #include "altera_avalon_timer_regs.h"
- volatile alt_u8 count = 0;
- volatile alt_u8 FLAG= 0;
- volatile int edge_capture = 0;
- static void handle_key_interrupts(void* context);
- static void init_pio_key_interrupts()
- {
- #ifdef KEY_BASE
- void *edge_capture_ptr;
- edge_capture_ptr = (void*) &edge_capture;
- IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEYS_BASE, 0x1);
- IOWR_ALTER_AVALON_PIO_EDGE_CAP(KEY_BASE, 0xf);
- alt_ic_isr_register(KEYS_IRQ_INTERRUPT_CONTROLLER_ID,
- KEYS_IRQ,
- handle_key_interrupts,
- edge_capture_ptr, 0x0);
- printf("interrupt initialization status: Set \n");
- #else
- printf("interrupt initialization status: Error \n");
- #endif
- }
- static void handle_key_interrupts(void* context);
- {
- FLAG = 0;
- volatile int *edge_capture_ptr = (volatile int*) context;
- *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(KEYS_BASE);
- IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEYS_BASE, 0xf);
- }
- static void init_timer()
- {
- unsigned int val;
- #ifdef TIMER_0_BASE
- IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE, 0x02FA);
- IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE, 0xF080);
- IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, 0x2 | 0x4);
- IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 0);
- val = IORD_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE);
- val = val << 16;
- val = val | IORD_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE);
- val = (val * 20) / 1000000000;
- printf("timer status: Set = %d [s] \n", val);
- #else
- printf("timer status: Error \n");
- #endif
- }
- int main()
- {
- printf("Start \n");
- unsigned int status = 0;
- init_pio_key_interrupts();
- init_timer();
- while(1)
- {
- status = IORD_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE);
- if(FLAG == 0)
- {
- count = 0;
- FLAG = 1;
- }
- else if (status & 0x01)
- {
- IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 0);
- count += 1;
- }
- IOWR(LEDSG_BASE,0,count);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement