Skip to content
Snippets Groups Projects
Commit 1c2c4355 authored by Venkateshwarlu Domakonda's avatar Venkateshwarlu Domakonda Committed by Gerrit - the friendly Code Review server
Browse files

fm: Added support for configuring performance parameters

Add apis to configure fm performance related parameters.

CRs-Fixed: 671803
Change-Id: I37565c21a731023e42372be71fb28edc30154672
parent 360a4509
Branches
No related tags found
No related merge requests found
...@@ -3,7 +3,11 @@ LOCAL_PATH := $(call my-dir) ...@@ -3,7 +3,11 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \ LOCAL_SRC_FILES:= \
android_hardware_fm.cpp android_hardware_fm.cpp \
ConfFileParser.cpp \
ConfigFmThs.cpp \
FmIoctlsInterface.cpp \
FmPerformanceParams.cpp
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
libnativehelper \ libnativehelper \
......
This diff is collapsed.
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __CONF_FILE_PARSER_H__
#define __CONF_FILE_PARSER_H__
#define MAX_LINE_LEN 512
#define MAX_UNIQ_KEYS 5
#define MAX_UNIQ_GRPS 10
#define TRUE 1
#define FALSE 0
struct key_value_pair_list
{
char *key;
char *value;
key_value_pair_list *next;
};
struct group
{
char *grp_name;
unsigned int num_of_keys;
unsigned int keys_hash_size;
key_value_pair_list **list;
group *grp_next;
};
struct group_table
{
unsigned int grps_hash_size;
unsigned int num_of_grps;
group **grps_hash;
};
enum CONF_PARSE_ERRO_CODE
{
PARSE_SUCCESS,
INVALID_FILE_NAME,
FILE_OPEN_FAILED,
FILE_NOT_PROPER,
MEMORY_ALLOC_FAILED,
PARSE_FAILED,
};
unsigned int get_hash_code(const char *str);
group_table *get_key_file();
void free_strs(char **str_array);
void free_key_file(group_table *key_file);
char parse_load_file(group_table *key_file, const char *file);
char **get_grps(const group_table *key_file);
char **get_keys(const group_table *key_file, const char *grp);
char *get_value(const group_table *key_file, const char *grp,
const char *key);
#endif //__CONF_FILE_PARSER_H__
This diff is collapsed.
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __CONFIG_FM_THS_H__
#define __CONFIG_FM_THS_H__
#include <cstring>
#include "FmConst.h"
#include "ConfFileParser.h"
#define MAX_GRPS 3
#define MAX_SRCH_PARAMS 8
#define MAX_AF_PARAMS 3
#define SINR_SAMPLES_CNT_MIN 0
#define SINR_SAMPLES_CNT_MAX 255
#define SINR_FIRST_STAGE_MIN -128
#define SINR_FIRST_STAGE_MAX 127
#define RMSSI_FIRST_STAGE_MIN -128
#define RMSSI_FIRST_STAGE_MAX 127
#define INTF_LOW_TH_MIN 0
#define INTF_LOW_TH_MAX 255
#define INTF_HIGH_TH_MIN 0
#define INTF_HIGH_TH_MAX 255
#define SRCH_ALGO_TYPE_MIN 0
#define SRCH_ALGO_TYPE_MAX 1
#define SINR_FINAL_STAGE_MIN -128
#define SINR_FINAL_STAGE_MAX 127
#define AF_RMSSI_TH_MIN 0
#define AF_RMSSI_TH_MAX 65535
#define AF_RMSSI_SAMPLES_MIN 0
#define AF_RMSSI_SAMPLES_MAX 255
#define GOOD_CH_RMSSI_TH_MIN -128
#define GOOD_CH_RMSSI_TH_MAX 127
const unsigned char MAX_HYBRID_SRCH_PARAMS = 2;
struct NAME_MAP
{
const char name[50];
const int num;
};
enum PERFORMANCE_GRPS
{
AF_THS,
SRCH_THS,
HYBRD_SRCH_LIST,
};
enum PERFORMANCE_SRCH_PARAMS
{
SRCH_ALGO_TYPE,
CF0_TH,
SINR_FIRST_STAGE,
SINR,
RMSSI_FIRST_STAGE,
INTF_LOW_TH,
INTF_HIGH_TH,
SINR_SAMPLES,
};
enum PERFORMANCE_AF_PARAMS
{
AF_RMSSI_TH,
AF_RMSSI_SAMPLES,
GOOD_CH_RMSSI_TH,
};
enum HYBRID_SRCH_PARAMS
{
FREQ_LIST,
SINR_LIST,
};
//Keep this list in sorted order (ascending order in terms of "name")
//Don't change the name of GRPS, if changed please also change accordingly
//file: fm_srch_af_th.conf
static struct NAME_MAP GRPS_MAP[] =
{
{"AFTHRESHOLDS", AF_THS},
{"HYBRIDSEARCHLIST", HYBRD_SRCH_LIST},
{"SEARCHTHRESHOLDS", SRCH_THS},
};
//Keep this list in sorted order (ascending order in terms of "name")
//Don't change the name of SEARCH thresholds,
//if changed please also change accordingly
//file: fm_srch_af_th.conf
static struct NAME_MAP SEACH_PARAMS_MAP[] =
{
{"Cf0Th12", CF0_TH},
{"IntfHighTh", INTF_HIGH_TH},
{"IntfLowTh", INTF_LOW_TH},
{"RmssiFirstStage", RMSSI_FIRST_STAGE},
{"SearchAlgoType", SRCH_ALGO_TYPE},
{"Sinr", SINR},
{"SinrFirstStage", SINR_FIRST_STAGE},
{"SinrSamplesCnt", SINR_SAMPLES},
};
//Keep this list in sorted order (ascending order in terms of "name")
//Don't change the name of SEARCH thresholds,
//if changed please also change accordingly
//file: fm_srch_af_th.conf
static struct NAME_MAP AF_PARAMS_MAP[] =
{
{"AfRmssiSamplesCnt", AF_RMSSI_SAMPLES},
{"AfRmssiTh", AF_RMSSI_TH},
{"GoodChRmssiTh", GOOD_CH_RMSSI_TH},
};
static struct NAME_MAP HYBRD_SRCH_MAP[] =
{
{"Freqs", FREQ_LIST},
{"Sinrs", SINR_LIST},
};
class ConfigFmThs {
private:
group_table *keyfile;
void set_srch_ths(UINT fd);
void set_af_ths(UINT fd);
unsigned int extract_comma_sep_freqs(char *freqs, unsigned int **freqs_arr, const char *str);
unsigned int extract_comma_sep_sinrs(char *sinrs, signed char **sinrs_arr, const char *str);
void set_hybrd_list(UINT fd);
public:
ConfigFmThs();
~ConfigFmThs();
void SetRxSearchAfThs(const char *file, UINT fd);
};
#endif //__CONFIG_FM_THS_H__
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __FM_CONST_H__
#define __FM_CONST_H__
typedef unsigned int UINT;
typedef unsigned long ULINT;
//return related
const int IOCTL_SUCC = 0;
const int FM_SUCCESS = 0;
const int FM_FAILURE = -1;
const int PROP_SET_SUCC = 0;
#define TUNE_MULT 16
const UINT CAL_DATA_SIZE = 23;
#define STD_BUF_SIZE 256
const char *const FM_PERFORMANCE_PARAMS = "/etc/fm/fm_srch_af_th.conf";
const char *const CALIB_DATA_NAME = "/data/app/Riva_fm_cal";
#define V4L2_CTRL_CLASS_USER 0x00980000
#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900)
#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE + 9)
const UINT SEARCH_DWELL_TIME = 2;
const UINT SEEK_DWELL_TIME = 0;
enum FM_AUDIO_PATH
{
AUDIO_DIGITAL_PATH,
AUDIO_ANALOG_PATH,
};
enum FM_DEVICE
{
FM_DEV_NONE,
FM_RX,
FM_TX,
};
enum BUFF_INDEXES
{
STATION_LIST_IND,
EVENT_IND,
RT_IND,
PS_IND,
AF_LIST_IND = PS_IND + 2,
RT_PLUS_IND = 11,
ERT_IND,
};
enum SEARCH_MODE
{
SEEK_MODE,
SCAN_MODE,
};
enum SEARCH_DIR
{
SEARCH_DOWN,
SEARCH_UP,
};
enum AUDIO_MODE
{
MONO,
STEREO,
};
//V4L2 CONTROLS FOR FM DRIVER
enum FM_V4L2_PRV_CONTROLS
{
V4L2_CID_PRV_BASE = 0x8000000,
V4L2_CID_PRV_SRCHMODE,
V4L2_CID_PRV_SCANDWELL,
V4L2_CID_PRV_SRCHON,
V4L2_CID_PRV_STATE,
V4L2_CID_PRV_TRANSMIT_MODE,
V4L2_CID_PRV_RDSGROUP_MASK,
V4L2_CID_PRV_REGION,
V4L2_CID_PRV_SIGNAL_TH,
V4L2_CID_PRV_SRCH_PTY,
V4L2_CID_PRV_SRCH_PI,
V4L2_CID_PRV_SRCH_CNT,
V4L2_CID_PRV_EMPHASIS,
V4L2_CID_PRV_RDS_STD,
V4L2_CID_PRV_CHAN_SPACING,
V4L2_CID_PRV_RDSON,
V4L2_CID_PRV_RDSGROUP_PROC,
V4L2_CID_PRV_LP_MODE,
V4L2_CID_PRV_INTDET = V4L2_CID_PRV_BASE + 25,
V4L2_CID_PRV_AF_JUMP = V4L2_CID_PRV_BASE + 27,
V4L2_CID_PRV_SOFT_MUTE = V4L2_CID_PRV_BASE + 30,
V4L2_CID_PRV_AUDIO_PATH = V4L2_CID_PRV_BASE + 41,
V4L2_CID_PRV_SINR = V4L2_CID_PRV_BASE + 44,
V4L2_CID_PRV_ON_CHANNEL_THRESHOLD = V4L2_CID_PRV_BASE + 0x2D,
V4L2_CID_PRV_OFF_CHANNEL_THRESHOLD,
V4L2_CID_PRV_SINR_THRESHOLD,
V4L2_CID_PRV_SINR_SAMPLES,
V4L2_CID_PRV_SPUR_FREQ,
V4L2_CID_PRV_SPUR_FREQ_RMSSI,
V4L2_CID_PRV_SPUR_SELECTION,
V4L2_CID_PRV_AF_RMSSI_TH = V4L2_CID_PRV_BASE + 0x36,
V4L2_CID_PRV_AF_RMSSI_SAMPLES,
V4L2_CID_PRV_GOOD_CH_RMSSI_TH,
V4L2_CID_PRV_SRCHALGOTYPE,
V4L2_CID_PRV_CF0TH12,
V4L2_CID_PRV_SINRFIRSTSTAGE,
V4L2_CID_PRV_RMSSIFIRSTSTAGE,
V4L2_CID_PRV_SOFT_MUTE_TH,
V4L2_CID_PRV_IRIS_RDSGRP_RT,
V4L2_CID_PRV_IRIS_RDSGRP_PS_SIMPLE,
V4L2_CID_PRV_IRIS_RDSGRP_AFLIST,
V4L2_CID_PRV_IRIS_RDSGRP_ERT,
V4L2_CID_PRV_IRIS_RDSGRP_RT_PLUS,
V4L2_CID_PRV_IRIS_RDSGRP_3A,
V4L2_CID_PRV_IRIS_READ_DEFAULT = V4L2_CTRL_CLASS_USER + 0x928,
V4L2_CID_PRV_IRIS_WRITE_DEFAULT,
V4L2_CID_PRV_SET_CALIBRATION = V4L2_CTRL_CLASS_USER + 0x92A,
};
#endif
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "FmIoctlsInterface.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <utils/Log.h>
#include <cutils/properties.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <math.h>
char const * const FmIoctlsInterface::LOGTAG = "FmIoctlsInterface";
int FmIoctlsInterface :: get_cur_freq
(
UINT fd, long &freq
)
{
int ret;
struct v4l2_frequency channel;
channel.type = V4L2_TUNER_RADIO;
ret = ioctl(fd, VIDIOC_G_FREQUENCY, &channel);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
freq = (channel.frequency / TUNE_MULT);
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: set_freq
(
UINT fd, ULINT freq
)
{
int ret;
struct v4l2_frequency channel;
channel.type = V4L2_TUNER_RADIO;
channel.frequency = (freq * TUNE_MULT);
ret = ioctl(fd, VIDIOC_S_FREQUENCY, &channel);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: set_control
(
UINT fd, UINT id, int val
)
{
int ret;
struct v4l2_control control;
control.value = val;
control.id = id;
for(int i = 0; i < 3; i++) {
ret = ioctl(fd, VIDIOC_S_CTRL, &control);
if(ret != IOCTL_SUCC) {
ret = FM_FAILURE;
}else {
ret = FM_SUCCESS;
break;
}
}
return ret;
}
int FmIoctlsInterface :: set_calibration
(
UINT fd
)
{
int ret;
FILE *cal_fp;
struct v4l2_ext_control ext_ctl;
struct v4l2_ext_controls v4l2_ctls;
char cal_data[CAL_DATA_SIZE] = {0};
cal_fp = fopen(CALIB_DATA_NAME, "r");
if(cal_fp != NULL) {
if(fread(&cal_data[0], 1, CAL_DATA_SIZE, cal_fp)
< CAL_DATA_SIZE) {
fclose(cal_fp);
ALOGE("%s: calibration file read failed\n", LOGTAG);
return FM_FAILURE;
}
fclose(cal_fp);
ext_ctl.id = V4L2_CID_PRV_SET_CALIBRATION;
ext_ctl.string = cal_data;
ext_ctl.size = CAL_DATA_SIZE;
v4l2_ctls.ctrl_class = V4L2_CTRL_CLASS_USER;
v4l2_ctls.count = 1;
v4l2_ctls.controls = &ext_ctl;
ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &v4l2_ctls);
if(ret != IOCTL_SUCC) {
ALOGE("%s: ioctl call failed\n", LOGTAG);
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}else {
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: get_control
(
UINT fd, UINT id, long &val
)
{
int ret;
struct v4l2_control control;
control.id = id;
ret = ioctl(fd, VIDIOC_G_CTRL, &control);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
val = control.value;
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: start_search
(
UINT fd, UINT dir
)
{
int ret;
struct v4l2_hw_freq_seek hw_seek;
hw_seek.seek_upward = dir;
hw_seek.type = V4L2_TUNER_RADIO;
ret = ioctl(fd, VIDIOC_S_HW_FREQ_SEEK, &hw_seek);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: set_band
(
UINT fd, ULINT low, ULINT high
)
{
int ret;
struct v4l2_tuner tuner;
tuner.index = 0;
tuner.signal = 0;
tuner.rangelow = (low * TUNE_MULT);
tuner.rangehigh = (high * TUNE_MULT);
ret = ioctl(fd, VIDIOC_S_TUNER, &tuner);
ret = set_control(fd, V4L2_CID_PRV_REGION, 0);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: get_rmssi
(
UINT fd, long &rmssi
)
{
struct v4l2_tuner tuner;
int ret;
tuner.index = 0;
tuner.signal = 0;
ret = ioctl(fd, VIDIOC_G_TUNER, &tuner);
if(ret != IOCTL_SUCC) {
ret = FM_FAILURE;
}else {
rmssi = tuner.signal;
ret = FM_SUCCESS;
}
return ret;
}
int FmIoctlsInterface :: get_upperband_limit
(
UINT fd, ULINT &freq
)
{
int ret;
struct v4l2_tuner tuner;
tuner.index = 0;
ret = ioctl(fd, VIDIOC_G_TUNER, &tuner);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
freq = (tuner.rangehigh / TUNE_MULT);
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: get_lowerband_limit
(
UINT fd, ULINT &freq
)
{
int ret;
struct v4l2_tuner tuner;
tuner.index = 0;
ret = ioctl(fd, VIDIOC_G_TUNER, &tuner);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
freq = (tuner.rangelow / TUNE_MULT);
return FM_SUCCESS;
}
}
int FmIoctlsInterface :: set_audio_mode
(
UINT fd, enum AUDIO_MODE mode
)
{
int ret;
struct v4l2_tuner tuner;
tuner.index = 0;
ret = ioctl(fd, VIDIOC_G_TUNER, &tuner);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
tuner.audmode = mode;
ret = ioctl(fd, VIDIOC_S_TUNER, &tuner);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
}
int FmIoctlsInterface :: get_buffer
(
UINT fd, char *buff, UINT len, UINT index
)
{
int ret;
struct v4l2_buffer v4l2_buf;
if((len < STD_BUF_SIZE) || (buff == NULL)) {
return FM_FAILURE;
}else {
memset(&v4l2_buf, 0, sizeof(v4l2_buf));
v4l2_buf.index = index;
v4l2_buf.type = V4L2_BUF_TYPE_PRIVATE;
v4l2_buf.length = STD_BUF_SIZE;
v4l2_buf.m.userptr = (ULINT)buff;
ret = ioctl(fd, VIDIOC_DQBUF, &v4l2_buf);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return v4l2_buf.bytesused;
}
}
}
int FmIoctlsInterface :: set_ext_control
(
UINT fd,
struct v4l2_ext_controls *v4l2_ctls
)
{
int ret;
ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, v4l2_ctls);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __FM_IOCTL_INTERFACE_H__
#define __FM_IOCTL_INTERFACE_H__
#include "FmConst.h"
#include <linux/videodev2.h>
class FmIoctlsInterface
{
private:
static char const * const LOGTAG;
public:
static int start_fm_patch_dl(UINT fd);
static int close_fm_patch_dl(void);
static int get_cur_freq(UINT fd, long &freq);
static int set_freq(UINT fd, ULINT freq);
static int set_control(UINT fd, UINT id, int val);
static int set_calibration(UINT fd);
static int get_control(UINT fd, UINT id, long &val);
static int start_search(UINT fd, UINT dir);
static int set_band(UINT fd, ULINT low, ULINT high);
static int get_upperband_limit(UINT fd, ULINT &freq);
static int get_lowerband_limit(UINT fd, ULINT &freq);
static int set_audio_mode(UINT fd, enum AUDIO_MODE mode);
static int get_buffer(UINT fd, char *buff, UINT len, UINT index);
static int get_rmssi(UINT fd, long &rmssi);
static int set_ext_control(UINT fd, struct v4l2_ext_controls *v4l2_ctls);
};
//char const *FmIoctlsInterface::LOGTAG = "FmIoctlsInterface";
#endif //__FM_IOCTL_INTERFACE_H__
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "FmPerformanceParams.h"
#include "FmIoctlsInterface.h"
#include <cstdio>
#include <linux/videodev2.h>
#include <utils/Log.h>
signed char FmPerformanceParams :: SetAfRmssiTh
(
UINT fd, unsigned short th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_AF_RMSSI_TH, th);
return ret;
}
signed char FmPerformanceParams :: SetAfRmssiSamplesCnt
(
UINT fd, unsigned char cnt
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_AF_RMSSI_SAMPLES, cnt);
return ret;
}
signed char FmPerformanceParams :: SetGoodChannelRmssiTh
(
UINT fd, signed char th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_GOOD_CH_RMSSI_TH, th);
return ret;
}
signed char FmPerformanceParams :: SetSrchAlgoType
(
UINT fd, unsigned char algo
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_SRCHALGOTYPE, algo);
return ret;
}
signed char FmPerformanceParams :: SetSinrFirstStage
(
UINT fd, signed char th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_SINRFIRSTSTAGE, th);
return ret;
}
signed char FmPerformanceParams :: SetRmssiFirstStage
(
UINT fd, signed char th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_RMSSIFIRSTSTAGE, th);
return ret;
}
signed char FmPerformanceParams :: SetCf0Th12
(
UINT fd, int th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_CF0TH12, th);
return ret;
}
signed char FmPerformanceParams :: SetSinrSamplesCnt
(
UINT fd, unsigned char cnt
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_SINR_SAMPLES, cnt);
return ret;
}
signed char FmPerformanceParams :: SetIntfLowTh
(
UINT fd, unsigned char th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_ON_CHANNEL_THRESHOLD, th);
return ret;
}
signed char FmPerformanceParams :: SetIntfHighTh
(
UINT fd, unsigned char th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_OFF_CHANNEL_THRESHOLD, th);
return ret;
}
signed char FmPerformanceParams :: SetSinrFinalStage
(
UINT fd, signed char th
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_SINR_THRESHOLD, th);
return ret;
}
signed char FmPerformanceParams :: GetAfRmssiTh
(
UINT fd, unsigned short &th
)
{
long int af_rmssi_th;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_AF_RMSSI_TH, af_rmssi_th);
if(ret == FM_SUCCESS) {
th = af_rmssi_th;
}
return ret;
}
signed char FmPerformanceParams :: GetAfRmssiSamplesCnt
(
UINT fd, unsigned char &cnt
)
{
long int af_samples_cnt;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_AF_RMSSI_SAMPLES, af_samples_cnt);
if(ret == FM_SUCCESS) {
cnt = af_samples_cnt;
}
return ret;
}
signed char FmPerformanceParams :: GetGoodChannelRmssiTh
(
UINT fd, signed char &th
)
{
long int gd_chan_rmssi_th;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_GOOD_CH_RMSSI_TH, gd_chan_rmssi_th);
if(ret == FM_SUCCESS) {
th = gd_chan_rmssi_th;
}
return ret;
}
signed char FmPerformanceParams :: GetSrchAlgoType
(
UINT fd, unsigned char &algo
)
{
long int srch_algo_type;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_SRCHALGOTYPE, srch_algo_type);
if(ret == FM_SUCCESS) {
algo = srch_algo_type;
}
return ret;
}
signed char FmPerformanceParams :: GetSinrFirstStage
(
UINT fd, signed char &th
)
{
long int sinr_first_stage;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_SINRFIRSTSTAGE, sinr_first_stage);
if(ret == FM_SUCCESS) {
th = sinr_first_stage;
}
return ret;
}
signed char FmPerformanceParams :: GetRmssiFirstStage
(
UINT fd, signed char &th
)
{
long int rmssi_first_stage;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_RMSSIFIRSTSTAGE, rmssi_first_stage);
if(ret == FM_SUCCESS) {
th = rmssi_first_stage;
}
return ret;
}
signed char FmPerformanceParams :: GetCf0Th12
(
UINT fd, int &th
)
{
long int cf0th12;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_CF0TH12, cf0th12);
if(ret == FM_SUCCESS) {
th = cf0th12;
}
return ret;
}
signed char FmPerformanceParams :: GetSinrSamplesCnt
(
UINT fd, unsigned char &cnt
)
{
long int sinr_samples_cnt;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_SINR_SAMPLES, sinr_samples_cnt);
if(ret == FM_SUCCESS) {
cnt = sinr_samples_cnt;
}
return ret;
}
signed char FmPerformanceParams :: GetIntfLowTh
(
UINT fd, unsigned char &th
)
{
long int intf_low_th;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_ON_CHANNEL_THRESHOLD, intf_low_th);
if(ret == FM_SUCCESS) {
th = intf_low_th;
}
return ret;
}
signed char FmPerformanceParams :: GetIntfHighTh
(
UINT fd, unsigned char &th
)
{
long int intf_high_th;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_OFF_CHANNEL_THRESHOLD, intf_high_th);
if(ret == FM_SUCCESS) {
th = intf_high_th;
}
return ret;
}
signed char FmPerformanceParams :: GetIntfDet
(
UINT fd, unsigned char &th
)
{
long int int_det;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_INTDET, int_det);
if(ret == FM_SUCCESS) {
th = int_det;
}
return ret;
}
signed char FmPerformanceParams :: GetSinrFinalStage
(
UINT fd, signed char &th
)
{
signed char ret = FM_FAILURE;
long int sinr;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_SINR_THRESHOLD, sinr);
if(ret == FM_SUCCESS) {
th = sinr;
}
return ret;
}
signed char FmPerformanceParams :: SetHybridSrchList
(
UINT fd,
unsigned int *freqs,
signed char *sinrs,
unsigned int n
)
{
struct v4l2_ext_control ext_ctl;
struct v4l2_ext_controls v4l2_ctls;
unsigned int freq;
signed char sinr;
unsigned int size = 0;
char *data = NULL;
signed char ret = FM_FAILURE;
if(n <= 0) {
return ret;
}
data = new char[(n * 3 + 3)];
if(data != NULL) {
data[size++] = 0x40;
data[size++] = ((n * 3) + 1);
data[size++] = n;
while((size < (n * 3 + 2)) && (freqs != NULL)
&& (sinrs != NULL)) {
freq = (*freqs - 76000) / 50;
data[size++] = (freq & 0xff);
data[size++] = ((freq >> 8) & 0xff);
data[size++] = *sinrs;
freqs++;
sinrs++;
}
if(size == (n * 3 + 3)) {
ext_ctl.id = V4L2_CID_PRV_IRIS_WRITE_DEFAULT;
ext_ctl.string = data;
ext_ctl.size = size;
v4l2_ctls.ctrl_class = V4L2_CTRL_CLASS_USER;
v4l2_ctls.count = 1;
v4l2_ctls.controls = &ext_ctl;
ret = FmIoctlsInterface::set_ext_control(fd, &v4l2_ctls);
if(ret == FM_SUCCESS) {
ALOGE("hybrid srch list sent successfully\n");
}else {
ALOGE("hybrid srch list setting failed\n");
}
}
}
delete []data;
return ret;
}
/*
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __FM_PERFORMANCE_PARAMS_H__
#define __FM_PERFORMANCE_PARAMS_H__
#include "FmConst.h"
class FmPerformanceParams
{
private:
public:
signed char SetAfRmssiTh(UINT fd, unsigned short th);
signed char SetAfRmssiSamplesCnt(UINT fd, unsigned char cnt);
signed char SetGoodChannelRmssiTh(UINT fd, signed char th);
signed char SetSrchAlgoType(UINT fd, unsigned char algo);
signed char SetSinrFirstStage(UINT fd, signed char th);
signed char SetRmssiFirstStage(UINT fd, signed char th);
signed char SetCf0Th12(UINT fd, int th);
signed char SetSinrSamplesCnt(UINT fd, unsigned char cnt);
signed char SetIntfLowTh(UINT fd, unsigned char th);
signed char SetIntfHighTh(UINT fd, unsigned char th);
signed char SetSinrFinalStage(UINT fd, signed char th);
signed char SetHybridSrchList(UINT fd, unsigned int *freqs, signed char *sinrs, unsigned int n);
signed char GetAfRmssiTh(UINT fd, unsigned short &th);
signed char GetAfRmssiSamplesCnt(UINT fd, unsigned char &cnt);
signed char GetGoodChannelRmssiTh(UINT fd, signed char &th);
signed char GetSrchAlgoType(UINT fd, unsigned char &algo);
signed char GetSinrFirstStage(UINT fd, signed char &th);
signed char GetRmssiFirstStage(UINT fd, signed char &th);
signed char GetCf0Th12(UINT fd, int &th);
signed char GetSinrSamplesCnt(UINT fd, unsigned char &cnt);
signed char GetIntfLowTh(UINT fd, unsigned char &th);
signed char GetIntfHighTh(UINT fd, unsigned char &th);
signed char GetIntfDet(UINT fd, unsigned char &th);
signed char GetSinrFinalStage(UINT fd, signed char &th);
};
#endif //__FM_PERFORMANCE_PARAMS_H__
This diff is collapsed.
...@@ -290,4 +290,5 @@ class FmReceiverJNI { ...@@ -290,4 +290,5 @@ class FmReceiverJNI {
* {@link #FM_JNI_FAILURE} * {@link #FM_JNI_FAILURE}
*/ */
static native int setSpurDataNative(int fd, short buff[], int len); static native int setSpurDataNative(int fd, short buff[], int len);
static native void configurePerformanceParams(int fd);
} }
/* /*
* Copyright (c) 2009,2012-2013, The Linux Foundation. All rights reserved. * Copyright (c) 2009,2012-2014, The Linux Foundation. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -91,6 +91,7 @@ class FmRxEventListner { ...@@ -91,6 +91,7 @@ class FmRxEventListner {
FmTransceiver.setFMPowerState(FmTransceiver.FMState_Rx_Turned_On); FmTransceiver.setFMPowerState(FmTransceiver.FMState_Rx_Turned_On);
Log.v(TAG, "RxEvtList: CURRENT-STATE : FMRxStarting ---> NEW-STATE : FMRxOn"); Log.v(TAG, "RxEvtList: CURRENT-STATE : FMRxStarting ---> NEW-STATE : FMRxOn");
cb.FmRxEvEnableReceiver(); cb.FmRxEvEnableReceiver();
FmReceiverJNI.configurePerformanceParams(fd);
} }
else if (FmTransceiver.getFMPowerState() == FmTransceiver.subPwrLevel_FMTurning_Off) { else if (FmTransceiver.getFMPowerState() == FmTransceiver.subPwrLevel_FMTurning_Off) {
/*Set the state as FMOff */ /*Set the state as FMOff */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment