I know this subject has been beaten to death but I can't seem to get it to go on my system. I have reviewed all of the past messages on the subject including the "buzz" examples and after several days I am turning to you folks for help. Here is a synopsis of the shared memory important stuff. The rtl_servo.c compiles to a module and runs the servo board fine. The main.c file does however throw a warning that the argument for the munmap() call is of an incorrect pointer type. Maybe this is the source of my problem, maybe not. Any suggestions? See the attached code Garth Gaddy
//sram.h SHARED MEMORY HEADER FILE #define SRAM_BASE ((63 * 0x100000)) typedef struct { unsigned char inuse; int arg1; int arg2; }SRAM_CMD; typedef struct { unsigned char inuse; int stat1; int stat2; }SRAM_STAT; typedef struct { SRAM_CMD command; SRAM_STAT status; }SRAM_ACCESS; //rtl_servo.h RTLINUX MODULE HEADER FILE extern void * vremap (unsigned long offset, unsigned long size); extern void vfree (void * addr); SRAM_ACCESS *rt_ptr; //rt_Linux side access //rtl_servo.c RTLINUX MODULE CODE #include "sram.h" int init_module(void) { rt_ptr = (SRAM_ACCESS *)vremap(SRAM_BASE, sizeof(SRAM_ACCESS)); //snip.....other init stuff....... return 0; } void cleanup_module(void) { //snip.... .other cleanup stuff..... vfree(rt_ptr); } void tsk_servo_pid(int bogus) //servo pid task { while (1) { sramCntr++; if(0 == rt_ptr->status.inuse) //if sram not is use, set data values { rt_ptr->status.stat1 = junk; rt_ptr->status.stat2 = sramCntr; } if(0 == rt_ptr->command.inuse) { junk = rt_ptr->command.arg1; } //snip ....... servo pid stuff } } //main.h USER SIDE LINUX MAIN PROGRAM HEADER FILE SRAM_ACCESS *alloc_sram(void); void free_sram (SRAM_ACCESS *); int help_menu(void); //main.c USER SIDE LINUX MAIN PROGRAM #include "sram.h" int main() { short c; SRAM_ACCESS *u_ptr; SRAM_ACCESS local; u_ptr = alloc_sram(); help_menu(); do { c = getchar(); putchar('\n'); switch(c) { case '1': u_ptr->status.inuse = 1; memcpy(&local, u_ptr, sizeof(SRAM_ACCESS)); u_ptr->status.inuse = 0; printf("Command Verify = %d\n", local.status.stat1); break; case '2': u_ptr->status.inuse = 1; memcpy(&local, u_ptr, sizeof(SRAM_ACCESS)); u_ptr->status.inuse = 0; printf("SRAM Counter = %d\n", local.status.stat2); break; case '3': local.command.arg1 = 1234; u_ptr->command.inuse = 1; memcpy(u_ptr, &local, sizeof(SRAM_ACCESS)); u_ptr->command.inuse = 0; printf("Command sent = %d\n", local.command.arg1); break; case 'q': break; default: printf("Enter Command for Shared Memory Test : "); } } while (c != 'q'); free_sram(u_ptr); return 0; } int help_menu(void) { printf("Commands:\n"); printf(" 1 - 1st arg in shared ram\n"); printf(" 2 - 2nd arg in shared ram\n"); printf(" 3 - Send Command to RT side\n"); printf(" q - Quit\n"); printf("Enter Command for Shared Memory Test : "); return(0); } SRAM_ACCESS *alloc_sram() { SRAM_ACCESS *u_ptr; int memd; if ( (memd=open("/dev/mem" , O_RDWR)) < 0 ) { printf("\nShared memory not opened\n"); return NULL; } u_ptr = (SRAM_ACCESS *) mmap(0, sizeof(SRAM_ACCESS), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, memd, SRAM_BASE); printf("\nShared memory setup up, pointer = %10d\n", u_ptr); if (MAP_FAILED == u_ptr) return NULL; close(memd); return u_ptr; } void free_sram (SRAM_ACCESS *user_ptr) { munmap(user_ptr, sizeof(SRAM_ACCESS)); }