public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] HAL register write problem
@ 2001-01-18 14:07 jeremy
  2001-01-18 15:11 ` Gary Thomas
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: jeremy @ 2001-01-18 14:07 UTC (permalink / raw)
  To: ecos-discuss

My platform is Samsung KS32C50100, which operates in big-endian mode.
I got some problem with writing to register using HAL_WRITE function.
For example, in plf_stub.c where I put the UART initialization function
in,
Here I write some initialize value to UART control registers,
 HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_UTXBUF, 0x0);
 HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_URXBUF, 0x0);
 HAL_WRITE_UINT16(CYG_DEVICE_SERIAL_RS232_UART_UBRDIV, 0x280);

The first two lines for writing 8-bits registers works fine. But the
last line doesn't write
anything into the 16-bits register. I defined that 16-bits register
like this in the first part
of the program:
#define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
    ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14)

I tried to write it as a word register by HAL_WRITE_UINT32, doesn't work
either,
Only works when I use HAL_WRITE_UINT8, but this way only writes in 0x80
instead
of 0x280. So the only way I can write it is to use arm ldr instruction
in vectors.S, which
is not good because I'll have more 16&32 bits registers to write.
Can anyone help me with this?
Thanks a lot!

Chien-Yu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [ECOS] HAL register write problem
  2001-01-18 14:07 [ECOS] HAL register write problem jeremy
@ 2001-01-18 15:11 ` Gary Thomas
  2001-01-18 19:04 ` Jonathan Larmour
  2001-01-19  8:33 ` Grant Edwards
  2 siblings, 0 replies; 8+ messages in thread
From: Gary Thomas @ 2001-01-18 15:11 UTC (permalink / raw)
  To: jeremy; +Cc: ecos-discuss

On 18-Jan-2001 jeremy wrote:
> My platform is Samsung KS32C50100, which operates in big-endian mode.
> I got some problem with writing to register using HAL_WRITE function.
> For example, in plf_stub.c where I put the UART initialization function
> in,
> Here I write some initialize value to UART control registers,
>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_UTXBUF, 0x0);
>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_URXBUF, 0x0);
>  HAL_WRITE_UINT16(CYG_DEVICE_SERIAL_RS232_UART_UBRDIV, 0x280);
> 
> The first two lines for writing 8-bits registers works fine. But the
> last line doesn't write
> anything into the 16-bits register. I defined that 16-bits register
> like this in the first part
> of the program:
>#define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
>     ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14)
> 
> I tried to write it as a word register by HAL_WRITE_UINT32, doesn't work
> either,
> Only works when I use HAL_WRITE_UINT8, but this way only writes in 0x80
> instead
> of 0x280. So the only way I can write it is to use arm ldr instruction
> in vectors.S, which
> is not good because I'll have more 16&32 bits registers to write.
> Can anyone help me with this?
> Thanks a lot!
>

How does the code generated by the HAL_WRITE_UINT16() macro differ from
what you can do by hand?  Have you compared the actual instruction sequences?

If you can do it manually, you should be able to do it using the macros.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] HAL register write problem
  2001-01-18 14:07 [ECOS] HAL register write problem jeremy
  2001-01-18 15:11 ` Gary Thomas
@ 2001-01-18 19:04 ` Jonathan Larmour
  2001-01-19  8:33 ` Grant Edwards
  2 siblings, 0 replies; 8+ messages in thread
From: Jonathan Larmour @ 2001-01-18 19:04 UTC (permalink / raw)
  To: jeremy; +Cc: ecos-discuss

jeremy wrote:
> 
> My platform is Samsung KS32C50100, which operates in big-endian mode.
> I got some problem with writing to register using HAL_WRITE function.
> For example, in plf_stub.c where I put the UART initialization function
> in,
> Here I write some initialize value to UART control registers,
>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_UTXBUF, 0x0);
>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_URXBUF, 0x0);
>  HAL_WRITE_UINT16(CYG_DEVICE_SERIAL_RS232_UART_UBRDIV, 0x280);
> 
> The first two lines for writing 8-bits registers works fine. But the
> last line doesn't write
> anything into the 16-bits register. I defined that 16-bits register
> like this in the first part
> of the program:
> #define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
>     ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14)

At a guess, you were probably intending to write

#define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
    ((volatile cyg_uint16 *) (CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14))

because adding 0x14 to something cast to a pointer to a 16-bit type will
increment it by 2*0x14=0x28 bytes.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Un cheval, pas du glue. Pas du cheval, beaucoup du glue. || Opinions==mine

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] HAL register write problem
  2001-01-18 14:07 [ECOS] HAL register write problem jeremy
  2001-01-18 15:11 ` Gary Thomas
  2001-01-18 19:04 ` Jonathan Larmour
@ 2001-01-19  8:33 ` Grant Edwards
  2001-01-19 19:37   ` jeremy
  2 siblings, 1 reply; 8+ messages in thread
From: Grant Edwards @ 2001-01-19  8:33 UTC (permalink / raw)
  To: jeremy; +Cc: ecos-discuss

On Thu, Jan 18, 2001 at 11:17:55AM -0800, jeremy wrote:

> #define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
>     ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14)

Are you sure that you want
        ((volatile cyg_uint16 *)XXX + 0x14)
and not        
        ((volatile cyg_uint16 *)(XXX+0x14))

I've been bitten by that one...

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] HAL register write problem
  2001-01-19  8:33 ` Grant Edwards
