/** * Returns a handler for the parameter with name "name". * This handler is then used by the functions oesr_var_param_value() and oesr_var_param_type() * * \param context OESR context pointer * \param name Name of the parameter, as it appears in the waveform .app file * \return On success, returns a non-null handler. On error returns null. */ var_t oesr_var_param_get(void *context, char *name) { cast_p(ctx,context); OESR_ASSERT_PARAM_P(name); sdebug("name=%s\n",name); nod_module_t *module = (nod_module_t*) ctx->module; variable_t *variable = nod_module_variable_get(module,name); if (!variable) { OESR_SETERROR(OESR_ERROR_NOTFOUND); return NULL; } return (var_t) variable; }
/** * It creates a new log for the module. The returned handler (if non-null) * is then passed as the first parameter to the functions oesr_log_write() or oesr_log_printf(). * \param context OESR context pointer * \param name Name of the log to create * \returns NULL on error or non-null on success. */ log_t oesr_log_create(void *context, char *name) { sdebug("context=0x%x, name=%s\n",context,name); cast_p(ctx,context); OESR_ASSERT_PARAM_P(name); int i; i=0; while(i<MAX(oesr_log) && ctx->logs[i].id) i++; if (i==MAX(oesr_log)) { OESR_SETERROR(OESR_ERROR_NOSPACE); return NULL; } if (oesr_log_init(ctx, &ctx->logs[i], name)) { return NULL; } ctx->logs[i].id = i+1; return (log_t) &ctx->logs[i]; }
/** * * oesr_counter_create() creates a new counter. It returns a handler that is then used by the * counter functions to manage it. * * \param context OESR context pointer * \param name Name associated to the public variable * \returns On success, returns a non-null counter_t object. On error returns null. */ counter_t oesr_counter_create(void *context, char *name) { sdebug("context=0x%x, name=%s\n",context,name); cast_p(ctx,context); OESR_ASSERT_PARAM_P(name); int i; i=0; while(i<MAX(oesr_counter) && ctx->counters[i].id) i++; if (i==MAX(oesr_counter)) { OESR_SETERROR(OESR_ERROR_NOSPACE); return NULL; } sdebug("counter_pos=%d\n",i); if (oesr_counter_init(ctx, &ctx->counters[i],name)) { return NULL; } else { ctx->counters[i].id = i+1; return (counter_t) &ctx->counters[i]; } }
/** * * The oesr_itf_create() function initializes the interface with the rtdal. A pair of * transmitter/receiver modules use the same rtdal interface to communicate each other. This interface * is created by the transmitter. The receiver then attaches to the same interface. Since the * order of creation is unknown, the interface might not yet be created by the transmitter. In this * case, the oesr_error_code is set to OESR_ERROR_NOTREADY and the transmitter may try to call * again the oesr_itf_create() function in the next timeslot. * * \param context Pointer to the oesr context * \param port_idx Interface local port number * \param mode READ or WRITE * \param size Maximum size of the packets that can be transmitted through the interface (used only * by the transmitter side) * * \return Non-null handler on success or null on error. * */ itf_t oesr_itf_create(void *context, int port_idx, oesr_itf_mode_t mode, int size) { oesr_context_t *ctx = context; nod_module_t *module = ctx->module; sdebug("context=0x%x, module_id=%d, port_idx=%d, mode=%d, size=%d inputs=%d outputs=%d\n",context,module->parent.id, port_idx, mode, size,module->parent.nof_inputs,module->parent.nof_outputs); r_itf_t rtdal_itf; interface_t *nod_itf = NULL; OESR_ASSERT_PARAM_P(module); OESR_ASSERT_PARAM_P(port_idx>=0); if (mode == ITF_WRITE) { if (port_idx >= module->parent.nof_outputs) { OESR_SETERROR(OESR_ERROR_NOTFOUND); return NULL; } nod_itf = &module->parent.outputs[port_idx]; } else { if (port_idx >= module->parent.nof_inputs) { OESR_SETERROR(OESR_ERROR_NOTFOUND); return NULL; } nod_itf = &module->parent.inputs[port_idx]; } if (nod_itf->physic_itf_id != 0) { /* is external */ rtdal_itf = (r_itf_t) rtdal_itfphysic_get_id(nod_itf->physic_itf_id); if (!rtdal_itf) { OESR_HWERROR("rtdal_itf_physic_get_id"); } } else { /* is internal */ if (mode == ITF_WRITE) { rtdal_itf = (r_itf_t) rtdal_itfspscq_new(OESR_ITF_DEFAULT_MSG, size); if (!rtdal_itf) { OESR_HWERROR("rtdal_itfqueue"); return NULL; } } else { sdebug("remote_id=%d, remote_idx=%d\n",nod_itf->remote_module_id, nod_itf->remote_port_idx); nod_waveform_t *waveform = module->parent.waveform; nod_module_t *remote = nod_waveform_find_module_id(waveform, nod_itf->remote_module_id); if (!remote) { OESR_SETERROR(OESR_ERROR_MODNOTFOUND); return NULL; } sdebug("remote found\n",0); if (nod_itf->remote_port_idx > remote->parent.nof_outputs) { OESR_SETERROR(OESR_ERROR_NOTFOUND); return NULL; } sdebug("valid\n",0); rtdal_itf = remote->parent.outputs[nod_itf->remote_port_idx].hw_itf; if (!rtdal_itf) { OESR_SETERROR(OESR_ERROR_NOTREADY); return NULL; } } } nod_itf->hw_itf = rtdal_itf; sdebug("module_id=%d hitf=0x%x\n",module->parent.id,rtdal_itf); return (itf_t) nod_itf; }