@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
interp.h
Go to the documentation of this file.
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _HARDWARE_INTERP_H
#define _HARDWARE_INTERP_H
#include "pico.h"
#include "hardware/structs/interp.h"
#include "hardware/regs/sio.h"
// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_INTERP, Enable/disable assertions in the hardware_interp module, type=bool, default=0, group=hardware_interp
#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_INTERP
#ifdef PARAM_ASSERTIONS_ENABLED_INTERP // backwards compatibility with SDK < 2.0.0
#define PARAM_ASSERTIONS_ENABLED_HARDWARE_INTERP PARAM_ASSERTIONS_ENABLED_INTERP
#else
#define PARAM_ASSERTIONS_ENABLED_HARDWARE_INTERP 0
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define interp0 interp0_hw
#define interp1 interp1_hw
typedef struct {
uint32_t ctrl;
} interp_config;
static inline uint interp_index(interp_hw_t *interp) {
valid_params_if(HARDWARE_INTERP, interp == interp0 || interp == interp1);
return interp == interp1 ? 1 : 0;
}
void interp_claim_lane(interp_hw_t *interp, uint lane);
// The above really should be called this for consistency
#define interp_lane_claim interp_claim_lane
void interp_claim_lane_mask(interp_hw_t *interp, uint lane_mask);
void interp_unclaim_lane(interp_hw_t *interp, uint lane);
// The above really should be called this for consistency
#define interp_lane_unclaim interp_unclaim_lane
bool interp_lane_is_claimed(interp_hw_t *interp, uint lane);
void interp_unclaim_lane_mask(interp_hw_t *interp, uint lane_mask);
static inline void interp_config_set_shift(interp_config *c, uint shift) {
valid_params_if(HARDWARE_INTERP, shift < 32);
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_SHIFT_BITS) |
((shift << SIO_INTERP0_CTRL_LANE0_SHIFT_LSB) & SIO_INTERP0_CTRL_LANE0_SHIFT_BITS);
}
static inline void interp_config_set_mask(interp_config *c, uint mask_lsb, uint mask_msb) {
valid_params_if(HARDWARE_INTERP, mask_msb < 32);
valid_params_if(HARDWARE_INTERP, mask_lsb <= mask_msb);
c->ctrl = (c->ctrl & ~(SIO_INTERP0_CTRL_LANE0_MASK_LSB_BITS | SIO_INTERP0_CTRL_LANE0_MASK_MSB_BITS)) |
((mask_lsb << SIO_INTERP0_CTRL_LANE0_MASK_LSB_LSB) & SIO_INTERP0_CTRL_LANE0_MASK_LSB_BITS) |
((mask_msb << SIO_INTERP0_CTRL_LANE0_MASK_MSB_LSB) & SIO_INTERP0_CTRL_LANE0_MASK_MSB_BITS);
}
static inline void interp_config_set_cross_input(interp_config *c, bool cross_input) {
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_CROSS_INPUT_BITS) |
(cross_input ? SIO_INTERP0_CTRL_LANE0_CROSS_INPUT_BITS : 0);
}
static inline void interp_config_set_cross_result(interp_config *c, bool cross_result) {
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_CROSS_RESULT_BITS) |
(cross_result ? SIO_INTERP0_CTRL_LANE0_CROSS_RESULT_BITS : 0);
}
static inline void interp_config_set_signed(interp_config *c, bool _signed) {
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_SIGNED_BITS) |
(_signed ? SIO_INTERP0_CTRL_LANE0_SIGNED_BITS : 0);
}
static inline void interp_config_set_add_raw(interp_config *c, bool add_raw) {
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_ADD_RAW_BITS) |
(add_raw ? SIO_INTERP0_CTRL_LANE0_ADD_RAW_BITS : 0);
}
static inline void interp_config_set_blend(interp_config *c, bool blend) {
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_BLEND_BITS) |
(blend ? SIO_INTERP0_CTRL_LANE0_BLEND_BITS : 0);
}
static inline void interp_config_set_clamp(interp_config *c, bool clamp) {
c->ctrl = (c->ctrl & ~SIO_INTERP1_CTRL_LANE0_CLAMP_BITS) |
(clamp ? SIO_INTERP1_CTRL_LANE0_CLAMP_BITS : 0);
}
static inline void interp_config_set_force_bits(interp_config *c, uint bits) {
invalid_params_if(HARDWARE_INTERP, bits > 3);
// note cannot use hw_set_bits on SIO
c->ctrl = (c->ctrl & ~SIO_INTERP0_CTRL_LANE0_FORCE_MSB_BITS) |
(bits << SIO_INTERP0_CTRL_LANE0_FORCE_MSB_LSB);
}
static inline interp_config interp_default_config(void) {
interp_config c = {0};
// Just pass through everything
interp_config_set_mask(&c, 0, 31);
return c;
}
static inline void interp_set_config(interp_hw_t *interp, uint lane, interp_config *config) {
invalid_params_if(HARDWARE_INTERP, lane > 1);
invalid_params_if(HARDWARE_INTERP, config->ctrl & SIO_INTERP1_CTRL_LANE0_CLAMP_BITS &&
(!interp_index(interp) || lane)); // only interp1 lane 0 has clamp bit
invalid_params_if(HARDWARE_INTERP, config->ctrl & SIO_INTERP0_CTRL_LANE0_BLEND_BITS &&
(interp_index(interp) || lane)); // only interp0 lane 0 has blend bit
interp->ctrl[lane] = config->ctrl;
}
static inline void interp_set_force_bits(interp_hw_t *interp, uint lane, uint bits) {
// note cannot use hw_set_bits on SIO
interp->ctrl[lane] = interp->ctrl[lane] | (bits << SIO_INTERP0_CTRL_LANE0_FORCE_MSB_LSB);
}
typedef struct {
uint32_t accum[2];
uint32_t base[3];
uint32_t ctrl[2];
} interp_hw_save_t;
void interp_save(interp_hw_t *interp, interp_hw_save_t *saver);
void interp_restore(interp_hw_t *interp, interp_hw_save_t *saver);
static inline void interp_set_base(interp_hw_t *interp, uint lane, uint32_t val) {
interp->base[lane] = val;
}
static inline uint32_t interp_get_base(interp_hw_t *interp, uint lane) {
return interp->base[lane];
}
static inline void interp_set_base_both(interp_hw_t *interp, uint32_t val) {
interp->base01 = val;
}
static inline void interp_set_accumulator(interp_hw_t *interp, uint lane, uint32_t val) {
interp->accum[lane] = val;
}
static inline uint32_t interp_get_accumulator(interp_hw_t *interp, uint lane) {
return interp->accum[lane];
}
static inline uint32_t interp_pop_lane_result(interp_hw_t *interp, uint lane) {
return interp->pop[lane];
}
static inline uint32_t interp_peek_lane_result(interp_hw_t *interp, uint lane) {
return interp->peek[lane];
}
static inline uint32_t interp_pop_full_result(interp_hw_t *interp) {
return interp->pop[2];
}
static inline uint32_t interp_peek_full_result(interp_hw_t *interp) {
return interp->peek[2];
}
static inline void interp_add_accumulator(interp_hw_t *interp, uint lane, uint32_t val) {
interp->add_raw[lane] = val;
}
// backwards incompatibility with old incorrect spelling
#define interp_add_accumulater(interp, lane, val) interp_add_accumulator(interp, lane, val)
static inline uint32_t interp_get_raw(interp_hw_t *interp, uint lane) {
return interp->add_raw[lane];
}
#ifdef __cplusplus
}
#endif
#endif
interp_get_base
static uint32_t interp_get_base(interp_hw_t *interp, uint lane)
Gets the content of interpolator base register by lane.
Definition interp.h:350
interp_get_raw
static uint32_t interp_get_raw(interp_hw_t *interp, uint lane)
Get raw lane value.
Definition interp.h:456
interp_set_base_both
static void interp_set_base_both(interp_hw_t *interp, uint32_t val)
Sets the interpolator base registers simultaneously.
Definition interp.h:363
interp_restore
void interp_restore(interp_hw_t *interp, interp_hw_save_t *saver)
Restore an interpolator state.
Definition interp.c:58
interp_unclaim_lane
void interp_unclaim_lane(interp_hw_t *interp, uint lane)
Release a previously claimed interpolator lane.
Definition interp.c:32
interp_add_accumulator
static void interp_add_accumulator(interp_hw_t *interp, uint lane, uint32_t val)
Add to accumulator.
Definition interp.h:441
interp_claim_lane
void interp_claim_lane(interp_hw_t *interp, uint lane)
Claim the interpolator lane specified.
Definition interp.c:21
interp_claim_lane_mask
void interp_claim_lane_mask(interp_hw_t *interp, uint lane_mask)
Claim the interpolator lanes specified in the mask.
Definition interp.c:26
interp_set_force_bits
static void interp_set_force_bits(interp_hw_t *interp, uint lane, uint bits)
Directly set the force bits on a specified lane.
Definition interp.h:302
interp_save
void interp_save(interp_hw_t *interp, interp_hw_save_t *saver)
Save the specified interpolator state.
Definition interp.c:48
interp_unclaim_lane_mask
void interp_unclaim_lane_mask(interp_hw_t *interp, uint lane_mask)
Release previously claimed interpolator lanes, see interp_claim_lane_mask.
Definition interp.c:42
interp_set_base
static void interp_set_base(interp_hw_t *interp, uint lane, uint32_t val)
Sets the interpolator base register by lane.
Definition interp.h:339
interp_peek_full_result
static uint32_t interp_peek_full_result(interp_hw_t *interp)
Read lane result.
Definition interp.h:428
interp_get_accumulator
static uint32_t interp_get_accumulator(interp_hw_t *interp, uint lane)
Gets the content of the interpolator accumulator register by lane.
Definition interp.h:386
interp_pop_full_result
static uint32_t interp_pop_full_result(interp_hw_t *interp)
Read lane result, and write lane results to both accumulators to update the interpolator.
Definition interp.h:418
interp_set_accumulator
static void interp_set_accumulator(interp_hw_t *interp, uint lane, uint32_t val)
Sets the interpolator accumulator register by lane.
Definition interp.h:375
interp_lane_is_claimed
bool interp_lane_is_claimed(interp_hw_t *interp, uint lane)
Determine if an interpolator lane is claimed.
Definition interp.c:37
interp_pop_lane_result
static uint32_t interp_pop_lane_result(interp_hw_t *interp, uint lane)
Read lane result, and write lane results to both accumulators to update the interpolator.
Definition interp.h:397
interp_peek_lane_result
static uint32_t interp_peek_lane_result(interp_hw_t *interp, uint lane)
Read lane result.
Definition interp.h:408
interp_config_set_clamp
static void interp_config_set_clamp(interp_config *c, bool clamp)
Set interpolator clamp mode (Interpolator 1 only).
Definition interp.h:234
interp_default_config
static interp_config interp_default_config(void)
Get a default configuration.
Definition interp.h:262
interp_config_set_force_bits
static void interp_config_set_force_bits(interp_config *c, uint bits)
Set interpolator Force bits.
Definition interp.h:250
interp_config_set_shift
static void interp_config_set_shift(interp_config *c, uint shift)
Set the interpolator shift value.
Definition interp.h:126
interp_config_set_mask
static void interp_config_set_mask(interp_config *c, uint mask_lsb, uint mask_msb)
Set the interpolator mask range.
Definition interp.h:141
interp_config_set_blend
static void interp_config_set_blend(interp_config *c, bool blend)
Set blend mode.
Definition interp.h:219
interp_config_set_add_raw
static void interp_config_set_add_raw(interp_config *c, bool add_raw)
Set raw add option.
Definition interp.h:199
interp_config_set_signed
static void interp_config_set_signed(interp_config *c, bool _signed)
Set sign extension.
Definition interp.h:186
interp_set_config
static void interp_set_config(interp_hw_t *interp, uint lane, interp_config *config)
Send configuration to a lane.
Definition interp.h:280
interp_config_set_cross_result
static void interp_config_set_cross_result(interp_config *c, bool cross_result)
Enable cross results.
Definition interp.h:172
interp_config_set_cross_input
static void interp_config_set_cross_input(interp_config *c, bool cross_input)
Enable cross input.
Definition interp.h:159
pico.h
interp_config
Definition interp.h:58
interp_hw_save_t
Definition interp.h:307
interp_hw_t
Definition interp.h:26