473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

register handling

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
Nov 14 '05 #1
9 1478

On Wed, 14 Jul 2004, silentlights wrote:

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
Nov 14 '05 #2
Probably way off base, but instead of returning SPORT, for example,
shouldn't it return st_sci?

Sorry if wrong :)

Kevin

"silentlights" <si**********@yahoo.co.uk> wrote in message
news:2b******************************@localhost.ta lkaboutprogramming.com...
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

Nov 14 '05 #3
silentlights wrote:
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

Nov 14 '05 #4

On Wed, 14 Jul 2004, silentlights wrote:

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
Nov 14 '05 #5
In 'comp.lang.c', "silentlights" <si**********@yahoo.co.uk> wrote:
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;

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #6
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
Nov 14 '05 #7
silentlights wrote:
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 ?

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.


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

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

Nov 14 '05 #8
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

Nov 14 '05 #9
On Thu, 15 Jul 2004 04:01:15 -0400, in comp.lang.c , "silentlights"
<si**********@yahoo.co.uk> wrote:

(quoting someone unknown)
#define TX_REG_OFFSET 0
#define RX_REG_OFFSET 4
#define STATUS_REG_OFFSET 8
#define CTRL_REG_OFFSET 12

unsigned char byte = 0;
if (*((unsigned int *)(base_ptr + CTRL_REG_OFFSET))
& RX_RDY)

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.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
10
by: Frits JK | last post by:
Hallo, I have to write a GUID to the register but I don't know to convert to hexadecimal. I have tried several things but I am shore that line 5 and 6 are not correct....
3
by: Alex | last post by:
I apoligise in advance if this is an os or platform based question, I don't know. I was wondering how register integers (and other types of register variables) are managed by c++. For example,...
14
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
9
by: Jackie | last post by:
Hi everyone, Does anyone know when "register" declarations should be used and when "register" must not be used? If possible please give examples for both cases. Thanks
29
by: orium69 | last post by:
hi everyone, i'm wondering if there is a way to have sure that a variable is allocated in the cache, after its declaration with "register"? Tks!
33
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a...
28
by: sowmiyakc18 | last post by:
Please clear my doubt. When do we declare a variable to be a register variable? What is its significance? What are the conditions to be adhered to when register variables are passed between...
8
by: nickooooola | last post by:
Hello to all I'm about to write a simulator for a microcontroller in python (why python? because I love it!!!) but I have a problem. The registry of this processor are all 8 bit long (and 10...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.