On Mon, Jan 24, 2011 at 11:12 PM, Gilles Chanteperdrix < [email protected]> wrote:
> at91_enthus wrote: > > On Mon, Jan 24, 2011 at 11:02 PM, Gilles Chanteperdrix < > > [email protected]> wrote: > > > >> at91_enthus wrote: > >>> On Mon, Jan 24, 2011 at 10:54 PM, Gilles Chanteperdrix < > >>> [email protected]> wrote: > >>> > >>>> at91_enthus wrote: > >>>>> On Mon, Jan 24, 2011 at 10:28 PM, Gilles Chanteperdrix < > >>>>> [email protected]> wrote: > >>>>> > >>>>>> at91_enthus wrote: > >>>>>>> On Mon, Jan 24, 2011 at 10:16 PM, Gilles Chanteperdrix < > >>>>>>> [email protected]> wrote: > >>>>>>> > >>>>>>>> at91_enthus wrote: > >>>>>>>>> On Mon, Jan 24, 2011 at 9:25 PM, Gilles Chanteperdrix < > >>>>>>>>> [email protected]> wrote: > >>>>>>>>> > >>>>>>>>>> at91_enthus wrote: > >>>>>>>>>>> On Mon, Jan 24, 2011 at 8:41 PM, Gilles Chanteperdrix < > >>>>>>>>>>> [email protected]> wrote: > >>>>>>>>>>> > >>>>>>>>>>>> at91_enthus wrote: > >>>>>>>>>>>>> Hi. > >>>>>>>>>>>>> > >>>>>>>>>>>>> I was testing Xenomai on my AT91SAM9G20-based board and > tried > >> to > >>>>>>>> adapt > >>>>>>>>>>>> the > >>>>>>>>>>>>> code found here: > >>>>>>>>>>>>> > >>>> http://www.armadeus.com/wiki/index.php?title=Xenomai:Blinking_LEDs. > >>>>>>>>>>>> By the way, this code is ridiculous. It creates a real-time > task > >>>> to > >>>>>>>>>>>> write to some non real-time device, which makes the real-time > >> task > >>>>>>>>>> useless. > >>>>>>>>>>> I know. > >>>>>>>>>> Yes, but this example is bad in many ways: > >>>>>>>>>> - first it uses xenomai api to create a real-time task, and uses > >>>> write > >>>>>>>>>> which causes the real-time task to switch to secondary domain; > >>>>>>>>>> - the Makefile does not use xeno-config, which have been the > >>>>>> recommended > >>>>>>>>>> way of getting the compiler flags since day 1; > >>>>>>>>>> - it nullifies SIGTERM and SIGINT, which is a dubious decision, > >> and > >>>>>>>>>> could lead people to believe that they should do the same when > >> using > >>>>>>>>>> Xenomai, whereas there is no such requirement. > >>>>>>>>>> - the pointers point to outdated version of the documentation. > >>>>>>>>>> - it uses runinfo/xeno-load, which are kind of outdated too, > make > >>>>>> things > >>>>>>>>>> uselessly complicated, and in any case, tell you to type Ctrl-C > to > >>>>>>>>>> interrupt the program, which is bound to fail if anything goes > >>>> wrong, > >>>>>>>>>> since SIGINT is neutralized in the program. > >>>>>>>>>> > >>>>>>>>>>> That's why I went to mmap(). > >>>>>>>>>> That is not really the right solution either. I admit that for > >>>> driving > >>>>>>>>>> leds, it may be a bit overkill, but anyway, what you should do > is > >>>>>> write > >>>>>>>>>> an RTDM driver for driving the leds. Keeping the driver > separated > >>>> from > >>>>>>>>>> the application will allow the same program to run on other > >>>> platforms > >>>>>>>>>> where driving the LEDS is done differently without changing much > >> of > >>>>>> the > >>>>>>>>>> application code. In other word, the application/driver > separation > >>>> is > >>>>>> a > >>>>>>>>>> sane one. > >>>>>>>>>> > >>>>>>>>>> Anyway, mmap should work. > >>>>>>>>>> > >>>>>>>>>> (I chose that sample code because, for > >>>>>>>>>>> now, I am only learning to use basic functions) > >>>>>>>>>>>> Wrong test here. Should be "if (aic_base == MAP_FAILED)" > >>>>>>>>>>> Indeed, my program fails miserably when I check the mapping of > >> AIC, > >>>>>> not > >>>>>>>>>>> PIOB's. And yet, I just can't figure why in the non-Xenomai > code, > >>>> AIC > >>>>>>>>>>> mmap-ing works fine. > >>>>>>>>>> Well errno might give you a clue. Do you have FCSE enabled? > >>>>>>>>>> > >>>>>>>>>> Regards. > >>>>>>>>>> > >>>>>>>>>> -- > >>>>>>>>>> > >>>>>> Gilles. > >>>>>>>>> FCSE is enabled. errno returns 22 (invalid argument). > >>>>>>>> best effort or guaranteed? > >>>>>>> Best effort > >>>>>>> > >>>>>>> > >>>>>>>> Please activate FCSE messages. > >>>>>>> ... compiling new kernel > >>>>>>> > >>>>>>> > >>>>>>>> How big is > >>>>>>>> MAP_SIZE? > >>>>>>>> > >>>>>>>> > >>>>>>> 4096 > >>>>>> Ok. Could you post your full kernel configuration, as well as the > full > >>>>>> program? > >>>>>> > >>>>> I put the .config and the code in the attachments. > >>>> If you remove all the native skin stuff, only keep main and > >>>> open_controller, do not link with the native library, you can confirm > >>>> that this same program runs without trouble? > >>>> > >>> Without Xenomai related stuff, it runs OK. > >> You sure of that? The exact same code, with the same kernel, with the > >> mlockall? > >> > >> -- > >> Gilles. > >> > > > > Oh. I assumed without mlockall (it wasn't part of my original code). > > Now, I placed mlockall in my original code (right before > open_controller()) > > and the pin gets toggled according to my scope. > > Ok. Show me the Makefile then. And the code which works. see attachment > Including the > value of the defines please (not all of them, only those the program > uses for open_controller). > > > #define AT91C_BASE_AIC 0xFFFFF000 // (AIC) Base Address #define AT91C_BASE_PIOB 0xFFFFF600 // (PIOB) Base Address #define PIO_PER 0x00000000 // (PIO_PER) PIO Enable Register #define PIO_PDR 0x00000004 // (PIO_PDR) PIO Disable Register #define PIO_PSR 0x00000008 // (PIO_PSR) PIO Status Register #define PIO_OER 0x00000010 // (PIO_OER) Output Enable Register #define PIO_SODR 0x00000030 // (PIO_SODR) Set Output Data Register #define PIO_CODR 0x00000034 // (PIO_CODR) Clear Output Data Register #define PIO_PPUDR 0x00000060 // (PIO_PPUDR) Pull-up Disable Register #define PIO_MDDR 0x00000054 // (PIO_MDDR) Multi-driver Disable Register
/* user-land driver for PIOB (bit 0 - J2)
Board: Electrum100 - Micromint, AT91SAM9G20
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "definitions.h"
#define MAP_SIZE 4096UL //4k
#define MAP_MASK (MAP_SIZE - 1)
int fd, i;
unsigned char *piob_base, *aic_base;
void open_controller(){
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
{
printf("Couldn't open /dev/mem. error %s\n", strerror(errno));
exit(1);
}
printf("/dev/mem opened.\n");
fflush(stdout);
/* mapping of PIOB */
aic_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, AT91C_BASE_PIOB & ~MAP_MASK);
piob_base = aic_base + AT91C_BASE_PIOB - AT91C_BASE_AIC;
if( (aic_base == MAP_FAILED)) {
printf("Couldn't get Map-Address. %d\n", errno);
exit(1);
}
fflush(stdout);
}
int main() {
mlockall(MCL_CURRENT|MCL_FUTURE);
open_controller();
*((unsigned int *) (piob_base + PIO_IDR)) = 1<<0;
*((unsigned int *) (piob_base + PIO_PER)) = 1<<0;
*((unsigned int *) (piob_base + PIO_CODR)) =1<<0;
*((unsigned int *) (piob_base + PIO_PPUDR)) =1<<0;
*((unsigned int *) (piob_base + PIO_OER)) = 1<<0;
*((unsigned int *) (piob_base + PIO_MDDR)) = 1<<0;
while(1){
*((unsigned int *) (piob_base + PIO_SODR)) = 1<<0;
*((unsigned int *) (piob_base + PIO_CODR)) = 1<<0;
}
close(fd);
return 0;
}
Makefile
Description: Binary data
_______________________________________________ Xenomai-help mailing list [email protected] https://mail.gna.org/listinfo/xenomai-help
