Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

NicheStack and ISR routine

Hi guys!

I'm trying to write a software that will transfer data over tcp/ip connection when an interrupt occurs.

I use NiosII standard design, MicroC OS and NicheStack.

I've based my desing on simple_socket_server example. I have added an ISR routine from count_binary example.

So the only one thing I can't understend is how to pass to ISR context information about TCP/IP socket created in main program?

I've tried to do this in this manner

//somewhere in main program
volatile SSSConn isr_conn;
//
----------
static void handle_button_interrupts(void* context, alt_u32 id)
{
    /* cast the context pointer to an SSSConn pointer. */
    volatile SSSConn *isr_conn_ptr  = (volatile SSSConn*) context;
    
    /* Write to the edge capture register to reset it. */
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
    /* reset interrupt capability for the Button PIO. */
    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);
    if ((isr_conn_ptr->fd != -1)) 
    {
    sss_send_data(&isr_conn_ptr); //call send data routine
     }        
    printf("IRQ happens\n\r");
}
static void init_button_pio(void)
{
   
    // Recast the isr_conn pointer to match the
    //alt_irq_register() function prototype. */
    
    void* isr_conn_ptr = (void*) &SSSConn;
//    void * irq_conn_ptr=(void*)irq_conn;
    /* Enable all 4 button interrupts. */
    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);
    /* Reset the edge capture register. */
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);
    /* Register the ISR. */
    alt_irq_register( BUTTON_PIO_IRQ,isr_conn_ptr,handle_button_interrupts );
}
-------
//somewhere in main program  in SSSSimpleSocketServerTask() routine I use isr_conn as main socket that passes over all procedures of accpeting and handling the connection.

It compiles well. But when I try to debug my code I see that the isr_conn variable does not stores information about connection during ISR call. It stores some garbage. And only when program execution returns to main loop it starts to store all needed information about TCP socket.

So, what I have done wrong?

And Can anyone help me?

Also another little question: How can I test weather client is connected to simple_socket_server o had been droped down the connection? Using NicheStack routines of cause.
No RepliesBe the first to reply