@ 2001-01-19 19:37   ` jeremy
  2001-01-22  0:40     ` Jesper Skov
  0 siblings, 1 reply; 8+ messages in thread
From: jeremy @ 2001-01-19 19:37 UTC (permalink / raw)
  To: ecos-discuss

Thanks.
I tried it, but still didn't work. And I found a strange thing.
I wrote a simple program like this:

#include <cyg/hal/hal_io.h>
int main(void)
{
HAL_WRITE_UINT8(0x3ffe014,0x6);
HAL_WRITE_UINT8(0x3ff5000,0x8);
HAL_WRITE_UINT32(0x3ff5004,0x12345678);
HAL_WRITE_UINT16(0x3ff4000,0x123);
 return 0;
}

After load and run it (i got a gdb-stub to do it), I used JEENI to
check the registers, and all these registers are written correctly.
But if I put the same code in plf_stub.c (which is compiled to a
ROM image), only HAL_WRITE_UNIT8 works after power-on.
The only difference is, the test program is compiled using packages
from "default" template and is start-up from  RAM, but the stub image
is compiled using "stub" template. One has kernal the other doesn't.
Do I need to add any package when compiling stub in order to use
16-bit and 32-bit HAL_WRITE ?
Thanks a lot!!

Jeremy




----- Original Message -----
From: "Grant Edwards" <grante@visi.com>
To: "jeremy" <chienyul@home.com>
Cc: <ecos-discuss@sourceware.cygnus.com>
Sent: Friday, January 19, 2001 8:37 AM
Subject: Re: [ECOS] HAL register write problem


> On Thu, Jan 18, 2001 at 11:17:55AM -0800, jeremy wrote:
>
> > #define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
> >     ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE +
0x14)
>
> Are you sure that you want
>         ((volatile cyg_uint16 *)XXX + 0x14)
> and not
>         ((volatile cyg_uint16 *)(XXX+0x14))
>
> I've been bitten by that one...
>
> --
> Grant Edwards
> grante@visi.com
>
 jeremy wrote:
>>
>>My platform is Samsung KS32C50100, which operates in big-endian mode.
>> I got some problem with writing to register using HAL_WRITE function.
>> For example, in plf_stub.c where I put the UART initialization
function
>> in,
>> Here I write some initialize value to UART control registers,
>>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_UTXBUF, 0x0);
>>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_URXBUF, 0x0);
>>  HAL_WRITE_UINT16(CYG_DEVICE_SERIAL_RS232_UART_UBRDIV, 0x280);
>>
>> The first two lines for writing 8-bits registers works fine. But the
>> last line doesn't write
>> anything into the 16-bits register. I defined that 16-bits register
>> like this in the first part
>> of the program:
>> #define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
>>     ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE +
0x14)

>At a guess, you were probably intending to write

>#define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
>    ((volatile cyg_uint16 *) (CYG_DEVICE_SERIAL_RS232_UART_BASE +
0x14))

>because adding 0x14 to something cast to a pointer to a 16-bit type
will
>increment it by 2*0x14=0x28 bytes.

