Forum Discussion
Altera_Forum
Honored Contributor
20 years agoHow to use interrupt?
Hello.
I want to use interrupt from USER_PIO, but I don't know how to use. I tried this sample code , but it seems that ISR is not executed. (I modified two point. *definition of CYGNUM_HAL_INTERRUPT_1 *add printf into ISR ) What is wrong? How can I solve it? This may be very primitive question, but I'm really newbie. Please help me. Thank you.#include <cyg/kernel/kapi.h>
static cyg_interrupt int1;
static cyg_handle_t int1_handle;
static cyg_sem_t data_ready;
# define CYGNUM_HAL_INTERRUPT_1 USER_PIO_IRQ //Changed# define CYGNUM_HAL_PRI_HIGH 0
//
// Interrupt service routine for interrupt 1.
//
cyg_uint32 interrupt_1_isr(
cyg_vector_t vector,
cyg_addrword_t data)
{
// Block this interrupt from occurring until
// the DSR completes.
cyg_interrupt_mask( vector );
// Tell the processor that we have received
// the interrupt.
cyg_interrupt_acknowledge(vector);
printf("ISR\n"); //changed
// Tell the kernel that chained interrupt processing
// is done and the DSR needs to be executed next.
return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
}
//
// Deferred service routine for interrupt 1.
//
void interrupt_1_dsr(
cyg_vector_t vector,
cyg_ucount32 count,
cyg_addrword_t data)
{
// Signal the thread to run for further processing.
cyg_semaphore_post(&data_ready);
// Allow this interrupt to occur again.
cyg_interrupt_unmask(vector);
}
//
// Main starting point for the application.
//
void cyg_user_start(void)
{
cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_1;
cyg_priority_t int1_priority = CYGNUM_HAL_PRI_HIGH;
// Initialize the semaphore used for interrupt 1.
cyg_semaphore_init(&data_ready,0);
//
// Create interrupt 1.
//
cyg_interrupt_create(
int1_vector,
int1_priority,
0,
&interrupt_1_isr,
&interrupt_1_dsr,
&int1_handle,
&int1);
// Attach the interrupt created to the vector.
cyg_interrupt_attach(int1_handle);
// Unmask the interrupt we just configured.
cyg_interrupt_unmask( int1_vector);
}13 Replies
- Altera_Forum
Honored Contributor
your thread runs once and then dies
you need a infinite loop in static void ledglow(cyg_addrword_t data) { while (1){ ledpio = ledpio^0x10; // IOWR (LED_PIO_BASE , 0, ledpio); } } - Altera_Forum
Honored Contributor
thanks i can understand,but in the following simple progamme with two thread,highest priority thread runs continuouslly ,it never dies...so here no need for infinite loop..?
# include <cyg/hal/hal_arch.h># include <cyg/kernel/kapi.h># include <cyg/hal/io.h> unsigned char ledpio; // These numbers depend entirely on your application# define NUMBER_OF_WORKERS 4# define PRODUCER_PRIORITY 18# define WORKER_PRIORITY 17# define PRODUCER_STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL# define WORKER_STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM + 1024) static unsigned char producer_stack[PRODUCER_STACKSIZE]; static unsigned char worker_stacks[NUMBER_OF_WORKERS][WORKER_STACKSIZE]; static cyg_handle_t producer_handle, worker_handles[NUMBER_OF_WORKERS]; static cyg_thread producer_thread,worker_threads[NUMBER_OF_WORKERS]; static void producer(cyg_addrword_t data) { ledpio = 0x8; // IOWR (LED_PIO_BASE , 0, ledpio); } static void worker(cyg_addrword_t data) { ledpio = 0x1; // IOWR (LED_PIO_BASE , 0, ledpio); } void cyg_user_start(void) { int i; cyg_thread_create(PRODUCER_PRIORITY, &producer, 0, "producer", producer_stack, PRODUCER_STACKSIZE, &producer_handle, &producer_thread); cyg_thread_resume(producer_handle); for (i = 0; i < NUMBER_OF_WORKERS; i++) { cyg_thread_create(WORKER_PRIORITY, &worker, i, "worker", worker_stacks, worker_stacksize,&(worker_handles), &(worker_threads));
cyg_thread_resume(worker_handles); } } --- Quote Start --- originally posted by glecordier@Feb 8 2006, 06:45 AM your thread runs once and then dies
you need a infinite loop in
static void ledglow(cyg_addrword_t data)
{
while (1){
ledpio = ledpio^0x10; //
iowr (led_pio_base , 0, ledpio);
}
}
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=12630)
--- quote end ---
--- Quote End ---
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by glecordier@Feb 6 2006, 06:31 AM i use the interrupt with the button pio like that:# include <cyg/hal/io.h> // for iowr and iord
unsigned char ledpio;
cyg_interrupt int_pio;
cyg_handle_t int_pio_handle;
:
:
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=12562)
--- quote end ---
--- Quote End --- Thank you, All. Especially GLecordier, thank you for showing your code. Now I can use interrupt as I expect. The reasons are (1) I tried to use printf in ISR. (2) I didn't unmask the interrupt. Thank you, very much.