|
Packit |
534379 |
// Copyright(c) 2018-2020, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include "bmcdata.h"
|
|
Packit |
534379 |
#include <opae/fpga.h>
|
|
Packit |
534379 |
#ifndef _WIN32
|
|
Packit |
534379 |
#include <unistd.h>
|
|
Packit |
534379 |
#include <uuid/uuid.h>
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
#include <fcntl.h>
|
|
Packit |
534379 |
#include <sys/types.h>
|
|
Packit |
534379 |
#include <stdlib.h>
|
|
Packit |
534379 |
#include <stddef.h>
|
|
Packit |
534379 |
#include <string.h>
|
|
Packit |
534379 |
#include <wchar.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
double getvalue(Values *val, uint8_t raw)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
int i;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
double res = val->M * raw + val->B;
|
|
Packit |
534379 |
for (i = 0; i < abs(val->result_exp); i++) {
|
|
Packit |
534379 |
if (val->result_exp >= 0) {
|
|
Packit |
534379 |
res *= 10.0;
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
res /= 10.0;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
void calc_params(sdr_body *body, Values *val)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
int32_t i;
|
|
Packit |
534379 |
int32_t M_val = 0;
|
|
Packit |
534379 |
int32_t B_val = 0;
|
|
Packit |
534379 |
uint32_t A_val = 0;
|
|
Packit |
534379 |
uint32_t T_val = 0;
|
|
Packit |
534379 |
uint32_t A_exp = 0;
|
|
Packit |
534379 |
int32_t R_exp = 0;
|
|
Packit |
534379 |
int32_t B_exp = 0;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define SIGN_EXT(val, bitpos) (((val) ^ (1 << (bitpos))) - (1 << (bitpos)))
|
|
Packit |
534379 |
|
|
Packit |
534379 |
B_val = (body->B_accuracy.bits.B_2_msb << 8) | body->B_8_lsb;
|
|
Packit |
534379 |
B_val = SIGN_EXT(B_val, 9);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
M_val = (body->M_tolerance.bits.M_2_msb << 8) | body->M_8_lsb;
|
|
Packit |
534379 |
M_val = SIGN_EXT(M_val, 9);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
A_val = (body->accuracy_accexp_sensor_direction.bits.accuracy_4_msb
|
|
Packit |
534379 |
<< 6)
|
|
Packit |
534379 |
| body->B_accuracy.bits.accuracy_6_lsb;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
T_val = body->M_tolerance.bits.tolerance;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
A_exp = body->accuracy_accexp_sensor_direction.bits.accuracy_exp;
|
|
Packit |
534379 |
R_exp = body->R_exp_B_exp.bits.R_exp;
|
|
Packit |
534379 |
R_exp = SIGN_EXT(R_exp, 3);
|
|
Packit |
534379 |
B_exp = body->R_exp_B_exp.bits.B_exp;
|
|
Packit |
534379 |
B_exp = SIGN_EXT(B_exp, 3);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
val->M = (double)M_val;
|
|
Packit |
534379 |
val->tolerance = T_val;
|
|
Packit |
534379 |
val->B = (double)B_val;
|
|
Packit |
534379 |
val->result_exp = R_exp;
|
|
Packit |
534379 |
val->A_exp = A_exp;
|
|
Packit |
534379 |
for (i = 0; i < abs(B_exp); i++) {
|
|
Packit |
534379 |
if (B_exp >= 0) {
|
|
Packit |
534379 |
val->B *= 10.0;
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
val->B /= 10.0;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
val->accuracy = (double)A_val;
|
|
Packit |
534379 |
for (i = 0; i < (int32_t)A_exp; i++) {
|
|
Packit |
534379 |
val->accuracy *= 10.0;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|