Esempio n. 1
0
PUBLIC void setupHardware(void)
{
    //inicializa as configuraçoes do micrococontrolador
    init_mcu();

    //Inicializa driver das interrupcoes
    interrupt_init();

    //Inicializa as portas do microcontrolador
    init_gpio();

    //Inicializa UART
    init_uart();

    //Inicializa TMR0
    init_timer0();

    //Inicializa I2C
    init_i2c();

    //Inicializa ADs
    init_AD();

    //Inicializa PWM
    init_pwm();
}
Esempio n. 2
0
void system_init(void)
{
	init_mcu();

	EXTERNAL_IRQ_0_init();

	USB_0_init();
}
Esempio n. 3
0
void main (void) {
init_mcu ();

init_interrupt ();


_BIS_SR(LPM3_bits + GIE);


while (1);
//_BIS_SR(LPM3_bits + GIE);


}
Esempio n. 4
0
int main(void) {

	short out;
	int resp;

	init_mcu();
	delay_ms(1000);
//	printf("Iniciando Encoder\n\r");
	resp = init_encoder(1);
//	printf("Responsta: %u", resp);

	while (TRUE)
		;

	return 0;
}
Esempio n. 5
0
/*!
 * brief Main function. Execution starts here.
 */
int main(void)
{
	// Reset RIMA counter
	DEBUG_TotalRIMA_Count = 0;
		
	// Initialize everything here...
	init_mcu();

	// Continue...
	init_mcu_led();
	init_pipe_job_system();
	init_XLINK();
	init_USB();
	
	// Initialize A2D
	a2d_init();
	a2d_get_temp(0);    // This is to clear the first invalid conversion result...
	a2d_get_temp(1);    // This is to clear the first invalid conversion result...
	a2d_get_voltage(0); // This is to clear the first invalid conversion result...
	a2d_get_voltage(1); // This is to clear the first invalid conversion result...
	a2d_get_voltage(2); // This is to clear the first invalid conversion result...
	
	// Initialize timer
	MCU_Timer_Initialize();
	MCU_Timer_SetInterval(10);
	MCU_Timer_Start();
	
	// Turn on the front LED
	MCU_MainLED_Initialize();
	MCU_MainLED_Set();
	
	// Initialize flash-saving sequence
	__AVR32_Flash_Initialize();
	
	// Initialize FAN subsystem
	FAN_SUBSYS_Initialize();
	
	// Initialize Global Activity Chip LEDs
	GLOBAL_ChipActivityLEDCounter[0] = 0;
	GLOBAL_ChipActivityLEDCounter[1] = 0;
	GLOBAL_ChipActivityLEDCounter[2] = 0;
	GLOBAL_ChipActivityLEDCounter[3] = 0;
	GLOBAL_ChipActivityLEDCounter[4] = 0;
	GLOBAL_ChipActivityLEDCounter[5] = 0;
	GLOBAL_ChipActivityLEDCounter[6] = 0;
	GLOBAL_ChipActivityLEDCounter[7] = 0;
	
	// Reset the total number of engines detected on startup
	GLOBAL_TotalEnginesDetectedOnStartup = 0;
	
	// Initialize total thermal cycles
	GLOBAL_TOTAL_THERMAL_CYCLES = 0;	
	
	// Last time JobIssue was called. 
	GLOBAL_LastJobIssueToAllEngines = 0;
	
	// Wait for 500ms before doing anything
	volatile unsigned int iHolder = MACRO_GetTickCountRet;
	while (MACRO_GetTickCountRet + 2 - iHolder < 500000) WATCHDOG_RESET;
	
	// Perform an ASIC GET CHIP COUNT
	init_ASIC();
	
	// Now set the side-led's accordingly
	#if defined(__PRODUCT_MODEL_LITTLE_SINGLE) || defined(__PRODUCT_MODEL_JALAPENO)
		if (ASIC_does_chip_exist(0) == TRUE) MCU_LED_Set(1);	
		if (ASIC_does_chip_exist(1) == TRUE) MCU_LED_Set(2);
		if (ASIC_does_chip_exist(2) == TRUE) MCU_LED_Set(3);
		if (ASIC_does_chip_exist(3) == TRUE) MCU_LED_Set(4);
		if (ASIC_does_chip_exist(4) == TRUE) MCU_LED_Set(5);
		if (ASIC_does_chip_exist(5) == TRUE) MCU_LED_Set(6);
		if (ASIC_does_chip_exist(6) == TRUE) MCU_LED_Set(7);
		if (ASIC_does_chip_exist(7) == TRUE) MCU_LED_Set(8);	
	#endif
	
	// Detect if we're chain master or not [MODIFY]
	XLINK_ARE_WE_MASTER = XLINK_detect_if_we_are_master(); // For the moment we're the chain master [MODIFY]
	if (XLINK_ARE_WE_MASTER) 
	{ 
		// Wait for a small time
		blink_medium(); 
		WATCHDOG_RESET;
		blink_medium(); 
		WATCHDOG_RESET;
		blink_medium();
		WATCHDOG_RESET; 
		blink_medium();
		WATCHDOG_RESET; 
		blink_medium();
		WATCHDOG_RESET; 
		blink_medium();
		WATCHDOG_RESET; 
		
		// Initialize the XLINK. Interrogate all devices in the chain and assign then addresses
		if (XLINK_is_cpld_present() == TRUE)
		{
			// We're the master, set proper configuration
			XLINK_set_cpld_id(0);
			XLINK_set_cpld_master(TRUE);
			XLINK_set_cpld_passthrough(FALSE);
			
			if (XLINK_MASTER_Start_Chain() == FALSE)
			{
				// Ok this can be bad, we failed the chain initialization
			}
		}
	}
	else
	{
		if (XLINK_is_cpld_present() == TRUE)
		{
			// Disable pass-through and set our cpld-address = 0x1E
			// We will await enumeration
			XLINK_set_cpld_id(XLINK_GENERAL_DISPATCH_ADDRESS);
			XLINK_set_cpld_master(FALSE);
			XLINK_set_cpld_passthrough(FALSE);
		}
	}
	
	// Reset global values
	global_vals[0] = 0;
	global_vals[1] = 0;
	global_vals[2] = 0;
	global_vals[3] = 0;
	global_vals[4] = 0;
	global_vals[5] = 0;

	GLOBAL_BLINK_REQUEST = 0;
	GLOBAL_PULSE_BLINK_REQUEST = 0;
	
	// Clear ASIC Results... This will make sure the diagnostic nonces are cleared
	unsigned int iNonceValues[16];
	unsigned int iNonceCount;
	ASIC_get_job_status(iNonceValues, &iNonceCount, FALSE, 0);
	
	// Did we reset the ASICs internally?
	GLOBAL_INTERNAL_ASIC_RESET_EXECUTED = FALSE;
	
	// Go to our protocol main loop
	MCU_Main_Loop();
	return(0);
}
Esempio n. 6
0
int main(void)
{
	unsigned char samples[16]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,};
	unsigned char a=0,count=0,i=0;
	init_mcu();
	uart_init();
	BUT_Init();
	KEY_Init();
	SEG_Init();
	sei();
    while(1)
    {
        //TODO:: Please write your application code 
		uart_write(a);
		a++;
		_delay_ms(100);
		
		count = uart_rx_count();
		if(count)
		{
			for(i = 0; i < count; ++i)
			samples[i] = uart_read();
		}
		//---------------------------------------------------------------------------------------
		switch(BUT_GetKey())
		{
			case 0:
			{
				//---------------------------------------------------------------------------------------
				//Set_led_num(a);
				//---------------------------------------------------------------------------------------
			};break;
			case 1:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(samples[0]);
				//---------------------------------------------------------------------------------------
			};break;
			case 2:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(2);
				//---------------------------------------------------------------------------------------
			};break;
			case 3:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(3);
				//---------------------------------------------------------------------------------------
			};break;
			case 4:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(4);
				//---------------------------------------------------------------------------------------
			};break;
			case 5:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(5);
				//---------------------------------------------------------------------------------------
			};break;
		};
		//---------------------------------------------------------------------------------------
		
		
		
		
		
		//---------------------------------------------------------------------------------------
		switch(KEY_GetKey())
		{
			case 0:
			{
				//---------------------------------------------------------------------------------------
				//Set_led_num(a);
				//---------------------------------------------------------------------------------------
			};break;
			case 1:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(1);
				//---------------------------------------------------------------------------------------
			};break;
			case 2:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(2);
				//---------------------------------------------------------------------------------------
			};break;
			case 3:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(3);
				//---------------------------------------------------------------------------------------
			};break;
			case 4:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(4);
				//---------------------------------------------------------------------------------------
			};break;
			case 5:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(5);
				//---------------------------------------------------------------------------------------
			};break;
			case 6:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(6);
				//---------------------------------------------------------------------------------------
			};break;
			case 7:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(7);
				//---------------------------------------------------------------------------------------
			};break;
			case 8:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(8);
				//---------------------------------------------------------------------------------------
			};break;
			case 9:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(9);
				//---------------------------------------------------------------------------------------
			};break;
			case 10:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(10);
				//---------------------------------------------------------------------------------------
			};break;
			case 11:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(11);
				//---------------------------------------------------------------------------------------
			};break;
			case 12:
			{
				//---------------------------------------------------------------------------------------
				Set_led_num(12);
				//---------------------------------------------------------------------------------------
			};break;
		};
		//---------------------------------------------------------------------------------------
		
			
		
		
		
		
    };
};
Esempio n. 7
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;
		}
	}
}