Beispiel #1
0
int main() {
	int fd;
	int wd;
	#define EV_BUFF 1024
	char buffer[EV_BUFF];
	
	fd = inotify_init();
	if(fd < 0)
		xdie("inotify_init failed!");
	
	/* create dir and try to watch it */
	umask(0);
	mkdir(WATCHDIR, S_IRWXU | S_IRWXG);
	chown(WATCHDIR, AID_SYSTEM, AID_AUDIO);
	wd = inotify_add_watch(fd, WATCHDIR, IN_CREATE|IN_DELETE);
	
	if(wd < 0)
		xdie("inotify_add_watch failed!");
	
	
	init_freq();
	
	for(;;) {
		ALOGI("inotify event\n");
		update_freq();
		read(fd, buffer, EV_BUFF);
	}
	close(fd);
	
	return 0;
}
Beispiel #2
0
static unsigned int get_symfreq(symfreq *sf, FILE *in)
{
    int c;
    unsigned int tot = 0;
    /* 初始化频率表 */
    init_freq(sf);
    /* 计算文件中每个符号的出现次数 */
    while ((c = fgetc(in)) != EOF) {
        unsigned char uc = c;
        if (!(*sf)[uc])
            (*sf)[uc] = new_leaf_node(uc);
        ++(*sf)[uc]->count;
        ++tot;
    }
    return tot;
}
Beispiel #3
0
void hi6220_pll_init(void)
{
	uint32_t data;

	init_pll();
	init_freq();

	/*
	 * Init DDR with 533MHz. Otherwise, DDR initialization
	 * may fail on 800MHz on some boards.
	 */
	ddr_phy_reset();
	init_ddr(0);
	/* Init DDR with 800MHz. */
	ddr_phy_reset();
	init_ddr(1);


	ddrc_common_init(1);
	dienum_det_and_rowcol_cfg();
	detect_ddr_chip_info();

	data = mmio_read_32(0xf7032000 + 0x010);
	data &= ~0x1;
	mmio_write_32(0xf7032000 + 0x010, data);
	data = mmio_read_32(0xf7032000 + 0x010);

	/*
	 * Test memory access. Do not use address 0x0 because the compiler
	 * may assume it is not a valid address and generate incorrect code
	 * (GCC 4.9.1 without -fno-delete-null-pointer-checks for instance).
	 */
	mmio_write_32(0x4, 0xa5a55a5a);
	INFO("ddr test value:0x%x\n", mmio_read_32(0x4));
	init_ddrc_qos();

	init_mmc0_pll();
	reset_mmc0_clk();
	init_media_clk();

	dsb();

	init_mmc1_pll();
	reset_mmc1_clk();
}
Beispiel #4
0
		static double freq() {
			static double f = init_freq();
			return f;
		}
