c - registering an ISR for a SPI slave -


i'm reading code demonstrates use of spi master sending data spi slave on soft processor (nios ii) on fpga. demonstrates how set isr runs when spi slave recieves data.

my question in relation function alt_ic_isr_register(). definition of function below. third argument alt_isr_func isr isr rountine runs when interrupt occurs (i got that).

alt_ic_isr_register()

could explain 4th argument void* isr_context. defined

isr_context points data structure associated device driver instance

but (void *)spi_command_string_tx passed function. if function registering irq slave why passing pointer tx string?

i don't understand happening here.

#include "altera_avalon_spi.h" #include "altera_avalon_spi_regs.h"  #include "sys/alt_irq.h"   #define spi_slave_irq_interrupt_controller_id 1 #define spi_master_base 0x00021020 #define spi_slave_base 0x00021000 #define spi_slave_irq 8   //this isr runs when spi slave receives data static void spi_rx_isr(void* isr_context){      alt_printf("isr :) %x \n" ,  iord_altera_avalon_spi_rxdata(spi_slave_base));          //this resets irq flag. otherwise irq continuously run.     iowr_altera_avalon_spi_status(spi_slave_base, 0x0);  }  int main() {   alt_printf("hello nios ii!\n");    int return_code,ret;    char spi_command_string_tx[10] = "$helloabc*";   char spi_command_string_rx[10] = "";    //this registers slave irq nios   ret = alt_ic_isr_register(spi_slave_irq_interrupt_controller_id,spi_slave_irq,spi_rx_isr,(void *)spi_command_string_tx,0x0);    alt_printf("irq register return %x \n", ret);    //you need enable irq in ip core control register well.   iowr_altera_avalon_spi_control(spi_slave_base,altera_avalon_spi_control_sso_msk | altera_avalon_spi_control_irrdy_msk);    //just calling isr see if function ok.   spi_rx_isr(null);    return_code = alt_avalon_spi_command(spi_master_base,0 ,                               1, spi_command_string_tx,                               0, spi_command_string_rx,                               0);    return_code = alt_avalon_spi_command(spi_master_base,0 ,                                 1, &spi_command_string_tx[1],                                 0, spi_command_string_rx,                                 0);    if(return_code < 0)          alt_printf("error spi tx ret = %x \n" , return_code);    alt_printf("transmit done. ret = %x spi_rx %x\n",return_code,spi_command_string_rx[0]);     //rx done via interrupts.   alt_printf("rx done \n");   return 0;  } 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -