static eOresult_t s_eo_appTheNVmapRef_tables_create(EOappTheNVmapRef* p, eOappTheNVmapRef_cfg_t *cfg)
{

    uint8_t         i;

//joint    
    p->jointMaxNumber = eo_appTheDB_GetNumeberOfConnectedJoints(eo_appTheDB_GetHandle);

    p->jointsList = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(void**), 
                                         p->jointMaxNumber);
      
    for(i = 0; i<p->jointMaxNumber; i++)
    {
        p->jointsList[i] = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, 
                                                sizeof(void*), eOappNVmapRef_jointNVindex_TOTALnumber);    
    }
    
//motor
    p->motortMaxNumber = eo_cfg_nvsEP_mc_motor_numbermax_Get((eOcfg_nvsEP_mc_endpoint_t)p->cfg.mc_endpoint);

    p->motorsList = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(void**), 
                                         p->motorMaxNumber);
      
    for(i = 0; i<p->motortMaxNumber; i++)
    {
        p->motortsList[i] = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, 
                                                sizeof(void*), eOappNVmapRef_motorNVindex_TOTALnumber);    
    }
    
    
    return(eores_OK);

}
extern EOmotors* eo_motors_New(uint8_t nMotors, eOemscontroller_board_t board) 
{
    if (!nMotors) return NULL;
    if (nMotors > MAX_NAXLES) nMotors = MAX_NAXLES;
    
    EOmotors *o = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOmotors), 1);

    if (o)
    {
        o->board = board;
        o->nMotors = nMotors;
        o->Jok = eobool_false;
        
        MOTORS(m)
        {
            o->motor_state_watchdog[m] = 0;
            o->motor_fault_mask2[m] = 0;

            JOINTS(j)
            {
                o->J[m][j] = o->Ji[m][j] = 0;
            }
        }
    }

    return o;
}
Beispiel #3
0
extern EOconfirmationManager* eo_confman_New(const eOconfman_cfg_t *cfg)
{
    EOconfirmationManager *retptr = NULL;   

    if(NULL == cfg)
    {    
        cfg = &eOconfman_cfg_default;
    }
    
    if(eoconfman_mode_disabled == cfg->mode)
    {
        return(NULL);
    }
    
    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOconfirmationManager), 1);
    
    memcpy(&retptr->config, cfg, sizeof(eOconfman_cfg_t));
    
    retptr->confrequests = (0 == cfg->maxnumberofconfreqrops) ? (NULL) : (eo_vector_New(sizeof(eOropdescriptor_t), cfg->maxnumberofconfreqrops, NULL, 0, NULL, NULL));

    retptr->mtx = (NULL == cfg->mutex_fn_new) ? (NULL) : (cfg->mutex_fn_new());
    
    return(retptr);
}
extern EOabsCalibratedEncoder* eo_absCalibratedEncoder_New(uint8_t ID)
{
    EOabsCalibratedEncoder *o = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOabsCalibratedEncoder), 1);

    if (o)
    {        
        o->ID = ID;
        o->distance = 0;
        o->position_last = 0;
        o->position_sure = 0;
        
        #ifndef USE_2FOC_FAST_ENCODER
        o->velocity = 0;
        #endif
        
        o->offset = 0;
        o->sign = 0;
        
        o->delta = 0;
        
        o->invalid_fault_cnt = 0;
        o->timeout_fault_cnt = 0;
        o->first_valid_data = 0;
        
        o->state_mask = SM_NOT_READY;
    }

    return o;
}
Beispiel #5
0
extern EOrop* eo_rop_New(uint16_t capacity)
{
    EOrop *retptr = NULL;    

    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOrop), 1);

    retptr->stream.capacity = capacity;

    if(0 != capacity)
    {
        retptr->stream.data = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_08bit, sizeof(uint8_t), capacity);
    }

    eo_rop_Reset(retptr);
    
    return(retptr);
}
extern EOtransceiver* eo_transceiver_New(const eOtransceiver_cfg_t *cfg)
{
    EOtransceiver *retptr = NULL;  
    eo_receiver_cfg_t rec_cfg;
    eo_transmitter_cfg_t tra_cfg;


    if(NULL == cfg)
    {    
        cfg = &eo_transceiver_cfg_default;
    }
    
    memcpy(&rec_cfg, &eo_receiver_cfg_default, sizeof(eo_receiver_cfg_t));
    rec_cfg.capacityofropframereply         = cfg->capacityofropframereplies;
    rec_cfg.capacityofropinput              = cfg->capacityofrop;
    rec_cfg.capacityofropreply              = cfg->capacityofrop;
    rec_cfg.nvscfg                          = cfg->nvscfg;

    
    memcpy(&tra_cfg, &eo_transmitter_cfg_default, sizeof(eo_transmitter_cfg_t));
    tra_cfg.capacityoftxpacket              = cfg->capacityoftxpacket;
    tra_cfg.capacityofropframeregulars      = cfg->capacityofropframeregulars;
    tra_cfg.capacityofropframeoccasionals   = cfg->capacityofropframeoccasionals;
    tra_cfg.capacityofropframereplies       = cfg->capacityofropframereplies;
    tra_cfg.capacityofrop                   = cfg->capacityofrop;
    tra_cfg.maxnumberofregularrops          = cfg->maxnumberofregularrops;
    tra_cfg.ipv4addr                        = cfg->remipv4addr;     // it is the address of the remote host: we filter incoming packet with this address and sends packets only to it
    tra_cfg.ipv4port                        = cfg->remipv4port;     // it is the remote port where to send packets
    tra_cfg.nvscfg                          = cfg->nvscfg;
    tra_cfg.mutex_fn_new                    = cfg->mutex_fn_new;
    tra_cfg.protection                      = (eo_trans_protection_none == cfg->protection) ? (eo_transmitter_protection_none) : (eo_transmitter_protection_total);
    
    
    
    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOtransceiver), 1);
    
    
    memcpy(&retptr->cfg, cfg, sizeof(eOtransceiver_cfg_t)); 
    
    retptr->receiver = eo_receiver_New(&rec_cfg);
    
    retptr->transmitter = eo_transmitter_New(&tra_cfg);
    
#if defined(USE_DEBUG_EOTRANSCEIVER)    
    memset(&retptr->debug, 0, sizeof(EOtransceiverDEBUG_t));
#endif

//     if((eo_trans_protection_enabled == cfg->protection) && (NULL != cfg->mutex_fn_new))
//     {
//         retptr->mtx_tx_replies      = cfg->mutex_fn_new();
//         retptr->mtx_tx_regulars     = cfg->mutex_fn_new();
//         retptr->mtx_tx_occasionals  = cfg->mutex_fn_new();
//     }
    
    return(retptr);
}
extern EOfakeStorage* eo_fakestrg_New(uint32_t id, uint32_t capacity, const void *defvalue, EOVmutexDerived *mtx)
{
    EOfakeStorage *retptr = NULL;  
    eov_strg_memmap_t *strgmem = NULL;    

    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOfakeStorage), 1);

    eo_errman_Assert(eo_errman_GetHandle(), (0 != capacity), s_eobj_ownname, "capacity cannot be zero");

    // get the base object
    retptr->storage = eov_strg_hid_New(id, capacity, defvalue, mtx);
    
    // pass to it the virtual table
    
    eov_strg_hid_SetVTABLE(retptr->storage, 
                          (eOres_fp_voidp_uint32_uint32_cvoidp_t) s_eo_fakestrg_set, 
                          (eOres_fp_voidp_uint32_uint32_voidp_t) s_eo_fakestrg_get);


    // now initialise the derived object
    
    strgmem = s_eo_fakestrg_get_storagememory(retptr->storage);
    
    if((NULL == strgmem) || (id != strgmem->id))
    {
        // create new memory partition, mark it with id and capacity, set its content to defvalue
        
        strgmem = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(uint32_t) + sizeof(uint32_t) + capacity, 1);
        strgmem->id         = id;
        strgmem->capacity   = capacity;

        memcpy(strgmem->data, defvalue, strgmem->capacity);
    
    }
 
    // assign the partition to the object
    retptr->ram = (void*)strgmem;
 
    return(retptr);

}
Beispiel #8
0
extern EOnvSet* eo_nvset_New(eOnvset_protection_t prot, eov_mutex_fn_mutexderived_new mtxnew)
{
    EOnvSet *p = NULL;  

    // i get the memory for the object
    p = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(EOnvSet), 1);
    
    // i dont initialise yet the device. i simply rely on the fact that it contains all zero data.
    p->theboard.ipaddress       = 0;    
    p->mtxderived_new           = mtxnew; 
    p->protection               = (NULL == mtxnew) ? (eo_nvset_protection_none) : (prot); 

    return(p);
}
Beispiel #9
0
extern EOsm * eo_sm_New(const eOsm_cfg_t * cfg) 
{
    EOsm *retptr = NULL;
   
    // verify that we have a non NULL cfg
    eo_errman_Assert(eo_errman_GetHandle(), (NULL != cfg), "eo_sm_New(): NULL cfg", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);    

    // i get the memory for the object. no need to check versus NULL because the memory pool already does it
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOsm), 1);
    
    // now the obj has valid memory. i need to initialise it with other user-defined data, by means of cfg.
    s_eo_sm_Specialise(retptr, cfg);
    
    return(retptr);    
}
extern EOCurrentsWatchdog* eo_currents_watchdog_Initialise(void)
{
    uint8_t m;
    //reserve memory for the number of thresholds needed
    s_eo_currents_watchdog.numberofmotors = eo_entities_NumOfJoints(eo_entities_GetHandle());
    
    if (s_eo_currents_watchdog.numberofmotors == 0)
        return NULL;

    s_eo_currents_watchdog.themotors = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(eOmc_motor_t*), s_eo_currents_watchdog.numberofmotors);
    // retrieve pointers to motors   
    for(m=0; m<s_eo_currents_watchdog.numberofmotors; m++)
    {
        s_eo_currents_watchdog.themotors[m] = eoprot_entity_ramof_get(eoprot_board_localboard, eoprot_endpoint_motioncontrol, eoprot_entity_mc_motor, m);
    }
    
    
    s_eo_currents_watchdog.nominalCurrent2 = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.nominalCurrent2, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));
    
    s_eo_currents_watchdog.I2T_threshold = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.I2T_threshold, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));
    
    //s_eo_currents_watchdog.filter_reg = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    //memset(s_eo_currents_watchdog.filter_reg, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));
    
    s_eo_currents_watchdog.avgCurrent = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(eoCurrentWD_averageData_t), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.avgCurrent, 0, s_eo_currents_watchdog.numberofmotors*sizeof(eoCurrentWD_averageData_t));

    s_eo_currents_watchdog.accomulatorEp = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.accomulatorEp, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));

    s_eo_currents_watchdog.initted = eobool_true;
    
    return(&s_eo_currents_watchdog);
}
Beispiel #11
0
extern EOfifoWord* eo_fifoword_New(eOsizecntnr_t capacity, EOVmutexDerived *mutex) 
{
    EOfifoWord *retptr = NULL; 
    
    // i get memory for a fifoword. it can never be NULL 
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOfifoWord), 1);
   
    eo_errman_Assert(eo_errman_GetHandle(), (0 != capacity), "eo_fifoword_New(): 0 capacity", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);

    // now i create a mutexfifo made of word (no ctor or dtor!) and i fill it into the fifo of 
    // the fifoword. it can never be NULL 
    retptr->fifo = eo_fifo_New(4, capacity, NULL, 0, NULL, NULL, mutex);

    // ok, done
    return(retptr);
}
extern EOVmutex* eov_mutex_hid_New(void) 
{
	EOVmutex *retptr = NULL;	

	// i get the memory for the object
	retptr = (EOVmutex*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOVmutex), 1);

	// now the obj has valid memory. i need to initialise it with user-defined data
    
    // vtable
    retptr->vtable[VF00_take]           = NULL;
    retptr->vtable[VF01_release]        = NULL;
    retptr->vtable[VF02_delete]         = NULL;
    // other stuff


	return(retptr);	
}
extern EOYmutex* eoy_mutex_New(void) 
{
    EOYmutex *retptr = NULL;    

    // i get the memory for the yarp mutex object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOYmutex), 1);
    
    // i get the base mutex
    retptr->mutex = eov_mutex_hid_New();

    // init its vtable
    eov_mutex_hid_SetVTABLE(retptr->mutex, s_eoy_mutex_take, s_eoy_mutex_release, s_eoy_mutex_delete); 
    
    // i get a new yarp mutex
    retptr->acemutex = ace_mutex_new();

    // need to check because yarp may return NULL
    eo_errman_Assert(eo_errman_GetHandle(), (NULL != retptr->acemutex), s_eobj_ownname, "eoy_mutex_New(): ace cannot give a mutex", &eo_errman_DescrRuntimeErrorLocal);
    
    return(retptr);    
}
extern EOfifo * eo_fifo_New(eOsizeitem_t item_size, eOsizecntnr_t capacity,
                            eOres_fp_voidp_uint32_t item_init, uint32_t init_arg, 
                            eOres_fp_voidp_voidp_t item_copy, eOres_fp_voidp_t item_clear,
                            EOVmutexDerived *mutex) 
{
    EOfifo *retptr = NULL; 
    
    // i get memory for a mutexfifo. it will never be null
    retptr = (EOfifo*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOfifo), 1);

    eo_errman_Assert(eo_errman_GetHandle(), (0 != item_size), "eo_fifo_New(): 0 item_size", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);
    eo_errman_Assert(eo_errman_GetHandle(), (0 != capacity), "eo_fifo_New(): 0 capacity", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);
    
    // now i fill the mutexfifo with a deque 
    retptr->dek = eo_deque_New(item_size, capacity, item_init, init_arg, item_copy, item_clear);

    // now i copy the passed mutex into mutexfifo. beware for future use, ... it may be NULL
    retptr->mutex = mutex;
 
    // ok, done
    return(retptr);
}
extern EOconstLookupTbl * eo_constLookupTbl_New(eOsizecntnr_t capacity, uint16_t offset , eOres_fp_voidp_t exceptionMngFn, const void* itemsList)
{
    EOconstLookupTbl *retptr = NULL;
 
    if(NULL == itemsList)
    {
        return(retptr);
    }

    // i get the memory for the object. no need to check versus NULL because the memory pool already does it
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOconstLookupTbl), 1);


    // now the obj has valid memory. i need to initialise it with user-defined data,

    eo_errman_Assert(eo_errman_GetHandle(), (0 != capacity), s_eobj_ownname, "capacity is zero");

    retptr->capacity           = capacity;
    retptr->offset             = offset;
    retptr->exceptionMngFn     = exceptionMngFn;
    retptr->itemsList          = itemsList;     
    
    return(retptr);   
}
Beispiel #16
0
extern EOreceiver* eo_receiver_New(const eOreceiver_cfg_t *cfg)
{
    EOreceiver *retptr = NULL;   

    if(NULL == cfg)
    {    
        cfg = &eo_receiver_cfg_default;
    }
    
    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOreceiver), 1);
    retptr->ropframeinput       = eo_ropframe_New();
    retptr->ropframereply       = eo_ropframe_New();
    retptr->ropinput            = eo_rop_New(cfg->sizes.capacityofropinput);
    retptr->ropreply            = eo_rop_New(cfg->sizes.capacityofropreply);
    retptr->agent               = cfg->agent;
    retptr->ipv4addr            = 0;
    retptr->ipv4port            = 0;
    retptr->bufferropframereply = (0 == cfg->sizes.capacityofropframereply) ? (NULL) : (eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->sizes.capacityofropframereply, 1));
    retptr->rx_seqnum           = eok_uint64dummy;
    retptr->tx_ageofframe       = eok_uint64dummy;
    memset(&retptr->error_seqnumber, 0, sizeof(retptr->error_seqnumber));       // even if it is already zero.
    memset(&retptr->error_invalidframe, 0, sizeof(retptr->error_invalidframe)); // even if it is already zero. 
    retptr->on_error_seqnumber  = cfg->extfn.onerrorseqnumber;
    retptr->on_error_invalidframe = cfg->extfn.onerrorinvalidframe;
    // now we need to allocate the buffer for the ropframereply