Beispiel #5
0
/***************************************************************************
Declaration : int main(void)

Function :    Main Loop
***************************************************************************/
int main(void)
{
	init_mcu();
	init_rf();
	init_buffer();
	init_protocol();
	init_freq();
	
	#ifdef TEST_TX_CW
		test_rf_transmitter(78);
	#endif
	#ifdef TEST_TX_MOD
		test_rf_modulator(81);
	#endif
	#ifdef TEST_RX
		test_rf_receiver(78);
	#endif
		
	/* Main Background loop */
	call_state = CALL_IDLE;
	
	while(1)
	{
		/* Call States */	
		switch (call_state)
		{
			case CALL_IDLE:
				#ifdef DONGLE
					sleep(WDT_TIMEOUT_60MS,STANDBY_MODE);
					call_status = CALL_NO_ACTIVITY;
					#ifdef USB
						SET_VOLUME_DOWN;
						SET_VOLUME_UP;
						SET_MUTE_PLAY;
						SET_MUTE_REC;
						if(CALL_ACTIVITY_PIN)
							call_status = CALL_ACTIVITY;
					#else
						if(!CALL_SETUP_KEY)
							call_status = CALL_ACTIVITY;
					#endif
					if(call_status == CALL_ACTIVITY)
						call_state = CALL_SETUP;
				#endif
				
				#ifdef HEADSET
					sleep(WDT_TIMEOUT_1S,POWER_DOWN_MODE);
					call_state = CALL_SETUP;
				#endif
				
			break;
			
			case CALL_SETUP:
				#ifdef DONGLE
					LED_ON;
					call_status = call_setup(&setup_freq[0],N_FREQ_SETUP);
					LED_OFF;
					if(call_status != CALL_SETUP_FAILURE)
					{
						init_buffer();
						init_rf();
						init_protocol();
						init_codec();
						start_codec();
						#ifdef USB
							// Enable watchdog to handle USB Suspend Mode
							wdt_enable(WDT_TIMEOUT_15MS);
						#else
							start_timer1(0,FRAME_PERIOD, DIV1);
						#endif
						call_state = CALL_CONNECTED;
					}	
					else
						call_state = CALL_IDLE;
				#endif
								
				#ifdef HEADSET
					LED_ON;
					call_status = call_detect(&setup_freq[0],N_FREQ_SETUP,N_REP_SETUP);
					LED_OFF;
					if(call_status != CALL_SETUP_FAILURE)
					{
						init_buffer();
						init_rf();
						init_protocol();
						init_codec();
						call_status &= ~MASTER_SYNC;
						start_timer1(0,FRAME_PERIOD, DIV1);
						call_state = CALL_CONNECTED;
					}
					else
						call_state = CALL_IDLE;
				#endif
			break;
			
			case CALL_CONNECTED:
				#ifdef DONGLE
					while(1)
					{
						// USB Dongle clears watchdog handling USB Suspend Mode
						#ifdef USB
							wdt_reset();
						#endif
						
						// Send and receive audio packet
						audio_transfer();
						
						// Handle key code from HEADSET
						key_code = (signal_in[1] & 0x1F);
						if(key_code != 0)
							LED_ON;
						else
							LED_OFF;
							
						#ifdef USB
							if(key_code & VOLUME_DOWN)
								CLEAR_VOLUME_DOWN;
							else
								SET_VOLUME_DOWN;
								
							if(key_code & VOLUME_UP)
								CLEAR_VOLUME_UP;
							else
								SET_VOLUME_UP;
								
							if(key_code & MUTE_PLAY)
								CLEAR_MUTE_PLAY;
							else
								SET_MUTE_PLAY;
								
							if(key_code & MUTE_REC)
								CLEAR_MUTE_REC;
							else
								SET_MUTE_REC;
						#endif
						
						// Check if call is to be cleared	
						#ifdef USB
							if(!CALL_ACTIVITY_PIN)
							{
								call_activity_timer += 1;
								if(call_activity_timer >= TIMEOUT_CALL_ACTIVITY)
									call_status = CALL_CLEAR;
							}
							else
								call_activity_timer = 0;
						
						#else
							if(!CALL_CLEAR_KEY)
								call_status = CALL_CLEAR;
						#endif
						
						
							
						// Call clearing by HEADSET or DONGLE
						if((key_code == CALL_CLEARING) || (call_status == CALL_CLEAR))
						{
							signal_out[0] |= SIGNAL_CALL_CLEAR;
							call_timer += 1;
							if(call_timer >= TIMEOUT_CALL_CLEAR_MASTER)
							{
								call_state = CALL_IDLE;
								stop_codec();
								init_buffer();
								init_rf();
								init_protocol();
								init_codec();
								eeprom_write(freq[0],EEPROM_ADR_FREQ0);
								eeprom_write(freq[1],EEPROM_ADR_FREQ1);
								LED_OFF;
								#ifdef USB
									// Disable watchdog used to handle USB Suspend Mode
									wdt_disable();
								#endif
								break;
							}
						}
						else
							signal_out[0] &= ~SIGNAL_CALL_CLEAR;
	
						// Call clearing due to Frame Loss
						if(frame_loss >= TIMEOUT_FRAME_LOSS)
						{
							#ifdef USB
								call_state = CALL_RECONNECT;
								init_rf();
								init_protocol();
								// Disable watchdog used to handle USB Suspend Mode
								wdt_disable();
							#else
								call_state = CALL_RECONNECT;
								stop_codec();
								init_buffer();
								init_rf();
								init_protocol();
								init_codec();
							#endif
							break;
						}
					}
				#endif
				
				#ifdef HEADSET
					while(1)
					{
						if(call_status & MASTER_SYNC)
						{
							audio_transfer();
						}
						else
						{
							call_status = get_sync();
							if(call_status & MASTER_SYNC)
								start_codec();
							else
								frame_loss += 10;
						}
						
						// Read and handle keys
						key_code = read_key();
						signal_out[1] &= 0xE0;
						signal_out[1] |= key_code;
						
						
						// Call cleared by DONGLE
						if(signal_in[0] & SIGNAL_CALL_CLEAR)
						{
							call_timer += 1;
							if(call_timer >= TIMEOUT_CALL_CLEAR_SLAVE)
							{
								call_state = CALL_IDLE;
								stop_codec();
								init_buffer();
								init_rf();
								init_protocol();
								init_codec();
								break;
							}
						}
						else
							call_timer = 0;
						
						// Call clearing due to Frame Loss
						if(frame_loss >= TIMEOUT_FRAME_LOSS)
						{
							call_state = CALL_RECONNECT;
							stop_codec();
							init_buffer();
							init_rf();
							init_protocol();
							init_codec();
							break;
						}
					}
				#endif
			break;

			case CALL_RECONNECT:
				#ifdef DONGLE
					LED_ON;
					call_status = call_setup(&setup_freq[0],N_FREQ_SETUP);
					LED_OFF;
					if(call_status != CALL_SETUP_FAILURE)
					{
						#ifdef USB
							init_rf();
							init_protocol();
							reset_codec();
							call_state = CALL_CONNECTED;
						#else
							init_buffer();
							init_rf();
							init_protocol();
							init_codec();
							start_codec();
							start_timer1(0,FRAME_PERIOD, DIV1);
							call_state = CALL_CONNECTED;
						#endif
					}	
					else
					{
						stop_codec();
						init_buffer();
						init_rf();
						init_protocol();
						init_codec();
						call_state = CALL_IDLE;
					}
				#endif
				
				#ifdef HEADSET
					LED_ON;
					call_status = call_detect(&setup_freq[0],N_FREQ_SETUP,N_REP_RECONNECT);
					LED_OFF;
					if(call_status != CALL_SETUP_FAILURE)
					{
						init_buffer();
						init_rf();
						init_protocol();
						init_codec();
						call_status &= ~MASTER_SYNC;
						start_timer1(0,FRAME_PERIOD, DIV1);
						call_state = CALL_CONNECTED;
					}
					else
						call_state = CALL_IDLE;

				#endif
			break;

			default:
			break;
		}
	}
}