summaryrefslogtreecommitdiff
path: root/src/include/mm_radio_priv_hal.h
blob: a629ad74c7a8dd07bbed10e9d2c7c724e7de86d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * mm_radio_priv_hal.h
 *
 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef __MM_Radio_INTERNAL_H__
#define	__MM_Radio_INTERNAL_H__

/*===========================================================================================
  INCLUDE FILES
========================================================================================== */
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <malloc.h>
#include <pthread.h>
#include <signal.h>

#include <mm_types.h>
#include <mm_message.h>
#include <media/mm_resource_manager.h>
#include <media/sound_manager.h>
#include <media/sound_manager_internal.h>

#include "mm_radio.h"
#include "mm_radio_utils.h"
#include "radio_hal_interface.h"
#include <linux/videodev2.h>

#include <glib.h>

#ifdef __cplusplus
	extern "C" {
#endif

/*===========================================================================================
  GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE
========================================================================================== */

/*---------------------------------------------------------------------------
    GLOBAL #defines:
---------------------------------------------------------------------------*/
#define SAMPLEDELAY					15000

/* si470x dependent define */
#define SYSCONFIG1					4		/* System Configuration 1 */
#define SYSCONFIG1_RDS				0x1000	/* bits 12..12: RDS Enable */
#define SYSCONFIG1_RDS_OFFSET		12		/* bits 12..12: RDS Enable Offset */

#define SYSCONFIG2					5		/* System Configuration 2 */
#define SYSCONFIG2_SEEKTH			0xff00	/* bits 15..08: RSSI Seek Threshold */
#define SYSCONFIG2_SEEKTH_OFFSET	8		/* bits 15..08: RSSI Seek Threshold Offset */

#define SYSCONFIG3					6		/* System Configuration 3 */
#define SYSCONFIG3_SKSNR			0x00f0	/* bits 07..04: Seek SNR Threshold */
#define SYSCONFIG3_SKCNT			0x000f	/* bits 03..00: Seek FM Impulse Detection Threshold */
#define SYSCONFIG3_SKSNR_OFFSET	4		/* bits 07..04: Seek SNR Threshold Offset */
#define SYSCONFIG3_SKCNT_OFFSET	0		/* bits 03..00: Seek FM Impulse Detection Threshold Offset */

#define DEFAULT_CHIP_MODEL			"radio-si470x"

/*---------------------------------------------------------------------------
    GLOBAL CONSTANT DEFINITIONS:
---------------------------------------------------------------------------*/
typedef enum {
	MMRADIO_COMMAND_CREATE = 0,
	MMRADIO_COMMAND_DESTROY,
	MMRADIO_COMMAND_REALIZE,
	MMRADIO_COMMAND_UNREALIZE,
	MMRADIO_COMMAND_START,
	MMRADIO_COMMAND_STOP,
	MMRADIO_COMMAND_START_SCAN,
	MMRADIO_COMMAND_STOP_SCAN,
	MMRADIO_COMMAND_SET_FREQ,
	MMRADIO_COMMAND_GET_FREQ,
	MMRADIO_COMMAND_VOLUME,
	MMRADIO_COMMAND_MUTE,
	MMRADIO_COMMAND_UNMUTE,
	MMRADIO_COMMAND_SEEK,
	MMRADIO_COMMAND_SET_REGION,
	MMRADIO_COMMAND_GET_REGION,
	MMRADIO_COMMAND_SET_VOLUME,
	MMRADIO_COMMAND_GET_VOLUME,
	MMRADIO_COMMAND_NUM
} MMRadioCommand;

/* max and mix frequency types, KHz */
typedef enum {
	MM_RADIO_FREQ_NONE				= 0,
	/* min band types */
	MM_RADIO_FREQ_MIN_76100_KHZ		= 76100,
	MM_RADIO_FREQ_MIN_87500_KHZ		= 87500,
	MM_RADIO_FREQ_MIN_88100_KHZ		= 88100,
	/* max band types */
	MM_RADIO_FREQ_MAX_89900_KHZ		= 89900,
	MM_RADIO_FREQ_MAX_108000_KHZ	= 108000,
} MMRadioFreqTypes;

/* de-emphasis types  */
typedef enum {
	MM_RADIO_DEEMPHASIS_NONE = 0,
	MM_RADIO_DEEMPHASIS_50_US,
	MM_RADIO_DEEMPHASIS_75_US,
} MMRadioDeemphasis;

/* radio region settings */
typedef struct {
	MMRadioRegionType country;
	MMRadioDeemphasis deemphasis;	// unit :  us
	MMRadioFreqTypes band_min;		// <- freq. range, unit : KHz
	MMRadioFreqTypes band_max;		// ->
	int channel_spacing;				// TBD
} MMRadioRegion_t;

typedef struct {
	pthread_t thread;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
	int thread_id;
	bool is_running;
	bool stop;
	bool thread_exit;
} MMRadioThread_t;

typedef enum {
	MM_RADIO_MSG_DESTROY = 0,
	MM_RADIO_MSG_SCAN_INFO,
	MM_RADIO_MSG_SCAN_STOPPED,
	MM_RADIO_MSG_SCAN_FINISHED,
	MM_RADIO_MSG_SEEK_FINISHED,
	MM_RADIO_MSG_STATE_INTERRUPTED,
	MM_RADIO_MSG_NUM
} MMRadioMsgTypes;

typedef struct {
	bool destroy;
	MMRadioMsgTypes msg_type;
	int data;
} mm_radio_msg_t;

typedef enum {
	MM_RADIO_THREAD_MSG = 0,
	MM_RADIO_THREAD_SEEK,
	MM_RADIO_THREAD_SCAN,
	MM_RADIO_THREAD_NUM
} MMRadioThreadTypes;

/*---------------------------------------------------------------------------
    GLOBAL DATA TYPE DEFINITIONS:
---------------------------------------------------------------------------*/

typedef struct {
	/* radio state */
	int current_state;
	int old_state;
	int pending_state;

	int cmd;

	/* command lock */
	pthread_mutex_t cmd_lock;

	/* radio attributes */
	MMHandleType *attrs;

	MMRadioThread_t thread[MM_RADIO_THREAD_NUM];

	/* message callback */
	GAsyncQueue *msg_queue;
	MMMessageCallback msg_cb;
	void *msg_cb_param;

	/* seek */
	int prev_seek_freq;
	bool is_muted;
	bool seek_unmute;
	bool is_ready;

	pthread_mutex_t hal_seek_mutex;

	MMRadioSeekDirectionType seek_direction;

	sound_stream_info_h stream_info;
	virtual_sound_stream_h vstream;

	int freq;

	/* command lock */
	pthread_mutex_t volume_lock;

	float local_volume;

	/* region settings */
	MMRadioRegion_t region_setting;

	radio_hal_interface *hal_inf;

	mm_resource_manager_h resource_manager;
	mm_resource_manager_res_h radio_resource;
	int interrupted_by_resource_conflict;

} mm_radio_t;

/*===========================================================================================
  GLOBAL FUNCTION PROTOTYPES
========================================================================================== */
int _mmradio_create_radio(mm_radio_t *radio);
int _mmradio_destroy(mm_radio_t *radio);
int _mmradio_realize(mm_radio_t *radio);
int _mmradio_unrealize(mm_radio_t *radio);
int _mmradio_set_message_callback(mm_radio_t *radio, MMMessageCallback callback, void *user_param);
int _mmradio_get_state(mm_radio_t *radio, int *pState);
int _mmradio_set_frequency(mm_radio_t *radio, int freq);
int _mmradio_get_frequency(mm_radio_t *radio, int *pFreq);
int _mmradio_mute(mm_radio_t *radio);
int _mmradio_unmute(mm_radio_t *radio);
int _mmradio_start(mm_radio_t *radio);
int _mmradio_stop(mm_radio_t *radio);
int _mmradio_seek(mm_radio_t *radio, MMRadioSeekDirectionType direction);
int _mmradio_start_scan(mm_radio_t *radio);
int _mmradio_stop_scan(mm_radio_t *radio);
int _mm_radio_get_signal_strength(mm_radio_t *radio, int *value);
int _mmradio_apply_region(mm_radio_t*radio, MMRadioRegionType region, bool update);
int _mmradio_get_region_type(mm_radio_t*radio, MMRadioRegionType *type);
int _mmradio_get_region_frequency_range(mm_radio_t *radio, unsigned int *min_freq, unsigned int *max_freq);
int _mmradio_get_channel_spacing(mm_radio_t* radio, unsigned int *ch_spacing);
int _mmradio_set_volume(mm_radio_t *radio, float volume);
int _mmradio_get_volume(mm_radio_t *radio, float *pVolume);

#ifdef __cplusplus
}
#endif

#endif /* __MM_Radio_INTERNAL_H__ */