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

libfmjni: Implement hal layer

Implement HAL layer that can be plugged in
with Android FM APP to get fm functionalities.

Change-Id: Id16d37a320fdbacb505ba7ecc431622db17bd4d7
parent ee21b948
Branches
No related tags found
No related merge requests found
......@@ -20,6 +20,8 @@ LOCAL_PATH := $(LOCAL_DIR_PATH)
include $(LOCAL_PATH)/fmapp2/Android.mk
LOCAL_PATH := $(LOCAL_DIR_PATH)
include $(LOCAL_PATH)/FMRecord/Android.mk
LOCAL_PATH := $(LOCAL_DIR_PATH)
include $(LOCAL_PATH)/libfm_jni/Android.mk
endif # is-vendor-board-platform
endif # BOARD_HAVE_QCOM_FM
......
ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM)))
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
FmIoctlsInterface.cpp \
ConfigFmThs.cpp \
FmPerformanceParams.cpp \
ConfFileParser.cpp \
FmRadioController.cpp \
LibfmJni.cpp
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) \
frameworks/base/include/media
LOCAL_SHARED_LIBRARIES := \
libcutils \
libdl \
libmedia \
libnativehelper \
#LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
#LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
LOCAL_MODULE := libfmjni
include $(BUILD_SHARED_LIBRARY)
endif
This diff is collapsed.
/*
Copyright (c) 2015, 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 "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) 2015, 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 "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 "FM_Const.h"
#include "ConfFileParser.h"
#define MAX_GRPS 4
#define MAX_SRCH_PARAMS 8
#define MAX_AF_PARAMS 3
#define MAX_BAND_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
#define FM_DE_EMP75 0
#define FM_DE_EMP50 1
#define FM_CHSPACE_200_KHZ 0
#define FM_CHSPACE_100_KHZ 1
#define FM_CHSPACE_50_KHZ 2
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,
BAND_CFG,
};
enum BAND_CFG_PARAMS
{
RADIO_BAND,
EMPHASIS,
CHANNEL_SPACING,
};
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},
{"BANDCONFIG", BAND_CFG},
{"HYBRIDSEARCHLIST", HYBRD_SRCH_LIST},
{"SEARCHTHRESHOLDS", SRCH_THS},
};
static struct NAME_MAP BAND_CFG_MAP[] =
{
{"ChSpacing", CHANNEL_SPACING},
{"Emphasis", EMPHASIS},
{"RadioBand", RADIO_BAND},
};
//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);
void set_band_cfgs(UINT fd);
public:
ConfigFmThs();
~ConfigFmThs();
void SetRxSearchAfThs(const char *file, UINT fd);
};
#endif //__CONFIG_FM_THS_H__
/*
Copyright (c) 2015, 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 "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__
//return related
#define IOCTL_SUCC 0
#define FM_SUCCESS 0
#define FM_FAILURE -1
#define PROP_SET_SUCC 0
#define MAX_VER_STR_LEN 40
#define INIT_LOOP_CNT 45
//Time in us
#define INIT_WAIT_TIMEOUT 200000
#define RDS_AVL_INT_WAIT_TIMEOUT 200000
//Time in secs
#define READY_EVENT_TIMEOUT 5
#define SCAN_COMPL_TIMEOUT 1280
#define TUNE_EVENT_TIMEOUT 2
#define SEEK_COMPL_TIMEOUT 60
#define FM_SCAN_CH_SIZE_MAX 25
#define TUNE_MULT 16
#define CAL_DATA_SIZE 23
#define STD_BUF_SIZE 256
//RDS GROUPS
#define GRP_3A 64
//data related to enabling various
//rds data RT, PS, AF LIST, AF JMP
#define RDS_GRP_RT_EN 1
#define RDS_GRP_PS_EN 2
#define RDS_AF_JMP_LIST_EN 8
#define RDS_GRP_AFJMP_EN 16
//Data for PS received
#define MAX_PS_LEN 8
#define PS_STR_NUM_IND 0
#define PS_DATA_OFFSET_IND 5
//RT related
#define MAX_RT_LEN 64
#define RT_LEN_IND 0
#define RT_DATA_OFFSET_IND 5
#define RT_A_B_FLAG_IND 4
//ERT related
#define ERT_LEN_IND 0
#define ERT_DATA_OFFSET_IND 3
//Common to RT, PS
#define FIRST_CTRL_CHAR 0
#define LAST_CTRL_CHAR 31
#define FIRST_NON_PRNT_CHAR 127
#define SPACE_CHAR 32
//RT PLUS related constanst
#define RT_OR_ERT_IND 1
#define RT_PLUS_TAGS_NUM_IND 0
#define MAX_RT_PLUS_TAGS 2
#define TAGS_DATA_BEGIN_OFFSET 4
#define ITEM_TOGGLE_IND 2
#define ITEM_RUNNING_IND 3
#define DUMMY_TAG_CODE 0
#define FM_RX_RDS_GRP_RT_EBL 1
#define FM_RX_RDS_GRP_PS_EBL 2
#define FM_RX_RDS_GRP_AF_EBL 4
#define FM_RX_RDS_GRP_PS_SIMPLE_EBL 16
#define FREQ_MULT 1000
#define HYBRID_SRCH_DATA_LEN 3
#define HYBRID_SRCH_DATA_INDEX 3
#define HYBRID_SRCH_MODE 0x40
#define STARTING_FREQ 76000
#define FREQ_MULTIPLEX 50
#define NO_OF_BYTES_EACH_FREQ 2
#define EXTRACT_FIRST_BYTE 0x03
#define SRCH_DIV 100
#define AF_SIZE_IDX 6
#define NO_OF_BYTES_AF 4
#define MAX_AF_LIST_SIZE 25
typedef unsigned int UINT;
typedef unsigned long ULINT;
//STRING LITERALS
const char *const FM_MODE_PROP = "hw.fm.mode";
const char *const FM_VERSION_PROP = "hw.fm.version";
const char *const FM_INIT_PROP = "hw.fm.init";
const char *const SCRIPT_START_PROP = "ctl.start";
const char *const FM_SOC_DL_SCRIPT = "fm_dl";
const char *const SCRIPT_STOP_PROP = "ctl.stOP";
const char *const CALIB_DATA_NAME = "/data/app/Riva_fm_cal";
const char *const SOC_PATCH_DL_SCRPT = "fm_dl";
const char *const FM_DEVICE_PATH = "/dev/radio0";
const char *const FM_PERFORMANCE_PARAMS = "/etc/fm/fm_srch_af_th.conf";
const UINT V4L2_CTRL_CLASS_USER = 0x00980000;
const UINT V4L2_CID_BASE = (V4L2_CTRL_CLASS_USER | 0x900);
const UINT V4L2_CID_AUDIO_MUTE = (V4L2_CID_BASE + 9);
const UINT SEARCH_DWELL_TIME = 2;
const UINT SEEK_DWELL_TIME = 0;
//BAND LIMITS
const UINT US_BAND_LOW = 87500;
const UINT US_BAND_HIGH = 108000;
const UINT EU_BAND_LOW = 87500;
const UINT EU_BAND_HIGH = 108000;
const UINT JAP_BAND_STD_LOW = 76000;
const UINT JAP_BAND_STD_HIGH = 90000;
const UINT JAP_BAND_WIDE_LOW = 90000;
const UINT JAP_BAND_WIDE_HIGH = 108000;
const UINT USR_DEF_BAND_LOW = 87500;
const UINT USR_DEF_BAND_HIGH = 108000;
const UINT FM_RX_SRCHLIST_MAX_STATIONS =20;
//RDS standard type
enum RDS_STD
{
RBDS,
RDS,
NO_RDS_RBDS,
};
enum DE_EMPHASIS
{
DE_EMP75,
DE_EMP50,
};
//Band Type
enum FM_REGION
{
BAND_87500_108000 = 1,
BAND_76000_108000,
BAND_76000_90000,
};
enum FM_AUDIO_PATH
{
AUDIO_DIGITAL_PATH,
AUDIO_ANALOG_PATH,
};
enum FM_DEVICE
{
FM_DEV_NONE,
FM_RX,
FM_TX,
};
enum fm_rds_onoff {
FM_RDS_ON,
FM_RDS_OFF,
FM_MAX
};
typedef enum {
FM_LONG_ANA = 0,
FM_SHORT_ANA
} fm_antenna_type;
enum BUFF_INDEXES
{
STATION_LIST_IND,
EVENT_IND,
RT_IND,
PS_IND,
AF_LIST_IND = PS_IND + 2,
RT_PLUS_IND = 11,
ERT_IND,
};
typedef enum {
RDS_EVT_UPDATE = 0x0001,
RDS_EVT_PI_UPDATE = 0x0002,
RDS_EVT_PTY_UPDATE = 0x0004,
RDS_EVT_PS_UPDATE = 0x0008,
RDS_EVT_RT_UPDATE = 0x0040,
RDS_EVT_AF_JUMP = 0x0080,
RDS_EVT_AF_LIST = 0x0100,
RDS_EVT_AF_LIST_UPDATE = 0x0200,
RDS_EVT_RDS_AVL = 0x2000,
RDS_EVT_RDS_NOT_AVL = 0x4000,
} RdsEvts;
enum SEARCH_MODE
{
SEEK_MODE,
SCAN_MODE,
SRCHLIST_MODE_STRONG,
SRCHLIST_MODE_WEAK,
SRCHRDS_MODE_SEEK_PTY,
SRCHRDS_MODE_SCAN_PTY,
SRCHRDS_MODE_SEEK_PI,
SRCHRDS_MODE_SEEK_AF,
SRCHLIST_MODE_STRONGEST,
SRCHLIST_MODE_WEAKEST,
};
enum SEARCH_DIR
{
SEARCH_DOWN,
SEARCH_UP,
};
//CHANNEL SPACING for samsung
enum SS_CHAN_SPACING
{
SS_CHAN_SPACE_200 = 20,
SS_CHAN_SPACE_100 = 10,
SS_CHAN_SPACE_50 = 5,
};
enum CHAN_SPACING
{
CHAN_SPACE_200,
CHAN_SPACE_100,
CHAN_SPACE_50,
};
enum AUDIO_MODE
{
MONO,
STEREO,
};
//HARD MUTE MODE
enum HARD_MUTE_MODE
{
UNMUTE_L_R_CHAN,
MUTE_L_CHAN,
MUTE_R_CHAN,
MUTE_L_R_CHAN,
};
//SOFT MUTE STATES
enum SOFT_MUTE_MODE
{
SMUTE_DISABLED,
SMUTE_ENABLED,
};
//FM EVENTS FROM KERNEL
enum FM_EVENTS
{
READY_EVENT,
TUNE_EVENT,
SEEK_COMPLETE_EVENT,
SCAN_NEXT_EVENT,
RAW_RDS_EVENT,
RT_EVENT,
PS_EVENT,
ERROR_EVENT,
BELOW_TH_EVENT,
ABOVE_TH_EVENT,
STEREO_EVENT,
MONO_EVENT,
RDS_AVAL_EVENT,
RDS_NOT_AVAL_EVENT,
SRCH_LIST_EVENT,
AF_LIST_EVENT,
DISABLED_EVENT = 18,
RDS_GRP_MASK_REQ_EVENT,
RT_PLUS_EVENT,
ERT_EVENT,
AF_JMP_EVENT,
};
//FM STATES
enum fm_states
{
FM_OFF,
FM_OFF_IN_PROGRESS,
FM_ON_IN_PROGRESS,
FM_ON,
FM_TUNE_IN_PROGRESS,
SEEK_IN_PROGRESS,
SCAN_IN_PROGRESS,
};
//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_ANTENNA,
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_BLEND_SINRHI,
V4L2_CID_PRV_IRIS_BLEND_RMSSIHI,
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) 2015, 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 "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 <cutils/properties.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <math.h>
#include <utils/Log.h>
int FmIoctlsInterface :: start_fm_patch_dl
(
UINT fd
)
{
int ret;
int init_success = 0;
char versionStr[MAX_VER_STR_LEN] = {'\0'};
char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
struct v4l2_capability cap;
ALOGE("start_fm_patch_dl = %d\n",fd);
ret = ioctl(fd, VIDIOC_QUERYCAP, &cap);
ALOGE("executed cmd\n");
if(ret == IOCTL_SUCC) {
ret = snprintf(versionStr, MAX_VER_STR_LEN, "%d", cap.version);
if(ret >= MAX_VER_STR_LEN) {
return FM_FAILURE;
}else {
ret = property_set(FM_VERSION_PROP, versionStr);
ALOGE("set versionStr done");
if(ret != PROP_SET_SUCC)
return FM_FAILURE;
ret = property_set(FM_MODE_PROP, "normal");
ALOGE("set FM_MODE_PROP done");
if(ret != PROP_SET_SUCC)
return FM_FAILURE;
ret = property_set(FM_INIT_PROP, "0");
ALOGE("set FM_INIT_PROP done");
if(ret != PROP_SET_SUCC)
return FM_FAILURE;
ret = property_set(SCRIPT_START_PROP, SOC_PATCH_DL_SCRPT);
if(ret != PROP_SET_SUCC)
return FM_FAILURE;
for(int i = 0; i < INIT_LOOP_CNT; i++) {
property_get(FM_INIT_PROP, prop_value, NULL);
if (strcmp(prop_value, "1") == 0) {
init_success = 1;
break;
}else {
usleep(INIT_WAIT_TIMEOUT);
}
}
if(!init_success) {
property_set(SCRIPT_STOP_PROP, SOC_PATCH_DL_SCRPT);
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
}else {
return FM_FAILURE;
}
}
int FmIoctlsInterface :: close_fm_patch_dl
(
void
)
{
int ret;
ret = property_set(SCRIPT_STOP_PROP, SOC_PATCH_DL_SCRPT);
if(ret != PROP_SET_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
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;
ret = ioctl(fd, VIDIOC_S_CTRL, &control);
if(ret != IOCTL_SUCC) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}
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);
return FM_FAILURE;
}
fclose(cal_fp);
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) {
return FM_FAILURE;
}else {
return FM_SUCCESS;
}
}else {
return FM_FAILURE;
}
}
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_SUCCESS;
}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);
ALOGE("high freq: %d\n",freq);
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);
ALOGE("low freq: %d\n",freq);
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) 2015, 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 "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 "FM_Const.h"
#include <linux/videodev2.h>
class FmIoctlsInterface
{
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);
};
#endif //__FM_IOCTL_INTERFACE_H__
/*
Copyright (c) 2015, 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 "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 <cstdio>
#include <utils/Log.h>
#include "FmPerformanceParams.h"
#include "FmIoctlsInterface.h"
#include <linux/videodev2.h>
signed char FmPerformanceParams :: SetBand
(
UINT fd, unsigned char band
)
{
signed char ret = FM_FAILURE;
switch(band) {
case BAND_87500_108000:
ret = FmIoctlsInterface::set_band(fd,
87500, 108000);
break;
case BAND_76000_108000:
ret = FmIoctlsInterface::set_band(fd,
76000, 108000);
break;
case BAND_76000_90000:
ret = FmIoctlsInterface::set_band(fd,
76000, 90000);
break;
default:
ALOGE("Band type: %ld is invalid\n", band);
ret = FM_FAILURE;
break;
}
return ret;
}
signed char FmPerformanceParams :: SetEmphsis
(
UINT fd, unsigned char emph
)
{
signed char ret = FM_FAILURE;
switch(emph) {
case DE_EMP75:
case DE_EMP50:
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_EMPHASIS, emph);
break;
default:
ALOGE("invalid de-emphasis value\n");
ret = FM_FAILURE;
break;
}
return ret;
}
signed char FmPerformanceParams :: SetChannelSpacing
(
UINT fd, unsigned char spacing
)
{
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_CHAN_SPACING, spacing);
return ret;
}
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 * HYBRID_SRCH_DATA_LEN + HYBRID_SRCH_DATA_INDEX)];
if(data != NULL) {
data[size++] = HYBRID_SRCH_MODE;
data[size++] = ((n * HYBRID_SRCH_DATA_LEN) + 1);
data[size++] = n;
while((size < (n * HYBRID_SRCH_DATA_LEN + 2)) && (freqs != NULL)
&& (sinrs != NULL)) {
freq = (*freqs - STARTING_FREQ) / FREQ_MULTIPLEX;
data[size++] = (freq & 0xff);
data[size++] = ((freq >> 8) & 0xff);
data[size++] = *sinrs;
freqs++;
sinrs++;
}
if(size == (n * HYBRID_SRCH_DATA_LEN + HYBRID_SRCH_DATA_INDEX)) {
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;
}
signed char FmPerformanceParams :: SetBlendSinr
(
UINT fd, signed char bsinr
)
{
signed char ret = FM_FAILURE;
if ((bsinr >= MIN_BLEND_SINRHI) &&
(bsinr <= MAX_BLEND_SINRHI))
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_IRIS_BLEND_SINRHI, bsinr);
return ret;
}
signed char FmPerformanceParams :: GetBlendSinr
(
UINT fd, signed char &bsinr
)
{
long int blend_sinr_hi;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_IRIS_BLEND_SINRHI, blend_sinr_hi);
if(ret == FM_SUCCESS) {
bsinr = blend_sinr_hi;
}
return ret;
}
signed char FmPerformanceParams :: SetBlendRmssi
(
UINT fd, signed char brmssi
)
{
signed char ret = FM_FAILURE;
if ((brmssi >= MIN_BLEND_RMSSIHI) &&
(brmssi <= MAX_BLEND_RMSSIHI))
ret = FmIoctlsInterface::set_control(fd,
V4L2_CID_PRV_IRIS_BLEND_RMSSIHI, brmssi);
return ret;
}
signed char FmPerformanceParams :: GetBlendRmssi
(
UINT fd, signed char &brmssi
)
{
long int blend_rmssi_hi;
signed char ret = FM_FAILURE;
ret = FmIoctlsInterface::get_control(fd,
V4L2_CID_PRV_IRIS_BLEND_RMSSIHI, blend_rmssi_hi);
if(ret == FM_SUCCESS) {
brmssi = blend_rmssi_hi;
}
return ret;
}
/*
Copyright (c) 2015, 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 "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 "FM_Const.h"
#define MIN_BLEND_SINRHI -128
#define MAX_BLEND_SINRHI 127
#define MIN_BLEND_RMSSIHI -128
#define MAX_BLEND_RMSSIHI 127
class FmPerformanceParams
{
private:
public:
signed char SetBand(UINT fd, unsigned char band);
signed char SetEmphsis(UINT fd, unsigned char emph);
signed char SetChannelSpacing(UINT fd, unsigned char spacing);
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 SetBlendSinr(UINT fd, signed char bsinr);
signed char SetBlendRmssi(UINT fd, signed char brmssi);
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);
signed char GetBlendSinr(UINT fd, signed char &bsinr);
signed char GetBlendRmssi(UINT fd, signed char &brmssi);
};
#endif //__FM_PERFORMANCE_PARAMS_H__
This diff is collapsed.
/*
Copyright (c) 2015, 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 "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_RADIO_CTRL_H__
#define __FM_RADIO_CTRL_H___
#include <pthread.h>
#include <ctime>
class FmRadioController
{
private:
int cur_fm_state;
char af_enabled;
bool seek_scan_canceled;
bool is_rds_support;
bool is_ps_event_received = false;
bool is_rt_event_received = false;
bool is_af_jump_received = false;
bool event_listener_canceled;
pthread_mutex_t mutex_fm_state;
pthread_mutex_t mutex_turn_on_cond;
pthread_mutex_t mutex_seek_compl_cond;
pthread_mutex_t mutex_scan_compl_cond;
pthread_mutex_t mutex_tune_compl_cond;
pthread_cond_t turn_on_cond;
pthread_cond_t seek_compl_cond;
pthread_cond_t scan_compl_cond;
pthread_cond_t tune_compl_cond;
char rds_enabled;
long int prev_freq;
int fd_driver;
pthread_t event_listener_thread;
int SetRdsGrpMask(int mask);
int SetRdsGrpProcessing(int grps);
void handle_enabled_event(void);
void handle_tuned_event(void);
void handle_seek_next_event(void);
void handle_seek_complete_event(void);
void handle_raw_rds_event(void);
void handle_rt_event(void);
void handle_ps_event(void);
void handle_error_event(void);
void handle_below_th_event(void);
void handle_above_th_event(void);
void handle_stereo_event(void);
void handle_mono_event(void);
void handle_rds_aval_event(void);
void handle_rds_not_aval_event(void);
void handle_srch_list_event(void);
void handle_af_list_event(void);
void handle_disabled_event(void);
void handle_rds_grp_mask_req_event(void);
void handle_rt_plus_event(void);
void handle_ert_event(void);
void handle_af_jmp_event(void);
void set_fm_state(int state);
struct timespec set_time_out(int secs);
int GetStationList(uint16_t *scan_tbl, int *max_cnt);
int EnableRDS(void);
int DisableRDS(void);
int EnableAF(void);
int DisableAF(void);
int SetStereo(void);
int SetMono(void);
int MuteOn(void);
int MuteOff(void);
int get_fm_state(void);
long GetCurrentRSSI(void);
bool GetSoftMute(void);
public:
FmRadioController();
~FmRadioController();
int open_dev(void);
int close_dev();
int Pwr_Up(int freq);
int Pwr_Down(void);
long GetChannel(void);
int TuneChannel(long);
bool IsRds_support();
int ScanList(uint16_t *scan_tbl, int *max_cnt);
int Seek(int dir);
int ReadRDS(void);
int Get_ps(char *ps, int *ps_len);
int Get_rt(char *rt, int *rt_len);
int Get_AF_freq(uint16_t *ret_freq);
int SetDeConstant(long );
int SetSoftMute(bool mode);
int Set_mute(bool mute);
int SetBand(long);
int SetChannelSpacing(long);
int Stop_Scan_Seek(void);
int Turn_On_Off_Rds(bool onoff);
int Antenna_Switch(int antenna);
static void* handle_events(void *arg);
bool process_radio_events(int event);
};
#endif
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment