예제 #1
0
파일: devLibVME.c 프로젝트: ukaea/epics
/*
 *
 * blockFind()
 *
 * Find unoccupied block in a large block
 *
 */
static long blockFind (
    epicsAddressType addrType,
    const rangeItem *pRange,
    /* size needed */
    size_t requestSize,
    /* n ls bits zero in base addr */
    unsigned alignment,
    /* base address found */
    size_t *pBase)
{
    int s = SUCCESS;
    size_t bb;
    size_t mask;
    size_t newBase;
    size_t newSize;

    /*
     * align the block base
     */
    mask = devCreateMask (alignment);
    newBase = pRange->begin;
    if ( mask & newBase ) {
        newBase |= mask;
        newBase++;
    }

    if ( requestSize == 0) {
        return S_dev_badRequest;
    }

    /*
     * align size of block
     */
    newSize = requestSize;
    if (mask & newSize) { 
        newSize |= mask;
        newSize++;
    }

    if (pRange->end - pRange->begin + 1 < newSize) {
        return S_dev_badRequest;
    }

    bb = pRange->begin;
    while (bb <= (pRange->end + 1) - newSize) {
        s = devNoResponseProbe (addrType, bb, newSize);
        if (s==SUCCESS) {
            *pBase = bb;
            return SUCCESS;
        }
        bb += newSize;
    }

    return s;
}
예제 #2
0
파일: devLibVME.c 프로젝트: ukaea/epics
/*
 * locationProbe
 *
 * !! DEPRECATED !!
 */
long locationProbe (epicsAddressType addrType, char *pLocation)
{
    return devNoResponseProbe (addrType, (size_t) pLocation, sizeof(long));
}
예제 #3
0
파일: omsMAXv.cpp 프로젝트: Brudhu/motor
void omsMAXv::initialize(const char* portName, int numAxes, int cardNo, const char* initString, int prio,
                int stackSz, unsigned int vmeAddr, int intrVector, int level, epicsAddressType vmeAddrType, int paramCount)
{

    const char* functionName = "initialize";
    long status;
    void* probeAddr;

    Debug(32, "omsMAXv::initialize: start initialize\n" );

    controllerType = epicsStrDup("MAXv");

    // TODO check if cardNo has already been used
    this->cardNo = cardNo;
    if(cardNo < 0 || cardNo >= MAXv_NUM_CARDS){
        printf("invalid cardNo: %d", cardNo);
        return;
    }

    epicsUInt8 *startAddr;
    epicsUInt8 *endAddr;
    epicsUInt32 boardAddrSize = 0;

    if (vmeAddrType == atVMEA16)
        boardAddrSize = 0x1000;
    else if (vmeAddrType == atVMEA24)
        boardAddrSize = 0x10000;
    else if (vmeAddrType == atVMEA32)
        boardAddrSize = 0x1000000;

    // if vmeAddr == 1 Setup/Config is used and not Config2
    if (vmeAddr == 1)
        probeAddr = baseAddress + (cardNo * boardAddrSize);
    else
        probeAddr = (void*) vmeAddr;

    startAddr = (epicsUInt8 *) probeAddr;
    endAddr = startAddr + boardAddrSize;

    Debug(64, "motor_init: devNoResponseProbe() on addr %p\n", probeAddr);

    /* Scan memory space to assure card id */
    while (startAddr < endAddr) {
        status = devNoResponseProbe(vmeAddrType, (size_t) startAddr, 2);
        if (status != S_dev_addressOverlap) {
            errlogPrintf("%s:%s:%s: Card NOT found in specified address range! \n",
                                driverName, functionName, portName);
            enabled = false;
            return;
        }
        startAddr += (boardAddrSize / 10);
    }

    status = devRegisterAddress(controllerType, vmeAddrType,
                                (size_t) probeAddr, boardAddrSize,
                                (volatile void **) &pmotor);
    Debug(64, "motor_init: devRegisterAddress() status = %d\n", (int) status);

    if (status) {
        errlogPrintf("%s:%s:%s: Can't register address 0x%lx \n",
                        driverName, functionName, portName, (long unsigned int) probeAddr);
        return;
    }

    Debug(64, "motor_init: pmotor = %p\n", pmotor);

    int loopCount=15;
    while (loopCount && (pmotor->firmware_status.Bits.initializing == 1)){
        Debug(1, "MAXv port %s still initializing; status = 0x%x\n",
                portName, (unsigned int) pmotor->firmware_status.All);
        epicsThreadSleep(0.2);
        --loopCount;
    }

    Debug(64, "motor_init: check if card is ready\n");

    if (pmotor->firmware_status.Bits.running == 0)
        errlogPrintf("MAXv port %s is NOT running; status = 0x%x\n",
                portName, (unsigned int) pmotor->firmware_status.All);

    Debug(64, "motor_init: init card\n");

    FIRMWARE_STATUS fwStatus;
    fwStatus.All = pmotor->firmware_status.All;
    Debug(64, "motor_init: firmware status register: 0x%x\n", fwStatus.All);

    pmotor->IACK_vector = intrVector;

    pmotor->status1_flag.All = 0xFFFFFFFF;
    pmotor->status2_flag = 0xFFFFFFFF;
    /* Disable all interrupts */
    pmotor->status1_irq_enable.All = 0;
    pmotor->status2_irq_enable = 0;

    Debug(64, "motor_init: clear all interrupt\n");
    //sendOnly("IC");

    Debug(64, "motor_init: firmware version\n");

    /* get FirmwareVersion */
    if(getFirmwareVersion() != asynSuccess) {
        errlogPrintf("%s:%s:%s: unable to talk to controller card %d\n",
                        driverName, functionName, portName, cardNo);
        return;
    }

    if (fwMinor < 30 ){
        errlogPrintf("%s:%s:%s: This Controllers Firmware Version %d.%d is not supported, version 1.30 or higher is mandatory\n",
                        driverName, functionName, portName, fwMajor, fwMinor);
    }

    Debug(64, "motor_init: send init string\n");

    if( Init(initString, 1) != asynSuccess) {
        errlogPrintf("%s:%s:%s: unable to send initstring to controller card %d\n",
                        driverName, functionName, portName, cardNo);
        return;
    }

    useWatchdog = true;

    if (watchdogOK()) {
        Debug(64, "motor_init: enable interrupts ( vector=%d, level=%d) \n", intrVector, level);
        /* Enable interrupt-when-done if selected */
        if (intrVector) motorIsrSetup((unsigned int)intrVector, level);
    }
    else
        return;

    if (epicsAtExit(&omsMAXv::resetOnExit, this))
        errlogPrintf("%s:%s:%s: card %d, unable to register exit function\n",
                        driverName, functionName, portName, cardNo);

    return;
}