Mobile Apps - Accessing physical memory through PC/104 bus

Asked By Peter_Šupina
05-Feb-10 10:19 AM
Hello all.

We need to access (read/write) memory on devices (cards) attached to
PC/104 bus.
Operating system: Microsoft Windows Embedded CE 6.0
Target processor: Advantech PCM-3375 (x86 architecture)
http://www.advantech.com/products/PCM-3375/mod_1-2JKGWQ.aspx

We were using operating system QNX 4.25 before, now we plan to migrate
our code to WinCE6.
Under QNX, we were accessing the memory using block of code similar to
this one:

{

int            addr =3D 0xd9080;        // physical address on card
unsigned long  size =3D 0x1000;   // size of block to access

unsigned char *mem =3D NULL;
int            fd;
void          *map;

/* Address has to be in specific range */
if (addr < 0xffff) addr +=3D 0xd0000;
addr &=3D 0xffff0;

/* Open physical memory */
fd =3D shm_open( "Physical", O_RDWR, 0777 );

if (fd =3D=3D -1) {
fprintf(stderr, "shm_open failed: %s\n", strerror(errno));
exit(1);
}

/* Map memory (4kB aligned) */
map =3D mmap( 0, size + (addr & 0xfff), PROT_WRITE | PROT_READ,
MAP_SHARED, fd, addr & ~0xfff );

if (addr =3D=3D (void *) -1) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
exit(1);
}

mem =3D (unsigned char*)((char*)map + (addr & 0xfff));

/* Working with memory */
mem[0] =3D 0xa0;      // Writing to memory
printf("mem[0] =3D %X\n", mem[0]);     // Reading from memory

/* Unmap memory */
munmap(map, size + (addr & 0xfff);
shm_unlink("Physical");

}

Reference to functions used:
http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/shm_open.ht=
ml
http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/mmap.html
http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/munmap.html
http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/shm_unlink.=
html


We need to write code to do the same operations under Windows Embedded
CE 6.0.

Do I need to write Kernel-mode driver to access the physical memory?
Do I need to adjust BSP?
Which functions should I use?

Thank you.

Best regards,
Peter =C5=A0upina
Windows Embedded CE 6.0
(1)
HalTranslateBusAddress
(1)
MmMapIoSpace
(1)
EMVP
(1)
Advantech
(1)
Tobey
(1)
Unmap
(1)
Strerror
(1)
  AndrewScholan[MCTS] replied to Peter_Šupina
05-Feb-10 11:35 AM
ch.com/products/PCM-3375/mod_1-2JKGWQ.aspx
=A0 =C2=A0 =C2=A0// physical address on card
watcom/clibref/qnx/shm_o...http://www.users.pjwstk.edu.pl/~jms/qnx/help/wat=
com/clibref/qnx/mmap....http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom=
/clibref/qnx/munma...http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/cl=
ibref/qnx/shm_u...

Yes, the correct way to do this is to write your own device driver.
It does not have to be a kernel mode driver, but most people write
drivers
that run in kernel mode rather than user mode drivers for CE 6.0.

Look at the online MSDN help for more information.
http://msdn.microsoft.com/en-us/library/aa910457.aspx

Andrew
  Peter_Šupina replied to AndrewScholan[MCTS]
05-Feb-10 11:35 AM
tech.com/products/PCM-3375/mod_1-2JKGWQ.aspx
=C2=A0 =C2=A0 =C2=A0// physical address on card
;
p/watcom/clibref/qnx/shm_o......
om/en-us/library/aa910457.aspx

Thank you for your quick response.
However, I wonder which memory mapping function I should use.

Is it enough to just call MmMapIoSpace() ?
Or do I need to translate the address somehow (e.g.
HalTranslateBusAddress) ?
  AndrewScholan[MCTS] replied to Peter_Šupina
