Switching PORTS on and off with evc++

selvabarathi
Hi,
i want to turn on and off gpio ,how can i do that in c language using evc++
i already tried hello world its working ,but if i try to do the following
its not working

#include"windows.h"
#define rGPBCON    (*(volatile unsigned *)0x56000010)  //Port B control
#define rGPBDAT    (*(volatile unsigned *)0x56000014)  //Port B data
#define rGPBUP     (*(volatile unsigned *)0x56000018)  //Pull-up control B

int WinMain()
{
  int data,i;
  data = 0x06;
     while(1)
     {
  rGPBDAT = (data<<5);
   for(i=0;i<100000;i++)
    {
    }
       data =~data;
  }
   
   return 0;
}

iam getting an error like this illegal operation while iam trying to run in
mini 2440

pls pa anybody help.....................

domodom
Hello, 
With Windows CE, you can't directly access registers by using their
physical address.
You have to declare a virtual pointer and map it to the physical address of
the register(s) you want to access. Then, to access register, you use the
virtual pointer.
If you are under CE 5.0, it could be made directly in an application. If
you are under CE 6.0, you have to use a driver.
You can have a look to my tutorial, you will find a GPIO driver and a
sample applcition written in c++
(http://www.domodom.fr/spip/A-GPIO-driver-for-mini2440.html). The source
code of the driver is available, then you will be able to study the source
code to understand how it works.
domodom

selvabarathi
Hi domdom,

Iam not good in c++.pls understand but iam good in c can u give me a sample
application to just turn on and off a led for wince 5 help me
pls..........................pa.......................................

domodom
My driver and its sample application are written in C, so you should easily
understand how it works.
domodom

selvabarathi
hi domdom,
             from my early age i love to work in embedded ,but this kit
makes me frustrating can u please help me to access a port can u give me a
sample program for me that just turns on and off the ports with  delay in
wince 5.0 can u spend a little time for me pls pa help me ...............
i know u are a master can u spend a little time pls ...............

Awaiting for ur reply     thanks...........

Andreas Watterott
Do you think someone will help you, if you start several topics with the
same content?

selvabarathi
sorry can u pls help me

selvabarathi
pls pa somebody help pa.i beg u pls.i have to submit a project.definitely
this time they are goin to fail
me............................................

domodom
What don't you understand in my source code ? Did you at least took the
time to study it ?
I won't write your project for you !
domdom

selvabarathi
domdom dont get angry pls this is my doubt.

in vb.net i have mapped the physical address like ths

 Shared iADCDAT0 As New PhysicalAddressPointer(&H5800000C, &H1)


in evc++ how can i map it just give me a example thats enough this is my
last doubt

hereafter i wont disturb u........

thanks for ur reply...............................

Andreas Watterott
Look in the source code of domodom's GPIO driver:
http://www.domodom.fr/spip/A-GPIO-driver-for-mini2440.html
There are also code snippets in this forum, if you search for GPIO...
So where is your problem!

selva
hi


#include <windows.h>

#include <pm.h>
#include "s2440.h"

#define U32 unsigned int



volatile IOPreg   *s2440IOP = (IOPreg *)IOP_BASE;





void Virtual_Alloc();  
void dely(U32);          // Virtual allocation


void dely(U32 tt)
{
   U32 i;
   for(;tt>0;tt--)
   {
     for(i=0;i<10000;i++){}
   }
}


void Virtual_Alloc()
{
  // GPIO Virtual alloc
  s2440IOP = (volatile IOPreg *) VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE,
PAGE_NOACCESS);

}



int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) 
{
  volatile UINT32* gpxCon = 0;
  volatile UINT32* gpxDat = 0;
int data;
data=0x06;


   
  Virtual_Alloc();


gpxCon = &s2440IOP->rGPBCON;

*gpxCon=0x155555;

gpxDat = &s2440IOP->rGPBDAT;

while(1)
{
       
     *gpxDat  =  (data<<5);

  dely(120);

     data =~data;
}
       
  
   
   return 0;
}



this is my new program is this correct but iam still getting errors while
iam trying to run the exe in wince5.0

selva
Hi domdom,
hi domdom dont get angry da pls tell me, my above program is correct or not
iam using mini2440 with wince5...............................

domodom
Yes, I think it's OK, but if you don't give us more explanations about your
problem, I won't be able to help you.
By the way, did you tried my driver in Windows CE 5 ? I think it should
work...
domodom

