DestinyR

Applying RSI Callback function

Discussion created by DestinyR on Nov 26, 2013
Latest reply on Nov 26, 2013 by DestinyR

Hello!

 

I need help to utilization of RSI callback function.

 

I wrote some code for this goal. But the callback function not called when I insert or remove the SD card.

/*****************************************************************************
 * RSIWork_Core0.c
 *****************************************************************************/


#include <ccblkfn.h>
#include "adi_initialize.h"
#include "RSIWork_Core0.h"
#include <drivers/rsi/adi_rsi.h>
#include <services/gpio/adi_gpio.h>
#include <services/int/adi_sec.h>


#define RSI_DEBUG 1
#if defined(RSI_DEBUG)
#include <stdio.h>
#define CHECK_RSI_RESULT(result, message) \
          if (rsiResult != ADI_RSI_SUCCESS) { \
                    if (rsiResult == ADI_RSI_BAD_DEVICE_NUMBER) { \
                              fprintf(stdout, "ADI_RSI_BAD_DEVICE_NUMBER: %s\n", message); \
                    } else if (rsiResult == ADI_RSI_GPIO_ERR) { \
                              fprintf(stdout, "ADI_RSI_GPIO_ERR: %s\n", message); \
                    } else if (rsiResult == ADI_RSI_SEMAPHORE_FAILED) { \
                              fprintf(stdout, "ADI_RSI_SEMAPHORE_FAILED: %s\n", message); \
                    } else if (rsiResult == ADI_RSI_DMA_FAILED) { \
                              fprintf(stdout, "ADI_RSI_DMA_FAILED: %s\n", message); \
                    } else if (rsiResult == ADI_RSI_INTERRUPT_FAILURE) { \
                              fprintf(stdout, "ADI_RSI_INTERRUPT_FAILURE: %s\n", message); \
                    } else { \
                              fprintf(stdout, "UNKNOWN ERROR: %s\n", message); \
                    } \
          }
#else
#define CHECK_RSI_RESULT(result, message)
#endif


/* memory for one callbacks */
#define GPIO_MEMORY_SIZE (ADI_GPIO_CALLBACK_MEM_SIZE*1u)


int32_t cntrSDEvents = 4;


/*
 *  Callback from RSI Driver
 *
 * Parameters
 *  - [in]  pCBParam    Callback parameter supplied by application
 *  - [in]  Event       Callback event
 *  - [in]  pArg        Callback argument
 *
 * Returns  None
 *
 */
void RSI_Callback(void *pCBParam, uint32_t Event, void *pArg)
{
          fprintf(stdout, "Hello from Callback\n");
    if (Event == ADI_RSI_EVENT_CARD_CHANGE )
    {
              if ((uint32_t)pArg == ADI_RSI_CARD_REMOVAL) {
                        fprintf(stdout, "Card Removed\n");
                    } else if ((uint32_t)pArg == ADI_RSI_CARD_INSERTION) {
                              fprintf(stdout, "Card Inserted\n");
                    } else {
                              fprintf(stdout, "Card Event Unknown\n");
                    }
              cntrSDEvents--;
//              pDev->CBparam,
//              (uint32_t)ADI_RSI_EVENT_CARD_CHANGE,
//              &cardState);
//              cardState = ADI_RSI_CARD_REMOVAL;
//              cardState = ADI_RSI_CARD_INSERTION;




    }
    else if (Event == ADI_RSI_EVENT_INTERRUPT)
    {
              fprintf(stdout, "ADI_RSI_EVENT_INTERRUPT\n");
//              pDev->CBparam,
//                    (uint32_t)ADI_RSI_EVENT_INTERRUPT,
//                    &interrupts);
//              interrupts = DEV_REG(pDev, XFR_IMSK1) & DEV_REG(pDev, XFRSTAT);


    }
    else if (Event == ADI_RSI_EVENT_EXCEPTION)
    {
              fprintf(stdout, "ADI_RSI_EVENT_EXCEPTION\n");
//              pDev->CBparam,
//                    (uint32_t)ADI_RSI_EVENT_EXCEPTION,
//                    &exceptions0);
//              exceptions0 = DEV_REG(pDev, STAT0) & DEV_REG(pDev, IMSK0);


    }
}


int main(void)
{
          uint32_t                    DeviceNum;
          ADI_RSI_HANDLE          phDevice;
          ADI_RSI_RESULT          rsiResult;
          uint32_t                    gpioMaxCallbacks;
          ADI_GPIO_RESULT          result;
          uint8_t                              gpioMemory[GPIO_MEMORY_SIZE];
          volatile bool          bCardExists = false;


          fprintf(stdout, "\n\n");
          fprintf(stdout, "***********************************************\n");
          /**
           * Initialize managed drivers and/or services that have been added to 
           * the project.
           * @return zero on success 
           */
          /*adi_initComponents();
          if (adi_sec_Init() != ADI_SEC_SUCCESS) {
                    fprintf(stdout, "SEC INIT FAILED\n");
          }


          adi_sec_Enable(true);*/


          fprintf(stdout, "TEST RSI COMMANDS\n");
          fprintf(stdout, "***********************************************\n");


          /* init the GPIO service */
          result = adi_gpio_Init(
                              (void*)gpioMemory,
                              GPIO_MEMORY_SIZE,
                              &gpioMaxCallbacks);


          if (result != ADI_GPIO_SUCCESS) {
                    fprintf(stdout, "GPIO Callback failed\n");
                    return 0;
          }


          DeviceNum = 0;
          fprintf(stdout, "Try to open RSI\n");
          rsiResult = adi_rsi_Open(DeviceNum, &phDevice);
          CHECK_RSI_RESULT(rsiResult, "adi_rsi_Open");


          rsiResult = adi_rsi_RegisterCallback(phDevice, RSI_Callback, NULL);
          CHECK_RSI_RESULT(rsiResult, "adi_rsi_RegisterCallback");


          fprintf(stdout, "Wait events\n");
          do {
                    rsiResult = adi_rsi_IsCardPresent(phDevice);
                    if (rsiResult == ADI_RSI_SUCCESS) {
                              if (!bCardExists) {
                                        bCardExists = true;
                                        cntrSDEvents--;
                                        fprintf(stdout, "Card exists\n");
                              }
                    } else if (rsiResult == ADI_RSI_NO_CARD) {
                              if (bCardExists) {
                                        bCardExists = false;
                                        cntrSDEvents--;
                                        fprintf(stdout, "Card removed\n");
                              }
                    } else if (rsiResult == ADI_RSI_CARD_PROTECTED) {
                              fprintf(stdout, "ADI_RSI_CARD_PROTECTED\n");
                              cntrSDEvents--;
                    } else if (rsiResult == ADI_RSI_GPIO_ERR) {
                              fprintf(stdout, "ADI_RSI_GPIO_ERR\n");
                              cntrSDEvents--;
                    }
          } while (cntrSDEvents > 0);


          fprintf(stdout, "Try to close RSI\n");
          if (phDevice != NULL) {
                    rsiResult = adi_rsi_Close(phDevice);
                    CHECK_RSI_RESULT(rsiResult, "adi_rsi_Close");
          } else {
                    fprintf(stdout, "RSI Device not opened\n");
          }




          fprintf(stdout, "***********************************************\n");
          fprintf(stdout, "FINISH\n");
          fprintf(stdout, "***********************************************\n");
          fprintf(stdout, "\n\n");
          return 0;
}

Outcomes