// sample the output pins to the current rb record static inline void apply(const sample_t *s, const hal_delayline_t *hd) { int i; for (i = 0; i < hd->nsamples; i++) { // because of the union the values and pins must be properly // dereferenced against their type switch (hd->pintype[i]) { case HAL_BIT: set_bit_value(hd->pins_out[i], get_bit_value(&s->value[i])); break; case HAL_FLOAT: set_float_value(hd->pins_out[i], get_float_value(&s->value[i])); break; case HAL_S32: set_s32_value(hd->pins_out[i], get_s32_value(&s->value[i])); break; case HAL_U32: set_u32_value(hd->pins_out[i], get_u32_value(&s->value[i])); break; case HAL_S64: set_s64_value(hd->pins_out[i], get_s64_value(&s->value[i])); break; case HAL_U64: set_u64_value(hd->pins_out[i], get_u64_value(&s->value[i])); break; case HAL_TYPE_MAX: case HAL_TYPE_UNSPECIFIED: // an error - should fail loudly TBD ; } } }
// write_sample_to_ring() will sample the pins and add them as a struct sample_t // into the ring. static void write_sample_to_ring(void *arg, long period) { int j; ringbuffer_t *rb = (ringbuffer_t *) arg; hal_delayline_t *hd = rb->scratchpad; // per-instance HAL data sample_t *s; // if pin_delay > max_delay then use max_delay, otherwise // use delay pin value // if time has increased, then take action by setting the input_ts to the // result of output_ts + delay. Otherwise do nothing. The situation of // decreasing the time will be acted upon in read_sample_to_ring() if ( *(hd->pin_delay) > (hal_u32_t)( hd->input_ts - hd->output_ts)) { if ( *(hd->pin_delay) > hd->max_delay) { hd->delay = hd->max_delay; } else { hd->delay = *(hd->pin_delay); } // set the new timestamp hd->input_ts = hd->output_ts + (__u64)(hd->delay); } if (!*(hd->enable)) { // skip if not sampling, just put the input // values into the output values for (j = 0; j < hd->nsamples; j++) { switch (hd->pintype[j]) { case HAL_BIT: set_bit_value(hd->pins_out[j], get_bit_value(hd->pins_in[j])); break; case HAL_FLOAT: set_float_value(hd->pins_out[j], get_float_value(hd->pins_in[j])); break; case HAL_S32: set_s32_value(hd->pins_out[j], get_s32_value(hd->pins_in[j])); break; case HAL_U32: set_u32_value(hd->pins_out[j], get_u32_value(hd->pins_in[j])); break; case HAL_S64: set_s64_value(hd->pins_out[j], get_s64_value(hd->pins_in[j])); break; case HAL_U64: set_u64_value(hd->pins_out[j], get_u64_value(hd->pins_in[j])); break; case HAL_TYPE_MAX: case HAL_TYPE_UNSPECIFIED: // an error - should fail loudly TBD ; } } goto DONE; } // use non-copying write: // allocate space in the ringbuffer and retrieve a pointer to it if (record_write_begin(rb, (void ** )&s, hd->sample_size)) { *(hd->write_fail) += 1; goto DONE; } // deposit record directly in rb memory s->timestamp = hd->input_ts; for (j = 0; j < hd->nsamples; j++) { switch (hd->pintype[j]) { case HAL_BIT: set_bit_value(&s->value[j], get_bit_value(hd->pins_in[j])); break; case HAL_FLOAT: set_float_value(&s->value[j], get_float_value(hd->pins_in[j])); break; case HAL_S32: set_s32_value(&s->value[j], get_s32_value(hd->pins_in[j])); break; case HAL_U32: set_u32_value(&s->value[j], get_u32_value(hd->pins_in[j])); break; case HAL_S64: set_s64_value(&s->value[j], get_s64_value(hd->pins_in[j])); break; case HAL_U64: set_u64_value(&s->value[j], get_u64_value(hd->pins_in[j])); break; case HAL_TYPE_MAX: case HAL_TYPE_UNSPECIFIED: // an error - should fail loudly TBD ; } } // commit the write given the actual write size (which is the same // as given in record_write_begin in our case). This makes the // record actually visible on the read side (advances pointer) if (record_write_end(rb, s, hd->sample_size)) *(hd->write_fail) += 1; DONE: hd->input_ts++; }
inline T set_bit(T const& t, int bit, bool b) { BOOST_STATIC_ASSERT((std::is_integral<T>::value)); if (bit >= sizeof(T)* 8) return t; return set_bit_value(t, ((T)1 << bit), b); }
void setCRB(ThreadState *state, uint32_t bit, uint32_t value) { state->cr.value = set_bit_value(state->cr.value, 31 - bit, value); }
static void setCRB(hwtest::RegisterState &state, uint32_t bit, uint32_t value) { state.cr.value = set_bit_value(state.cr.value, 31 - bit, value); }