selva
ya i tried it is not working

i also tried to write like this



#include <windows.h>
#include <pm.h>
#include "s2440.h"

#define U32 unsigned int

volatile IOPreg   *s2440IOP = (IOPreg *)IOP_BASE;

void Virtual_Alloc();  
void dely(U32);          // Virtual allocation

void dely(U32 tt)
{
   U32 i;
   for(;tt>0;tt--)
   {
     for(i=0;i<10000;i++){}
   }
}
void Virtual_Alloc()
{

// GPIO Virtual alloc
  s2440IOP = (volatile IOPreg *) VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE,
PAGE_NOACCESS);
  }
  }


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) 
{
  volatile UINT32* gpxCon = 0;
  volatile UINT32* gpxDat = 0;
int data;
data=0x06;
Virtual_Alloc();
2440IOP->rGPBDAT=  s2440IOP->rGPBDAT & (0x1 << 5);//reading pin 5
s2440IOP->rGPBCON = (s2440IOP->rGPBCON &~ ( 3 << 5*2)) | ( 1<< 5*2); 
while(1)
{
       
s2440IOP->rGPBDAT = (s2440IOP->rGPBDAT &~ (0x1 << 5));
dely(120);
 s2440IOP->rGPBDAT = (s2440IOP->rGPBDAT | (0x1 << 5));

}
    return 0;
}


it is also giving error pa domdom.any ideas or suggestions....

domodom
What error do you have ?

selva
application lava.exe has performed illegal operation and will be shutdown
if the problem persists contact the program vendor

program:lava.exe
exception:0xC0000005
address:000110E0

domdom sir is my above program is right......................
why am i getting this
domdom sir thanks for helping me.........

domodom
What is the value s2440IOP returned by VirtualAlloc ?

selva
Hi domdom,

so i have to add this line right

void Virtual_Alloc()
{

    // GPIO Virtual alloc
  s2440IOP = (volatile IOPreg *) VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE,
PAGE_NOACCESS);
  if(s2440IOP == NULL) {
    RETAILMSG(1,(TEXT("For s2440IOP: VirtualAlloc faiLED!\r\n")));
    
  }
}

domodom
Not only, I just seen you forgot the virtualcopy() call.

selva
Hi domdom
            iam going to cry domdom my usb driver is not working now.
I am having window xp2. In dnw i get this error usb not ok because i cant
install the usb driver. i tryed my computer manage->usb driver and i
installed but it is asking for SECBULK.Sys...........


ok i will addd virtual copy
also.....................................................................

domodom
I'm sorry, but I can't help you with this problem...
I think that with virtualcopy, it should work
domodom

selva
void Virtual_Alloc()
{

    // GPIO Virtual alloc
  s2440IOP = (volatile IOPreg *) VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE,
PAGE_NOACCESS);
  if(s2440IOP == NULL) {
    RETAILMSG(1,(TEXT("For s2440IOP: VirtualAlloc faiLED!\r\n")));
    
  }
  else {
   
if(!VirtualCopy((PVOID)s2440IOP,(PVOID)(IOP_BASE),sizeof(IOPreg),PAGE_READWRITE
| PAGE_NOCACHE )) {
      RETAILMSG(1,(TEXT("For s2440IOP: VirtualCopy faiLED!\r\n")));
    }

}
}


i included this files only

#include <windows.h>
#include <pm.h>
#include "s2440.h"


i tryed to add like this but getting the following error..

C:\Documents and Settings\selva\Desktop\gpio.cpp(42) : error C2065:
'VirtualCopy' : undeclared identifier

sir am i missing any header.... sir

selva
i resolved the problem but i didnt check it in wince because of usb
problem.tommorow pls check my forum pls da domdom.......

take care
#define EXTERNC    extern "C"


EXTERNC BOOL VirtualCopy(LPVOID dest, LPVOID src, DWORD size, DWORD flags);

domodom
VirtualCopy is declared if the pkfuncs.h file that you can find here : 
C:\WINCE600\OSDesigns\Mini2440\Mini2440\Wince600\Mini2440_ARMV4I\cesysgen\oak\in
c
under wince 6.0
I don't know where it is under CE 5.0, you have to find it by yourself
domodom

selva
domdom u are great

thanks very very thanks....................

for helping me 


at last i got the output...............................................


can u give me ur phonenumber i have to speak with u.........

love u  .......................

