none
Check the Gpio pin for 128 pins code ??? RRS feed

  • Question

  • Hello Friends,

    I am working with some omapL138 and i have some clarification reg how to test the gpio pins bec in the omapL138 i have not found any gpio out. so i cant able to check the correct pins am doing this by manually. i found the 
    Mr.Bruce Code from the following link
    that codes are very useful for me. from that i modified some of them . i have 128 gpio pins that i want to test here i have make an array structure for he registers. and also in the case i have did using for loop but its not giving the correct output. can any body tell how to make changes.


    i have 32*4= 128 register how to do it??


    typedef struct _GPIO_REGISTERS_
    {
        volatile DWORD ReadReg[4];
           volatile DWORD DirectionReg[4];
           volatile DWORD SetReg[4];
        volatile DWORD ClearReg[4];
    } GPIO_REGISTERS;
    case IOCTL_READ_GPIO:
    if( pBufOut && pBufIn && *pBufIn < 128 )
    {
    DWORD *pPinNumber = (DWORD *)pBufIn;
    DWORD *pPinValue = (DWORD *)pBufOut;
    RETAILMSG( 1, (TEXT("Read GPIO pin %d\r\n"), *pPinNumber ));
    for(i=0;i<=3;i++);
    *pPinValue = (pDriverContext->pGPIO->ReadReg[4]] & ( 1 << *pPinNumber )) >> *pPinNumber;
    RetVal = TRUE;
    }
    else
    {
    SetLastError(ERROR_INVALID_PARAMETER);
    RetVal = FALSE;
    }
    break;


    Regards
    Joseph.
    Saturday, September 4, 2010 7:56 AM

