Loading jni/fmr/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ cc_library_shared { }), shared_libs: [ "libbase", "libcutils", "libdl", "liblog", Loading jni/fmr/fm.h +3 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,9 @@ enum { // seek threshold #define FM_SEEKTH_LEVEL_DEFAULT 4 #define RSSI_TH -296 #define FM_NOISE_FLOOR_OFFSET 10 struct fm_tune_parm { uint8_t err; uint8_t band; Loading jni/fmr/fmr.h +5 −11 Original line number Diff line number Diff line Loading @@ -66,18 +66,12 @@ #define FM_DEV_NAME "/dev/fm" #define FM_RDS_PS_LEN 8 #define FMR_MAX_FAKE_CHANS 6 struct fm_fake_channel { int freq; int rssi_th; int reserve; }; struct fm_fake_channel_t { int size; struct fm_fake_channel *chan; }; struct CUST_cfg_ds Loading @@ -92,7 +86,9 @@ struct CUST_cfg_ds int32_t scan_sort; int32_t short_ana_sup; int32_t rssi_th_l2; struct fm_fake_channel_t *fake_chan; int32_t fake_channels; bool noise_floor_detect; struct fm_fake_channel fake_chan[FMR_MAX_FAKE_CHANS]; }; struct fm_cbk_tbl { Loading Loading @@ -131,10 +127,8 @@ struct fmr_ds { uint16_t cur_freq; uint16_t backup_freq; void *priv; void *custom_handler; struct CUST_cfg_ds cfg_data; struct fm_cbk_tbl tbl; CUST_func_type get_cfg; void *init_handler; init_func_type init_func; RDSData_Struct rds; Loading Loading @@ -184,7 +178,7 @@ void FMR_seterr(int err); //fmr_core.cpp int FMR_init(void); int FMR_get_cfgs(int idx); void FMR_get_cfgs(int idx); int FMR_open_dev(int idx); int FMR_close_dev(int idx); int FMR_pwr_up(int idx, int freq); Loading jni/fmr/fmr_core.cpp +79 −75 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ #include "fmr.h" #include <sstream> #include <android-base/properties.h> #ifdef LOG_TAG #undef LOG_TAG #endif Loading @@ -47,37 +50,45 @@ struct fmr_ds *pfmr_data[FMR_MAX_IDX] = {0}; #define FMR_seek_space(idx) ((pfmr_data[idx])->cfg_data.seek_space) #define FMR_max_scan_num(idx) ((pfmr_data[idx])->cfg_data.max_scan_num) #define FMR_cbk_tbl(idx) ((pfmr_data[idx])->tbl) #define FMR_cust_hdler(idx) ((pfmr_data[idx])->custom_handler) #define FMR_get_cfg(idx) ((pfmr_data[idx])->get_cfg) int FMR_get_cfgs(int idx) #define FM_PROP_PREFIX "ro.fm." using ::android::base::GetProperty; using ::android::base::GetIntProperty; using ::android::base::GetBoolProperty; void FMR_get_cfgs(int idx) { int ret = -1; FMR_cust_hdler(idx) = NULL; FMR_get_cfg(idx) = NULL; FMR_cust_hdler(idx) = dlopen(CUST_LIB_NAME, RTLD_NOW); if (FMR_cust_hdler(idx) == NULL) { LOGE("%s failed, %s\n", __FUNCTION__, dlerror()); //FMR_seterr(ERR_LD_LIB); } else { *(void **) (&FMR_get_cfg(idx)) = dlsym(FMR_cust_hdler(idx), "CUST_get_cfg"); if (FMR_get_cfg(idx) == NULL) { LOGE("%s failed, %s\n", __FUNCTION__, dlerror()); //FMR_seterr(ERR_FIND_CUST_FNUC); } else { LOGI("Go to run cust function\n"); (*FMR_get_cfg(idx))(&(pfmr_data[idx]->cfg_data)); LOGI("OK\n"); ret = 0; std::istringstream is; struct CUST_cfg_ds* cfg = &(pfmr_data[idx]->cfg_data); cfg->chip = GetIntProperty(FM_PROP_PREFIX "chip", 0); cfg->band = GetIntProperty(FM_PROP_PREFIX "band", 0); cfg->low_band = GetIntProperty(FM_PROP_PREFIX "low_band", 0); cfg->high_band = GetIntProperty(FM_PROP_PREFIX "high_band", 0); cfg->seek_space = GetIntProperty(FM_PROP_PREFIX "seek_space", 0); cfg->max_scan_num = GetIntProperty(FM_PROP_PREFIX "max_scan_num", 0); cfg->seek_lev = GetIntProperty(FM_PROP_PREFIX "seek_lev", 0); cfg->scan_sort = GetIntProperty(FM_PROP_PREFIX "scan_sort", 0); cfg->short_ana_sup = GetIntProperty(FM_PROP_PREFIX "short_ana_sup", 0); cfg->rssi_th_l2 = GetIntProperty(FM_PROP_PREFIX "rssi_th_l2", 0); cfg->noise_floor_detect = GetBoolProperty(FM_PROP_PREFIX "noise_floor_detect", 0); cfg->fake_channels = GetIntProperty(FM_PROP_PREFIX "fake_chans", 0); if (cfg->fake_channels > FMR_MAX_FAKE_CHANS) { LOGE("%s: fake_chan.size > FMR_MAX_FAKE_CHANS", __FUNCTION__); return; } //dlclose(FMR_cust_hdler(idx)); FMR_cust_hdler(idx) = NULL; FMR_get_cfg(idx) = NULL; for (int i = 0; i < cfg->fake_channels; i++) { struct fm_fake_channel *chan = &cfg->fake_chan[i]; std::string property = FM_PROP_PREFIX "fake_chan_" + std::to_string(i); is = std::istringstream(GetProperty(property, "")); is >> chan->freq >> chan->rssi_th; } LOGI("%s successfully. chip: 0x%x, lband: %d, hband: %d, seek_space: %d, max_scan_num: %d\n", __FUNCTION__, FMR_chip(idx), FMR_low_band(idx), FMR_high_band(idx), FMR_seek_space(idx), FMR_max_scan_num(idx)); return ret; LOGI("%s successfully. chip: 0x%x, lband: %d, hband: %d, seek_space: %d, max_scan_num: %d\n", __FUNCTION__, FMR_chip(idx), FMR_low_band(idx), FMR_high_band(idx), FMR_seek_space(idx), FMR_max_scan_num(idx)); } int FMR_chk_cfg_data(int idx __unused) Loading Loading @@ -108,11 +119,7 @@ int FMR_init() pfmr_data[idx] = &fmr_data; memset(pfmr_data[idx], 0, sizeof(struct fmr_ds)); if (FMR_get_cfgs(idx) < 0) { LOGI("FMR_get_cfgs failed\n"); goto fail; } FMR_get_cfgs(idx); if (FMR_chk_cfg_data(idx) < 0) { LOGI("FMR_chk_cfg_data failed\n"); goto fail; Loading Loading @@ -274,14 +281,14 @@ fm_bool FMR_DensenseDetect(fm_s32 idx, fm_u16 ChannelNo, fm_s32 RSSI) fm_bool FMR_SevereDensense(fm_u16 ChannelNo, fm_s32 RSSI) { fm_s32 i = 0; struct fm_fake_channel_t *chan_info = fmr_data.cfg_data.fake_chan; struct CUST_cfg_ds *cfg = &fmr_data.cfg_data; ChannelNo /= 10; for (i=0; i<chan_info->size; i++) { if (ChannelNo == chan_info->chan[i].freq) { for (i = 0; i < cfg->fake_channels; i++) { if (ChannelNo == cfg->fake_chan[i].freq) { //if (RSSI < FM_SEVERE_RSSI_TH) if (RSSI < chan_info->chan[i].rssi_th) { if (RSSI < cfg->fake_chan[i].rssi_th) { LOGI(" SevereDensense[%d] RSSI[%d]\n", ChannelNo,RSSI); return fm_true; } else { Loading @@ -291,7 +298,7 @@ fm_bool FMR_SevereDensense(fm_u16 ChannelNo, fm_s32 RSSI) } return fm_false; } #if (FMR_NOISE_FLOORT_DETECT==1) /*return TRUE:get noise floor freq*/ fm_bool FMR_NoiseFloorDetect(fm_bool *rF, fm_s32 rssi, fm_s32 *F_rssi) { Loading @@ -310,7 +317,6 @@ fm_bool FMR_NoiseFloorDetect(fm_bool *rF, fm_s32 rssi, fm_s32 *F_rssi) } return fm_false; } #endif /*check the cur_freq->freq is valid or not return fm_true : need check cur_freq->valid Loading Loading @@ -579,13 +585,11 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha static struct fm_cqi SortData[CQI_CH_NUM_MAX]; fm_bool LastExist = fm_false; struct fm_cqi swap; #if (FMR_NOISE_FLOORT_DETECT==1) fm_s32 Pacc = 0, Nacc = 0; fm_s32 NF = 0; fm_bool F[3] = {fm_false, fm_false, fm_false}; fm_s32 F_Rssi[3] = {0}; fm_u8 NF_Idx = 0; #endif memset(SortData, 0, CQI_CH_NUM_MAX*sizeof(struct fm_cqi)); LOGI("band_channel_no=[%d], seek_space=%d, start freq=%d\n", band_channel_no,seek_space,Start_Freq); Loading @@ -604,9 +608,9 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha continue; } if (cur_freq.valid == fm_true)/*get valid channel*/ { #if (FMR_NOISE_FLOORT_DETECT==1) if (fmr_data.cfg_data.noise_floor_detect) memset(F, fm_false, sizeof(F)); #endif if (FMR_DensenseDetect(idx, cur_freq.freq, cur_freq.rssi) == fm_true) { LOGI("desense channel detected:[%d] \n", cur_freq.freq); LastExist = fm_false; Loading Loading @@ -639,7 +643,7 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha LOGI("Num++:[%d] \n", Num); } } else { #if (FMR_NOISE_FLOORT_DETECT==1) if (fmr_data.cfg_data.noise_floor_detect) { if (FMR_DensenseDetect(idx, cur_freq.freq, cur_freq.rssi) == fm_false) { if (FMR_NoiseFloorDetect(F, cur_freq.rssi, F_Rssi) == fm_true) { Pacc += F_Rssi[1]; Loading @@ -656,10 +660,10 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha } else { memset(F, fm_false, sizeof(F)); } #endif } LastExist = fm_false; } #if (FMR_NOISE_FLOORT_DETECT==1) if (fmr_data.cfg_data.noise_floor_detect) { if (((i%NF_Space) == 0) && (i != 0)) { if (Nacc > 0) { NF = Pacc/Nacc; Loading @@ -677,7 +681,7 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha NF_Idx = j; LOGI("FM Noise FLoor NF_Idx[%d] \n", NF_Idx); } #endif } } LOGI("get channel no.[%d] \n", Num); if (Num == 0)/*get nothing*/ { Loading Loading
jni/fmr/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ cc_library_shared { }), shared_libs: [ "libbase", "libcutils", "libdl", "liblog", Loading
jni/fmr/fm.h +3 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,9 @@ enum { // seek threshold #define FM_SEEKTH_LEVEL_DEFAULT 4 #define RSSI_TH -296 #define FM_NOISE_FLOOR_OFFSET 10 struct fm_tune_parm { uint8_t err; uint8_t band; Loading
jni/fmr/fmr.h +5 −11 Original line number Diff line number Diff line Loading @@ -66,18 +66,12 @@ #define FM_DEV_NAME "/dev/fm" #define FM_RDS_PS_LEN 8 #define FMR_MAX_FAKE_CHANS 6 struct fm_fake_channel { int freq; int rssi_th; int reserve; }; struct fm_fake_channel_t { int size; struct fm_fake_channel *chan; }; struct CUST_cfg_ds Loading @@ -92,7 +86,9 @@ struct CUST_cfg_ds int32_t scan_sort; int32_t short_ana_sup; int32_t rssi_th_l2; struct fm_fake_channel_t *fake_chan; int32_t fake_channels; bool noise_floor_detect; struct fm_fake_channel fake_chan[FMR_MAX_FAKE_CHANS]; }; struct fm_cbk_tbl { Loading Loading @@ -131,10 +127,8 @@ struct fmr_ds { uint16_t cur_freq; uint16_t backup_freq; void *priv; void *custom_handler; struct CUST_cfg_ds cfg_data; struct fm_cbk_tbl tbl; CUST_func_type get_cfg; void *init_handler; init_func_type init_func; RDSData_Struct rds; Loading Loading @@ -184,7 +178,7 @@ void FMR_seterr(int err); //fmr_core.cpp int FMR_init(void); int FMR_get_cfgs(int idx); void FMR_get_cfgs(int idx); int FMR_open_dev(int idx); int FMR_close_dev(int idx); int FMR_pwr_up(int idx, int freq); Loading
jni/fmr/fmr_core.cpp +79 −75 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ #include "fmr.h" #include <sstream> #include <android-base/properties.h> #ifdef LOG_TAG #undef LOG_TAG #endif Loading @@ -47,37 +50,45 @@ struct fmr_ds *pfmr_data[FMR_MAX_IDX] = {0}; #define FMR_seek_space(idx) ((pfmr_data[idx])->cfg_data.seek_space) #define FMR_max_scan_num(idx) ((pfmr_data[idx])->cfg_data.max_scan_num) #define FMR_cbk_tbl(idx) ((pfmr_data[idx])->tbl) #define FMR_cust_hdler(idx) ((pfmr_data[idx])->custom_handler) #define FMR_get_cfg(idx) ((pfmr_data[idx])->get_cfg) int FMR_get_cfgs(int idx) #define FM_PROP_PREFIX "ro.fm." using ::android::base::GetProperty; using ::android::base::GetIntProperty; using ::android::base::GetBoolProperty; void FMR_get_cfgs(int idx) { int ret = -1; FMR_cust_hdler(idx) = NULL; FMR_get_cfg(idx) = NULL; FMR_cust_hdler(idx) = dlopen(CUST_LIB_NAME, RTLD_NOW); if (FMR_cust_hdler(idx) == NULL) { LOGE("%s failed, %s\n", __FUNCTION__, dlerror()); //FMR_seterr(ERR_LD_LIB); } else { *(void **) (&FMR_get_cfg(idx)) = dlsym(FMR_cust_hdler(idx), "CUST_get_cfg"); if (FMR_get_cfg(idx) == NULL) { LOGE("%s failed, %s\n", __FUNCTION__, dlerror()); //FMR_seterr(ERR_FIND_CUST_FNUC); } else { LOGI("Go to run cust function\n"); (*FMR_get_cfg(idx))(&(pfmr_data[idx]->cfg_data)); LOGI("OK\n"); ret = 0; std::istringstream is; struct CUST_cfg_ds* cfg = &(pfmr_data[idx]->cfg_data); cfg->chip = GetIntProperty(FM_PROP_PREFIX "chip", 0); cfg->band = GetIntProperty(FM_PROP_PREFIX "band", 0); cfg->low_band = GetIntProperty(FM_PROP_PREFIX "low_band", 0); cfg->high_band = GetIntProperty(FM_PROP_PREFIX "high_band", 0); cfg->seek_space = GetIntProperty(FM_PROP_PREFIX "seek_space", 0); cfg->max_scan_num = GetIntProperty(FM_PROP_PREFIX "max_scan_num", 0); cfg->seek_lev = GetIntProperty(FM_PROP_PREFIX "seek_lev", 0); cfg->scan_sort = GetIntProperty(FM_PROP_PREFIX "scan_sort", 0); cfg->short_ana_sup = GetIntProperty(FM_PROP_PREFIX "short_ana_sup", 0); cfg->rssi_th_l2 = GetIntProperty(FM_PROP_PREFIX "rssi_th_l2", 0); cfg->noise_floor_detect = GetBoolProperty(FM_PROP_PREFIX "noise_floor_detect", 0); cfg->fake_channels = GetIntProperty(FM_PROP_PREFIX "fake_chans", 0); if (cfg->fake_channels > FMR_MAX_FAKE_CHANS) { LOGE("%s: fake_chan.size > FMR_MAX_FAKE_CHANS", __FUNCTION__); return; } //dlclose(FMR_cust_hdler(idx)); FMR_cust_hdler(idx) = NULL; FMR_get_cfg(idx) = NULL; for (int i = 0; i < cfg->fake_channels; i++) { struct fm_fake_channel *chan = &cfg->fake_chan[i]; std::string property = FM_PROP_PREFIX "fake_chan_" + std::to_string(i); is = std::istringstream(GetProperty(property, "")); is >> chan->freq >> chan->rssi_th; } LOGI("%s successfully. chip: 0x%x, lband: %d, hband: %d, seek_space: %d, max_scan_num: %d\n", __FUNCTION__, FMR_chip(idx), FMR_low_band(idx), FMR_high_band(idx), FMR_seek_space(idx), FMR_max_scan_num(idx)); return ret; LOGI("%s successfully. chip: 0x%x, lband: %d, hband: %d, seek_space: %d, max_scan_num: %d\n", __FUNCTION__, FMR_chip(idx), FMR_low_band(idx), FMR_high_band(idx), FMR_seek_space(idx), FMR_max_scan_num(idx)); } int FMR_chk_cfg_data(int idx __unused) Loading Loading @@ -108,11 +119,7 @@ int FMR_init() pfmr_data[idx] = &fmr_data; memset(pfmr_data[idx], 0, sizeof(struct fmr_ds)); if (FMR_get_cfgs(idx) < 0) { LOGI("FMR_get_cfgs failed\n"); goto fail; } FMR_get_cfgs(idx); if (FMR_chk_cfg_data(idx) < 0) { LOGI("FMR_chk_cfg_data failed\n"); goto fail; Loading Loading @@ -274,14 +281,14 @@ fm_bool FMR_DensenseDetect(fm_s32 idx, fm_u16 ChannelNo, fm_s32 RSSI) fm_bool FMR_SevereDensense(fm_u16 ChannelNo, fm_s32 RSSI) { fm_s32 i = 0; struct fm_fake_channel_t *chan_info = fmr_data.cfg_data.fake_chan; struct CUST_cfg_ds *cfg = &fmr_data.cfg_data; ChannelNo /= 10; for (i=0; i<chan_info->size; i++) { if (ChannelNo == chan_info->chan[i].freq) { for (i = 0; i < cfg->fake_channels; i++) { if (ChannelNo == cfg->fake_chan[i].freq) { //if (RSSI < FM_SEVERE_RSSI_TH) if (RSSI < chan_info->chan[i].rssi_th) { if (RSSI < cfg->fake_chan[i].rssi_th) { LOGI(" SevereDensense[%d] RSSI[%d]\n", ChannelNo,RSSI); return fm_true; } else { Loading @@ -291,7 +298,7 @@ fm_bool FMR_SevereDensense(fm_u16 ChannelNo, fm_s32 RSSI) } return fm_false; } #if (FMR_NOISE_FLOORT_DETECT==1) /*return TRUE:get noise floor freq*/ fm_bool FMR_NoiseFloorDetect(fm_bool *rF, fm_s32 rssi, fm_s32 *F_rssi) { Loading @@ -310,7 +317,6 @@ fm_bool FMR_NoiseFloorDetect(fm_bool *rF, fm_s32 rssi, fm_s32 *F_rssi) } return fm_false; } #endif /*check the cur_freq->freq is valid or not return fm_true : need check cur_freq->valid Loading Loading @@ -579,13 +585,11 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha static struct fm_cqi SortData[CQI_CH_NUM_MAX]; fm_bool LastExist = fm_false; struct fm_cqi swap; #if (FMR_NOISE_FLOORT_DETECT==1) fm_s32 Pacc = 0, Nacc = 0; fm_s32 NF = 0; fm_bool F[3] = {fm_false, fm_false, fm_false}; fm_s32 F_Rssi[3] = {0}; fm_u8 NF_Idx = 0; #endif memset(SortData, 0, CQI_CH_NUM_MAX*sizeof(struct fm_cqi)); LOGI("band_channel_no=[%d], seek_space=%d, start freq=%d\n", band_channel_no,seek_space,Start_Freq); Loading @@ -604,9 +608,9 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha continue; } if (cur_freq.valid == fm_true)/*get valid channel*/ { #if (FMR_NOISE_FLOORT_DETECT==1) if (fmr_data.cfg_data.noise_floor_detect) memset(F, fm_false, sizeof(F)); #endif if (FMR_DensenseDetect(idx, cur_freq.freq, cur_freq.rssi) == fm_true) { LOGI("desense channel detected:[%d] \n", cur_freq.freq); LastExist = fm_false; Loading Loading @@ -639,7 +643,7 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha LOGI("Num++:[%d] \n", Num); } } else { #if (FMR_NOISE_FLOORT_DETECT==1) if (fmr_data.cfg_data.noise_floor_detect) { if (FMR_DensenseDetect(idx, cur_freq.freq, cur_freq.rssi) == fm_false) { if (FMR_NoiseFloorDetect(F, cur_freq.rssi, F_Rssi) == fm_true) { Pacc += F_Rssi[1]; Loading @@ -656,10 +660,10 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha } else { memset(F, fm_false, sizeof(F)); } #endif } LastExist = fm_false; } #if (FMR_NOISE_FLOORT_DETECT==1) if (fmr_data.cfg_data.noise_floor_detect) { if (((i%NF_Space) == 0) && (i != 0)) { if (Nacc > 0) { NF = Pacc/Nacc; Loading @@ -677,7 +681,7 @@ int FMR_scan_Channels(int idx, uint16_t *scan_tbl, int *max_cnt, fm_s32 band_cha NF_Idx = j; LOGI("FM Noise FLoor NF_Idx[%d] \n", NF_Idx); } #endif } } LOGI("get channel no.[%d] \n", Num); if (Num == 0)/*get nothing*/ { Loading