473,811 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An alternative register access..?

Hi Guys, I am looking for an alternative means of register access in a
microcontroller . Currently my get() function looks like this..
------------------------
implementation in comm.c
------------------------
/*A simple get() function*/
unsigned char port0_get_char( void)
{
unsigned char input_c;

// Poll the SSR RDRF bit until it is ready
while ( !(Serial_Port0_ Status_Register .BIT.RDRF))
{ ; }

input_c = Serial_Port0_Re ceive_Data_Reg;

// Clear the SSR RDRF bit
Serial_Port0_St atus_Register.B IT.RDRF = SET_BIT_LOW;

return input_c;
}
............... ............... ............... ............

This means if I have 4 ports I have to define get()/put() functions for 4
serial ports 4 different times.. although the procedure is the same while
the registers are different. Is there a smater way of doing it... where
there could be only one function and access the registers in the functions
using pointers.. does any have a suggestion.. Here is how I defined the
header files.. is there an alternative way of defining the registers..

Thanks in advance
Densil
-------------------------------------------------
Header file
------------------------
definition in hardware.h
------------------------
struct st_sci { /* struct SCI
*/
union { /* SMR
*/
unsigned char BYTE; /* Byte Access
*/
struct { /* Bit Access
*/
unsigned char CA :1; /* C/A
*/
unsigned char CHR :1; /* CHR
*/
unsigned char PE :1; /* PE
*/
unsigned char OE :1; /* O/E
*/
unsigned char STOP:1; /* STOP
*/
unsigned char MP :1; /* MP
*/
unsigned char CKS :2; /* CKS
*/
} BIT; /*
*/
} SMR; /*
*/
unsigned char BRR; /* BRR
*/
union { /* SCR
*/
unsigned char BYTE; /* Byte Access
*/
struct { /* Bit Access
*/
unsigned char TIE :1; /* TIE
*/
unsigned char RIE :1; /* RIE
*/
unsigned char TE :1; /* TE
*/
unsigned char RE :1; /* RE
*/
unsigned char MPIE:1; /* MPIE
*/
unsigned char TEIE:1; /* TEIE
*/
unsigned char CKE :2; /* CKE
*/
} BIT; /*
*/
} SCR; /*
*/
unsigned char TDR; /* TDR
*/
union { /* SSR
*/
unsigned char BYTE; /* Byte Access
*/
struct { /* Bit Access
*/
unsigned char TDRE:1; /* TDRE
*/
unsigned char RDRF:1; /* RDRF
*/
unsigned char ORER:1; /* ORER
*/
unsigned char FER :1; /* FER
*/
unsigned char PER :1; /* PER
*/
unsigned char TEND:1; /* TEND
*/
unsigned char MPB :1; /* MPB
*/
unsigned char MPBT:1; /* MPBT
*/
} BIT; /*
*/
} SSR; /*
*/
};

#define P_SCI0 (*(volatile struct st_sci *)0xFFFF78) /* SCI0
Address*/
#define P_SCI1 (*(volatile struct st_sci *)0xFFFF80) /* SCI1
Address*/
#define P_SCI2 (*(volatile struct st_sci *)0xFFFF88) /* SCI2
Address*/
#define P_SCI3 (*(volatile struct st_sci *)0xFFFDD0) /* SCI3
Address*/

--------------------
definition in comm.h
--------------------
#define Serial_Port0_Co ntrol_Register P_SCI0.SCR
#define Serial_Port0_St atus_Register P_SCI0.SSR

#define Serial_Port1_Co ntrol_Register P_SCI1.SCR
#define Serial_Port1_St atus_Register P_SCI1.SSR
....
----------------------------------------------------------

Nov 14 '05
16 2969
In <Xn************ **************@ 212.27.42.74> Emmanuel Delahaye <em**********@n oos.fr> writes:
In 'comp.lang.c', "Mark A. Odell" <od*******@hotm ail.com> wrote:
Although I agree with you in principle, I must say I use carefully
packed bit-fields often.

I once have been bitten by an Motorola to Intel bit order changes. Once
was fine. More would be silly.


So you switched CPUs in mid-project? How, praytell, did you expect your


