register handling

K

kevin.watters

Probably way off base, but instead of returning SPORT, for example,
shouldn't it return st_sci?



Sorry if wrong :)



Kevin
 
S

silentlights

HI,
How could I handle groups of registers in a single function by passing the
address of the registers to the functions as parameters..?

I am trying something like..

typedef volatile struct st_sci * SPORT;
SPORT getPort(char port);

SPORT getPort(char PORTNAME)
{
SPORT temp;
switch(PORTNAME)
{
case 0: temp = 0xFFFF78; break;
case 1: temp = 0xFFFF80; break;
case 2: temp = 0xFFFF88; break;
case 3: temp = 0xFFFDD0; break;
}
return temp;
}

char getChar(char PORTNAME)
{
SPORT sci = getPort(PORTNAME);
char data = sci.RDR;
return data;
}


COMPILE ERROR:- "temp" TYPE NOT COMPATABLE

...........................................

Any suggestions..!!
Thanks
 
A

Arthur J. O'Dwyer

typedef volatile struct st_sci * SPORT;

SPORT temp;
switch(PORTNAME)
{
case 0: temp = 0xFFFF78; break;
COMPILE ERROR:- "temp" TYPE NOT COMPATABLE

Yes. 0xFFFF78 is probably an 'unsigned int' value. It's
definitely *some* kind of integer. 'temp', on the other
hand, is a pointer variable. Integers and pointers can't
be blithely assigned back and forth. If you are absolutely
sure you know what you're doing, then use a cast:

case 0: temp = (SPORT) 0xFFFF78; break;

and likewise for the other assignments.

-Arthur
 
A

Arthur J. O'Dwyer

typedef volatile struct st_sci * SPORT;
SPORT getPort(char port);
SPORT sci = getPort(PORTNAME);
char data = sci.RDR;

Another error: for 'sci.RDR', read 'sci->RDR'. Assuming
'RDR' is a member of 'struct st_sci' with integer type;
otherwise you've got some more casting to do.

-Arthur
 
T

Thomas Matthews

silentlights said:
HI,
How could I handle groups of registers in a single function by passing the
address of the registers to the functions as parameters..?

I am trying something like..

typedef volatile struct st_sci * SPORT;
SPORT getPort(char port);

SPORT getPort(char PORTNAME)
{
SPORT temp;
switch(PORTNAME)
{
case 0: temp = 0xFFFF78; break;
case 1: temp = 0xFFFF80; break;
case 2: temp = 0xFFFF88; break;
case 3: temp = 0xFFFDD0; break;
}
return temp;
}

char getChar(char PORTNAME)
{
SPORT sci = getPort(PORTNAME);
char data = sci.RDR;
return data;
}


COMPILE ERROR:- "temp" TYPE NOT COMPATABLE

..........................................

Any suggestions..!!
Thanks

By the way, don't use SPORT for serial port.
Use SPORT for baseball.

#define TX_REG_OFFSET 0
#define RX_REG_OFFSET 4
#define STATUS_REG_OFFSET 8
#define CTRL_REG_OFFSET 12

unsigned char Read_Serial_Port(unsigned char * base_ptr)
{
unsigned char byte = 0;
if (*((unsigned int *)(base_ptr + CTRL_REG_OFFSET))
& RX_RDY)
{
byte = base_ptr[RX_REG_OFFSET];
}
return byte;
}

I prefer not to use structures when accessing
hardware devices. Hardware components can change and
fields in structures can be padded.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
E

Emmanuel Delahaye

silentlights said:
typedef volatile struct st_sci * SPORT;
SPORT getPort(char port);

SPORT getPort(char PORTNAME)
{
SPORT temp;
switch(PORTNAME)
{
case 0: temp = 0xFFFF78; break;

case 0: temp = (SPORT) 0xFFFF78; break;
 
S

silentlights

Hi Thomas,
That was a brilliant idea. Could you please explain me a little bit more..
I want to understand in detail so I can implement this idea in all other
get() and put() functions.
#define TX_REG_OFFSET 0
#define RX_REG_OFFSET 4
#define STATUS_REG_OFFSET 8
#define CTRL_REG_OFFSET 12

How do I calculate the offset ?
unsigned char Read_Serial_Port(unsigned char * base_ptr)
{
unsigned char byte = 0;
if (*((unsigned int *)(base_ptr + CTRL_REG_OFFSET))
& RX_RDY)

What is RX_RDY ?, If I want to check for a flag in register how can I do
that..?

Thanks in advance
Densil
 
T

Thomas Matthews

silentlights said:
Hi Thomas,
That was a brilliant idea. Could you please explain me a little bit more..
I want to understand in detail so I can implement this idea in all other
get() and put() functions.




How do I calculate the offset ?
The offsets are calculated by subtracting the address of a given
register from the base or first register. This just happens
to be an example I made up. I used this method on a tape
drive project.

What is RX_RDY ?, If I want to check for a flag in register how can I do
that..?

Thanks in advance
Densil
RX_RDY happens to be a bit in the status register that
indicates a character is in the receive register of the
UART.

To check flags (bits) in a register, read the register
then use the bit operators: &, |, ! or ^. Generally,
the bitwise-AND is used to mask out unwanted bits.


On the current platform that I am working on, the
designers use this paradigm:
#define UART_BASE 0x40000
#define UART0_RECV_REG (volatile char *)(UART_BASE + 4)
#define UART0_XMIT_REG (volatile char *)(UART_BASE + 8)

Since the processor is 32-bit, the hardware designers
have placed the registers on 32-bit boundaries to make
accessing easier on the processor.

The above paradigm is used in case the H/W folk decide
to change where the UART is located in the address space.
Thus only one value would have to change.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
S

silentlights

Hi Thomas,
Thank you very much for your tips. I find it as an extremly flexible
paradigm. I have to do quite a lot of operations with 4 UARTS, and I want
to know more about working on the bits, could you recommend me a website
or an online resource which would be handy for this particular topic. I
know there exists a lot, but I want to know abt bitwire operations from
the register access point of view. If you know some resource, just put it
here. Would be great.

Thanks a lot
Cheers
Densil
 
M

Mark McIntyre

On Thu, 15 Jul 2004 04:01:15 -0400, in comp.lang.c , "silentlights"

(quoting someone unknown)er, this looks horribly like some sort of attempt to directly access
hardware. Any attempt to do that is platform specific, you need to ask in a
platform-specific group, dos programming, maybe . In any events,not in CLC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Cash register challenge 2
Register Question 0
Register parameters 7
register keyword 3
Register bit count 3
Opening and appending to file in Python3 0
Error Handling 27
Opening and appending to file in Python3 6

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top