Issue with Handling GPIO, ADC, PWM

Hi,

I am running Colibri VF61 with BSP version 2.6, Qt for Application Development.

I have often use of GPIO Get/Set, ADC Read and PWM Enable Disable in flow of Application.

I use normal file operations to perform above scenarios. A sample code for GPIO Read is given below:

bool GPIO::GetPinStatus()
{
    int nPinFile;
    int n8retVal;
    char caPinValue[5];

    char caPortValueFile[50]="";
    sprintf(caPortValueFile,"/sys/class/gpio/gpio%d/value",u_n8GPIONumber);

    nPinFile=open(caPortValueFile, O_RDONLY);
    if(-1 == nPinFile)
    {
        nGPIOStatus = GPIO_STATUS_UNABLE_TO_OPEN_FILE;
        return 0;
    }
    n8retVal = read(nPinFile, &caPinValue, 1);

    if(1 != n8retVal)
    {
        nGPIOStatus = GPIO_STATUS_UNABLE_TO_READ_FILE;
        return 0;
    }

    n8retVal = close(nPinFile);
    return caPinValue[0]-'0';
}

Similar Algorithm is used for all peripherals mentioned below
Issue We are facing is following:

After running the application for some time above mentioned algorithm will have no control over peripherals.
All File operations open,read,write etc returns successful but corresponding GPIOs,ADC and PWM does not respond to algorithm. All other peripherals like UART,SPI,I2C which are not handle file operations from user space are working fine.

What could be the issue?

Am I doing these peripheral operations correctly?

Is it an issue with Linux Image?

Regards,

Aneesh

What could be the issue? Am I doing these peripheral operations correctly?

Does those GPIOs/PWM/ADC work fine when trying to access via command line ?
Does the GPIO pins you are trying to access from your applicaiton code are muxed as GPIOs in device tree ?

Is it an issue with linux Image?

I don’t think so.

Which Linux Image you are using ? Have you done any customizations on top of our Linux BSP ?

Yes when the application shows this scenario. I Tested the same with command line and its working properly. Yes i have done following customization to default image

  1. Added SPI
  2. Removed PWM from backlinght( Not using the same PWM in application)
  3. Made the image to drive 7" 800 x 640 tianma display

Is it the correct way to drive the terminals.n
Is there a different method to drive them other than file operations

All Gpio are ase GPIO in device tree

Yes when the application shows this scenario. I Tested the same with command line and its working properly.

I would suggest to debug your application code.

Is there a different method to drive them other than file operations

No, not at least from userspace.

All Gpio are ase GPIO in device tree

Okay

Hi,

The issue is solved
I was using a socket to connect to a tcpserver. It creates new socket every second and tries to connect to server. When server is not online , continuously new sockets are created. I suppose it depleted the sockets available,since i was not freeing the socket, and no FileID were available for normal operations.

Thankyou for the support,

         Regards Aneesh