No. It was more a problem of data exchange between two different
architecture s.


So, it had exactly zilch to do with our discussion. Of course, it is
sheer stupidity to try to map an externally imposed data format with a
structure, if you expect any kind of code portability.

But even in this case, you still use a structure and a couple of
conversion functions from external buffer format to internal structure
format and from internal structure format to external buffer format,
so that all the ugliness is restricted to these two functions.
And these two functions can be portably implemented, even if the
internal structure layout is implementation-specific.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #11
Hi,
The compiler tell that, SCI is not type compatable. Could you let me know
what could be the reason.

Thanks
Densil

Nov 14 '05 #12
Hi,
The other methods you had suggested were little confusing for me. I could
get the switch case suggestion, it is simple. I am also trying something
like,

#define ACCESS(TYPE, LADR) (*((TYPE volatile *) (LADR)))
#define S_PORT(ADR) (ACCESS(st_sci, ADR))
#define SPORT0_TYPE S_PORT
#define SPORT0_ADR 0xFFFF78
#define SPORT1_TYPE S_PORT
#define SPORT1_ADR 0xFFFF80
#define SPORT2_TYPE S_PORT
#define SPORT2_ADR 0xFFFF88

void putChar(S_PORT PORTNAME, char VAL);
char getChar(S_PORT PORTNAME);

Could someone tell me what I made as mistake here..? Do you have an idea
of how I can do the header definitions in this way..?

Thanks in advance
Densil

Nov 14 '05 #13
"silentligh ts" <si**********@y ahoo.co.uk> wrote in
news:57******** *************** *******@localho st.talkaboutpro gramming.com:
Hi,
The other methods you had suggested were little confusing for me. I
could get the switch case suggestion, it is simple. I am also trying
something like,

#define ACCESS(TYPE, LADR) (*((TYPE volatile *) (LADR)))
#define S_PORT(ADR) (ACCESS(st_sci, ADR))
#define SPORT0_TYPE S_PORT
#define SPORT0_ADR 0xFFFF78
#define SPORT1_TYPE S_PORT
#define SPORT1_ADR 0xFFFF80
#define SPORT2_TYPE S_PORT
#define SPORT2_ADR 0xFFFF88

void putChar(S_PORT PORTNAME, char VAL);
char getChar(S_PORT PORTNAME);

Could someone tell me what I made as mistake here..? Do you have an idea
of how I can do the header definitions in this way..?


I think you need to dispense with the macros. What was so confusing about
my serial port picker table? Macros have problems that functions do not
and should only be used where a function cannot reasonably do the job.

--
- Mark ->
--
Nov 14 '05 #14

On Wed, 14 Jul 2004, silentlights wrote:

#define ACCESS(TYPE, LADR) (*((TYPE volatile *) (LADR)))
#define S_PORT(ADR) (ACCESS(st_sci, ADR)) void putChar(S_PORT PORTNAME, char VAL);
char getChar(S_PORT PORTNAME);

Could someone tell me what I made as mistake here..?


Simple --- expand the macros and look for syntax errors.

void putChar(S_PORT PORTNAME, char VAL);

Here's a syntax error already --- S_PORT is an undefined identifier.
Did you mean perhaps

void putChar(S_PORT( ) PORTNAME, char VAL);

? That would expand to

void putChar((*((st_ sci volatile *) ())) PORTNAME, char VAL);

which is again a syntax error. Or you might have meant

void putChar(S_PORT( PORTNAME), char VAL);

which would expand to

void putChar((*((st_ sci volatile *) (PORTNAME))), char VAL);

which is /again/ a syntax error. What are you trying to do here?
Declare a function parameter, obviously, but what type is it supposed
to have? If it's a pointer to 'volatile st_sci', then just write

void putChar(st_sci volatile *PORTNAME, char VAL);

and be done with it. Make a macro

#define S_PORTD(ident) st_sci volatile *ident

void putChar(S_PORTD (PORTNAME), char VAL);

if you really want to, but that looks a lot like overkill to me.
Perhaps you'd better give some context...

-Arthur