domodom
Congratulations !!
It's funny the pleasure we can sometimes feel just by turning on a led !!
;o) I rememeber the night 20 years ago, when I succeeded to light on a led
by pushing a button that was triggering a interrupt in a 8051...
If you want to directly contact me, you can do it via my website.
Best regards
domodom

PS : a french expression : plus ça rate, plus ç a de chances de réussir ->
the more it fails, the more it has chance to succeed

selva
Hey domdom

ya ya ayae hurrah thanku......................
he he he ha ha ha ha


thanks a lot.................

selva
hi domdom

what am i doin here


volatile IOPreg   *s2440IOP = (IOPreg *)IOP_BASE;



pls tell me

am i declaring pointer *s2440IOP same as iopreg 
then what is this (IOPreg *)IOP_BASE;


explanation please

domodom
s2440IOP is the name of your variable.

IOPreg* is the type (= a pointer on a IOPreg object)

volatile is a compiler directive that ask him to calculate the variable
each time you use it.

IOP_BASE is the adress of your registers, you want s2440IOP to point on
this address, it is defined in a .h file included in your project, with a
line like this one : 
#define IOP_BASE 0x12345678
Before compilation, the precompiler will replace, in your source code,
IOP_BASE by 0x12345678

If you write : 
volatile IOPreg* s2440IOP = IOP_BASE;
after precompiler, you will have
volatile IOPreg* s2440IOP = 0X12345678
you will have a compiler error, because the type of the terms each side of
the = sign are not the same (a pointer on an object at left, a number at
right)

That's why you have to make a cast operation to transform the number in a
pointer on the same object : 
volatile IOPreg* s2440IOP = (IOPreg*)IOP_BASE;

Is it clear ?

domodom

selva
Hi domdom
           everything is clear.

one silly question

in structure concept what we will do is

struct domdom
{
int hello;
}a,*ptr;

then we will access it by a.hello=35;
then we wil access hello by a pointer we will use arrow sign like this
ptr->hello=35;

but here my doubt is

in header

#define IOP_BASE 0x12345678
typedef struct
{
uint rgpdat
uint sddd;
uint xxxx;
uint wwww;
}IOPreg;


so here IOPreg is not a pointer and u said s2440IOP is the name of your
variable.
 so we are not using any pointer here then what is the need of arrow sign 
s2440IOP->rGPBCON  here......pls dont kill me............................

 thanks domdom...

domodom
yes, s2440IOP is a pointer, you declare it like this : 
IOPreg *s2440IOP;

If you write 
IOPreg s2440IOP;
you access the member of the structure with s2440IOP.rgpdat

but if you write 
IOPreg* s2440IOP;
you access the member of the structure with s2440IOP->rgpdat

domodom

selva
thanks domdom sir,

                  great explanation thanks

thank you, take care byeeeeeeeeeeeeee

selva
but domdom
 in gpio.cpp we have declared like this right
IOPreg *s2440IOP not like this IOPreg* s2440IOP;
which is correct a confusion here....

domodom
it is exactly the same for the compipler.
domodom

selva
ok domdom

thank you..see domdom u are the only one helping in this forum.
why people's are greedy?
like u i will also help every person
i love ur true heart...truly

byeeeeeeeeeeeee

thankuuuuuuuuu uuuuuuuuu uuuuuuuuuuuuuuuuu uuuuuuuuuuuuuu uuuuuuuuuuuuu

domodom
No, i'm not the only one.
Each people answer if he has time and if he can help.
I don't reply when I don't know the answer (you won't see me replying in
the linux section for example... ;o)
domodom

selva
hehe hehe

selva
hi domdom,

whats happening in ce.iam very confused i tryed to write a serial port 
communication for transmitting char "a" by accesing the registers.

in the data sheet they have given some registers to set like pic
microcontrollers. i did all and its working fine


s2440IOP->rUBRDIV = 21;//baudrate 115200 kbs..
s2440IOP->rULCON =0x03;....
s2440IOP->rUCON =0x4C04;bla bla

s2440IOP1->rUCON=0x8000;
s2440IOP2->  rGPHCON = s2440IOP2->rGPHCON & ~(3<<16); //GPH8(UEXTCLK) input
dely(1); // about 100us
s2440IOP2->rGPHCON = s2440IOP2->rGPHCON & ~(3<<16) | (1<<17); GPH8(UEXTCLK)
UEXTCLK