All replies

  • There are so many things wrong with your code it's hard to know where to
    start...
     
    1.
    > typedef struct _GPIO_REGISTERS_
    > {
    > volatile DWORD ReadReg[4];
    > volatile DWORD DirectionReg[4];
    > volatile DWORD SetReg[4];
    > volatile DWORD ClearReg[4];
    > } GPIO_REGISTERS;
     
    I don't know the omap, but somebody with omap knowledge (or the time to
    look up the datasheet) can probably check this for you.
     
    2.
    > for(i=0;i<=3;i++);
     
    Is that supposed to be a small delay? The ; at the end of that for will
    loop it back to the beginning of the for, so this statement does nothing.
     
    3.
    > *pPinValue = (pDriverContext->pGPIO->ReadReg[4]] & ( 1 << *pPinNumber )) >> *pPinNumber;
     
    There is no pGPIO->ReadReg[4]. There is a ReadReg[0]..ReadReg[3]
     
    I think what you need is:
     
    DWORD i = *pPinNumber >> 5; // This will give the correct GPIO block
    pPinValue = (pDriverContext->pGPIO->ReadReg[i] & (1 <<
    *pPinNumber)) >> *pPinNumber;
     
     
     
    Also you didn't show us how you map the GPIO registers, but if you took
    code from Bruce then it should be right (of course only if you modified
    it correctly according to your chip's datasheet).
     

    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.
    Saturday, September 4, 2010 12:21 PM
    Moderator
  • Hi Michel

     

    Really i mistaken something in the code which i posted. i executed your code but i cant able to get the right shift by 5.

    i did the following steps.

    I declared pPinValue by DWORD.

     

    case IOCTL_READ_GPIO:
    if( pBufOut && pBufIn && *pBufIn < 128 )
    {
    DWORD *pPinNumber = (DWORD *)pBufIn;

     

     

    DWORD i = *pPinNumber >> 5; 
    pPinValue = (pDriverContext->pGPIO->ReadReg[i] & (1 <<*pPinNumber)) >> *pPinNumber; 
    RETAILMSG( 1, (TEXT("Read GPIO pin %d\r\n"), *pPinValue. ));


    When i executed the above code am getting the pin number .
    but for right shifting i even tried with some of the stuff by pPinNumber%32 ,
    pPinNumber/32 . it also not working .

    The application (.exe )in my code is
    for( count = 0; count <= 128; count++ )
    {
    ReadGpioPin(hGPIO_API, count);
    RETAILMSG( 1, (TEXT( "Read Gpio pin is %d\r\n"),count));
    }

    When i executed this code its getting error in the right shifting line. can u able to tell what is the mistake i did here.

    Regards
    Joseph.


     

    Monday, September 6, 2010 5:29 PM
  • There's nothing wrong with my code (there are again some mistakes in
    your code though...)
     
    You are saying:
     
    > it also not working
     
    That is a complete useless statement. Explain WHAT is not working. What
    have you tried. I think you should really read this:
    http://guruce.com/blogpost/howtoaskquestionsonnewsgroups
     
    When you pass in a pinnumber of say 115, then 'i' should be 3.
     
    Have you verified that your code
    > for( count = 0; count <= 128; count++ )
    > {
    > ReadGpioPin(hGPIO_API, count);
    > RETAILMSG( 1, (TEXT( "Read Gpio pin is %d\r\n"),count));
    > }
     
    results in *pBufIn being 0...128 (which is another mistake: You are now
    saying there are 129 GPIO's!) in the IOCTL_READ_GPIO code?
     
    If it is then *pPinNumber will be 115 as well and if i = *pPinNumber >>
    5; then i will be 3.
     
    If you need proof then just run this:
     
    DWORD dwPin = 115;
    DWORD* pdwPin = &dwPin;
    DWORD dwBlock = *pdwPin >> 5;
     
    dwBlock will be 3.
     
    Unless your CPU can't count of course.
     
    I suspect there may be some more mistakes in your implementation of
    ReadGpioPin. Show us that code (AFTER you've answered my questions above
    and have verified what I've told you to verify).
     

    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.
    Tuesday, September 7, 2010 12:12 AM
    Moderator
  • Did you also read http://geekswithblogs.net/BruceEitman/archive/2010/08/01/windows-ce-using-a-driver-to-readwrite-hardware-registers.aspx where I discuss the driver and how I developed GPIO_REGISTERS?

    If it were me, and I was struggling with the code, I would keep it simple.  Something like:

    if( *pPinNumber >= 0 && *pPinNumber < 32 )
    {
           DWORD RegisterNumber = *pPinNumber / 32;
           DWORD PinNumber = *pPinNumber % 32;
           *pPinValue = (pDriverContext->pGPIO->ReadReg[RegisterNumber]] & ( 1 << PinNumber )) >> PinNumber ;
    }
    else if ( *pPinNumber >= 32 && *pPinNumber < 64 )
    {
           DWORD RegisterNumber = *pPinNumber / 32;
           DWORD PinNumber = *pPinNumber % 32;
           *pPinValue = (pDriverContext->pGPIO->ReadReg[RegisterNumber ]] & ( 1 << PinNumber )) >> PinNumber ;
    }else ...

    That way you can work out the math and check to see that it is correct.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Tuesday, September 7, 2010 12:55 PM
    Moderator
  • Hello friends

     

    Am really cant able to express but dont make me to read some stuff how to make a question and all . i just doing but i cant able to write ellaborate that you people cant understand.  i ll correct my mistakes in future. 

     

    Now i come for the solution which i got i really worked with the stuff with the help of you people. and i followed the another way to get work for 128 pins.

     

    I did the mistake in the array by doing readreg[4] it wont work. bec each bank consists 10 registers so even though you give a starting physical address it will go within the 10 registers.

     

    So if you need more than that we cant get the result. so i tried wit read reg1,readreg2 like that.so finally by doing that way similar to the if loop which bruce explained above .

     

     

    if any other  which i need surely i ll post my error.

    So thanks for all the one who helped me.

     

    Regards

    Joseph.

    Tuesday, September 7, 2010 2:50 PM
  • If I undestand you correctly, you have solved the problem with GPIO_REGISTERS and are now able to move forward.  Is that correct?

    I looked up the documentation for your processor to undestand what you were saying better.  Looks to me like you could set up a structure for those 10 registers, and then have an array of that structure.  It would make the code fairly simple.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Tuesday, September 7, 2010 3:32 PM
    Moderator