Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: how to program and ran PCK0 on at91
PostPosted: Tue Apr 10, 2012 11:26 am 
Offline

Joined: Mon Apr 09, 2012 10:27 am
Posts: 3
Hi , I know that was a similar topic but I need much more help so please be forgiving. I will add that I am unfortunately a beginner in the topic. I use the following set with ARM9 : http://www.propox.com/products/t_232.html?lang=en . Module is delivered with system Linux which is based on OpenWrt distribution. I need to build a measurement module, and most of the sensors are operating properly. I have a problem with one sensor, it needs get signal 32kHz . On my set is out (PB30) Programmable Clock Register 0, from what I see from the data sheet must enter a value of 0x0 to the registry PMC_PCK0. Next you need to set the PMC_SCRER and it should work? Here is the problem, do not know how to go about it ... you can probably set up registry from the console of Linux or the programs in C but I do not know how...Maybe someone could write me a C Program that runs the clock, I'll be very grateful. To compile I use arm-linux-gcc-4.1.2


Top
 Profile  
 
 Post subject: Re: how to program and ran PCK0 on at91
PostPosted: Tue Apr 10, 2012 7:39 pm 
Offline

Joined: Mon Apr 09, 2012 10:27 am
Posts: 3
I found something like this :

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux2/i2c-dev.h>
#include <AT91SAM9260.h>

int main()
{

unsigned int pck = 1;
unsigned int mode = AT91C_PMC_CSS_SLOW_CLK | AT91C_PMC_PRES_CLK;

AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK1;
AT91C_BASE_PMC->PMC_IDR = AT91C_PMC_PCK1;
AT91C_BASE_PMC->PMC_PCKR[pck] = mode; //set pclk mode
AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_PCK1; //enable pclk clock

while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_PCK1RDY));

AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK1;


}

but when I ran this I got : Segmentation fault

Some advice ?


Top
 Profile  
 
 Post subject: Re: how to program and ran PCK0 on at91
PostPosted: Wed Apr 11, 2012 2:07 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 784
The problem here is that Linux user space will not let you touch the peripheral registers directly, you would need to mmap() a region.

Generally it would be better to place code like this in a driver, or board specific initialization.

Another place to configure hardware is in the AT91BootStrap code, where you can touch hardware in this fashion.


Top
 Profile  
 
 Post subject: Re: how to program and ran PCK0 on at91
PostPosted: Fri Apr 13, 2012 12:31 pm 
Offline

Joined: Mon Apr 09, 2012 10:27 am
Posts: 3
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <linux2/i2c-dev.h>
#include <AT91SAM9260.h>
#include <sys/mman.h>




#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE -1)


int main()
{

int fd;
void *base;
FILE *outfile;
unsigned int pck = 1;
unsigned int mode = AT91C_PMC_CSS_SLOW_CLK | AT91C_PMC_PRES_CLK;

if((fd = open ("/dev/mem", O_RDWR | O_SYNC)) ==-1)
{

printf("NOT OK");
return -1;
}
printf("OK");

if((base =mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE,MAP_SHARED,fd,(long int)AT91C_BASE_PMC & ~MAP_MASK)) == (void *)-1)
{
printf("NOT OK");
return -1;
}

printf("OK");

*(unsigned long int *)(base + 40) = AT91C_PMC_PRES_CLK_16 | AT91C_PMC_CSS_MAIN_CLK;
*(unsigned long int *)(base + 0) = AT91C_PMC_PCK0; //enable pclk clock

while(! ( (*(unsigned long int *) (base + 68)) & AT91C_PMC_PCK0RDY) );


//*(unsigned int *)(base + 4) = AT91C_PMC_PCK1;
//*(unsigned int *)(base + 64) = AT91C_PMC_PCK1;
//*(unsigned int *)(base + 40) = mode; //set pclk mode
//*(unsigned int *)(base + 0) = AT91C_PMC_PCK1; //enable pclk clock

// while(! ( *(unsigned int *) ((base + 68)) & AT91C_PMC_PCK1RDY));


printf("end");
}

it is ok ? What is wrong with this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: