Re: Help in accessing GPIOs in an i.MX21 (ADS21 board) by Paul
Paul
Thu Sep 21 18:20:57 CDT 2006
As far as I know, there's no layer between your managed code and the DLL
it's calling, but, again, those calls are *not* standard Windows CE calls.
You are breaking in mx21ddk.dll in the call DDKGetGpioSignalState()? We
should also check, how is GPIOHANDLE declared by the unmanaged code? It's
not a different size than IntPtr or something, is it?
Paul T.
"Mario" <alphatommy@hotmail.com> wrote in message
news:1158880364.964997.312830@e3g2000cwe.googlegroups.com...
> Hi Paul,
>
> The size of enumeration is 32-bits. I built a simple unmanaged
> application and used sizeof on the enumration and it returned a value
> of 4. By declaring the parameters to be Int32 and passing values of
> 0x000002 or 0x000003, I still see at the driver side that it sees
> Port_A, which is 0x00000000. Is there a layer between my managed
> application and the driver that I can snoop and see what actually was
> passed? Thanks all for all your responses.
>
> mario
>
>
> Paul G. Tobey [eMVP] wrote:
>> OK, so forget about trying to P/Invoke with a managed enumeration.
>> Declare
>> the parameter as an Int32 and pass the value that corresponds to some
>> other
>> port (1, 2, 3, whatever), and see what you get in that case. It would be
>> useful to verify the size of the enumeration expected by the unmanaged
>> code,
>> also. I would expect it to be 32-bit, but I could be wrong about that.
>>
>> Paul T.
>>
>> "Mario" <alphatommy@hotmail.com> wrote in message
>> news:1158870731.936903.11560@d34g2000cwd.googlegroups.com...
>> > Hi Paul,
>> >
>> > Sorry, what I meant by "did not work" was that regardless of what value
>> > I sent as Port (GPIO_PORT_B, C, D, E or MAX) I still see that the value
>> > passed for Port is GPIO_PORT_A. I see this by breaking on the driver,
>> > and GPIO_PORT_A is the value that shows up when I place the cursor on
>> > top of Port or through Quick Watch. The value that is returned is
>> > wrong because it is looking at the different port that I have selected.
>> > I still have to try to call the method from an umanaged application.
>> > Thanks.
>> >
>> > -- mario
>> >
>> > Paul G. Tobey [eMVP] wrote:
>> >> Sorry, "did not work" is useless information. What value did you
>> >> pass?
>> >> What was returned in the byte? What do you get when you pass the same
>> >> values from unmanaged code?
>> >>
>> >> Paul T.
>> >>
>> >> "Mario" <alphatommy@hotmail.com> wrote in message
>> >> news:1158794169.432339.250470@i42g2000cwa.googlegroups.com...
>> >> > Hi Paul,
>> >> >
>> >> > I could try using byte for return value. On the GPIO_PORT, I have
>> >> > tried Int32 before, but it did not work. Thanks.
>> >> >
>> >> > -- mario
>> >> >
>> >> >
>> >> > Paul G. Tobey [eMVP] wrote:
>> >> >> Well, that return type is wrong. Clearly you should be returning
>> >> >> some
>> >> >> 8-bit
>> >> >> value, which you aren't. Try 'byte'; it's a good choice.
>> >> >>
>> >> >> Try also, for now, just making the GPIO_PORT parameter an Int32 and
>> >> >> passing
>> >> >> the right value as an integer to it. Does that work?
>> >> >>
>> >> >> Paul T.
>> >> >>
>> >> >>
>> >> >> "Mario" <alphatommy@hotmail.com> wrote in message
>> >> >> news:1158791251.466377.92460@m7g2000cwm.googlegroups.com...
>> >> >> > Hi Paul,
>> >> >> >
>> >> >> > For the method INT8 DDKGetGpioSignalState(GPIOHANDLE
>> >> >> > gpiohandle,
>> >> >> > GPIO_PORT port, UINT32 signal)
>> >> >> >
>> >> >> > I did the following:
>> >> >> >
>> >> >> > [DllImport ("mx21ddk.dll")] //mx21ddk.dll contains the methods
>> >> >> > that
>> >> >> > I am calling
>> >> >> > public static extern Int16 DDKGetGpioSignalState(IntPtr
>> >> >> > gpiohandle,
>> >> >> > GPIO_PORT port, UInt32 signal);
>> >> >> >
>> >> >> > The reason why I used Int16 is because there is no Int16 in C#.
>> >> >> >
>> >> >> > //GPIO in C#
>> >> >> > public enum
>> >> >> > {
>> >> >> > GPIO_PORT_A,
>> >> >> > GPIO_PORT_B,
>> >> >> > GPIO_PORT_C,
>> >> >> > GPIO_PORT_D,
>> >> >> > GPIO_PORT_E,
>> >> >> > GPIO_PORT_F,
>> >> >> > GPIOPORTMAX
>> >> >> > }
>> >> >> >
>> >> >> > Please let me know if you see any errors. Thanks.
>> >> >> >
>> >> >> > mario
>> >> >> >
>> >> >> >
>> >> >> > Paul G. Tobey [eMVP] wrote:
>> >> >> >> Those don't appear to be standard DDK calls to me, but I'm no
>> >> >> >> expert
>> >> >> >> on
>> >> >> >> any
>> >> >> >> i.MX21 BSPs. How have you P/Invoked them? GPIOHANDLE is
>> >> >> >> probably
>> >> >> >> an
>> >> >> >> IntPtr, GPIO_PORT you can probably create an enum for that
>> >> >> >> corresponds
>> >> >> >> directly to what the C/C++ code uses, UINT32 is pretty obvious,
>> >> >> >> 'uint',
>> >> >> >> etc.
>> >> >> >> What value, integer value, are you passing in the GPIO_PORT
>> >> >> >> parameters?
>> >> >> >>
>> >> >> >> Paul T.
>> >> >> >>
>> >> >> >> "Mario" <alphatommy@hotmail.com> wrote in message
>> >> >> >> news:1158785258.148715.111740@i42g2000cwa.googlegroups.com...
>> >> >> >> > Hi Paul,
>> >> >> >> >
>> >> >> >> > I have tried the following methods (their signatures are as
>> >> >> >> > follow):
>> >> >> >> >
>> >> >> >> > 1. INT8 DDKGetGpioSignalState(GPIOHANDLE gpiohandle,
>> >> >> >> > GPIO_PORT
>> >> >> >> > port,
>> >> >> >> > UINT32 signal)
>> >> >> >> > 2. void DDKSetGpioSignalState(GPIOHANDLE gpiohandle,
>> >> >> >> > GPIO_PORT
>> >> >> >> > port,
>> >> >> >> > UINT32 signal, UINT8 state, BOOL bInPowerMode)
>> >> >> >> >
>> >> >> >> > 3. UINT32 DDKGetGpioSignals(GPIOHANDLE gpiohandle, GPIO_PORT
>> >> >> >> > port,
>> >> >> >> > UINT32 signalMask)
>> >> >> >> >
>> >> >> >> > 4. void DDKSetGpioSignals(GPIOHANDLE gpiohandle, GPIO_PORT
>> >> >> >> > port,
>> >> >> >> > UINT32 signalMask, UINT32 stateMask)
>> >> >> >> >
>> >> >> >> > GPIO_PORT is defined in the driver header as:
>> >> >> >> >
>> >> >> >> > typedef enum {
>> >> >> >> > GPIO_PORT_A,
>> >> >> >> > GPIO_PORT_B,
>> >> >> >> > GPIO_PORT_C,
>> >> >> >> > GPIO_PORT_D,
>> >> >> >> > GPIO_PORT_E,
>> >> >> >> > GPIO_PORT_F,
>> >> >> >> > GPIO_PORT_MAX,
>> >> >> >> > } GPIO_PORT;
>> >> >> >> >
>> >> >> >> > Thanks in advance for any input.
>> >> >> >> >
>> >> >> >> > -- mario
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > Paul G. Tobey [eMVP] wrote:
>> >> >> >> >> What GPIO method calls?
>> >> >> >> >>
>> >> >> >> >> Paul T.
>> >> >> >> >>
>> >> >> >> >> "Mario" <alphatommy@hotmail.com> wrote in message
>> >> >> >> >> news:1158076582.805617.137440@i42g2000cwa.googlegroups.com...
>> >> >> >> >> > Hi,
>> >> >> >> >> >
>> >> >> >> >> > Has anyone had any success in accessing (reading and
>> >> >> >> >> > writing)
>> >> >> >> >> > the
>> >> >> >> >> > GPIOs
>> >> >> >> >> > in a Freescale i.MX21 (ADS21 board) from a managed code
>> >> >> >> >> > application?
>> >> >> >> >> > The problem that I have is that regardless of which port
>> >> >> >> >> > parameter I
>> >> >> >> >> > pass in the GPIO method calls, the GPIO driver always take
>> >> >> >> >> > Port_A
>> >> >> >> >> > as
>> >> >> >> >> > default. The rest of the parameters are passed correctly.
>> >> >> >> >> > Any
>> >> >> >> >> > inputs
>> >> >> >> >> > or suggestions on how to fix this is appreciated. Thanks.
>> >> >> >> >> >
>> >> >> >> >> > I am not sure if this is the correct forum, but I did not
>> >> >> >> >> > get
>> >> >> >> >> > any
>> >> >> >> >> > response after posting the same question in the freescale
>> >> >> >> >> > site
>> >> >> >> >> > for
>> >> >> >> >> > almost two weeks.
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > -- mario
>> >> >> >> >> >
>> >> >> >> >
>> >> >> >
>> >> >
>> >
>