while(i)
{
  MessageBox (NULL, TEXT ("send a"), TEXT ("SERIAL"), MB_OK);
s2440IOP->rUTXH='a';

i++;


if(i==4)
{
  break;
}
}


but after that i checked by commenting each of the line  like this

//s2440IOP->rUBRDIV = 21;
//s2440IOP->rULCON =0x03;
//s2440IOP->rUCON =0x4C04;

//s2440IOP1->rUCON=0x8000;
//s2440IOP2->  rGPHCON = s2440IOP2->rGPHCON & ~(3<<16); //GPH8(UEXTCLK)
input
//dely(1); // about 100us
//s2440IOP2->rGPHCON = s2440IOP2->rGPHCON & ~(3<<16) | (1<<17);
//GPH8(UEXTCLK) UEXTCLK


while(i)
{
  MessageBox (NULL, TEXT ("send a"), TEXT ("SERIAL"), MB_OK);
s2440IOP->rUTXH='a';

i++;


if(i==4)
{
  break;
}
}


and i came to know only one line is enough
s2440IOP->rUTXH='a';
 how it is possible....

any ideas .or accessing only one register is enough  domdom

selva
hi domdom,

anyway i got the output for serial txion and reception using registers.
my next project is rfid attendance system with wince for that how can i
fetch wince time using evc++,then how can i write datas to a notepad or to
a excel sheet. can u help me regarding to this.....


godnight bye----pls see the above thread also.


domdom.......i want to say one thing now iam feeling very strong in my
company because of u

thanks for the help

Fernando
I believe there are a lot of domodom fans around here  :)

selva
Hi domdom

         iam doing a rfid project now.

but a problem while displaying a dialog box.iam using a infinite loop
to check for rfid card input.so iam sending value char->"C"  from the
computer serial port to mini 2440.it is correctly matching if i send the
correct word.but at the first time only dialog box is opening and
displaying my name selva and after that when i click ok it is closed upto
this my program is working fine.after the first time if i send the
character the dialog box is closing very fast.for that i have tryed full
night to make the dialog box stable but i cant. can u give me a solution 





while(1)
{

if(s2440IOP->rUTRSTAT==0x7)//to check wheaathet character is rxed only read
is allowed for this reg
  {
if(s2440IOP->rURXH=='c')//checking for a
{

CDateandtimeDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

}
}
}

thanks
domdom

domodom
Hello, 
Sorry for my late reply, I have a lot of work this week.
For your problem with the registers that don't seem to have to be
configured, if launch an application that configure the registers, after
the end of your application, the registers keep their configuration value.
Then, if you start another application that use the serial port without
configure these registers, it will work.
For you second problem, I would need your source code to understand what is
wrong. But I don't believe to have time to have a look on it before next
week.
domodom

selva
ok domdom,

Thanks for ur reply.......if u have time pls tell me. i will provide my
source code thanks for ur reply.

selva
Hi domdom,

         pls help domdom sorry to disturb u one small problem pls help me

domdom silly thing for u'


while(1)
{
m_time = CTime::GetCurrentTime();
}

and iam using this function to get time and display it in timer picker
control....

when iam using an infinite loop like above its not working..

while(1)
{
m_time = CTime::GetCurrentTime();
break;
}

but if i use break after it ,it is working fine

how can i make it to work in infinite loop help pls domdom

selva
sorry up:)


see the above topic pls help domdom.....

Fernando
Selva, do not get angry with what I'm going to say, but there is no need to
insist in this way in the forum ... it's a little annoying for the rest.
when someone, domodom or some other person, can will answer to your doubts.
Regards, and good luck with your project.

Fernando

selva
thanks fernando,
                u are right but domdom is the only person right now helping
me.so i did like that.sorry fernando i won't repeat it.

thanks for ur care.........

selva
hi fernando,

       i think u also working with serial port.if u are having any problem
with serial i can help u ....

Fernando
Thanks selva, and I'm glad you didn't get angry with my comments.
Yes, I'm working with the serial port, but no problem with it, I am
handling it ok. Thanks anyway for your consideration.

Sadly I cant help you much with your needs, because I never used Visual C,
only C for DOS or microcontrollers... someday I hope I can learn Visual C
(just need time + good tutorial), because I know is a lot much powerfull
than Visual Basic. But for the moment.. I'm sticking to what I'm used to :)

Fernando

jhonny
Hello.
How do i found the pkfuncs.h?, 
I have not been able to find it, appreciate if someone help me find it.
My mail is albusve@hotmail.com.