Пример #1
0
/* Read access */
static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
{
    stream_sys_t *sys = s->p_sys;
    input_thread_t *input = s->p_input;
    ssize_t val = 0;

    do
    {
        if (vlc_access_Eof(sys->access))
            return 0;
        if (vlc_killed())
            return -1;

        val = vlc_access_Read(sys->access, buf, len);
        if (val == 0)
            return 0; /* EOF */
    }
    while (val < 0);

    if (input != NULL)
    {
        uint64_t total;

        vlc_mutex_lock(&input->p->counters.counters_lock);
        stats_Update(input->p->counters.p_read_bytes, val, &total);
        stats_Update(input->p->counters.p_input_bitrate, total, NULL);
        stats_Update(input->p->counters.p_read_packets, 1, NULL);
        vlc_mutex_unlock(&input->p->counters.counters_lock);
    }

    return val;
}
Пример #2
0
/* Block access */
static ssize_t AStreamReadBlock(stream_t *s, void *buf, size_t len)
{
    stream_sys_t *sys = s->p_sys;
    input_thread_t *input = s->p_input;
    block_t *block = sys->block;

    while (block == NULL)
    {
        if (vlc_access_Eof(sys->access))
            return 0;
        if (vlc_killed())
            return -1;

        block = vlc_access_Block(sys->access);
    }

    if (input != NULL)
    {
        uint64_t total;

        vlc_mutex_lock(&input->p->counters.counters_lock);
        stats_Update(input->p->counters.p_read_bytes, block->i_buffer, &total);
        stats_Update(input->p->counters.p_input_bitrate, total, NULL);
        stats_Update(input->p->counters.p_read_packets, 1, NULL);
        vlc_mutex_unlock(&input->p->counters.counters_lock);
    }

    size_t copy = block->i_buffer < len ? block->i_buffer : len;

    if (likely(copy > 0) && buf != NULL /* skipping data? */)
        memcpy(buf, block->p_buffer, copy);

    block->p_buffer += copy;
    block->i_buffer -= copy;

    if (block->i_buffer == 0)
    {
        block_Release(block);
        sys->block = NULL;
    }
    else
        sys->block = block;

    return copy;
}
Пример #3
0
/**
 * \brief Updates the current drawn by load according to selected load function
 *
 * This function is called from an interrupt (using timer 2) every millisecond
 */
void load_update(void) {
    hal_frontPanelUpdate();

    if (load.disableIOcontrol)
        return;

    if (settings.turnOffOnError && error.code) {
        load.powerOn = 0;
        hal_SelectShunt(HAL_SHUNT_NONE);
    } else if (settings.powerMode) {
        hal_SelectShunt(HAL_SHUNT_R01);
    } else {
        hal_SelectShunt(HAL_SHUNT_1R);
    }

    load.state.voltage = cal_getVoltage();

    load.state.current = cal_getCurrent();

    load.state.power = (uint64_t) load.state.voltage * load.state.current
            / 1000000UL;

    // update average values
    load.state.voltageSum += load.state.voltage;
    load.state.currentSum += load.state.current;
    load.state.powerSum += load.state.power;
    load.state.nsamples++;

    load.state.temp1 = cal_getTemp1();
    load.state.temp2 = cal_getTemp2();
    uint16_t highTemp = load.state.temp1;
    if (load.state.temp2 > load.state.temp1)
        highTemp = load.state.temp2;

    // switch fan
    if (highTemp >= LOAD_FANON_TEMP)
        hal_setFan(1);
    else if (highTemp <= LOAD_FANOFF_TEMP)
        hal_setFan(0);

    uint8_t triggerIn = hal_getTriggerIn();
    events.triggerInState = triggerIn - load.triggerInOld;
    load.triggerInOld = triggerIn;

    if (!cal.active) {
        // only run function that can potentially change settings
        // while calibration is not active
        events_decrementTimers();
        events_updateWaveformPhase();
        events_HandleEvents();

        arb_Update();
        waveform_Update();
        characteristic_Update();
        load_ConstrainSettings();

        uint32_t current = 0;
//    uint32_t currentLimit = ((uint64_t) settings.maxPower[settings.powerMode]
//            * 1000000) / load.state.voltage;

        uint8_t enableInput = load.powerOn;
        if (highTemp > LOAD_MAX_TEMP) {
            // disable input if temperature too high
            enableInput = 0;
        }
        switch (load.mode) {
        case FUNCTION_CC:
//        if (load.current > currentLimit)
//            current = currentLimit;
//        else
            current = load.current;
            hal_SetControlMode(HAL_MODE_CC);
            if (enableInput) {
                cal_setCurrent(current);
            } else {
                hal_setDAC(0);
            }
            break;
        case FUNCTION_CV:
            hal_SetControlMode(HAL_MODE_CV);
            if (enableInput) {
                cal_setVoltage(load.voltage);
            } else {
                hal_setDAC(HAL_DAC_MAX);
            }
            break;
        case FUNCTION_CR:
            // control resistance in digital mode: set current depending on voltage
            hal_SetControlMode(HAL_MODE_CC);
            if (enableInput) {
                // calculate necessary current
                current = ((uint64_t) load.state.voltage * 1000)
                        / load.resistance;
                cal_setCurrent(current);
            } else {
                hal_setDAC(0);
            }
            break;
        case FUNCTION_CP:
            // control control in digital mode: set current depending on voltage
            hal_SetControlMode(HAL_MODE_CC);
            if (enableInput) {
                // calculate necessary current
                current = ((uint64_t) load.power * 1000000)
                        / load.state.voltage;
                cal_setCurrent(current);
            } else {
                hal_setDAC(0);
            }
            break;
        }
        // update trigger out
        if(events.triggerOutState==1){
            hal_setTriggerOut(1);
        } else if(events.triggerOutState==-1){
            hal_setTriggerOut(0);
        }
        errors_Check();
    } else {
        // calibration is active
        switch (load.mode) {
        case FUNCTION_CC:
            hal_SetControlMode(HAL_MODE_CC);
            break;
        case FUNCTION_CV:
            hal_SetControlMode(HAL_MODE_CV);
            break;
        case FUNCTION_CR:
            hal_SetControlMode(HAL_MODE_CC);
            break;
        case FUNCTION_CP:
            hal_SetControlMode(HAL_MODE_CC);
            break;
        }
        hal_setDAC(load.DACoverride);
    }

    stats_Update();
}