#if defined(USE_DEBUG_EORECEIVER)    
    memset(&retptr->debug, 0, sizeof(EOreceiverDEBUG_t));
#endif  
    
    eo_ropframe_Load(retptr->ropframereply, retptr->bufferropframereply, eo_ropframe_sizeforZEROrops, cfg->sizes.capacityofropframereply);
    eo_ropframe_Clear(retptr->ropframereply);
    
    return(retptr);
}
extern EOCurrentsWatchdog* eo_currents_watchdog_Initialise(void)
{
    uint8_t m;
    //reserve memory for the number of thresholds needed
    s_eo_currents_watchdog.numberofmotors = eo_entities_NumOfMotors(eo_entities_GetHandle());
    
    if (s_eo_currents_watchdog.numberofmotors == 0)
        return NULL;

    s_eo_currents_watchdog.themotors = (eOmc_motor_t**) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(eOmc_motor_t*), s_eo_currents_watchdog.numberofmotors);
    // retrieve pointers to motors   
    for(m=0; m<s_eo_currents_watchdog.numberofmotors; m++)
    {
        s_eo_currents_watchdog.themotors[m] = eo_entities_GetMotor(eo_entities_GetHandle(), m);
    }
    
    
    s_eo_currents_watchdog.nominalCurrent2 = (float*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.nominalCurrent2, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));
    
    s_eo_currents_watchdog.I2T_threshold = (float*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.I2T_threshold, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));
    
    s_eo_currents_watchdog.avgCurrent = (eoCurrentWD_averageData_t*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(eoCurrentWD_averageData_t), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.avgCurrent, 0, s_eo_currents_watchdog.numberofmotors*sizeof(eoCurrentWD_averageData_t));

    s_eo_currents_watchdog.accomulatorEp = (float*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(float), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.accomulatorEp, 0, s_eo_currents_watchdog.numberofmotors*sizeof(float));
    
    s_eo_currents_watchdog.motorinI2Tfault = (eObool_t*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeof(eObool_t), s_eo_currents_watchdog.numberofmotors);
    memset(s_eo_currents_watchdog.motorinI2Tfault, 0, s_eo_currents_watchdog.numberofmotors*sizeof(eObool_t)); //all motors are not in I2t fault

    s_eo_currents_watchdog.initted = eobool_true;
    
    suppliedVoltage_counter = 0;
    nv_controller_ptr = (eOmc_controller_t*) eoprot_entity_ramof_get(eoprot_board_localboard, eoprot_endpoint_motioncontrol, eoprot_entity_mc_controller, 0);
    
    if(nv_controller_ptr == NULL)
        return NULL;
    
    
    return(&s_eo_currents_watchdog);
}
Beispiel #18
0
extern eOresult_t eo_nvset_LoadEP(EOnvSet* p, eOprot_EPcfg_t *cfgofep, eObool_t initNVs)
{
    eOnvset_brd_t* theBoard = NULL;
    eOnvBRD_t brd = 0;      // local or 0, 1, 2, etc.
    eOnvset_ep_t *theEndpoint = NULL;
    uint16_t epnvsnumberof = 0;  
    uint16_t sizeofram =0;
 
    if((NULL == p) || (NULL == cfgofep)) 
    {
        return(eores_NOK_nullpointer); 
    }
        
        
    theBoard = &p->theboard;
    brd = p->theboard.boardnum;
        
    theEndpoint = eo_mempool_New(eo_mempool_GetHandle(), 1*sizeof(eOnvset_ep_t));
    
    memcpy(&theEndpoint->epcfg, cfgofep, sizeof(eOprot_EPcfg_t));   
    
    // ok, now in theEndpoint->epcfg.numberofsentities[] we have some ram. we use it to load the protocol.
    eoprot_config_endpoint_entities(brd, theEndpoint->epcfg.endpoint, theEndpoint->epcfg.numberofentities);
    // now it is ok to compute the size of the endpoint using the proper protocol function
    sizeofram = eoprot_endpoint_sizeof_get(brd, theEndpoint->epcfg.endpoint); 
    
    // now that i have loaded  the number of entities i verify if they are ok by checking the number of variables in the endpoint.
    epnvsnumberof = eoprot_endpoint_numberofvariables_get(brd, cfgofep->endpoint);   
    if(0 == epnvsnumberof)
    {
        //#warning TBD: see how we continue in here ....
        char str[64] = {0};
        snprintf(str, sizeof(str), "EOnvSet: ep %d has 0 nvs", cfgofep->endpoint);  
        eo_errman_Error(eo_errman_GetHandle(), eo_errortype_error, str, NULL, &eo_errman_DescrRuntimeErrorLocal); 
        
        eoprot_config_endpoint_entities(brd, theEndpoint->epcfg.endpoint, NULL);
        eo_mempool_Delete(eo_mempool_GetHandle(), theEndpoint); 
        
        return(eores_NOK_generic); 
    }  
    
    theEndpoint->epnvsnumberof      = epnvsnumberof;
    theEndpoint->initted            = eobool_false;    
    theEndpoint->epram              = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_auto, sizeofram, 1);
    theEndpoint->mtx_endpoint       = (eo_nvset_protection_one_per_endpoint == p->protection) ? p->mtxderived_new() : NULL;
        
    // now we must load the ram in the endpoint
    eoprot_config_endpoint_ram(brd, theEndpoint->epcfg.endpoint, theEndpoint->epram, sizeofram);
    
    // now add the vector of mtx if needed.
    if(eo_nvset_protection_one_per_netvar == p->protection)
    {
        uint16_t i;
        theEndpoint->themtxofthenvs = eo_vector_New(sizeof(EOVmutexDerived*), epnvsnumberof, NULL, 0, NULL, NULL);
        for(i=0; i<epnvsnumberof; i++)
        {
            EOVmutexDerived* mtx = p->mtxderived_new();
            eo_vector_PushBack(theEndpoint->themtxofthenvs, &mtx);           
        }
    }
    
    // now, i must update the mapping function from ep value to vector of endpoints  
    theBoard->ep2indexlut[theEndpoint->epcfg.endpoint] = eo_vector_Size(theBoard->theendpoints);
    // and only now i push back the endpoint
    eo_vector_PushBack(theBoard->theendpoints, &theEndpoint);
    
    
    if(eobool_true == initNVs)
    {
        s_eo_nvset_NVsOfEP_Initialise(p, theEndpoint, theEndpoint->epcfg.endpoint); 
    }

    return(eores_OK);
}
Beispiel #19
0
static void s_eo_sm_Specialise(EOsm *p, const eOsm_cfg_t * c) 
{
 
    const eOsmTransition_t *tr = NULL;
    EOsmStateQuickInfo_t *st = NULL;
    uint8_t i = 0;
    
    
    // fill state machine object with user-define data structure.
    
    p->cfg = c;
    p->started = 0;  
    
    // activestate. 
    p->activestate = c->initstate;
    p->latestevent = eo_sm_evNONE;


    


    // statequickinfo: get memory. the memory is zero initialised. 
    // IMPORTANT: every evtmask must be zero.
    p->statequickinfo = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOsmStateQuickInfo_t), c->nstates);
    // also for transindices
    for(i=0; i<c->nstates; i++)
    {
        p->statequickinfo[i].evtmask = 0; // it is a redundant instruction.
        p->statequickinfo[i].transindices = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_08bit, 1, c->maxevts);
    }
    

    // we map the transitions in ram into the statequickinfo
    for(i=0; i<c->ntrans; i++)
    {
        tr = &c->transitions[i];
        // tr must point to a valid location .... we cannot do much to verify that. however, we verify its content.
        eo_errman_Assert(eo_errman_GetHandle(), 
                         (tr->curr < c->nstates) && (tr->next < c->nstates) && (tr->evt < c->maxevts), 
                         "s_eo_sm_Specialise(): wrong cfg", s_eobj_ownname, &eo_errman_DescrWrongParamLocal); 
        
        st = &p->statequickinfo[tr->curr];
        
        // the evtmask keeps a bit in pos j-th if the j-th event triggers a transition
        st->evtmask |= (0x00000001 << tr->evt);
        // the j-th event triggers transition number st->transindices[j] in cfg->transitions.
        st->transindices[tr->evt] = i; 
    }
    
    
    // ram
    p->ram = (0 == c->sizeofdynamicdata) ? (NULL) : (eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, c->sizeofdynamicdata, 1));
    
    // init
    if(NULL != p->cfg->init_fn) 
    {
        p->cfg->init_fn(p);
    }

    // reset
    eo_sm_Reset(p);
    
}
Beispiel #20
0
extern EOtransmitter* eo_transmitter_New(const eo_transmitter_cfg_t *cfg)
{
    EOtransmitter *retptr = NULL;   

    if(NULL == cfg)
    {    
        cfg = &eo_transmitter_cfg_default;
    }
    
    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOtransmitter), 1);
    
    retptr->txpacket                = eo_packet_New(cfg->capacityoftxpacket);
    retptr->ropframereadytotx       = eo_ropframe_New();
    retptr->ropframeregulars        = eo_ropframe_New();
    retptr->ropframeoccasionals     = eo_ropframe_New();
    retptr->ropframereplies         = eo_ropframe_New();
    retptr->roptmp                  = eo_rop_New(cfg->capacityofrop);
    retptr->nvscfg                  = cfg->nvscfg;
    retptr->theagent                = eo_agent_Initialise(NULL);
    retptr->ipv4addr                = cfg->ipv4addr;
    retptr->ipv4port                = cfg->ipv4port;
    retptr->bufferropframeregulars  = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->capacityofropframeregulars, 1);
    retptr->bufferropframeoccasionals = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->capacityofropframeoccasionals, 1);
    retptr->bufferropframereplies   = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->capacityofropframereplies, 1);
    retptr->listofregropinfo        = (0 == cfg->maxnumberofregularrops) ? (NULL) : (eo_list_New(sizeof(eo_transm_regrop_info_t), cfg->maxnumberofregularrops, NULL, 0, NULL, NULL));
    retptr->currenttime             = 0;
    retptr->tx_seqnum               = 0;

    eo_ropframe_Load(retptr->ropframeregulars, retptr->bufferropframeregulars, eo_ropframe_sizeforZEROrops, cfg->capacityofropframeregulars);
    eo_ropframe_Clear(retptr->ropframeregulars);
    eo_ropframe_Load(retptr->ropframeoccasionals, retptr->bufferropframeoccasionals, eo_ropframe_sizeforZEROrops, cfg->capacityofropframeoccasionals);
    eo_ropframe_Clear(retptr->ropframeoccasionals);
    eo_ropframe_Load(retptr->ropframereplies, retptr->bufferropframereplies, eo_ropframe_sizeforZEROrops, cfg->capacityofropframereplies);
    eo_ropframe_Clear(retptr->ropframereplies);


    {   // we set the content of ropframereadytotx with the same memory used by txpacket, so that when we operate on 
        // ropframereadytotx then we prepare the txpacket.
        uint8_t *data;
        uint16_t size;
        uint16_t capacity;
        
        eo_packet_Payload_Get(retptr->txpacket, &data, &size);
        eo_packet_Capacity_Get(retptr->txpacket, &capacity);
    
        eo_ropframe_Load(retptr->ropframereadytotx, data, eo_ropframe_sizeforZEROrops, capacity); // dont use size because size is now zero.
        eo_ropframe_Clear(retptr->ropframereadytotx);
        
        if(eobool_true != eo_ropframe_IsValid(retptr->ropframereadytotx))
        {
            eo_errman_Error(eo_errman_GetHandle(), eo_errortype_fatal, s_eobj_ownname, "the ropframeready2tx is not valid... cannot continue");
        }

        // the destination ipv4addr and ipv4port are constant and are the ones passed through configuration
        eo_packet_Addressing_Set(retptr->txpacket, retptr->ipv4addr, retptr->ipv4port);
    } 

    if((NULL != cfg->mutex_fn_new) && (eo_transmitter_protection_total == cfg->protection))
    {
        retptr->mtx_replies     = cfg->mutex_fn_new();
        retptr->mtx_regulars    = cfg->mutex_fn_new();
        retptr->mtx_occasionals = cfg->mutex_fn_new();        
    }
    else
    {
        retptr->mtx_replies     = NULL;
        retptr->mtx_regulars    = NULL;
        retptr->mtx_occasionals = NULL;
    }
    
