I'm a begginer to device driver.
Now I'm trying to set a gpio register and check if it is set correctly.
Following is my code.

RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n",
*(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));

v_pIOPregs->GPBCON = 0x155555;

RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n",
*(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));

But the result is not same as my expection.
14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 0
14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 60010

Although I set 0x155555 to GPBCON, the retailmsg printed 60010.
What's wrong with my code?
Please help me.

Re: register dumping by Michel

Michel
Wed May 07 05:05:04 PDT 2008

Probably nothing is wrong with the code, there's just something wrong
with the assumptions you are making:

If any of those GPIO's are configured as input they will show the value
at the port at the moment of the read.


Good luck,

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

GuruCE Ltd.
Microsoft Embedded Partner
http://GuruCE.com
Consultancy, training and development services.

daniel wrote:
> I'm a begginer to device driver.
> Now I'm trying to set a gpio register and check if it is set correctly.
> Following is my code.
>
> RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n",
> *(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));
>
> v_pIOPregs->GPBCON = 0x155555;
>
> RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n",
> *(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));
>
> But the result is not same as my expection.
> 14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 0
> 14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 60010
>
> Although I set 0x155555 to GPBCON, the retailmsg printed 60010.
> What's wrong with my code?
> Please help me.

Re: register dumping by Helge

Helge
Wed May 07 20:58:34 PDT 2008

That's quite strange if we assume, v_pIOPregs->GPBCON is a kind of pointer to your bus.

The two lines show that v_pIOPregs->GPBCON is changing (0 -> 0x60010). That is not what you've written to the location.

But your are taking the dereferenced value with *(v_pIOPregs->GPBCON) and get the same value 2202309720 (0x83449458)?

Do you want to check if the code and the output are related? Do you want to post a bit more info like the definition of GPBCON?

Confused...
/Helge


"daniel" <daniel@discussions.microsoft.com> wrote in message news:371ACA74-5FD8-462C-A2ED-B22BA5D6949F@microsoft.com...
> I'm a begginer to device driver.
> Now I'm trying to set a gpio register and check if it is set correctly.
> Following is my code.
>
> RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n",
> *(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));
>
> v_pIOPregs->GPBCON = 0x155555;
>
> RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n",
> *(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));
>
> But the result is not same as my expection.
> 14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 0
> 14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 60010
>
> Although I set 0x155555 to GPBCON, the retailmsg printed 60010.
> What's wrong with my code?
> Please help me.

Re: register dumping by Steve

Steve
Thu May 08 04:30:41 PDT 2008

What platform are you doing this on? Did you map the GPIO registers
into virtual memory before you tried poking them?

I say this because I'm doing the same thing on a PXA270. I had to use
the MmMapIoSpace() API to get the registers mapped into my process
space. For example:

PHYSICAL_ADDRESS MyReg;
MyReg.HighPart = 0x0;
MyReg.LowPart = 0x40000010; // physical address of register, get from
PXA270 manual

void* MyRegVirtualPtr; //MmMapIoSpace wants a void pointer

MyRegVirtualPtr = MmMapIoSpace(MyReg, 4, FALSE); // map into virtual
memory

*(DWORD*)MyRegVirtualPtr = 0x00c0ffee; // This sets MyReg to a value
of c0ffee. We had to cast the void pointer to a "Pointer to DWORD",
since we're poking a 32-bit register with it.


The "4" in MmMapIoSpace and the pointer cast assume a 32-bit register.
I don't know if this method is too elegant, or even correct, but it
seems to work for me so far.


Hope this helps

Steve



Re: register dumping by Dean

Dean
Thu May 08 08:25:44 PDT 2008

I think there is mistake in the code. Unless you've got a really odd
device, v_pIOPregs->GPBCON *is* the register. It should not be
dereferenced.

If you want the virtual address of the register, use
&v_pIOPregs->GPBCON

If you want the contents of the register, use
v_pIOPregs->GPBCON

And prior to all this, you have to make sure the register is mapped
correctly. Where is the code that initializes v_pIOPregs?

--
Dean Ramsier - eMVP
BSQUARE Corporation


"Helge Kruse" <Helge.Kruse-nospam@gmx.net> wrote in message
news:fvttq0$t2c$02$1@news.t-online.com...
> That's quite strange if we assume, v_pIOPregs->GPBCON is a kind of pointer
> to your bus.
>
> The two lines show that v_pIOPregs->GPBCON is changing (0 -> 0x60010).
> That is not what you've written to the location.
>
> But your are taking the dereferenced value with *(v_pIOPregs->GPBCON) and
> get the same value 2202309720 (0x83449458)?
>
> Do you want to check if the code and the output are related? Do you want
> to post a bit more info like the definition of GPBCON?
>
> Confused... /Helge
>
>
> "daniel" <daniel@discussions.microsoft.com> wrote in message
> news:371ACA74-5FD8-462C-A2ED-B22BA5D6949F@microsoft.com...
>> I'm a begginer to device driver. Now I'm trying to set a gpio register
>> and check if it is set correctly. Following is my code. RETAILMSG(1,
>> (TEXT("v_pIOPregs->GPBCON is %ud - %p\r\n", *(v_pIOPregs->GPBCON),
>> v_pIOPregs->GPBCON)));
>>
>> v_pIOPregs->GPBCON = 0x155555; RETAILMSG(1, (TEXT("v_pIOPregs->GPBCON is
>> %ud - %p\r\n", *(v_pIOPregs->GPBCON), v_pIOPregs->GPBCON)));
>>
>> But the result is not same as my expection. 14034 PID:34c9fc6 TID:34ad6ca
>> v_pIOPregs->GPBCON is 2202309720d - 0
>> 14034 PID:34c9fc6 TID:34ad6ca v_pIOPregs->GPBCON is 2202309720d - 60010
>>
>> Although I set 0x155555 to GPBCON, the retailmsg printed 60010. What's
>> wrong with my code? Please help me.