I am far from an expert on the emc stuff, but basically the shared memory is a method of passing data from userspace to realtime.

The memory is allocated to the size of a specific structure, (say emcmot_struct_t) then pointers are allocated to elements within the structure.

These pointers are then used to pass and access the values.

As for the specific connection, motion.c creates the structure for realtime functions.
usmotintf.cc, does not create a different structure, it you look it gets the emcmot SHMEM_KEY (line 64) of the realtime structure and uses that to create its local version (line 690)

This is cutting edge MIT 1980s coding, only the sheer complexity of replacing it has prevented simpler and more efficient code.

That and the fact that it works, so don't fix it :)


Search the pointers created, for instance emcmotCommand, and you will find it accessed by taskintf.cc and command.c
On 09/01/18 03:46, [email protected] wrote:
Hi everyone,

  I found that two blocks of share memory of emcmot_struct_t has been created, but how does they get associated?

usrmotintf.cc
int usrmotInit(const char *modname)
{
int retval;

module_id = rtapi_init(modname);
if (module_id < 0) {
    fprintf(stderr,
     "usrmotintf: ERROR: rtapi init failed\n");
    return -1;
}
/* get shared memory block from RTAPI */
shmem_id = rtapi_shmem_new(SHMEM_KEY, module_id, sizeof(emcmot_struct_t));
if (shmem_id < 0) {
    fprintf(stderr,
     "usrmotintf: ERROR: could not open shared memory\n");
    rtapi_exit(module_id);
    return -1;
}
/* get address of shared memory area */
retval = rtapi_shmem_getptr(shmem_id, (void **) &emcmotStruct);
if (retval < 0) {
    rtapi_print_msg(RTAPI_MSG_ERR,
     "usrmotintf: ERROR: could not access shared memory\n");
    rtapi_exit(module_id);
    return -1;
}

motion.c
static int init_comm_buffers(void)
{
int joint_num, axis_num, n;
emcmot_joint_t *joint;
int retval;

rtapi_print_msg(RTAPI_MSG_INFO, "MOTION: init_comm_buffers() starting...\n");

emcmotStruct = 0;
emcmotDebug = 0;
emcmotStatus = 0;
emcmotCommand = 0;
emcmotConfig = 0;

/* allocate and initialize the shared memory structure */
emc_shmem_id = rtapi_shmem_new(key, mot_comp_id, sizeof(emcmot_struct_t));
if (emc_shmem_id < 0) {
    rtapi_print_msg(RTAPI_MSG_ERR,
     "MOTION: rtapi_shmem_new failed, returned %d\n", emc_shmem_id);
    return -1;
}
retval = rtapi_shmem_getptr(emc_shmem_id, (void **) &emcmotStruct);
if (retval < 0) {
    rtapi_print_msg(RTAPI_MSG_ERR,
     "MOTION: rtapi_shmem_getptr failed, returned %d\n", retval);
    return -1;
}
--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Visit this group at https://groups.google.com/group/machinekit.
For more options, visit https://groups.google.com/d/optout.

--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Visit this group at https://groups.google.com/group/machinekit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to