11.02.09

New Job

Publicado en Amigos a 5:27 pm por Arturo Plauchu

Hi, I was in transactional state, I changed my job and now the new challenges are in the Air (as Love’s in the Air song). I hope I will be fine in my new job at Sasken. Good Luck Chu!! and See you later alligators!!

09.11.09

Shared memory in QNX

Publicado en Amigos a 10:28 am por Arturo Plauchu

Hi everybody!! I give you an example how to use shared memory in QNX using mmap.

First we are going to set our data structure.


#include stdio.h
#include string.h
#include fcntl.h
#include errno.h
#include stdlib.h
#include unistd.h
#include limits.h
#include sys/mman.h

typedef struct{
int a;
int b;
}s_t;

int main( int argc, char** argv )
{
int fd;
s_t *addr;

addr = calloc(2, sizeof(s_t));

fd = shm_open( "/mi_memoria", O_RDWR | O_CREAT, 0777 );
if( fd == -1 ) {
fprintf( stderr, "Open failed:%s\n", strerror( errno ) );
return EXIT_FAILURE;
}

if( ftruncate( fd, (size_t)(sizeof( addr )*2) ) == -1 ) {
fprintf( stderr, "ftruncate: %s\n", strerror( errno ) );
return EXIT_FAILURE;
}

addr = mmap( 0, (size_t)(sizeof( addr )*2) , PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
if( addr == MAP_FAILED ) {
fprintf( stderr, "mmap failed: %s\n", strerror( errno ) );
return EXIT_FAILURE;
}

printf( "Map addr is 0x%08x\n", addr );

addr[0].a = 1;
addr[0].b = 2;
addr[1].a = 3;
addr[1].b = 4;

close( fd );

return EXIT_SUCCESS;
}

So…. we are going to read or write our shared memory with the same code minus the O_CREAT FLAG at open the file descriptor with the memry path :D


#include
#include stdio.h
#include string.h
#include fcntl.h
#include errno.h
#include stdlib.h
#include unistd.h
#include limits.h
#include sys/mman.h

typedef struct{
int a;
int b;
}s_t;

int main( int argc, char** argv )
{
int fd;
s_t *addr = NULL;

addr = calloc(2, sizeof(s_t));

fd = shm_open( "/mi_memoria", O_RDWR, 0777 );
if( fd == -1 ) {
fprintf( stderr, "Open failed:%s\n", strerror( errno ) );
return EXIT_FAILURE;
}

if( ftruncate( fd, (size_t)(sizeof( addr )*2) ) == -1 ) {
fprintf( stderr, "ftruncate: %s\n", strerror( errno ) );
return EXIT_FAILURE;
}

addr = mmap( 0, (size_t)(sizeof( addr )*2) , PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
if( addr == MAP_FAILED ) {
fprintf( stderr, "mmap failed: %s\n", strerror( errno ) );
return EXIT_FAILURE;
}

while(addr->a != NULL){
printf( "Map addr is 0x%08x\n", addr );
printf( "Map value a %d \n", addr->a );
printf( "Map value b %d \n", addr->b );
addr++;
}

close( fd );

return EXIT_SUCCESS;
}

And wala!!!!!! This code can save you a redundant data storage or I don’t know that you have to know what jejeje. Bye!

07.29.09

OCB and Resource Managers

Publicado en Ciencia a 4:20 pm por Arturo Plauchu

I registered my device names /dev/plc and /dev/plc/0-20. Now I’m using the OCB… the second would drive the first 20 bytes in data (for example).

well… Where is the data struct who give me the name for the device (in a string or an unique id) that call the io_write o io_read function?.

I saw some structures and I didn’t see any member as a (char *) with the name as I wrote in the resmgr_attach() function.

The io_read/io_write function parameters are a IOFUNC_OCB_T pointer, a resmgr_context_t pointer and io_write_t or io_read_t pointer.

Is that information in a special structure?

I need that information to my io_read/io_write functions who call the driver functions. So… I’ll seek only the registers who i want.

Sorry my english. :) . See you later alligators!

Resource Manager, POSIX API

Publicado en Ciencia a 4:06 pm por Arturo Plauchu

My idea was a POSIX development, thats is the reason that I want develop the RM. The communication would be via tcp/ip (serial in a future). Of course that I was thinking in a just a process but the POSIX is rounding at my mind jaja.

the first question about the RM woulb be…

How do I do to attach the device name?… well the doumentation have that with examples. But..

How do I do to attach a sector device name?… for example if I want to read a address N40:1/10 (a bit) in /dev/myplc/N40/1/10 (with a cat command). am I crazy? Is this possible?… The documentation have something called OCB but it’s not clear to me…yet Smile.

Thanks all, and good luck.

Siguiente página