#if defined(USE_DEBUG_EOTRANSMITTER)
    // DEBUG
    retptr->debug.txropframeistoobigforthepacket = 0;
#endif
    
    return(retptr);
}
Beispiel #21
0
extern EOMtheSystem * eom_sys_Initialise(const eOmsystem_cfg_t *syscfg, 
                                         const eOmempool_cfg_t *mpoolcfg, 
                                         const eOerrman_cfg_t *errmancfg,
                                         const eOmtimerman_cfg_t *tmrmancfg,
                                         const eOmcallbackman_cfg_t *cbkmancfg)
{
    uint32_t ram08size = 0;
    uint64_t *ram08data = NULL;

    if(NULL != s_eom_system.thevsys) 
    {
        // already initialised
        return(&s_eom_system);
    }


    eo_errman_Assert(eo_errman_GetHandle(), (NULL != syscfg), "eom_sys_Initialise(): NULL syscfg", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);
    // verify that we have a valid osalcfg and halcfg. fsalcfg can be NULL
    eo_errman_Assert(eo_errman_GetHandle(), (NULL != syscfg->halcfg), "eom_sys_Initialise(): NULL halcfg", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);
    eo_errman_Assert(eo_errman_GetHandle(), (NULL != syscfg->osalcfg), "eom_sys_Initialise(): NULL osalcfg", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);

    // mpoolcfg can be NULL: in such a case we use eo_mempool_alloc_dynamic mode
    // errmancfg can be NULL
    // tmrmancfg can be NULL: in such a case we use default values
    // cbkmancfg can be NULL: in such a case we use default values

    
    // mempool and error manager initialised inside here.
    s_eom_system.thevsys = eov_sys_hid_Initialise(mpoolcfg,
                                                  errmancfg,        // error man 
                                                  (eOres_fp_voidfpvoid_t)s_eom_sys_start, s_eom_gettask, 
                                                  osal_system_abstime_get, osal_system_ticks_abstime_set, 
                                                  (eOuint64_fp_void_t)osal_system_nanotime_get,
                                                  hal_sys_irq_disable);

    s_eom_system.halcfg     = syscfg->halcfg;
    s_eom_system.osalcfg    = syscfg->osalcfg;
    s_eom_system.tmrmancfg  = tmrmancfg;
    s_eom_system.cbkmancfg  = cbkmancfg;


    hal_core_init(syscfg->halcfg);
    hal_core_start();

    if(0 != syscfg->codespaceoffset)
    {
        hal_sys_vectortable_relocate(syscfg->codespaceoffset);
    }    

 
    // initialise osal
    osal_base_memory_getsize(s_eom_system.osalcfg, &ram08size);
    if(0 != ram08size)
    {
        ram08data = (uint64_t*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_64bit, ram08size, 1);
    }

    osal_base_initialise(s_eom_system.osalcfg, ram08data);


    return(&s_eom_system);
   
}
extern EOdeque * eo_deque_New(eOsizeitem_t item_size, eOsizecntnr_t capacity,
                              eOres_fp_voidp_uint32_t item_init, uint32_t init_par,  
                              eOres_fp_voidp_voidp_t item_copy, eOres_fp_voidp_t item_clear)
{
    EOdeque *retptr = NULL;
    uint8_t *start = NULL;
    uint8_t *item = NULL;
//    uint32_t pos = 0;
    eOsizecntnr_t i = 0; 
    eOmempool_alignment_t align = eo_mempool_align_08bit;


    // i get the memory for the object. no need to check versus NULL because the memory pool already does it
    retptr = (EOdeque*) eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOdeque), 1);



    // now the object has valid memory. i need to initialise it with user-defined data,
    
    retptr->size                = 0;
    retptr->first               = 0;
    retptr->next                = 0;

    eo_errman_Assert(eo_errman_GetHandle(), (0 != item_size), "eo_deque_New(): 0 item_size", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);
    eo_errman_Assert(eo_errman_GetHandle(), (0 != capacity), "eo_deque_New(): 0 capacity", s_eobj_ownname, &eo_errman_DescrWrongParamLocal);

    retptr->item_size           = item_size;
    retptr->sizeofstoreditem    = item_size;
    retptr->capacity            = capacity;
    retptr->item_init_fn        = item_init;
    retptr->item_init_par       = init_par;    
    retptr->item_copy_fn        = item_copy;
    retptr->item_clear_fn       = item_clear;

    // now we get memory for copying objects inside
    if(1 == item_size)
    {
        align = eo_mempool_align_08bit;
    }
    else if(2 == item_size)
    {
        align = eo_mempool_align_16bit;
    }
    else if (item_size <= 4)
    {
        align = eo_mempool_align_32bit;
        retptr->sizeofstoreditem = 4;
    }
    else
    {   // use 8-bytes alignment for everything else
        align = eo_mempool_align_64bit;
        retptr->sizeofstoreditem = (item_size+7)/8;
        retptr->sizeofstoreditem *= 8;
    }
    
    //#warning --> se alloco memoria per n oggetti (eg. di dimensione 6) in modo che ci sia allineamento ad 8, come indicizzo gli oggetti? a 6 oppure a 8?
    // da codice si evince a 6 ... quindi perche' spreco memoria nell'allocazione?
    // se uso dynamic, il heap viene gestito con allineamento a 8. ma quetso vuol dire che per 4 oggetti: 6*4 = 24 che sono tre uint64_t.
    // se uso align_64, anche qui ho array da uint64_t ma per 4 oggetti uso 4*(6+7)/8 = 4*1 = quattro uint64_t .... si spreca perche arrotondo sul item size e non sul totale. 

    // here is the memory from the correct memory pool (or the heap)
    retptr->stored_items  = (void*) eo_mempool_GetMemory(eo_mempool_GetHandle(), align, item_size, capacity);     

    start = (uint8_t*) (retptr->stored_items);
    for(i=0; i<capacity; i++) 
    {
        // cast to uint32_t to tell the reader that index of array start[] can be bigger than max eOsizecntnr_t
        item = &start[(uint32_t)i * item_size];        
        if(NULL != item_init)
        {   // construct each item
            item_init(item, init_par);
        }
        else
        {   // default init
            s_eo_deque_default_init(item, retptr);
        }
    }

    return(retptr);  
}