mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-02 05:40:35 +08:00
Rework the ringbuffer class so that it's not templated, and refactor its clients so they aren't dancing around the linker anymore.
This commit is contained in:
@@ -147,14 +147,7 @@ private:
|
||||
struct hrt_call _call;
|
||||
unsigned _call_interval;
|
||||
|
||||
/*
|
||||
this wrapper type is needed to avoid a linker error for
|
||||
RingBuffer instances which appear in two drivers.
|
||||
*/
|
||||
struct _accel_report {
|
||||
accel_report r;
|
||||
};
|
||||
RingBuffer<struct _accel_report> *_reports;
|
||||
RingBuffer *_reports;
|
||||
|
||||
struct accel_scale _accel_scale;
|
||||
float _accel_range_scale;
|
||||
@@ -284,7 +277,7 @@ BMA180::init()
|
||||
goto out;
|
||||
|
||||
/* allocate basic report buffers */
|
||||
_reports = new RingBuffer<_accel_report>(2);
|
||||
_reports = new RingBuffer(2, sizeof(accel_report));
|
||||
|
||||
if (_reports == nullptr)
|
||||
goto out;
|
||||
@@ -349,7 +342,7 @@ ssize_t
|
||||
BMA180::read(struct file *filp, char *buffer, size_t buflen)
|
||||
{
|
||||
unsigned count = buflen / sizeof(struct accel_report);
|
||||
struct _accel_report *arp = reinterpret_cast<struct _accel_report *>(buffer);
|
||||
struct accel_report *arp = reinterpret_cast<struct accel_report *>(buffer);
|
||||
int ret = 0;
|
||||
|
||||
/* buffer must be large enough */
|
||||
@@ -365,7 +358,7 @@ BMA180::read(struct file *filp, char *buffer, size_t buflen)
|
||||
* we are careful to avoid racing with it.
|
||||
*/
|
||||
while (count--) {
|
||||
if (_reports->get(*arp)) {
|
||||
if (_reports->get(arp)) {
|
||||
ret += sizeof(*arp);
|
||||
arp++;
|
||||
}
|
||||
@@ -380,7 +373,7 @@ BMA180::read(struct file *filp, char *buffer, size_t buflen)
|
||||
measure();
|
||||
|
||||
/* measurement will have generated a report, copy it out */
|
||||
if (_reports->get(*arp))
|
||||
if (_reports->get(arp))
|
||||
ret = sizeof(*arp);
|
||||
|
||||
return ret;
|
||||
@@ -676,7 +669,7 @@ BMA180::measure()
|
||||
// } raw_report;
|
||||
// #pragma pack(pop)
|
||||
|
||||
struct _accel_report report;
|
||||
struct accel_report report;
|
||||
|
||||
/* start the performance counter */
|
||||
perf_begin(_sample_perf);
|
||||
@@ -696,40 +689,40 @@ BMA180::measure()
|
||||
* them before. There is no good way to synchronise with the internal
|
||||
* measurement flow without using the external interrupt.
|
||||
*/
|
||||
report.r.timestamp = hrt_absolute_time();
|
||||
report.timestamp = hrt_absolute_time();
|
||||
/*
|
||||
* y of board is x of sensor and x of board is -y of sensor
|
||||
* perform only the axis assignment here.
|
||||
* Two non-value bits are discarded directly
|
||||
*/
|
||||
report.r.y_raw = read_reg(ADDR_ACC_X_LSB + 0);
|
||||
report.r.y_raw |= read_reg(ADDR_ACC_X_LSB + 1) << 8;
|
||||
report.r.x_raw = read_reg(ADDR_ACC_X_LSB + 2);
|
||||
report.r.x_raw |= read_reg(ADDR_ACC_X_LSB + 3) << 8;
|
||||
report.r.z_raw = read_reg(ADDR_ACC_X_LSB + 4);
|
||||
report.r.z_raw |= read_reg(ADDR_ACC_X_LSB + 5) << 8;
|
||||
report.y_raw = read_reg(ADDR_ACC_X_LSB + 0);
|
||||
report.y_raw |= read_reg(ADDR_ACC_X_LSB + 1) << 8;
|
||||
report.x_raw = read_reg(ADDR_ACC_X_LSB + 2);
|
||||
report.x_raw |= read_reg(ADDR_ACC_X_LSB + 3) << 8;
|
||||
report.z_raw = read_reg(ADDR_ACC_X_LSB + 4);
|
||||
report.z_raw |= read_reg(ADDR_ACC_X_LSB + 5) << 8;
|
||||
|
||||
/* discard two non-value bits in the 16 bit measurement */
|
||||
report.r.x_raw = (report.r.x_raw / 4);
|
||||
report.r.y_raw = (report.r.y_raw / 4);
|
||||
report.r.z_raw = (report.r.z_raw / 4);
|
||||
report.x_raw = (report.x_raw / 4);
|
||||
report.y_raw = (report.y_raw / 4);
|
||||
report.z_raw = (report.z_raw / 4);
|
||||
|
||||
/* invert y axis, due to 14 bit data no overflow can occur in the negation */
|
||||
report.r.y_raw = -report.r.y_raw;
|
||||
report.y_raw = -report.y_raw;
|
||||
|
||||
report.r.x = ((report.r.x_raw * _accel_range_scale) - _accel_scale.x_offset) * _accel_scale.x_scale;
|
||||
report.r.y = ((report.r.y_raw * _accel_range_scale) - _accel_scale.y_offset) * _accel_scale.y_scale;
|
||||
report.r.z = ((report.r.z_raw * _accel_range_scale) - _accel_scale.z_offset) * _accel_scale.z_scale;
|
||||
report.r.scaling = _accel_range_scale;
|
||||
report.r.range_m_s2 = _accel_range_m_s2;
|
||||
report.x = ((report.x_raw * _accel_range_scale) - _accel_scale.x_offset) * _accel_scale.x_scale;
|
||||
report.y = ((report.y_raw * _accel_range_scale) - _accel_scale.y_offset) * _accel_scale.y_scale;
|
||||
report.z = ((report.z_raw * _accel_range_scale) - _accel_scale.z_offset) * _accel_scale.z_scale;
|
||||
report.scaling = _accel_range_scale;
|
||||
report.range_m_s2 = _accel_range_m_s2;
|
||||
|
||||
_reports->force(report);
|
||||
_reports->force(&report);
|
||||
|
||||
/* notify anyone waiting for data */
|
||||
poll_notify(POLLIN);
|
||||
|
||||
/* publish for subscribers */
|
||||
orb_publish(ORB_ID(sensor_accel), _accel_topic, &report.r);
|
||||
orb_publish(ORB_ID(sensor_accel), _accel_topic, &report);
|
||||
|
||||
/* stop the perf counter */
|
||||
perf_end(_sample_perf);
|
||||
|
||||
Reference in New Issue
Block a user