Nov 14 '05 #15
What are you trying to do here? Declare a function parameter, obviously,
but what type is it supposed
to have?

I am trying to declare a function Eg. getChar. I have 4 serial ports
(Ports 0,1,2 & 3)and I want to write a single function putChar() common
for all ports. Inside the function I have to access the registers of
individual ports like PORT1->Data_Registe r or something like PORT1.DR. The
structure of the registers are defined in the st_sci structure.

In which case, I have pass an argument which has the address of the group
of registers which belong to Port 1. Inside the function, I have to handle
a particular register using the passed parameter. And then I landed up in
a piece of code like,

#define ACCESS(TYPE, LADR) (*((TYPE volatile *) (LADR)))
#define S_PORT(ADR) (ACCESS(st_sci, ADR))

#define SPORT0_TYPE S_PORT
#define SPORT0_ADR 0xFFFF78
#define SPORT1_TYPE S_PORT
#define SPORT1_ADR 0xFFFF80
#define SPORT2_TYPE S_PORT
#define SPORT2_ADR 0xFFFF88
#define sci S_PORT

//typedef S_PORT sci;

char getChar(sci PORTNAME);

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

Thanks in advance
Densil

Nov 14 '05 #16
You are right abt the code Mark, I appreciate your reply. I dont want to
execute a function which finds me an address everytime I am into a
getChar() function. Instead, I want to pass the address of the register
directly into the getChar function which would read the registers of the
corresponding ports. And this I want to reach using macros. I could use a
simple switch case block or the way you had suggested. A call to a
function costs me 8 cycles and then the execution of the function takes me
more. If I have a chance to pass it directly, then I have the read done
with less overhead.

Cheers
Densil

Nov 14 '05 #17

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

Similar topics

2
4289
by: Robert M. | last post by:
Information: Server A: SQL Server 2000 Enterprise Edition. OS is Windows 2003 Server Enterprise Edition. SQL Service pack is 3a. Member of domain ABCDomain. Server A is going to function as a Distributor. Location: New York. Server B: SQL Server 2000 Enterprise Edition. OS is Windows 2003 Server Standard Edition. SQL Service pack is 3a. Member of domain ABCDomain. Server B is going to function as a Subscriber.
2
2979
by: war_wheelan | last post by:
I have two servers running SQL Server on the same network and I am receiving errors registering the various instances as follows: SERVER1 tried to register the local instance (by netname, ip address and local) ERROR Msg: SQL Server does not exist or access denied (ConnectionOpen | Connect() SERVER1 trying to register Server2's default instance (by netname, ip address and local) COMPLETES SUCESSFULLY (THIS INSTANCE CAN BE REGISTER
1
4212
by: Earl Anderson | last post by:
My brother is in the process of purchasing a neighborhood dry cleaners store. Having seen some of the process applications I've written in MS Access, he asked me if I could develop an application to use in his new dry cleaning store since the existing one is of 1988 vintage. I told him that although I thought the 'process' involved in a dry cleaners couldn't be too complex and probably could be developed in Access, I had absolutely no...
115
14208
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i prefer a solution that (also) supports Windows. On the net I found a number of products that i looked at, but none of them gave me the impression of a serious candidate at this moment (KNoda, Gnome DB Manager, InterBase...). 2 additional...
20
3505
by: Sushil | last post by:
Hi gurus I was reading FAQ "alloca cannot be written portably, and is difficult to implement on machines without a conventional stack." I understand that the standard does not mandate "heap" or "stack" I'm curious to know the implemenations which dont have stack or heap.
9
8613
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
2481
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!
1
2339
by: Hitchkas | last post by:
I posted this in PocketPC newsgroup with no response yet, hopefully somebody here has an answer. I have an application that runs locally on PocketPC. The user interface for this application is HTML with Javascript. The Javascript on the page instantiates an ActiveX control written in C++ ATL. The ActiveX does not have a visual interface and its basic functionality is to access the serial port and do some calculations and return the...
33
3297
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 full 10 minutes every time a "register" declared variable is read from or written to. Besides this lag, everything else runs as expected. Then my compiler is still C compliant, aye? If so, then it is unwise for any programmer to ever use the...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.