>Jifl
>--
>Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223)
271062
>Un cheval, pas du glue. Pas du cheval, beaucoup du glue. ||
Opinions==mine

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] HAL register write problem
  2001-01-19 19:37   ` jeremy
@ 2001-01-22  0:40     ` Jesper Skov
  0 siblings, 0 replies; 8+ messages in thread
From: Jesper Skov @ 2001-01-22  0:40 UTC (permalink / raw)
  To: jeremy; +Cc: ecos-discuss

>>>>> "jeremy" == jeremy  <chienyul@home.com> writes:

jeremy> template. One has kernal the other doesn't.  Do I need to add
jeremy> any package when compiling stub in order to use 16-bit and
jeremy> 32-bit HAL_WRITE ?  Thanks a lot!!

No. The HAL IO macros are just memory writes. If you have a JEENI,
can't you single step through the assembly to see what happens?

Jesper

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] HAL register write problem
  2001-01-23 16:16 jeremy
@ 2001-01-24  7:18 ` Grant Edwards
  0 siblings, 0 replies; 8+ messages in thread
From: Grant Edwards @ 2001-01-24  7:18 UTC (permalink / raw)
  To: jeremy; +Cc: ecos-discuss

On Tue, Jan 23, 2001 at 04:18:55PM -0800, jeremy wrote:

> I only parenthesized the 16 bit register, and that was the problem.
> In original pid codes, all registers are 8-bits, so it ok if all defined
> this way:
> ((volatile cyg_uint8 *) XXX + 0xXX)
> ...
> Is it because of the alignment?

No, it's because of the precedence of the typecast and addition
operators in the C language.

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] HAL register write problem
@ 2001-01-23 16:16 jeremy
  2001-01-24  7:18 ` Grant Edwards
  0 siblings, 1 reply; 8+ messages in thread
From: jeremy @ 2001-01-23 16:16 UTC (permalink / raw)
  To: ecos-discuss

I got it done! All registers should cast like this:
        ((volatile cyg_uint8 *) (XXX + 0xXX))
        ((volatile cyg_uint8 *) (XXX + 0xXX))
        ((volatile cyg_uint8 *) (XXX + 0xXX))
        ((volatile cyg_uint16 *) (XXX + 0xXX))

I only parenthesized the 16 bit register, and that was the problem.
In original pid codes, all registers are 8-bits, so it ok if all defined
this way:
((volatile cyg_uint8 *) XXX + 0xXX)
...
Is it because of the alignment?

Anyway, I should have tried this earlier :-)
Thanks to all helped me!!

jeremy



jeremy wrote:
>
> My platform is Samsung KS32C50100, which operates in big-endian mode.
> I got some problem with writing to register using HAL_WRITE function.
> For example, in plf_stub.c where I put the UART initialization
function
> in,
> Here I write some initialize value to UART control registers,
>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_UTXBUF, 0x0);
>  HAL_WRITE_UINT8 (CYG_DEVICE_SERIAL_RS232_UART_URXBUF, 0x0);
>  HAL_WRITE_UINT16(CYG_DEVICE_SERIAL_RS232_UART_UBRDIV, 0x280);
>
> The first two lines for writing 8-bits registers works fine. But the
> last line doesn't write
> anything into the 16-bits register. I defined that 16-bits register
> like this in the first part
> of the program:
> #define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
>     ((volatile cyg_uint16 *) CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14)

>>At a guess, you were probably intending to write

>#define CYG_DEVICE_SERIAL_RS232_UART_UBRDIV \
    ((volatile cyg_uint16 *) (CYG_DEVICE_SERIAL_RS232_UART_BASE + 0x14))

>>because adding 0x14 to something cast to a pointer to a 16-bit type
will
>>increment it by 2*0x14=0x28 bytes.

>>Jifl
--
>>Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223)
271062
>>Un cheval, pas du glue. Pas du cheval, beaucoup du glue. || Opinions



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-01-24  7:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-18 14:07 [ECOS] HAL register write problem jeremy
2001-01-18 15:11 ` Gary Thomas
2001-01-18 19:04 ` Jonathan Larmour
2001-01-19  8:33 ` Grant Edwards
2001-01-19 19:37   ` jeremy
2001-01-22  0:40     ` Jesper Skov
2001-01-23 16:16 jeremy
2001-01-24  7:18 ` Grant Edwards

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).