473,386 Members | 1,969 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,386 software developers and data experts.

simple port access

I am trying to write a simple code for bit maniipulation and to start
with wrote a little code to read the port A of a microcontroller
MPC8xx. Its running on VxWorks. Anyways thats probably irrelevant. Can
anyone please point out mistake in the code.?

#include <stdio.h>
#include <iostream.h>
#include "arch/ppc/vxPpcLib.h"

unsigned long ppc_base_addr = vxImmrGet(); //Get the base address
#define PADAT *(volatile unsigned long *)(ppc_base_addr+0x956) //0x956
is address of port A
#define BIT(x) (1 << (x))

unsigned long read()
{

unsigned long i = 0x80000000;
PADAT = i;
unsigned long temp = *(unsigned long *)(PADAT);
return(temp);
}
Thanks for any suggestions.

PS- I can probably ask the Q in VxWorks or Embedded group but I think
its my C++ that a problem....

Aug 9 '06 #1
4 2976
le*******@gmail.com wrote:
I am trying to write a simple code for bit maniipulation and to start
with wrote a little code to read the port A of a microcontroller
MPC8xx.
That's beyond the scope of this newsgroup. Hardware manipulation and
control is not part of C++ *language*. It's defined at the platform
level, and as such cannot be expressed in terms of Standard C++ alone.
Its running on VxWorks. Anyways thats probably irrelevant.
Platform is irrelevant to most questions that are on topic here. What
your program does and why it doesn't do what it should (if that's so),
it absolutely relevant to what platform it runs on.
Can
anyone please point out mistake in the code.?
I'll tell you what I see as a mistake, but it doesn't mean you will fix
your program by correcting it.
>
#include <stdio.h>
#include <iostream.h>
There is no header '<iostream.h>' in C++. The header you need is called
'<iostream>' (notice no '.h').
#include "arch/ppc/vxPpcLib.h"
That's a non-standard header, and I have no idea what it does or how
it can affect the correctness of your program.
>
unsigned long ppc_base_addr = vxImmrGet(); //Get the base address
'vxImmrGet' is not a standard function. Use at your own risk.
#define PADAT *(volatile unsigned long *)(ppc_base_addr+0x956) //0x956
is address of port A
#define BIT(x) (1 << (x))

unsigned long read()
{

unsigned long i = 0x80000000;
PADAT = i;
The line above hides what really happens. I'd probably define 'PADAT'
*without* the leading dereference and then used

*PADAT = i;

here.
unsigned long temp = *(unsigned long *)(PADAT);
This is probably the source of your trouble. 'PADAT' is a reference to
the long that resides in your port. You're treating it as a pointer.
Use my advice above, and drop the leading asterisk from the definition
of PADAT macro.
return(temp);
Parentheses are superfluous here.
}
Thanks for any suggestions.

PS- I can probably ask the Q in VxWorks or Embedded group but I think
its my C++ that a problem....
Next time you probably should.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 9 '06 #2

le*******@gmail.com wrote:
I am trying to write a simple code for bit maniipulation and to start
with wrote a little code to read the port A of a microcontroller
MPC8xx. Its running on VxWorks. Anyways thats probably irrelevant. Can
anyone please point out mistake in the code.?

#include <stdio.h>
#include <iostream.h>
#include "arch/ppc/vxPpcLib.h"

unsigned long ppc_base_addr = vxImmrGet(); //Get the base address
#define PADAT *(volatile unsigned long *)(ppc_base_addr+0x956)
#define PAADDR (volatile unsigned long *)(ppc_base_addr+0x956)
#define BIT(x) (1 << (x))

unsigned long read()
{

unsigned long i = 0x80000000;
PADAT = i;
unsigned long temp = *PAADDR;
return(temp);
}
Aug 9 '06 #3
ge***********@gmail.com wrote:
le*******@gmail.com wrote:
>I am trying to write a simple code for bit maniipulation and to start
with wrote a little code to read the port A of a microcontroller
MPC8xx. Its running on VxWorks. Anyways thats probably irrelevant.
Can anyone please point out mistake in the code.?

#include <stdio.h>
#include <iostream.h>
#include "arch/ppc/vxPpcLib.h"

unsigned long ppc_base_addr = vxImmrGet(); //Get the base address
#define PADAT *(volatile unsigned long *)(ppc_base_addr+0x956)
#define PAADDR (volatile unsigned long *)(ppc_base_addr+0x956)
>#define BIT(x) (1 << (x))

unsigned long read()
{

unsigned long i = 0x80000000;
PADAT = i;
Then probably

*PADAT = i;
>unsigned long temp = *PAADDR;
return(temp);
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 9 '06 #4
On 9 Aug 2006 14:05:36 -0700 in comp.lang.c++, "le*******@gmail.com"
<le*******@gmail.comwrote,
>Can anyone please point out mistake in the code.?
What makes you think there is any mistake in the code? Is it
supposed to do something?
>#define PADAT *(volatile unsigned long *)(ppc_base_addr+0x956) //0x956
is address of port A
I'm not real happy about seeing this macro here. Better C++ style
would be inline functions for such access.

And in this case, the macro is hiding your problem from you. Below
you are using PADAT as if it was both the value you are assigning
and elsewhere as if it was a pointer. You are getting confused
about how many levels of indirection to apply.
> PADAT = i;
No *, not a pointer.
> unsigned long temp = *(unsigned long *)(PADAT);
Extra *, PADAT treated as a pointer.

Aug 9 '06 #5

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

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
1
by: StevenBarnes | last post by:
I need to have some .Net code be able to send Email using my ISP's SMTP server. I found some articles on how to use the MAIL FROM: and RCPT TO: commands that you can stream to a tcp connection on...
3
by: MBW | last post by:
The following code is for a simple server/client asplication that allows the user to toggle between serve and or client modes and send/recieve a message however i am getting an Attribute error on...
16
by: News VS.NET \( MS ILM \) | last post by:
Hello VC, Given a non-DotNET dll from some unknown place How do I know the classes in it, or how do I view the classes, methods, properties etc.. Thank you
5
by: c#freeskier89 | last post by:
Can someone please give me some information on sending data through a USB port. What I am trying to do is use the USB port (I get how to do it on a COM port). I am using VC# 2005. I have searched...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
3
by: Frank Swarbrick | last post by:
We are just starting to use DB2. I have a question about Control Center and port 523. Our DBA set up a database that listens on port 30280 (I have no idea where that port number came from...). ...
0
by: aymen | last post by:
Hi all, I have 2 applications trying to gain access to the same GPRS modem port COM3 (the 1st application comes with the product and can't be configured to use another port and 2nd application is...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.