05-Feb-10 12:52 PM
e:
antech.com/products/PCM-3375/mod_1-2JKGWQ.aspx
e
o
=C2=A0 =C2=A0 =C2=A0// physical address on card
s
));
ry
elp/watcom/clibref/qnx/shm_o......
d
.com/en-us/library/aa910457.aspx
  Peter_Šupina replied to AndrewScholan[MCTS]
05-Feb-10 01:26 PM
ote:
o
dvantech.com/products/PCM-3375/mod_1-2JKGWQ.aspx
ate
to
=A0 =C2=A0 =C2=A0 =C2=A0// physical address on card
ess
no));
;
mory
/help/watcom/clibref/qnx/shm_o......
ded
?
  Paul G. Tobey [eMVP] replied to Peter_Šupina
05-Feb-10 06:21 PM
PC/104 is always ISA; that is how it is defined.

That's the result that I would expect.  Since the ISA bus is almost always
just a direct connection to the processor, there is no mapping from processor
address space to bus address space.  There could be exceptions if your
processor is not x86 (where there are no I/O instructions, only memory
instructions, and therefore the I/O address on the bus has to be mapped to a
memory address).  However, since you are running on a CEPC, essentially, I'd
expect no remapping of addresses.

Paul T.
  Peter_Šupina replied to Paul G. Tobey [eMVP]
05-Feb-10 07:04 PM
On 6. Feb, 00:21 h., Paul G. Tobey [eMVP] <paultobey _at_ earthlink
always
sor
ur
o a
lly, I'd


Thank you for your response.

If I am reading it right, in this case (ISA bus and x86 architecture),
there is no need for calling HalTranslateBusAddress()?
So, should I just use MmMapIoSpace() function to get virtual address
(or *other* function?) and use READ_REGISTER_* / WRITE_REGISTER_*

Thank you.

Best regards,
Peter =C5=A0upina
  Paul G. Tobey [eMVP] replied to Peter_Šupina
08-Feb-10 11:18 AM
Perhaps there is no need, but the cost is low and there is no reason, unless
you have profiled this and found that, to meet some performance target, you
do not have time to call it.  The result could then be used with READ/WRITE
macros.

Paul T.
Create New Account
help
Does Windows Embedded CE 6.0 support IMGFS? Mobile Apps Hello! I have experienced IMGFS(Image File System) at Windows Mobile 5.0 based platform. Does Windows Embedded CE 6.0 support IMGFS??? MSDN does not almost mention IMGFS. . . thanks WindowsCE Platform Builder Discussions Windows Embedded CE 6.0 (1) Windows Mobile 5.0 (1) EMVP (1) BSQUARE (1) IMGFS
Windows Emb CE 6.0 Memory Architecture Mobile Apps Hi, I have gone through Windows Embedded CE 6.0 Advanced Memory Management. I have some Questions 1. In Windows CE 5.0 we had ‘Slot 0’ for current running process, where are the current running process in Windows Embedded CE 6.0 run as there is no ‘Slot’ in it. 2. Memory
Windows Mobile vs Windows CE Mobile Apps Hello, I am confused from Micosoft OS names. Could you anybody explain them? For example: what difference is between Windows Mobile 6.0, Windows CE 6.0, Windows Embedded CE 6.0 and Windows CE .Net? What OS is used on smartphone devices? Thank
Windows Embedded CE 6.0 Monthly Update (August 2007) Mobile Apps Hi, looking at the Windows Embedded CE Updates site (http: / / msdn2.microsoft.com / it-it / embedded / aa731256.aspx) the latest available update is the one released for July. We have found by chance a newer Windows Embedded CE 6.0 Monthly Update (August 2007) on another MS site (http: / / www.microsoft
Visual Studio crash after installing Windows Embedded CE 6 R2. Mobile Apps Hi All, I have seen Visual Studio crash several times after installing Windows Embedded CE 6 R2 (See previous post: Issues adding SDBUS support with Windows Embedded CE 6 R2). My latest is when I am trying to use the debugger. Whenever